UNPKG

4.77 kBJavaScriptView Raw
1#!/usr/bin/env node
2///@ts-check
3"use strict";
4var config = require("../src/load-config");
5var tasks = require("../src/task");
6var argv = require("yargs")
7 .scriptName("mp")
8 .usage("\nMiniProgram build tools <小程序编译打包工具>")
9 .usage("Usage <用法>:\n $0 [command...] [--option]")
10 .usage("FullName <完整名称>:\n miniprogram-build [command...] [--option]")
11 .example("$0 js js-watch", "编译并监测生成js文件")
12 .example("$0 --config=mpconfig.json", "指定配置文件")
13 .example("$0 --release --var.APP_ID=1234", "优化编译")
14 // configuration
15 .pkgConf("mpconfig")
16 .config(config.default())
17 .config("config", "JSON config file <配置置文件,命令参数优先级高于配置>", config.load)
18 .alias("c", "config")
19 .help("help", "show help <显示帮助信息>")
20 .alias("h", "help")
21 .describe("version", "show version number <查看本版号>")
22 .epilog("2018 - " + new Date().getFullYear() + " @ NewFuture")
23 .option("release", {
24 describe: "production mode <发布模式会优化压缩>",
25 default: false,
26 boolean: true,
27 })
28 .option("src", {
29 describe: "source folder <源文件目录>",
30 default: "src",
31 type: "string",
32 })
33 .option("dist", {
34 describe: "output folder <编译输出目录>",
35 default: "dist",
36 type: "string",
37 })
38 .option("exclude", {
39 describe: "ignored files <编译忽略文件(夹)>",
40 example: "types/**/*",
41 array: true,
42 string: true,
43 })
44 .option("tsconfig", {
45 describe: "typescript config file <TS配置,未设置会自动查找tsconfig.json>",
46 // default: '',
47 // type:'string',
48 })
49 .option("copy", {
50 describe: "files to copy <复制的文件>",
51 })
52 .option("assets", {
53 describe:
54 "assets folder under src/ for compling style, wont put to dist <样式所需资源文件;会监测文件修改,但不会编译或复制到输出目录>",
55 default: "assets",
56 type: "string",
57 })
58 .option("var", {
59 describe: "KEY value pair to replace in js/json <替换JS和JSON中的变量>",
60 // type: 'object',
61 })
62 // .showHelpOnFail(true,'--help for available options')
63 .command(["*", "dev"], "build and watch <构建和检测文件修改>")
64 .command("watch", "watch file changes <监测文件变化>")
65 .command("build", "clean and compile <清理和编译所有文件>")
66 .command("clean", "remove all files in dist <清理dist>")
67 .command("compile", "compile all source files to dist <编译所有源文件>")
68 .command("js", "compile ts/js files to `.js` <编译生成js>")
69 .command("typescript", "compile ts files to `.js` <编译ts>")
70 .command("javascript", "compile all js as JavaScript <编译js>")
71 .command("wxs", "compile wxs/wxts to `wxs` <编译生成wxs>")
72 .command("wxts", "compile WeiXinTypeScript to `wxs` <编译wxts>")
73 .command("wxjs", "compile wxs as JavaScript <编译wxs>")
74 .command("wxss", "compile scss/sass/css/wxss to `.wxss` <编译生成wxss>")
75 .command("wxml", "compile html/wxml files to `.wxml` <编译生成wxml>")
76 .command("json", "compile all json/jsonc files to json <编译生成json>")
77 .command("image", "compresse all images in source to dist <压缩所有图片>")
78 .command("copy", "copy all files match `copy` <复制需要复制的文件>")
79 .command("npm", "build npm dependencies to dist <编译npm依赖>")
80 .command("js-watch", "watch changes of ts/js files <监测ts/js改动>")
81 .command("typescript-watch", false) //"watch changes of ts files <监测ts改动>"
82 .command("javascript-watch", false) // "watch changes of js files <监测js改动>"
83 .command("wxs-watch", "watch changes of .wxs/.wxts <监测.wxs/.wxts>")
84 .command("wxts-watch", false) //"watch changes of .wxts files <监测wxts改动>"
85 .command("wxjs-watch", false) //"watch changes of .wxs files <监测wxs改动>"
86 .command("wxss-watch", "watch changes of scss/sass/css/wxss <实时生成wxss>")
87 .command("wxml-watch", "watch changes of html/wxml files <实时生成wxml>")
88 .command("json-watch", "watch changes of all json/jsonc files <实时生成json>")
89 .command("image-watch", "watch changes of all images in source <实时压缩图片>")
90 .command("copy-watch", "watch changes of `copy` files <实时复制更新文件>")
91 .command("npm-watch", "watch changes of npm dependencies <实时更新npm依赖>")
92 .strict().argv;
93
94Object.assign(tasks.$config, argv);
95tasks.$execute(argv._.length === 0 ? ["dev"] : argv._);