@mbc-cqrs-serverless/cli
Version:
a CLI to get started with MBC CQRS serverless framework
45 lines (44 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = generateAction;
const schematic_runner_1 = require("../runners/schematic.runner");
const schematics_1 = require("../schematics");
const ui_1 = require("../ui");
/* eslint-disable no-console */
async function generateAction(schematic, name, options, command) {
ui_1.logger.info(`Executing command '${command.name()}' for application with options '${JSON.stringify(options)}'`);
const commandOptions = command.opts();
const formatOptions = [];
formatOptions.push({ name: 'dry-run', value: !!commandOptions.dryRun });
formatOptions.push({ name: 'mode', value: commandOptions.mode });
formatOptions.push({
name: 'schema',
value: !!commandOptions.schema || !!commandOptions.noSchema, // noSchema > schema
});
const inputs = [];
inputs.push({ name: 'schematic', value: schematic });
inputs.push({ name: 'name', value: name });
const fullInputs = formatOptions.concat(inputs);
const schematicOptions = mapSchematicOptions(fullInputs);
const runner = new schematic_runner_1.SchematicRunner();
const fullCommand = buildCommandLine(schematic, schematicOptions);
runner.run(fullCommand);
}
function buildCommandLine(name, options) {
return `@mbc-cqrs-serverless/cli:${name}${buildOptions(options)}`;
}
function buildOptions(options) {
return options.reduce((line, option) => {
return line.concat(` ${option.toCommandString()}`);
}, '');
}
const mapSchematicOptions = (inputs) => {
const excludedInputNames = ['schematic', 'spec', 'flat', 'specFileSuffix'];
const options = [];
inputs.forEach((input) => {
if (!excludedInputNames.includes(input.name) && input.value !== undefined) {
options.push(new schematics_1.SchematicOption(input.name, input.value));
}
});
return options;
};