UNPKG

@wechat-mp/cli

Version:

微信小程序脚手架,集成 Taro、uniapp 第三方模版,支持小程序 CI 上传,预览,发布

64 lines (51 loc) 1.69 kB
"use strict"; const commander = require("commander"); const prepare = require("./prepare"); const pkg = require("../package.json"); const { log } = require("@wechat-mp/utils"); const exec = require("./exec"); const program = new commander.Command(); module.exports = cli; async function cli() { try { await prepare(); registerCommand(); } catch (e) { log.error(e.message); } } function registerCommand() { program .name(Object.keys(pkg.bin)[0]) .usage("<command> [options]") .version(pkg.version) .option("-d, --debug", "是否开启调试模式", false) .option("-tp, --targetPath <targetPath>", "是否指定本地调试文件路径", ""); program.command("init").action(exec); program.command("create [projectName]").action(exec); program .command("ci") .option("-i, --init", "初始化配置", false) .option("-p, --preview", "预览小程序项目", false) .option("-u, --upload", "上传小程序项目到微信平台", false) .action(exec); // 指定targetPath program.on("option:targetPath", function () { process.env.CLI_TARGET_PATH = program.targetPath; }); program.on("option:debug", function () { process.env.LOG_LEVEL = "verbose"; }); // 对未知命令监听 program.on("command:*", function (obj) { const availableCommands = program.commands.map((cmd) => cmd.name()); console.log(colors.red("未知的命令:" + obj[0])); if (availableCommands.length > 0) { console.log(colors.red("可用命令:" + availableCommands.join(","))); } }); program.parse(process.argv); if (program.args && program.args.length < 1) { program.outputHelp(); } }