@tmsfe/tmskit 0.0.21 → 0.0.24
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 +1036 -1309
- package/package.json +4 -7
- package/src/compile/compile.js +53 -155
- package/src/compile/dev.js +10 -48
- package/src/compile/plugins/mpProjectJson.js +13 -0
- package/src/compile/plugins/replaceEnv.js +7 -14
- package/src/compile/watch.js +49 -17
- package/src/config/constant.js +29 -8
- package/src/core/buildAppJson.js +3 -0
- package/src/core/checkDependencies.js +4 -1
- package/src/core/cloneModules.js +3 -0
- package/src/core/npm.js +3 -19
- package/src/core/recommendVersion.js +118 -0
- package/src/core/report.js +30 -0
- package/src/core/tmsMpconfig.js +12 -10
- package/src/entry.js +12 -13
- package/src/index.js +54 -27
- package/src/scripts/create/index.js +3 -1
- package/src/scripts/extend-cmd/index.js +74 -0
- package/src/scripts/run/build/index.js +4 -2
- package/src/scripts/run/dev/index.js +10 -4
- package/src/scripts/run/index.js +9 -3
- package/src/scripts/run/install/cache.js +36 -0
- package/src/scripts/run/install/index.js +3 -3
- package/src/utils/log.js +3 -0
- package/src/utils/widgets.js +49 -34
package/dist/index.cjs.js
CHANGED
|
@@ -1,101 +1,84 @@
|
|
|
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$$
|
|
81
|
+
const chalk$4 = require$$3__default;
|
|
99
82
|
const moment = require$$1__default;
|
|
100
83
|
/**
|
|
101
84
|
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
@@ -143,24 +126,24 @@ const warn$2 = message => {
|
|
|
143
126
|
|
|
144
127
|
const info$d = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
145
128
|
|
|
129
|
+
const infoNoTime$2 = (...args) => console.log(...args);
|
|
130
|
+
|
|
146
131
|
var log$1 = {
|
|
147
132
|
fail: fail$9,
|
|
148
133
|
succeed: succeed$2,
|
|
149
134
|
warn: warn$2,
|
|
150
|
-
info: info$d
|
|
135
|
+
info: info$d,
|
|
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$f = require$$1__default$1;
|
|
141
|
+
const fs$g = require$$0__default$1;
|
|
142
|
+
const shelljs$9 = require$$2__default;
|
|
143
|
+
const glob = require$$4__default;
|
|
160
144
|
const {
|
|
161
145
|
info: info$c
|
|
162
146
|
} = log$1;
|
|
163
|
-
const chalk$3 = require$$0__default;
|
|
164
147
|
const shelljsOptions = {
|
|
165
148
|
slient: true,
|
|
166
149
|
async: false
|
|
@@ -168,37 +151,15 @@ const shelljsOptions = {
|
|
|
168
151
|
|
|
169
152
|
const cwd = process.cwd();
|
|
170
153
|
|
|
171
|
-
function resolve$
|
|
172
|
-
return path$
|
|
154
|
+
function resolve$e(...args) {
|
|
155
|
+
return path$f.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$g.existsSync(dest)) {
|
|
190
|
+
shelljs$9.rm('-rf', path$f.join(dest));
|
|
230
191
|
}
|
|
231
192
|
|
|
232
|
-
shelljs$
|
|
233
|
-
shelljs$
|
|
234
|
-
shelljs$
|
|
193
|
+
shelljs$9.mkdir('-p', dest);
|
|
194
|
+
shelljs$9.cd(dest);
|
|
195
|
+
shelljs$9.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$9.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$9.cd(dest);
|
|
219
|
+
shelljs$9.exec('git config pull.rebase false', shelljsOptions);
|
|
220
|
+
shelljs$9.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$9.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$9.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,7 +293,7 @@ const cost = start => Date.now() - start;
|
|
|
306
293
|
*/
|
|
307
294
|
|
|
308
295
|
|
|
309
|
-
function createTask$
|
|
296
|
+
function createTask$3(task, startText, endText) {
|
|
310
297
|
return async (...args) => {
|
|
311
298
|
const start = Date.now();
|
|
312
299
|
const spinner = ora$1();
|
|
@@ -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$f.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$5 = (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
|
}
|
|
@@ -376,46 +359,74 @@ function findFiles(globPath, filter = []) {
|
|
|
376
359
|
|
|
377
360
|
function getAbsolutePath$3(pathDir, cwd = '') {
|
|
378
361
|
let newPath = pathDir;
|
|
379
|
-
newPath = newPath.startsWith('/') ? newPath : resolve$
|
|
362
|
+
newPath = newPath.startsWith('/') ? newPath : resolve$e(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;
|
|
382
386
|
}
|
|
383
387
|
|
|
384
388
|
var widgets = {
|
|
385
|
-
resolve: resolve$
|
|
389
|
+
resolve: resolve$e,
|
|
386
390
|
isObject,
|
|
387
391
|
isArray,
|
|
388
|
-
createTask: createTask$
|
|
392
|
+
createTask: createTask$3,
|
|
389
393
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
390
394
|
pullRepoForGit: pullRepoForGit$1,
|
|
391
|
-
suggestCommands: suggestCommands$1,
|
|
392
395
|
camelize,
|
|
393
396
|
npmInstall: npmInstall$2,
|
|
394
397
|
mergeMap: mergeMap$1,
|
|
395
398
|
relativeCwdPath: relativeCwdPath$1,
|
|
396
|
-
filterField: filterField$
|
|
399
|
+
filterField: filterField$5,
|
|
397
400
|
findFiles,
|
|
398
|
-
getAbsolutePath: getAbsolutePath$3
|
|
401
|
+
getAbsolutePath: getAbsolutePath$3,
|
|
402
|
+
getNpmRegistry,
|
|
403
|
+
versionCompare: versionCompare$1
|
|
399
404
|
};
|
|
400
405
|
|
|
401
406
|
var tmsMpconfig = {exports: {}};
|
|
402
407
|
|
|
403
|
-
const path$
|
|
408
|
+
const path$e = require$$1__default$1;
|
|
409
|
+
const os = require$$1__default$2; // 用户目录
|
|
410
|
+
|
|
411
|
+
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
404
412
|
|
|
405
|
-
const
|
|
413
|
+
const CACHE_DIR = path$e.resolve(HOME_DIR, '.tmskit'); // 版本管理的CDN地址
|
|
406
414
|
|
|
415
|
+
const VERSION_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json'; // version缓存文件
|
|
407
416
|
|
|
408
|
-
const
|
|
417
|
+
const VERSION_CACHE_FILE$1 = path$e.resolve(CACHE_DIR, 'version_cache_file.json'); // npm缓存文件
|
|
409
418
|
|
|
410
|
-
const
|
|
419
|
+
const NPM_CACHE_FILE$1 = path$e.resolve(CACHE_DIR, 'npm_cache_file.json'); // 脚手架模板代码所在目录
|
|
411
420
|
|
|
412
|
-
const
|
|
421
|
+
const TEMPLATE_DIR$1 = path$e.resolve(CACHE_DIR, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
413
422
|
|
|
414
|
-
const
|
|
423
|
+
const MODULE_CODE_DIR$2 = path$e.resolve(CACHE_DIR, 'modules_code'); // 缓存分包node_modules的目录
|
|
415
424
|
|
|
416
|
-
const
|
|
425
|
+
const NODE_MODULES_DIR$2 = path$e.resolve(CACHE_DIR, 'node_modules'); // 扩展命令源码的存放处
|
|
417
426
|
|
|
418
|
-
const
|
|
427
|
+
const EXTEND_CMD$1 = path$e.resolve(CACHE_DIR, 'cmd'); // 创建模板的名称
|
|
428
|
+
|
|
429
|
+
const TEMPLATE_NAME$1 = 'tmskit-template'; // 脚手架模板的远程地址
|
|
419
430
|
|
|
420
431
|
const TEMPLATE_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip'; // 脚手架的名称
|
|
421
432
|
|
|
@@ -431,10 +442,10 @@ const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
|
431
442
|
const MODULE_CONFIG_FILENAME = 'module.config.json'; // 默认的webpack entry
|
|
432
443
|
|
|
433
444
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
434
|
-
app: path$
|
|
445
|
+
app: path$e.resolve(process.cwd(), 'app')
|
|
435
446
|
}; // 默认从源码拷贝到编译后的配置
|
|
436
447
|
|
|
437
|
-
const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json'];
|
|
448
|
+
const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json', 'project.config.json'];
|
|
438
449
|
const ENV = {
|
|
439
450
|
dev: 'development',
|
|
440
451
|
prod: 'production'
|
|
@@ -450,32 +461,38 @@ const CREATE_TEMPLATE_QUESTION$1 = [{
|
|
|
450
461
|
}, {
|
|
451
462
|
name: '小程序模块',
|
|
452
463
|
value: 'mp-module'
|
|
464
|
+
}, {
|
|
465
|
+
name: '构建工具扩展命令',
|
|
466
|
+
value: 'cmd'
|
|
467
|
+
}, {
|
|
468
|
+
name: '构建工具编译插件',
|
|
469
|
+
value: 'plugin'
|
|
453
470
|
}]
|
|
454
471
|
}];
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
472
|
+
var constant = {
|
|
473
|
+
HOME_DIR,
|
|
474
|
+
CACHE_DIR,
|
|
475
|
+
NPM_CACHE_FILE: NPM_CACHE_FILE$1,
|
|
476
|
+
VERSION_CACHE_FILE: VERSION_CACHE_FILE$1,
|
|
477
|
+
TEMPLATE_DIR: TEMPLATE_DIR$1,
|
|
478
|
+
TEMPLATE_NAME: TEMPLATE_NAME$1,
|
|
479
|
+
TMS_NAME: TMS_NAME$1,
|
|
480
|
+
TMS_CONFIG_FILENAME,
|
|
481
|
+
TMS_PRIVATE_FILENAME,
|
|
482
|
+
DEFAULT_MODULE_DIR,
|
|
483
|
+
MODULE_CONFIG_FILENAME,
|
|
484
|
+
EXTEND_CMD: EXTEND_CMD$1,
|
|
485
|
+
DEFAULT_WEBPACK_ENTRY,
|
|
486
|
+
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
|
|
487
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$2,
|
|
488
|
+
NODE_MODULES_DIR: NODE_MODULES_DIR$2,
|
|
489
|
+
ENV,
|
|
490
|
+
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
491
|
+
DEFAULT_CLOUD_MODULE_DIR,
|
|
492
|
+
CREATE_TEMPLATE_QUESTION: CREATE_TEMPLATE_QUESTION$1,
|
|
493
|
+
TEMPLATE_URL: TEMPLATE_URL$1,
|
|
494
|
+
VERSION_URL: VERSION_URL$1
|
|
495
|
+
};
|
|
479
496
|
|
|
480
497
|
var defaultTmsConfig = {
|
|
481
498
|
// 全局的环境配置项
|
|
@@ -502,14 +519,14 @@ var defaultTmsConfig = {
|
|
|
502
519
|
|
|
503
520
|
(function (module) {
|
|
504
521
|
/* 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$
|
|
522
|
+
const loadash = require$$0__default$2;
|
|
523
|
+
const fs = require$$0__default$1;
|
|
524
|
+
const path = require$$1__default$1;
|
|
508
525
|
const {
|
|
509
526
|
TMS_CONFIG_FILENAME,
|
|
510
527
|
MODULE_CONFIG_FILENAME,
|
|
511
528
|
TMS_PRIVATE_FILENAME
|
|
512
|
-
} =
|
|
529
|
+
} = constant;
|
|
513
530
|
const {
|
|
514
531
|
resolve,
|
|
515
532
|
isObject,
|
|
@@ -522,14 +539,14 @@ var defaultTmsConfig = {
|
|
|
522
539
|
} = log$1;
|
|
523
540
|
/**
|
|
524
541
|
* 读取tms.config.js
|
|
525
|
-
*
|
|
542
|
+
* @param {string} configPath tms.config.js的路径
|
|
526
543
|
*/
|
|
527
544
|
|
|
528
|
-
const readTmsConfig = function () {
|
|
529
|
-
const tmsConfigPath = resolve(TMS_CONFIG_FILENAME);
|
|
545
|
+
const readTmsConfig = function (configPath) {
|
|
546
|
+
const tmsConfigPath = configPath ? `${configPath}/${TMS_CONFIG_FILENAME}` : resolve(TMS_CONFIG_FILENAME);
|
|
530
547
|
|
|
531
548
|
if (!fs.existsSync(tmsConfigPath)) {
|
|
532
|
-
fail(
|
|
549
|
+
fail(`${path.dirname(tmsConfigPath)}没有找到tms.config.js,请进行配置`);
|
|
533
550
|
process.exit(1);
|
|
534
551
|
}
|
|
535
552
|
|
|
@@ -537,16 +554,17 @@ var defaultTmsConfig = {
|
|
|
537
554
|
|
|
538
555
|
const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn() : tmsConfigFn; // 合并默认值
|
|
539
556
|
|
|
540
|
-
return loadash.mergeWith(defaultTmsConfig$1, tmsConfig);
|
|
557
|
+
return loadash.mergeWith({}, defaultTmsConfig$1, tmsConfig);
|
|
541
558
|
};
|
|
542
559
|
/**
|
|
543
560
|
* 读取tms.private.config.js
|
|
561
|
+
* @param {string} configPath tms.private.config.js的路径
|
|
544
562
|
*/
|
|
545
563
|
|
|
546
564
|
|
|
547
|
-
const readTmsPrivateCf = function () {
|
|
565
|
+
const readTmsPrivateCf = function (configPath) {
|
|
548
566
|
let tmsPrivateCf = {};
|
|
549
|
-
const tmsPrivatePath = resolve(TMS_PRIVATE_FILENAME);
|
|
567
|
+
const tmsPrivatePath = configPath ? `${configPath}/${TMS_PRIVATE_FILENAME}` : resolve(TMS_PRIVATE_FILENAME);
|
|
550
568
|
|
|
551
569
|
if (fs.existsSync(tmsPrivatePath)) {
|
|
552
570
|
const tmsPrivateFn = require(tmsPrivatePath);
|
|
@@ -558,13 +576,14 @@ var defaultTmsConfig = {
|
|
|
558
576
|
};
|
|
559
577
|
/**
|
|
560
578
|
* 获取tms.config.js, tms.private.config.js的配置项
|
|
579
|
+
* @param {string} configPath config.js的路径
|
|
561
580
|
* @returns
|
|
562
581
|
*/
|
|
563
582
|
|
|
564
583
|
|
|
565
|
-
const getTmsConfig =
|
|
566
|
-
const tmsPrivateCf = readTmsPrivateCf();
|
|
567
|
-
const tmsConfig = readTmsConfig();
|
|
584
|
+
const getTmsConfig = configPath => {
|
|
585
|
+
const tmsPrivateCf = readTmsPrivateCf(configPath);
|
|
586
|
+
const tmsConfig = readTmsConfig(configPath);
|
|
568
587
|
const modules = {};
|
|
569
588
|
|
|
570
589
|
if (Array.isArray(tmsConfig.modules)) {
|
|
@@ -822,8 +841,8 @@ var defaultTmsConfig = {
|
|
|
822
841
|
};
|
|
823
842
|
})(tmsMpconfig);
|
|
824
843
|
|
|
825
|
-
const fs$
|
|
826
|
-
const path$
|
|
844
|
+
const fs$f = require$$0__default$1;
|
|
845
|
+
const path$d = require$$1__default$1;
|
|
827
846
|
const {
|
|
828
847
|
info: info$b
|
|
829
848
|
} = log$1;
|
|
@@ -836,12 +855,12 @@ const {
|
|
|
836
855
|
* @returns
|
|
837
856
|
*/
|
|
838
857
|
|
|
839
|
-
const isDirEmpty = dirname => fs$
|
|
858
|
+
const isDirEmpty = dirname => fs$f.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
840
859
|
|
|
841
860
|
|
|
842
861
|
const isFile = pathName => {
|
|
843
862
|
try {
|
|
844
|
-
const stat = fs$
|
|
863
|
+
const stat = fs$f.lstatSync(pathName);
|
|
845
864
|
return stat.isFile();
|
|
846
865
|
} catch {
|
|
847
866
|
return false;
|
|
@@ -853,9 +872,9 @@ const isFile = pathName => {
|
|
|
853
872
|
*/
|
|
854
873
|
|
|
855
874
|
|
|
856
|
-
const ensureDirExist$
|
|
857
|
-
if (!fs$
|
|
858
|
-
fs$
|
|
875
|
+
const ensureDirExist$4 = dirname => {
|
|
876
|
+
if (!fs$f.existsSync(dirname)) {
|
|
877
|
+
fs$f.mkdirSync(dirname, {
|
|
859
878
|
recursive: true
|
|
860
879
|
});
|
|
861
880
|
}
|
|
@@ -863,20 +882,20 @@ const ensureDirExist$2 = dirname => {
|
|
|
863
882
|
|
|
864
883
|
|
|
865
884
|
const copyFile = function (src, dest) {
|
|
866
|
-
if (fs$
|
|
867
|
-
fs$
|
|
885
|
+
if (fs$f.existsSync(dest)) {
|
|
886
|
+
fs$f.unlinkSync(dest);
|
|
868
887
|
}
|
|
869
888
|
|
|
870
|
-
const dir = path$
|
|
871
|
-
ensureDirExist$
|
|
872
|
-
fs$
|
|
889
|
+
const dir = path$d.dirname(dest);
|
|
890
|
+
ensureDirExist$4(dir);
|
|
891
|
+
fs$f.copyFileSync(src, dest);
|
|
873
892
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
874
893
|
|
|
875
894
|
|
|
876
|
-
function diffContentCopyFile
|
|
877
|
-
if (fs$
|
|
878
|
-
const depDestContent = fs$
|
|
879
|
-
const depOriginContent = fs$
|
|
895
|
+
function diffContentCopyFile(originFile, destFile) {
|
|
896
|
+
if (fs$f.existsSync(destFile)) {
|
|
897
|
+
const depDestContent = fs$f.readFileSync(destFile, 'utf8');
|
|
898
|
+
const depOriginContent = fs$f.readFileSync(originFile, 'utf8');
|
|
880
899
|
|
|
881
900
|
if (depDestContent !== depOriginContent) {
|
|
882
901
|
info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
@@ -889,12 +908,12 @@ function diffContentCopyFile$3(originFile, destFile) {
|
|
|
889
908
|
} // 添加后缀
|
|
890
909
|
|
|
891
910
|
|
|
892
|
-
function ext
|
|
911
|
+
function ext(filePath, extensions) {
|
|
893
912
|
let newFilePath = filePath;
|
|
894
913
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
895
914
|
|
|
896
915
|
try {
|
|
897
|
-
const stat = fs$
|
|
916
|
+
const stat = fs$f.lstatSync(newFilePath);
|
|
898
917
|
|
|
899
918
|
if (stat.isDirectory()) {
|
|
900
919
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -905,7 +924,7 @@ function ext$3(filePath, extensions) {
|
|
|
905
924
|
for (const ext of extensions) {
|
|
906
925
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
907
926
|
|
|
908
|
-
if (fs$
|
|
927
|
+
if (fs$f.existsSync(file)) {
|
|
909
928
|
return {
|
|
910
929
|
ext,
|
|
911
930
|
extPath: extPath + ext,
|
|
@@ -922,12 +941,12 @@ function ext$3(filePath, extensions) {
|
|
|
922
941
|
} // 判断文件是否在某个目录
|
|
923
942
|
|
|
924
943
|
|
|
925
|
-
const fileInDir
|
|
926
|
-
if (!fs$
|
|
944
|
+
const fileInDir = (dir, file) => {
|
|
945
|
+
if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
|
|
927
946
|
return false;
|
|
928
947
|
}
|
|
929
948
|
|
|
930
|
-
const relativePath = path$
|
|
949
|
+
const relativePath = path$d.relative(dir, file);
|
|
931
950
|
|
|
932
951
|
if (relativePath.startsWith('..')) {
|
|
933
952
|
return false;
|
|
@@ -936,14 +955,14 @@ const fileInDir$3 = (dir, file) => {
|
|
|
936
955
|
return true;
|
|
937
956
|
};
|
|
938
957
|
|
|
939
|
-
function findAllFilesOfDir
|
|
958
|
+
function findAllFilesOfDir(dir) {
|
|
940
959
|
const list = [];
|
|
941
960
|
|
|
942
961
|
function listFile(dir) {
|
|
943
|
-
const arr = fs$
|
|
962
|
+
const arr = fs$f.readdirSync(dir);
|
|
944
963
|
arr.forEach(item => {
|
|
945
|
-
const fullPath = path$
|
|
946
|
-
const stats = fs$
|
|
964
|
+
const fullPath = path$d.join(dir, item);
|
|
965
|
+
const stats = fs$f.statSync(fullPath);
|
|
947
966
|
|
|
948
967
|
if (stats.isDirectory()) {
|
|
949
968
|
listFile(fullPath);
|
|
@@ -961,15 +980,15 @@ function findAllFilesOfDir$1(dir) {
|
|
|
961
980
|
var io$3 = {
|
|
962
981
|
isDirEmpty,
|
|
963
982
|
copyFile,
|
|
964
|
-
diffContentCopyFile
|
|
965
|
-
ensureDirExist: ensureDirExist$
|
|
966
|
-
ext
|
|
967
|
-
fileInDir
|
|
983
|
+
diffContentCopyFile,
|
|
984
|
+
ensureDirExist: ensureDirExist$4,
|
|
985
|
+
ext,
|
|
986
|
+
fileInDir,
|
|
968
987
|
isFile,
|
|
969
|
-
findAllFilesOfDir
|
|
988
|
+
findAllFilesOfDir
|
|
970
989
|
};
|
|
971
990
|
|
|
972
|
-
const async = require$$0__default$
|
|
991
|
+
const async = require$$0__default$3;
|
|
973
992
|
const ejs = require$$1__default$3;
|
|
974
993
|
|
|
975
994
|
const render$1 = (files, metalsmith, next) => {
|
|
@@ -989,14 +1008,14 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
989
1008
|
|
|
990
1009
|
var render_1 = render$1;
|
|
991
1010
|
|
|
992
|
-
const fs$
|
|
993
|
-
const inquirer$
|
|
1011
|
+
const fs$e = require$$0__default$1;
|
|
1012
|
+
const inquirer$2 = require$$1__default$4;
|
|
994
1013
|
const {
|
|
995
|
-
resolve: resolve$
|
|
1014
|
+
resolve: resolve$d
|
|
996
1015
|
} = widgets;
|
|
997
1016
|
const {
|
|
998
1017
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
999
|
-
} =
|
|
1018
|
+
} = constant;
|
|
1000
1019
|
/**
|
|
1001
1020
|
* 获取模板内的问题
|
|
1002
1021
|
* @param {string} dir questions.json所在的目录
|
|
@@ -1006,12 +1025,12 @@ const {
|
|
|
1006
1025
|
const parseTemplateQuestions = dir => {
|
|
1007
1026
|
let prompts = [];
|
|
1008
1027
|
|
|
1009
|
-
if (!fs$
|
|
1028
|
+
if (!fs$e.existsSync(`${dir}/questions.json`)) {
|
|
1010
1029
|
return prompts;
|
|
1011
1030
|
}
|
|
1012
1031
|
|
|
1013
1032
|
try {
|
|
1014
|
-
const json = JSON.parse(fs$
|
|
1033
|
+
const json = JSON.parse(fs$e.readFileSync(`${dir}/questions.json`));
|
|
1015
1034
|
|
|
1016
1035
|
if (Array.isArray(json) && json.length > 0) {
|
|
1017
1036
|
json.forEach((item, index) => {
|
|
@@ -1044,7 +1063,7 @@ const isQuestionType = result => {
|
|
|
1044
1063
|
};
|
|
1045
1064
|
|
|
1046
1065
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
1047
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
1066
|
+
const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
1048
1067
|
const metadata = metalsmith.metadata();
|
|
1049
1068
|
const filteredPrompts = prompts.filter(prompt => {
|
|
1050
1069
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -1053,7 +1072,7 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
|
1053
1072
|
|
|
1054
1073
|
return true;
|
|
1055
1074
|
});
|
|
1056
|
-
inquirer$
|
|
1075
|
+
inquirer$2.prompt(filteredPrompts).then(res => {
|
|
1057
1076
|
for (const prompt of filteredPrompts) {
|
|
1058
1077
|
metadata[prompt.name] = res[prompt.name];
|
|
1059
1078
|
}
|
|
@@ -1069,7 +1088,7 @@ var ask_1 = ask$1;
|
|
|
1069
1088
|
const FILES_TO_IGNORE$1 = ['node_modules'];
|
|
1070
1089
|
var ignoreFiles = FILES_TO_IGNORE$1;
|
|
1071
1090
|
|
|
1072
|
-
const Metalsmith = require$$0__default$
|
|
1091
|
+
const Metalsmith = require$$0__default$4;
|
|
1073
1092
|
const render = render_1;
|
|
1074
1093
|
const ask = ask_1;
|
|
1075
1094
|
const FILES_TO_IGNORE = ignoreFiles;
|
|
@@ -1086,19 +1105,57 @@ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolv
|
|
|
1086
1105
|
|
|
1087
1106
|
var generator_1 = generator$1;
|
|
1088
1107
|
|
|
1089
|
-
const
|
|
1090
|
-
const
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1108
|
+
const request$2 = require$$0__default$5;
|
|
1109
|
+
const shelljs$8 = require$$2__default;
|
|
1110
|
+
const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
|
|
1111
|
+
|
|
1112
|
+
function getGitUser() {
|
|
1113
|
+
const res = shelljs$8.exec('git config user.name', {
|
|
1114
|
+
async: false,
|
|
1115
|
+
silent: true
|
|
1116
|
+
});
|
|
1117
|
+
return res.stdout;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
const report$8 = (name, attrs = {}) => {
|
|
1121
|
+
try {
|
|
1122
|
+
const param = [];
|
|
1123
|
+
param[27] = name;
|
|
1124
|
+
param[28] = 'tmskit';
|
|
1125
|
+
param[29] = getGitUser();
|
|
1126
|
+
param[30] = JSON.stringify(attrs);
|
|
1127
|
+
|
|
1128
|
+
for (let i = 0; i < 40; i++) {
|
|
1129
|
+
if (!param[i]) param[i] = null;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
;
|
|
1133
|
+
request$2.post({
|
|
1134
|
+
url: apiUrl,
|
|
1135
|
+
json: {
|
|
1136
|
+
param
|
|
1137
|
+
}
|
|
1138
|
+
}); // (error, response, body) => {
|
|
1139
|
+
// console.log('body:', body);
|
|
1140
|
+
// }
|
|
1141
|
+
} catch (e) {}
|
|
1142
|
+
};
|
|
1143
|
+
|
|
1144
|
+
var report_1 = report$8;
|
|
1145
|
+
|
|
1146
|
+
const path$c = require$$1__default$1;
|
|
1147
|
+
const fs$d = require$$0__default$1;
|
|
1148
|
+
const shelljs$7 = require$$2__default;
|
|
1149
|
+
const inquirer$1 = require$$1__default$4;
|
|
1093
1150
|
const {
|
|
1094
1151
|
TEMPLATE_DIR,
|
|
1095
1152
|
TEMPLATE_URL,
|
|
1096
1153
|
TEMPLATE_NAME,
|
|
1097
1154
|
TEMPLATE_TKIT_DIR,
|
|
1098
1155
|
CREATE_TEMPLATE_QUESTION
|
|
1099
|
-
} =
|
|
1156
|
+
} = constant;
|
|
1100
1157
|
const {
|
|
1101
|
-
resolve: resolve$
|
|
1158
|
+
resolve: resolve$c
|
|
1102
1159
|
} = widgets;
|
|
1103
1160
|
const io$2 = io$3;
|
|
1104
1161
|
const {
|
|
@@ -1107,8 +1164,9 @@ const {
|
|
|
1107
1164
|
info: info$a
|
|
1108
1165
|
} = log$1;
|
|
1109
1166
|
const generator = generator_1;
|
|
1110
|
-
const request = require$$
|
|
1167
|
+
const request$1 = require$$0__default$5;
|
|
1111
1168
|
const unzip = require$$10__default;
|
|
1169
|
+
const report$7 = report_1;
|
|
1112
1170
|
/**
|
|
1113
1171
|
* 如果该目录下面存在文件,换个名字
|
|
1114
1172
|
* @param { string } targetDir 当前文件夹
|
|
@@ -1117,13 +1175,13 @@ const unzip = require$$10__default;
|
|
|
1117
1175
|
|
|
1118
1176
|
async function createProjectDir(targetDir) {
|
|
1119
1177
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
1120
|
-
if (fs$
|
|
1178
|
+
if (fs$d.existsSync(targetDir)) {
|
|
1121
1179
|
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
1122
1180
|
fail$8('该目录名已经存在,换个项目名字吧~');
|
|
1123
1181
|
process.exit(1);
|
|
1124
1182
|
}
|
|
1125
1183
|
} else {
|
|
1126
|
-
shelljs$
|
|
1184
|
+
shelljs$7.mkdir('-p', targetDir);
|
|
1127
1185
|
}
|
|
1128
1186
|
}
|
|
1129
1187
|
/**
|
|
@@ -1138,14 +1196,14 @@ async function createProjectDir(targetDir) {
|
|
|
1138
1196
|
function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
|
|
1139
1197
|
return new Promise((resolve, reject) => {
|
|
1140
1198
|
const localZipPath = `${templateDir}/${templateName}.zip`;
|
|
1141
|
-
const stream = fs$
|
|
1142
|
-
request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
|
|
1199
|
+
const stream = fs$d.createWriteStream(localZipPath);
|
|
1200
|
+
request$1(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
|
|
1143
1201
|
if (err) {
|
|
1144
1202
|
reject(err);
|
|
1145
1203
|
return;
|
|
1146
1204
|
}
|
|
1147
1205
|
|
|
1148
|
-
fs$
|
|
1206
|
+
fs$d.createReadStream(localZipPath).pipe(unzip.Extract({
|
|
1149
1207
|
path: templateDir
|
|
1150
1208
|
})).on('close', err => {
|
|
1151
1209
|
if (err) {
|
|
@@ -1167,45 +1225,51 @@ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
|
|
|
1167
1225
|
|
|
1168
1226
|
async function create(projectName) {
|
|
1169
1227
|
const cwd = process.cwd();
|
|
1170
|
-
const targetDir = path$
|
|
1228
|
+
const targetDir = path$c.resolve(cwd, projectName);
|
|
1171
1229
|
const {
|
|
1172
1230
|
projectType
|
|
1173
|
-
} = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
|
|
1231
|
+
} = await inquirer$1.prompt(CREATE_TEMPLATE_QUESTION);
|
|
1232
|
+
report$7('create-start', {
|
|
1233
|
+
projectType
|
|
1234
|
+
}); // 创建项目目录
|
|
1174
1235
|
|
|
1175
1236
|
await createProjectDir(targetDir); // 新创建缓存目录
|
|
1176
1237
|
|
|
1177
|
-
if (fs$
|
|
1178
|
-
shelljs$
|
|
1238
|
+
if (fs$d.existsSync(TEMPLATE_DIR)) {
|
|
1239
|
+
shelljs$7.rm('-rf', TEMPLATE_DIR);
|
|
1179
1240
|
}
|
|
1180
1241
|
|
|
1181
|
-
fs$
|
|
1242
|
+
fs$d.mkdirSync(TEMPLATE_DIR, {
|
|
1182
1243
|
recursive: true
|
|
1183
1244
|
}); // 下载和解压模板
|
|
1184
1245
|
|
|
1185
1246
|
await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
1186
1247
|
|
|
1187
|
-
generator(path$
|
|
1188
|
-
shelljs$
|
|
1189
|
-
const hookFilePath = resolve$
|
|
1248
|
+
generator(path$c.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
|
|
1249
|
+
shelljs$7.cd(projectName);
|
|
1250
|
+
const hookFilePath = resolve$c(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
|
|
1190
1251
|
|
|
1191
|
-
if (fs$
|
|
1252
|
+
if (fs$d.existsSync(hookFilePath)) {
|
|
1192
1253
|
const hooks = require(hookFilePath);
|
|
1193
1254
|
|
|
1194
1255
|
if (hooks.afterCreate) {
|
|
1195
1256
|
hooks.afterCreate.forEach(item => {
|
|
1196
1257
|
if (typeof item === 'function') {
|
|
1197
|
-
item.call(null, shelljs$
|
|
1258
|
+
item.call(null, shelljs$7, {
|
|
1198
1259
|
projectName
|
|
1199
1260
|
});
|
|
1200
1261
|
} else {
|
|
1201
|
-
shelljs$
|
|
1262
|
+
shelljs$7.exec(item);
|
|
1202
1263
|
}
|
|
1203
1264
|
});
|
|
1204
1265
|
}
|
|
1205
1266
|
|
|
1206
|
-
shelljs$
|
|
1267
|
+
shelljs$7.rm('-rf', resolve$c(projectName, TEMPLATE_TKIT_DIR));
|
|
1207
1268
|
}
|
|
1208
1269
|
|
|
1270
|
+
report$7('create-success', {
|
|
1271
|
+
projectType
|
|
1272
|
+
});
|
|
1209
1273
|
succeed$1('项目创建完成.');
|
|
1210
1274
|
}).catch(err => {
|
|
1211
1275
|
fail$8(err.message);
|
|
@@ -1215,7 +1279,95 @@ async function create(projectName) {
|
|
|
1215
1279
|
|
|
1216
1280
|
var create_1 = create;
|
|
1217
1281
|
|
|
1218
|
-
const
|
|
1282
|
+
const fs$c = require$$0__default$1;
|
|
1283
|
+
const path$b = require$$1__default$1;
|
|
1284
|
+
const shellJs$1 = require$$2__default;
|
|
1285
|
+
const {
|
|
1286
|
+
ensureDirExist: ensureDirExist$3
|
|
1287
|
+
} = io$3;
|
|
1288
|
+
const {
|
|
1289
|
+
EXTEND_CMD
|
|
1290
|
+
} = constant;
|
|
1291
|
+
const {
|
|
1292
|
+
createTask: createTask$2
|
|
1293
|
+
} = widgets;
|
|
1294
|
+
const {
|
|
1295
|
+
info: info$9,
|
|
1296
|
+
fail: fail$7
|
|
1297
|
+
} = log$1;
|
|
1298
|
+
/**
|
|
1299
|
+
* 下载扩展命令的npm包
|
|
1300
|
+
* @param {string} npmName npm包名
|
|
1301
|
+
* @param {object} cmd {registry: 'http://mirrors.tencent.com/npm/'} 用户输入执行install-cmd的参数
|
|
1302
|
+
*/
|
|
1303
|
+
|
|
1304
|
+
async function installCmd(npmName, cmd) {
|
|
1305
|
+
try {
|
|
1306
|
+
const cmdPackageJson = `${EXTEND_CMD}/package.json`;
|
|
1307
|
+
|
|
1308
|
+
if (!fs$c.existsSync(cmdPackageJson)) {
|
|
1309
|
+
ensureDirExist$3(EXTEND_CMD);
|
|
1310
|
+
fs$c.writeFileSync(cmdPackageJson, JSON.stringify({
|
|
1311
|
+
dependencies: {}
|
|
1312
|
+
}, null, 2));
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
shellJs$1.cd(EXTEND_CMD);
|
|
1316
|
+
await createTask$2(npmName => new Promise((resolve, reject) => {
|
|
1317
|
+
const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
|
|
1318
|
+
shellJs$1.exec(`npm install --save ${npmName} ${registry}`, {
|
|
1319
|
+
cwd: EXTEND_CMD,
|
|
1320
|
+
silent: true
|
|
1321
|
+
}, (code, stdout, stderr) => {
|
|
1322
|
+
if (code !== 0) {
|
|
1323
|
+
reject(stderr);
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
resolve();
|
|
1327
|
+
});
|
|
1328
|
+
}), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
|
|
1329
|
+
} catch (e) {
|
|
1330
|
+
fail$7('构建出现错误:');
|
|
1331
|
+
info$9(e);
|
|
1332
|
+
process.exit(1);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* 加载扩展命令的npm包
|
|
1337
|
+
* @returns
|
|
1338
|
+
*/
|
|
1339
|
+
|
|
1340
|
+
|
|
1341
|
+
function loadExtendCmd$1() {
|
|
1342
|
+
const cmdPackageJson = `${EXTEND_CMD}/package.json`;
|
|
1343
|
+
const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
|
|
1344
|
+
|
|
1345
|
+
if (fs$c.existsSync(cmdPackageJson)) {
|
|
1346
|
+
const content = fs$c.readFileSync(cmdPackageJson, 'utf8');
|
|
1347
|
+
const json = JSON.parse(content);
|
|
1348
|
+
const deps = json.dependencies || {};
|
|
1349
|
+
const cmdConfigs = [];
|
|
1350
|
+
Object.keys(deps).forEach(name => {
|
|
1351
|
+
// 检索cmd的npm包
|
|
1352
|
+
if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
|
|
1353
|
+
const cmdConfig = path$b.join(cmdNpmDir, name, 'tms.config.js');
|
|
1354
|
+
|
|
1355
|
+
if (fs$c.existsSync(cmdConfig)) {
|
|
1356
|
+
cmdConfigs.push(cmdConfig);
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
return cmdConfigs;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
return [];
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
var extendCmd = {
|
|
1366
|
+
installCmd,
|
|
1367
|
+
loadExtendCmd: loadExtendCmd$1
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
const global$7 = {
|
|
1219
1371
|
data: {},
|
|
1220
1372
|
|
|
1221
1373
|
setData(...args) {
|
|
@@ -1237,30 +1389,30 @@ const global$6 = {
|
|
|
1237
1389
|
|
|
1238
1390
|
};
|
|
1239
1391
|
var global_1 = {
|
|
1240
|
-
global: global$
|
|
1392
|
+
global: global$7
|
|
1241
1393
|
};
|
|
1242
1394
|
|
|
1243
1395
|
const {
|
|
1244
|
-
fail: fail$
|
|
1396
|
+
fail: fail$6
|
|
1245
1397
|
} = log$1;
|
|
1246
1398
|
const {
|
|
1247
|
-
global: global$
|
|
1399
|
+
global: global$6
|
|
1248
1400
|
} = global_1;
|
|
1249
1401
|
|
|
1250
1402
|
function handleError$5(error, isQuit = false) {
|
|
1251
1403
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1252
1404
|
|
|
1253
1405
|
if (isQuit) {
|
|
1254
|
-
fail$
|
|
1406
|
+
fail$6(errMsg);
|
|
1255
1407
|
process.exit(1);
|
|
1256
1408
|
}
|
|
1257
1409
|
|
|
1258
|
-
const isDev = global$
|
|
1410
|
+
const isDev = global$6.getData('isDev');
|
|
1259
1411
|
|
|
1260
1412
|
if (isDev) {
|
|
1261
|
-
fail$
|
|
1413
|
+
fail$6(errMsg);
|
|
1262
1414
|
} else {
|
|
1263
|
-
fail$
|
|
1415
|
+
fail$6(errMsg);
|
|
1264
1416
|
process.exit(1);
|
|
1265
1417
|
}
|
|
1266
1418
|
}
|
|
@@ -1274,25 +1426,26 @@ var handleError_1 = {
|
|
|
1274
1426
|
*/
|
|
1275
1427
|
/* eslint-disable no-param-reassign */
|
|
1276
1428
|
|
|
1277
|
-
const fs$
|
|
1429
|
+
const fs$b = require$$0__default$1;
|
|
1278
1430
|
const {
|
|
1279
1431
|
getSubPackages: getSubPackages$3,
|
|
1280
1432
|
getModulesConfig
|
|
1281
1433
|
} = tmsMpconfig.exports;
|
|
1282
1434
|
const {
|
|
1283
|
-
fail: fail$
|
|
1284
|
-
info: info$
|
|
1435
|
+
fail: fail$5,
|
|
1436
|
+
info: info$8
|
|
1285
1437
|
} = log$1;
|
|
1286
1438
|
const {
|
|
1287
|
-
resolve: resolve$
|
|
1288
|
-
filterField: filterField$
|
|
1439
|
+
resolve: resolve$b,
|
|
1440
|
+
filterField: filterField$4
|
|
1289
1441
|
} = widgets;
|
|
1290
1442
|
const {
|
|
1291
1443
|
handleError: handleError$4
|
|
1292
1444
|
} = handleError_1;
|
|
1293
1445
|
const {
|
|
1294
|
-
global: global$
|
|
1446
|
+
global: global$5
|
|
1295
1447
|
} = global_1;
|
|
1448
|
+
const report$6 = report_1;
|
|
1296
1449
|
/**
|
|
1297
1450
|
* 更新appJson里面的主包配置
|
|
1298
1451
|
* @param { object } appJson appJson信息
|
|
@@ -1300,7 +1453,7 @@ const {
|
|
|
1300
1453
|
* @returns { object } appJson小程序主页配置信息
|
|
1301
1454
|
*/
|
|
1302
1455
|
|
|
1303
|
-
function updateMainPackages(appJson, mainPackages
|
|
1456
|
+
function updateMainPackages(appJson, mainPackages) {
|
|
1304
1457
|
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1305
1458
|
|
|
1306
1459
|
if (foundMainPackages.length === 0) {
|
|
@@ -1311,7 +1464,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1311
1464
|
|
|
1312
1465
|
foundMainPackages.forEach(subpackage => {
|
|
1313
1466
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
1314
|
-
fail$
|
|
1467
|
+
fail$5(`主包 ${subpackage} 不能没有 pages`);
|
|
1315
1468
|
process.exit(-1);
|
|
1316
1469
|
}
|
|
1317
1470
|
|
|
@@ -1336,12 +1489,12 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1336
1489
|
|
|
1337
1490
|
|
|
1338
1491
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
1339
|
-
if (!fs$
|
|
1340
|
-
fail$
|
|
1492
|
+
if (!fs$b.existsSync(sourceAppJsonPath)) {
|
|
1493
|
+
fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1341
1494
|
process.exit(1);
|
|
1342
1495
|
}
|
|
1343
1496
|
|
|
1344
|
-
const appJson = JSON.parse(fs$
|
|
1497
|
+
const appJson = JSON.parse(fs$b.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1345
1498
|
|
|
1346
1499
|
appJson.subpackages = [];
|
|
1347
1500
|
appJson.pages = [];
|
|
@@ -1386,7 +1539,7 @@ const fixAppJson = appJson => {
|
|
|
1386
1539
|
appJson[key] = preloadRuleMap;
|
|
1387
1540
|
}
|
|
1388
1541
|
});
|
|
1389
|
-
return filterField$
|
|
1542
|
+
return filterField$4(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
|
|
1390
1543
|
}); // 如果plugins重复,则错误提示
|
|
1391
1544
|
|
|
1392
1545
|
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
@@ -1420,7 +1573,7 @@ function buildOutputAppJson$2(tmsConfig, modules) {
|
|
|
1420
1573
|
|
|
1421
1574
|
const subPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
|
|
1422
1575
|
|
|
1423
|
-
const appJson = getAppJsonContent(resolve$
|
|
1576
|
+
const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
|
|
1424
1577
|
|
|
1425
1578
|
appJson.subpackages = subPackages;
|
|
1426
1579
|
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name)); // 处理appJson中重复||冲突的地方
|
|
@@ -1428,23 +1581,24 @@ function buildOutputAppJson$2(tmsConfig, modules) {
|
|
|
1428
1581
|
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1429
1582
|
|
|
1430
1583
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1431
|
-
fs$
|
|
1584
|
+
fs$b.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1432
1585
|
|
|
1433
1586
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1434
1587
|
var _tmsConfig$hooks2;
|
|
1435
1588
|
|
|
1436
1589
|
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1437
|
-
tmsConfig: filterField$
|
|
1590
|
+
tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
|
|
1438
1591
|
modules,
|
|
1439
1592
|
appJson,
|
|
1440
|
-
isDev: global$
|
|
1593
|
+
isDev: global$5.getData('isDev')
|
|
1441
1594
|
});
|
|
1595
|
+
report$6('hooks:updateAppJson');
|
|
1442
1596
|
}
|
|
1443
1597
|
|
|
1444
1598
|
return appJson;
|
|
1445
1599
|
} catch (e) {
|
|
1446
1600
|
handleError$4(`生成app.json出现错误: ${e}`);
|
|
1447
|
-
info$
|
|
1601
|
+
info$8(e);
|
|
1448
1602
|
}
|
|
1449
1603
|
}
|
|
1450
1604
|
|
|
@@ -1455,24 +1609,24 @@ var buildAppJson = {
|
|
|
1455
1609
|
/**
|
|
1456
1610
|
* 下载第三方代码
|
|
1457
1611
|
*/
|
|
1458
|
-
const MetalSmith = require$$0__default$
|
|
1612
|
+
const MetalSmith = require$$0__default$4;
|
|
1459
1613
|
const crypto$2 = require$$1__default$5;
|
|
1460
1614
|
const {
|
|
1461
1615
|
downloadRepoForGit,
|
|
1462
1616
|
pullRepoForGit,
|
|
1463
|
-
resolve: resolve$
|
|
1617
|
+
resolve: resolve$a
|
|
1464
1618
|
} = widgets;
|
|
1465
1619
|
const {
|
|
1466
|
-
fail: fail$
|
|
1467
|
-
info: info$
|
|
1620
|
+
fail: fail$4,
|
|
1621
|
+
info: info$7
|
|
1468
1622
|
} = log$1;
|
|
1469
|
-
const fs$
|
|
1470
|
-
const shelljs$
|
|
1623
|
+
const fs$a = require$$0__default$1;
|
|
1624
|
+
const shelljs$6 = require$$2__default;
|
|
1471
1625
|
const {
|
|
1472
1626
|
handleError: handleError$3
|
|
1473
1627
|
} = handleError_1;
|
|
1474
1628
|
const {
|
|
1475
|
-
global: global$
|
|
1629
|
+
global: global$4
|
|
1476
1630
|
} = global_1;
|
|
1477
1631
|
/**
|
|
1478
1632
|
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
@@ -1485,7 +1639,7 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
1485
1639
|
var _tmsConfig$gitAccount;
|
|
1486
1640
|
|
|
1487
1641
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1488
|
-
const tmsConfig = global$
|
|
1642
|
+
const tmsConfig = global$4.getData('tmsConfig');
|
|
1489
1643
|
let gitUrl = httpRepoUrl;
|
|
1490
1644
|
const {
|
|
1491
1645
|
username = '',
|
|
@@ -1508,12 +1662,16 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
1508
1662
|
*/
|
|
1509
1663
|
|
|
1510
1664
|
|
|
1511
|
-
function moveFile(sourceDir, targetDir, ignore
|
|
1512
|
-
|
|
1665
|
+
function moveFile(sourceDir, targetDir, ignore) {
|
|
1666
|
+
if (fs$a.existsSync(targetDir)) {
|
|
1667
|
+
shelljs$6.rm('-rf', targetDir);
|
|
1668
|
+
} // 删除不是文件夹的文件
|
|
1669
|
+
|
|
1670
|
+
|
|
1513
1671
|
return new Promise((resolve, reject) => {
|
|
1514
1672
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1515
1673
|
if (e) {
|
|
1516
|
-
fail$
|
|
1674
|
+
fail$4(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1517
1675
|
reject(e);
|
|
1518
1676
|
}
|
|
1519
1677
|
|
|
@@ -1566,7 +1724,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1566
1724
|
}));
|
|
1567
1725
|
});
|
|
1568
1726
|
await Promise.all(arrPromises);
|
|
1569
|
-
shelljs$
|
|
1727
|
+
shelljs$6.cd(cwd);
|
|
1570
1728
|
}
|
|
1571
1729
|
/**
|
|
1572
1730
|
* 收集下载模块代码的任务
|
|
@@ -1607,9 +1765,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1607
1765
|
|
|
1608
1766
|
const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
|
|
1609
1767
|
|
|
1610
|
-
const sourcePath = resolve$
|
|
1768
|
+
const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
|
|
1611
1769
|
|
|
1612
|
-
const targetPath = resolve$
|
|
1770
|
+
const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
|
|
1613
1771
|
|
|
1614
1772
|
const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
|
|
1615
1773
|
|
|
@@ -1619,8 +1777,8 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1619
1777
|
targetPath
|
|
1620
1778
|
},
|
|
1621
1779
|
fn: async (sourceModulePath, targetPath) => {
|
|
1622
|
-
if (fs$
|
|
1623
|
-
shelljs$
|
|
1780
|
+
if (fs$a.existsSync(targetPath)) {
|
|
1781
|
+
shelljs$6.rm('-rf', `${targetPath}/*`);
|
|
1624
1782
|
}
|
|
1625
1783
|
|
|
1626
1784
|
await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
|
|
@@ -1634,14 +1792,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1634
1792
|
} else {
|
|
1635
1793
|
let promiseTask;
|
|
1636
1794
|
|
|
1637
|
-
if (fs$
|
|
1795
|
+
if (fs$a.existsSync(sourcePath) && fs$a.existsSync(`${sourcePath}/.git`)) {
|
|
1638
1796
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1639
|
-
info$
|
|
1797
|
+
info$7(`git pull:${httpRepoUrl}`);
|
|
1640
1798
|
return pullRepoForGit(sourcePath, branch);
|
|
1641
1799
|
};
|
|
1642
1800
|
} else {
|
|
1643
1801
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1644
|
-
info$
|
|
1802
|
+
info$7(`git clone: ${httpRepoUrl}`);
|
|
1645
1803
|
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
1646
1804
|
};
|
|
1647
1805
|
}
|
|
@@ -1682,7 +1840,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
|
1682
1840
|
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
|
|
1683
1841
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1684
1842
|
|
|
1685
|
-
if (!fs$
|
|
1843
|
+
if (!fs$a.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1686
1844
|
return true;
|
|
1687
1845
|
}
|
|
1688
1846
|
}
|
|
@@ -1695,8 +1853,8 @@ var cloneModules_1 = {
|
|
|
1695
1853
|
checkRemoteModGitUrlBranch
|
|
1696
1854
|
};
|
|
1697
1855
|
|
|
1698
|
-
const ci = require$$0__default$
|
|
1699
|
-
const path$a = require$$1__default$
|
|
1856
|
+
const ci = require$$0__default$6;
|
|
1857
|
+
const path$a = require$$1__default$1;
|
|
1700
1858
|
/**
|
|
1701
1859
|
* 获取小程序ci的Project对象
|
|
1702
1860
|
* @returns {Object} 小程序ci对象
|
|
@@ -1776,22 +1934,21 @@ var mpCi = {
|
|
|
1776
1934
|
buildMpNpm: buildMpNpm$1
|
|
1777
1935
|
};
|
|
1778
1936
|
|
|
1779
|
-
const fs$
|
|
1780
|
-
const path$9 = require$$1__default$
|
|
1937
|
+
const fs$9 = require$$0__default$1;
|
|
1938
|
+
const path$9 = require$$1__default$1;
|
|
1781
1939
|
const {
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
} = require$$5;
|
|
1940
|
+
NPM_CACHE_FILE
|
|
1941
|
+
} = constant;
|
|
1785
1942
|
const {
|
|
1786
|
-
ensureDirExist: ensureDirExist$
|
|
1943
|
+
ensureDirExist: ensureDirExist$2
|
|
1787
1944
|
} = io$3;
|
|
1788
1945
|
|
|
1789
1946
|
function getCache$1(projectDir, type) {
|
|
1790
1947
|
var _content$projectDir;
|
|
1791
1948
|
|
|
1792
|
-
const filePath =
|
|
1949
|
+
const filePath = NPM_CACHE_FILE;
|
|
1793
1950
|
|
|
1794
|
-
if (!fs$
|
|
1951
|
+
if (!fs$9.existsSync(filePath)) {
|
|
1795
1952
|
return null;
|
|
1796
1953
|
}
|
|
1797
1954
|
|
|
@@ -1801,12 +1958,12 @@ function getCache$1(projectDir, type) {
|
|
|
1801
1958
|
}
|
|
1802
1959
|
|
|
1803
1960
|
function setCache$1(projectDir, type = 'miniprogram_npm', data) {
|
|
1804
|
-
const filePath =
|
|
1961
|
+
const filePath = NPM_CACHE_FILE;
|
|
1805
1962
|
|
|
1806
|
-
if (!fs$
|
|
1963
|
+
if (!fs$9.existsSync(filePath)) {
|
|
1807
1964
|
const dir = path$9.dirname(filePath);
|
|
1808
|
-
ensureDirExist$
|
|
1809
|
-
fs$
|
|
1965
|
+
ensureDirExist$2(dir);
|
|
1966
|
+
fs$9.writeFileSync(filePath, '{}');
|
|
1810
1967
|
}
|
|
1811
1968
|
|
|
1812
1969
|
const content = require(filePath);
|
|
@@ -1818,7 +1975,7 @@ function setCache$1(projectDir, type = 'miniprogram_npm', data) {
|
|
|
1818
1975
|
content[projectDir] = {
|
|
1819
1976
|
[type]: data
|
|
1820
1977
|
};
|
|
1821
|
-
fs$
|
|
1978
|
+
fs$9.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
1822
1979
|
}
|
|
1823
1980
|
|
|
1824
1981
|
var cache = {
|
|
@@ -1829,12 +1986,11 @@ var cache = {
|
|
|
1829
1986
|
/**
|
|
1830
1987
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1831
1988
|
*/
|
|
1832
|
-
const fs$
|
|
1989
|
+
const fs$8 = require$$0__default$1;
|
|
1833
1990
|
const fsExtra = require$$1__default$6;
|
|
1834
1991
|
const crypto$1 = require$$1__default$5;
|
|
1835
|
-
const path$8 = require$$1__default$
|
|
1836
|
-
const shell = require$$
|
|
1837
|
-
const glob = require$$6__default;
|
|
1992
|
+
const path$8 = require$$1__default$1;
|
|
1993
|
+
const shell = require$$2__default;
|
|
1838
1994
|
const log = log$1;
|
|
1839
1995
|
const {
|
|
1840
1996
|
npmInstall: npmInstall$1
|
|
@@ -1842,6 +1998,9 @@ const {
|
|
|
1842
1998
|
const {
|
|
1843
1999
|
handleError: handleError$2
|
|
1844
2000
|
} = handleError_1;
|
|
2001
|
+
const {
|
|
2002
|
+
global: global$3
|
|
2003
|
+
} = global_1;
|
|
1845
2004
|
const shellJsOption = {
|
|
1846
2005
|
async: false,
|
|
1847
2006
|
silent: true
|
|
@@ -1864,7 +2023,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1864
2023
|
const npmTasksMap = new Map();
|
|
1865
2024
|
|
|
1866
2025
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1867
|
-
const packageContent = fs$
|
|
2026
|
+
const packageContent = fs$8.readFileSync(packageJsonPath);
|
|
1868
2027
|
let packageJson;
|
|
1869
2028
|
|
|
1870
2029
|
try {
|
|
@@ -1915,7 +2074,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1915
2074
|
fsExtra.emptydirSync(cacheNMPath);
|
|
1916
2075
|
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
1917
2076
|
log.info(`npm install: ${packageJsonPath}`);
|
|
1918
|
-
|
|
2077
|
+
const tmsConfig = global$3.getData('tmsConfig');
|
|
2078
|
+
return npmInstall$1(cacheNMPath, tmsConfig.npm).then(() => {
|
|
1919
2079
|
const newShellJsOption = { ...shellJsOption,
|
|
1920
2080
|
cwd: cacheNMPath
|
|
1921
2081
|
};
|
|
@@ -1988,7 +2148,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1988
2148
|
|
|
1989
2149
|
const find = (startPath, filter) => {
|
|
1990
2150
|
// 目录不存在
|
|
1991
|
-
if (!fs$
|
|
2151
|
+
if (!fs$8.existsSync(startPath)) {
|
|
1992
2152
|
log.fail(`${startPath}目录不存在`);
|
|
1993
2153
|
process.exit(-1);
|
|
1994
2154
|
return;
|
|
@@ -2001,10 +2161,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
2001
2161
|
return;
|
|
2002
2162
|
}
|
|
2003
2163
|
|
|
2004
|
-
const files = fs$
|
|
2164
|
+
const files = fs$8.readdirSync(startPath);
|
|
2005
2165
|
files.forEach(file => {
|
|
2006
2166
|
const filename = path$8.join(startPath, file);
|
|
2007
|
-
const stat = fs$
|
|
2167
|
+
const stat = fs$8.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
2008
2168
|
|
|
2009
2169
|
if (stat.isDirectory()) {
|
|
2010
2170
|
find(filename, filter);
|
|
@@ -2041,39 +2201,19 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
2041
2201
|
return result;
|
|
2042
2202
|
};
|
|
2043
2203
|
|
|
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
2204
|
var npm = {
|
|
2064
|
-
cloudNpmInstall,
|
|
2065
2205
|
npmInstallAll: npmInstallAll$1,
|
|
2066
2206
|
findAllPackageJson,
|
|
2067
2207
|
findFilesByFilter
|
|
2068
2208
|
};
|
|
2069
2209
|
|
|
2070
2210
|
const crypto = require$$1__default$5;
|
|
2071
|
-
const fs$
|
|
2211
|
+
const fs$7 = require$$0__default$1;
|
|
2072
2212
|
|
|
2073
2213
|
function fileMd5$1(filePath) {
|
|
2074
2214
|
return new Promise((resolve, reject) => {
|
|
2075
2215
|
const md5sum = crypto.createHash('md5');
|
|
2076
|
-
const stream = fs$
|
|
2216
|
+
const stream = fs$7.ReadStream(filePath);
|
|
2077
2217
|
stream.on('data', d => {
|
|
2078
2218
|
md5sum.update(d);
|
|
2079
2219
|
});
|
|
@@ -2091,21 +2231,26 @@ var md5 = {
|
|
|
2091
2231
|
fileMd5: fileMd5$1
|
|
2092
2232
|
};
|
|
2093
2233
|
|
|
2094
|
-
const fs$
|
|
2234
|
+
const fs$6 = require$$0__default$1;
|
|
2095
2235
|
const semver$1 = require$$1__default$7;
|
|
2096
2236
|
const {
|
|
2097
|
-
resolve: resolve$
|
|
2237
|
+
resolve: resolve$9,
|
|
2098
2238
|
getAbsolutePath: getAbsolutePath$2
|
|
2099
2239
|
} = widgets;
|
|
2100
|
-
const path$7 = require$$1__default$
|
|
2101
|
-
const shelljs$
|
|
2240
|
+
const path$7 = require$$1__default$1;
|
|
2241
|
+
const shelljs$5 = require$$2__default;
|
|
2102
2242
|
const {
|
|
2103
2243
|
handleError: handleError$1
|
|
2104
2244
|
} = handleError_1;
|
|
2105
2245
|
|
|
2106
2246
|
const getLatestVersion = npmName => {
|
|
2107
|
-
const data = shelljs$
|
|
2108
|
-
|
|
2247
|
+
const data = shelljs$5.exec(`npm view ${npmName} version`);
|
|
2248
|
+
|
|
2249
|
+
if (data.code === 0) {
|
|
2250
|
+
return data.stdout;
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
return '0.0.0';
|
|
2109
2254
|
}; // 收集package.json
|
|
2110
2255
|
|
|
2111
2256
|
|
|
@@ -2115,16 +2260,16 @@ function collectPackageJson(subPackages, cwd, outputDir) {
|
|
|
2115
2260
|
|
|
2116
2261
|
const packageArr = [{
|
|
2117
2262
|
srcPackageDir: path$7.join(cwd, packageJsonName),
|
|
2118
|
-
destNpmDir: resolve$
|
|
2263
|
+
destNpmDir: resolve$9(outputDir, 'node_modules')
|
|
2119
2264
|
}]; // 1.2模块的package.json
|
|
2120
2265
|
|
|
2121
2266
|
subPackages.forEach(item => {
|
|
2122
2267
|
const srcPackageDir = `${getAbsolutePath$2(item.path)}/package.json`;
|
|
2123
2268
|
|
|
2124
|
-
if (fs$
|
|
2269
|
+
if (fs$6.existsSync(srcPackageDir)) {
|
|
2125
2270
|
packageArr.push({
|
|
2126
2271
|
srcPackageDir,
|
|
2127
|
-
destNpmDir: resolve$
|
|
2272
|
+
destNpmDir: resolve$9(outputDir, item.root, 'node_modules')
|
|
2128
2273
|
});
|
|
2129
2274
|
}
|
|
2130
2275
|
});
|
|
@@ -2133,7 +2278,7 @@ function collectPackageJson(subPackages, cwd, outputDir) {
|
|
|
2133
2278
|
|
|
2134
2279
|
|
|
2135
2280
|
function readPackageDependencies(srcPackageDir) {
|
|
2136
|
-
const packageJson = fs$
|
|
2281
|
+
const packageJson = fs$6.readFileSync(srcPackageDir, 'utf-8');
|
|
2137
2282
|
let dependencies = {};
|
|
2138
2283
|
|
|
2139
2284
|
try {
|
|
@@ -2170,13 +2315,13 @@ const checkPackageVersion$1 = packageArr => {
|
|
|
2170
2315
|
for (const key of dependenciesKeys) {
|
|
2171
2316
|
const depPath = path$7.join(item.destNpmDir, key);
|
|
2172
2317
|
|
|
2173
|
-
if (!fs$
|
|
2318
|
+
if (!fs$6.existsSync(depPath)) {
|
|
2174
2319
|
return true;
|
|
2175
2320
|
}
|
|
2176
2321
|
|
|
2177
2322
|
const depPackagePath = path$7.join(depPath, 'package.json');
|
|
2178
2323
|
|
|
2179
|
-
if (fs$
|
|
2324
|
+
if (fs$6.existsSync(depPackagePath)) {
|
|
2180
2325
|
const packageData = require(depPackagePath);
|
|
2181
2326
|
|
|
2182
2327
|
if (dependencies[key] === 'latest') {
|
|
@@ -2202,13 +2347,13 @@ var checkDependencies = {
|
|
|
2202
2347
|
checkPackageVersion: checkPackageVersion$1
|
|
2203
2348
|
};
|
|
2204
2349
|
|
|
2205
|
-
const shelljs$
|
|
2206
|
-
const fs$
|
|
2207
|
-
const path$6 = require$$1__default$
|
|
2350
|
+
const shelljs$4 = require$$2__default;
|
|
2351
|
+
const fs$5 = require$$0__default$1;
|
|
2352
|
+
const path$6 = require$$1__default$1;
|
|
2208
2353
|
const io$1 = io$3;
|
|
2209
2354
|
const {
|
|
2210
2355
|
createTask: createTask$1,
|
|
2211
|
-
resolve: resolve$
|
|
2356
|
+
resolve: resolve$8,
|
|
2212
2357
|
getAbsolutePath: getAbsolutePath$1
|
|
2213
2358
|
} = widgets;
|
|
2214
2359
|
const {
|
|
@@ -2219,13 +2364,13 @@ const {
|
|
|
2219
2364
|
getCache
|
|
2220
2365
|
} = cache;
|
|
2221
2366
|
const {
|
|
2222
|
-
|
|
2223
|
-
} =
|
|
2367
|
+
NODE_MODULES_DIR: NODE_MODULES_DIR$1
|
|
2368
|
+
} = constant;
|
|
2224
2369
|
const {
|
|
2225
2370
|
npmInstallAll
|
|
2226
2371
|
} = npm;
|
|
2227
2372
|
const {
|
|
2228
|
-
info: info$
|
|
2373
|
+
info: info$6
|
|
2229
2374
|
} = log$1;
|
|
2230
2375
|
const {
|
|
2231
2376
|
fileMd5
|
|
@@ -2234,7 +2379,7 @@ const {
|
|
|
2234
2379
|
isDependenciesUpdate
|
|
2235
2380
|
} = checkDependencies;
|
|
2236
2381
|
|
|
2237
|
-
async function install$2(tmsConfig, subPackages, useCache
|
|
2382
|
+
async function install$2(tmsConfig, subPackages, useCache) {
|
|
2238
2383
|
const cwd = process.cwd();
|
|
2239
2384
|
const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
|
|
2240
2385
|
|
|
@@ -2246,13 +2391,13 @@ async function install$2(tmsConfig, subPackages, useCache = true) {
|
|
|
2246
2391
|
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
|
|
2247
2392
|
}
|
|
2248
2393
|
|
|
2249
|
-
shelljs$
|
|
2394
|
+
shelljs$4.cd(cwd);
|
|
2250
2395
|
}
|
|
2251
2396
|
|
|
2252
2397
|
async function npmInstall(tmsConfig, subPackages, useCache) {
|
|
2253
2398
|
// 如果依赖没有更新和使用缓存数据(则命中缓存)
|
|
2254
|
-
if (!isDependenciesUpdate(subPackages, resolve$
|
|
2255
|
-
info$
|
|
2399
|
+
if (!isDependenciesUpdate(subPackages, resolve$8('./'), tmsConfig.outputDir) && useCache) {
|
|
2400
|
+
info$6('node_modules命中缓存');
|
|
2256
2401
|
return {
|
|
2257
2402
|
isCache: true
|
|
2258
2403
|
};
|
|
@@ -2260,12 +2405,12 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
|
|
|
2260
2405
|
|
|
2261
2406
|
|
|
2262
2407
|
subPackages.forEach(item => {
|
|
2263
|
-
const outputModuleDir = resolve$
|
|
2408
|
+
const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
|
|
2264
2409
|
io$1.ensureDirExist(outputModuleDir);
|
|
2265
2410
|
const modulePackagePath = `${getAbsolutePath$1(item.path)}/package.json`;
|
|
2266
|
-
if (fs$
|
|
2411
|
+
if (fs$5.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
2267
2412
|
});
|
|
2268
|
-
await npmInstallAll(subPackages, resolve$
|
|
2413
|
+
await npmInstallAll(subPackages, resolve$8(tmsConfig.outputDir), NODE_MODULES_DIR$1);
|
|
2269
2414
|
return {
|
|
2270
2415
|
isCache: false
|
|
2271
2416
|
};
|
|
@@ -2274,16 +2419,16 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
|
|
|
2274
2419
|
|
|
2275
2420
|
async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
2276
2421
|
const packageJsonFiles = [];
|
|
2277
|
-
const rootPackFile = resolve$
|
|
2422
|
+
const rootPackFile = resolve$8(`${tmsConfig.outputDir}/package.json`);
|
|
2278
2423
|
|
|
2279
|
-
if (fs$
|
|
2424
|
+
if (fs$5.existsSync(rootPackFile)) {
|
|
2280
2425
|
packageJsonFiles.push(rootPackFile);
|
|
2281
2426
|
}
|
|
2282
2427
|
|
|
2283
2428
|
subPackages.forEach(item => {
|
|
2284
|
-
const packageJsonFile = resolve$
|
|
2429
|
+
const packageJsonFile = resolve$8(`${tmsConfig.outputDir}/${item.root}/package.json`);
|
|
2285
2430
|
|
|
2286
|
-
if (fs$
|
|
2431
|
+
if (fs$5.existsSync(packageJsonFile)) {
|
|
2287
2432
|
packageJsonFiles.push(packageJsonFile);
|
|
2288
2433
|
}
|
|
2289
2434
|
});
|
|
@@ -2297,7 +2442,7 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2297
2442
|
let flag = true;
|
|
2298
2443
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2299
2444
|
const packageDir = path$6.dirname(item);
|
|
2300
|
-
const mpDir = resolve$
|
|
2445
|
+
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2301
2446
|
const md5Value = await getMNPMd5(packageDir);
|
|
2302
2447
|
const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
|
|
2303
2448
|
// 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
|
|
@@ -2310,14 +2455,14 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2310
2455
|
}
|
|
2311
2456
|
|
|
2312
2457
|
if (isCache) {
|
|
2313
|
-
info$
|
|
2458
|
+
info$6('miniprogram_npm命中缓存');
|
|
2314
2459
|
return;
|
|
2315
2460
|
} // 即将构建,在cache中标记开始
|
|
2316
2461
|
|
|
2317
2462
|
|
|
2318
2463
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2319
2464
|
const packageDir = path$6.dirname(item);
|
|
2320
|
-
const mpDir = resolve$
|
|
2465
|
+
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2321
2466
|
setCache(mpDir, 'miniprogram_npm', {
|
|
2322
2467
|
md5: '',
|
|
2323
2468
|
status: statusMap.doing
|
|
@@ -2325,13 +2470,13 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2325
2470
|
}));
|
|
2326
2471
|
await buildMpNpm({
|
|
2327
2472
|
appId: tmsConfig.appId,
|
|
2328
|
-
projectPath: resolve$
|
|
2473
|
+
projectPath: resolve$8('./'),
|
|
2329
2474
|
privateKey: tmsConfig.privateKey
|
|
2330
2475
|
}); // 构建成功后,计算md5写入cache
|
|
2331
2476
|
|
|
2332
2477
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2333
2478
|
const packageDir = path$6.dirname(item);
|
|
2334
|
-
const mpDir = resolve$
|
|
2479
|
+
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2335
2480
|
const md5Value = await getMNPMd5(packageDir);
|
|
2336
2481
|
setCache(mpDir, 'miniprogram_npm', {
|
|
2337
2482
|
md5: md5Value,
|
|
@@ -2346,16 +2491,16 @@ async function getMNPMd5(cwd) {
|
|
|
2346
2491
|
async: false,
|
|
2347
2492
|
silent: true
|
|
2348
2493
|
};
|
|
2349
|
-
shelljs$
|
|
2494
|
+
shelljs$4.cd(cwd);
|
|
2350
2495
|
|
|
2351
|
-
if (fs$
|
|
2352
|
-
shelljs$
|
|
2496
|
+
if (fs$5.existsSync('miniprogram_npm')) {
|
|
2497
|
+
shelljs$4.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
|
|
2353
2498
|
cwd,
|
|
2354
2499
|
...shellJsOption
|
|
2355
2500
|
});
|
|
2356
2501
|
const tarDir = path$6.join(cwd, './miniprogram_npm.tar.gz');
|
|
2357
2502
|
const md5Value = await fileMd5(tarDir);
|
|
2358
|
-
shelljs$
|
|
2503
|
+
shelljs$4.rm('-rf', tarDir);
|
|
2359
2504
|
return md5Value;
|
|
2360
2505
|
}
|
|
2361
2506
|
|
|
@@ -2364,20 +2509,20 @@ async function getMNPMd5(cwd) {
|
|
|
2364
2509
|
|
|
2365
2510
|
var install_1 = install$2;
|
|
2366
2511
|
|
|
2367
|
-
const shelljs$
|
|
2368
|
-
const fs$
|
|
2512
|
+
const shelljs$3 = require$$2__default;
|
|
2513
|
+
const fs$4 = require$$0__default$1;
|
|
2369
2514
|
const io = io$3;
|
|
2370
2515
|
const {
|
|
2371
|
-
resolve: resolve$
|
|
2516
|
+
resolve: resolve$7,
|
|
2372
2517
|
createTask
|
|
2373
2518
|
} = widgets;
|
|
2374
2519
|
const {
|
|
2375
2520
|
buildOutputAppJson: buildOutputAppJson$1
|
|
2376
2521
|
} = buildAppJson;
|
|
2377
2522
|
const {
|
|
2378
|
-
MODULE_CODE_DIR,
|
|
2523
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
2379
2524
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
|
|
2380
|
-
} =
|
|
2525
|
+
} = constant;
|
|
2381
2526
|
const {
|
|
2382
2527
|
cloneModules
|
|
2383
2528
|
} = cloneModules_1;
|
|
@@ -2386,8 +2531,8 @@ const {
|
|
|
2386
2531
|
getSubPackages: getSubPackages$2
|
|
2387
2532
|
} = tmsMpconfig.exports;
|
|
2388
2533
|
const {
|
|
2389
|
-
fail: fail$
|
|
2390
|
-
info: info$
|
|
2534
|
+
fail: fail$3,
|
|
2535
|
+
info: info$5
|
|
2391
2536
|
} = log$1;
|
|
2392
2537
|
const install$1 = install_1;
|
|
2393
2538
|
/**
|
|
@@ -2399,18 +2544,18 @@ const install$1 = install_1;
|
|
|
2399
2544
|
*/
|
|
2400
2545
|
|
|
2401
2546
|
const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
2402
|
-
const outputDir = resolve$
|
|
2547
|
+
const outputDir = resolve$7(tmsConfig.outputDir);
|
|
2403
2548
|
io.ensureDirExist(outputDir);
|
|
2404
2549
|
defaultFiles.forEach(item => {
|
|
2405
|
-
if (fs$
|
|
2406
|
-
shelljs$
|
|
2550
|
+
if (fs$4.existsSync(resolve$7(item))) {
|
|
2551
|
+
shelljs$3.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
|
|
2407
2552
|
}
|
|
2408
2553
|
});
|
|
2409
2554
|
};
|
|
2410
2555
|
|
|
2411
2556
|
async function task(tmsConfig, targetModules) {
|
|
2412
2557
|
// 下载和移动代码
|
|
2413
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$
|
|
2558
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$7('./'), targetModules); // 获取所有模块,合并模块依赖的模块
|
|
2414
2559
|
|
|
2415
2560
|
const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
|
|
2416
2561
|
|
|
@@ -2433,8 +2578,8 @@ async function init$3(tmsConfig, targetModules) {
|
|
|
2433
2578
|
return taskRes;
|
|
2434
2579
|
} catch (error) {
|
|
2435
2580
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
2436
|
-
fail$
|
|
2437
|
-
info$
|
|
2581
|
+
fail$3(`初始化流程出现错误: ${errMsg}`);
|
|
2582
|
+
info$5('详细的错误信息', error);
|
|
2438
2583
|
process.exit(1);
|
|
2439
2584
|
}
|
|
2440
2585
|
}
|
|
@@ -2442,722 +2587,111 @@ async function init$3(tmsConfig, targetModules) {
|
|
|
2442
2587
|
var init_1 = init$3;
|
|
2443
2588
|
|
|
2444
2589
|
/* 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
|
-
|
|
2458
|
-
code = strip.block(code); // 定义最后返回的结果
|
|
2459
|
-
|
|
2460
|
-
const result = [];
|
|
2461
|
-
let matchList; // 循环遍历代码段,直至匹配结果为空
|
|
2462
|
-
|
|
2463
|
-
while (matchList = MATCH_RULE.exec(code)) {
|
|
2464
|
-
var _matchList, _matchList2;
|
|
2465
|
-
|
|
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
|
-
} // 返回结果
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
return result;
|
|
2472
|
-
};
|
|
2473
|
-
|
|
2474
|
-
var findCssImport = {
|
|
2475
|
-
findCssImports: findCssImports$1
|
|
2476
|
-
};
|
|
2477
|
-
|
|
2478
|
-
/* eslint-disable no-param-reassign */
|
|
2479
|
-
const {
|
|
2480
|
-
fail: fail$3
|
|
2481
|
-
} = log$1;
|
|
2482
2590
|
|
|
2483
|
-
function
|
|
2484
|
-
|
|
2591
|
+
function mpProjectJson$1() {
|
|
2592
|
+
return function ({
|
|
2593
|
+
vinyl,
|
|
2594
|
+
next
|
|
2595
|
+
}) {
|
|
2596
|
+
if (vinyl.isBuffer()) {
|
|
2597
|
+
let contents = String(vinyl.contents);
|
|
2598
|
+
contents = contents.replace(/"miniprogramRoot"[^,]+,/g, '');
|
|
2599
|
+
vinyl.contents = Buffer.from(contents);
|
|
2600
|
+
}
|
|
2485
2601
|
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
} else {
|
|
2489
|
-
fail$3(errMsg);
|
|
2490
|
-
process.exit(1);
|
|
2491
|
-
}
|
|
2602
|
+
next();
|
|
2603
|
+
};
|
|
2492
2604
|
}
|
|
2493
2605
|
|
|
2494
|
-
var
|
|
2495
|
-
pluginError: pluginError$3
|
|
2496
|
-
};
|
|
2606
|
+
var mpProjectJson_1 = mpProjectJson$1;
|
|
2497
2607
|
|
|
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
2608
|
const {
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2609
|
+
src: src$1,
|
|
2610
|
+
dest
|
|
2611
|
+
} = require$$0__default$7;
|
|
2612
|
+
const path$5 = require$$1__default$1;
|
|
2613
|
+
const minimatch = require$$2__default$1;
|
|
2614
|
+
const gulpif = require$$3__default$1;
|
|
2615
|
+
const mpProjectJson = mpProjectJson_1;
|
|
2510
2616
|
const {
|
|
2511
|
-
resolve: resolve$
|
|
2617
|
+
resolve: resolve$6
|
|
2512
2618
|
} = widgets;
|
|
2513
|
-
const
|
|
2619
|
+
const through = require$$6__default;
|
|
2514
2620
|
const {
|
|
2515
|
-
|
|
2516
|
-
} =
|
|
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
|
-
}
|
|
2621
|
+
fail: fail$2
|
|
2622
|
+
} = log$1;
|
|
2547
2623
|
|
|
2548
|
-
|
|
2549
|
-
|
|
2624
|
+
const getTargetFile$1 = (sourceFile, module, outputDir) => {
|
|
2625
|
+
const sourceFileRelativeModule = path$5.relative(resolve$6(module.from), sourceFile);
|
|
2626
|
+
const targetFile = resolve$6(outputDir, module.to, sourceFileRelativeModule);
|
|
2627
|
+
return targetFile;
|
|
2628
|
+
};
|
|
2550
2629
|
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2630
|
+
const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
|
|
2631
|
+
const {
|
|
2632
|
+
plugins = []
|
|
2633
|
+
} = tmsConfig;
|
|
2634
|
+
const newPlugins = [{
|
|
2635
|
+
glob: '**/project.config.json',
|
|
2636
|
+
action: mpProjectJson()
|
|
2637
|
+
}, ...plugins];
|
|
2638
|
+
return newPlugins.reduce((srcPipe, pluginItem) => srcPipe.pipe(gulpif(vinyl => minimatch(vinyl.path, pluginItem.glob), through.obj(function (vinyl, enc, next) {
|
|
2639
|
+
const sourceFile = vinyl.history[0];
|
|
2640
|
+
pluginItem.action({
|
|
2641
|
+
tmsConfig,
|
|
2642
|
+
sourceFile,
|
|
2643
|
+
vinyl,
|
|
2644
|
+
targetFile: getTargetFile$1(sourceFile, pluginParams.module, tmsConfig.outputDir),
|
|
2645
|
+
isDev: pluginParams.isDev,
|
|
2646
|
+
next
|
|
2561
2647
|
});
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
dfs(anaFileOriginFile, anaFileDestFile, extensions);
|
|
2565
|
-
return resDep;
|
|
2648
|
+
this.push(vinyl);
|
|
2649
|
+
}))), srcPipe);
|
|
2566
2650
|
};
|
|
2567
2651
|
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
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);
|
|
2652
|
+
var compile$1 = function (tmsConfig, {
|
|
2653
|
+
glob,
|
|
2654
|
+
destPath,
|
|
2655
|
+
srcOption,
|
|
2656
|
+
module,
|
|
2657
|
+
isDev
|
|
2658
|
+
}) {
|
|
2659
|
+
const compileTasksMap = new Map();
|
|
2660
|
+
compileTasksMap.set(glob, {
|
|
2661
|
+
module,
|
|
2662
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2663
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : glob;
|
|
2664
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2665
|
+
let srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2666
|
+
});
|
|
2667
|
+
const pluginParams = {
|
|
2668
|
+
module,
|
|
2669
|
+
isDev
|
|
2670
|
+
};
|
|
2671
|
+
srcPipe = addPlugins(tmsConfig, srcPipe, pluginParams);
|
|
2672
|
+
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
2673
|
+
fail$2(`编译报错${err}`);
|
|
2631
2674
|
});
|
|
2632
|
-
file.contents = Buffer.from(contents);
|
|
2633
2675
|
}
|
|
2634
|
-
|
|
2635
|
-
this.push(file);
|
|
2636
|
-
cb();
|
|
2637
2676
|
});
|
|
2638
|
-
return
|
|
2639
|
-
}
|
|
2640
|
-
|
|
2641
|
-
var mpCommonDep_1 = {
|
|
2642
|
-
mpCommonDep: mpCommonDep$1,
|
|
2643
|
-
dfsFindCommonDep: dfsFindCommonDep$2
|
|
2677
|
+
return compileTasksMap;
|
|
2644
2678
|
};
|
|
2645
2679
|
|
|
2646
|
-
/* eslint-disable
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
const
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
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
|
-
|
|
2886
|
-
});
|
|
2887
|
-
parser.write(contents);
|
|
2888
|
-
parser.end();
|
|
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
|
|
2992
|
-
};
|
|
2993
|
-
|
|
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
|
-
var compile$1 = function (tmsConfig, {
|
|
3018
|
-
glob,
|
|
3019
|
-
destPath,
|
|
3020
|
-
srcOption,
|
|
3021
|
-
module,
|
|
3022
|
-
isDev
|
|
3023
|
-
}) {
|
|
3024
|
-
const compileTasksMap = new Map();
|
|
3025
|
-
Object.keys(glob).forEach(globKey => {
|
|
3026
|
-
const globValue = glob[globKey];
|
|
3027
|
-
|
|
3028
|
-
switch (globKey) {
|
|
3029
|
-
case 'js':
|
|
3030
|
-
compileTasksMap.set(globValue, {
|
|
3031
|
-
module,
|
|
3032
|
-
taskFn: (sourceFile, targetPath) => {
|
|
3033
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
3034
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
3035
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
3036
|
-
});
|
|
3037
|
-
return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
3038
|
-
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
|
|
3039
|
-
fail$2(`mpCommonDep编译报错${err}`);
|
|
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;
|
|
3141
|
-
}
|
|
3142
|
-
});
|
|
3143
|
-
return compileTasksMap;
|
|
3144
|
-
};
|
|
3145
|
-
|
|
3146
|
-
/* eslint-disable */
|
|
3147
|
-
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
3148
|
-
|
|
3149
|
-
const assign = require$$0__default$b;
|
|
3150
|
-
const path$2 = require$$1__default$2;
|
|
3151
|
-
const PluginError = require$$2__default$1;
|
|
3152
|
-
const fancyLog = require$$3__default;
|
|
3153
|
-
const colors = require$$4__default;
|
|
3154
|
-
const chokidar = require$$5__default;
|
|
2680
|
+
/* eslint-disable */
|
|
2681
|
+
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
2682
|
+
|
|
2683
|
+
const assign = require$$0__default$8;
|
|
2684
|
+
const path$4 = require$$1__default$1;
|
|
2685
|
+
const PluginError = require$$2__default$2;
|
|
2686
|
+
const fancyLog = require$$3__default$2;
|
|
2687
|
+
const colors = require$$4__default$1;
|
|
2688
|
+
const chokidar = require$$5__default;
|
|
3155
2689
|
const {
|
|
3156
2690
|
Duplex
|
|
3157
2691
|
} = require$$6__default$1;
|
|
3158
2692
|
const vinyl = require$$7__default;
|
|
3159
2693
|
const File = require$$8__default;
|
|
3160
|
-
const anymatch = require$$9__default
|
|
2694
|
+
const anymatch = require$$9__default;
|
|
3161
2695
|
const pathIsAbsolute = require$$10__default$1;
|
|
3162
2696
|
const globParent = require$$11__default;
|
|
3163
2697
|
const slash = require$$12__default;
|
|
@@ -3192,10 +2726,10 @@ function watch$2(globs, opts, cb) {
|
|
|
3192
2726
|
|
|
3193
2727
|
function resolveFilepath(filepath) {
|
|
3194
2728
|
if (pathIsAbsolute(filepath)) {
|
|
3195
|
-
return path$
|
|
2729
|
+
return path$4.normalize(filepath);
|
|
3196
2730
|
}
|
|
3197
2731
|
|
|
3198
|
-
return path$
|
|
2732
|
+
return path$4.resolve(opts.cwd || process.cwd(), filepath);
|
|
3199
2733
|
}
|
|
3200
2734
|
|
|
3201
2735
|
function resolveGlob(glob) {
|
|
@@ -3251,7 +2785,7 @@ function watch$2(globs, opts, cb) {
|
|
|
3251
2785
|
let glob;
|
|
3252
2786
|
let currentFilepath = filepath;
|
|
3253
2787
|
|
|
3254
|
-
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$
|
|
2788
|
+
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$4.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
3255
2789
|
|
|
3256
2790
|
|
|
3257
2791
|
if (!glob) {
|
|
@@ -3260,7 +2794,7 @@ function watch$2(globs, opts, cb) {
|
|
|
3260
2794
|
}
|
|
3261
2795
|
|
|
3262
2796
|
if (!baseForced) {
|
|
3263
|
-
fileOpts.base = path$
|
|
2797
|
+
fileOpts.base = path$4.normalize(globParent(glob));
|
|
3264
2798
|
} // Do not stat deleted files
|
|
3265
2799
|
|
|
3266
2800
|
|
|
@@ -3320,15 +2854,19 @@ var gulpWatch = watch$2;
|
|
|
3320
2854
|
|
|
3321
2855
|
/* eslint-disable no-restricted-syntax */
|
|
3322
2856
|
const watch$1 = gulpWatch;
|
|
3323
|
-
const path$
|
|
3324
|
-
const shellJs = require$$
|
|
2857
|
+
const path$3 = require$$1__default$1;
|
|
2858
|
+
const shellJs = require$$2__default;
|
|
2859
|
+
const {
|
|
2860
|
+
series: series$1
|
|
2861
|
+
} = require$$0__default$7;
|
|
3325
2862
|
const {
|
|
3326
|
-
info: info$
|
|
2863
|
+
info: info$4,
|
|
3327
2864
|
warn: warn$1,
|
|
3328
2865
|
fail: fail$1
|
|
3329
2866
|
} = log$1;
|
|
3330
2867
|
const {
|
|
3331
|
-
resolve: resolve$5
|
|
2868
|
+
resolve: resolve$5,
|
|
2869
|
+
filterField: filterField$3
|
|
3332
2870
|
} = widgets;
|
|
3333
2871
|
const {
|
|
3334
2872
|
global: global$2
|
|
@@ -3336,9 +2874,7 @@ const {
|
|
|
3336
2874
|
const {
|
|
3337
2875
|
checkPackageVersion
|
|
3338
2876
|
} = checkDependencies;
|
|
3339
|
-
const
|
|
3340
|
-
findAllFilesOfDir
|
|
3341
|
-
} = io$3;
|
|
2877
|
+
const report$5 = report_1;
|
|
3342
2878
|
const TIP_MAP = {
|
|
3343
2879
|
'package.json': {
|
|
3344
2880
|
tip: '依赖版本有变动,请重新执行tmskit run dev',
|
|
@@ -3367,14 +2903,14 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
|
|
|
3367
2903
|
}
|
|
3368
2904
|
}
|
|
3369
2905
|
|
|
3370
|
-
info$
|
|
2906
|
+
info$4(`${fileName}有更新`);
|
|
3371
2907
|
} catch (e) {
|
|
3372
2908
|
fail$1(`${sourceFile}文件更新提示出现错误: ${e.message}`);
|
|
3373
2909
|
}
|
|
3374
2910
|
};
|
|
3375
2911
|
|
|
3376
2912
|
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
3377
|
-
const sourceFileRelativeModule = path$
|
|
2913
|
+
const sourceFileRelativeModule = path$3.relative(resolve$5(module.from), sourceFile);
|
|
3378
2914
|
const targetFile = resolve$5(outputDir, module.to, sourceFileRelativeModule);
|
|
3379
2915
|
return targetFile;
|
|
3380
2916
|
};
|
|
@@ -3387,43 +2923,71 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3387
2923
|
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
3388
2924
|
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
3389
2925
|
const tmsConfig = global$2.getData('tmsConfig');
|
|
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
|
-
|
|
3406
2926
|
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
3407
2927
|
|
|
3408
2928
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
3409
|
-
info$
|
|
2929
|
+
info$4(`删除${sourceFileName}`);
|
|
3410
2930
|
shellJs.rm('-rf', targetFile);
|
|
2931
|
+
updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
|
|
3411
2932
|
return;
|
|
3412
2933
|
}
|
|
3413
2934
|
|
|
2935
|
+
runCallback({
|
|
2936
|
+
tmsConfig,
|
|
2937
|
+
sourceFile,
|
|
2938
|
+
targetFile,
|
|
2939
|
+
callback,
|
|
2940
|
+
type: vinyl.event
|
|
2941
|
+
});
|
|
3414
2942
|
logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
|
|
3415
|
-
return callback([sourceFile], path$1.dirname(targetFile));
|
|
3416
2943
|
});
|
|
3417
|
-
};
|
|
2944
|
+
}; // 开始执行watch 文件的 callback函数
|
|
2945
|
+
|
|
2946
|
+
|
|
2947
|
+
async function runCallback({
|
|
2948
|
+
tmsConfig,
|
|
2949
|
+
sourceFile,
|
|
2950
|
+
targetFile,
|
|
2951
|
+
callback,
|
|
2952
|
+
type
|
|
2953
|
+
}) {
|
|
2954
|
+
// callbacl.name === taskFn 代表进入gulp编译流程
|
|
2955
|
+
// series为gulp编译串行执行,callback执行完毕后,执行updateFileHooks钩子
|
|
2956
|
+
if (callback.name === 'taskFn') {
|
|
2957
|
+
series$1(callback.bind(null, [sourceFile], path$3.dirname(targetFile)), cb => {
|
|
2958
|
+
cb();
|
|
2959
|
+
updateFileHook(tmsConfig, sourceFile, targetFile, type);
|
|
2960
|
+
})();
|
|
2961
|
+
} else {
|
|
2962
|
+
// 普通的callback函数
|
|
2963
|
+
await callback([sourceFile], path$3.dirname(targetFile));
|
|
2964
|
+
await updateFileHook(tmsConfig, sourceFile, targetFile, type);
|
|
2965
|
+
}
|
|
2966
|
+
} // 执行源码文件更新的钩子
|
|
2967
|
+
|
|
3418
2968
|
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
2969
|
+
async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
|
|
2970
|
+
var _tmsConfig$hooks;
|
|
2971
|
+
|
|
2972
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateFile) === 'function') {
|
|
2973
|
+
await tmsConfig.hooks.updateFile({
|
|
2974
|
+
tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
|
|
2975
|
+
sourceFile,
|
|
2976
|
+
targetFile,
|
|
2977
|
+
type
|
|
2978
|
+
});
|
|
2979
|
+
report$5('hooks:updateFile');
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
const path$2 = require$$1__default$1;
|
|
2984
|
+
const fs$3 = require$$0__default$1;
|
|
2985
|
+
const ora = require$$0__default;
|
|
2986
|
+
const chalk$3 = require$$3__default;
|
|
3423
2987
|
const {
|
|
3424
2988
|
parallel,
|
|
3425
2989
|
series
|
|
3426
|
-
} = require$$0__default$
|
|
2990
|
+
} = require$$0__default$7;
|
|
3427
2991
|
const {
|
|
3428
2992
|
resolve: resolve$4,
|
|
3429
2993
|
mergeMap,
|
|
@@ -3435,42 +2999,20 @@ const {
|
|
|
3435
2999
|
} = buildAppJson;
|
|
3436
3000
|
const {
|
|
3437
3001
|
DEFAULT_COPY_CONFIG
|
|
3438
|
-
} =
|
|
3002
|
+
} = constant;
|
|
3439
3003
|
const compile = compile$1;
|
|
3440
3004
|
const watch = watch_1;
|
|
3441
3005
|
const {
|
|
3442
|
-
info: info$
|
|
3006
|
+
info: info$3
|
|
3443
3007
|
} = log$1;
|
|
3008
|
+
const report$4 = report_1;
|
|
3444
3009
|
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
3445
3010
|
|
|
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
3011
|
var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
3468
3012
|
const compileTasksMap = new Map(); // 监听根目录的文件
|
|
3469
3013
|
|
|
3470
3014
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3471
|
-
glob:
|
|
3472
|
-
json: DEFAULT_COPY_CONFIG.map(item => resolve$4(item))
|
|
3473
|
-
},
|
|
3015
|
+
glob: DEFAULT_COPY_CONFIG.map(item => resolve$4(item)),
|
|
3474
3016
|
module: {
|
|
3475
3017
|
from: resolve$4(),
|
|
3476
3018
|
to: resolve$4(tmsConfig.outputDir)
|
|
@@ -3504,7 +3046,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3504
3046
|
|
|
3505
3047
|
const excludes = moduleItem.exclude.map(ePath => {
|
|
3506
3048
|
const newPath = getAbsolutePath(ePath, srcModulePath);
|
|
3507
|
-
const ext = path.extname(ePath).slice(1);
|
|
3049
|
+
const ext = path$2.extname(ePath).slice(1);
|
|
3508
3050
|
|
|
3509
3051
|
if (ext) {
|
|
3510
3052
|
return `!${resolve$4(srcModulePath, newPath)}`;
|
|
@@ -3512,17 +3054,8 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3512
3054
|
|
|
3513
3055
|
return `!${resolve$4(srcModulePath, newPath)}/**/*`;
|
|
3514
3056
|
});
|
|
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
3057
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3523
|
-
glob: { ...
|
|
3524
|
-
other: [`${srcModulePath}/**/*`, ...excludeGlob(glob)]
|
|
3525
|
-
},
|
|
3058
|
+
glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
|
|
3526
3059
|
destPath: buildModulePath,
|
|
3527
3060
|
module: {
|
|
3528
3061
|
from: srcModulePath,
|
|
@@ -3533,7 +3066,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3533
3066
|
},
|
|
3534
3067
|
isDev
|
|
3535
3068
|
}));
|
|
3536
|
-
} //
|
|
3069
|
+
} // static静态资源目录
|
|
3537
3070
|
|
|
3538
3071
|
|
|
3539
3072
|
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
@@ -3541,22 +3074,15 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3541
3074
|
item.from = getAbsolutePath(item.from);
|
|
3542
3075
|
item.to = getAbsolutePath(item.to);
|
|
3543
3076
|
let glob = {};
|
|
3544
|
-
const ext = path.extname(item.from).slice(1);
|
|
3077
|
+
const ext = path$2.extname(item.from).slice(1);
|
|
3545
3078
|
|
|
3546
3079
|
if (ext) {
|
|
3547
|
-
glob
|
|
3080
|
+
glob = [item.from];
|
|
3548
3081
|
} 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)];
|
|
3082
|
+
glob = [`${item.from}/**/*`];
|
|
3557
3083
|
}
|
|
3558
3084
|
|
|
3559
|
-
const from = fs$
|
|
3085
|
+
const from = fs$3.lstatSync(item.from).isFile() ? path$2.dirname(item.from) : item.from;
|
|
3560
3086
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3561
3087
|
glob,
|
|
3562
3088
|
destPath: item.to,
|
|
@@ -3577,7 +3103,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3577
3103
|
const spinner = ora();
|
|
3578
3104
|
|
|
3579
3105
|
function start(cb) {
|
|
3580
|
-
info$
|
|
3106
|
+
info$3('启动编译...');
|
|
3581
3107
|
spinner.start();
|
|
3582
3108
|
sTime = new Date().getTime();
|
|
3583
3109
|
cb();
|
|
@@ -3611,17 +3137,18 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3611
3137
|
|
|
3612
3138
|
eTime = new Date().getTime() - sTime;
|
|
3613
3139
|
|
|
3614
|
-
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.
|
|
3140
|
+
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
3141
|
var _tmsConfig$hooks2;
|
|
3616
3142
|
|
|
3617
|
-
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.
|
|
3143
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterFirstCompile({
|
|
3618
3144
|
isDev,
|
|
3619
3145
|
tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
|
|
3620
3146
|
modules
|
|
3621
3147
|
}));
|
|
3148
|
+
report$4('hooks:afterCompile');
|
|
3622
3149
|
}
|
|
3623
3150
|
|
|
3624
|
-
spinner.succeed(chalk$
|
|
3151
|
+
spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
3625
3152
|
spinner.stop();
|
|
3626
3153
|
cb();
|
|
3627
3154
|
}
|
|
@@ -3636,7 +3163,232 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3636
3163
|
series(start, parallel(...compileTasks), end)();
|
|
3637
3164
|
};
|
|
3638
3165
|
|
|
3639
|
-
|
|
3166
|
+
var require$$12 = {
|
|
3167
|
+
name: "@tmsfe/tmskit",
|
|
3168
|
+
version: "0.0.24",
|
|
3169
|
+
description: "tmskit",
|
|
3170
|
+
main: "dist/index.cjs",
|
|
3171
|
+
bin: {
|
|
3172
|
+
tmskit: "main.js"
|
|
3173
|
+
},
|
|
3174
|
+
files: [
|
|
3175
|
+
"build",
|
|
3176
|
+
"src",
|
|
3177
|
+
"dist",
|
|
3178
|
+
"main.js",
|
|
3179
|
+
"package.json"
|
|
3180
|
+
],
|
|
3181
|
+
scripts: {
|
|
3182
|
+
dev: "rollup -wc --environment TARGET:tmskit",
|
|
3183
|
+
build: "rollup -c --environment TARGET:tmskit",
|
|
3184
|
+
"pub:patch": "sh build/publish.sh patch",
|
|
3185
|
+
"pub:minor": "sh build/publish.sh minor",
|
|
3186
|
+
"pub:major": "sh build/publish.sh major"
|
|
3187
|
+
},
|
|
3188
|
+
author: "tms·web",
|
|
3189
|
+
license: "ISC",
|
|
3190
|
+
buildOptions: {
|
|
3191
|
+
formats: [
|
|
3192
|
+
"cjs"
|
|
3193
|
+
]
|
|
3194
|
+
},
|
|
3195
|
+
devDependencies: {
|
|
3196
|
+
"@rollup/plugin-babel": "^5.0.2",
|
|
3197
|
+
"@rollup/plugin-commonjs": "^19.0.0",
|
|
3198
|
+
"@rollup/plugin-json": "^4.0.3",
|
|
3199
|
+
rollup: "^2.6.1"
|
|
3200
|
+
},
|
|
3201
|
+
dependencies: {
|
|
3202
|
+
"ansi-colors": "1.1.0",
|
|
3203
|
+
anymatch: "^1.3.0",
|
|
3204
|
+
async: "^3.2.2",
|
|
3205
|
+
chalk: "^4.1.0",
|
|
3206
|
+
chokidar: "^3.5.3",
|
|
3207
|
+
commander: "^8.3.0",
|
|
3208
|
+
"copy-webpack-plugin": "^9.1.0",
|
|
3209
|
+
ejs: "^3.1.5",
|
|
3210
|
+
"fancy-log": "1.3.2",
|
|
3211
|
+
"fs-extra": "^10.0.1",
|
|
3212
|
+
"glob-ignore": "^1.0.2",
|
|
3213
|
+
"glob-parent": "^3.0.1",
|
|
3214
|
+
gulp: "^4.0.2",
|
|
3215
|
+
"gulp-if": "^3.0.0",
|
|
3216
|
+
"gulp-watch": "^5.0.1",
|
|
3217
|
+
htmlparser2: "^7.2.0",
|
|
3218
|
+
inquirer: "^7.3.3",
|
|
3219
|
+
leven: "3.1.0",
|
|
3220
|
+
lodash: "^4.17.21",
|
|
3221
|
+
metalsmith: "^2.3.0",
|
|
3222
|
+
minimatch: "^5.1.0",
|
|
3223
|
+
"miniprogram-ci": "1.4.13",
|
|
3224
|
+
moment: "^2.29.2",
|
|
3225
|
+
"object-assign": "^4.0.1",
|
|
3226
|
+
ora: "^5.1.0",
|
|
3227
|
+
"path-is-absolute": "^1.0.1",
|
|
3228
|
+
"plugin-error": "^1.0.0",
|
|
3229
|
+
postcss: "^8.4.6",
|
|
3230
|
+
precinct: "^8.3.1",
|
|
3231
|
+
"readable-stream": "^2.2.2",
|
|
3232
|
+
"replace-ext": "^2.0.0",
|
|
3233
|
+
request: "^2.88.2",
|
|
3234
|
+
shelljs: "^0.8.4",
|
|
3235
|
+
slash: "^1.0.0",
|
|
3236
|
+
"strip-comments": "^2.0.1",
|
|
3237
|
+
through2: "^4.0.2",
|
|
3238
|
+
unzipper: "^0.10.11",
|
|
3239
|
+
vinyl: "^2.1.0",
|
|
3240
|
+
"vinyl-file": "^2.0.0",
|
|
3241
|
+
"vinyl-sourcemaps-apply": "^0.2.0"
|
|
3242
|
+
},
|
|
3243
|
+
engines: {
|
|
3244
|
+
node: "^12.17.0 || >= 14.13.1"
|
|
3245
|
+
},
|
|
3246
|
+
jest: {
|
|
3247
|
+
testEnvironment: "jest-environment-node"
|
|
3248
|
+
}
|
|
3249
|
+
};
|
|
3250
|
+
|
|
3251
|
+
const fs$2 = require$$0__default$1;
|
|
3252
|
+
const path$1 = require$$1__default$1;
|
|
3253
|
+
const shelljs$2 = require$$2__default;
|
|
3254
|
+
const chalk$2 = require$$3__default;
|
|
3255
|
+
const request = require$$0__default$5;
|
|
3256
|
+
const inquirer = require$$1__default$4;
|
|
3257
|
+
const {
|
|
3258
|
+
infoNoTime: infoNoTime$1
|
|
3259
|
+
} = log$1;
|
|
3260
|
+
const packageJson$1 = require$$12;
|
|
3261
|
+
const {
|
|
3262
|
+
VERSION_CACHE_FILE,
|
|
3263
|
+
VERSION_URL
|
|
3264
|
+
} = constant;
|
|
3265
|
+
const {
|
|
3266
|
+
ensureDirExist: ensureDirExist$1
|
|
3267
|
+
} = io$3;
|
|
3268
|
+
const {
|
|
3269
|
+
versionCompare
|
|
3270
|
+
} = widgets; // 获取推荐的tmskit版本
|
|
3271
|
+
|
|
3272
|
+
function getRecommendVersion() {
|
|
3273
|
+
return new Promise((resolve, reject) => {
|
|
3274
|
+
request(`${VERSION_URL}?v=${new Date().getTime()}`, (error, response, body) => {
|
|
3275
|
+
if (!error && response && response.statusCode === 200) {
|
|
3276
|
+
resolve(JSON.parse(body));
|
|
3277
|
+
} else {
|
|
3278
|
+
reject(response.statusCode);
|
|
3279
|
+
}
|
|
3280
|
+
});
|
|
3281
|
+
});
|
|
3282
|
+
} // 获取当前用户tmskit的版本
|
|
3283
|
+
|
|
3284
|
+
|
|
3285
|
+
function getUserTmskitVersion() {
|
|
3286
|
+
const data = shelljs$2.exec('tmskit -v', {
|
|
3287
|
+
async: false,
|
|
3288
|
+
silent: true
|
|
3289
|
+
});
|
|
3290
|
+
|
|
3291
|
+
if (data.code === 0) {
|
|
3292
|
+
// tmskit 0.0.21 => 0.0.21
|
|
3293
|
+
return data.slice(7);
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
return '0.0.0';
|
|
3297
|
+
} // 询问用户是否安装最新版本
|
|
3298
|
+
|
|
3299
|
+
|
|
3300
|
+
function isInstallLatestVersion() {
|
|
3301
|
+
return inquirer.prompt([{
|
|
3302
|
+
type: 'confirm',
|
|
3303
|
+
name: 'isInstall',
|
|
3304
|
+
message: '是否安装最新版本',
|
|
3305
|
+
choices: [{
|
|
3306
|
+
name: '否',
|
|
3307
|
+
value: false
|
|
3308
|
+
}, {
|
|
3309
|
+
name: '是',
|
|
3310
|
+
value: true
|
|
3311
|
+
}]
|
|
3312
|
+
}]);
|
|
3313
|
+
} // 获取tmskit的版本是否推荐过
|
|
3314
|
+
|
|
3315
|
+
|
|
3316
|
+
function getVersionIsRecommend(version) {
|
|
3317
|
+
const filePath = VERSION_CACHE_FILE;
|
|
3318
|
+
|
|
3319
|
+
if (!fs$2.existsSync(filePath)) {
|
|
3320
|
+
return false;
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
const content = require(filePath);
|
|
3324
|
+
|
|
3325
|
+
return content === null || content === void 0 ? void 0 : content[version];
|
|
3326
|
+
} // 设置tmskit版本推荐过
|
|
3327
|
+
|
|
3328
|
+
|
|
3329
|
+
function setVersionRecommend(version, isRecommend) {
|
|
3330
|
+
const filePath = VERSION_CACHE_FILE;
|
|
3331
|
+
|
|
3332
|
+
if (!fs$2.existsSync(filePath)) {
|
|
3333
|
+
const dir = path$1.dirname(filePath);
|
|
3334
|
+
ensureDirExist$1(dir);
|
|
3335
|
+
fs$2.writeFileSync(filePath, '{}');
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
const content = require(filePath);
|
|
3339
|
+
|
|
3340
|
+
content[version] = isRecommend;
|
|
3341
|
+
fs$2.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
3342
|
+
} // 推荐理由
|
|
3343
|
+
|
|
3344
|
+
|
|
3345
|
+
function displayRecommends(arr) {
|
|
3346
|
+
infoNoTime$1(chalk$2.green('构建工具有新的版本~~:'));
|
|
3347
|
+
arr.forEach(item => {
|
|
3348
|
+
infoNoTime$1(chalk$2.green(item));
|
|
3349
|
+
});
|
|
3350
|
+
} // 推荐tmskit的安装版本
|
|
3351
|
+
|
|
3352
|
+
|
|
3353
|
+
async function recommendVersion$1() {
|
|
3354
|
+
try {
|
|
3355
|
+
// 获取当前用户安装的版本
|
|
3356
|
+
const tmskitVersion = getUserTmskitVersion(); // 获取官方推荐版本
|
|
3357
|
+
|
|
3358
|
+
const recommendRes = await getRecommendVersion();
|
|
3359
|
+
const recommendVersion = recommendRes.version; // 当前用户安装版本小于官方推荐版本 && 该版本没有推荐过
|
|
3360
|
+
|
|
3361
|
+
if (versionCompare(tmskitVersion, recommendVersion) === -1 && !getVersionIsRecommend(recommendVersion)) {
|
|
3362
|
+
displayRecommends(recommendRes.version_detail); // 设置该版本推荐过
|
|
3363
|
+
|
|
3364
|
+
setVersionRecommend(recommendVersion, true); // 询问用户是否安装最新版本
|
|
3365
|
+
|
|
3366
|
+
const installRes = await isInstallLatestVersion(recommendRes);
|
|
3367
|
+
|
|
3368
|
+
if (installRes.isInstall) {
|
|
3369
|
+
// mac
|
|
3370
|
+
if (process.platform === 'darwin') {
|
|
3371
|
+
infoNoTime$1(`将执行以下命令: ${chalk$2.green(`sudo npm install -g ${packageJson$1.name}@${recommendVersion}`)}`);
|
|
3372
|
+
shelljs$2.exec(`sudo npm install -g ${packageJson$1.name}@${recommendVersion}`, {
|
|
3373
|
+
async: false,
|
|
3374
|
+
silent: false
|
|
3375
|
+
});
|
|
3376
|
+
process.exit(-1);
|
|
3377
|
+
} else {
|
|
3378
|
+
// window
|
|
3379
|
+
infoNoTime$1(`请使用超级管理员执行以下命令: ${chalk$2.green(`npm install -g ${packageJson$1.name}@${recommendVersion}`)}`);
|
|
3380
|
+
process.exit(-1);
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
} catch {}
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
var recommendVersion_1 = {
|
|
3388
|
+
recommendVersion: recommendVersion$1
|
|
3389
|
+
};
|
|
3390
|
+
|
|
3391
|
+
const shelljs$1 = require$$2__default;
|
|
3640
3392
|
const compileDev = dev$3;
|
|
3641
3393
|
const {
|
|
3642
3394
|
resolve: resolve$3,
|
|
@@ -3648,14 +3400,19 @@ const {
|
|
|
3648
3400
|
getSubPackages: getSubPackages$1
|
|
3649
3401
|
} = tmsMpconfig.exports;
|
|
3650
3402
|
const {
|
|
3651
|
-
info: info$
|
|
3403
|
+
info: info$2
|
|
3652
3404
|
} = log$1;
|
|
3653
3405
|
const {
|
|
3654
3406
|
global: global$1
|
|
3655
3407
|
} = global_1;
|
|
3656
3408
|
const {
|
|
3657
|
-
|
|
3658
|
-
|
|
3409
|
+
MODULE_CODE_DIR,
|
|
3410
|
+
NODE_MODULES_DIR
|
|
3411
|
+
} = constant;
|
|
3412
|
+
const report$3 = report_1;
|
|
3413
|
+
const {
|
|
3414
|
+
recommendVersion
|
|
3415
|
+
} = recommendVersion_1; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
3659
3416
|
|
|
3660
3417
|
function delOtherPackages(tmsConfig, targetSubPackages) {
|
|
3661
3418
|
// 获取所有模块,合并模块依赖的模块
|
|
@@ -3683,24 +3440,28 @@ async function dev$2(tmsConfig, targetModules) {
|
|
|
3683
3440
|
|
|
3684
3441
|
if (noCache) {
|
|
3685
3442
|
shelljs$1.rm('-rf', resolve$3(tmsConfig.outputDir));
|
|
3686
|
-
shelljs$1.rm('-rf',
|
|
3687
|
-
|
|
3443
|
+
shelljs$1.rm('-rf', MODULE_CODE_DIR);
|
|
3444
|
+
shelljs$1.rm('-rf', NODE_MODULES_DIR);
|
|
3445
|
+
} // 推荐tmskit的版本
|
|
3688
3446
|
|
|
3689
3447
|
|
|
3448
|
+
await recommendVersion(); // 初始化操作
|
|
3449
|
+
|
|
3690
3450
|
const {
|
|
3691
3451
|
subPackages,
|
|
3692
3452
|
modules: newModules
|
|
3693
3453
|
} = await init$2(tmsConfig, targetModules);
|
|
3694
|
-
info$
|
|
3454
|
+
info$2('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
|
|
3695
3455
|
|
|
3696
|
-
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.
|
|
3456
|
+
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
3457
|
var _tmsConfig$hooks2;
|
|
3698
3458
|
|
|
3699
|
-
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.
|
|
3459
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
|
|
3700
3460
|
isDev: true,
|
|
3701
3461
|
tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
|
|
3702
3462
|
modules: newModules
|
|
3703
3463
|
}));
|
|
3464
|
+
report$3('hooks:beforeCompile');
|
|
3704
3465
|
}
|
|
3705
3466
|
delOtherPackages(tmsConfig, subPackages);
|
|
3706
3467
|
compileDev(tmsConfig, newModules, true);
|
|
@@ -3714,13 +3475,14 @@ var build$2 = async (tmsConfig, newModules, isDev) => {
|
|
|
3714
3475
|
dev$1(tmsConfig, newModules, isDev);
|
|
3715
3476
|
};
|
|
3716
3477
|
|
|
3717
|
-
const shelljs = require$$
|
|
3478
|
+
const shelljs = require$$2__default;
|
|
3718
3479
|
const {
|
|
3719
3480
|
resolve: resolve$2,
|
|
3720
3481
|
filterField
|
|
3721
3482
|
} = widgets;
|
|
3722
3483
|
const init$1 = init_1;
|
|
3723
3484
|
const compileBuild = build$2;
|
|
3485
|
+
const report$2 = report_1;
|
|
3724
3486
|
|
|
3725
3487
|
async function build$1(tmsConfig, targetModules) {
|
|
3726
3488
|
var _tmsConfig$hooks;
|
|
@@ -3732,21 +3494,22 @@ async function build$1(tmsConfig, targetModules) {
|
|
|
3732
3494
|
} = await init$1(tmsConfig, targetModules);
|
|
3733
3495
|
const isDev = false;
|
|
3734
3496
|
|
|
3735
|
-
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.
|
|
3497
|
+
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
3498
|
var _tmsConfig$hooks2;
|
|
3737
3499
|
|
|
3738
|
-
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.
|
|
3500
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
|
|
3739
3501
|
isDev,
|
|
3740
3502
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3741
3503
|
modules: newModules
|
|
3742
3504
|
}));
|
|
3505
|
+
report$2('hooks:beforeCompile');
|
|
3743
3506
|
}
|
|
3744
3507
|
compileBuild(tmsConfig, newModules, isDev);
|
|
3745
3508
|
}
|
|
3746
3509
|
|
|
3747
3510
|
var build_1 = build$1;
|
|
3748
3511
|
|
|
3749
|
-
const fs$1 = require$$0__default$
|
|
3512
|
+
const fs$1 = require$$0__default$1;
|
|
3750
3513
|
const {
|
|
3751
3514
|
resolve: resolve$1
|
|
3752
3515
|
} = widgets;
|
|
@@ -3812,11 +3575,12 @@ const install = install_1;
|
|
|
3812
3575
|
const cloud = cloud$1;
|
|
3813
3576
|
const {
|
|
3814
3577
|
fail,
|
|
3815
|
-
info: info$
|
|
3578
|
+
info: info$1
|
|
3816
3579
|
} = log$1;
|
|
3817
3580
|
const {
|
|
3818
3581
|
global
|
|
3819
3582
|
} = global_1;
|
|
3583
|
+
const report$1 = report_1;
|
|
3820
3584
|
const {
|
|
3821
3585
|
getTmsConfig: getTmsConfig$1,
|
|
3822
3586
|
getModulesByMergeDepModules,
|
|
@@ -3868,10 +3632,11 @@ const getSpecificModuleNames = (moduleArg, modules) => {
|
|
|
3868
3632
|
};
|
|
3869
3633
|
|
|
3870
3634
|
async function run(commandName, cmd) {
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
const tmsConfig = getTmsConfig$1(); // 缓存数据
|
|
3635
|
+
// 用户本地的配置
|
|
3636
|
+
const tmsConfig = getTmsConfig$1();
|
|
3874
3637
|
|
|
3638
|
+
try {
|
|
3639
|
+
// 缓存数据
|
|
3875
3640
|
global.setData({
|
|
3876
3641
|
cmd,
|
|
3877
3642
|
tmsConfig
|
|
@@ -3879,14 +3644,21 @@ async function run(commandName, cmd) {
|
|
|
3879
3644
|
|
|
3880
3645
|
if (commandName === 'cloud') {
|
|
3881
3646
|
cloud(tmsConfig);
|
|
3647
|
+
report$1('run:cloud', {
|
|
3648
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3649
|
+
});
|
|
3882
3650
|
return;
|
|
3883
3651
|
}
|
|
3884
3652
|
|
|
3885
3653
|
otherCommands(tmsConfig, commandName, cmd);
|
|
3886
3654
|
} catch (error) {
|
|
3887
3655
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
3656
|
+
report$1('run', {
|
|
3657
|
+
errMsg,
|
|
3658
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3659
|
+
});
|
|
3888
3660
|
fail(`构建出现错误: ${errMsg}`);
|
|
3889
|
-
info$
|
|
3661
|
+
info$1('详细错误信息', error);
|
|
3890
3662
|
process.exit(1);
|
|
3891
3663
|
}
|
|
3892
3664
|
}
|
|
@@ -3905,20 +3677,32 @@ function otherCommands(tmsConfig, commandName, cmd) {
|
|
|
3905
3677
|
switch (commandName) {
|
|
3906
3678
|
case 'init':
|
|
3907
3679
|
init(tmsConfig, newModules);
|
|
3680
|
+
report$1('run:init', {
|
|
3681
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3682
|
+
});
|
|
3908
3683
|
return;
|
|
3909
3684
|
|
|
3910
3685
|
case 'dev':
|
|
3911
3686
|
global.setData('isDev', true);
|
|
3912
3687
|
dev(tmsConfig, newModules);
|
|
3688
|
+
report$1('run:dev', {
|
|
3689
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3690
|
+
});
|
|
3913
3691
|
return;
|
|
3914
3692
|
|
|
3915
3693
|
case 'install':
|
|
3916
3694
|
install(tmsConfig, subPackages, false);
|
|
3695
|
+
report$1('run:install', {
|
|
3696
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3697
|
+
});
|
|
3917
3698
|
return;
|
|
3918
3699
|
|
|
3919
3700
|
case 'build':
|
|
3920
3701
|
global.setData('isDev', false);
|
|
3921
3702
|
build(tmsConfig, newModules);
|
|
3703
|
+
report$1('run:build', {
|
|
3704
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3705
|
+
});
|
|
3922
3706
|
return;
|
|
3923
3707
|
|
|
3924
3708
|
default:
|
|
@@ -3934,9 +3718,17 @@ var entry = [{
|
|
|
3934
3718
|
action: projectName => {
|
|
3935
3719
|
create_1(projectName);
|
|
3936
3720
|
}
|
|
3721
|
+
}, {
|
|
3722
|
+
command: 'install-cmd <npm-name>',
|
|
3723
|
+
description: '安装扩展命令',
|
|
3724
|
+
options: [['--registry [registry]', 'npm源']],
|
|
3725
|
+
action: (npmName, cmd) => {
|
|
3726
|
+
const res = extendCmd;
|
|
3727
|
+
res.installCmd(npmName, cmd);
|
|
3728
|
+
}
|
|
3937
3729
|
}, {
|
|
3938
3730
|
name: 'run',
|
|
3939
|
-
type: '
|
|
3731
|
+
type: 'parent',
|
|
3940
3732
|
description: '项目开发使用的命令',
|
|
3941
3733
|
commands: [{
|
|
3942
3734
|
command: 'install',
|
|
@@ -3966,114 +3758,14 @@ var entry = [{
|
|
|
3966
3758
|
action: cmd => {
|
|
3967
3759
|
run_1('build', cmd);
|
|
3968
3760
|
}
|
|
3969
|
-
}
|
|
3970
|
-
// {
|
|
3971
|
-
// command: 'init',
|
|
3972
|
-
// description: '模块配置初始化项目(eg: 下载第三方模块代码、安装依赖、生成app.json等)',
|
|
3973
|
-
// options: [
|
|
3974
|
-
// ['-m, --module [moduleName]', '模块名称'],
|
|
3975
|
-
// ['-e, --env [env]', '环境变量'],
|
|
3976
|
-
// ],
|
|
3977
|
-
// action: (cmd) => {
|
|
3978
|
-
// require('./scripts/run/index')('init', cmd);
|
|
3979
|
-
// },
|
|
3980
|
-
// },
|
|
3981
|
-
]
|
|
3761
|
+
}]
|
|
3982
3762
|
}];
|
|
3983
3763
|
|
|
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
3764
|
const semver = require$$1__default$7;
|
|
4073
|
-
const packageJson = require$$
|
|
4074
|
-
const chalk$1 = require$$
|
|
3765
|
+
const packageJson = require$$12;
|
|
3766
|
+
const chalk$1 = require$$3__default;
|
|
4075
3767
|
const {
|
|
4076
|
-
info
|
|
3768
|
+
info
|
|
4077
3769
|
} = log$1;
|
|
4078
3770
|
const requiredVersion = packageJson.engines.node;
|
|
4079
3771
|
const packName = packageJson.name;
|
|
@@ -4088,7 +3780,7 @@ const checkNodeVersion = (wanted, id) => {
|
|
|
4088
3780
|
if (!semver.satisfies(process.version, wanted, {
|
|
4089
3781
|
includePrerelease: true
|
|
4090
3782
|
})) {
|
|
4091
|
-
info
|
|
3783
|
+
info(chalk$1.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id} 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
|
|
4092
3784
|
process.exit(1);
|
|
4093
3785
|
}
|
|
4094
3786
|
};
|
|
@@ -4105,31 +3797,36 @@ function check$1() {
|
|
|
4105
3797
|
|
|
4106
3798
|
var check_1 = check$1;
|
|
4107
3799
|
|
|
4108
|
-
|
|
4109
|
-
const
|
|
3800
|
+
/* eslint-disable no-param-reassign */
|
|
3801
|
+
const chalk = require$$3__default;
|
|
3802
|
+
const commander = require$$1__default$8;
|
|
3803
|
+
const path = require$$1__default$1;
|
|
3804
|
+
const fs = require$$0__default$1;
|
|
4110
3805
|
const {
|
|
4111
|
-
suggestCommands,
|
|
4112
3806
|
resolve
|
|
4113
3807
|
} = widgets;
|
|
4114
3808
|
const {
|
|
4115
|
-
|
|
3809
|
+
infoNoTime
|
|
4116
3810
|
} = log$1;
|
|
4117
3811
|
const {
|
|
4118
3812
|
getTmsConfig
|
|
4119
3813
|
} = tmsMpconfig.exports;
|
|
4120
3814
|
const {
|
|
4121
3815
|
TMS_NAME
|
|
4122
|
-
} =
|
|
3816
|
+
} = constant;
|
|
4123
3817
|
const commands = entry;
|
|
4124
3818
|
const check = check_1;
|
|
4125
|
-
const
|
|
3819
|
+
const {
|
|
3820
|
+
loadExtendCmd
|
|
3821
|
+
} = extendCmd;
|
|
3822
|
+
const report = report_1;
|
|
4126
3823
|
check();
|
|
4127
3824
|
const program = new commander.Command(TMS_NAME);
|
|
4128
|
-
program.version(`${TMS_NAME} ${require$$
|
|
3825
|
+
program.version(`${TMS_NAME} ${require$$12.version}`, '-v, -V, --version'); // 注册命令底层实现
|
|
4129
3826
|
|
|
4130
3827
|
function registerCommand(program, commands) {
|
|
4131
3828
|
commands.forEach(cmd => {
|
|
4132
|
-
if (cmd.type === '
|
|
3829
|
+
if (cmd.type === 'parent') {
|
|
4133
3830
|
const childProgram = new commander.Command(cmd.name);
|
|
4134
3831
|
cmd.usage && childProgram.usage(cmd.usage);
|
|
4135
3832
|
cmd.description && childProgram.description(cmd.description);
|
|
@@ -4141,35 +3838,65 @@ function registerCommand(program, commands) {
|
|
|
4141
3838
|
const command = program.command(cmd.command);
|
|
4142
3839
|
cmd.usage && command.usage(cmd.usage);
|
|
4143
3840
|
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));
|
|
3841
|
+
(_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt)); // 上报
|
|
3842
|
+
|
|
3843
|
+
command.hook('preAction', thisCommand => {
|
|
3844
|
+
report(`${thisCommand._name}-pre`);
|
|
3845
|
+
}); // 上报
|
|
3846
|
+
|
|
3847
|
+
command.hook('postAction', thisCommand => {
|
|
3848
|
+
report(`${thisCommand._name}-post`);
|
|
3849
|
+
});
|
|
4145
3850
|
command.action(cmd.action);
|
|
4146
3851
|
}
|
|
4147
3852
|
});
|
|
4148
|
-
}
|
|
3853
|
+
} // 注册扩展命令
|
|
4149
3854
|
|
|
4150
|
-
function register() {
|
|
4151
|
-
// 注册脚手架内部命令
|
|
4152
|
-
registerCommand(program, commands); // 注册扩展命令
|
|
4153
3855
|
|
|
4154
|
-
|
|
4155
|
-
|
|
3856
|
+
function registerExtendCommand(program, configPath) {
|
|
3857
|
+
const tmsConfig = getTmsConfig(configPath);
|
|
4156
3858
|
|
|
4157
|
-
|
|
4158
|
-
|
|
3859
|
+
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.commands) {
|
|
3860
|
+
const commands = typeof tmsConfig.commands === 'function' ? tmsConfig.commands() : tmsConfig.commands;
|
|
3861
|
+
|
|
3862
|
+
if (Array.isArray(commands)) {
|
|
3863
|
+
registerCommand(program, commands);
|
|
4159
3864
|
}
|
|
4160
3865
|
}
|
|
3866
|
+
} // 注册所有的命令
|
|
3867
|
+
|
|
3868
|
+
|
|
3869
|
+
function registerAllCmds(program, commands) {
|
|
3870
|
+
// 注册脚手架内部命令
|
|
3871
|
+
registerCommand(program, commands); // 注册npm包扩展命令
|
|
3872
|
+
|
|
3873
|
+
const cmdConfigs = loadExtendCmd();
|
|
3874
|
+
cmdConfigs.forEach(cmdConfig => {
|
|
3875
|
+
registerExtendCommand(program, path.dirname(cmdConfig));
|
|
3876
|
+
}); // 注册当前目录扩展命令
|
|
3877
|
+
|
|
3878
|
+
const tmsConfigPath = resolve('./tms.config.js');
|
|
3879
|
+
|
|
3880
|
+
if (fs.existsSync(tmsConfigPath)) {
|
|
3881
|
+
registerExtendCommand(program, path.dirname(tmsConfigPath));
|
|
3882
|
+
}
|
|
4161
3883
|
}
|
|
4162
3884
|
|
|
4163
|
-
|
|
3885
|
+
registerAllCmds(program, commands); // 捕获未注册的命令
|
|
3886
|
+
|
|
3887
|
+
program.arguments('<command>').option('-c, --config <value>', '配置', value => {
|
|
3888
|
+
// 注册指定配置的扩展命令
|
|
3889
|
+
registerExtendCommand(program, path.dirname(resolve(value)));
|
|
3890
|
+
}).action(cmd => {
|
|
3891
|
+
infoNoTime(chalk.yellow(`
|
|
3892
|
+
没有找到${cmd}命令
|
|
3893
|
+
你可以通过${chalk.green('tmskit install-cmd <npm-name>')}安装扩展命令, ${chalk.green('扩展命令列表:https://www.npmjs.com/search?q=tmskit-cmd')}
|
|
3894
|
+
你也可以通过 ${chalk.green('tmskit <command> --config=../tms.config.js')} 指定本地的扩展命令
|
|
3895
|
+
`));
|
|
3896
|
+
report(`${cmd}-not-find`);
|
|
3897
|
+
});
|
|
4164
3898
|
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;
|
|
3899
|
+
infoNoTime(`Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
4173
3900
|
});
|
|
4174
3901
|
|
|
4175
3902
|
if (!process.argv.slice(2).length) {
|