UNPKG

@boostercloud/cli

Version:

CLI of the Booster Framework, the next level of abstraction for cloud-native applications

71 lines (70 loc) 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const base_command_1 = require("../../common/base-command"); const script_1 = require("../../common/script"); const brand_1 = require("../../common/brand"); const generator_1 = require("../../services/generator"); const target_1 = require("../../services/generator/target"); const path = require("path"); const project_checker_1 = require("../../services/project-checker"); class Command extends base_command_1.default { async run() { const { args, flags } = await this.parse(Command); try { const fields = flags.fields || []; if (!args.commandName) throw "You haven't provided a command name, but it is required, run with --help for usage"; return run(args.commandName, fields); } catch (error) { console.error(error); } } } Command.description = "Generate new resource, write 'boost new' to see options"; Command.flags = { help: core_1.Flags.help({ char: 'h' }), fields: core_1.Flags.string({ char: 'f', description: 'Field that this command will contain', multiple: true, }), }; Command.args = { commandName: core_1.Args.string(), }; exports.default = Command; const run = async (name, rawFields) => script_1.Script.init(`boost ${brand_1.default.energize('new:command')} 🚧`, (0, target_1.joinParsers)((0, target_1.parseName)(name), (0, target_1.parseFields)(rawFields))) .step('Verifying project', project_checker_1.checkCurrentDirIsABoosterProject) .step('Creating new command', generateCommand) .info('Command generated!') .done(); function generateImports(info) { const commandFieldTypes = info.fields.map((f) => f.type); const commandUsesUUID = commandFieldTypes.some((type) => type == 'UUID'); const componentsFromBoosterTypes = ['Register']; if (commandUsesUUID) { componentsFromBoosterTypes.push('UUID'); } return [ { packagePath: '@boostercloud/framework-core', commaSeparatedComponents: 'Command', }, { packagePath: '@boostercloud/framework-types', commaSeparatedComponents: componentsFromBoosterTypes.join(', '), }, ]; } const generateCommand = (info) => (0, generator_1.generate)({ name: info.name, extension: '.ts', placementDir: path.join('src', 'commands'), template: (0, generator_1.template)('command'), info: { imports: generateImports(info), ...info, }, });