Remove dist folder for insomnia-cli (#2431)

This commit is contained in:
Opender Singh 2020-07-24 06:23:26 +12:00 committed by GitHub
parent b7bc88a326
commit 85ad4f7194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 0 additions and 234 deletions

View File

@ -1,28 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.go = go;
var _generate = require("./commands/generate");
var _util = require("./util");
function makeGenerateCommand(exitOverride) {
// inso generate
const generate = (0, _util.createCommand)(exitOverride, 'generate').description('Code generation utilities');
const conversionTypes = Object.keys(_generate.ConversionTypeMap).join(', '); // inso generate config -t kubernetes config.yaml
generate.command('config <identifier>').description('Generate configuration from an api spec').requiredOption('-t, --type <value>', `the type of configuration to generate, options are [${conversionTypes}]`).option('-o, --output <path>', 'the output path').action((identifier, cmd) => (0, _generate.generateConfig)(identifier, (0, _util.getAllOptions)(cmd)));
return generate;
}
function go(args, exitOverride) {
if (!args) {
args = process.argv;
} // inso -v
(0, _util.createCommand)(!!exitOverride).version((0, _util.getVersion)(), '-v, --version').description('A CLI for Insomnia!').option('--workingDir <dir>', 'Working directory').addCommand(makeGenerateCommand(!!exitOverride)).parseAsync(args).catch(err => console.log('An error occurred', err));
}

View File

@ -1,82 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.generateConfig = generateConfig;
exports.ConversionTypeMap = void 0;
var o2k = _interopRequireWildcard(require("openapi-2-kong"));
var _yaml = _interopRequireDefault(require("yaml"));
var _path = _interopRequireDefault(require("path"));
var _fs = _interopRequireDefault(require("fs"));
var _memDb = require("../db/mem-db");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const ConversionTypeMap = {
kubernetes: 'kong-for-kubernetes',
declarative: 'kong-declarative-config'
};
exports.ConversionTypeMap = ConversionTypeMap;
function validateOptions({
type
}) {
if (!ConversionTypeMap[type]) {
const conversionTypes = Object.keys(ConversionTypeMap).join(', ');
console.log(`Config type "${type}" not unrecognized. Options are [${conversionTypes}].`);
return false;
}
return true;
}
async function generateConfig(identifier, options) {
if (!validateOptions(options)) {
return;
}
const {
type,
output,
workingDir
} = options;
const db = await (0, _memDb.gitDataDirDb)({
dir: workingDir,
filterTypes: ['ApiSpec']
});
let result;
const specFromDb = db.ApiSpec.get(identifier);
try {
if (specFromDb === null || specFromDb === void 0 ? void 0 : specFromDb.contents) {
result = await o2k.generateFromString(specFromDb.contents, ConversionTypeMap[type]);
} else {
result = await o2k.generate(identifier, ConversionTypeMap[type]);
}
} catch (err) {
console.log('Config failed to generate', err);
return;
}
const yamlDocs = result.documents.map(d => _yaml.default.stringify(d)); // Join the YAML docs with "---" and strip any extra newlines surrounding them
const document = yamlDocs.join('\n---\n').replace(/\n+---\n+/g, '\n---\n');
if (output) {
const fullOutputPath = _path.default.resolve(output);
_fs.default.writeFileSync(fullOutputPath, document);
} else {
console.log(document);
}
}

View File

@ -1,65 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.gitDataDirDb = exports.emptyDb = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _yaml = _interopRequireDefault(require("yaml"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const emptyDb = () => ({
ApiSpec: new Map(),
Environment: new Map(),
Request: new Map(),
RequestGroup: new Map(),
Workspace: new Map()
});
exports.emptyDb = emptyDb;
const gitDataDirDb = async ({
dir,
filterTypes
}) => {
const db = emptyDb();
const insomniaDir = _path.default.normalize(_path.default.join(dir || '.', '.insomnia'));
if (!_fs.default.existsSync(insomniaDir)) {
// TODO: control logging with verbose flag
// console.log(`Directory not found: ${insomniaDir}`);
return db;
}
const readAndInsertDoc = async (type, fileName) => {
// Get contents of each file in type dir and insert into data
const contents = await _fs.default.promises.readFile(fileName);
const obj = _yaml.default.parse(contents.toString());
db[type].set(obj._id, obj);
};
const types = (filterTypes === null || filterTypes === void 0 ? void 0 : filterTypes.length) ? filterTypes : Object.keys(db);
await Promise.all(types.map(async type => {
// Get all files in type dir
const typeDir = _path.default.join(insomniaDir, type);
if (!_fs.default.existsSync(typeDir)) {
return;
}
const files = await _fs.default.promises.readdir(typeDir);
return Promise.all( // Insert each file from each type
files.map(file => readAndInsertDoc(type, _path.default.join(insomniaDir, type, file))));
}));
return db;
};
exports.gitDataDirDb = gitDataDirDb;

View File

@ -1,11 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SpecName = void 0;
// These types should come from a shared location (maybe insomnia-importers?)
// They represent the models that are read from an Insomnia data source
// eg. git data directory, insomnia export format, etc
const SpecName = 'ApiSpec';
exports.SpecName = SpecName;

View File

@ -1,47 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createCommand = createCommand;
exports.getVersion = getVersion;
exports.getAllOptions = getAllOptions;
var _commander = _interopRequireDefault(require("commander"));
var packageJson = _interopRequireWildcard(require("../package.json"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createCommand(exitOverride, cmd) {
const command = new _commander.default.Command(cmd).storeOptionsAsProperties(false);
if (exitOverride) {
return command.exitOverride();
}
return command;
}
function getVersion() {
return packageJson.version;
}
function getAllOptions(cmd) {
let opts = {};
let command = cmd;
do {
// overwrite options with more specific ones
opts = { ...command.opts(),
...opts
};
command = command.parent;
} while (command);
return opts;
}