@boostercloud/cli
Version:
CLI of the Booster Framework, the next level of abstraction for cloud-native applications
60 lines (59 loc) • 2.33 kB
JavaScript
;
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 ScheduledCommand extends base_command_1.default {
async run() {
const { args } = await this.parse(ScheduledCommand);
try {
if (!args.scheduledCommandName)
throw "You haven't provided a scheduled command name, but it is required, run with --help for usage";
return run(args.scheduledCommandName);
}
catch (error) {
console.error(error);
}
}
}
ScheduledCommand.description = "generate new scheduled command, write 'boost new:scheduled-command -h' to see options";
ScheduledCommand.flags = {
help: core_1.Flags.help({ char: 'h' }),
};
ScheduledCommand.args = {
scheduledCommandName: core_1.Args.string(),
};
exports.default = ScheduledCommand;
const run = async (name) => script_1.Script.init(`boost ${brand_1.default.energize('new:scheduled-command')} 🚧`, (0, target_1.joinParsers)((0, target_1.parseName)(name)))
.step('Verifying project', project_checker_1.checkCurrentDirIsABoosterProject)
.step('Creating new scheduled command', generateScheduledCommand)
.info('Scheduled command generated!')
.done();
function generateImports() {
const componentsFromBoosterTypes = ['Register'];
return [
{
packagePath: '@boostercloud/framework-core',
commaSeparatedComponents: 'ScheduledCommand',
},
{
packagePath: '@boostercloud/framework-types',
commaSeparatedComponents: componentsFromBoosterTypes.join(', '),
},
];
}
const generateScheduledCommand = (info) => (0, generator_1.generate)({
name: info.name,
extension: '.ts',
placementDir: path.join('src', 'scheduled-commands'),
template: (0, generator_1.template)('scheduled-command'),
info: {
imports: generateImports(),
...info,
},
});