UNPKG

@cuba-platform/front-generator

Version:
57 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.launchCli = exports.createCli = exports.createAndLaunchCli = exports.ownVersion = void 0; /* istanbul ignore file */ //todo not sure how to test and cover this const init_1 = require("./init"); const list_1 = require("./list"); const cli_options_1 = require("./common/cli-options"); exports.ownVersion = require('../package').version; /** * @alpha */ function createAndLaunchCli() { const clients = (0, init_1.collectClients)(); const program = createCli(exports.ownVersion, clients); launchCli(program); } exports.createAndLaunchCli = createAndLaunchCli; /** * @alpha */ function createCli(version, clients, customClientNames, customClientsBaseDir) { const program = require('commander'); program.version(version, '-v, --version') .usage('[command] [options]'); program .command('list') .description('List all available clients and their clients') .option('-s, --save [saveTo]', 'Save information about clients ') .action((cmd) => (0, list_1.exportList)(clients, cmd)); clients.forEach(client => { client.generators.forEach(function (generator) { const generationCommand = program .command(`${client.name}:${generator.name}`) .description(`Generates ${client.name} ${generator.name}`); (0, cli_options_1.extractAvailableOptions)(generator.options).forEach(({ pattern, description }) => { generationCommand.option(pattern, description); }); const baseDir = (customClientNames === null || customClientNames === void 0 ? void 0 : customClientNames.includes(client.name)) ? customClientsBaseDir : undefined; generationCommand.action(function (cmd) { return (0, init_1.generate)(client.name, generator.name, (0, cli_options_1.pickOptions)(cmd, generator.options), baseDir); }); }); }); return program; } exports.createCli = createCli; /** * @alpha */ function launchCli(program) { program.parse(process.argv); // invokes provided command if (!process.argv.slice(2).length) { program.outputHelp(); } } exports.launchCli = launchCli; //# sourceMappingURL=cli.js.map