@tmsfe/tmskit 0.0.21 → 0.0.24-beta.0
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/CHANGELOG.md +7 -1
- package/dist/index.cjs.js +1481 -1405
- package/package.json +5 -8
- package/src/.DS_Store +0 -0
- package/src/compile/compile.js +53 -155
- package/src/compile/dev.js +12 -48
- package/src/compile/plugins/mpProjectJson.js +13 -0
- package/src/compile/plugins/replaceEnv.js +7 -14
- package/src/compile/watch.js +50 -17
- package/src/config/constant.js +29 -8
- package/src/config/defaultTmsConfig.js +24 -0
- package/src/core/buildAppJson.js +4 -0
- package/src/core/checkDependencies.js +4 -1
- package/src/core/cloneModules.js +6 -3
- package/src/core/mpCi.js +62 -14
- package/src/core/npm.js +3 -19
- package/src/core/recommendVersion.js +118 -0
- package/src/core/report.js +25 -0
- package/src/core/tmsMpconfig.js +16 -29
- package/src/entry.js +45 -21
- package/src/index.js +54 -27
- package/src/scripts/.DS_Store +0 -0
- package/src/scripts/create/index.js +3 -1
- package/src/scripts/extend-cmd/index.js +74 -0
- package/src/scripts/run/build/index.js +10 -3
- package/src/scripts/run/cloud/index.js +1 -1
- package/src/scripts/run/dev/index.js +12 -5
- package/src/scripts/run/index.js +27 -11
- package/src/scripts/run/install/cache.js +36 -0
- package/src/scripts/run/install/index.js +3 -3
- package/src/scripts/run/preview/index.js +70 -0
- package/src/scripts/run/preview/utils.js +43 -0
- package/src/scripts/run/upload/index.js +65 -0
- package/src/utils/log.js +3 -0
- package/src/utils/widgets.js +55 -34
package/dist/index.cjs.js
CHANGED
|
@@ -1,102 +1,85 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var require$$
|
|
3
|
+
var require$$3 = require('chalk');
|
|
4
4
|
var require$$1 = require('moment');
|
|
5
|
-
var require$$0
|
|
6
|
-
var require$$1$1 = require('
|
|
7
|
-
var require$$
|
|
8
|
-
var require$$
|
|
9
|
-
var require$$
|
|
10
|
-
var require$$
|
|
11
|
-
var require$$
|
|
12
|
-
var require$$0$
|
|
13
|
-
var require$$0$5 = require('async');
|
|
5
|
+
var require$$0 = require('ora');
|
|
6
|
+
var require$$1$1 = require('path');
|
|
7
|
+
var require$$0$1 = require('fs');
|
|
8
|
+
var require$$2 = require('shelljs');
|
|
9
|
+
var require$$4 = require('glob-ignore');
|
|
10
|
+
var require$$1$2 = require('os');
|
|
11
|
+
var require$$0$2 = require('lodash');
|
|
12
|
+
var require$$0$3 = require('async');
|
|
14
13
|
var require$$1$3 = require('ejs');
|
|
15
14
|
var require$$1$4 = require('inquirer');
|
|
16
|
-
var require$$0$
|
|
17
|
-
var require$$
|
|
15
|
+
var require$$0$4 = require('metalsmith');
|
|
16
|
+
var require$$0$5 = require('request');
|
|
18
17
|
var require$$10 = require('unzipper');
|
|
19
18
|
var require$$1$5 = require('crypto');
|
|
20
|
-
var require$$0$
|
|
19
|
+
var require$$0$6 = require('miniprogram-ci');
|
|
21
20
|
var require$$1$6 = require('fs-extra');
|
|
22
21
|
var require$$1$7 = require('semver');
|
|
23
|
-
var require$$0$
|
|
24
|
-
var require$$
|
|
25
|
-
var require$$1
|
|
26
|
-
var require$$
|
|
27
|
-
var require$$0$
|
|
28
|
-
var require$$
|
|
29
|
-
var require$$
|
|
30
|
-
var require$$
|
|
31
|
-
var require$$5$1 = require('chokidar');
|
|
22
|
+
var require$$0$7 = require('gulp');
|
|
23
|
+
var require$$2$1 = require('minimatch');
|
|
24
|
+
var require$$3$1 = require('gulp-if');
|
|
25
|
+
var require$$6 = require('through2');
|
|
26
|
+
var require$$0$8 = require('object-assign');
|
|
27
|
+
var require$$3$2 = require('fancy-log');
|
|
28
|
+
var require$$4$1 = require('ansi-colors');
|
|
29
|
+
var require$$5 = require('chokidar');
|
|
32
30
|
var require$$6$1 = require('readable-stream');
|
|
33
31
|
var require$$7 = require('vinyl-file');
|
|
34
32
|
var require$$8 = require('vinyl');
|
|
35
|
-
var require$$9
|
|
33
|
+
var require$$9 = require('anymatch');
|
|
36
34
|
var require$$11 = require('glob-parent');
|
|
37
|
-
var require$$2$
|
|
35
|
+
var require$$2$2 = require('plugin-error');
|
|
38
36
|
var require$$10$1 = require('path-is-absolute');
|
|
39
|
-
var require$$12 = require('slash');
|
|
37
|
+
var require$$12$1 = require('slash');
|
|
38
|
+
var require$$1$8 = require('commander');
|
|
40
39
|
|
|
41
40
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
42
41
|
|
|
43
|
-
var require$$
|
|
42
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
44
43
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
45
|
-
var require$$0__default
|
|
44
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
46
45
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
46
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
47
47
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
48
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
48
49
|
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
49
50
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
50
51
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
51
|
-
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
52
|
-
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
53
|
-
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
54
52
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
55
53
|
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
56
|
-
var require$$0__default$
|
|
57
|
-
var require$$
|
|
54
|
+
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
55
|
+
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
58
56
|
var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
|
|
59
57
|
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
60
|
-
var require$$0__default$
|
|
58
|
+
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
61
59
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
62
60
|
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
61
|
+
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
62
|
+
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
63
|
+
var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
64
|
+
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
63
65
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
64
|
-
var require$$
|
|
65
|
-
var require$$
|
|
66
|
-
var require$$
|
|
67
|
-
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
68
|
-
var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
|
|
69
|
-
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
70
|
-
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
71
|
-
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
|
|
66
|
+
var require$$3__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
|
|
67
|
+
var require$$4__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
|
|
68
|
+
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
72
69
|
var require$$6__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
|
|
73
70
|
var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
|
|
74
71
|
var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
|
|
75
|
-
var require$$9__default
|
|
72
|
+
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
76
73
|
var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
|
|
77
|
-
var require$$2__default$
|
|
74
|
+
var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
|
|
78
75
|
var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
|
|
79
|
-
var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12);
|
|
80
|
-
|
|
81
|
-
function getAugmentedNamespace(n) {
|
|
82
|
-
if (n.__esModule) return n;
|
|
83
|
-
var a = Object.defineProperty({}, '__esModule', {value: true});
|
|
84
|
-
Object.keys(n).forEach(function (k) {
|
|
85
|
-
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
86
|
-
Object.defineProperty(a, k, d.get ? d : {
|
|
87
|
-
enumerable: true,
|
|
88
|
-
get: function () {
|
|
89
|
-
return n[k];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
return a;
|
|
94
|
-
}
|
|
76
|
+
var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12$1);
|
|
77
|
+
var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
|
|
95
78
|
|
|
96
79
|
var src$2 = {};
|
|
97
80
|
|
|
98
|
-
const chalk$4 = require$$
|
|
99
|
-
const moment = require$$1__default;
|
|
81
|
+
const chalk$4 = require$$3__default;
|
|
82
|
+
const moment$1 = require$$1__default;
|
|
100
83
|
/**
|
|
101
84
|
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
102
85
|
*/
|
|
@@ -114,7 +97,7 @@ const fail$9 = (message = '') => {
|
|
|
114
97
|
|
|
115
98
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
116
99
|
|
|
117
|
-
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
100
|
+
console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
118
101
|
};
|
|
119
102
|
/**
|
|
120
103
|
* 打印绿底黑字格式的文字
|
|
@@ -128,7 +111,7 @@ const succeed$2 = (message = '') => {
|
|
|
128
111
|
|
|
129
112
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
130
113
|
|
|
131
|
-
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
114
|
+
console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
132
115
|
};
|
|
133
116
|
/**
|
|
134
117
|
* 打印warn提示
|
|
@@ -138,29 +121,29 @@ const succeed$2 = (message = '') => {
|
|
|
138
121
|
|
|
139
122
|
|
|
140
123
|
const warn$2 = message => {
|
|
141
|
-
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$4.yellow(message));
|
|
124
|
+
console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, chalk$4.yellow(message));
|
|
142
125
|
};
|
|
143
126
|
|
|
144
|
-
const info$
|
|
127
|
+
const info$g = (...args) => console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
128
|
+
|
|
129
|
+
const infoNoTime$2 = (...args) => console.log(...args);
|
|
145
130
|
|
|
146
131
|
var log$1 = {
|
|
147
132
|
fail: fail$9,
|
|
148
133
|
succeed: succeed$2,
|
|
149
134
|
warn: warn$2,
|
|
150
|
-
info: info$
|
|
135
|
+
info: info$g,
|
|
136
|
+
infoNoTime: infoNoTime$2
|
|
151
137
|
};
|
|
152
138
|
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const shelljs$7 = require$$0__default$3;
|
|
159
|
-
const glob$1 = require$$6__default;
|
|
139
|
+
const ora$1 = require$$0__default;
|
|
140
|
+
const path$g = require$$1__default$1;
|
|
141
|
+
const fs$i = require$$0__default$1;
|
|
142
|
+
const shelljs$8 = require$$2__default;
|
|
143
|
+
const glob = require$$4__default;
|
|
160
144
|
const {
|
|
161
|
-
info: info$
|
|
145
|
+
info: info$f
|
|
162
146
|
} = log$1;
|
|
163
|
-
const chalk$3 = require$$0__default;
|
|
164
147
|
const shelljsOptions = {
|
|
165
148
|
slient: true,
|
|
166
149
|
async: false
|
|
@@ -169,36 +152,14 @@ const shelljsOptions = {
|
|
|
169
152
|
const cwd = process.cwd();
|
|
170
153
|
|
|
171
154
|
function resolve$g(...args) {
|
|
172
|
-
return path$
|
|
155
|
+
return path$g.resolve(cwd, ...args);
|
|
173
156
|
}
|
|
174
|
-
/**
|
|
175
|
-
* 用户输入命令时,进行提示
|
|
176
|
-
* @param {String} unknownCommand 非预期的命令
|
|
177
|
-
* @returns {Undefined} 无需返回值
|
|
178
|
-
*/
|
|
179
|
-
|
|
180
|
-
const suggestCommands$1 = unknownCommand => {
|
|
181
|
-
const availableCommands = program$1.commands.map(cmd => cmd._name);
|
|
182
|
-
let suggestion;
|
|
183
|
-
availableCommands.forEach(cmd => {
|
|
184
|
-
const isBestMatch = leven(cmd, unknownCommand) < leven(suggestion || '', unknownCommand);
|
|
185
|
-
|
|
186
|
-
if (leven(cmd, unknownCommand) < 3 && isBestMatch) {
|
|
187
|
-
suggestion = cmd;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
if (suggestion) {
|
|
192
|
-
info$c(` ${chalk$3.red(`Did you mean ${chalk$3.yellow(suggestion)}?`)}`);
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
157
|
/**
|
|
196
158
|
* 判断变量是否是一个数组
|
|
197
159
|
* @param { unknown } obj 变量
|
|
198
160
|
* @returns { boolean } 是否是一个数组
|
|
199
161
|
*/
|
|
200
162
|
|
|
201
|
-
|
|
202
163
|
function isObject(obj) {
|
|
203
164
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
204
165
|
}
|
|
@@ -225,20 +186,20 @@ function downloadRepoForGit$1(url, dest, branch) {
|
|
|
225
186
|
const cwd = process.cwd();
|
|
226
187
|
return new Promise((resolve, reject) => {
|
|
227
188
|
// 如果目标目录不存在
|
|
228
|
-
if (fs$
|
|
229
|
-
shelljs$
|
|
189
|
+
if (fs$i.existsSync(dest)) {
|
|
190
|
+
shelljs$8.rm('-rf', path$g.join(dest));
|
|
230
191
|
}
|
|
231
192
|
|
|
232
|
-
shelljs$
|
|
233
|
-
shelljs$
|
|
234
|
-
shelljs$
|
|
193
|
+
shelljs$8.mkdir('-p', dest);
|
|
194
|
+
shelljs$8.cd(dest);
|
|
195
|
+
shelljs$8.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
|
|
235
196
|
silent: true
|
|
236
197
|
}, (code, stdout, stderr) => {
|
|
237
198
|
if (code !== 0) {
|
|
238
199
|
reject(stderr);
|
|
239
200
|
}
|
|
240
201
|
|
|
241
|
-
shelljs$
|
|
202
|
+
shelljs$8.cd(cwd);
|
|
242
203
|
resolve();
|
|
243
204
|
});
|
|
244
205
|
});
|
|
@@ -254,30 +215,32 @@ function downloadRepoForGit$1(url, dest, branch) {
|
|
|
254
215
|
function pullRepoForGit$1(dest, branch) {
|
|
255
216
|
const cwd = process.cwd();
|
|
256
217
|
return new Promise((resolve, reject) => {
|
|
257
|
-
shelljs$
|
|
258
|
-
shelljs$
|
|
259
|
-
shelljs$
|
|
218
|
+
shelljs$8.cd(dest);
|
|
219
|
+
shelljs$8.exec('git config pull.rebase false', shelljsOptions);
|
|
220
|
+
shelljs$8.exec(`git pull origin ${branch}`, {
|
|
260
221
|
silent: true
|
|
261
222
|
}, (code, stdout, stderr) => {
|
|
262
223
|
if (code !== 0) {
|
|
263
224
|
reject(stderr);
|
|
264
225
|
}
|
|
265
226
|
|
|
266
|
-
shelljs$
|
|
227
|
+
shelljs$8.cd(cwd);
|
|
267
228
|
resolve();
|
|
268
229
|
});
|
|
269
230
|
});
|
|
270
231
|
}
|
|
271
232
|
/**
|
|
272
233
|
* npm 下载依赖
|
|
273
|
-
* @param {
|
|
234
|
+
* @param {string} dir 下载npm的目录
|
|
235
|
+
* @param {object} npm npm的配置 (见下获取npm源入参)
|
|
274
236
|
* @returns
|
|
275
237
|
*/
|
|
276
238
|
|
|
277
239
|
|
|
278
|
-
function npmInstall$2(dir) {
|
|
240
|
+
function npmInstall$2(dir, npmConfig) {
|
|
279
241
|
return new Promise((resolve, reject) => {
|
|
280
|
-
|
|
242
|
+
const registry = getNpmRegistry(npmConfig);
|
|
243
|
+
shelljs$8.exec(`npm install --production ${registry}`, {
|
|
281
244
|
cwd: dir,
|
|
282
245
|
silent: true
|
|
283
246
|
}, (code, stdout, stderr) => {
|
|
@@ -288,6 +251,30 @@ function npmInstall$2(dir) {
|
|
|
288
251
|
resolve();
|
|
289
252
|
});
|
|
290
253
|
});
|
|
254
|
+
} // 获取npm源
|
|
255
|
+
// 入参:{
|
|
256
|
+
// registry: "https://registry.npmjs.org/",
|
|
257
|
+
// scope: {
|
|
258
|
+
// "@tencent": "http://mirrors.tencent.com/npm/"
|
|
259
|
+
// }
|
|
260
|
+
// }
|
|
261
|
+
// 出参: --@tencent:registry=http://mirrors.tencent.com/npm/ --registry=https://registry.npmjs.org/
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
function getNpmRegistry(npmConfig = {}) {
|
|
265
|
+
let resRegistry = '';
|
|
266
|
+
|
|
267
|
+
if (npmConfig.registry) {
|
|
268
|
+
resRegistry = ` --registry=${npmConfig.registry}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (isObject(npmConfig.scope)) {
|
|
272
|
+
Object.keys(npmConfig.scope).forEach(key => {
|
|
273
|
+
resRegistry += ` --${key}:registry=${npmConfig.scope[key]}`;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return resRegistry;
|
|
291
278
|
}
|
|
292
279
|
/**
|
|
293
280
|
* 计算各项任务耗时
|
|
@@ -306,11 +293,11 @@ const cost = start => Date.now() - start;
|
|
|
306
293
|
*/
|
|
307
294
|
|
|
308
295
|
|
|
309
|
-
function createTask$
|
|
296
|
+
function createTask$5(task, startText, endText) {
|
|
310
297
|
return async (...args) => {
|
|
311
298
|
const start = Date.now();
|
|
312
299
|
const spinner = ora$1();
|
|
313
|
-
info$
|
|
300
|
+
info$f(startText);
|
|
314
301
|
spinner.start();
|
|
315
302
|
const result = await task(...args);
|
|
316
303
|
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
@@ -328,18 +315,14 @@ const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : ''
|
|
|
328
315
|
|
|
329
316
|
const mergeMap$1 = function (obj, src) {
|
|
330
317
|
for (const [k, v] of src) {
|
|
331
|
-
|
|
332
|
-
obj.set(k, obj.get(k) + v);
|
|
333
|
-
} else {
|
|
334
|
-
obj.set(k, v);
|
|
335
|
-
}
|
|
318
|
+
obj.set(k, v);
|
|
336
319
|
}
|
|
337
320
|
|
|
338
321
|
return obj;
|
|
339
322
|
};
|
|
340
323
|
|
|
341
324
|
const relativeCwdPath$1 = function (file) {
|
|
342
|
-
return path$
|
|
325
|
+
return path$g.relative(process.cwd(), file);
|
|
343
326
|
};
|
|
344
327
|
/**
|
|
345
328
|
* 从一个对象中,检索出去几个字段
|
|
@@ -349,7 +332,7 @@ const relativeCwdPath$1 = function (file) {
|
|
|
349
332
|
*/
|
|
350
333
|
|
|
351
334
|
|
|
352
|
-
const filterField$
|
|
335
|
+
const filterField$7 = (obj, filterNames = []) => {
|
|
353
336
|
const newObj = { ...obj
|
|
354
337
|
};
|
|
355
338
|
filterNames.forEach(name => {
|
|
@@ -363,7 +346,7 @@ const filterField$4 = (obj, filterNames = []) => {
|
|
|
363
346
|
|
|
364
347
|
function findFiles(globPath, filter = []) {
|
|
365
348
|
return new Promise((resolve, reject) => {
|
|
366
|
-
glob
|
|
349
|
+
glob(globPath, filter, (err, files) => {
|
|
367
350
|
if (err) {
|
|
368
351
|
reject(err);
|
|
369
352
|
}
|
|
@@ -374,48 +357,85 @@ function findFiles(globPath, filter = []) {
|
|
|
374
357
|
} // 获取绝对路径
|
|
375
358
|
|
|
376
359
|
|
|
377
|
-
function getAbsolutePath$
|
|
360
|
+
function getAbsolutePath$5(pathDir, cwd = '') {
|
|
378
361
|
let newPath = pathDir;
|
|
379
362
|
newPath = newPath.startsWith('/') ? newPath : resolve$g(cwd, newPath);
|
|
380
363
|
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
381
364
|
return newPath;
|
|
365
|
+
} // 版本比较 => 1(大于), 0(等于), -1(小于)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
function versionCompare$1(v1, v2) {
|
|
369
|
+
// 将两个版本号拆成数组
|
|
370
|
+
const arr1 = v1.split('.');
|
|
371
|
+
const arr2 = v2.split('.');
|
|
372
|
+
const minLength = Math.min(arr1.length, arr2.length); // 依次比较版本号每一位大小
|
|
373
|
+
|
|
374
|
+
for (let i = 0; i < minLength; i++) {
|
|
375
|
+
if (parseInt(arr1[i], 10) !== parseInt(arr2[i], 10)) {
|
|
376
|
+
return parseInt(arr1[i], 10) > parseInt(arr2[i], 10) ? 1 : -1;
|
|
377
|
+
}
|
|
378
|
+
} // 若前几位分隔相同,则按分隔数比较。
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
if (arr1.length === arr2.length) {
|
|
382
|
+
return 0;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return arr1.length > arr2.length ? 1 : -1;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function getGitUser$2() {
|
|
389
|
+
const res = shelljs$8.exec('git config user.name', {
|
|
390
|
+
async: false,
|
|
391
|
+
silent: true
|
|
392
|
+
});
|
|
393
|
+
return res.stdout;
|
|
382
394
|
}
|
|
383
395
|
|
|
384
396
|
var widgets = {
|
|
385
397
|
resolve: resolve$g,
|
|
386
398
|
isObject,
|
|
387
399
|
isArray,
|
|
388
|
-
createTask: createTask$
|
|
400
|
+
createTask: createTask$5,
|
|
389
401
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
390
402
|
pullRepoForGit: pullRepoForGit$1,
|
|
391
|
-
suggestCommands: suggestCommands$1,
|
|
392
403
|
camelize,
|
|
393
404
|
npmInstall: npmInstall$2,
|
|
394
405
|
mergeMap: mergeMap$1,
|
|
395
406
|
relativeCwdPath: relativeCwdPath$1,
|
|
396
|
-
filterField: filterField$
|
|
407
|
+
filterField: filterField$7,
|
|
397
408
|
findFiles,
|
|
398
|
-
getAbsolutePath: getAbsolutePath$
|
|
409
|
+
getAbsolutePath: getAbsolutePath$5,
|
|
410
|
+
getNpmRegistry,
|
|
411
|
+
versionCompare: versionCompare$1,
|
|
412
|
+
getGitUser: getGitUser$2
|
|
399
413
|
};
|
|
400
414
|
|
|
401
415
|
var tmsMpconfig = {exports: {}};
|
|
402
416
|
|
|
403
|
-
const path$
|
|
417
|
+
const path$f = require$$1__default$1;
|
|
418
|
+
const os = require$$1__default$2; // 用户目录
|
|
404
419
|
|
|
405
|
-
const
|
|
420
|
+
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
406
421
|
|
|
422
|
+
const CACHE_DIR = path$f.resolve(HOME_DIR, '.tmskit'); // 版本管理的CDN地址
|
|
407
423
|
|
|
408
|
-
const
|
|
424
|
+
const VERSION_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json'; // version缓存文件
|
|
409
425
|
|
|
410
|
-
const
|
|
426
|
+
const VERSION_CACHE_FILE$1 = path$f.resolve(CACHE_DIR, 'version_cache_file.json'); // npm缓存文件
|
|
411
427
|
|
|
412
|
-
const
|
|
428
|
+
const NPM_CACHE_FILE$1 = path$f.resolve(CACHE_DIR, 'npm_cache_file.json'); // 脚手架模板代码所在目录
|
|
413
429
|
|
|
414
|
-
const TEMPLATE_DIR$1 = path$
|
|
430
|
+
const TEMPLATE_DIR$1 = path$f.resolve(CACHE_DIR, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
415
431
|
|
|
416
|
-
const
|
|
432
|
+
const MODULE_CODE_DIR$2 = path$f.resolve(CACHE_DIR, 'modules_code'); // 缓存分包node_modules的目录
|
|
417
433
|
|
|
418
|
-
const
|
|
434
|
+
const NODE_MODULES_DIR$2 = path$f.resolve(CACHE_DIR, 'node_modules'); // 扩展命令源码的存放处
|
|
435
|
+
|
|
436
|
+
const EXTEND_CMD$1 = path$f.resolve(CACHE_DIR, 'cmd'); // 创建模板的名称
|
|
437
|
+
|
|
438
|
+
const TEMPLATE_NAME$1 = 'tmskit-template'; // 脚手架模板的远程地址
|
|
419
439
|
|
|
420
440
|
const TEMPLATE_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip'; // 脚手架的名称
|
|
421
441
|
|
|
@@ -431,10 +451,10 @@ const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
|
431
451
|
const MODULE_CONFIG_FILENAME = 'module.config.json'; // 默认的webpack entry
|
|
432
452
|
|
|
433
453
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
434
|
-
app: path$
|
|
454
|
+
app: path$f.resolve(process.cwd(), 'app')
|
|
435
455
|
}; // 默认从源码拷贝到编译后的配置
|
|
436
456
|
|
|
437
|
-
const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json'];
|
|
457
|
+
const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json', 'project.config.json'];
|
|
438
458
|
const ENV = {
|
|
439
459
|
dev: 'development',
|
|
440
460
|
prod: 'production'
|
|
@@ -450,32 +470,38 @@ const CREATE_TEMPLATE_QUESTION$1 = [{
|
|
|
450
470
|
}, {
|
|
451
471
|
name: '小程序模块',
|
|
452
472
|
value: 'mp-module'
|
|
473
|
+
}, {
|
|
474
|
+
name: '构建工具扩展命令',
|
|
475
|
+
value: 'cmd'
|
|
476
|
+
}, {
|
|
477
|
+
name: '构建工具编译插件',
|
|
478
|
+
value: 'plugin'
|
|
453
479
|
}]
|
|
454
480
|
}];
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
481
|
+
var constant = {
|
|
482
|
+
HOME_DIR,
|
|
483
|
+
CACHE_DIR,
|
|
484
|
+
NPM_CACHE_FILE: NPM_CACHE_FILE$1,
|
|
485
|
+
VERSION_CACHE_FILE: VERSION_CACHE_FILE$1,
|
|
486
|
+
TEMPLATE_DIR: TEMPLATE_DIR$1,
|
|
487
|
+
TEMPLATE_NAME: TEMPLATE_NAME$1,
|
|
488
|
+
TMS_NAME: TMS_NAME$1,
|
|
489
|
+
TMS_CONFIG_FILENAME,
|
|
490
|
+
TMS_PRIVATE_FILENAME,
|
|
491
|
+
DEFAULT_MODULE_DIR,
|
|
492
|
+
MODULE_CONFIG_FILENAME,
|
|
493
|
+
EXTEND_CMD: EXTEND_CMD$1,
|
|
494
|
+
DEFAULT_WEBPACK_ENTRY,
|
|
495
|
+
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
|
|
496
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$2,
|
|
497
|
+
NODE_MODULES_DIR: NODE_MODULES_DIR$2,
|
|
498
|
+
ENV,
|
|
499
|
+
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
500
|
+
DEFAULT_CLOUD_MODULE_DIR,
|
|
501
|
+
CREATE_TEMPLATE_QUESTION: CREATE_TEMPLATE_QUESTION$1,
|
|
502
|
+
TEMPLATE_URL: TEMPLATE_URL$1,
|
|
503
|
+
VERSION_URL: VERSION_URL$1
|
|
504
|
+
};
|
|
479
505
|
|
|
480
506
|
var defaultTmsConfig = {
|
|
481
507
|
// 全局的环境配置项
|
|
@@ -493,7 +519,33 @@ var defaultTmsConfig = {
|
|
|
493
519
|
sourceDir: './',
|
|
494
520
|
|
|
495
521
|
/** 静态资源目录 */
|
|
496
|
-
static: []
|
|
522
|
+
static: [],
|
|
523
|
+
|
|
524
|
+
/** 上传是的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E7%BC%96%E8%AF%91%E8%AE%BE%E7%BD%AE */
|
|
525
|
+
upload: {
|
|
526
|
+
setting: {
|
|
527
|
+
es6: true,
|
|
528
|
+
es7: true,
|
|
529
|
+
minify: true,
|
|
530
|
+
minifyJS: true,
|
|
531
|
+
minifyWXML: true,
|
|
532
|
+
minifyWXSS: true,
|
|
533
|
+
autoPrefixWXSS: true
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
|
|
537
|
+
/** 预览的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88 */
|
|
538
|
+
preview: {
|
|
539
|
+
setting: {
|
|
540
|
+
es6: true,
|
|
541
|
+
es7: true,
|
|
542
|
+
minify: true,
|
|
543
|
+
minifyJS: true,
|
|
544
|
+
minifyWXML: true,
|
|
545
|
+
minifyWXSS: true,
|
|
546
|
+
autoPrefixWXSS: true
|
|
547
|
+
}
|
|
548
|
+
}
|
|
497
549
|
};
|
|
498
550
|
|
|
499
551
|
/**
|
|
@@ -502,14 +554,14 @@ var defaultTmsConfig = {
|
|
|
502
554
|
|
|
503
555
|
(function (module) {
|
|
504
556
|
/* eslint-disable no-param-reassign, no-nested-ternary */
|
|
505
|
-
const loadash = require$$0__default$
|
|
506
|
-
const fs = require$$0__default$
|
|
507
|
-
const path = require$$1__default$
|
|
557
|
+
const loadash = require$$0__default$2;
|
|
558
|
+
const fs = require$$0__default$1;
|
|
559
|
+
const path = require$$1__default$1;
|
|
508
560
|
const {
|
|
509
561
|
TMS_CONFIG_FILENAME,
|
|
510
562
|
MODULE_CONFIG_FILENAME,
|
|
511
563
|
TMS_PRIVATE_FILENAME
|
|
512
|
-
} =
|
|
564
|
+
} = constant;
|
|
513
565
|
const {
|
|
514
566
|
resolve,
|
|
515
567
|
isObject,
|
|
@@ -522,14 +574,14 @@ var defaultTmsConfig = {
|
|
|
522
574
|
} = log$1;
|
|
523
575
|
/**
|
|
524
576
|
* 读取tms.config.js
|
|
525
|
-
*
|
|
577
|
+
* @param {string} configPath tms.config.js的路径
|
|
526
578
|
*/
|
|
527
579
|
|
|
528
|
-
const readTmsConfig = function () {
|
|
529
|
-
const tmsConfigPath = resolve(TMS_CONFIG_FILENAME);
|
|
580
|
+
const readTmsConfig = function (configPath) {
|
|
581
|
+
const tmsConfigPath = configPath ? `${configPath}/${TMS_CONFIG_FILENAME}` : resolve(TMS_CONFIG_FILENAME);
|
|
530
582
|
|
|
531
583
|
if (!fs.existsSync(tmsConfigPath)) {
|
|
532
|
-
fail(
|
|
584
|
+
fail(`${path.dirname(tmsConfigPath)}没有找到tms.config.js,请进行配置`);
|
|
533
585
|
process.exit(1);
|
|
534
586
|
}
|
|
535
587
|
|
|
@@ -537,16 +589,17 @@ var defaultTmsConfig = {
|
|
|
537
589
|
|
|
538
590
|
const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn() : tmsConfigFn; // 合并默认值
|
|
539
591
|
|
|
540
|
-
return loadash.mergeWith(defaultTmsConfig$1, tmsConfig);
|
|
592
|
+
return loadash.mergeWith({}, defaultTmsConfig$1, tmsConfig);
|
|
541
593
|
};
|
|
542
594
|
/**
|
|
543
595
|
* 读取tms.private.config.js
|
|
596
|
+
* @param {string} configPath tms.private.config.js的路径
|
|
544
597
|
*/
|
|
545
598
|
|
|
546
599
|
|
|
547
|
-
const readTmsPrivateCf = function () {
|
|
600
|
+
const readTmsPrivateCf = function (configPath) {
|
|
548
601
|
let tmsPrivateCf = {};
|
|
549
|
-
const tmsPrivatePath = resolve(TMS_PRIVATE_FILENAME);
|
|
602
|
+
const tmsPrivatePath = configPath ? `${configPath}/${TMS_PRIVATE_FILENAME}` : resolve(TMS_PRIVATE_FILENAME);
|
|
550
603
|
|
|
551
604
|
if (fs.existsSync(tmsPrivatePath)) {
|
|
552
605
|
const tmsPrivateFn = require(tmsPrivatePath);
|
|
@@ -558,13 +611,14 @@ var defaultTmsConfig = {
|
|
|
558
611
|
};
|
|
559
612
|
/**
|
|
560
613
|
* 获取tms.config.js, tms.private.config.js的配置项
|
|
614
|
+
* @param {string} configPath config.js的路径
|
|
561
615
|
* @returns
|
|
562
616
|
*/
|
|
563
617
|
|
|
564
618
|
|
|
565
|
-
const getTmsConfig =
|
|
566
|
-
const tmsPrivateCf = readTmsPrivateCf();
|
|
567
|
-
const tmsConfig = readTmsConfig();
|
|
619
|
+
const getTmsConfig = configPath => {
|
|
620
|
+
const tmsPrivateCf = readTmsPrivateCf(configPath);
|
|
621
|
+
const tmsConfig = readTmsConfig(configPath);
|
|
568
622
|
const modules = {};
|
|
569
623
|
|
|
570
624
|
if (Array.isArray(tmsConfig.modules)) {
|
|
@@ -640,18 +694,10 @@ var defaultTmsConfig = {
|
|
|
640
694
|
return content;
|
|
641
695
|
}
|
|
642
696
|
|
|
643
|
-
const adaptDependencies = function (dependencies, subPackages) {
|
|
644
|
-
const newDependencies = dependencies || [];
|
|
645
|
-
subPackages.forEach(item => {
|
|
646
|
-
if (item.dependencies) {
|
|
647
|
-
dependencies = newDependencies.concat(item.dependencies);
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
return newDependencies;
|
|
651
|
-
};
|
|
652
|
-
|
|
653
697
|
const adaptSubPackages = function (moduleConfig, appName) {
|
|
654
|
-
const
|
|
698
|
+
const {
|
|
699
|
+
subPackages
|
|
700
|
+
} = moduleConfig;
|
|
655
701
|
return adaptMpCgContent(subPackages, appName);
|
|
656
702
|
};
|
|
657
703
|
/**
|
|
@@ -675,10 +721,8 @@ var defaultTmsConfig = {
|
|
|
675
721
|
|
|
676
722
|
|
|
677
723
|
const subPackages = adaptSubPackages(moduleConfig, appName);
|
|
678
|
-
const dependencies = adaptDependencies(moduleConfig.dependencies, subPackages);
|
|
679
724
|
moduleConfig = { ...(isObject(moduleConfig) ? moduleConfig : {}),
|
|
680
|
-
subPackages
|
|
681
|
-
dependencies
|
|
725
|
+
subPackages
|
|
682
726
|
}; // 兼容逻辑--- end
|
|
683
727
|
|
|
684
728
|
modulesConfig.push(moduleConfig);
|
|
@@ -728,10 +772,7 @@ var defaultTmsConfig = {
|
|
|
728
772
|
const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
|
|
729
773
|
const newModuleItem = { ...tmsModuleItem,
|
|
730
774
|
...moduleConfig
|
|
731
|
-
}; //
|
|
732
|
-
|
|
733
|
-
if (!newModuleItem.moduleName) newModuleItem.moduleName = newModuleItem.name;
|
|
734
|
-
delete newModuleItem.name; // 参数校验-模块源码路径
|
|
775
|
+
}; // 参数校验-模块源码路径
|
|
735
776
|
|
|
736
777
|
if (!newModuleItem.path) {
|
|
737
778
|
throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
|
|
@@ -774,6 +815,10 @@ var defaultTmsConfig = {
|
|
|
774
815
|
|
|
775
816
|
function dfs(tmsConfig, modules) {
|
|
776
817
|
modules.forEach(moduleItem => {
|
|
818
|
+
if (!moduleItem.path) {
|
|
819
|
+
throw new Error(`${moduleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
|
|
820
|
+
}
|
|
821
|
+
|
|
777
822
|
const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
|
|
778
823
|
|
|
779
824
|
if (!fs.existsSync(moduleConfigPath)) {
|
|
@@ -822,10 +867,10 @@ var defaultTmsConfig = {
|
|
|
822
867
|
};
|
|
823
868
|
})(tmsMpconfig);
|
|
824
869
|
|
|
825
|
-
const fs$
|
|
826
|
-
const path$
|
|
870
|
+
const fs$h = require$$0__default$1;
|
|
871
|
+
const path$e = require$$1__default$1;
|
|
827
872
|
const {
|
|
828
|
-
info: info$
|
|
873
|
+
info: info$e
|
|
829
874
|
} = log$1;
|
|
830
875
|
const {
|
|
831
876
|
relativeCwdPath
|
|
@@ -836,12 +881,12 @@ const {
|
|
|
836
881
|
* @returns
|
|
837
882
|
*/
|
|
838
883
|
|
|
839
|
-
const isDirEmpty = dirname => fs$
|
|
884
|
+
const isDirEmpty = dirname => fs$h.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
840
885
|
|
|
841
886
|
|
|
842
887
|
const isFile = pathName => {
|
|
843
888
|
try {
|
|
844
|
-
const stat = fs$
|
|
889
|
+
const stat = fs$h.lstatSync(pathName);
|
|
845
890
|
return stat.isFile();
|
|
846
891
|
} catch {
|
|
847
892
|
return false;
|
|
@@ -853,9 +898,9 @@ const isFile = pathName => {
|
|
|
853
898
|
*/
|
|
854
899
|
|
|
855
900
|
|
|
856
|
-
const ensureDirExist$
|
|
857
|
-
if (!fs$
|
|
858
|
-
fs$
|
|
901
|
+
const ensureDirExist$5 = dirname => {
|
|
902
|
+
if (!fs$h.existsSync(dirname)) {
|
|
903
|
+
fs$h.mkdirSync(dirname, {
|
|
859
904
|
recursive: true
|
|
860
905
|
});
|
|
861
906
|
}
|
|
@@ -863,38 +908,38 @@ const ensureDirExist$2 = dirname => {
|
|
|
863
908
|
|
|
864
909
|
|
|
865
910
|
const copyFile = function (src, dest) {
|
|
866
|
-
if (fs$
|
|
867
|
-
fs$
|
|
911
|
+
if (fs$h.existsSync(dest)) {
|
|
912
|
+
fs$h.unlinkSync(dest);
|
|
868
913
|
}
|
|
869
914
|
|
|
870
|
-
const dir = path$
|
|
871
|
-
ensureDirExist$
|
|
872
|
-
fs$
|
|
915
|
+
const dir = path$e.dirname(dest);
|
|
916
|
+
ensureDirExist$5(dir);
|
|
917
|
+
fs$h.copyFileSync(src, dest);
|
|
873
918
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
874
919
|
|
|
875
920
|
|
|
876
|
-
function diffContentCopyFile
|
|
877
|
-
if (fs$
|
|
878
|
-
const depDestContent = fs$
|
|
879
|
-
const depOriginContent = fs$
|
|
921
|
+
function diffContentCopyFile(originFile, destFile) {
|
|
922
|
+
if (fs$h.existsSync(destFile)) {
|
|
923
|
+
const depDestContent = fs$h.readFileSync(destFile, 'utf8');
|
|
924
|
+
const depOriginContent = fs$h.readFileSync(originFile, 'utf8');
|
|
880
925
|
|
|
881
926
|
if (depDestContent !== depOriginContent) {
|
|
882
|
-
info$
|
|
927
|
+
info$e(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
883
928
|
copyFile(originFile, destFile);
|
|
884
929
|
}
|
|
885
930
|
} else {
|
|
886
|
-
info$
|
|
931
|
+
info$e(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
887
932
|
copyFile(originFile, destFile);
|
|
888
933
|
}
|
|
889
934
|
} // 添加后缀
|
|
890
935
|
|
|
891
936
|
|
|
892
|
-
function ext
|
|
937
|
+
function ext(filePath, extensions) {
|
|
893
938
|
let newFilePath = filePath;
|
|
894
939
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
895
940
|
|
|
896
941
|
try {
|
|
897
|
-
const stat = fs$
|
|
942
|
+
const stat = fs$h.lstatSync(newFilePath);
|
|
898
943
|
|
|
899
944
|
if (stat.isDirectory()) {
|
|
900
945
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -905,7 +950,7 @@ function ext$3(filePath, extensions) {
|
|
|
905
950
|
for (const ext of extensions) {
|
|
906
951
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
907
952
|
|
|
908
|
-
if (fs$
|
|
953
|
+
if (fs$h.existsSync(file)) {
|
|
909
954
|
return {
|
|
910
955
|
ext,
|
|
911
956
|
extPath: extPath + ext,
|
|
@@ -922,12 +967,12 @@ function ext$3(filePath, extensions) {
|
|
|
922
967
|
} // 判断文件是否在某个目录
|
|
923
968
|
|
|
924
969
|
|
|
925
|
-
const fileInDir
|
|
926
|
-
if (!fs$
|
|
970
|
+
const fileInDir = (dir, file) => {
|
|
971
|
+
if (!fs$h.existsSync(dir) || !fs$h.existsSync(file)) {
|
|
927
972
|
return false;
|
|
928
973
|
}
|
|
929
974
|
|
|
930
|
-
const relativePath = path$
|
|
975
|
+
const relativePath = path$e.relative(dir, file);
|
|
931
976
|
|
|
932
977
|
if (relativePath.startsWith('..')) {
|
|
933
978
|
return false;
|
|
@@ -936,14 +981,14 @@ const fileInDir$3 = (dir, file) => {
|
|
|
936
981
|
return true;
|
|
937
982
|
};
|
|
938
983
|
|
|
939
|
-
function findAllFilesOfDir
|
|
984
|
+
function findAllFilesOfDir(dir) {
|
|
940
985
|
const list = [];
|
|
941
986
|
|
|
942
987
|
function listFile(dir) {
|
|
943
|
-
const arr = fs$
|
|
988
|
+
const arr = fs$h.readdirSync(dir);
|
|
944
989
|
arr.forEach(item => {
|
|
945
|
-
const fullPath = path$
|
|
946
|
-
const stats = fs$
|
|
990
|
+
const fullPath = path$e.join(dir, item);
|
|
991
|
+
const stats = fs$h.statSync(fullPath);
|
|
947
992
|
|
|
948
993
|
if (stats.isDirectory()) {
|
|
949
994
|
listFile(fullPath);
|
|
@@ -961,15 +1006,15 @@ function findAllFilesOfDir$1(dir) {
|
|
|
961
1006
|
var io$3 = {
|
|
962
1007
|
isDirEmpty,
|
|
963
1008
|
copyFile,
|
|
964
|
-
diffContentCopyFile
|
|
965
|
-
ensureDirExist: ensureDirExist$
|
|
966
|
-
ext
|
|
967
|
-
fileInDir
|
|
1009
|
+
diffContentCopyFile,
|
|
1010
|
+
ensureDirExist: ensureDirExist$5,
|
|
1011
|
+
ext,
|
|
1012
|
+
fileInDir,
|
|
968
1013
|
isFile,
|
|
969
|
-
findAllFilesOfDir
|
|
1014
|
+
findAllFilesOfDir
|
|
970
1015
|
};
|
|
971
1016
|
|
|
972
|
-
const async = require$$0__default$
|
|
1017
|
+
const async = require$$0__default$3;
|
|
973
1018
|
const ejs = require$$1__default$3;
|
|
974
1019
|
|
|
975
1020
|
const render$1 = (files, metalsmith, next) => {
|
|
@@ -989,14 +1034,14 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
989
1034
|
|
|
990
1035
|
var render_1 = render$1;
|
|
991
1036
|
|
|
992
|
-
const fs$
|
|
993
|
-
const inquirer$
|
|
1037
|
+
const fs$g = require$$0__default$1;
|
|
1038
|
+
const inquirer$2 = require$$1__default$4;
|
|
994
1039
|
const {
|
|
995
1040
|
resolve: resolve$f
|
|
996
1041
|
} = widgets;
|
|
997
1042
|
const {
|
|
998
1043
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
999
|
-
} =
|
|
1044
|
+
} = constant;
|
|
1000
1045
|
/**
|
|
1001
1046
|
* 获取模板内的问题
|
|
1002
1047
|
* @param {string} dir questions.json所在的目录
|
|
@@ -1006,12 +1051,12 @@ const {
|
|
|
1006
1051
|
const parseTemplateQuestions = dir => {
|
|
1007
1052
|
let prompts = [];
|
|
1008
1053
|
|
|
1009
|
-
if (!fs$
|
|
1054
|
+
if (!fs$g.existsSync(`${dir}/questions.json`)) {
|
|
1010
1055
|
return prompts;
|
|
1011
1056
|
}
|
|
1012
1057
|
|
|
1013
1058
|
try {
|
|
1014
|
-
const json = JSON.parse(fs$
|
|
1059
|
+
const json = JSON.parse(fs$g.readFileSync(`${dir}/questions.json`));
|
|
1015
1060
|
|
|
1016
1061
|
if (Array.isArray(json) && json.length > 0) {
|
|
1017
1062
|
json.forEach((item, index) => {
|
|
@@ -1053,7 +1098,7 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
|
1053
1098
|
|
|
1054
1099
|
return true;
|
|
1055
1100
|
});
|
|
1056
|
-
inquirer$
|
|
1101
|
+
inquirer$2.prompt(filteredPrompts).then(res => {
|
|
1057
1102
|
for (const prompt of filteredPrompts) {
|
|
1058
1103
|
metadata[prompt.name] = res[prompt.name];
|
|
1059
1104
|
}
|
|
@@ -1069,7 +1114,7 @@ var ask_1 = ask$1;
|
|
|
1069
1114
|
const FILES_TO_IGNORE$1 = ['node_modules'];
|
|
1070
1115
|
var ignoreFiles = FILES_TO_IGNORE$1;
|
|
1071
1116
|
|
|
1072
|
-
const Metalsmith = require$$0__default$
|
|
1117
|
+
const Metalsmith = require$$0__default$4;
|
|
1073
1118
|
const render = render_1;
|
|
1074
1119
|
const ask = ask_1;
|
|
1075
1120
|
const FILES_TO_IGNORE = ignoreFiles;
|
|
@@ -1086,17 +1131,49 @@ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolv
|
|
|
1086
1131
|
|
|
1087
1132
|
var generator_1 = generator$1;
|
|
1088
1133
|
|
|
1089
|
-
const
|
|
1090
|
-
const
|
|
1091
|
-
|
|
1092
|
-
|
|
1134
|
+
const request$2 = require$$0__default$5;
|
|
1135
|
+
const {
|
|
1136
|
+
getGitUser: getGitUser$1
|
|
1137
|
+
} = widgets;
|
|
1138
|
+
const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
|
|
1139
|
+
|
|
1140
|
+
const report$a = (name, attrs = {}) => {
|
|
1141
|
+
try {
|
|
1142
|
+
const param = [];
|
|
1143
|
+
param[27] = name;
|
|
1144
|
+
param[28] = 'tmskit';
|
|
1145
|
+
param[29] = getGitUser$1();
|
|
1146
|
+
param[30] = JSON.stringify(attrs);
|
|
1147
|
+
|
|
1148
|
+
for (let i = 0; i < 40; i++) {
|
|
1149
|
+
if (!param[i]) param[i] = null;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
;
|
|
1153
|
+
request$2.post({
|
|
1154
|
+
url: apiUrl,
|
|
1155
|
+
json: {
|
|
1156
|
+
param
|
|
1157
|
+
}
|
|
1158
|
+
}, () => {}); // (error, response, body) => {
|
|
1159
|
+
// console.log('body:', body);
|
|
1160
|
+
// }
|
|
1161
|
+
} catch (e) {}
|
|
1162
|
+
};
|
|
1163
|
+
|
|
1164
|
+
var report_1 = report$a;
|
|
1165
|
+
|
|
1166
|
+
const path$d = require$$1__default$1;
|
|
1167
|
+
const fs$f = require$$0__default$1;
|
|
1168
|
+
const shelljs$7 = require$$2__default;
|
|
1169
|
+
const inquirer$1 = require$$1__default$4;
|
|
1093
1170
|
const {
|
|
1094
1171
|
TEMPLATE_DIR,
|
|
1095
1172
|
TEMPLATE_URL,
|
|
1096
1173
|
TEMPLATE_NAME,
|
|
1097
1174
|
TEMPLATE_TKIT_DIR,
|
|
1098
1175
|
CREATE_TEMPLATE_QUESTION
|
|
1099
|
-
} =
|
|
1176
|
+
} = constant;
|
|
1100
1177
|
const {
|
|
1101
1178
|
resolve: resolve$e
|
|
1102
1179
|
} = widgets;
|
|
@@ -1104,11 +1181,12 @@ const io$2 = io$3;
|
|
|
1104
1181
|
const {
|
|
1105
1182
|
fail: fail$8,
|
|
1106
1183
|
succeed: succeed$1,
|
|
1107
|
-
info: info$
|
|
1184
|
+
info: info$d
|
|
1108
1185
|
} = log$1;
|
|
1109
1186
|
const generator = generator_1;
|
|
1110
|
-
const request = require$$
|
|
1187
|
+
const request$1 = require$$0__default$5;
|
|
1111
1188
|
const unzip = require$$10__default;
|
|
1189
|
+
const report$9 = report_1;
|
|
1112
1190
|
/**
|
|
1113
1191
|
* 如果该目录下面存在文件,换个名字
|
|
1114
1192
|
* @param { string } targetDir 当前文件夹
|
|
@@ -1117,13 +1195,13 @@ const unzip = require$$10__default;
|
|
|
1117
1195
|
|
|
1118
1196
|
async function createProjectDir(targetDir) {
|
|
1119
1197
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
1120
|
-
if (fs$
|
|
1198
|
+
if (fs$f.existsSync(targetDir)) {
|
|
1121
1199
|
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
1122
1200
|
fail$8('该目录名已经存在,换个项目名字吧~');
|
|
1123
1201
|
process.exit(1);
|
|
1124
1202
|
}
|
|
1125
1203
|
} else {
|
|
1126
|
-
shelljs$
|
|
1204
|
+
shelljs$7.mkdir('-p', targetDir);
|
|
1127
1205
|
}
|
|
1128
1206
|
}
|
|
1129
1207
|
/**
|
|
@@ -1138,14 +1216,14 @@ async function createProjectDir(targetDir) {
|
|
|
1138
1216
|
function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
|
|
1139
1217
|
return new Promise((resolve, reject) => {
|
|
1140
1218
|
const localZipPath = `${templateDir}/${templateName}.zip`;
|
|
1141
|
-
const stream = fs$
|
|
1142
|
-
request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
|
|
1219
|
+
const stream = fs$f.createWriteStream(localZipPath);
|
|
1220
|
+
request$1(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
|
|
1143
1221
|
if (err) {
|
|
1144
1222
|
reject(err);
|
|
1145
1223
|
return;
|
|
1146
1224
|
}
|
|
1147
1225
|
|
|
1148
|
-
fs$
|
|
1226
|
+
fs$f.createReadStream(localZipPath).pipe(unzip.Extract({
|
|
1149
1227
|
path: templateDir
|
|
1150
1228
|
})).on('close', err => {
|
|
1151
1229
|
if (err) {
|
|
@@ -1167,55 +1245,149 @@ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
|
|
|
1167
1245
|
|
|
1168
1246
|
async function create(projectName) {
|
|
1169
1247
|
const cwd = process.cwd();
|
|
1170
|
-
const targetDir = path$
|
|
1248
|
+
const targetDir = path$d.resolve(cwd, projectName);
|
|
1171
1249
|
const {
|
|
1172
1250
|
projectType
|
|
1173
|
-
} = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
|
|
1251
|
+
} = await inquirer$1.prompt(CREATE_TEMPLATE_QUESTION);
|
|
1252
|
+
report$9('create-start', {
|
|
1253
|
+
projectType
|
|
1254
|
+
}); // 创建项目目录
|
|
1174
1255
|
|
|
1175
1256
|
await createProjectDir(targetDir); // 新创建缓存目录
|
|
1176
1257
|
|
|
1177
|
-
if (fs$
|
|
1178
|
-
shelljs$
|
|
1258
|
+
if (fs$f.existsSync(TEMPLATE_DIR)) {
|
|
1259
|
+
shelljs$7.rm('-rf', TEMPLATE_DIR);
|
|
1179
1260
|
}
|
|
1180
1261
|
|
|
1181
|
-
fs$
|
|
1262
|
+
fs$f.mkdirSync(TEMPLATE_DIR, {
|
|
1182
1263
|
recursive: true
|
|
1183
1264
|
}); // 下载和解压模板
|
|
1184
1265
|
|
|
1185
1266
|
await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
1186
1267
|
|
|
1187
|
-
generator(path$
|
|
1188
|
-
shelljs$
|
|
1268
|
+
generator(path$d.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
|
|
1269
|
+
shelljs$7.cd(projectName);
|
|
1189
1270
|
const hookFilePath = resolve$e(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
|
|
1190
1271
|
|
|
1191
|
-
if (fs$
|
|
1272
|
+
if (fs$f.existsSync(hookFilePath)) {
|
|
1192
1273
|
const hooks = require(hookFilePath);
|
|
1193
1274
|
|
|
1194
1275
|
if (hooks.afterCreate) {
|
|
1195
1276
|
hooks.afterCreate.forEach(item => {
|
|
1196
1277
|
if (typeof item === 'function') {
|
|
1197
|
-
item.call(null, shelljs$
|
|
1278
|
+
item.call(null, shelljs$7, {
|
|
1198
1279
|
projectName
|
|
1199
1280
|
});
|
|
1200
1281
|
} else {
|
|
1201
|
-
shelljs$
|
|
1282
|
+
shelljs$7.exec(item);
|
|
1202
1283
|
}
|
|
1203
1284
|
});
|
|
1204
1285
|
}
|
|
1205
1286
|
|
|
1206
|
-
shelljs$
|
|
1287
|
+
shelljs$7.rm('-rf', resolve$e(projectName, TEMPLATE_TKIT_DIR));
|
|
1207
1288
|
}
|
|
1208
1289
|
|
|
1290
|
+
report$9('create-success', {
|
|
1291
|
+
projectType
|
|
1292
|
+
});
|
|
1209
1293
|
succeed$1('项目创建完成.');
|
|
1210
1294
|
}).catch(err => {
|
|
1211
1295
|
fail$8(err.message);
|
|
1212
|
-
info$
|
|
1296
|
+
info$d('详细的错误信息:', err);
|
|
1213
1297
|
});
|
|
1214
1298
|
}
|
|
1215
1299
|
|
|
1216
1300
|
var create_1 = create;
|
|
1217
1301
|
|
|
1218
|
-
const
|
|
1302
|
+
const fs$e = require$$0__default$1;
|
|
1303
|
+
const path$c = require$$1__default$1;
|
|
1304
|
+
const shellJs$1 = require$$2__default;
|
|
1305
|
+
const {
|
|
1306
|
+
ensureDirExist: ensureDirExist$4
|
|
1307
|
+
} = io$3;
|
|
1308
|
+
const {
|
|
1309
|
+
EXTEND_CMD
|
|
1310
|
+
} = constant;
|
|
1311
|
+
const {
|
|
1312
|
+
createTask: createTask$4
|
|
1313
|
+
} = widgets;
|
|
1314
|
+
const {
|
|
1315
|
+
info: info$c,
|
|
1316
|
+
fail: fail$7
|
|
1317
|
+
} = log$1;
|
|
1318
|
+
/**
|
|
1319
|
+
* 下载扩展命令的npm包
|
|
1320
|
+
* @param {string} npmName npm包名
|
|
1321
|
+
* @param {object} cmd {registry: 'http://mirrors.tencent.com/npm/'} 用户输入执行install-cmd的参数
|
|
1322
|
+
*/
|
|
1323
|
+
|
|
1324
|
+
async function installCmd(npmName, cmd) {
|
|
1325
|
+
try {
|
|
1326
|
+
const cmdPackageJson = `${EXTEND_CMD}/package.json`;
|
|
1327
|
+
|
|
1328
|
+
if (!fs$e.existsSync(cmdPackageJson)) {
|
|
1329
|
+
ensureDirExist$4(EXTEND_CMD);
|
|
1330
|
+
fs$e.writeFileSync(cmdPackageJson, JSON.stringify({
|
|
1331
|
+
dependencies: {}
|
|
1332
|
+
}, null, 2));
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
shellJs$1.cd(EXTEND_CMD);
|
|
1336
|
+
await createTask$4(npmName => new Promise((resolve, reject) => {
|
|
1337
|
+
const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
|
|
1338
|
+
shellJs$1.exec(`npm install --save ${npmName} ${registry}`, {
|
|
1339
|
+
cwd: EXTEND_CMD,
|
|
1340
|
+
silent: true
|
|
1341
|
+
}, (code, stdout, stderr) => {
|
|
1342
|
+
if (code !== 0) {
|
|
1343
|
+
reject(stderr);
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
resolve();
|
|
1347
|
+
});
|
|
1348
|
+
}), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
|
|
1349
|
+
} catch (e) {
|
|
1350
|
+
fail$7('构建出现错误:');
|
|
1351
|
+
info$c(e);
|
|
1352
|
+
process.exit(1);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* 加载扩展命令的npm包
|
|
1357
|
+
* @returns
|
|
1358
|
+
*/
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
function loadExtendCmd$1() {
|
|
1362
|
+
const cmdPackageJson = `${EXTEND_CMD}/package.json`;
|
|
1363
|
+
const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
|
|
1364
|
+
|
|
1365
|
+
if (fs$e.existsSync(cmdPackageJson)) {
|
|
1366
|
+
const content = fs$e.readFileSync(cmdPackageJson, 'utf8');
|
|
1367
|
+
const json = JSON.parse(content);
|
|
1368
|
+
const deps = json.dependencies || {};
|
|
1369
|
+
const cmdConfigs = [];
|
|
1370
|
+
Object.keys(deps).forEach(name => {
|
|
1371
|
+
// 检索cmd的npm包
|
|
1372
|
+
if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
|
|
1373
|
+
const cmdConfig = path$c.join(cmdNpmDir, name, 'tms.config.js');
|
|
1374
|
+
|
|
1375
|
+
if (fs$e.existsSync(cmdConfig)) {
|
|
1376
|
+
cmdConfigs.push(cmdConfig);
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
return cmdConfigs;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
return [];
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
var extendCmd = {
|
|
1386
|
+
installCmd,
|
|
1387
|
+
loadExtendCmd: loadExtendCmd$1
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
const global$b = {
|
|
1219
1391
|
data: {},
|
|
1220
1392
|
|
|
1221
1393
|
setData(...args) {
|
|
@@ -1237,36 +1409,36 @@ const global$6 = {
|
|
|
1237
1409
|
|
|
1238
1410
|
};
|
|
1239
1411
|
var global_1 = {
|
|
1240
|
-
global: global$
|
|
1412
|
+
global: global$b
|
|
1241
1413
|
};
|
|
1242
1414
|
|
|
1243
1415
|
const {
|
|
1244
|
-
fail: fail$
|
|
1416
|
+
fail: fail$6
|
|
1245
1417
|
} = log$1;
|
|
1246
1418
|
const {
|
|
1247
|
-
global: global$
|
|
1419
|
+
global: global$a
|
|
1248
1420
|
} = global_1;
|
|
1249
1421
|
|
|
1250
|
-
function handleError$
|
|
1422
|
+
function handleError$7(error, isQuit = false) {
|
|
1251
1423
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1252
1424
|
|
|
1253
1425
|
if (isQuit) {
|
|
1254
|
-
fail$
|
|
1426
|
+
fail$6(errMsg);
|
|
1255
1427
|
process.exit(1);
|
|
1256
1428
|
}
|
|
1257
1429
|
|
|
1258
|
-
const isDev = global$
|
|
1430
|
+
const isDev = global$a.getData('isDev');
|
|
1259
1431
|
|
|
1260
1432
|
if (isDev) {
|
|
1261
|
-
fail$
|
|
1433
|
+
fail$6(errMsg);
|
|
1262
1434
|
} else {
|
|
1263
|
-
fail$
|
|
1435
|
+
fail$6(errMsg);
|
|
1264
1436
|
process.exit(1);
|
|
1265
1437
|
}
|
|
1266
1438
|
}
|
|
1267
1439
|
|
|
1268
1440
|
var handleError_1 = {
|
|
1269
|
-
handleError: handleError$
|
|
1441
|
+
handleError: handleError$7
|
|
1270
1442
|
};
|
|
1271
1443
|
|
|
1272
1444
|
/**
|
|
@@ -1274,25 +1446,26 @@ var handleError_1 = {
|
|
|
1274
1446
|
*/
|
|
1275
1447
|
/* eslint-disable no-param-reassign */
|
|
1276
1448
|
|
|
1277
|
-
const fs$d = require$$0__default$
|
|
1449
|
+
const fs$d = require$$0__default$1;
|
|
1278
1450
|
const {
|
|
1279
1451
|
getSubPackages: getSubPackages$3,
|
|
1280
1452
|
getModulesConfig
|
|
1281
1453
|
} = tmsMpconfig.exports;
|
|
1282
1454
|
const {
|
|
1283
|
-
fail: fail$
|
|
1284
|
-
info: info$
|
|
1455
|
+
fail: fail$5,
|
|
1456
|
+
info: info$b
|
|
1285
1457
|
} = log$1;
|
|
1286
1458
|
const {
|
|
1287
1459
|
resolve: resolve$d,
|
|
1288
|
-
filterField: filterField$
|
|
1460
|
+
filterField: filterField$6
|
|
1289
1461
|
} = widgets;
|
|
1290
1462
|
const {
|
|
1291
|
-
handleError: handleError$
|
|
1463
|
+
handleError: handleError$6
|
|
1292
1464
|
} = handleError_1;
|
|
1293
1465
|
const {
|
|
1294
|
-
global: global$
|
|
1466
|
+
global: global$9
|
|
1295
1467
|
} = global_1;
|
|
1468
|
+
const report$8 = report_1;
|
|
1296
1469
|
/**
|
|
1297
1470
|
* 更新appJson里面的主包配置
|
|
1298
1471
|
* @param { object } appJson appJson信息
|
|
@@ -1311,7 +1484,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1311
1484
|
|
|
1312
1485
|
foundMainPackages.forEach(subpackage => {
|
|
1313
1486
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
1314
|
-
fail$
|
|
1487
|
+
fail$5(`主包 ${subpackage} 不能没有 pages`);
|
|
1315
1488
|
process.exit(-1);
|
|
1316
1489
|
}
|
|
1317
1490
|
|
|
@@ -1337,7 +1510,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1337
1510
|
|
|
1338
1511
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
1339
1512
|
if (!fs$d.existsSync(sourceAppJsonPath)) {
|
|
1340
|
-
fail$
|
|
1513
|
+
fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1341
1514
|
process.exit(1);
|
|
1342
1515
|
}
|
|
1343
1516
|
|
|
@@ -1386,7 +1559,7 @@ const fixAppJson = appJson => {
|
|
|
1386
1559
|
appJson[key] = preloadRuleMap;
|
|
1387
1560
|
}
|
|
1388
1561
|
});
|
|
1389
|
-
return filterField$
|
|
1562
|
+
return filterField$6(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
|
|
1390
1563
|
}); // 如果plugins重复,则错误提示
|
|
1391
1564
|
|
|
1392
1565
|
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
@@ -1434,17 +1607,19 @@ function buildOutputAppJson$2(tmsConfig, modules) {
|
|
|
1434
1607
|
var _tmsConfig$hooks2;
|
|
1435
1608
|
|
|
1436
1609
|
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1437
|
-
tmsConfig: filterField$
|
|
1610
|
+
tmsConfig: filterField$6(tmsConfig, ['gitAccount']),
|
|
1611
|
+
cmdOptions: global$9.getData('cmdOptions'),
|
|
1438
1612
|
modules,
|
|
1439
1613
|
appJson,
|
|
1440
|
-
isDev: global$
|
|
1614
|
+
isDev: global$9.getData('isDev')
|
|
1441
1615
|
});
|
|
1616
|
+
report$8('hooks:updateAppJson');
|
|
1442
1617
|
}
|
|
1443
1618
|
|
|
1444
1619
|
return appJson;
|
|
1445
1620
|
} catch (e) {
|
|
1446
|
-
handleError$
|
|
1447
|
-
info$
|
|
1621
|
+
handleError$6(`生成app.json出现错误: ${e}`);
|
|
1622
|
+
info$b(e);
|
|
1448
1623
|
}
|
|
1449
1624
|
}
|
|
1450
1625
|
|
|
@@ -1455,7 +1630,7 @@ var buildAppJson = {
|
|
|
1455
1630
|
/**
|
|
1456
1631
|
* 下载第三方代码
|
|
1457
1632
|
*/
|
|
1458
|
-
const MetalSmith = require$$0__default$
|
|
1633
|
+
const MetalSmith = require$$0__default$4;
|
|
1459
1634
|
const crypto$2 = require$$1__default$5;
|
|
1460
1635
|
const {
|
|
1461
1636
|
downloadRepoForGit,
|
|
@@ -1463,16 +1638,16 @@ const {
|
|
|
1463
1638
|
resolve: resolve$c
|
|
1464
1639
|
} = widgets;
|
|
1465
1640
|
const {
|
|
1466
|
-
fail: fail$
|
|
1467
|
-
info: info$
|
|
1641
|
+
fail: fail$4,
|
|
1642
|
+
info: info$a
|
|
1468
1643
|
} = log$1;
|
|
1469
|
-
const fs$c = require$$0__default$
|
|
1470
|
-
const shelljs$
|
|
1644
|
+
const fs$c = require$$0__default$1;
|
|
1645
|
+
const shelljs$6 = require$$2__default;
|
|
1471
1646
|
const {
|
|
1472
|
-
handleError: handleError$
|
|
1647
|
+
handleError: handleError$5
|
|
1473
1648
|
} = handleError_1;
|
|
1474
1649
|
const {
|
|
1475
|
-
global: global$
|
|
1650
|
+
global: global$8
|
|
1476
1651
|
} = global_1;
|
|
1477
1652
|
/**
|
|
1478
1653
|
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
@@ -1482,15 +1657,15 @@ const {
|
|
|
1482
1657
|
*/
|
|
1483
1658
|
|
|
1484
1659
|
function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
1485
|
-
var _tmsConfig$gitAccount;
|
|
1660
|
+
var _tmsConfig$gitAccount, _tmsConfig$gitAccount2;
|
|
1486
1661
|
|
|
1487
1662
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1488
|
-
const tmsConfig = global$
|
|
1663
|
+
const tmsConfig = global$8.getData('tmsConfig');
|
|
1489
1664
|
let gitUrl = httpRepoUrl;
|
|
1490
1665
|
const {
|
|
1491
1666
|
username = '',
|
|
1492
1667
|
pass = ''
|
|
1493
|
-
} = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
|
|
1668
|
+
} = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount2 = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount2 === void 0 ? void 0 : _tmsConfig$gitAccount2[httpRepoUrl]) || {};
|
|
1494
1669
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
1495
1670
|
|
|
1496
1671
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -1509,11 +1684,15 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
1509
1684
|
|
|
1510
1685
|
|
|
1511
1686
|
function moveFile(sourceDir, targetDir, ignore = []) {
|
|
1512
|
-
|
|
1687
|
+
if (fs$c.existsSync(targetDir)) {
|
|
1688
|
+
shelljs$6.rm('-rf', targetDir);
|
|
1689
|
+
} // 删除不是文件夹的文件
|
|
1690
|
+
|
|
1691
|
+
|
|
1513
1692
|
return new Promise((resolve, reject) => {
|
|
1514
1693
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1515
1694
|
if (e) {
|
|
1516
|
-
fail$
|
|
1695
|
+
fail$4(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1517
1696
|
reject(e);
|
|
1518
1697
|
}
|
|
1519
1698
|
|
|
@@ -1562,11 +1741,11 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1562
1741
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1563
1742
|
return Promise.all(callArr);
|
|
1564
1743
|
}).catch(e => {
|
|
1565
|
-
handleError$
|
|
1744
|
+
handleError$5(`下载代码${params.httpRepoUrl}出现错误:${e}`);
|
|
1566
1745
|
}));
|
|
1567
1746
|
});
|
|
1568
1747
|
await Promise.all(arrPromises);
|
|
1569
|
-
shelljs$
|
|
1748
|
+
shelljs$6.cd(cwd);
|
|
1570
1749
|
}
|
|
1571
1750
|
/**
|
|
1572
1751
|
* 收集下载模块代码的任务
|
|
@@ -1620,7 +1799,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1620
1799
|
},
|
|
1621
1800
|
fn: async (sourceModulePath, targetPath) => {
|
|
1622
1801
|
if (fs$c.existsSync(targetPath)) {
|
|
1623
|
-
shelljs$
|
|
1802
|
+
shelljs$6.rm('-rf', `${targetPath}/*`);
|
|
1624
1803
|
}
|
|
1625
1804
|
|
|
1626
1805
|
await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
|
|
@@ -1636,12 +1815,12 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1636
1815
|
|
|
1637
1816
|
if (fs$c.existsSync(sourcePath) && fs$c.existsSync(`${sourcePath}/.git`)) {
|
|
1638
1817
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1639
|
-
info$
|
|
1818
|
+
info$a(`git pull:${httpRepoUrl} --branch: ${branch}`);
|
|
1640
1819
|
return pullRepoForGit(sourcePath, branch);
|
|
1641
1820
|
};
|
|
1642
1821
|
} else {
|
|
1643
1822
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1644
|
-
info$
|
|
1823
|
+
info$a(`git clone: ${httpRepoUrl}`);
|
|
1645
1824
|
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
1646
1825
|
};
|
|
1647
1826
|
}
|
|
@@ -1695,8 +1874,8 @@ var cloneModules_1 = {
|
|
|
1695
1874
|
checkRemoteModGitUrlBranch
|
|
1696
1875
|
};
|
|
1697
1876
|
|
|
1698
|
-
const ci = require$$0__default$
|
|
1699
|
-
const path$
|
|
1877
|
+
const ci = require$$0__default$6;
|
|
1878
|
+
const path$b = require$$1__default$1;
|
|
1700
1879
|
/**
|
|
1701
1880
|
* 获取小程序ci的Project对象
|
|
1702
1881
|
* @returns {Object} 小程序ci对象
|
|
@@ -1708,11 +1887,11 @@ const getMpCi = ({
|
|
|
1708
1887
|
type = 'miniProgram',
|
|
1709
1888
|
privateKey = 'TODO'
|
|
1710
1889
|
}) => {
|
|
1711
|
-
var
|
|
1890
|
+
var _projectCg$packOption, _projectCg$packOption2;
|
|
1712
1891
|
|
|
1713
|
-
const
|
|
1892
|
+
const projectCg = require(path$b.join(projectPath, 'project.config.json'));
|
|
1714
1893
|
|
|
1715
|
-
const ignores = (
|
|
1894
|
+
const ignores = (projectCg === null || projectCg === void 0 ? void 0 : (_projectCg$packOption = projectCg.packOptions) === null || _projectCg$packOption === void 0 ? void 0 : (_projectCg$packOption2 = _projectCg$packOption.ignore) === null || _projectCg$packOption2 === void 0 ? void 0 : _projectCg$packOption2.map(({
|
|
1716
1895
|
value
|
|
1717
1896
|
}) => value)) || [];
|
|
1718
1897
|
return new ci.Project({
|
|
@@ -1722,13 +1901,6 @@ const getMpCi = ({
|
|
|
1722
1901
|
projectPath,
|
|
1723
1902
|
ignores: ['node_modules/**/*', 'cloud/**/*', ...ignores]
|
|
1724
1903
|
});
|
|
1725
|
-
}; // 用小程序ci工具构建小程序
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
const packMpProject = async project => {
|
|
1729
|
-
await ci.packNpm(project, {
|
|
1730
|
-
ignores: ['cloud/**/*']
|
|
1731
|
-
});
|
|
1732
1904
|
};
|
|
1733
1905
|
/**
|
|
1734
1906
|
* 格式化构建npm结果信息
|
|
@@ -1747,8 +1919,12 @@ const formatPackNpmWarning = warning => {
|
|
|
1747
1919
|
return result;
|
|
1748
1920
|
};
|
|
1749
1921
|
/**
|
|
1750
|
-
* 构建miniprogram_npm
|
|
1751
|
-
*
|
|
1922
|
+
* 构建miniprogram_npm https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E6%9E%84%E5%BB%BAnpm
|
|
1923
|
+
* * @param {object} {
|
|
1924
|
+
* appId,
|
|
1925
|
+
* peojectPath,
|
|
1926
|
+
* privateKey,
|
|
1927
|
+
* }
|
|
1752
1928
|
*/
|
|
1753
1929
|
|
|
1754
1930
|
|
|
@@ -1757,12 +1933,14 @@ const buildMpNpm$1 = async ({
|
|
|
1757
1933
|
projectPath,
|
|
1758
1934
|
privateKey
|
|
1759
1935
|
}) => {
|
|
1760
|
-
const mpCi =
|
|
1936
|
+
const mpCi = getMpCi({
|
|
1761
1937
|
appId,
|
|
1762
1938
|
projectPath,
|
|
1763
1939
|
privateKey
|
|
1764
1940
|
});
|
|
1765
|
-
const packNpmWarning = await
|
|
1941
|
+
const packNpmWarning = await ci.packNpm(mpCi, {
|
|
1942
|
+
ignores: ['cloud/**/*']
|
|
1943
|
+
});
|
|
1766
1944
|
const packNpmMsg = formatPackNpmWarning(packNpmWarning);
|
|
1767
1945
|
|
|
1768
1946
|
if (packNpmMsg) {
|
|
@@ -1771,25 +1949,86 @@ const buildMpNpm$1 = async ({
|
|
|
1771
1949
|
|
|
1772
1950
|
return Promise.resolve();
|
|
1773
1951
|
};
|
|
1952
|
+
/**
|
|
1953
|
+
* 预览小程序码 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88
|
|
1954
|
+
* @param {object} {
|
|
1955
|
+
* appId,
|
|
1956
|
+
* peojectPath,
|
|
1957
|
+
* privateKey,
|
|
1958
|
+
* desc
|
|
1959
|
+
* robot
|
|
1960
|
+
* }
|
|
1961
|
+
*/
|
|
1962
|
+
|
|
1963
|
+
|
|
1964
|
+
const previewMp = async (params = {}) => {
|
|
1965
|
+
const {
|
|
1966
|
+
appId,
|
|
1967
|
+
projectPath,
|
|
1968
|
+
privateKey,
|
|
1969
|
+
...resetParams
|
|
1970
|
+
} = params;
|
|
1971
|
+
const mpCi = await getMpCi({
|
|
1972
|
+
appId,
|
|
1973
|
+
projectPath,
|
|
1974
|
+
privateKey
|
|
1975
|
+
});
|
|
1976
|
+
return await ci.preview({
|
|
1977
|
+
project: mpCi,
|
|
1978
|
+
...resetParams,
|
|
1979
|
+
onProgressUpdate: () => {}
|
|
1980
|
+
});
|
|
1981
|
+
};
|
|
1982
|
+
/**
|
|
1983
|
+
* 上传小程序 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E4%B8%8A%E4%BC%A0
|
|
1984
|
+
* @param {object} {
|
|
1985
|
+
* appId,
|
|
1986
|
+
* peojectPath,
|
|
1987
|
+
* privateKey,
|
|
1988
|
+
* version,
|
|
1989
|
+
* desc
|
|
1990
|
+
* }
|
|
1991
|
+
*/
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
const uploadMp = async (params = {}) => {
|
|
1995
|
+
const {
|
|
1996
|
+
appId,
|
|
1997
|
+
projectPath,
|
|
1998
|
+
privateKey,
|
|
1999
|
+
...resetParams
|
|
2000
|
+
} = params;
|
|
2001
|
+
const mpCi = await getMpCi({
|
|
2002
|
+
appId,
|
|
2003
|
+
projectPath,
|
|
2004
|
+
privateKey
|
|
2005
|
+
});
|
|
2006
|
+
return await ci.upload({
|
|
2007
|
+
project: mpCi,
|
|
2008
|
+
...resetParams,
|
|
2009
|
+
onProgressUpdate: () => {}
|
|
2010
|
+
});
|
|
2011
|
+
};
|
|
1774
2012
|
|
|
1775
|
-
var mpCi = {
|
|
1776
|
-
buildMpNpm: buildMpNpm$1
|
|
2013
|
+
var mpCi$2 = {
|
|
2014
|
+
buildMpNpm: buildMpNpm$1,
|
|
2015
|
+
previewMp,
|
|
2016
|
+
uploadMp
|
|
1777
2017
|
};
|
|
1778
2018
|
|
|
1779
|
-
const fs$b = require$$0__default$
|
|
1780
|
-
const path$
|
|
2019
|
+
const fs$b = require$$0__default$1;
|
|
2020
|
+
const path$a = require$$1__default$1;
|
|
1781
2021
|
const {
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
} = require$$5;
|
|
2022
|
+
NPM_CACHE_FILE
|
|
2023
|
+
} = constant;
|
|
1785
2024
|
const {
|
|
1786
|
-
ensureDirExist: ensureDirExist$
|
|
2025
|
+
ensureDirExist: ensureDirExist$3
|
|
1787
2026
|
} = io$3;
|
|
1788
2027
|
|
|
1789
2028
|
function getCache$1(projectDir, type) {
|
|
1790
2029
|
var _content$projectDir;
|
|
1791
2030
|
|
|
1792
|
-
const filePath =
|
|
2031
|
+
const filePath = NPM_CACHE_FILE;
|
|
1793
2032
|
|
|
1794
2033
|
if (!fs$b.existsSync(filePath)) {
|
|
1795
2034
|
return null;
|
|
@@ -1801,11 +2040,11 @@ function getCache$1(projectDir, type) {
|
|
|
1801
2040
|
}
|
|
1802
2041
|
|
|
1803
2042
|
function setCache$1(projectDir, type = 'miniprogram_npm', data) {
|
|
1804
|
-
const filePath =
|
|
2043
|
+
const filePath = NPM_CACHE_FILE;
|
|
1805
2044
|
|
|
1806
2045
|
if (!fs$b.existsSync(filePath)) {
|
|
1807
|
-
const dir = path$
|
|
1808
|
-
ensureDirExist$
|
|
2046
|
+
const dir = path$a.dirname(filePath);
|
|
2047
|
+
ensureDirExist$3(dir);
|
|
1809
2048
|
fs$b.writeFileSync(filePath, '{}');
|
|
1810
2049
|
}
|
|
1811
2050
|
|
|
@@ -1829,19 +2068,21 @@ var cache = {
|
|
|
1829
2068
|
/**
|
|
1830
2069
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1831
2070
|
*/
|
|
1832
|
-
const fs$a = require$$0__default$
|
|
2071
|
+
const fs$a = require$$0__default$1;
|
|
1833
2072
|
const fsExtra = require$$1__default$6;
|
|
1834
2073
|
const crypto$1 = require$$1__default$5;
|
|
1835
|
-
const path$
|
|
1836
|
-
const shell = require$$
|
|
1837
|
-
const glob = require$$6__default;
|
|
2074
|
+
const path$9 = require$$1__default$1;
|
|
2075
|
+
const shell = require$$2__default;
|
|
1838
2076
|
const log = log$1;
|
|
1839
2077
|
const {
|
|
1840
2078
|
npmInstall: npmInstall$1
|
|
1841
2079
|
} = widgets;
|
|
1842
2080
|
const {
|
|
1843
|
-
handleError: handleError$
|
|
2081
|
+
handleError: handleError$4
|
|
1844
2082
|
} = handleError_1;
|
|
2083
|
+
const {
|
|
2084
|
+
global: global$7
|
|
2085
|
+
} = global_1;
|
|
1845
2086
|
const shellJsOption = {
|
|
1846
2087
|
async: false,
|
|
1847
2088
|
silent: true
|
|
@@ -1879,14 +2120,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1879
2120
|
|
|
1880
2121
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1881
2122
|
const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1882
|
-
const cacheNMPath = path$
|
|
1883
|
-
const cacheNMTarFile = path$
|
|
2123
|
+
const cacheNMPath = path$9.join(cacheDir, md5Key);
|
|
2124
|
+
const cacheNMTarFile = path$9.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1884
2125
|
|
|
1885
2126
|
const callback = {
|
|
1886
2127
|
params: {
|
|
1887
2128
|
cacheNMPath,
|
|
1888
2129
|
cacheNMTarFile,
|
|
1889
|
-
packageJsonDir: path$
|
|
2130
|
+
packageJsonDir: path$9.dirname(packageJsonPath),
|
|
1890
2131
|
shell
|
|
1891
2132
|
},
|
|
1892
2133
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
@@ -1915,7 +2156,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1915
2156
|
fsExtra.emptydirSync(cacheNMPath);
|
|
1916
2157
|
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
1917
2158
|
log.info(`npm install: ${packageJsonPath}`);
|
|
1918
|
-
|
|
2159
|
+
const tmsConfig = global$7.getData('tmsConfig');
|
|
2160
|
+
return npmInstall$1(cacheNMPath, tmsConfig.npm).then(() => {
|
|
1919
2161
|
const newShellJsOption = { ...shellJsOption,
|
|
1920
2162
|
cwd: cacheNMPath
|
|
1921
2163
|
};
|
|
@@ -1962,7 +2204,7 @@ const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
|
|
|
1962
2204
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1963
2205
|
return Promise.all(callArr);
|
|
1964
2206
|
}).catch(e => {
|
|
1965
|
-
handleError$
|
|
2207
|
+
handleError$4(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
|
|
1966
2208
|
}));
|
|
1967
2209
|
});
|
|
1968
2210
|
await Promise.all(arrPromises);
|
|
@@ -2003,7 +2245,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
2003
2245
|
|
|
2004
2246
|
const files = fs$a.readdirSync(startPath);
|
|
2005
2247
|
files.forEach(file => {
|
|
2006
|
-
const filename = path$
|
|
2248
|
+
const filename = path$9.join(startPath, file);
|
|
2007
2249
|
const stat = fs$a.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
2008
2250
|
|
|
2009
2251
|
if (stat.isDirectory()) {
|
|
@@ -2030,10 +2272,10 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
2030
2272
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
2031
2273
|
|
|
2032
2274
|
const cwd = contextDir || dirPath;
|
|
2033
|
-
const result = [path$
|
|
2275
|
+
const result = [path$9.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
2034
2276
|
|
|
2035
2277
|
subRoots.forEach(subRoot => {
|
|
2036
|
-
const toppath = path$
|
|
2278
|
+
const toppath = path$9.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
2037
2279
|
|
|
2038
2280
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
2039
2281
|
result.push(...list);
|
|
@@ -2041,34 +2283,14 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
2041
2283
|
return result;
|
|
2042
2284
|
};
|
|
2043
2285
|
|
|
2044
|
-
function cloudNpmInstall(contextDir) {
|
|
2045
|
-
return new Promise((resolve, reject) => {
|
|
2046
|
-
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
2047
|
-
if (err) {
|
|
2048
|
-
reject(err);
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
files.forEach(file => {
|
|
2052
|
-
const dir = path$8.dirname(file);
|
|
2053
|
-
shell.cd(dir);
|
|
2054
|
-
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
2055
|
-
silent: false
|
|
2056
|
-
});
|
|
2057
|
-
});
|
|
2058
|
-
resolve();
|
|
2059
|
-
});
|
|
2060
|
-
});
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
2286
|
var npm = {
|
|
2064
|
-
cloudNpmInstall,
|
|
2065
2287
|
npmInstallAll: npmInstallAll$1,
|
|
2066
2288
|
findAllPackageJson,
|
|
2067
2289
|
findFilesByFilter
|
|
2068
2290
|
};
|
|
2069
2291
|
|
|
2070
2292
|
const crypto = require$$1__default$5;
|
|
2071
|
-
const fs$9 = require$$0__default$
|
|
2293
|
+
const fs$9 = require$$0__default$1;
|
|
2072
2294
|
|
|
2073
2295
|
function fileMd5$1(filePath) {
|
|
2074
2296
|
return new Promise((resolve, reject) => {
|
|
@@ -2091,21 +2313,26 @@ var md5 = {
|
|
|
2091
2313
|
fileMd5: fileMd5$1
|
|
2092
2314
|
};
|
|
2093
2315
|
|
|
2094
|
-
const fs$8 = require$$0__default$
|
|
2316
|
+
const fs$8 = require$$0__default$1;
|
|
2095
2317
|
const semver$1 = require$$1__default$7;
|
|
2096
2318
|
const {
|
|
2097
2319
|
resolve: resolve$b,
|
|
2098
|
-
getAbsolutePath: getAbsolutePath$
|
|
2320
|
+
getAbsolutePath: getAbsolutePath$4
|
|
2099
2321
|
} = widgets;
|
|
2100
|
-
const path$
|
|
2101
|
-
const shelljs$
|
|
2322
|
+
const path$8 = require$$1__default$1;
|
|
2323
|
+
const shelljs$5 = require$$2__default;
|
|
2102
2324
|
const {
|
|
2103
|
-
handleError: handleError$
|
|
2325
|
+
handleError: handleError$3
|
|
2104
2326
|
} = handleError_1;
|
|
2105
2327
|
|
|
2106
2328
|
const getLatestVersion = npmName => {
|
|
2107
|
-
const data = shelljs$
|
|
2108
|
-
|
|
2329
|
+
const data = shelljs$5.exec(`npm view ${npmName} version`);
|
|
2330
|
+
|
|
2331
|
+
if (data.code === 0) {
|
|
2332
|
+
return data.stdout;
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
return '0.0.0';
|
|
2109
2336
|
}; // 收集package.json
|
|
2110
2337
|
|
|
2111
2338
|
|
|
@@ -2114,12 +2341,12 @@ function collectPackageJson(subPackages, cwd, outputDir) {
|
|
|
2114
2341
|
// 1.1根目录的package.json
|
|
2115
2342
|
|
|
2116
2343
|
const packageArr = [{
|
|
2117
|
-
srcPackageDir: path$
|
|
2344
|
+
srcPackageDir: path$8.join(cwd, packageJsonName),
|
|
2118
2345
|
destNpmDir: resolve$b(outputDir, 'node_modules')
|
|
2119
2346
|
}]; // 1.2模块的package.json
|
|
2120
2347
|
|
|
2121
2348
|
subPackages.forEach(item => {
|
|
2122
|
-
const srcPackageDir = `${getAbsolutePath$
|
|
2349
|
+
const srcPackageDir = `${getAbsolutePath$4(item.path)}/package.json`;
|
|
2123
2350
|
|
|
2124
2351
|
if (fs$8.existsSync(srcPackageDir)) {
|
|
2125
2352
|
packageArr.push({
|
|
@@ -2140,7 +2367,7 @@ function readPackageDependencies(srcPackageDir) {
|
|
|
2140
2367
|
const json = packageJson ? JSON.parse(packageJson) : {};
|
|
2141
2368
|
dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
|
|
2142
2369
|
} catch (e) {
|
|
2143
|
-
handleError$
|
|
2370
|
+
handleError$3(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
2144
2371
|
}
|
|
2145
2372
|
|
|
2146
2373
|
return dependencies;
|
|
@@ -2168,13 +2395,13 @@ const checkPackageVersion$1 = packageArr => {
|
|
|
2168
2395
|
const dependenciesKeys = Object.keys(dependencies);
|
|
2169
2396
|
|
|
2170
2397
|
for (const key of dependenciesKeys) {
|
|
2171
|
-
const depPath = path$
|
|
2398
|
+
const depPath = path$8.join(item.destNpmDir, key);
|
|
2172
2399
|
|
|
2173
2400
|
if (!fs$8.existsSync(depPath)) {
|
|
2174
2401
|
return true;
|
|
2175
2402
|
}
|
|
2176
2403
|
|
|
2177
|
-
const depPackagePath = path$
|
|
2404
|
+
const depPackagePath = path$8.join(depPath, 'package.json');
|
|
2178
2405
|
|
|
2179
2406
|
if (fs$8.existsSync(depPackagePath)) {
|
|
2180
2407
|
const packageData = require(depPackagePath);
|
|
@@ -2202,30 +2429,30 @@ var checkDependencies = {
|
|
|
2202
2429
|
checkPackageVersion: checkPackageVersion$1
|
|
2203
2430
|
};
|
|
2204
2431
|
|
|
2205
|
-
const shelljs$
|
|
2206
|
-
const fs$7 = require$$0__default$
|
|
2207
|
-
const path$
|
|
2432
|
+
const shelljs$4 = require$$2__default;
|
|
2433
|
+
const fs$7 = require$$0__default$1;
|
|
2434
|
+
const path$7 = require$$1__default$1;
|
|
2208
2435
|
const io$1 = io$3;
|
|
2209
2436
|
const {
|
|
2210
|
-
createTask: createTask$
|
|
2437
|
+
createTask: createTask$3,
|
|
2211
2438
|
resolve: resolve$a,
|
|
2212
|
-
getAbsolutePath: getAbsolutePath$
|
|
2439
|
+
getAbsolutePath: getAbsolutePath$3
|
|
2213
2440
|
} = widgets;
|
|
2214
2441
|
const {
|
|
2215
2442
|
buildMpNpm
|
|
2216
|
-
} = mpCi;
|
|
2443
|
+
} = mpCi$2;
|
|
2217
2444
|
const {
|
|
2218
2445
|
setCache,
|
|
2219
2446
|
getCache
|
|
2220
2447
|
} = cache;
|
|
2221
2448
|
const {
|
|
2222
|
-
|
|
2223
|
-
} =
|
|
2449
|
+
NODE_MODULES_DIR: NODE_MODULES_DIR$1
|
|
2450
|
+
} = constant;
|
|
2224
2451
|
const {
|
|
2225
2452
|
npmInstallAll
|
|
2226
2453
|
} = npm;
|
|
2227
2454
|
const {
|
|
2228
|
-
info: info$
|
|
2455
|
+
info: info$9
|
|
2229
2456
|
} = log$1;
|
|
2230
2457
|
const {
|
|
2231
2458
|
fileMd5
|
|
@@ -2236,23 +2463,23 @@ const {
|
|
|
2236
2463
|
|
|
2237
2464
|
async function install$2(tmsConfig, subPackages, useCache = true) {
|
|
2238
2465
|
const cwd = process.cwd();
|
|
2239
|
-
const npmInstallRes = await createTask$
|
|
2466
|
+
const npmInstallRes = await createTask$3(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
|
|
2240
2467
|
|
|
2241
2468
|
if (!npmInstallRes.isCache) {
|
|
2242
2469
|
// 构建miniprogram_npm, 不使用缓存
|
|
2243
|
-
await createTask$
|
|
2470
|
+
await createTask$3(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
|
|
2244
2471
|
} else {
|
|
2245
2472
|
// 构建miniprogram_npm
|
|
2246
|
-
await createTask$
|
|
2473
|
+
await createTask$3(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
|
|
2247
2474
|
}
|
|
2248
2475
|
|
|
2249
|
-
shelljs$
|
|
2476
|
+
shelljs$4.cd(cwd);
|
|
2250
2477
|
}
|
|
2251
2478
|
|
|
2252
2479
|
async function npmInstall(tmsConfig, subPackages, useCache) {
|
|
2253
2480
|
// 如果依赖没有更新和使用缓存数据(则命中缓存)
|
|
2254
2481
|
if (!isDependenciesUpdate(subPackages, resolve$a('./'), tmsConfig.outputDir) && useCache) {
|
|
2255
|
-
info$
|
|
2482
|
+
info$9('node_modules命中缓存');
|
|
2256
2483
|
return {
|
|
2257
2484
|
isCache: true
|
|
2258
2485
|
};
|
|
@@ -2262,10 +2489,10 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
|
|
|
2262
2489
|
subPackages.forEach(item => {
|
|
2263
2490
|
const outputModuleDir = resolve$a(`${tmsConfig.outputDir}/${item.root}`);
|
|
2264
2491
|
io$1.ensureDirExist(outputModuleDir);
|
|
2265
|
-
const modulePackagePath = `${getAbsolutePath$
|
|
2266
|
-
if (fs$7.existsSync(modulePackagePath)) shelljs$
|
|
2492
|
+
const modulePackagePath = `${getAbsolutePath$3(item.path)}/package.json`;
|
|
2493
|
+
if (fs$7.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
2267
2494
|
});
|
|
2268
|
-
await npmInstallAll(subPackages, resolve$a(tmsConfig.outputDir),
|
|
2495
|
+
await npmInstallAll(subPackages, resolve$a(tmsConfig.outputDir), NODE_MODULES_DIR$1);
|
|
2269
2496
|
return {
|
|
2270
2497
|
isCache: false
|
|
2271
2498
|
};
|
|
@@ -2296,7 +2523,7 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2296
2523
|
if (useCache) {
|
|
2297
2524
|
let flag = true;
|
|
2298
2525
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2299
|
-
const packageDir = path$
|
|
2526
|
+
const packageDir = path$7.dirname(item);
|
|
2300
2527
|
const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
|
|
2301
2528
|
const md5Value = await getMNPMd5(packageDir);
|
|
2302
2529
|
const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
|
|
@@ -2310,13 +2537,13 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2310
2537
|
}
|
|
2311
2538
|
|
|
2312
2539
|
if (isCache) {
|
|
2313
|
-
info$
|
|
2540
|
+
info$9('miniprogram_npm命中缓存');
|
|
2314
2541
|
return;
|
|
2315
2542
|
} // 即将构建,在cache中标记开始
|
|
2316
2543
|
|
|
2317
2544
|
|
|
2318
2545
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2319
|
-
const packageDir = path$
|
|
2546
|
+
const packageDir = path$7.dirname(item);
|
|
2320
2547
|
const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
|
|
2321
2548
|
setCache(mpDir, 'miniprogram_npm', {
|
|
2322
2549
|
md5: '',
|
|
@@ -2330,7 +2557,7 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2330
2557
|
}); // 构建成功后,计算md5写入cache
|
|
2331
2558
|
|
|
2332
2559
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2333
|
-
const packageDir = path$
|
|
2560
|
+
const packageDir = path$7.dirname(item);
|
|
2334
2561
|
const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
|
|
2335
2562
|
const md5Value = await getMNPMd5(packageDir);
|
|
2336
2563
|
setCache(mpDir, 'miniprogram_npm', {
|
|
@@ -2346,16 +2573,16 @@ async function getMNPMd5(cwd) {
|
|
|
2346
2573
|
async: false,
|
|
2347
2574
|
silent: true
|
|
2348
2575
|
};
|
|
2349
|
-
shelljs$
|
|
2576
|
+
shelljs$4.cd(cwd);
|
|
2350
2577
|
|
|
2351
2578
|
if (fs$7.existsSync('miniprogram_npm')) {
|
|
2352
|
-
shelljs$
|
|
2579
|
+
shelljs$4.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
|
|
2353
2580
|
cwd,
|
|
2354
2581
|
...shellJsOption
|
|
2355
2582
|
});
|
|
2356
|
-
const tarDir = path$
|
|
2583
|
+
const tarDir = path$7.join(cwd, './miniprogram_npm.tar.gz');
|
|
2357
2584
|
const md5Value = await fileMd5(tarDir);
|
|
2358
|
-
shelljs$
|
|
2585
|
+
shelljs$4.rm('-rf', tarDir);
|
|
2359
2586
|
return md5Value;
|
|
2360
2587
|
}
|
|
2361
2588
|
|
|
@@ -2364,20 +2591,20 @@ async function getMNPMd5(cwd) {
|
|
|
2364
2591
|
|
|
2365
2592
|
var install_1 = install$2;
|
|
2366
2593
|
|
|
2367
|
-
const shelljs$
|
|
2368
|
-
const fs$6 = require$$0__default$
|
|
2594
|
+
const shelljs$3 = require$$2__default;
|
|
2595
|
+
const fs$6 = require$$0__default$1;
|
|
2369
2596
|
const io = io$3;
|
|
2370
2597
|
const {
|
|
2371
2598
|
resolve: resolve$9,
|
|
2372
|
-
createTask
|
|
2599
|
+
createTask: createTask$2
|
|
2373
2600
|
} = widgets;
|
|
2374
2601
|
const {
|
|
2375
2602
|
buildOutputAppJson: buildOutputAppJson$1
|
|
2376
2603
|
} = buildAppJson;
|
|
2377
2604
|
const {
|
|
2378
|
-
MODULE_CODE_DIR,
|
|
2605
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
2379
2606
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
|
|
2380
|
-
} =
|
|
2607
|
+
} = constant;
|
|
2381
2608
|
const {
|
|
2382
2609
|
cloneModules
|
|
2383
2610
|
} = cloneModules_1;
|
|
@@ -2386,8 +2613,8 @@ const {
|
|
|
2386
2613
|
getSubPackages: getSubPackages$2
|
|
2387
2614
|
} = tmsMpconfig.exports;
|
|
2388
2615
|
const {
|
|
2389
|
-
fail: fail$
|
|
2390
|
-
info: info$
|
|
2616
|
+
fail: fail$3,
|
|
2617
|
+
info: info$8
|
|
2391
2618
|
} = log$1;
|
|
2392
2619
|
const install$1 = install_1;
|
|
2393
2620
|
/**
|
|
@@ -2403,24 +2630,24 @@ const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
|
2403
2630
|
io.ensureDirExist(outputDir);
|
|
2404
2631
|
defaultFiles.forEach(item => {
|
|
2405
2632
|
if (fs$6.existsSync(resolve$9(item))) {
|
|
2406
|
-
shelljs$
|
|
2633
|
+
shelljs$3.cp('-rf', resolve$9(item), resolve$9(tmsConfig.outputDir, item));
|
|
2407
2634
|
}
|
|
2408
2635
|
});
|
|
2409
2636
|
};
|
|
2410
2637
|
|
|
2411
2638
|
async function task(tmsConfig, targetModules) {
|
|
2412
2639
|
// 下载和移动代码
|
|
2413
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$9('./'), targetModules); // 获取所有模块,合并模块依赖的模块
|
|
2640
|
+
await createTask$2(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$9('./'), targetModules); // 获取所有模块,合并模块依赖的模块
|
|
2414
2641
|
|
|
2415
2642
|
const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
|
|
2416
2643
|
|
|
2417
2644
|
const newSubPackages = getSubPackages$2(newModules); // 拷贝相关配置文件到输出目录
|
|
2418
2645
|
|
|
2419
|
-
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
|
|
2646
|
+
await createTask$2(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
|
|
2420
2647
|
|
|
2421
2648
|
await install$1(tmsConfig, newSubPackages, true); // 动态生成编译后的app.json;
|
|
2422
2649
|
|
|
2423
|
-
await createTask(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
2650
|
+
await createTask$2(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
2424
2651
|
return {
|
|
2425
2652
|
modules: newModules,
|
|
2426
2653
|
subPackages: newSubPackages
|
|
@@ -2433,8 +2660,8 @@ async function init$3(tmsConfig, targetModules) {
|
|
|
2433
2660
|
return taskRes;
|
|
2434
2661
|
} catch (error) {
|
|
2435
2662
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
2436
|
-
fail$
|
|
2437
|
-
info$
|
|
2663
|
+
fail$3(`初始化流程出现错误: ${errMsg}`);
|
|
2664
|
+
info$8('详细的错误信息', error);
|
|
2438
2665
|
process.exit(1);
|
|
2439
2666
|
}
|
|
2440
2667
|
}
|
|
@@ -2442,578 +2669,68 @@ async function init$3(tmsConfig, targetModules) {
|
|
|
2442
2669
|
var init_1 = init$3;
|
|
2443
2670
|
|
|
2444
2671
|
/* eslint-disable no-param-reassign */
|
|
2445
|
-
const strip = require$$0__default$8; // 匹配规则
|
|
2446
|
-
|
|
2447
|
-
const MATCH_RULE = new RegExp(/@import *(?:url\(['"]?([^'")]+)['"]?\)|['"]([^'"]+)['"]);?/g);
|
|
2448
|
-
/**
|
|
2449
|
-
* 获取样式文件中的@import语句
|
|
2450
|
-
* @param code 代码片段
|
|
2451
|
-
* @returns 结果数组
|
|
2452
|
-
*/
|
|
2453
|
-
|
|
2454
|
-
const findCssImports$1 = code => {
|
|
2455
|
-
// 将buffer转成字符串
|
|
2456
|
-
code = code.toString(); // 去除注释
|
|
2457
2672
|
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2673
|
+
function mpProjectJson$1() {
|
|
2674
|
+
return function ({
|
|
2675
|
+
vinyl,
|
|
2676
|
+
next
|
|
2677
|
+
}) {
|
|
2678
|
+
if (vinyl.isBuffer()) {
|
|
2679
|
+
let contents = String(vinyl.contents);
|
|
2680
|
+
contents = contents.replace(/"miniprogramRoot"[^,]+,/g, '');
|
|
2681
|
+
vinyl.contents = Buffer.from(contents);
|
|
2682
|
+
}
|
|
2462
2683
|
|
|
2463
|
-
|
|
2464
|
-
|
|
2684
|
+
next();
|
|
2685
|
+
};
|
|
2686
|
+
}
|
|
2465
2687
|
|
|
2466
|
-
|
|
2467
|
-
result.push(((_matchList = matchList) === null || _matchList === void 0 ? void 0 : _matchList[1]) || ((_matchList2 = matchList) === null || _matchList2 === void 0 ? void 0 : _matchList2[2]));
|
|
2468
|
-
} // 返回结果
|
|
2688
|
+
var mpProjectJson_1 = mpProjectJson$1;
|
|
2469
2689
|
|
|
2690
|
+
const {
|
|
2691
|
+
src: src$1,
|
|
2692
|
+
dest
|
|
2693
|
+
} = require$$0__default$7;
|
|
2694
|
+
const path$6 = require$$1__default$1;
|
|
2695
|
+
const minimatch = require$$2__default$1;
|
|
2696
|
+
const gulpif = require$$3__default$1;
|
|
2697
|
+
const mpProjectJson = mpProjectJson_1;
|
|
2698
|
+
const {
|
|
2699
|
+
resolve: resolve$8
|
|
2700
|
+
} = widgets;
|
|
2701
|
+
const through = require$$6__default;
|
|
2702
|
+
const {
|
|
2703
|
+
fail: fail$2
|
|
2704
|
+
} = log$1;
|
|
2470
2705
|
|
|
2471
|
-
|
|
2706
|
+
const getTargetFile$1 = (sourceFile, module, outputDir) => {
|
|
2707
|
+
const sourceFileRelativeModule = path$6.relative(resolve$8(module.from), sourceFile);
|
|
2708
|
+
const targetFile = resolve$8(outputDir, module.to, sourceFileRelativeModule);
|
|
2709
|
+
return targetFile;
|
|
2472
2710
|
};
|
|
2473
2711
|
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
}
|
|
2492
|
-
}
|
|
2493
|
-
|
|
2494
|
-
var pluginError_1 = {
|
|
2495
|
-
pluginError: pluginError$3
|
|
2496
|
-
};
|
|
2497
|
-
|
|
2498
|
-
/* eslint-disable no-param-reassign */
|
|
2499
|
-
const through$2 = require$$0__default$9;
|
|
2500
|
-
const precinct = require$$1__default$8;
|
|
2501
|
-
const path$5 = require$$1__default$2;
|
|
2502
|
-
const {
|
|
2503
|
-
findCssImports
|
|
2504
|
-
} = findCssImport;
|
|
2505
|
-
const {
|
|
2506
|
-
ext: ext$2,
|
|
2507
|
-
fileInDir: fileInDir$2,
|
|
2508
|
-
diffContentCopyFile: diffContentCopyFile$2
|
|
2509
|
-
} = io$3;
|
|
2510
|
-
const {
|
|
2511
|
-
resolve: resolve$8
|
|
2512
|
-
} = widgets;
|
|
2513
|
-
const fs$5 = require$$0__default$2;
|
|
2514
|
-
const {
|
|
2515
|
-
pluginError: pluginError$2
|
|
2516
|
-
} = pluginError_1;
|
|
2517
|
-
const cssFilter = ['.less', '.wxss'];
|
|
2518
|
-
|
|
2519
|
-
const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensions, isWatch = true) {
|
|
2520
|
-
const resDep = new Map();
|
|
2521
|
-
|
|
2522
|
-
function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
|
|
2523
|
-
let contents = '';
|
|
2524
|
-
|
|
2525
|
-
try {
|
|
2526
|
-
contents = fs$5.readFileSync(anaFileOriginFile, 'utf8');
|
|
2527
|
-
} catch (e) {
|
|
2528
|
-
pluginError$2(e, isWatch);
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
|
-
const deps = cssFilter.indexOf(path$5.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2532
|
-
deps.forEach(depItem => {
|
|
2533
|
-
if (depItem.startsWith('.')) {
|
|
2534
|
-
// 被依赖文件的存在的绝对路径
|
|
2535
|
-
const depOriginPath = path$5.join(path$5.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2536
|
-
|
|
2537
|
-
const {
|
|
2538
|
-
ext: extAlias,
|
|
2539
|
-
file: depOriginFile,
|
|
2540
|
-
extPath
|
|
2541
|
-
} = ext$2(depOriginPath, extensions);
|
|
2542
|
-
|
|
2543
|
-
if (!fs$5.existsSync(depOriginFile)) {
|
|
2544
|
-
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2545
|
-
return;
|
|
2546
|
-
}
|
|
2547
|
-
|
|
2548
|
-
const depDestPath = resolve$8(path$5.dirname(anaFileDestFile), depItem);
|
|
2549
|
-
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2550
|
-
|
|
2551
|
-
if (!resDep.has(depDestFile)) {
|
|
2552
|
-
resDep.set(depDestFile, {
|
|
2553
|
-
anaFileOriginFile,
|
|
2554
|
-
anaFileDestFile,
|
|
2555
|
-
depDestFile,
|
|
2556
|
-
depOriginFile
|
|
2557
|
-
});
|
|
2558
|
-
dfs(depOriginFile, depDestFile, extensions);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
});
|
|
2562
|
-
}
|
|
2563
|
-
|
|
2564
|
-
dfs(anaFileOriginFile, anaFileDestFile, extensions);
|
|
2565
|
-
return resDep;
|
|
2566
|
-
};
|
|
2567
|
-
|
|
2568
|
-
function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
2569
|
-
const stream = through$2.obj(function (file, enc, cb) {
|
|
2570
|
-
// 依赖分析的文件
|
|
2571
|
-
const anaFileOriginFile = file.history[0];
|
|
2572
|
-
const anaFileRelativeModule = path$5.relative(resolve$8(module.from), anaFileOriginFile);
|
|
2573
|
-
const anaFileDestFile = resolve$8(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2574
|
-
|
|
2575
|
-
if (file.isBuffer()) {
|
|
2576
|
-
let contents = String(file.contents);
|
|
2577
|
-
const deps = cssFilter.indexOf(path$5.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2578
|
-
const copyModules = new Map();
|
|
2579
|
-
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2580
|
-
const includePath = tmsConfig.dependencies[includeName];
|
|
2581
|
-
deps.forEach(depItem => {
|
|
2582
|
-
if (depItem.indexOf(includeName) > -1) {
|
|
2583
|
-
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
2584
|
-
const depOriginPath = path$5.join(path$5.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2585
|
-
|
|
2586
|
-
const {
|
|
2587
|
-
ext: extAlias,
|
|
2588
|
-
file: depOriginFile,
|
|
2589
|
-
extPath
|
|
2590
|
-
} = ext$2(depOriginPath, extensions);
|
|
2591
|
-
|
|
2592
|
-
if (!fileInDir$2(includePath, depOriginFile)) {
|
|
2593
|
-
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2594
|
-
return;
|
|
2595
|
-
} // eslint-disable-next-line
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2599
|
-
const regRes = depItem.match(reg) || [];
|
|
2600
|
-
|
|
2601
|
-
if (regRes[2]) {
|
|
2602
|
-
const depDestPath = resolve$8(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2603
|
-
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2604
|
-
|
|
2605
|
-
if (!copyModules.has(depDestFile)) {
|
|
2606
|
-
copyModules.set(depDestFile, {
|
|
2607
|
-
depOriginFile,
|
|
2608
|
-
depDestFile,
|
|
2609
|
-
beforeDepPath: depItem,
|
|
2610
|
-
afterDepPath: path$5.relative(path$5.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2611
|
-
});
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
});
|
|
2616
|
-
}); // console.log('mpCommonDep copyModules', copyModules);
|
|
2617
|
-
|
|
2618
|
-
copyModules.forEach(({
|
|
2619
|
-
depOriginFile,
|
|
2620
|
-
depDestFile,
|
|
2621
|
-
beforeDepPath,
|
|
2622
|
-
afterDepPath
|
|
2623
|
-
}) => {
|
|
2624
|
-
diffContentCopyFile$2(depOriginFile, depDestFile);
|
|
2625
|
-
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2626
|
-
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2627
|
-
const defs = dfsFindCommonDep$2(depOriginFile, depDestFile, extensions, isWatch);
|
|
2628
|
-
defs.forEach(item => {
|
|
2629
|
-
diffContentCopyFile$2(item.depOriginFile, item.depDestFile);
|
|
2630
|
-
}); // console.log('mpCommonDep defs', defs);
|
|
2631
|
-
});
|
|
2632
|
-
file.contents = Buffer.from(contents);
|
|
2633
|
-
}
|
|
2634
|
-
|
|
2635
|
-
this.push(file);
|
|
2636
|
-
cb();
|
|
2637
|
-
});
|
|
2638
|
-
return stream;
|
|
2639
|
-
}
|
|
2640
|
-
|
|
2641
|
-
var mpCommonDep_1 = {
|
|
2642
|
-
mpCommonDep: mpCommonDep$1,
|
|
2643
|
-
dfsFindCommonDep: dfsFindCommonDep$2
|
|
2644
|
-
};
|
|
2645
|
-
|
|
2646
|
-
/* eslint-disable no-param-reassign */
|
|
2647
|
-
const through$1 = require$$0__default$9;
|
|
2648
|
-
const path$4 = require$$1__default$2;
|
|
2649
|
-
const {
|
|
2650
|
-
ext: ext$1,
|
|
2651
|
-
fileInDir: fileInDir$1,
|
|
2652
|
-
diffContentCopyFile: diffContentCopyFile$1
|
|
2653
|
-
} = io$3;
|
|
2654
|
-
const {
|
|
2655
|
-
resolve: resolve$7
|
|
2656
|
-
} = widgets;
|
|
2657
|
-
const fs$4 = require$$0__default$2;
|
|
2658
|
-
const {
|
|
2659
|
-
pluginError: pluginError$1
|
|
2660
|
-
} = pluginError_1;
|
|
2661
|
-
const {
|
|
2662
|
-
dfsFindCommonDep: dfsFindCommonDep$1
|
|
2663
|
-
} = mpCommonDep_1;
|
|
2664
|
-
|
|
2665
|
-
function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch) {
|
|
2666
|
-
const stream = through$1.obj(function (file, enc, cb) {
|
|
2667
|
-
// 当前分析的文件的路径
|
|
2668
|
-
const anaFileOriginFile = file.history[0];
|
|
2669
|
-
const anaFileRelativeModule = path$4.relative(resolve$7(module.from), anaFileOriginFile);
|
|
2670
|
-
const anaFileDestFile = resolve$7(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2671
|
-
|
|
2672
|
-
if (file.isBuffer()) {
|
|
2673
|
-
let contents = String(file.contents);
|
|
2674
|
-
const copyModules = new Map();
|
|
2675
|
-
|
|
2676
|
-
try {
|
|
2677
|
-
try {
|
|
2678
|
-
contents = contents ? JSON.parse(contents) : {};
|
|
2679
|
-
} catch (e) {
|
|
2680
|
-
throw new Error(`解析${file.path}出现错误,请检查配置信息: ${e}`);
|
|
2681
|
-
}
|
|
2682
|
-
|
|
2683
|
-
if (contents.usingComponents) {
|
|
2684
|
-
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2685
|
-
const includePath = tmsConfig.dependencies[includeName];
|
|
2686
|
-
Object.keys(contents.usingComponents).forEach(componentKey => {
|
|
2687
|
-
const componentPath = contents.usingComponents[componentKey];
|
|
2688
|
-
|
|
2689
|
-
if (componentPath.indexOf(includeName) > -1) {
|
|
2690
|
-
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
|
|
2691
|
-
|
|
2692
|
-
const {
|
|
2693
|
-
ext: extAlias,
|
|
2694
|
-
file: depOriginFile,
|
|
2695
|
-
extPath
|
|
2696
|
-
} = ext$1(depOriginPath, extensions);
|
|
2697
|
-
const isFileInDir = fileInDir$1(includePath, depOriginFile);
|
|
2698
|
-
|
|
2699
|
-
if (!isFileInDir) {
|
|
2700
|
-
pluginError$1(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2701
|
-
return;
|
|
2702
|
-
} // eslint-disable-next-line
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2706
|
-
const regRes = componentPath.match(reg) || [];
|
|
2707
|
-
|
|
2708
|
-
if (regRes[2]) {
|
|
2709
|
-
const depDestPath = resolve$7(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2710
|
-
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2711
|
-
|
|
2712
|
-
if (!copyModules.has(depDestFile)) {
|
|
2713
|
-
copyModules.set(depDestFile, {
|
|
2714
|
-
depOriginFile,
|
|
2715
|
-
depOriginExt: extAlias,
|
|
2716
|
-
depDestFile,
|
|
2717
|
-
beforeDepPath: componentPath,
|
|
2718
|
-
afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2719
|
-
});
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
}
|
|
2723
|
-
});
|
|
2724
|
-
});
|
|
2725
|
-
}
|
|
2726
|
-
} catch (e) {
|
|
2727
|
-
pluginError$1(e, isWatch);
|
|
2728
|
-
} // console.log('json copyModules', copyModules);
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
copyModules.forEach(({
|
|
2732
|
-
depOriginFile,
|
|
2733
|
-
depOriginExt,
|
|
2734
|
-
depDestFile,
|
|
2735
|
-
beforeDepPath,
|
|
2736
|
-
afterDepPath
|
|
2737
|
-
}) => {
|
|
2738
|
-
// 拷贝当前依赖组件几个部分 wxml、wxss、wxs、json
|
|
2739
|
-
filesExt.forEach(extKey => {
|
|
2740
|
-
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2741
|
-
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2742
|
-
|
|
2743
|
-
if (fs$4.existsSync(originFile)) {
|
|
2744
|
-
diffContentCopyFile$1(originFile, destFile);
|
|
2745
|
-
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2746
|
-
|
|
2747
|
-
if (extensionsFilter.indexOf(extKey) > -1) {
|
|
2748
|
-
const defs = dfsFindCommonDep$1(originFile, destFile, extensionsFilter); // console.log('json defs', defs);
|
|
2749
|
-
|
|
2750
|
-
defs.forEach(item => {
|
|
2751
|
-
diffContentCopyFile$1(item.depOriginFile, item.depDestFile);
|
|
2752
|
-
});
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
});
|
|
2756
|
-
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
2757
|
-
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2758
|
-
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2759
|
-
});
|
|
2760
|
-
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
2761
|
-
file.contents = Buffer.from(contents);
|
|
2762
|
-
}
|
|
2763
|
-
|
|
2764
|
-
this.push(file);
|
|
2765
|
-
cb();
|
|
2766
|
-
});
|
|
2767
|
-
return stream;
|
|
2768
|
-
}
|
|
2769
|
-
|
|
2770
|
-
var mpJsonDep_1 = {
|
|
2771
|
-
mpJsonDep: mpJsonDep$1
|
|
2772
|
-
};
|
|
2773
|
-
|
|
2774
|
-
/* eslint-disable no-param-reassign */
|
|
2775
|
-
const through = require$$0__default$9;
|
|
2776
|
-
const htmlparser2 = require$$1__default$9;
|
|
2777
|
-
const fs$3 = require$$0__default$2;
|
|
2778
|
-
const path$3 = require$$1__default$2;
|
|
2779
|
-
const {
|
|
2780
|
-
diffContentCopyFile,
|
|
2781
|
-
ext,
|
|
2782
|
-
fileInDir
|
|
2783
|
-
} = io$3;
|
|
2784
|
-
const {
|
|
2785
|
-
resolve: resolve$6
|
|
2786
|
-
} = widgets;
|
|
2787
|
-
const {
|
|
2788
|
-
dfsFindCommonDep
|
|
2789
|
-
} = mpCommonDep_1;
|
|
2790
|
-
const {
|
|
2791
|
-
pluginError
|
|
2792
|
-
} = pluginError_1; // 处理后缀(源码引入依赖时,不带后缀的情况)
|
|
2793
|
-
|
|
2794
|
-
const extFile = function (name, file) {
|
|
2795
|
-
const extMap = {
|
|
2796
|
-
import: '.wxml',
|
|
2797
|
-
include: '.wxml',
|
|
2798
|
-
wxs: '.wxs'
|
|
2799
|
-
};
|
|
2800
|
-
let extObj = {};
|
|
2801
|
-
|
|
2802
|
-
if (Object.keys(extMap).indexOf(name) > -1 && !file.endsWith(extMap[name])) {
|
|
2803
|
-
extObj = ext(file, [extMap[name]]);
|
|
2804
|
-
}
|
|
2805
|
-
|
|
2806
|
-
return {
|
|
2807
|
-
extPath: extObj.extPath || '',
|
|
2808
|
-
ext: extObj.ext || '',
|
|
2809
|
-
file: extObj.file || file
|
|
2810
|
-
};
|
|
2811
|
-
};
|
|
2812
|
-
|
|
2813
|
-
const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = true) {
|
|
2814
|
-
const resDep = {
|
|
2815
|
-
image: new Map(),
|
|
2816
|
-
wxml: new Map(),
|
|
2817
|
-
wxs: new Map()
|
|
2818
|
-
};
|
|
2819
|
-
|
|
2820
|
-
function dfs(anaFileOriginFile, anaFileDestFile) {
|
|
2821
|
-
let contents = '';
|
|
2822
|
-
|
|
2823
|
-
try {
|
|
2824
|
-
contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
|
|
2825
|
-
} catch (e) {
|
|
2826
|
-
pluginError(e, isWatch);
|
|
2827
|
-
}
|
|
2828
|
-
|
|
2829
|
-
const parser = new htmlparser2.Parser({
|
|
2830
|
-
onopentag(name, attributes) {
|
|
2831
|
-
var _attributes$src;
|
|
2832
|
-
|
|
2833
|
-
if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
|
|
2834
|
-
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
|
|
2835
|
-
|
|
2836
|
-
const {
|
|
2837
|
-
ext,
|
|
2838
|
-
file: depOriginFile,
|
|
2839
|
-
extPath
|
|
2840
|
-
} = extFile(name, depOriginPath);
|
|
2841
|
-
|
|
2842
|
-
if (!fs$3.existsSync(depOriginFile)) {
|
|
2843
|
-
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2844
|
-
return;
|
|
2845
|
-
}
|
|
2846
|
-
|
|
2847
|
-
const depDestPath = path$3.join(path$3.dirname(anaFileDestFile), attributes.src);
|
|
2848
|
-
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
|
|
2849
|
-
|
|
2850
|
-
if (['import', 'include'].indexOf(name) > -1) {
|
|
2851
|
-
resDep.wxml.set(depDestFile, {
|
|
2852
|
-
anaFileOriginFile,
|
|
2853
|
-
anaFileDestFile,
|
|
2854
|
-
depDestFile,
|
|
2855
|
-
depOriginFile
|
|
2856
|
-
});
|
|
2857
|
-
dfs(depOriginFile, depDestFile);
|
|
2858
|
-
} // 收集image依赖
|
|
2859
|
-
// if (name === 'image') {
|
|
2860
|
-
// resDep.image.set(attributes.src, {
|
|
2861
|
-
// anaFileOriginFile,
|
|
2862
|
-
// anaFileDestFile,
|
|
2863
|
-
// depDestFile,
|
|
2864
|
-
// depOriginFile,
|
|
2865
|
-
// });
|
|
2866
|
-
// dfs(depOriginFile, depDestFile);
|
|
2867
|
-
// }
|
|
2868
|
-
// 收集wxs依赖
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
if (name === 'wxs') {
|
|
2872
|
-
resDep.wxs.set(depDestFile, {
|
|
2873
|
-
anaFileOriginFile,
|
|
2874
|
-
anaFileDestFile,
|
|
2875
|
-
depDestFile,
|
|
2876
|
-
depOriginFile
|
|
2877
|
-
});
|
|
2878
|
-
const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs']);
|
|
2879
|
-
defs.forEach((item, key) => {
|
|
2880
|
-
resDep.wxs.set(key, item);
|
|
2881
|
-
});
|
|
2882
|
-
}
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
|
|
2712
|
+
const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
|
|
2713
|
+
const {
|
|
2714
|
+
plugins = []
|
|
2715
|
+
} = tmsConfig;
|
|
2716
|
+
const newPlugins = [{
|
|
2717
|
+
glob: '**/project.config.json',
|
|
2718
|
+
action: mpProjectJson()
|
|
2719
|
+
}, ...plugins];
|
|
2720
|
+
return newPlugins.reduce((srcPipe, pluginItem) => srcPipe.pipe(gulpif(vinyl => minimatch(vinyl.path, pluginItem.glob), through.obj(function (vinyl, enc, next) {
|
|
2721
|
+
const sourceFile = vinyl.history[0];
|
|
2722
|
+
pluginItem.action({
|
|
2723
|
+
tmsConfig,
|
|
2724
|
+
sourceFile,
|
|
2725
|
+
vinyl,
|
|
2726
|
+
targetFile: getTargetFile$1(sourceFile, pluginParams.module, tmsConfig.outputDir),
|
|
2727
|
+
isDev: pluginParams.isDev,
|
|
2728
|
+
next
|
|
2886
2729
|
});
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
}
|
|
2890
|
-
|
|
2891
|
-
dfs(anaFileOriginFile, anaFileDestFile);
|
|
2892
|
-
return resDep;
|
|
2893
|
-
};
|
|
2894
|
-
|
|
2895
|
-
function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
2896
|
-
const stream = through.obj(function (file, enc, cb) {
|
|
2897
|
-
// 依赖分析的文件
|
|
2898
|
-
const anaFileOriginFile = file.history[0];
|
|
2899
|
-
const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
|
|
2900
|
-
const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2901
|
-
|
|
2902
|
-
if (file.isBuffer()) {
|
|
2903
|
-
let contents = String(file.contents);
|
|
2904
|
-
const copyModules = new Map();
|
|
2905
|
-
const parser = new htmlparser2.Parser({
|
|
2906
|
-
onopentag(name, attributes) {
|
|
2907
|
-
const nameFilter = ['import', 'include', 'wxs'];
|
|
2908
|
-
|
|
2909
|
-
if (nameFilter.indexOf(name) > -1 && attributes.src) {
|
|
2910
|
-
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
|
|
2911
|
-
|
|
2912
|
-
const {
|
|
2913
|
-
ext,
|
|
2914
|
-
file: depOriginFile,
|
|
2915
|
-
extPath
|
|
2916
|
-
} = extFile(name, depOriginPath);
|
|
2917
|
-
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2918
|
-
if (attributes.src.indexOf(includeName) > -1) {
|
|
2919
|
-
const includePath = tmsConfig.dependencies[includeName];
|
|
2920
|
-
|
|
2921
|
-
if (!fileInDir(includePath, depOriginFile)) {
|
|
2922
|
-
pluginError(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2923
|
-
return;
|
|
2924
|
-
} // eslint-disable-next-line
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2928
|
-
const regRes = attributes.src.match(reg) || [];
|
|
2929
|
-
|
|
2930
|
-
if (regRes[2]) {
|
|
2931
|
-
const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2932
|
-
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2933
|
-
|
|
2934
|
-
if (!copyModules.has(depDestFile)) {
|
|
2935
|
-
copyModules.set(depDestFile, {
|
|
2936
|
-
depOriginFile,
|
|
2937
|
-
depDestFile,
|
|
2938
|
-
beforeDepPath: attributes.src,
|
|
2939
|
-
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
|
|
2940
|
-
});
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
});
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
|
|
2948
|
-
});
|
|
2949
|
-
parser.write(contents);
|
|
2950
|
-
parser.end(); // console.log('wxml copyModules', copyModules);
|
|
2951
|
-
|
|
2952
|
-
copyModules.forEach(({
|
|
2953
|
-
depOriginFile,
|
|
2954
|
-
depDestFile,
|
|
2955
|
-
beforeDepPath,
|
|
2956
|
-
afterDepPath
|
|
2957
|
-
}) => {
|
|
2958
|
-
if (fs$3.existsSync(depOriginFile)) {
|
|
2959
|
-
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2960
|
-
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2961
|
-
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2962
|
-
}
|
|
2963
|
-
|
|
2964
|
-
if (depOriginFile.endsWith('.wxml')) {
|
|
2965
|
-
const defs = dfsFindWxmlDep(depOriginFile, depDestFile, isWatch); // console.log('wxml defs', defs);
|
|
2966
|
-
|
|
2967
|
-
[...defs.wxml, ...defs.wxs].forEach(([, item]) => {
|
|
2968
|
-
diffContentCopyFile(item.depOriginFile, item.depDestFile);
|
|
2969
|
-
});
|
|
2970
|
-
}
|
|
2971
|
-
|
|
2972
|
-
if (depOriginFile.endsWith('.wxs')) {
|
|
2973
|
-
const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs'], isWatch); // console.log('wxs defs', defs);
|
|
2974
|
-
|
|
2975
|
-
defs.forEach(item => {
|
|
2976
|
-
diffContentCopyFile(item.depOriginFile, item.depDestFile);
|
|
2977
|
-
});
|
|
2978
|
-
}
|
|
2979
|
-
});
|
|
2980
|
-
file.contents = Buffer.from(contents);
|
|
2981
|
-
}
|
|
2982
|
-
|
|
2983
|
-
this.push(file);
|
|
2984
|
-
cb();
|
|
2985
|
-
});
|
|
2986
|
-
return stream;
|
|
2987
|
-
}
|
|
2988
|
-
|
|
2989
|
-
var mpWxmlDep_1 = {
|
|
2990
|
-
mpWxmlDep: mpWxmlDep$1,
|
|
2991
|
-
dfsFindWxmlDep
|
|
2730
|
+
this.push(vinyl);
|
|
2731
|
+
}))), srcPipe);
|
|
2992
2732
|
};
|
|
2993
2733
|
|
|
2994
|
-
const {
|
|
2995
|
-
src: src$1,
|
|
2996
|
-
dest
|
|
2997
|
-
} = require$$0__default$a; // const px2rpx = require('gulp-px-to-rpx');
|
|
2998
|
-
// const cache = require('gulp-cache');
|
|
2999
|
-
// const image = require('gulp-image');
|
|
3000
|
-
// const replaceEnv = require('./plugins/replaceEnv');
|
|
3001
|
-
|
|
3002
|
-
const {
|
|
3003
|
-
mpCommonDep
|
|
3004
|
-
} = mpCommonDep_1;
|
|
3005
|
-
const {
|
|
3006
|
-
mpJsonDep
|
|
3007
|
-
} = mpJsonDep_1;
|
|
3008
|
-
const {
|
|
3009
|
-
mpWxmlDep
|
|
3010
|
-
} = mpWxmlDep_1; // const postcss = require('gulp-postcss');
|
|
3011
|
-
// const base64 = require('./plugins/postcss-font-base64');
|
|
3012
|
-
|
|
3013
|
-
const {
|
|
3014
|
-
fail: fail$2
|
|
3015
|
-
} = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
3016
|
-
|
|
3017
2734
|
var compile$1 = function (tmsConfig, {
|
|
3018
2735
|
glob,
|
|
3019
2736
|
destPath,
|
|
@@ -3022,122 +2739,21 @@ var compile$1 = function (tmsConfig, {
|
|
|
3022
2739
|
isDev
|
|
3023
2740
|
}) {
|
|
3024
2741
|
const compileTasksMap = new Map();
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
}).pipe(dest(newDestPath, {
|
|
3041
|
-
overwrite: true
|
|
3042
|
-
})).on('error', err => {
|
|
3043
|
-
fail$2(`js编译报错${err}`);
|
|
3044
|
-
});
|
|
3045
|
-
}
|
|
3046
|
-
});
|
|
3047
|
-
break;
|
|
3048
|
-
|
|
3049
|
-
case 'wxss':
|
|
3050
|
-
compileTasksMap.set(globValue, {
|
|
3051
|
-
module,
|
|
3052
|
-
taskFn: (sourceFile, targetPath) => {
|
|
3053
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
3054
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
3055
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
3056
|
-
});
|
|
3057
|
-
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
|
|
3058
|
-
fail$2(`mpCommonDep编译报错${err}`);
|
|
3059
|
-
}) // .pipe(postcss([base64()]))
|
|
3060
|
-
// .on('error', (err) => {
|
|
3061
|
-
// fail(`postcss编译报错${err}`);
|
|
3062
|
-
// })
|
|
3063
|
-
// .pipe(px2rpx({
|
|
3064
|
-
// designWidth: 375, // 设计稿宽度,默认为750
|
|
3065
|
-
// precision: 2, // 小数最大精度,默认为6
|
|
3066
|
-
// }))
|
|
3067
|
-
.pipe(dest(newDestPath)).on('error', err => {
|
|
3068
|
-
fail$2(`wxss编译报错${err}`);
|
|
3069
|
-
});
|
|
3070
|
-
}
|
|
3071
|
-
});
|
|
3072
|
-
break;
|
|
3073
|
-
|
|
3074
|
-
case 'json':
|
|
3075
|
-
compileTasksMap.set(globValue, {
|
|
3076
|
-
module,
|
|
3077
|
-
taskFn: (sourceFile, targetPath) => {
|
|
3078
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
3079
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
3080
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
3081
|
-
});
|
|
3082
|
-
return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
|
|
3083
|
-
fail$2(`mpJsonDep编译报错${err}`);
|
|
3084
|
-
}).pipe(dest(newDestPath)).on('error', err => {
|
|
3085
|
-
fail$2(`json编译报错${err}`);
|
|
3086
|
-
});
|
|
3087
|
-
}
|
|
3088
|
-
});
|
|
3089
|
-
break;
|
|
3090
|
-
|
|
3091
|
-
case 'wxml':
|
|
3092
|
-
compileTasksMap.set(globValue, {
|
|
3093
|
-
module,
|
|
3094
|
-
taskFn: (sourceFile, targetPath) => {
|
|
3095
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
3096
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
3097
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
3098
|
-
});
|
|
3099
|
-
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
|
|
3100
|
-
fail$2(`mpWxmlDep编译报错${err}`);
|
|
3101
|
-
}).pipe(dest(newDestPath)).on('error', err => {
|
|
3102
|
-
fail$2(`wxml编译报错${err}`);
|
|
3103
|
-
});
|
|
3104
|
-
}
|
|
3105
|
-
});
|
|
3106
|
-
break;
|
|
3107
|
-
|
|
3108
|
-
case 'image':
|
|
3109
|
-
compileTasksMap.set(globValue, {
|
|
3110
|
-
module,
|
|
3111
|
-
taskFn: (sourceFile, targetPath) => {
|
|
3112
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
3113
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
3114
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
3115
|
-
});
|
|
3116
|
-
return srcPipe // .pipe(cache(image()))
|
|
3117
|
-
// .on('error', (err) => {
|
|
3118
|
-
// fail(`image编译报错${err}`);
|
|
3119
|
-
// })
|
|
3120
|
-
.pipe(dest(newDestPath)).on('error', err => {
|
|
3121
|
-
fail$2(`image编译报错${err}`);
|
|
3122
|
-
});
|
|
3123
|
-
}
|
|
3124
|
-
});
|
|
3125
|
-
break;
|
|
3126
|
-
|
|
3127
|
-
case 'other':
|
|
3128
|
-
compileTasksMap.set(globValue, {
|
|
3129
|
-
module,
|
|
3130
|
-
taskFn: (sourceFile, targetPath) => {
|
|
3131
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
3132
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
3133
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
3134
|
-
});
|
|
3135
|
-
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
3136
|
-
fail$2(`编译报错${err}`);
|
|
3137
|
-
});
|
|
3138
|
-
}
|
|
3139
|
-
});
|
|
3140
|
-
break;
|
|
2742
|
+
compileTasksMap.set(glob, {
|
|
2743
|
+
module,
|
|
2744
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2745
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : glob;
|
|
2746
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2747
|
+
let srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2748
|
+
});
|
|
2749
|
+
const pluginParams = {
|
|
2750
|
+
module,
|
|
2751
|
+
isDev
|
|
2752
|
+
};
|
|
2753
|
+
srcPipe = addPlugins(tmsConfig, srcPipe, pluginParams);
|
|
2754
|
+
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
2755
|
+
fail$2(`编译报错${err}`);
|
|
2756
|
+
});
|
|
3141
2757
|
}
|
|
3142
2758
|
});
|
|
3143
2759
|
return compileTasksMap;
|
|
@@ -3146,18 +2762,18 @@ var compile$1 = function (tmsConfig, {
|
|
|
3146
2762
|
/* eslint-disable */
|
|
3147
2763
|
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
3148
2764
|
|
|
3149
|
-
const assign = require$$0__default$
|
|
3150
|
-
const path$
|
|
3151
|
-
const PluginError = require$$2__default$
|
|
3152
|
-
const fancyLog = require$$3__default;
|
|
3153
|
-
const colors = require$$4__default;
|
|
2765
|
+
const assign = require$$0__default$8;
|
|
2766
|
+
const path$5 = require$$1__default$1;
|
|
2767
|
+
const PluginError = require$$2__default$2;
|
|
2768
|
+
const fancyLog = require$$3__default$2;
|
|
2769
|
+
const colors = require$$4__default$1;
|
|
3154
2770
|
const chokidar = require$$5__default;
|
|
3155
2771
|
const {
|
|
3156
2772
|
Duplex
|
|
3157
2773
|
} = require$$6__default$1;
|
|
3158
2774
|
const vinyl = require$$7__default;
|
|
3159
2775
|
const File = require$$8__default;
|
|
3160
|
-
const anymatch = require$$9__default
|
|
2776
|
+
const anymatch = require$$9__default;
|
|
3161
2777
|
const pathIsAbsolute = require$$10__default$1;
|
|
3162
2778
|
const globParent = require$$11__default;
|
|
3163
2779
|
const slash = require$$12__default;
|
|
@@ -3192,10 +2808,10 @@ function watch$2(globs, opts, cb) {
|
|
|
3192
2808
|
|
|
3193
2809
|
function resolveFilepath(filepath) {
|
|
3194
2810
|
if (pathIsAbsolute(filepath)) {
|
|
3195
|
-
return path$
|
|
2811
|
+
return path$5.normalize(filepath);
|
|
3196
2812
|
}
|
|
3197
2813
|
|
|
3198
|
-
return path$
|
|
2814
|
+
return path$5.resolve(opts.cwd || process.cwd(), filepath);
|
|
3199
2815
|
}
|
|
3200
2816
|
|
|
3201
2817
|
function resolveGlob(glob) {
|
|
@@ -3251,7 +2867,7 @@ function watch$2(globs, opts, cb) {
|
|
|
3251
2867
|
let glob;
|
|
3252
2868
|
let currentFilepath = filepath;
|
|
3253
2869
|
|
|
3254
|
-
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$
|
|
2870
|
+
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$5.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
3255
2871
|
|
|
3256
2872
|
|
|
3257
2873
|
if (!glob) {
|
|
@@ -3260,7 +2876,7 @@ function watch$2(globs, opts, cb) {
|
|
|
3260
2876
|
}
|
|
3261
2877
|
|
|
3262
2878
|
if (!baseForced) {
|
|
3263
|
-
fileOpts.base = path$
|
|
2879
|
+
fileOpts.base = path$5.normalize(globParent(glob));
|
|
3264
2880
|
} // Do not stat deleted files
|
|
3265
2881
|
|
|
3266
2882
|
|
|
@@ -3320,25 +2936,27 @@ var gulpWatch = watch$2;
|
|
|
3320
2936
|
|
|
3321
2937
|
/* eslint-disable no-restricted-syntax */
|
|
3322
2938
|
const watch$1 = gulpWatch;
|
|
3323
|
-
const path$
|
|
3324
|
-
const shellJs = require$$
|
|
2939
|
+
const path$4 = require$$1__default$1;
|
|
2940
|
+
const shellJs = require$$2__default;
|
|
2941
|
+
const {
|
|
2942
|
+
series: series$1
|
|
2943
|
+
} = require$$0__default$7;
|
|
3325
2944
|
const {
|
|
3326
|
-
info: info$
|
|
2945
|
+
info: info$7,
|
|
3327
2946
|
warn: warn$1,
|
|
3328
2947
|
fail: fail$1
|
|
3329
2948
|
} = log$1;
|
|
3330
2949
|
const {
|
|
3331
|
-
resolve: resolve$
|
|
2950
|
+
resolve: resolve$7,
|
|
2951
|
+
filterField: filterField$5
|
|
3332
2952
|
} = widgets;
|
|
3333
2953
|
const {
|
|
3334
|
-
global: global$
|
|
2954
|
+
global: global$6
|
|
3335
2955
|
} = global_1;
|
|
3336
2956
|
const {
|
|
3337
2957
|
checkPackageVersion
|
|
3338
2958
|
} = checkDependencies;
|
|
3339
|
-
const
|
|
3340
|
-
findAllFilesOfDir
|
|
3341
|
-
} = io$3;
|
|
2959
|
+
const report$7 = report_1;
|
|
3342
2960
|
const TIP_MAP = {
|
|
3343
2961
|
'package.json': {
|
|
3344
2962
|
tip: '依赖版本有变动,请重新执行tmskit run dev',
|
|
@@ -3367,15 +2985,15 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
|
|
|
3367
2985
|
}
|
|
3368
2986
|
}
|
|
3369
2987
|
|
|
3370
|
-
info$
|
|
2988
|
+
info$7(`${fileName}有更新`);
|
|
3371
2989
|
} catch (e) {
|
|
3372
2990
|
fail$1(`${sourceFile}文件更新提示出现错误: ${e.message}`);
|
|
3373
2991
|
}
|
|
3374
2992
|
};
|
|
3375
2993
|
|
|
3376
2994
|
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
3377
|
-
const sourceFileRelativeModule = path$
|
|
3378
|
-
const targetFile = resolve$
|
|
2995
|
+
const sourceFileRelativeModule = path$4.relative(resolve$7(module.from), sourceFile);
|
|
2996
|
+
const targetFile = resolve$7(outputDir, module.to, sourceFileRelativeModule);
|
|
3379
2997
|
return targetFile;
|
|
3380
2998
|
};
|
|
3381
2999
|
|
|
@@ -3386,96 +3004,106 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3386
3004
|
const sourceFile = vinyl.history[0];
|
|
3387
3005
|
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
3388
3006
|
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
3389
|
-
const tmsConfig = global$
|
|
3390
|
-
|
|
3391
|
-
if (vinyl.event === 'addDir') {
|
|
3392
|
-
info$5(`更新${sourceFileName}目录`);
|
|
3393
|
-
const files = findAllFilesOfDir(sourceFile);
|
|
3394
|
-
|
|
3395
|
-
for (const file of files) {
|
|
3396
|
-
const fileDirArr = file.replace(/\\/g, '/').split('/');
|
|
3397
|
-
const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
|
|
3398
|
-
const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
|
|
3399
|
-
logTip(fileName, sourceFile, targetFile, TIP_MAP);
|
|
3400
|
-
callback([file], path$1.dirname(targetFile));
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
|
-
return;
|
|
3404
|
-
}
|
|
3405
|
-
|
|
3007
|
+
const tmsConfig = global$6.getData('tmsConfig');
|
|
3406
3008
|
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
3407
3009
|
|
|
3408
3010
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
3409
|
-
info$
|
|
3011
|
+
info$7(`删除${sourceFileName}`);
|
|
3410
3012
|
shellJs.rm('-rf', targetFile);
|
|
3013
|
+
updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
|
|
3411
3014
|
return;
|
|
3412
3015
|
}
|
|
3413
3016
|
|
|
3017
|
+
runCallback({
|
|
3018
|
+
tmsConfig,
|
|
3019
|
+
sourceFile,
|
|
3020
|
+
targetFile,
|
|
3021
|
+
callback,
|
|
3022
|
+
type: vinyl.event
|
|
3023
|
+
});
|
|
3414
3024
|
logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
|
|
3415
|
-
return callback([sourceFile], path$1.dirname(targetFile));
|
|
3416
3025
|
});
|
|
3417
|
-
};
|
|
3026
|
+
}; // 开始执行watch 文件的 callback函数
|
|
3027
|
+
|
|
3028
|
+
|
|
3029
|
+
async function runCallback({
|
|
3030
|
+
tmsConfig,
|
|
3031
|
+
sourceFile,
|
|
3032
|
+
targetFile,
|
|
3033
|
+
callback,
|
|
3034
|
+
type
|
|
3035
|
+
}) {
|
|
3036
|
+
// callbacl.name === taskFn 代表进入gulp编译流程
|
|
3037
|
+
// series为gulp编译串行执行,callback执行完毕后,执行updateFileHooks钩子
|
|
3038
|
+
if (callback.name === 'taskFn') {
|
|
3039
|
+
series$1(callback.bind(null, [sourceFile], path$4.dirname(targetFile)), cb => {
|
|
3040
|
+
cb();
|
|
3041
|
+
updateFileHook(tmsConfig, sourceFile, targetFile, type);
|
|
3042
|
+
})();
|
|
3043
|
+
} else {
|
|
3044
|
+
// 普通的callback函数
|
|
3045
|
+
await callback([sourceFile], path$4.dirname(targetFile));
|
|
3046
|
+
await updateFileHook(tmsConfig, sourceFile, targetFile, type);
|
|
3047
|
+
}
|
|
3048
|
+
} // 执行源码文件更新的钩子
|
|
3049
|
+
|
|
3050
|
+
|
|
3051
|
+
async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
|
|
3052
|
+
var _tmsConfig$hooks;
|
|
3418
3053
|
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3054
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateFile) === 'function') {
|
|
3055
|
+
await tmsConfig.hooks.updateFile({
|
|
3056
|
+
tmsConfig: filterField$5(tmsConfig, ['gitAccount']),
|
|
3057
|
+
cmdOptions: global$6.getData('cmdOptions'),
|
|
3058
|
+
sourceFile,
|
|
3059
|
+
targetFile,
|
|
3060
|
+
type
|
|
3061
|
+
});
|
|
3062
|
+
report$7('hooks:updateFile');
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3066
|
+
const path$3 = require$$1__default$1;
|
|
3067
|
+
const fs$5 = require$$0__default$1;
|
|
3068
|
+
const ora = require$$0__default;
|
|
3069
|
+
const chalk$3 = require$$3__default;
|
|
3423
3070
|
const {
|
|
3424
3071
|
parallel,
|
|
3425
3072
|
series
|
|
3426
|
-
} = require$$0__default$
|
|
3073
|
+
} = require$$0__default$7;
|
|
3427
3074
|
const {
|
|
3428
|
-
resolve: resolve$
|
|
3075
|
+
resolve: resolve$6,
|
|
3429
3076
|
mergeMap,
|
|
3430
|
-
filterField: filterField$
|
|
3431
|
-
getAbsolutePath
|
|
3077
|
+
filterField: filterField$4,
|
|
3078
|
+
getAbsolutePath: getAbsolutePath$2
|
|
3432
3079
|
} = widgets;
|
|
3433
3080
|
const {
|
|
3434
3081
|
buildOutputAppJson
|
|
3435
3082
|
} = buildAppJson;
|
|
3436
3083
|
const {
|
|
3437
3084
|
DEFAULT_COPY_CONFIG
|
|
3438
|
-
} =
|
|
3085
|
+
} = constant;
|
|
3439
3086
|
const compile = compile$1;
|
|
3440
3087
|
const watch = watch_1;
|
|
3441
3088
|
const {
|
|
3442
|
-
info: info$
|
|
3089
|
+
info: info$6
|
|
3443
3090
|
} = log$1;
|
|
3091
|
+
const report$6 = report_1;
|
|
3092
|
+
const {
|
|
3093
|
+
global: global$5
|
|
3094
|
+
} = global_1;
|
|
3444
3095
|
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
3445
3096
|
|
|
3446
|
-
function excludeGlob(glob) {
|
|
3447
|
-
const otherArr = new Set();
|
|
3448
|
-
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
3449
|
-
Object.keys(glob).forEach(globKey => {
|
|
3450
|
-
if (typeof glob[globKey] === 'string') {
|
|
3451
|
-
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
3452
|
-
otherArr.add(data);
|
|
3453
|
-
}
|
|
3454
|
-
|
|
3455
|
-
if (Array.isArray(glob[globKey])) {
|
|
3456
|
-
glob[globKey].forEach(value => {
|
|
3457
|
-
if (typeof value === 'string') {
|
|
3458
|
-
const data = value.startsWith('!') ? value : `!${value}`;
|
|
3459
|
-
otherArr.add(data);
|
|
3460
|
-
}
|
|
3461
|
-
});
|
|
3462
|
-
}
|
|
3463
|
-
});
|
|
3464
|
-
return Array.from(otherArr);
|
|
3465
|
-
}
|
|
3466
|
-
|
|
3467
3097
|
var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
3468
3098
|
const compileTasksMap = new Map(); // 监听根目录的文件
|
|
3469
3099
|
|
|
3470
3100
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3471
|
-
glob:
|
|
3472
|
-
json: DEFAULT_COPY_CONFIG.map(item => resolve$4(item))
|
|
3473
|
-
},
|
|
3101
|
+
glob: DEFAULT_COPY_CONFIG.map(item => resolve$6(item)),
|
|
3474
3102
|
module: {
|
|
3475
|
-
from: resolve$
|
|
3476
|
-
to: resolve$
|
|
3103
|
+
from: resolve$6(),
|
|
3104
|
+
to: resolve$6(tmsConfig.outputDir)
|
|
3477
3105
|
},
|
|
3478
|
-
destPath: resolve$
|
|
3106
|
+
destPath: resolve$6(tmsConfig.outputDir),
|
|
3479
3107
|
srcOption: {
|
|
3480
3108
|
allowEmpty: true
|
|
3481
3109
|
},
|
|
@@ -3489,8 +3117,8 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3489
3117
|
},
|
|
3490
3118
|
...moduleItem
|
|
3491
3119
|
};
|
|
3492
|
-
const srcModulePath = getAbsolutePath(moduleItem.path);
|
|
3493
|
-
const buildModulePath = resolve$
|
|
3120
|
+
const srcModulePath = getAbsolutePath$2(moduleItem.path);
|
|
3121
|
+
const buildModulePath = resolve$6(tmsConfig.outputDir, moduleItem.modulePath);
|
|
3494
3122
|
|
|
3495
3123
|
if (isDev) {
|
|
3496
3124
|
// 监听模块配置文件
|
|
@@ -3503,26 +3131,17 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3503
3131
|
}
|
|
3504
3132
|
|
|
3505
3133
|
const excludes = moduleItem.exclude.map(ePath => {
|
|
3506
|
-
const newPath = getAbsolutePath(ePath, srcModulePath);
|
|
3507
|
-
const ext = path.extname(ePath).slice(1);
|
|
3134
|
+
const newPath = getAbsolutePath$2(ePath, srcModulePath);
|
|
3135
|
+
const ext = path$3.extname(ePath).slice(1);
|
|
3508
3136
|
|
|
3509
3137
|
if (ext) {
|
|
3510
|
-
return `!${resolve$
|
|
3138
|
+
return `!${resolve$6(srcModulePath, newPath)}`;
|
|
3511
3139
|
}
|
|
3512
3140
|
|
|
3513
|
-
return `!${resolve$
|
|
3141
|
+
return `!${resolve$6(srcModulePath, newPath)}/**/*`;
|
|
3514
3142
|
});
|
|
3515
|
-
const glob = {
|
|
3516
|
-
js: [`${srcModulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
3517
|
-
json: [`${srcModulePath}/**/*.json`, `!${srcModulePath}/**/module.config.json`, ...excludes],
|
|
3518
|
-
wxss: [`${srcModulePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
|
|
3519
|
-
wxml: [`${srcModulePath}/**/*.wxml`, ...excludes],
|
|
3520
|
-
image: [`${srcModulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
3521
|
-
};
|
|
3522
3143
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3523
|
-
glob: { ...
|
|
3524
|
-
other: [`${srcModulePath}/**/*`, ...excludeGlob(glob)]
|
|
3525
|
-
},
|
|
3144
|
+
glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
|
|
3526
3145
|
destPath: buildModulePath,
|
|
3527
3146
|
module: {
|
|
3528
3147
|
from: srcModulePath,
|
|
@@ -3533,30 +3152,23 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3533
3152
|
},
|
|
3534
3153
|
isDev
|
|
3535
3154
|
}));
|
|
3536
|
-
} //
|
|
3155
|
+
} // static静态资源目录
|
|
3537
3156
|
|
|
3538
3157
|
|
|
3539
3158
|
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
3540
3159
|
for (const item of tmsConfig.static) {
|
|
3541
|
-
item.from = getAbsolutePath(item.from);
|
|
3542
|
-
item.to = getAbsolutePath(item.to);
|
|
3160
|
+
item.from = getAbsolutePath$2(item.from);
|
|
3161
|
+
item.to = getAbsolutePath$2(item.to);
|
|
3543
3162
|
let glob = {};
|
|
3544
|
-
const ext = path.extname(item.from).slice(1);
|
|
3163
|
+
const ext = path$3.extname(item.from).slice(1);
|
|
3545
3164
|
|
|
3546
3165
|
if (ext) {
|
|
3547
|
-
glob
|
|
3166
|
+
glob = [item.from];
|
|
3548
3167
|
} else {
|
|
3549
|
-
glob = {
|
|
3550
|
-
js: [`${item.from}/**/*.{js,ts,wxs}`],
|
|
3551
|
-
json: [`${item.from}/**/*.json`],
|
|
3552
|
-
wxss: [`${item.from}/**/*.{less,wxss,scss,sass,styl}`],
|
|
3553
|
-
wxml: [`${item.from}/**/*.wxml`],
|
|
3554
|
-
image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
|
|
3555
|
-
};
|
|
3556
|
-
glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
|
|
3168
|
+
glob = [`${item.from}/**/*`];
|
|
3557
3169
|
}
|
|
3558
3170
|
|
|
3559
|
-
const from = fs$
|
|
3171
|
+
const from = fs$5.lstatSync(item.from).isFile() ? path$3.dirname(item.from) : item.from;
|
|
3560
3172
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3561
3173
|
glob,
|
|
3562
3174
|
destPath: item.to,
|
|
@@ -3577,7 +3189,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3577
3189
|
const spinner = ora();
|
|
3578
3190
|
|
|
3579
3191
|
function start(cb) {
|
|
3580
|
-
info$
|
|
3192
|
+
info$6('启动编译...');
|
|
3581
3193
|
spinner.start();
|
|
3582
3194
|
sTime = new Date().getTime();
|
|
3583
3195
|
cb();
|
|
@@ -3588,12 +3200,12 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3588
3200
|
|
|
3589
3201
|
if (isDev) {
|
|
3590
3202
|
// 监听app.json
|
|
3591
|
-
watch([resolve$
|
|
3203
|
+
watch([resolve$6('app.json')], {
|
|
3592
3204
|
ignoreInitial: false,
|
|
3593
3205
|
events: watchEvents
|
|
3594
3206
|
}, () => buildOutputAppJson(tmsConfig, modules, isDev), {
|
|
3595
|
-
from: resolve$
|
|
3596
|
-
to: resolve$
|
|
3207
|
+
from: resolve$6(),
|
|
3208
|
+
to: resolve$6(tmsConfig.outputDir)
|
|
3597
3209
|
}); // 监听其他文件
|
|
3598
3210
|
|
|
3599
3211
|
compileTasksMap.forEach(({
|
|
@@ -3611,17 +3223,19 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3611
3223
|
|
|
3612
3224
|
eTime = new Date().getTime() - sTime;
|
|
3613
3225
|
|
|
3614
|
-
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.
|
|
3226
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterFirstCompile) === 'function') {
|
|
3615
3227
|
var _tmsConfig$hooks2;
|
|
3616
3228
|
|
|
3617
|
-
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.
|
|
3229
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterFirstCompile({
|
|
3618
3230
|
isDev,
|
|
3619
|
-
tmsConfig: filterField$
|
|
3620
|
-
modules
|
|
3231
|
+
tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
|
|
3232
|
+
modules,
|
|
3233
|
+
cmdOptions: global$5.getData('cmdOptions')
|
|
3621
3234
|
}));
|
|
3235
|
+
report$6('hooks:afterCompile');
|
|
3622
3236
|
}
|
|
3623
3237
|
|
|
3624
|
-
spinner.succeed(chalk$
|
|
3238
|
+
spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
3625
3239
|
spinner.stop();
|
|
3626
3240
|
cb();
|
|
3627
3241
|
}
|
|
@@ -3636,36 +3250,266 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3636
3250
|
series(start, parallel(...compileTasks), end)();
|
|
3637
3251
|
};
|
|
3638
3252
|
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3253
|
+
var require$$12 = {
|
|
3254
|
+
name: "@tmsfe/tmskit",
|
|
3255
|
+
version: "0.0.24",
|
|
3256
|
+
description: "tmskit",
|
|
3257
|
+
main: "dist/index.cjs",
|
|
3258
|
+
bin: {
|
|
3259
|
+
tmskit: "main.js"
|
|
3260
|
+
},
|
|
3261
|
+
files: [
|
|
3262
|
+
"build",
|
|
3263
|
+
"src",
|
|
3264
|
+
"dist",
|
|
3265
|
+
"main.js",
|
|
3266
|
+
"package.json"
|
|
3267
|
+
],
|
|
3268
|
+
scripts: {
|
|
3269
|
+
dev: "rollup -wc --environment TARGET:tmskit",
|
|
3270
|
+
build: "rollup -c --environment TARGET:tmskit",
|
|
3271
|
+
"pub:patch": "sh build/publish.sh patch",
|
|
3272
|
+
"pub:minor": "sh build/publish.sh minor",
|
|
3273
|
+
"pub:major": "sh build/publish.sh major"
|
|
3274
|
+
},
|
|
3275
|
+
author: "tms·web",
|
|
3276
|
+
license: "ISC",
|
|
3277
|
+
buildOptions: {
|
|
3278
|
+
formats: [
|
|
3279
|
+
"cjs"
|
|
3280
|
+
]
|
|
3281
|
+
},
|
|
3282
|
+
devDependencies: {
|
|
3283
|
+
"@rollup/plugin-babel": "^5.0.2",
|
|
3284
|
+
"@rollup/plugin-commonjs": "^19.0.0",
|
|
3285
|
+
"@rollup/plugin-json": "^4.0.3",
|
|
3286
|
+
rollup: "^2.6.1"
|
|
3287
|
+
},
|
|
3288
|
+
dependencies: {
|
|
3289
|
+
"ansi-colors": "1.1.0",
|
|
3290
|
+
anymatch: "^1.3.0",
|
|
3291
|
+
async: "^3.2.2",
|
|
3292
|
+
chalk: "^4.1.0",
|
|
3293
|
+
chokidar: "^3.5.3",
|
|
3294
|
+
commander: "^8.3.0",
|
|
3295
|
+
"copy-webpack-plugin": "^9.1.0",
|
|
3296
|
+
ejs: "^3.1.5",
|
|
3297
|
+
"fancy-log": "1.3.2",
|
|
3298
|
+
"fs-extra": "^10.0.1",
|
|
3299
|
+
"glob-ignore": "^1.0.2",
|
|
3300
|
+
"glob-parent": "^3.0.1",
|
|
3301
|
+
gulp: "^4.0.2",
|
|
3302
|
+
"gulp-if": "^3.0.0",
|
|
3303
|
+
"gulp-watch": "^5.0.1",
|
|
3304
|
+
htmlparser2: "^7.2.0",
|
|
3305
|
+
inquirer: "^7.3.3",
|
|
3306
|
+
leven: "3.1.0",
|
|
3307
|
+
lodash: "^4.17.21",
|
|
3308
|
+
metalsmith: "^2.3.0",
|
|
3309
|
+
minimatch: "^5.1.0",
|
|
3310
|
+
"miniprogram-ci": "1.8.25",
|
|
3311
|
+
moment: "^2.29.2",
|
|
3312
|
+
"object-assign": "^4.0.1",
|
|
3313
|
+
ora: "^5.1.0",
|
|
3314
|
+
"path-is-absolute": "^1.0.1",
|
|
3315
|
+
"plugin-error": "^1.0.0",
|
|
3316
|
+
postcss: "^8.4.6",
|
|
3317
|
+
precinct: "^8.3.1",
|
|
3318
|
+
"readable-stream": "^2.2.2",
|
|
3319
|
+
"replace-ext": "^2.0.0",
|
|
3320
|
+
request: "^2.88.2",
|
|
3321
|
+
shelljs: "^0.8.4",
|
|
3322
|
+
slash: "^1.0.0",
|
|
3323
|
+
"strip-comments": "^2.0.1",
|
|
3324
|
+
through2: "^4.0.2",
|
|
3325
|
+
unzipper: "^0.10.11",
|
|
3326
|
+
vinyl: "^2.1.0",
|
|
3327
|
+
"vinyl-file": "^2.0.0",
|
|
3328
|
+
"vinyl-sourcemaps-apply": "^0.2.0"
|
|
3329
|
+
},
|
|
3330
|
+
engines: {
|
|
3331
|
+
node: "^12.17.0 || >= 14.13.1"
|
|
3332
|
+
},
|
|
3333
|
+
jest: {
|
|
3334
|
+
testEnvironment: "jest-environment-node"
|
|
3335
|
+
}
|
|
3336
|
+
};
|
|
3337
|
+
|
|
3338
|
+
const fs$4 = require$$0__default$1;
|
|
3339
|
+
const path$2 = require$$1__default$1;
|
|
3340
|
+
const shelljs$2 = require$$2__default;
|
|
3341
|
+
const chalk$2 = require$$3__default;
|
|
3342
|
+
const request = require$$0__default$5;
|
|
3343
|
+
const inquirer = require$$1__default$4;
|
|
3344
|
+
const {
|
|
3345
|
+
infoNoTime: infoNoTime$1
|
|
3346
|
+
} = log$1;
|
|
3347
|
+
const packageJson$1 = require$$12;
|
|
3348
|
+
const {
|
|
3349
|
+
VERSION_CACHE_FILE,
|
|
3350
|
+
VERSION_URL
|
|
3351
|
+
} = constant;
|
|
3352
|
+
const {
|
|
3353
|
+
ensureDirExist: ensureDirExist$2
|
|
3354
|
+
} = io$3;
|
|
3355
|
+
const {
|
|
3356
|
+
versionCompare
|
|
3357
|
+
} = widgets; // 获取推荐的tmskit版本
|
|
3358
|
+
|
|
3359
|
+
function getRecommendVersion() {
|
|
3360
|
+
return new Promise((resolve, reject) => {
|
|
3361
|
+
request(`${VERSION_URL}?v=${new Date().getTime()}`, (error, response, body) => {
|
|
3362
|
+
if (!error && response && response.statusCode === 200) {
|
|
3363
|
+
resolve(JSON.parse(body));
|
|
3364
|
+
} else {
|
|
3365
|
+
reject(response.statusCode);
|
|
3366
|
+
}
|
|
3367
|
+
});
|
|
3368
|
+
});
|
|
3369
|
+
} // 获取当前用户tmskit的版本
|
|
3370
|
+
|
|
3371
|
+
|
|
3372
|
+
function getUserTmskitVersion() {
|
|
3373
|
+
const data = shelljs$2.exec('tmskit -v', {
|
|
3374
|
+
async: false,
|
|
3375
|
+
silent: true
|
|
3376
|
+
});
|
|
3377
|
+
|
|
3378
|
+
if (data.code === 0) {
|
|
3379
|
+
// tmskit 0.0.21 => 0.0.21
|
|
3380
|
+
return data.slice(7);
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
return '0.0.0';
|
|
3384
|
+
} // 询问用户是否安装最新版本
|
|
3385
|
+
|
|
3386
|
+
|
|
3387
|
+
function isInstallLatestVersion() {
|
|
3388
|
+
return inquirer.prompt([{
|
|
3389
|
+
type: 'confirm',
|
|
3390
|
+
name: 'isInstall',
|
|
3391
|
+
message: '是否安装最新版本',
|
|
3392
|
+
choices: [{
|
|
3393
|
+
name: '否',
|
|
3394
|
+
value: false
|
|
3395
|
+
}, {
|
|
3396
|
+
name: '是',
|
|
3397
|
+
value: true
|
|
3398
|
+
}]
|
|
3399
|
+
}]);
|
|
3400
|
+
} // 获取tmskit的版本是否推荐过
|
|
3401
|
+
|
|
3402
|
+
|
|
3403
|
+
function getVersionIsRecommend(version) {
|
|
3404
|
+
const filePath = VERSION_CACHE_FILE;
|
|
3405
|
+
|
|
3406
|
+
if (!fs$4.existsSync(filePath)) {
|
|
3407
|
+
return false;
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
const content = require(filePath);
|
|
3411
|
+
|
|
3412
|
+
return content === null || content === void 0 ? void 0 : content[version];
|
|
3413
|
+
} // 设置tmskit版本推荐过
|
|
3414
|
+
|
|
3415
|
+
|
|
3416
|
+
function setVersionRecommend(version, isRecommend) {
|
|
3417
|
+
const filePath = VERSION_CACHE_FILE;
|
|
3418
|
+
|
|
3419
|
+
if (!fs$4.existsSync(filePath)) {
|
|
3420
|
+
const dir = path$2.dirname(filePath);
|
|
3421
|
+
ensureDirExist$2(dir);
|
|
3422
|
+
fs$4.writeFileSync(filePath, '{}');
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
const content = require(filePath);
|
|
3426
|
+
|
|
3427
|
+
content[version] = isRecommend;
|
|
3428
|
+
fs$4.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
3429
|
+
} // 推荐理由
|
|
3430
|
+
|
|
3431
|
+
|
|
3432
|
+
function displayRecommends(arr = []) {
|
|
3433
|
+
infoNoTime$1(chalk$2.green('构建工具有新的版本~~:'));
|
|
3434
|
+
arr.forEach(item => {
|
|
3435
|
+
infoNoTime$1(chalk$2.green(item));
|
|
3436
|
+
});
|
|
3437
|
+
} // 推荐tmskit的安装版本
|
|
3438
|
+
|
|
3439
|
+
|
|
3440
|
+
async function recommendVersion$1() {
|
|
3441
|
+
try {
|
|
3442
|
+
// 获取当前用户安装的版本
|
|
3443
|
+
const tmskitVersion = getUserTmskitVersion(); // 获取官方推荐版本
|
|
3444
|
+
|
|
3445
|
+
const recommendRes = await getRecommendVersion();
|
|
3446
|
+
const recommendVersion = recommendRes.version; // 当前用户安装版本小于官方推荐版本 && 该版本没有推荐过
|
|
3447
|
+
|
|
3448
|
+
if (versionCompare(tmskitVersion, recommendVersion) === -1 && !getVersionIsRecommend(recommendVersion)) {
|
|
3449
|
+
displayRecommends(recommendRes.version_detail); // 设置该版本推荐过
|
|
3450
|
+
|
|
3451
|
+
setVersionRecommend(recommendVersion, true); // 询问用户是否安装最新版本
|
|
3452
|
+
|
|
3453
|
+
const installRes = await isInstallLatestVersion(recommendRes);
|
|
3454
|
+
|
|
3455
|
+
if (installRes.isInstall) {
|
|
3456
|
+
// mac
|
|
3457
|
+
if (process.platform === 'darwin') {
|
|
3458
|
+
infoNoTime$1(`将执行以下命令: ${chalk$2.green(`sudo npm install -g ${packageJson$1.name}@${recommendVersion}`)}`);
|
|
3459
|
+
shelljs$2.exec(`sudo npm install -g ${packageJson$1.name}@${recommendVersion}`, {
|
|
3460
|
+
async: false,
|
|
3461
|
+
silent: false
|
|
3462
|
+
});
|
|
3463
|
+
process.exit(-1);
|
|
3464
|
+
} else {
|
|
3465
|
+
// window
|
|
3466
|
+
infoNoTime$1(`请使用超级管理员执行以下命令: ${chalk$2.green(`npm install -g ${packageJson$1.name}@${recommendVersion}`)}`);
|
|
3467
|
+
process.exit(-1);
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
} catch {}
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
var recommendVersion_1 = {
|
|
3475
|
+
recommendVersion: recommendVersion$1
|
|
3476
|
+
};
|
|
3477
|
+
|
|
3478
|
+
const shelljs$1 = require$$2__default;
|
|
3479
|
+
const compileDev = dev$3;
|
|
3480
|
+
const {
|
|
3481
|
+
resolve: resolve$5,
|
|
3482
|
+
filterField: filterField$3
|
|
3483
|
+
} = widgets;
|
|
3484
|
+
const init$2 = init_1;
|
|
3485
|
+
const {
|
|
3486
|
+
getModulesByMergeDepModules: getModulesByMergeDepModules$1,
|
|
3487
|
+
getSubPackages: getSubPackages$1
|
|
3488
|
+
} = tmsMpconfig.exports;
|
|
3489
|
+
const {
|
|
3490
|
+
info: info$5
|
|
3491
|
+
} = log$1;
|
|
3492
|
+
const {
|
|
3493
|
+
global: global$4
|
|
3494
|
+
} = global_1;
|
|
3495
|
+
const {
|
|
3496
|
+
MODULE_CODE_DIR,
|
|
3497
|
+
NODE_MODULES_DIR
|
|
3498
|
+
} = constant;
|
|
3499
|
+
const report$5 = report_1;
|
|
3500
|
+
const {
|
|
3501
|
+
recommendVersion
|
|
3502
|
+
} = recommendVersion_1; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
3503
|
+
|
|
3504
|
+
function delOtherPackages(tmsConfig, targetSubPackages) {
|
|
3505
|
+
// 获取所有模块,合并模块依赖的模块
|
|
3506
|
+
const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all); // 获取所有的分包
|
|
3507
|
+
|
|
3508
|
+
const allSubPackages = getSubPackages$1(allModules);
|
|
3665
3509
|
const targetSubPackagesName = targetSubPackages.map(item => item.name);
|
|
3666
3510
|
allSubPackages.forEach(item => {
|
|
3667
3511
|
if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
|
|
3668
|
-
const moduleRootDir = resolve$
|
|
3512
|
+
const moduleRootDir = resolve$5(`${tmsConfig.outputDir}/${item.root}`);
|
|
3669
3513
|
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
3670
3514
|
silent: true
|
|
3671
3515
|
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
@@ -3679,28 +3523,33 @@ async function dev$2(tmsConfig, targetModules) {
|
|
|
3679
3523
|
|
|
3680
3524
|
const {
|
|
3681
3525
|
noCache
|
|
3682
|
-
} = global$
|
|
3526
|
+
} = global$4.getData('cmdOptions');
|
|
3683
3527
|
|
|
3684
3528
|
if (noCache) {
|
|
3685
|
-
shelljs$1.rm('-rf', resolve$
|
|
3686
|
-
shelljs$1.rm('-rf',
|
|
3687
|
-
|
|
3529
|
+
shelljs$1.rm('-rf', resolve$5(tmsConfig.outputDir));
|
|
3530
|
+
shelljs$1.rm('-rf', MODULE_CODE_DIR);
|
|
3531
|
+
shelljs$1.rm('-rf', NODE_MODULES_DIR);
|
|
3532
|
+
} // 推荐tmskit的版本
|
|
3688
3533
|
|
|
3689
3534
|
|
|
3535
|
+
await recommendVersion(); // 初始化操作
|
|
3536
|
+
|
|
3690
3537
|
const {
|
|
3691
3538
|
subPackages,
|
|
3692
3539
|
modules: newModules
|
|
3693
3540
|
} = await init$2(tmsConfig, targetModules);
|
|
3694
|
-
info$
|
|
3541
|
+
info$5('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
|
|
3695
3542
|
|
|
3696
|
-
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.
|
|
3543
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
|
|
3697
3544
|
var _tmsConfig$hooks2;
|
|
3698
3545
|
|
|
3699
|
-
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.
|
|
3546
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
|
|
3700
3547
|
isDev: true,
|
|
3701
|
-
tmsConfig: filterField$
|
|
3702
|
-
modules: newModules
|
|
3548
|
+
tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
|
|
3549
|
+
modules: newModules,
|
|
3550
|
+
cmdOptions: global$4.getData('cmdOptions')
|
|
3703
3551
|
}));
|
|
3552
|
+
report$5('hooks:beforeCompile');
|
|
3704
3553
|
}
|
|
3705
3554
|
delOtherPackages(tmsConfig, subPackages);
|
|
3706
3555
|
compileDev(tmsConfig, newModules, true);
|
|
@@ -3714,39 +3563,272 @@ var build$2 = async (tmsConfig, newModules, isDev) => {
|
|
|
3714
3563
|
dev$1(tmsConfig, newModules, isDev);
|
|
3715
3564
|
};
|
|
3716
3565
|
|
|
3717
|
-
const shelljs = require$$
|
|
3566
|
+
const shelljs = require$$2__default;
|
|
3718
3567
|
const {
|
|
3719
|
-
resolve: resolve$
|
|
3720
|
-
filterField
|
|
3568
|
+
resolve: resolve$4,
|
|
3569
|
+
filterField: filterField$2
|
|
3721
3570
|
} = widgets;
|
|
3722
3571
|
const init$1 = init_1;
|
|
3572
|
+
const {
|
|
3573
|
+
info: info$4
|
|
3574
|
+
} = log$1;
|
|
3723
3575
|
const compileBuild = build$2;
|
|
3576
|
+
const report$4 = report_1;
|
|
3577
|
+
const {
|
|
3578
|
+
global: global$3
|
|
3579
|
+
} = global_1;
|
|
3724
3580
|
|
|
3725
3581
|
async function build$1(tmsConfig, targetModules) {
|
|
3726
3582
|
var _tmsConfig$hooks;
|
|
3727
3583
|
|
|
3728
3584
|
// 开始构建前,清理输出目录
|
|
3729
|
-
await shelljs.rm('-rf', resolve$
|
|
3585
|
+
await shelljs.rm('-rf', resolve$4(tmsConfig.outputDir));
|
|
3730
3586
|
const {
|
|
3731
3587
|
modules: newModules
|
|
3732
3588
|
} = await init$1(tmsConfig, targetModules);
|
|
3589
|
+
info$4('当前build有效模块', newModules.map(item => item.moduleName).sort());
|
|
3733
3590
|
const isDev = false;
|
|
3734
3591
|
|
|
3735
|
-
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.
|
|
3592
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
|
|
3736
3593
|
var _tmsConfig$hooks2;
|
|
3737
3594
|
|
|
3738
|
-
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.
|
|
3595
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
|
|
3739
3596
|
isDev,
|
|
3740
|
-
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3741
|
-
modules: newModules
|
|
3597
|
+
tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
|
|
3598
|
+
modules: newModules,
|
|
3599
|
+
cmdOptions: global$3.getData('cmdOptions')
|
|
3742
3600
|
}));
|
|
3601
|
+
report$4('hooks:beforeCompile');
|
|
3743
3602
|
}
|
|
3744
3603
|
compileBuild(tmsConfig, newModules, isDev);
|
|
3745
3604
|
}
|
|
3746
3605
|
|
|
3747
3606
|
var build_1 = build$1;
|
|
3748
3607
|
|
|
3749
|
-
const
|
|
3608
|
+
const moment = require$$1__default;
|
|
3609
|
+
const path$1 = require$$1__default$1;
|
|
3610
|
+
const fs$3 = require$$0__default$1;
|
|
3611
|
+
const {
|
|
3612
|
+
getGitUser,
|
|
3613
|
+
getAbsolutePath: getAbsolutePath$1
|
|
3614
|
+
} = widgets;
|
|
3615
|
+
const {
|
|
3616
|
+
ensureDirExist: ensureDirExist$1
|
|
3617
|
+
} = io$3;
|
|
3618
|
+
|
|
3619
|
+
function getAllSize$2(data = {}) {
|
|
3620
|
+
let allSize;
|
|
3621
|
+
|
|
3622
|
+
for (const item of data === null || data === void 0 ? void 0 : data.subPackageInfo) {
|
|
3623
|
+
if (item.name === '__FULL__') {
|
|
3624
|
+
allSize = item.size;
|
|
3625
|
+
break;
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
|
|
3629
|
+
return allSize;
|
|
3630
|
+
}
|
|
3631
|
+
|
|
3632
|
+
const getDefaultDesc$2 = () => {
|
|
3633
|
+
const user = getGitUser();
|
|
3634
|
+
const date = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
3635
|
+
return `构建人: ${user}; 构建时间:${date}`;
|
|
3636
|
+
};
|
|
3637
|
+
|
|
3638
|
+
const outputInfo$2 = (infoOutput, data) => {
|
|
3639
|
+
const outPath = getAbsolutePath$1(infoOutput);
|
|
3640
|
+
const dir = path$1.dirname(outPath);
|
|
3641
|
+
ensureDirExist$1(dir);
|
|
3642
|
+
fs$3.writeFileSync(outPath, JSON.stringify(data, null, 2));
|
|
3643
|
+
};
|
|
3644
|
+
|
|
3645
|
+
const getDetaultVersion = () => {
|
|
3646
|
+
const version = moment().format('gggg,mm').split(',');
|
|
3647
|
+
version.push('0');
|
|
3648
|
+
return version.join('.');
|
|
3649
|
+
};
|
|
3650
|
+
|
|
3651
|
+
var utils = {
|
|
3652
|
+
getAllSize: getAllSize$2,
|
|
3653
|
+
getDefaultDesc: getDefaultDesc$2,
|
|
3654
|
+
outputInfo: outputInfo$2,
|
|
3655
|
+
getDetaultVersion
|
|
3656
|
+
};
|
|
3657
|
+
|
|
3658
|
+
const mpCi$1 = mpCi$2;
|
|
3659
|
+
const fs$2 = require$$0__default$1;
|
|
3660
|
+
const {
|
|
3661
|
+
resolve: resolve$3,
|
|
3662
|
+
createTask: createTask$1,
|
|
3663
|
+
getAbsolutePath,
|
|
3664
|
+
filterField: filterField$1
|
|
3665
|
+
} = widgets;
|
|
3666
|
+
const {
|
|
3667
|
+
handleError: handleError$2
|
|
3668
|
+
} = handleError_1;
|
|
3669
|
+
const {
|
|
3670
|
+
info: info$3
|
|
3671
|
+
} = log$1;
|
|
3672
|
+
const {
|
|
3673
|
+
global: global$2
|
|
3674
|
+
} = global_1;
|
|
3675
|
+
const {
|
|
3676
|
+
getAllSize: getAllSize$1,
|
|
3677
|
+
outputInfo: outputInfo$1,
|
|
3678
|
+
getDefaultDesc: getDefaultDesc$1
|
|
3679
|
+
} = utils;
|
|
3680
|
+
const report$3 = report_1;
|
|
3681
|
+
|
|
3682
|
+
const handleParams$1 = (tmsConfig, cmdOptions) => {
|
|
3683
|
+
const params = { ...(tmsConfig.preview ? tmsConfig.preview : {}),
|
|
3684
|
+
...cmdOptions
|
|
3685
|
+
};
|
|
3686
|
+
return { ...params,
|
|
3687
|
+
appId: params.appId || tmsConfig.appId,
|
|
3688
|
+
projectPath: resolve$3(tmsConfig.outputDir),
|
|
3689
|
+
privateKey: params.privateKey || tmsConfig.privateKey,
|
|
3690
|
+
robot: params.robot || 30,
|
|
3691
|
+
desc: params.desc || getDefaultDesc$1(),
|
|
3692
|
+
qrcodeOutputDest: getAbsolutePath(params.qrcodeOutputDest || '')
|
|
3693
|
+
};
|
|
3694
|
+
};
|
|
3695
|
+
/**
|
|
3696
|
+
* 预览
|
|
3697
|
+
* @params {object} tmsConfig
|
|
3698
|
+
* @param {object} cmdOptions {qrcodeFormat: 'base64', qrcodeOutputDest: './a.txt', robot: 2, infoOutput: './a.txt' }
|
|
3699
|
+
*/
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
async function preview$1(tmsConfig, cmdOptions) {
|
|
3703
|
+
try {
|
|
3704
|
+
var _tmsConfig$hooks;
|
|
3705
|
+
|
|
3706
|
+
const params = handleParams$1(tmsConfig, cmdOptions);
|
|
3707
|
+
|
|
3708
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforePreview) === 'function') {
|
|
3709
|
+
var _tmsConfig$hooks2;
|
|
3710
|
+
|
|
3711
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforePreview({
|
|
3712
|
+
tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
|
|
3713
|
+
cmdOptions: global$2.getData('cmdOptions'),
|
|
3714
|
+
params
|
|
3715
|
+
}));
|
|
3716
|
+
report$3('hooks:beforePreview');
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
;
|
|
3720
|
+
const previewRes = await createTask$1(mpCi$1.previewMp, '正在构建预览码', '构建预览码完成')({ ...params
|
|
3721
|
+
});
|
|
3722
|
+
const allSize = getAllSize$1(previewRes);
|
|
3723
|
+
|
|
3724
|
+
if (params.infoOutput) {
|
|
3725
|
+
let qrcodeBase64 = '';
|
|
3726
|
+
|
|
3727
|
+
if (params.qrcodeFormat === 'base64' && fs$2.existsSync(params.qrcodeOutputDest)) {
|
|
3728
|
+
qrcodeBase64 = fs$2.readFileSync(params.qrcodeOutputDest, 'utf8');
|
|
3729
|
+
}
|
|
3730
|
+
|
|
3731
|
+
outputInfo$1(params.infoOutput, {
|
|
3732
|
+
sourceCode: params.projectPath,
|
|
3733
|
+
qrcodeBase64,
|
|
3734
|
+
...previewRes
|
|
3735
|
+
});
|
|
3736
|
+
}
|
|
3737
|
+
|
|
3738
|
+
info$3('预览包大小:', `${allSize}k`);
|
|
3739
|
+
} catch (e) {
|
|
3740
|
+
console.log('详细错误:', e);
|
|
3741
|
+
handleError$2(`预览错误: ${e.message}`, true);
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3745
|
+
var preview_1 = preview$1;
|
|
3746
|
+
|
|
3747
|
+
const mpCi = mpCi$2;
|
|
3748
|
+
const {
|
|
3749
|
+
resolve: resolve$2,
|
|
3750
|
+
createTask,
|
|
3751
|
+
filterField
|
|
3752
|
+
} = widgets;
|
|
3753
|
+
const {
|
|
3754
|
+
handleError: handleError$1
|
|
3755
|
+
} = handleError_1;
|
|
3756
|
+
const {
|
|
3757
|
+
info: info$2
|
|
3758
|
+
} = log$1;
|
|
3759
|
+
const {
|
|
3760
|
+
global: global$1
|
|
3761
|
+
} = global_1;
|
|
3762
|
+
const {
|
|
3763
|
+
getAllSize,
|
|
3764
|
+
outputInfo,
|
|
3765
|
+
getDefaultDesc
|
|
3766
|
+
} = utils;
|
|
3767
|
+
const report$2 = report_1;
|
|
3768
|
+
|
|
3769
|
+
const handleParams = (tmsConfig, cmdOptions) => {
|
|
3770
|
+
const params = { ...(tmsConfig.upload ? tmsConfig.upload : {}),
|
|
3771
|
+
...cmdOptions
|
|
3772
|
+
};
|
|
3773
|
+
|
|
3774
|
+
if (!params.version) {
|
|
3775
|
+
throw new Error('请指定传入版本号 eg: tmskit run upload -v 2022.28.5');
|
|
3776
|
+
}
|
|
3777
|
+
|
|
3778
|
+
return { ...params,
|
|
3779
|
+
appId: params.appId || tmsConfig.appId,
|
|
3780
|
+
projectPath: resolve$2(tmsConfig.outputDir),
|
|
3781
|
+
privateKey: params.privateKey || tmsConfig.privateKey,
|
|
3782
|
+
robot: params.robot || 30,
|
|
3783
|
+
desc: params.desc || getDefaultDesc()
|
|
3784
|
+
};
|
|
3785
|
+
};
|
|
3786
|
+
/**
|
|
3787
|
+
* 上传
|
|
3788
|
+
* @param {object} tmsConfig
|
|
3789
|
+
* @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
|
|
3790
|
+
*/
|
|
3791
|
+
|
|
3792
|
+
|
|
3793
|
+
async function upload$1(tmsConfig, cmdOptions) {
|
|
3794
|
+
try {
|
|
3795
|
+
var _tmsConfig$hooks;
|
|
3796
|
+
|
|
3797
|
+
const params = handleParams(tmsConfig, cmdOptions);
|
|
3798
|
+
|
|
3799
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeUpload) === 'function') {
|
|
3800
|
+
var _tmsConfig$hooks2;
|
|
3801
|
+
|
|
3802
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeUpload({
|
|
3803
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3804
|
+
cmdOptions: global$1.getData('cmdOptions'),
|
|
3805
|
+
params
|
|
3806
|
+
}));
|
|
3807
|
+
report$2('hooks:beforeUpload');
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3810
|
+
;
|
|
3811
|
+
const uploadRes = await createTask(mpCi.uploadMp, '正在构建预览码', '构建预览码完成')({ ...params
|
|
3812
|
+
});
|
|
3813
|
+
const allSize = getAllSize(uploadRes);
|
|
3814
|
+
|
|
3815
|
+
if (params.infoOutput) {
|
|
3816
|
+
outputInfo(params.infoOutput, {
|
|
3817
|
+
sourceCode: params.projectPath,
|
|
3818
|
+
...uploadRes
|
|
3819
|
+
});
|
|
3820
|
+
}
|
|
3821
|
+
|
|
3822
|
+
info$2(`上传包大小: ${allSize}k; 上传包版本: ${params.version}`);
|
|
3823
|
+
} catch (e) {
|
|
3824
|
+
console.log('详细错误:', e);
|
|
3825
|
+
handleError$1(`上传错误: ${e.message}`, true);
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
|
|
3829
|
+
var upload_1 = upload$1;
|
|
3830
|
+
|
|
3831
|
+
const fs$1 = require$$0__default$1;
|
|
3750
3832
|
const {
|
|
3751
3833
|
resolve: resolve$1
|
|
3752
3834
|
} = widgets;
|
|
@@ -3800,7 +3882,7 @@ var cloud$1 = async tmsConfig => {
|
|
|
3800
3882
|
try {
|
|
3801
3883
|
await symLink(tmsConfig);
|
|
3802
3884
|
} catch (e) {
|
|
3803
|
-
handleError(`创建软链错误: ${e}
|
|
3885
|
+
handleError(`创建软链错误: ${e}`, true);
|
|
3804
3886
|
}
|
|
3805
3887
|
};
|
|
3806
3888
|
|
|
@@ -3809,14 +3891,17 @@ const init = init_1;
|
|
|
3809
3891
|
const dev = dev_1;
|
|
3810
3892
|
const build = build_1;
|
|
3811
3893
|
const install = install_1;
|
|
3894
|
+
const preview = preview_1;
|
|
3895
|
+
const upload = upload_1;
|
|
3812
3896
|
const cloud = cloud$1;
|
|
3813
3897
|
const {
|
|
3814
3898
|
fail,
|
|
3815
|
-
info: info$
|
|
3899
|
+
info: info$1
|
|
3816
3900
|
} = log$1;
|
|
3817
3901
|
const {
|
|
3818
3902
|
global
|
|
3819
3903
|
} = global_1;
|
|
3904
|
+
const report$1 = report_1;
|
|
3820
3905
|
const {
|
|
3821
3906
|
getTmsConfig: getTmsConfig$1,
|
|
3822
3907
|
getModulesByMergeDepModules,
|
|
@@ -3824,10 +3909,10 @@ const {
|
|
|
3824
3909
|
getModulesByModuleNames
|
|
3825
3910
|
} = tmsMpconfig.exports;
|
|
3826
3911
|
|
|
3827
|
-
const handleModuleArg =
|
|
3912
|
+
const handleModuleArg = cmdOptions => {
|
|
3828
3913
|
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
3829
|
-
if (typeof
|
|
3830
|
-
return
|
|
3914
|
+
if (typeof cmdOptions.module === 'string') {
|
|
3915
|
+
return cmdOptions.module.split(',');
|
|
3831
3916
|
}
|
|
3832
3917
|
|
|
3833
3918
|
return [];
|
|
@@ -3867,33 +3952,41 @@ const getSpecificModuleNames = (moduleArg, modules) => {
|
|
|
3867
3952
|
return all.map(item => item.moduleName);
|
|
3868
3953
|
};
|
|
3869
3954
|
|
|
3870
|
-
async function run(commandName,
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
const tmsConfig = getTmsConfig$1(); // 缓存数据
|
|
3955
|
+
async function run(commandName, cmdOptions) {
|
|
3956
|
+
// 用户本地的配置
|
|
3957
|
+
const tmsConfig = getTmsConfig$1();
|
|
3874
3958
|
|
|
3959
|
+
try {
|
|
3960
|
+
// 缓存数据
|
|
3875
3961
|
global.setData({
|
|
3876
|
-
|
|
3962
|
+
cmdOptions,
|
|
3877
3963
|
tmsConfig
|
|
3878
3964
|
});
|
|
3879
3965
|
|
|
3880
3966
|
if (commandName === 'cloud') {
|
|
3881
3967
|
cloud(tmsConfig);
|
|
3968
|
+
report$1('run:cloud', {
|
|
3969
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3970
|
+
});
|
|
3882
3971
|
return;
|
|
3883
3972
|
}
|
|
3884
3973
|
|
|
3885
|
-
otherCommands(tmsConfig, commandName,
|
|
3974
|
+
otherCommands(tmsConfig, commandName, cmdOptions);
|
|
3886
3975
|
} catch (error) {
|
|
3887
3976
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
3977
|
+
report$1('run', {
|
|
3978
|
+
errMsg,
|
|
3979
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3980
|
+
});
|
|
3888
3981
|
fail(`构建出现错误: ${errMsg}`);
|
|
3889
|
-
info$
|
|
3982
|
+
info$1('详细错误信息', error);
|
|
3890
3983
|
process.exit(1);
|
|
3891
3984
|
}
|
|
3892
3985
|
}
|
|
3893
3986
|
|
|
3894
|
-
function otherCommands(tmsConfig, commandName,
|
|
3987
|
+
function otherCommands(tmsConfig, commandName, cmdOptions) {
|
|
3895
3988
|
// 处理module参数
|
|
3896
|
-
const specificModuleNames = getSpecificModuleNames(handleModuleArg(
|
|
3989
|
+
const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmdOptions), tmsConfig.modules); // moduleNames => ['home', 'car']
|
|
3897
3990
|
|
|
3898
3991
|
const moduleNames = [...new Set([...specificModuleNames])];
|
|
3899
3992
|
const modules = getModulesByModuleNames(tmsConfig, moduleNames, false); // 获取所有模块,合并模块依赖的模块
|
|
@@ -3905,20 +3998,46 @@ function otherCommands(tmsConfig, commandName, cmd) {
|
|
|
3905
3998
|
switch (commandName) {
|
|
3906
3999
|
case 'init':
|
|
3907
4000
|
init(tmsConfig, newModules);
|
|
4001
|
+
report$1('run:init', {
|
|
4002
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
4003
|
+
});
|
|
3908
4004
|
return;
|
|
3909
4005
|
|
|
3910
4006
|
case 'dev':
|
|
3911
4007
|
global.setData('isDev', true);
|
|
3912
4008
|
dev(tmsConfig, newModules);
|
|
4009
|
+
report$1('run:dev', {
|
|
4010
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
4011
|
+
});
|
|
3913
4012
|
return;
|
|
3914
4013
|
|
|
3915
4014
|
case 'install':
|
|
3916
4015
|
install(tmsConfig, subPackages, false);
|
|
4016
|
+
report$1('run:install', {
|
|
4017
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
4018
|
+
});
|
|
3917
4019
|
return;
|
|
3918
4020
|
|
|
3919
4021
|
case 'build':
|
|
3920
4022
|
global.setData('isDev', false);
|
|
3921
4023
|
build(tmsConfig, newModules);
|
|
4024
|
+
report$1('run:build', {
|
|
4025
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
4026
|
+
});
|
|
4027
|
+
return;
|
|
4028
|
+
|
|
4029
|
+
case 'preview':
|
|
4030
|
+
preview(tmsConfig, cmdOptions);
|
|
4031
|
+
report$1('run:preview', {
|
|
4032
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
4033
|
+
});
|
|
4034
|
+
return;
|
|
4035
|
+
|
|
4036
|
+
case 'upload':
|
|
4037
|
+
upload(tmsConfig, cmdOptions);
|
|
4038
|
+
report$1('run:upload', {
|
|
4039
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
4040
|
+
});
|
|
3922
4041
|
return;
|
|
3923
4042
|
|
|
3924
4043
|
default:
|
|
@@ -3934,146 +4053,68 @@ var entry = [{
|
|
|
3934
4053
|
action: projectName => {
|
|
3935
4054
|
create_1(projectName);
|
|
3936
4055
|
}
|
|
4056
|
+
}, {
|
|
4057
|
+
command: 'install-cmd <npm-name>',
|
|
4058
|
+
description: '安装扩展命令',
|
|
4059
|
+
options: [['--registry [registry]', 'npm源']],
|
|
4060
|
+
action: (npmName, cmdOptions) => {
|
|
4061
|
+
const res = extendCmd;
|
|
4062
|
+
res.installCmd(npmName, cmdOptions);
|
|
4063
|
+
}
|
|
3937
4064
|
}, {
|
|
3938
4065
|
name: 'run',
|
|
3939
|
-
type: '
|
|
4066
|
+
type: 'parent',
|
|
3940
4067
|
description: '项目开发使用的命令',
|
|
3941
4068
|
commands: [{
|
|
3942
4069
|
command: 'install',
|
|
3943
4070
|
description: '安装依赖',
|
|
3944
4071
|
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
3945
|
-
action:
|
|
3946
|
-
run_1('install',
|
|
4072
|
+
action: cmdOptions => {
|
|
4073
|
+
run_1('install', cmdOptions);
|
|
3947
4074
|
}
|
|
3948
4075
|
}, {
|
|
3949
4076
|
command: 'dev',
|
|
3950
4077
|
description: 'dev 打包编译',
|
|
3951
4078
|
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-noCache, --noCache', '不使用缓存功能']],
|
|
3952
|
-
action:
|
|
3953
|
-
run_1('dev',
|
|
4079
|
+
action: cmdOptions => {
|
|
4080
|
+
run_1('dev', cmdOptions);
|
|
3954
4081
|
}
|
|
3955
4082
|
}, {
|
|
3956
4083
|
command: 'cloud',
|
|
3957
4084
|
description: '云函数开发',
|
|
3958
4085
|
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
3959
|
-
action:
|
|
3960
|
-
run_1('cloud',
|
|
4086
|
+
action: cmdOptions => {
|
|
4087
|
+
run_1('cloud', cmdOptions);
|
|
3961
4088
|
}
|
|
3962
4089
|
}, {
|
|
3963
4090
|
command: 'build',
|
|
3964
4091
|
description: 'prod 打包编译',
|
|
3965
4092
|
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
3966
|
-
action:
|
|
3967
|
-
run_1('build',
|
|
4093
|
+
action: cmdOptions => {
|
|
4094
|
+
run_1('build', cmdOptions);
|
|
3968
4095
|
}
|
|
3969
|
-
}
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
4096
|
+
}, {
|
|
4097
|
+
command: 'preview',
|
|
4098
|
+
description: '小程序预览',
|
|
4099
|
+
options: [['-f, --qrcodeFormat [qrcodeFormat]', '二维码的格式,选项terminal, image, base64。默认terminal'], ['-o, --qrcodeOutputDest [qrcodeOutputDest]', '二维码会被输出到给定路径'], ['-i, --info-output [infoOutput]', '相关信息会被输出到给定路径']],
|
|
4100
|
+
action: cmdOptions => {
|
|
4101
|
+
run_1('preview', cmdOptions);
|
|
4102
|
+
}
|
|
4103
|
+
}, {
|
|
4104
|
+
command: 'upload',
|
|
4105
|
+
description: '小程序上传',
|
|
4106
|
+
options: [['-version, --version [version]', '上传代码版本,version 指定版本号'], ['-d, --desc [desc]', '上传代码时的备注'], ['-i, --info-output [infoOutput]', '相关信息会被输出到给定路径'], ['-r, --robot [robot]', '指定使用哪一个 ci 机器人,可选值:1 ~ 30']],
|
|
4107
|
+
action: cmdOptions => {
|
|
4108
|
+
run_1('upload', cmdOptions);
|
|
4109
|
+
}
|
|
4110
|
+
}]
|
|
3982
4111
|
}];
|
|
3983
4112
|
|
|
3984
|
-
var require$$9 = {
|
|
3985
|
-
name: "@tmsfe/tmskit",
|
|
3986
|
-
version: "0.0.21",
|
|
3987
|
-
description: "tmskit",
|
|
3988
|
-
main: "dist/index.cjs",
|
|
3989
|
-
bin: {
|
|
3990
|
-
tmskit: "main.js"
|
|
3991
|
-
},
|
|
3992
|
-
files: [
|
|
3993
|
-
"build",
|
|
3994
|
-
"src",
|
|
3995
|
-
"dist",
|
|
3996
|
-
"main.js",
|
|
3997
|
-
"package.json"
|
|
3998
|
-
],
|
|
3999
|
-
scripts: {
|
|
4000
|
-
dev: "rollup -wc --environment TARGET:tmskit",
|
|
4001
|
-
build: "rollup -c --environment TARGET:tmskit",
|
|
4002
|
-
"pub:patch": "sh build/publish.sh patch",
|
|
4003
|
-
"pub:minor": "sh build/publish.sh minor",
|
|
4004
|
-
"pub:major": "sh build/publish.sh major"
|
|
4005
|
-
},
|
|
4006
|
-
author: "tms·web",
|
|
4007
|
-
license: "ISC",
|
|
4008
|
-
buildOptions: {
|
|
4009
|
-
formats: [
|
|
4010
|
-
"cjs"
|
|
4011
|
-
]
|
|
4012
|
-
},
|
|
4013
|
-
devDependencies: {
|
|
4014
|
-
"@rollup/plugin-babel": "^5.0.2",
|
|
4015
|
-
"@rollup/plugin-commonjs": "^19.0.0",
|
|
4016
|
-
"@rollup/plugin-dynamic-import-vars": "^1.1.1",
|
|
4017
|
-
"@rollup/plugin-json": "^4.0.3",
|
|
4018
|
-
rollup: "^2.6.1",
|
|
4019
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
4020
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
4021
|
-
"rollup-plugin-terser": "^6.1.0",
|
|
4022
|
-
"rollup-plugin-typescript2": "0.27.0"
|
|
4023
|
-
},
|
|
4024
|
-
dependencies: {
|
|
4025
|
-
"ansi-colors": "1.1.0",
|
|
4026
|
-
anymatch: "^1.3.0",
|
|
4027
|
-
async: "^3.2.2",
|
|
4028
|
-
chalk: "^4.1.0",
|
|
4029
|
-
chokidar: "^3.5.3",
|
|
4030
|
-
commander: "^8.3.0",
|
|
4031
|
-
"copy-webpack-plugin": "^9.1.0",
|
|
4032
|
-
ejs: "^3.1.5",
|
|
4033
|
-
"fancy-log": "1.3.2",
|
|
4034
|
-
"fs-extra": "^10.0.1",
|
|
4035
|
-
"glob-ignore": "^1.0.2",
|
|
4036
|
-
"glob-parent": "^3.0.1",
|
|
4037
|
-
gulp: "^4.0.2",
|
|
4038
|
-
"gulp-watch": "^5.0.1",
|
|
4039
|
-
htmlparser2: "^7.2.0",
|
|
4040
|
-
inquirer: "^7.3.3",
|
|
4041
|
-
leven: "3.1.0",
|
|
4042
|
-
lodash: "^4.17.21",
|
|
4043
|
-
metalsmith: "^2.3.0",
|
|
4044
|
-
"miniprogram-ci": "1.4.13",
|
|
4045
|
-
moment: "^2.29.2",
|
|
4046
|
-
"object-assign": "^4.0.1",
|
|
4047
|
-
ora: "^5.1.0",
|
|
4048
|
-
"path-is-absolute": "^1.0.1",
|
|
4049
|
-
"plugin-error": "^1.0.0",
|
|
4050
|
-
postcss: "^8.4.6",
|
|
4051
|
-
precinct: "^8.3.1",
|
|
4052
|
-
"readable-stream": "^2.2.2",
|
|
4053
|
-
"replace-ext": "^2.0.0",
|
|
4054
|
-
request: "^2.88.2",
|
|
4055
|
-
shelljs: "^0.8.4",
|
|
4056
|
-
slash: "^1.0.0",
|
|
4057
|
-
"strip-comments": "^2.0.1",
|
|
4058
|
-
through2: "^4.0.2",
|
|
4059
|
-
unzipper: "^0.10.11",
|
|
4060
|
-
vinyl: "^2.1.0",
|
|
4061
|
-
"vinyl-file": "^2.0.0",
|
|
4062
|
-
"vinyl-sourcemaps-apply": "^0.2.0"
|
|
4063
|
-
},
|
|
4064
|
-
engines: {
|
|
4065
|
-
node: "^12.17.0 || >= 14.13.1"
|
|
4066
|
-
},
|
|
4067
|
-
jest: {
|
|
4068
|
-
testEnvironment: "jest-environment-node"
|
|
4069
|
-
}
|
|
4070
|
-
};
|
|
4071
|
-
|
|
4072
4113
|
const semver = require$$1__default$7;
|
|
4073
|
-
const packageJson = require$$
|
|
4074
|
-
const chalk$1 = require$$
|
|
4114
|
+
const packageJson = require$$12;
|
|
4115
|
+
const chalk$1 = require$$3__default;
|
|
4075
4116
|
const {
|
|
4076
|
-
info
|
|
4117
|
+
info
|
|
4077
4118
|
} = log$1;
|
|
4078
4119
|
const requiredVersion = packageJson.engines.node;
|
|
4079
4120
|
const packName = packageJson.name;
|
|
@@ -4088,7 +4129,7 @@ const checkNodeVersion = (wanted, id) => {
|
|
|
4088
4129
|
if (!semver.satisfies(process.version, wanted, {
|
|
4089
4130
|
includePrerelease: true
|
|
4090
4131
|
})) {
|
|
4091
|
-
info
|
|
4132
|
+
info(chalk$1.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id} 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
|
|
4092
4133
|
process.exit(1);
|
|
4093
4134
|
}
|
|
4094
4135
|
};
|
|
@@ -4105,31 +4146,36 @@ function check$1() {
|
|
|
4105
4146
|
|
|
4106
4147
|
var check_1 = check$1;
|
|
4107
4148
|
|
|
4108
|
-
|
|
4109
|
-
const
|
|
4149
|
+
/* eslint-disable no-param-reassign */
|
|
4150
|
+
const chalk = require$$3__default;
|
|
4151
|
+
const commander = require$$1__default$8;
|
|
4152
|
+
const path = require$$1__default$1;
|
|
4153
|
+
const fs = require$$0__default$1;
|
|
4110
4154
|
const {
|
|
4111
|
-
suggestCommands,
|
|
4112
4155
|
resolve
|
|
4113
4156
|
} = widgets;
|
|
4114
4157
|
const {
|
|
4115
|
-
|
|
4158
|
+
infoNoTime
|
|
4116
4159
|
} = log$1;
|
|
4117
4160
|
const {
|
|
4118
4161
|
getTmsConfig
|
|
4119
4162
|
} = tmsMpconfig.exports;
|
|
4120
4163
|
const {
|
|
4121
4164
|
TMS_NAME
|
|
4122
|
-
} =
|
|
4165
|
+
} = constant;
|
|
4123
4166
|
const commands = entry;
|
|
4124
4167
|
const check = check_1;
|
|
4125
|
-
const
|
|
4168
|
+
const {
|
|
4169
|
+
loadExtendCmd
|
|
4170
|
+
} = extendCmd;
|
|
4171
|
+
const report = report_1;
|
|
4126
4172
|
check();
|
|
4127
4173
|
const program = new commander.Command(TMS_NAME);
|
|
4128
|
-
program.version(`${TMS_NAME} ${require$$
|
|
4174
|
+
program.version(`${TMS_NAME} ${require$$12.version}`, '-v, -V, --version'); // 注册命令底层实现
|
|
4129
4175
|
|
|
4130
4176
|
function registerCommand(program, commands) {
|
|
4131
4177
|
commands.forEach(cmd => {
|
|
4132
|
-
if (cmd.type === '
|
|
4178
|
+
if (cmd.type === 'parent') {
|
|
4133
4179
|
const childProgram = new commander.Command(cmd.name);
|
|
4134
4180
|
cmd.usage && childProgram.usage(cmd.usage);
|
|
4135
4181
|
cmd.description && childProgram.description(cmd.description);
|
|
@@ -4141,35 +4187,65 @@ function registerCommand(program, commands) {
|
|
|
4141
4187
|
const command = program.command(cmd.command);
|
|
4142
4188
|
cmd.usage && command.usage(cmd.usage);
|
|
4143
4189
|
cmd.description && command.description(cmd.description);
|
|
4144
|
-
(_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
|
|
4190
|
+
(_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt)); // 上报
|
|
4191
|
+
|
|
4192
|
+
command.hook('preAction', thisCommand => {
|
|
4193
|
+
report(`${thisCommand._name}-pre`);
|
|
4194
|
+
}); // 上报
|
|
4195
|
+
|
|
4196
|
+
command.hook('postAction', thisCommand => {
|
|
4197
|
+
report(`${thisCommand._name}-post`);
|
|
4198
|
+
});
|
|
4145
4199
|
command.action(cmd.action);
|
|
4146
4200
|
}
|
|
4147
4201
|
});
|
|
4148
|
-
}
|
|
4202
|
+
} // 注册扩展命令
|
|
4149
4203
|
|
|
4150
|
-
function register() {
|
|
4151
|
-
// 注册脚手架内部命令
|
|
4152
|
-
registerCommand(program, commands); // 注册扩展命令
|
|
4153
4204
|
|
|
4154
|
-
|
|
4155
|
-
|
|
4205
|
+
function registerExtendCommand(program, configPath) {
|
|
4206
|
+
const tmsConfig = getTmsConfig(configPath);
|
|
4207
|
+
|
|
4208
|
+
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.commands) {
|
|
4209
|
+
const commands = typeof tmsConfig.commands === 'function' ? tmsConfig.commands() : tmsConfig.commands;
|
|
4156
4210
|
|
|
4157
|
-
if (Array.isArray(
|
|
4158
|
-
registerCommand(program,
|
|
4211
|
+
if (Array.isArray(commands)) {
|
|
4212
|
+
registerCommand(program, commands);
|
|
4159
4213
|
}
|
|
4160
4214
|
}
|
|
4215
|
+
} // 注册所有的命令
|
|
4216
|
+
|
|
4217
|
+
|
|
4218
|
+
function registerAllCmds(program, commands) {
|
|
4219
|
+
// 注册脚手架内部命令
|
|
4220
|
+
registerCommand(program, commands); // 注册npm包扩展命令
|
|
4221
|
+
|
|
4222
|
+
const cmdConfigs = loadExtendCmd();
|
|
4223
|
+
cmdConfigs.forEach(cmdConfig => {
|
|
4224
|
+
registerExtendCommand(program, path.dirname(cmdConfig));
|
|
4225
|
+
}); // 注册当前目录扩展命令
|
|
4226
|
+
|
|
4227
|
+
const tmsConfigPath = resolve('./tms.config.js');
|
|
4228
|
+
|
|
4229
|
+
if (fs.existsSync(tmsConfigPath)) {
|
|
4230
|
+
registerExtendCommand(program, path.dirname(tmsConfigPath));
|
|
4231
|
+
}
|
|
4161
4232
|
}
|
|
4162
4233
|
|
|
4163
|
-
|
|
4234
|
+
registerAllCmds(program, commands); // 捕获未注册的命令
|
|
4235
|
+
|
|
4236
|
+
program.arguments('<command>').option('-c, --config <value>', '配置', value => {
|
|
4237
|
+
// 注册指定配置的扩展命令
|
|
4238
|
+
registerExtendCommand(program, path.dirname(resolve(value)));
|
|
4239
|
+
}).action(cmd => {
|
|
4240
|
+
infoNoTime(chalk.yellow(`
|
|
4241
|
+
没有找到${cmd}命令
|
|
4242
|
+
你可以通过${chalk.green('tmskit install-cmd <npm-name>')}安装扩展命令, ${chalk.green('扩展命令列表:https://www.npmjs.com/search?q=tmskit-cmd')}
|
|
4243
|
+
你也可以通过 ${chalk.green('tmskit <command> --config=../tms.config.js')} 指定本地的扩展命令
|
|
4244
|
+
`));
|
|
4245
|
+
report(`${cmd}-not-find`);
|
|
4246
|
+
});
|
|
4164
4247
|
program.on('--help', () => {
|
|
4165
|
-
|
|
4166
|
-
}); // 捕获未注册的命令
|
|
4167
|
-
|
|
4168
|
-
program.arguments('<command>').action(cmd => {
|
|
4169
|
-
program.outputHelp();
|
|
4170
|
-
info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
|
|
4171
|
-
suggestCommands(cmd);
|
|
4172
|
-
process.exitCode = 1;
|
|
4248
|
+
infoNoTime(`Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
4173
4249
|
});
|
|
4174
4250
|
|
|
4175
4251
|
if (!process.argv.slice(2).length) {
|