mine-auto-cli 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/package.json +36 -0
- package/dist/src/abconfig.json +6 -0
- package/dist/src/commander/actions.js +238 -0
- package/dist/src/commander/cmds.js +10 -0
- package/dist/src/commander/enums.js +8 -0
- package/dist/src/commander/index.js +25 -0
- package/dist/src/commander/interfaces.js +2 -0
- package/dist/src/index.js +5 -0
- package/dist/src/utils/alias.js +15 -0
- package/dist/src/utils/index.js +10 -0
- package/dist/src/utils/interfaces.js +2 -0
- package/dist/src/utils/log.js +54 -0
- package/package.json +1 -1
- package/src/commander/actions.ts +49 -1
- package/src/commander/cmds.ts +2 -0
- package/src/commander/index.ts +3 -1
package/README.md
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://img.shields.io/npm/v/mine-auto-cli.svg" /></a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://img.shields.io/npm/dt/mine-auto-cli" /></a>
|
|
8
8
|
<a href="https://www.npmjs.com/package/mine-auto-cli"><img src="https://packagephobia.com/badge?p=mine-auto-cli" /></a>
|
|
9
|
-
<a href="https://github.com/biaov/MINE-H5-UI/blob/master/LICENSE"><img src="https://img.shields.io/github/license/biaov/mine-auto-cli.svg" /></a>
|
|
10
9
|
</h2>
|
|
11
10
|
|
|
12
11
|
## 使用
|
|
@@ -14,17 +13,17 @@
|
|
|
14
13
|
### 安装
|
|
15
14
|
|
|
16
15
|
```Basic
|
|
17
|
-
npm i mine-auto-cli
|
|
16
|
+
npm i mine-auto-cli -g
|
|
18
17
|
```
|
|
19
18
|
|
|
20
19
|
### 自动打包
|
|
21
20
|
|
|
22
21
|
```Basic
|
|
23
|
-
|
|
22
|
+
auto build [desc]
|
|
24
23
|
```
|
|
25
24
|
|
|
26
25
|
### 自动 git 提交
|
|
27
26
|
|
|
28
27
|
```Basic
|
|
29
|
-
|
|
28
|
+
auto git [desc]
|
|
30
29
|
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mine-auto-cli",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "一个本地自动化打包工具,用来节省你的工作流程",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"auto": "bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "npm run serve",
|
|
12
|
+
"serve": "tsc -p tsconfig.json -w",
|
|
13
|
+
"build": "tsc -p tsconfig.json"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git@gitee.com:biaovorg/mine-auto-cli.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"auto",
|
|
21
|
+
"build",
|
|
22
|
+
"tool"
|
|
23
|
+
],
|
|
24
|
+
"author": "biaov <biaov@qq.com>",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^16.9.1"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"chalk": "^4.1.2",
|
|
31
|
+
"commander": "^8.2.0",
|
|
32
|
+
"log-symbols": "^4.1.0",
|
|
33
|
+
"module-alias": "^2.2.2",
|
|
34
|
+
"ora": "^4.1.1"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.buildProd = exports.buildTest = exports.build = exports.git = exports.autoBuild = exports.initConfig = void 0;
|
|
43
|
+
var log_1 = __importDefault(require("@/utils/log")); // 日志
|
|
44
|
+
var ora_1 = __importDefault(require("ora")); // 显示动画效果
|
|
45
|
+
var child_process_1 = require("child_process");
|
|
46
|
+
var chalk_1 = require("chalk"); // 添加字体颜色
|
|
47
|
+
var commander_1 = require("commander"); // 自动解析命令和参数
|
|
48
|
+
var fs_1 = require("fs");
|
|
49
|
+
var path_1 = require("path");
|
|
50
|
+
var abconfig_json_1 = __importDefault(require("../abconfig.json"));
|
|
51
|
+
var package_json_1 = require("@/../package.json"); // 包信息
|
|
52
|
+
var enums_1 = require("./enums");
|
|
53
|
+
var cmds_1 = require("./cmds");
|
|
54
|
+
var cwd = process.cwd(); // 程序根路径
|
|
55
|
+
var iconError = log_1.default.iconError, iconSuccess = log_1.default.iconSuccess, success = log_1.default.success, info = log_1.default.info, error = log_1.default.error, warning = log_1.default.warning;
|
|
56
|
+
var configName = 'abconfig.json';
|
|
57
|
+
var endConfig = abconfig_json_1.default;
|
|
58
|
+
var logOption = enums_1.programOption.log || enums_1.programOption.log2;
|
|
59
|
+
var showLog = process.argv.some(function (value) { return value === logOption; });
|
|
60
|
+
// 执行命令
|
|
61
|
+
var executeCommand = function (dir) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
var building;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
switch (_a.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
info(dir);
|
|
67
|
+
info();
|
|
68
|
+
info((0, chalk_1.blueBright)("auto-build v".concat(package_json_1.version)));
|
|
69
|
+
info();
|
|
70
|
+
info("".concat((0, chalk_1.yellow)('>>'), " \u5728\u6B64\u76EE\u5F55\u4E0B\u81EA\u52A8\u5316\u6253\u5305\u9879\u76EE\uFF1A").concat((0, chalk_1.yellow)(dir)));
|
|
71
|
+
building = endConfig.cmd.map(function (cmd) { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
+
var spinner;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
info("\u5F00\u59CB\u6267\u884C ".concat((0, chalk_1.cyanBright)(cmd), " \u547D\u4EE4"));
|
|
77
|
+
spinner = (0, ora_1.default)({ text: '正在执行命令中...', color: 'yellow' });
|
|
78
|
+
spinner.start();
|
|
79
|
+
info();
|
|
80
|
+
(0, child_process_1.execSync)(cmd, {
|
|
81
|
+
cwd: dir
|
|
82
|
+
});
|
|
83
|
+
spinner.succeed("".concat((0, chalk_1.green)(cmd), " \u547D\u4EE4\u6267\u884C\u6210\u529F"));
|
|
84
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
85
|
+
resolve(true);
|
|
86
|
+
})];
|
|
87
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}); });
|
|
91
|
+
return [4 /*yield*/, Promise.all(building)];
|
|
92
|
+
case 1:
|
|
93
|
+
_a.sent();
|
|
94
|
+
info();
|
|
95
|
+
success('命令全部执行完成');
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}); };
|
|
100
|
+
// 创建目录
|
|
101
|
+
var createDirs = function (dir) {
|
|
102
|
+
try {
|
|
103
|
+
(0, fs_1.accessSync)(dir);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch (_a) {
|
|
107
|
+
if (createDirs((0, path_1.dirname)(dir))) {
|
|
108
|
+
(0, fs_1.mkdirSync)(dir);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
// 初始化 config 文件
|
|
114
|
+
var initConfig = function (dir) {
|
|
115
|
+
if (dir === void 0) { dir = './'; }
|
|
116
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
117
|
+
var outDir, entryFile, spinner, content;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
outDir = (0, path_1.join)(cwd, dir);
|
|
120
|
+
entryFile = (0, path_1.resolve)(__dirname, "../".concat(configName));
|
|
121
|
+
spinner = (0, ora_1.default)({ text: '文件初始化中...', color: 'yellow' });
|
|
122
|
+
info();
|
|
123
|
+
spinner.start();
|
|
124
|
+
content = (0, fs_1.readFileSync)(entryFile).toString() // 读取需要修改的文件
|
|
125
|
+
;
|
|
126
|
+
createDirs(outDir); // 创建目录
|
|
127
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(outDir, configName), content); // 写入文件
|
|
128
|
+
spinner.succeed('文件初始化成功'); // 下载成功
|
|
129
|
+
info();
|
|
130
|
+
return [2 /*return*/];
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
exports.initConfig = initConfig;
|
|
135
|
+
// auto build
|
|
136
|
+
var autoBuild = function (path) {
|
|
137
|
+
if (path === void 0) { path = ''; }
|
|
138
|
+
var options = commander_1.program.opts();
|
|
139
|
+
options.config && (endConfig = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(process.cwd(), options.config)).toString()));
|
|
140
|
+
options.dir && (path = options.dir);
|
|
141
|
+
options.project && (path = endConfig.project[options.project]);
|
|
142
|
+
!path && (path = './');
|
|
143
|
+
var dir = (0, path_1.join)(cwd, path);
|
|
144
|
+
executeCommand(dir);
|
|
145
|
+
};
|
|
146
|
+
exports.autoBuild = autoBuild;
|
|
147
|
+
// git 命令
|
|
148
|
+
var git = function (value) {
|
|
149
|
+
if (value === void 0) { value = 'update'; }
|
|
150
|
+
info();
|
|
151
|
+
info("".concat((0, chalk_1.yellow)('>>'), " \u5F00\u59CB\u4F9D\u6B21\u6267\u884C\u547D\u4EE4..."));
|
|
152
|
+
info();
|
|
153
|
+
// 执行命令
|
|
154
|
+
cmds_1.gitCmds.map(function (cmd) {
|
|
155
|
+
info("\u5F00\u59CB\u6267\u884C ".concat((0, chalk_1.cyanBright)(cmd), " \u547D\u4EE4"));
|
|
156
|
+
var spinner = (0, ora_1.default)({ text: '正在执行命令中...', color: 'yellow' });
|
|
157
|
+
spinner.start();
|
|
158
|
+
cmd.includes('-m') && (cmd += " ".concat(value));
|
|
159
|
+
var childProcess = (0, child_process_1.execSync)(cmd, {
|
|
160
|
+
cwd: process.cwd()
|
|
161
|
+
});
|
|
162
|
+
showLog && info(childProcess.toString());
|
|
163
|
+
spinner.succeed("".concat((0, chalk_1.green)(cmd), " \u547D\u4EE4\u6267\u884C\u6210\u529F"));
|
|
164
|
+
info();
|
|
165
|
+
});
|
|
166
|
+
success('全部命令执行完成');
|
|
167
|
+
info();
|
|
168
|
+
};
|
|
169
|
+
exports.git = git;
|
|
170
|
+
// build 命令
|
|
171
|
+
var build = function (value) {
|
|
172
|
+
if (value === void 0) { value = 'build'; }
|
|
173
|
+
info();
|
|
174
|
+
info("".concat((0, chalk_1.yellow)('>>'), " \u5F00\u59CB\u4F9D\u6B21\u6267\u884C\u547D\u4EE4..."));
|
|
175
|
+
info();
|
|
176
|
+
// 执行命令
|
|
177
|
+
cmds_1.buildCmds.map(function (cmd) {
|
|
178
|
+
info("\u5F00\u59CB\u6267\u884C ".concat((0, chalk_1.cyanBright)(cmd), " \u547D\u4EE4"));
|
|
179
|
+
var spinner = (0, ora_1.default)({ text: '正在执行命令中...', color: 'yellow' });
|
|
180
|
+
spinner.start();
|
|
181
|
+
cmd.includes('-m') && (cmd += " ".concat(value));
|
|
182
|
+
var childProcess = (0, child_process_1.execSync)(cmd, {
|
|
183
|
+
cwd: process.cwd()
|
|
184
|
+
});
|
|
185
|
+
showLog && info(childProcess.toString());
|
|
186
|
+
spinner.succeed("".concat((0, chalk_1.green)(cmd), " \u547D\u4EE4\u6267\u884C\u6210\u529F"));
|
|
187
|
+
info();
|
|
188
|
+
});
|
|
189
|
+
success('全部命令执行完成');
|
|
190
|
+
info();
|
|
191
|
+
};
|
|
192
|
+
exports.build = build;
|
|
193
|
+
// build 命令
|
|
194
|
+
var buildTest = function (value) {
|
|
195
|
+
if (value === void 0) { value = 'build'; }
|
|
196
|
+
info();
|
|
197
|
+
info("".concat((0, chalk_1.yellow)('>>'), " \u5F00\u59CB\u4F9D\u6B21\u6267\u884C\u547D\u4EE4..."));
|
|
198
|
+
info();
|
|
199
|
+
// 执行命令
|
|
200
|
+
cmds_1.buildTestCmds.map(function (cmd) {
|
|
201
|
+
info("\u5F00\u59CB\u6267\u884C ".concat((0, chalk_1.cyanBright)(cmd), " \u547D\u4EE4"));
|
|
202
|
+
var spinner = (0, ora_1.default)({ text: '正在执行命令中...', color: 'yellow' });
|
|
203
|
+
spinner.start();
|
|
204
|
+
cmd.includes('-m') && (cmd += " ".concat(value));
|
|
205
|
+
var childProcess = (0, child_process_1.execSync)(cmd, {
|
|
206
|
+
cwd: process.cwd()
|
|
207
|
+
});
|
|
208
|
+
showLog && info(childProcess.toString());
|
|
209
|
+
spinner.succeed("".concat((0, chalk_1.green)(cmd), " \u547D\u4EE4\u6267\u884C\u6210\u529F"));
|
|
210
|
+
info();
|
|
211
|
+
});
|
|
212
|
+
success('全部命令执行完成');
|
|
213
|
+
info();
|
|
214
|
+
};
|
|
215
|
+
exports.buildTest = buildTest;
|
|
216
|
+
// build 命令
|
|
217
|
+
var buildProd = function (value) {
|
|
218
|
+
if (value === void 0) { value = 'build'; }
|
|
219
|
+
info();
|
|
220
|
+
info("".concat((0, chalk_1.yellow)('>>'), " \u5F00\u59CB\u4F9D\u6B21\u6267\u884C\u547D\u4EE4..."));
|
|
221
|
+
info();
|
|
222
|
+
// 执行命令
|
|
223
|
+
cmds_1.buildProdCmds.map(function (cmd) {
|
|
224
|
+
info("\u5F00\u59CB\u6267\u884C ".concat((0, chalk_1.cyanBright)(cmd), " \u547D\u4EE4"));
|
|
225
|
+
var spinner = (0, ora_1.default)({ text: '正在执行命令中...', color: 'yellow' });
|
|
226
|
+
spinner.start();
|
|
227
|
+
cmd.includes('-m') && (cmd += " ".concat(value));
|
|
228
|
+
var childProcess = (0, child_process_1.execSync)(cmd, {
|
|
229
|
+
cwd: process.cwd()
|
|
230
|
+
});
|
|
231
|
+
showLog && info(childProcess.toString());
|
|
232
|
+
spinner.succeed("".concat((0, chalk_1.green)(cmd), " \u547D\u4EE4\u6267\u884C\u6210\u529F"));
|
|
233
|
+
info();
|
|
234
|
+
});
|
|
235
|
+
success('全部命令执行完成');
|
|
236
|
+
info();
|
|
237
|
+
};
|
|
238
|
+
exports.buildProd = buildProd;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildProdCmds = exports.buildTestCmds = exports.buildCmds = exports.gitCmds = void 0;
|
|
4
|
+
// 关于 git 的 cmd 命令
|
|
5
|
+
exports.gitCmds = ['git add -A', 'git commit -m', 'git push'];
|
|
6
|
+
// export const gitCmds: string[] = ['npm run build:staging', 'git add -A']
|
|
7
|
+
// 关于打包的命令
|
|
8
|
+
exports.buildCmds = ['npm run build:staging', 'git add -A', 'git commit -m', 'git push'];
|
|
9
|
+
exports.buildTestCmds = ['npm run build:test', 'git add -A', 'git commit -m', 'git push'];
|
|
10
|
+
exports.buildProdCmds = ['npm run build:prod', 'git add -A', 'git commit -m', 'git push'];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.programOption = void 0;
|
|
4
|
+
var programOption;
|
|
5
|
+
(function (programOption) {
|
|
6
|
+
programOption["log"] = "-l";
|
|
7
|
+
programOption["log2"] = "--log";
|
|
8
|
+
})(programOption = exports.programOption || (exports.programOption = {}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var commander_1 = require("commander");
|
|
4
|
+
var package_json_1 = require("@/../package.json");
|
|
5
|
+
var actions_1 = require("./actions");
|
|
6
|
+
// 定义命令带参数
|
|
7
|
+
// options 重写
|
|
8
|
+
commander_1.program
|
|
9
|
+
.usage('[commands] [options]')
|
|
10
|
+
.version(package_json_1.version, '-v, --version', '输出版本号')
|
|
11
|
+
.helpOption('-h, --help', '输出所有命令')
|
|
12
|
+
.option('-d, --dir <dir>', '自动化打包目录')
|
|
13
|
+
.option('-p, --project <name>', '自动化打包项目,对应 abconfig.json 里的 project')
|
|
14
|
+
.option('-c, --config <filePath>', "".concat(package_json_1.name, " \u914D\u7F6E\u6587\u4EF6\u5730\u5740"))
|
|
15
|
+
.option('-i, --init [dir]', "\u521D\u59CB\u5316 ".concat(package_json_1.name, " \u914D\u7F6E\u6587\u4EF6 abconfig.json, \u76F8\u5BF9\u8DEF\u5F84"))
|
|
16
|
+
.option('-l, --log', '运行命令时打印日志');
|
|
17
|
+
// 命令
|
|
18
|
+
commander_1.program.command('start [dir]').description('运行自动化构建,dir 表示目录').action(actions_1.autoBuild); // 注册命令的回调
|
|
19
|
+
commander_1.program.command('init [dir]').description('初始化配置文件,dir 表示目录').action(actions_1.initConfig); // 注册命令的回调
|
|
20
|
+
commander_1.program.command('git [desc]').description('git 提交').action(actions_1.git); // 注册命令的回调
|
|
21
|
+
commander_1.program.command('build [desc]').description('打包提交').action(actions_1.build); // 注册命令的回调
|
|
22
|
+
commander_1.program.command('build-test [desc]').description('打包提交').action(actions_1.buildTest); // 注册命令的回调
|
|
23
|
+
commander_1.program.command('build-prod [desc]').description('打包提交').action(actions_1.buildProd); // 注册命令的回调
|
|
24
|
+
process.argv.length < 3 && commander_1.program.help(); // 如果后序没有输入命令,执行帮助指令
|
|
25
|
+
commander_1.program.parse(process.argv); // 处理参数
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file 路径引入文件
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
var path_1 = __importDefault(require("path"));
|
|
10
|
+
var module_alias_1 = __importDefault(require("module-alias"));
|
|
11
|
+
exports.default = (function () {
|
|
12
|
+
module_alias_1.default.addAliases({
|
|
13
|
+
'@': path_1.default.resolve(__dirname, '../')
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var alias_1 = __importDefault(require("./alias")); // 别名
|
|
7
|
+
(0, alias_1.default)();
|
|
8
|
+
/// <reference path="./module.d.ts" />
|
|
9
|
+
var log_1 = __importDefault(require("./log"));
|
|
10
|
+
exports.default = { log: log_1.default };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file 日志打印文件
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
var chalk_1 = require("chalk");
|
|
10
|
+
var log_symbols_1 = __importDefault(require("log-symbols")); // 显示出 √ 或 × 等的图标
|
|
11
|
+
var package_json_1 = require("@/../package.json");
|
|
12
|
+
var log = {};
|
|
13
|
+
var error = log_symbols_1.default.error, success = log_symbols_1.default.success;
|
|
14
|
+
// 管理命令 log 颜色
|
|
15
|
+
var logTypes = [
|
|
16
|
+
{
|
|
17
|
+
name: 'success',
|
|
18
|
+
color: chalk_1.green
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'error',
|
|
22
|
+
color: chalk_1.red,
|
|
23
|
+
prefix: package_json_1.name
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'warning',
|
|
27
|
+
color: chalk_1.red
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'info'
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
// 循环遍历
|
|
34
|
+
logTypes.forEach(function (_a) {
|
|
35
|
+
var logName = _a.name, color = _a.color, _b = _a.prefix, prefix = _b === void 0 ? '' : _b;
|
|
36
|
+
log[logName] = function (text) {
|
|
37
|
+
if (text === void 0) { text = ''; }
|
|
38
|
+
// 是否为对象
|
|
39
|
+
if (typeof text === 'object') {
|
|
40
|
+
var _a = text.text, content = _a === void 0 ? '' : _a, _b = text.prefix, prefixTxt = _b === void 0 ? '' : _b;
|
|
41
|
+
content && console.log("".concat(prefixTxt + ' ').concat(text));
|
|
42
|
+
}
|
|
43
|
+
else if (color) {
|
|
44
|
+
// 是否有颜色
|
|
45
|
+
console.log("".concat(prefix + ' ').concat(color(logName.toUpperCase()), " ").concat(text));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.log(text);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
log.iconError = error;
|
|
53
|
+
log.iconSuccess = success;
|
|
54
|
+
exports.default = log;
|
package/package.json
CHANGED
package/src/commander/actions.ts
CHANGED
|
@@ -10,7 +10,7 @@ import abconfig from '../abconfig.json'
|
|
|
10
10
|
import { version } from '@/../package.json' // 包信息
|
|
11
11
|
import { ABConfig } from './interfaces'
|
|
12
12
|
import { programOption } from './enums'
|
|
13
|
-
import { gitCmds, buildCmds } from './cmds'
|
|
13
|
+
import { gitCmds, buildCmds, buildTestCmds, buildProdCmds } from './cmds'
|
|
14
14
|
|
|
15
15
|
const cwd = process.cwd() // 程序根路径
|
|
16
16
|
const { iconError, iconSuccess, success, info, error, warning } = log
|
|
@@ -127,3 +127,51 @@ export const build = (value = 'build') => {
|
|
|
127
127
|
success('全部命令执行完成')
|
|
128
128
|
info()
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
// build 命令
|
|
132
|
+
export const buildTest = (value = 'build') => {
|
|
133
|
+
info()
|
|
134
|
+
info(`${yellow('>>')} 开始依次执行命令...`)
|
|
135
|
+
info()
|
|
136
|
+
|
|
137
|
+
// 执行命令
|
|
138
|
+
buildTestCmds.map(cmd => {
|
|
139
|
+
info(`开始执行 ${cyanBright(cmd)} 命令`)
|
|
140
|
+
const spinner = ora({ text: '正在执行命令中...', color: 'yellow' })
|
|
141
|
+
spinner.start()
|
|
142
|
+
cmd.includes('-m') && (cmd += ` ${value}`)
|
|
143
|
+
const childProcess = execSync(cmd, {
|
|
144
|
+
cwd: process.cwd()
|
|
145
|
+
})
|
|
146
|
+
showLog && info(childProcess.toString())
|
|
147
|
+
spinner.succeed(`${green(cmd)} 命令执行成功`)
|
|
148
|
+
info()
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
success('全部命令执行完成')
|
|
152
|
+
info()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// build 命令
|
|
156
|
+
export const buildProd = (value = 'build') => {
|
|
157
|
+
info()
|
|
158
|
+
info(`${yellow('>>')} 开始依次执行命令...`)
|
|
159
|
+
info()
|
|
160
|
+
|
|
161
|
+
// 执行命令
|
|
162
|
+
buildProdCmds.map(cmd => {
|
|
163
|
+
info(`开始执行 ${cyanBright(cmd)} 命令`)
|
|
164
|
+
const spinner = ora({ text: '正在执行命令中...', color: 'yellow' })
|
|
165
|
+
spinner.start()
|
|
166
|
+
cmd.includes('-m') && (cmd += ` ${value}`)
|
|
167
|
+
const childProcess = execSync(cmd, {
|
|
168
|
+
cwd: process.cwd()
|
|
169
|
+
})
|
|
170
|
+
showLog && info(childProcess.toString())
|
|
171
|
+
spinner.succeed(`${green(cmd)} 命令执行成功`)
|
|
172
|
+
info()
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
success('全部命令执行完成')
|
|
176
|
+
info()
|
|
177
|
+
}
|
package/src/commander/cmds.ts
CHANGED
|
@@ -4,3 +4,5 @@ export const gitCmds: string[] = ['git add -A', 'git commit -m', 'git push']
|
|
|
4
4
|
|
|
5
5
|
// 关于打包的命令
|
|
6
6
|
export const buildCmds: string[] = ['npm run build:staging', 'git add -A', 'git commit -m', 'git push']
|
|
7
|
+
export const buildTestCmds: string[] = ['npm run build:test', 'git add -A', 'git commit -m', 'git push']
|
|
8
|
+
export const buildProdCmds: string[] = ['npm run build:prod', 'git add -A', 'git commit -m', 'git push']
|
package/src/commander/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { program } from 'commander'
|
|
2
2
|
import { version, name } from '@/../package.json'
|
|
3
|
-
import { initConfig, autoBuild, git,build } from './actions'
|
|
3
|
+
import { initConfig, autoBuild, git, build, buildTest, buildProd } from './actions'
|
|
4
4
|
|
|
5
5
|
// 定义命令带参数
|
|
6
6
|
// options 重写
|
|
@@ -19,6 +19,8 @@ program.command('start [dir]').description('运行自动化构建,dir 表示目
|
|
|
19
19
|
program.command('init [dir]').description('初始化配置文件,dir 表示目录').action(initConfig) // 注册命令的回调
|
|
20
20
|
program.command('git [desc]').description('git 提交').action(git) // 注册命令的回调
|
|
21
21
|
program.command('build [desc]').description('打包提交').action(build) // 注册命令的回调
|
|
22
|
+
program.command('build-test [desc]').description('打包提交').action(buildTest) // 注册命令的回调
|
|
23
|
+
program.command('build-prod [desc]').description('打包提交').action(buildProd) // 注册命令的回调
|
|
22
24
|
|
|
23
25
|
process.argv.length < 3 && program.help() // 如果后序没有输入命令,执行帮助指令
|
|
24
26
|
program.parse(process.argv) // 处理参数
|