ff-mini-cli
Version:
A tool for mini program development and deployment
48 lines • 1.92 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.resolveCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const child_process_1 = require("child_process");
const index_1 = require("./utils/index");
exports.resolveCommand = (command, options = {}) => {
const action = options && options.command;
const found = index_1.cmdOpts.find(_ => _.cmd === action);
const opts = found && found.opts;
const missingOpts = (opts || []).filter((opt) => {
const { alias = '' } = (opt || {});
const optName = opt.name;
const optAlias = alias.slice(1);
const isDerivedFromProps = options[optName] || options[optAlias];
return (opt.required || opt.optional) && !isDerivedFromProps;
});
const missingParameters = missingOpts.map(o => {
const { alias, name, get, optional } = o;
const key = alias || `--${name}`;
const value = index_1.isFunction(get) ? get() : '';
return (optional && !value) ? '' : `${key} ${value}`;
}).join(' ');
return `${command} ${missingParameters}`;
};
exports.run = (command) => {
const shouldRunDevToolCli = process.platform === 'darwin';
if (command.trim()) {
console.log(chalk_1.default.cyan(`command => ${chalk_1.default.blue(command)}`));
}
if (shouldRunDevToolCli) {
const cliPath = '/Applications/wechatwebdevtools.app/Contents/MacOS/cli';
const cmd = `${cliPath} ${command}`;
try {
child_process_1.execSync(cmd, {
stdio: 'inherit'
});
return true;
}
catch (err) {
console.log(`run WeChat Dev Tool error: ${err}`);
}
}
};
//# sourceMappingURL=resolver.js.map