1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
5 | return new (P || (P = Promise))(function (resolve, reject) {
|
6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
9 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
10 | });
|
11 | };
|
12 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
13 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
14 | };
|
15 | var __importStar = (this && this.__importStar) || function (mod) {
|
16 | if (mod && mod.__esModule) return mod;
|
17 | var result = {};
|
18 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
19 | result["default"] = mod;
|
20 | return result;
|
21 | };
|
22 | Object.defineProperty(exports, "__esModule", { value: true });
|
23 | const platforms_1 = __importDefault(require("../consts/platforms"));
|
24 | const buildOptions_1 = __importDefault(require("../consts/buildOptions"));
|
25 | const cliBuilder_1 = __importDefault(require("./cliBuilder"));
|
26 | const init_1 = __importDefault(require("./commands/init"));
|
27 | const createPage_1 = __importDefault(require("./commands/createPage"));
|
28 | const install_1 = __importDefault(require("./commands/install"));
|
29 | const path = __importStar(require("path"));
|
30 | require("../tasks/chaikaMergeTask/injectChaikaEnv");
|
31 | const { version } = require('../package.json');
|
32 | const index_1 = __importDefault(require("../tasks/chaikaMergeTask/index"));
|
33 | let cwd = process.cwd();
|
34 | function changeWorkingDir() {
|
35 | process.chdir(path.join(cwd, '.CACHE/nanachi'));
|
36 | }
|
37 | function isChaikaMode() {
|
38 | return process.env.NANACHI_CHAIK_MODE === 'CHAIK_MODE';
|
39 | }
|
40 | const cli = new cliBuilder_1.default();
|
41 | cli.checkNodeVersion('8.6.0');
|
42 | cli.version = version;
|
43 | cli.addCommand('init <app-name>', null, 'description: 初始化项目', {}, (appName) => {
|
44 | init_1.default(appName);
|
45 | });
|
46 | cli.addCommand('install [name]', null, 'description: 安装拆库模块. 文档: https://rubylouvre.github.io/nanachi/documents/chaika.html', {
|
47 | 'branch': {
|
48 | desc: '指定分支',
|
49 | alias: 'b'
|
50 | }
|
51 | }, function (name, opts) {
|
52 | install_1.default(name, opts);
|
53 | });
|
54 | ['page', 'component'].forEach(type => {
|
55 | cli.addCommand(`${type} <page-name>`, null, `description: 创建${type}s/<${type}-name>/index.js模版`, {}, (name) => {
|
56 | createPage_1.default({ name, isPage: type === 'page' });
|
57 | });
|
58 | });
|
59 | platforms_1.default.forEach(function (el) {
|
60 | const { buildType, des, isDefault } = el;
|
61 | ['build', 'watch'].forEach(function (compileType) {
|
62 | cli.addCommand(`${compileType}:${buildType}`, isDefault ? compileType : null, des, buildOptions_1.default, (options) => __awaiter(this, void 0, void 0, function* () {
|
63 | if (isChaikaMode()) {
|
64 | try {
|
65 | yield index_1.default();
|
66 | changeWorkingDir();
|
67 | }
|
68 | catch (err) {
|
69 | console.error(err);
|
70 | process.exit(1);
|
71 | }
|
72 | }
|
73 | require('./commands/build')(Object.assign(Object.assign({}, options), { watch: compileType === 'watch', buildType }));
|
74 | }));
|
75 | });
|
76 | });
|
77 | cli.run();
|