@wpk-cli/cli
Version:
an unofficial CLI for webpack
58 lines (44 loc) • 2 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = installCommand;
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
var _get = _interopRequireDefault(require("lodash/get"));
var _commandRun = _interopRequireDefault(require("./command-run"));
var _package = _interopRequireDefault(require("../package"));
var _util = require("./util");
function prepareCommand(cmd) {
cmd.version(_package.default.version); // wpk prompt options
// TODO only set --preset flag when the command uses WpkPrompt
cmd.option("--preset <name>", "Use a saved preset for the command prompts (if applicable)");
cmd.option("-n, --no-help", "Do not display live help text & documentation (if applicable)"); // wpk options
cmd.option("--webpack <scope>", "Force use of local or global webpack");
cmd.option("--wpk-debug", "Enable wpk debug mode");
cmd.option("--wpk-no-info", "Do not log initial wpk info");
cmd.option("--wpk-profile", "Enable wpk profiling mode");
cmd.option("--wpk-is-profiling", "Set when wpk is in profiling mode (no-op)");
}
function installCommand(program, command) {
try {
const install = (0, _get.default)(command, "install");
if ((0, _isFunction.default)(install)) {
const cmd = install(program, (0, _util.getCommandDefaults)());
if ((0, _isFunction.default)((0, _get.default)(cmd, "option"))) {
prepareCommand(cmd);
/* istanbul ignore next */
cmd.action((...args) => (0, _commandRun.default)(command, args));
} else {
throw new Error("command#install did not return a Command");
}
} else if (install) {
throw new Error("command#install is not a function");
} else {
throw new Error("command#install function not found");
}
} catch (err) {
(0, _util.printCommandError)(err, command, "install");
global.wpk.exit(1);
}
}
;