UNPKG

@contentstack/cli-dev-dependencies

Version:

Customized dev dependencies for ContentStack projects

31 lines (30 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.command = void 0; const tslib_1 = require("tslib"); const first_1 = tslib_1.__importDefault(require("lodash/first")); const split_1 = tslib_1.__importDefault(require("lodash/split")); const replace_1 = tslib_1.__importDefault(require("lodash/replace")); const core_1 = require("@oclif/core"); const load_config_1 = require("./load-config"); const castArray = (input) => { if (input === undefined) return []; return Array.isArray(input) ? input : [input]; }; function command(commandInstance, args, opts = {}) { return { async run(ctx) { if (!ctx.config || opts.reset) ctx.config = await (0, load_config_1.loadConfig)(opts).run({}); args = castArray(args); const firstExample = '' + (0, first_1.default)(commandInstance.examples); const [id] = (0, split_1.default)((0, replace_1.default)(firstExample, '$ csdx ', ''), ' '); const cmdId = (0, core_1.toStandardizedId)(id, ctx.config); ctx.expectation = ctx.expectation || `runs ${args.join(' ')}`; await ctx.config.runHook('init', { id: cmdId, argv: args }); await commandInstance.run(args); }, }; } exports.command = command;