UNPKG

@dojo/cli

Version:

Dojo CLI utility

50 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const yargs = require("yargs"); const Helper_1 = require("./Helper"); const template_1 = require("./template"); const command_1 = require("./command"); const validate_1 = require("./commands/validate"); /** * CommandHelper class which is passed into each command's run function * allowing commands to call one another. Provides 'run' and 'exists' functions */ class SingleCommandHelper { constructor(commandsMap, context, configurationHelperFactory) { this._groupMap = commandsMap; this._context = context; this._configurationFactory = configurationHelperFactory; } renderFiles(renderFilesConfig, renderData) { renderFilesConfig.forEach(({ src, dest }) => { template_1.default(src, dest, renderData); }); } run(group, commandName, args) { try { const command = command_1.getCommand(this._groupMap, group, commandName); if (command) { const validateHelper = { validate: validate_1.builtInCommandValidation }; const helper = new Helper_1.default(this, yargs, this._context, this._configurationFactory, validateHelper); return command.run(helper.sandbox(group, command.name), args); } else { return Promise.reject(new Error('The command does not exist')); } } catch (_a) { return Promise.reject(new Error('The command does not exist')); } } exists(group, commandName) { try { return !!command_1.getCommand(this._groupMap, group, commandName); } catch (_a) { return false; } } } exports.SingleCommandHelper = SingleCommandHelper; exports.default = SingleCommandHelper; //# sourceMappingURL=CommandHelper.js.map