@tmsfe/tmskit 0.0.17 → 0.0.20
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 +12 -2
- package/dist/index.cjs.js +1421 -1083
- package/package.json +10 -8
- package/src/compile/build.js +2 -2
- package/src/compile/dev.js +35 -26
- package/src/compile/watch.js +31 -12
- package/src/config/constant.js +29 -5
- package/src/config/defaultTmsConfig.js +1 -1
- package/src/core/buildAppJson.js +40 -48
- package/src/core/cache.js +36 -0
- package/src/core/checkDependencies.js +35 -18
- package/src/core/cloneModules.js +6 -8
- package/src/core/handleError.js +7 -1
- package/src/core/npm.js +10 -4
- package/src/core/tmsMpconfig.js +90 -113
- package/src/entry.js +3 -3
- package/src/scripts/create/generator.js +1 -2
- package/src/scripts/create/index.js +73 -32
- package/src/scripts/run/build/index.js +9 -5
- package/src/scripts/run/dev/index.js +21 -16
- package/src/scripts/run/index.js +96 -65
- package/src/scripts/run/init/index.js +14 -15
- package/src/scripts/run/install/index.js +110 -18
- package/src/utils/md5.js +25 -0
- package/src/utils/widgets.js +31 -0
- package/src/core/isInIt.js +0 -65
package/dist/index.cjs.js
CHANGED
|
@@ -8,14 +8,16 @@ var require$$2 = require('ora');
|
|
|
8
8
|
var require$$1$2 = require('path');
|
|
9
9
|
var require$$0$2 = require('fs');
|
|
10
10
|
var require$$0$3 = require('shelljs');
|
|
11
|
+
var require$$6 = require('glob-ignore');
|
|
11
12
|
var require$$0$4 = require('async');
|
|
12
13
|
var require$$1$3 = require('ejs');
|
|
13
14
|
var require$$1$4 = require('inquirer');
|
|
14
15
|
var require$$0$5 = require('metalsmith');
|
|
16
|
+
var require$$9 = require('request');
|
|
17
|
+
var require$$10 = require('unzipper');
|
|
15
18
|
var require$$0$6 = require('lodash');
|
|
16
19
|
var require$$1$5 = require('crypto');
|
|
17
20
|
var require$$0$7 = require('miniprogram-ci');
|
|
18
|
-
var require$$5 = require('glob-ignore');
|
|
19
21
|
var require$$1$6 = require('fs-extra');
|
|
20
22
|
var require$$1$7 = require('semver');
|
|
21
23
|
var require$$0$8 = require('strip-comments');
|
|
@@ -26,14 +28,14 @@ var require$$0$a = require('gulp');
|
|
|
26
28
|
var require$$0$b = require('object-assign');
|
|
27
29
|
var require$$3 = require('fancy-log');
|
|
28
30
|
var require$$4$1 = require('ansi-colors');
|
|
29
|
-
var require$$5
|
|
30
|
-
var require$$6 = require('readable-stream');
|
|
31
|
+
var require$$5 = require('chokidar');
|
|
32
|
+
var require$$6$1 = require('readable-stream');
|
|
31
33
|
var require$$7$1 = require('vinyl-file');
|
|
32
34
|
var require$$8 = require('vinyl');
|
|
33
|
-
var require$$9 = require('anymatch');
|
|
35
|
+
var require$$9$1 = require('anymatch');
|
|
34
36
|
var require$$11 = require('glob-parent');
|
|
35
37
|
var require$$2$1 = require('plugin-error');
|
|
36
|
-
var require$$10 = require('path-is-absolute');
|
|
38
|
+
var require$$10$1 = require('path-is-absolute');
|
|
37
39
|
var require$$12 = require('slash');
|
|
38
40
|
|
|
39
41
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
@@ -46,14 +48,16 @@ var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
|
46
48
|
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
47
49
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
48
50
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
51
|
+
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
49
52
|
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
50
53
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
51
54
|
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
52
55
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
56
|
+
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
57
|
+
var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
|
|
53
58
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
54
59
|
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
55
60
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
56
|
-
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
57
61
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
58
62
|
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
59
63
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
@@ -64,14 +68,14 @@ var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
|
64
68
|
var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
|
|
65
69
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
66
70
|
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
|
|
67
|
-
var require$$5__default
|
|
68
|
-
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
71
|
+
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
72
|
+
var require$$6__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
|
|
69
73
|
var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7$1);
|
|
70
74
|
var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
|
|
71
|
-
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
75
|
+
var require$$9__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$9$1);
|
|
72
76
|
var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
|
|
73
77
|
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
74
|
-
var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
|
|
78
|
+
var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
|
|
75
79
|
var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12);
|
|
76
80
|
|
|
77
81
|
function getAugmentedNamespace(n) {
|
|
@@ -91,7 +95,7 @@ function getAugmentedNamespace(n) {
|
|
|
91
95
|
|
|
92
96
|
var src$2 = {};
|
|
93
97
|
|
|
94
|
-
const chalk$
|
|
98
|
+
const chalk$4 = require$$0__default;
|
|
95
99
|
const moment = require$$1__default;
|
|
96
100
|
/**
|
|
97
101
|
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
@@ -105,7 +109,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
105
109
|
* @returns {undefined} 无
|
|
106
110
|
*/
|
|
107
111
|
|
|
108
|
-
const fail$
|
|
112
|
+
const fail$a = (message = '') => {
|
|
109
113
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
110
114
|
|
|
111
115
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
@@ -134,28 +138,29 @@ const succeed$2 = (message = '') => {
|
|
|
134
138
|
|
|
135
139
|
|
|
136
140
|
const warn$2 = message => {
|
|
137
|
-
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$
|
|
141
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$4.yellow(message));
|
|
138
142
|
};
|
|
139
143
|
|
|
140
|
-
const info$
|
|
144
|
+
const info$d = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
141
145
|
|
|
142
146
|
var log$1 = {
|
|
143
|
-
fail: fail$
|
|
147
|
+
fail: fail$a,
|
|
144
148
|
succeed: succeed$2,
|
|
145
149
|
warn: warn$2,
|
|
146
|
-
info: info$
|
|
150
|
+
info: info$d
|
|
147
151
|
};
|
|
148
152
|
|
|
149
153
|
const program$1 = require$$0__default$1;
|
|
150
154
|
const leven = require$$1__default$1;
|
|
151
|
-
const ora = require$$2__default;
|
|
152
|
-
const path$
|
|
153
|
-
const fs$
|
|
155
|
+
const ora$1 = require$$2__default;
|
|
156
|
+
const path$e = require$$1__default$2;
|
|
157
|
+
const fs$g = require$$0__default$2;
|
|
154
158
|
const shelljs$7 = require$$0__default$3;
|
|
159
|
+
const glob$1 = require$$6__default;
|
|
155
160
|
const {
|
|
156
|
-
info: info$
|
|
161
|
+
info: info$c
|
|
157
162
|
} = log$1;
|
|
158
|
-
const chalk$
|
|
163
|
+
const chalk$3 = require$$0__default;
|
|
159
164
|
const shelljsOptions = {
|
|
160
165
|
slient: true,
|
|
161
166
|
async: false
|
|
@@ -163,8 +168,8 @@ const shelljsOptions = {
|
|
|
163
168
|
|
|
164
169
|
const cwd = process.cwd();
|
|
165
170
|
|
|
166
|
-
function resolve$
|
|
167
|
-
return path$
|
|
171
|
+
function resolve$f(...args) {
|
|
172
|
+
return path$e.resolve(cwd, ...args);
|
|
168
173
|
}
|
|
169
174
|
/**
|
|
170
175
|
* 用户输入命令时,进行提示
|
|
@@ -184,7 +189,7 @@ const suggestCommands$1 = unknownCommand => {
|
|
|
184
189
|
});
|
|
185
190
|
|
|
186
191
|
if (suggestion) {
|
|
187
|
-
info$
|
|
192
|
+
info$c(` ${chalk$3.red(`Did you mean ${chalk$3.yellow(suggestion)}?`)}`);
|
|
188
193
|
}
|
|
189
194
|
};
|
|
190
195
|
/**
|
|
@@ -194,7 +199,7 @@ const suggestCommands$1 = unknownCommand => {
|
|
|
194
199
|
*/
|
|
195
200
|
|
|
196
201
|
|
|
197
|
-
function isObject
|
|
202
|
+
function isObject(obj) {
|
|
198
203
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
199
204
|
}
|
|
200
205
|
/**
|
|
@@ -204,7 +209,7 @@ function isObject$1(obj) {
|
|
|
204
209
|
*/
|
|
205
210
|
|
|
206
211
|
|
|
207
|
-
function isArray
|
|
212
|
+
function isArray(obj) {
|
|
208
213
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
209
214
|
}
|
|
210
215
|
/**
|
|
@@ -216,12 +221,12 @@ function isArray$1(obj) {
|
|
|
216
221
|
*/
|
|
217
222
|
|
|
218
223
|
|
|
219
|
-
function downloadRepoForGit$
|
|
224
|
+
function downloadRepoForGit$1(url, dest, branch) {
|
|
220
225
|
const cwd = process.cwd();
|
|
221
226
|
return new Promise((resolve, reject) => {
|
|
222
227
|
// 如果目标目录不存在
|
|
223
|
-
if (fs$
|
|
224
|
-
shelljs$7.rm('-rf', path$
|
|
228
|
+
if (fs$g.existsSync(dest)) {
|
|
229
|
+
shelljs$7.rm('-rf', path$e.join(dest));
|
|
225
230
|
}
|
|
226
231
|
|
|
227
232
|
shelljs$7.mkdir('-p', dest);
|
|
@@ -270,7 +275,7 @@ function pullRepoForGit$1(dest, branch) {
|
|
|
270
275
|
*/
|
|
271
276
|
|
|
272
277
|
|
|
273
|
-
function npmInstall$
|
|
278
|
+
function npmInstall$2(dir) {
|
|
274
279
|
return new Promise((resolve, reject) => {
|
|
275
280
|
shelljs$7.exec('npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
276
281
|
cwd: dir,
|
|
@@ -301,11 +306,11 @@ const cost = start => Date.now() - start;
|
|
|
301
306
|
*/
|
|
302
307
|
|
|
303
308
|
|
|
304
|
-
function createTask$
|
|
309
|
+
function createTask$2(task, startText, endText) {
|
|
305
310
|
return async (...args) => {
|
|
306
311
|
const start = Date.now();
|
|
307
|
-
const spinner = ora();
|
|
308
|
-
info$
|
|
312
|
+
const spinner = ora$1();
|
|
313
|
+
info$c(startText);
|
|
309
314
|
spinner.start();
|
|
310
315
|
const result = await task(...args);
|
|
311
316
|
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
@@ -321,7 +326,7 @@ function createTask$3(task, startText, endText) {
|
|
|
321
326
|
|
|
322
327
|
const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
|
|
323
328
|
|
|
324
|
-
const mergeMap = function (obj, src) {
|
|
329
|
+
const mergeMap$1 = function (obj, src) {
|
|
325
330
|
for (const [k, v] of src) {
|
|
326
331
|
if (obj.has(k)) {
|
|
327
332
|
obj.set(k, obj.get(k) + v);
|
|
@@ -334,87 +339,137 @@ const mergeMap = function (obj, src) {
|
|
|
334
339
|
};
|
|
335
340
|
|
|
336
341
|
const relativeCwdPath$1 = function (file) {
|
|
337
|
-
return path$
|
|
342
|
+
return path$e.relative(process.cwd(), file);
|
|
338
343
|
};
|
|
344
|
+
/**
|
|
345
|
+
* 从一个对象中,检索出去几个字段
|
|
346
|
+
* @param {*} obj
|
|
347
|
+
* @param {*} name
|
|
348
|
+
* @returns
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
const filterField$4 = (obj, filterNames = []) => {
|
|
353
|
+
const newObj = { ...obj
|
|
354
|
+
};
|
|
355
|
+
filterNames.forEach(name => {
|
|
356
|
+
if (newObj[name]) {
|
|
357
|
+
delete newObj[name];
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
return newObj;
|
|
361
|
+
}; // 检索出文件列表
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
function findFiles(globPath, filter = []) {
|
|
365
|
+
return new Promise((resolve, reject) => {
|
|
366
|
+
glob$1(globPath, filter, (err, files) => {
|
|
367
|
+
if (err) {
|
|
368
|
+
reject(err);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
resolve(files);
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
}
|
|
339
375
|
|
|
340
376
|
var widgets = {
|
|
341
|
-
resolve: resolve$
|
|
342
|
-
isObject
|
|
343
|
-
isArray
|
|
344
|
-
createTask: createTask$
|
|
345
|
-
downloadRepoForGit: downloadRepoForGit$
|
|
377
|
+
resolve: resolve$f,
|
|
378
|
+
isObject,
|
|
379
|
+
isArray,
|
|
380
|
+
createTask: createTask$2,
|
|
381
|
+
downloadRepoForGit: downloadRepoForGit$1,
|
|
346
382
|
pullRepoForGit: pullRepoForGit$1,
|
|
347
383
|
suggestCommands: suggestCommands$1,
|
|
348
384
|
camelize,
|
|
349
|
-
npmInstall: npmInstall$
|
|
350
|
-
mergeMap,
|
|
351
|
-
relativeCwdPath: relativeCwdPath$1
|
|
385
|
+
npmInstall: npmInstall$2,
|
|
386
|
+
mergeMap: mergeMap$1,
|
|
387
|
+
relativeCwdPath: relativeCwdPath$1,
|
|
388
|
+
filterField: filterField$4,
|
|
389
|
+
findFiles
|
|
352
390
|
};
|
|
353
391
|
|
|
354
|
-
const path$
|
|
392
|
+
const path$d = require('path');
|
|
355
393
|
|
|
356
394
|
const os = require('os'); // 用户目录
|
|
357
395
|
|
|
358
396
|
|
|
359
397
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
360
398
|
|
|
361
|
-
const CACHE_DIR$
|
|
399
|
+
const CACHE_DIR$3 = path$d.resolve(HOME_DIR, '.tmskit'); // 缓存文件
|
|
400
|
+
|
|
401
|
+
const CACHE_FILE$1 = 'cache_file.json'; // 脚手架模板代码所在目录
|
|
402
|
+
|
|
403
|
+
const TEMPLATE_DIR$1 = path$d.resolve(CACHE_DIR$3, 'template'); // 模板的名称
|
|
362
404
|
|
|
363
|
-
const
|
|
405
|
+
const TEMPLATE_NAME$1 = 'tmskit-template'; // 第三方模块源码存放的临时缓存目录
|
|
364
406
|
|
|
365
|
-
const MODULE_CODE_DIR$1 = path$
|
|
407
|
+
const MODULE_CODE_DIR$1 = path$d.resolve(CACHE_DIR$3, 'modules_code'); // 脚手架模板的远程地址
|
|
366
408
|
|
|
367
|
-
const
|
|
409
|
+
const TEMPLATE_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip'; // 脚手架的名称
|
|
368
410
|
|
|
369
411
|
const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
|
|
370
412
|
|
|
371
|
-
const TMS_CONFIG_FILENAME
|
|
372
|
-
const TMS_PRIVATE_FILENAME
|
|
413
|
+
const TMS_CONFIG_FILENAME = 'tms.config.js';
|
|
414
|
+
const TMS_PRIVATE_FILENAME = 'tms.private.config.js'; // 模块代码的默认在modules子目录
|
|
373
415
|
|
|
374
416
|
const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目录
|
|
375
417
|
|
|
376
418
|
const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
377
419
|
|
|
378
|
-
const MODULE_CONFIG_FILENAME
|
|
420
|
+
const MODULE_CONFIG_FILENAME = 'module.config.json'; // 默认的webpack entry
|
|
379
421
|
|
|
380
422
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
381
|
-
app: path$
|
|
423
|
+
app: path$d.resolve(process.cwd(), 'app')
|
|
382
424
|
}; // 默认从源码拷贝到编译后的配置
|
|
383
425
|
|
|
384
|
-
const DEFAULT_COPY_CONFIG$
|
|
426
|
+
const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json'];
|
|
385
427
|
const ENV = {
|
|
386
428
|
dev: 'development',
|
|
387
429
|
prod: 'production'
|
|
388
430
|
};
|
|
389
431
|
const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
390
|
-
const
|
|
432
|
+
const CREATE_TEMPLATE_QUESTION$1 = [{
|
|
433
|
+
type: 'list',
|
|
434
|
+
name: 'projectType',
|
|
435
|
+
message: '选择你要创建的模板',
|
|
436
|
+
choices: [{
|
|
437
|
+
name: '小程序项目',
|
|
438
|
+
value: 'mp'
|
|
439
|
+
}, {
|
|
440
|
+
name: '小程序模块',
|
|
441
|
+
value: 'mp-module'
|
|
442
|
+
}]
|
|
443
|
+
}];
|
|
391
444
|
|
|
392
445
|
var constant = /*#__PURE__*/Object.freeze({
|
|
393
446
|
__proto__: null,
|
|
394
447
|
HOME_DIR: HOME_DIR,
|
|
395
|
-
CACHE_DIR: CACHE_DIR$
|
|
448
|
+
CACHE_DIR: CACHE_DIR$3,
|
|
449
|
+
CACHE_FILE: CACHE_FILE$1,
|
|
396
450
|
TEMPLATE_DIR: TEMPLATE_DIR$1,
|
|
397
|
-
|
|
451
|
+
TEMPLATE_NAME: TEMPLATE_NAME$1,
|
|
398
452
|
TMS_NAME: TMS_NAME$1,
|
|
399
|
-
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME
|
|
400
|
-
TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME
|
|
453
|
+
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME,
|
|
454
|
+
TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME,
|
|
401
455
|
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
|
|
402
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME
|
|
456
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME,
|
|
403
457
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
404
|
-
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$
|
|
458
|
+
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
|
|
405
459
|
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
406
460
|
ENV: ENV,
|
|
407
461
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
408
|
-
|
|
409
|
-
|
|
462
|
+
DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR,
|
|
463
|
+
CREATE_TEMPLATE_QUESTION: CREATE_TEMPLATE_QUESTION$1,
|
|
464
|
+
TEMPLATE_URL: TEMPLATE_URL$1
|
|
410
465
|
});
|
|
411
466
|
|
|
412
467
|
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
413
468
|
|
|
414
|
-
const fs$
|
|
415
|
-
const path$
|
|
469
|
+
const fs$f = require$$0__default$2;
|
|
470
|
+
const path$c = require$$1__default$2;
|
|
416
471
|
const {
|
|
417
|
-
info: info$
|
|
472
|
+
info: info$b
|
|
418
473
|
} = log$1;
|
|
419
474
|
const {
|
|
420
475
|
relativeCwdPath
|
|
@@ -425,12 +480,12 @@ const {
|
|
|
425
480
|
* @returns
|
|
426
481
|
*/
|
|
427
482
|
|
|
428
|
-
const isDirEmpty = dirname => fs$
|
|
483
|
+
const isDirEmpty = dirname => fs$f.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
429
484
|
|
|
430
485
|
|
|
431
486
|
const isFile = pathName => {
|
|
432
487
|
try {
|
|
433
|
-
const stat = fs$
|
|
488
|
+
const stat = fs$f.lstatSync(pathName);
|
|
434
489
|
return stat.isFile();
|
|
435
490
|
} catch {
|
|
436
491
|
return false;
|
|
@@ -442,9 +497,9 @@ const isFile = pathName => {
|
|
|
442
497
|
*/
|
|
443
498
|
|
|
444
499
|
|
|
445
|
-
const ensureDirExist$
|
|
446
|
-
if (!fs$
|
|
447
|
-
fs$
|
|
500
|
+
const ensureDirExist$2 = dirname => {
|
|
501
|
+
if (!fs$f.existsSync(dirname)) {
|
|
502
|
+
fs$f.mkdirSync(dirname, {
|
|
448
503
|
recursive: true
|
|
449
504
|
});
|
|
450
505
|
}
|
|
@@ -452,27 +507,27 @@ const ensureDirExist$1 = dirname => {
|
|
|
452
507
|
|
|
453
508
|
|
|
454
509
|
const copyFile = function (src, dest) {
|
|
455
|
-
if (fs$
|
|
456
|
-
fs$
|
|
510
|
+
if (fs$f.existsSync(dest)) {
|
|
511
|
+
fs$f.unlinkSync(dest);
|
|
457
512
|
}
|
|
458
513
|
|
|
459
|
-
const dir = path$
|
|
460
|
-
ensureDirExist$
|
|
461
|
-
fs$
|
|
514
|
+
const dir = path$c.dirname(dest);
|
|
515
|
+
ensureDirExist$2(dir);
|
|
516
|
+
fs$f.copyFileSync(src, dest);
|
|
462
517
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
463
518
|
|
|
464
519
|
|
|
465
520
|
function diffContentCopyFile$3(originFile, destFile) {
|
|
466
|
-
if (fs$
|
|
467
|
-
const depDestContent = fs$
|
|
468
|
-
const depOriginContent = fs$
|
|
521
|
+
if (fs$f.existsSync(destFile)) {
|
|
522
|
+
const depDestContent = fs$f.readFileSync(destFile, 'utf8');
|
|
523
|
+
const depOriginContent = fs$f.readFileSync(originFile, 'utf8');
|
|
469
524
|
|
|
470
525
|
if (depDestContent !== depOriginContent) {
|
|
471
|
-
info$
|
|
526
|
+
info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
472
527
|
copyFile(originFile, destFile);
|
|
473
528
|
}
|
|
474
529
|
} else {
|
|
475
|
-
info$
|
|
530
|
+
info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
476
531
|
copyFile(originFile, destFile);
|
|
477
532
|
}
|
|
478
533
|
} // 添加后缀
|
|
@@ -483,7 +538,7 @@ function ext$3(filePath, extensions) {
|
|
|
483
538
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
484
539
|
|
|
485
540
|
try {
|
|
486
|
-
const stat = fs$
|
|
541
|
+
const stat = fs$f.lstatSync(newFilePath);
|
|
487
542
|
|
|
488
543
|
if (stat.isDirectory()) {
|
|
489
544
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -494,7 +549,7 @@ function ext$3(filePath, extensions) {
|
|
|
494
549
|
for (const ext of extensions) {
|
|
495
550
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
496
551
|
|
|
497
|
-
if (fs$
|
|
552
|
+
if (fs$f.existsSync(file)) {
|
|
498
553
|
return {
|
|
499
554
|
ext,
|
|
500
555
|
extPath: extPath + ext,
|
|
@@ -512,11 +567,11 @@ function ext$3(filePath, extensions) {
|
|
|
512
567
|
|
|
513
568
|
|
|
514
569
|
const fileInDir$3 = (dir, file) => {
|
|
515
|
-
if (!fs$
|
|
570
|
+
if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
|
|
516
571
|
return false;
|
|
517
572
|
}
|
|
518
573
|
|
|
519
|
-
const relativePath = path$
|
|
574
|
+
const relativePath = path$c.relative(dir, file);
|
|
520
575
|
|
|
521
576
|
if (relativePath.startsWith('..')) {
|
|
522
577
|
return false;
|
|
@@ -529,10 +584,10 @@ function findAllFilesOfDir$1(dir) {
|
|
|
529
584
|
const list = [];
|
|
530
585
|
|
|
531
586
|
function listFile(dir) {
|
|
532
|
-
const arr = fs$
|
|
587
|
+
const arr = fs$f.readdirSync(dir);
|
|
533
588
|
arr.forEach(item => {
|
|
534
|
-
const fullPath = path$
|
|
535
|
-
const stats = fs$
|
|
589
|
+
const fullPath = path$c.join(dir, item);
|
|
590
|
+
const stats = fs$f.statSync(fullPath);
|
|
536
591
|
|
|
537
592
|
if (stats.isDirectory()) {
|
|
538
593
|
listFile(fullPath);
|
|
@@ -551,7 +606,7 @@ var io$3 = {
|
|
|
551
606
|
isDirEmpty,
|
|
552
607
|
copyFile,
|
|
553
608
|
diffContentCopyFile: diffContentCopyFile$3,
|
|
554
|
-
ensureDirExist: ensureDirExist$
|
|
609
|
+
ensureDirExist: ensureDirExist$2,
|
|
555
610
|
ext: ext$3,
|
|
556
611
|
fileInDir: fileInDir$3,
|
|
557
612
|
isFile,
|
|
@@ -578,10 +633,10 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
578
633
|
|
|
579
634
|
var render_1 = render$1;
|
|
580
635
|
|
|
581
|
-
const fs$
|
|
582
|
-
const inquirer = require$$1__default$4;
|
|
636
|
+
const fs$e = require$$0__default$2;
|
|
637
|
+
const inquirer$1 = require$$1__default$4;
|
|
583
638
|
const {
|
|
584
|
-
resolve: resolve$
|
|
639
|
+
resolve: resolve$e
|
|
585
640
|
} = widgets;
|
|
586
641
|
const {
|
|
587
642
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
@@ -595,12 +650,12 @@ const {
|
|
|
595
650
|
const parseTemplateQuestions = dir => {
|
|
596
651
|
let prompts = [];
|
|
597
652
|
|
|
598
|
-
if (!fs$
|
|
653
|
+
if (!fs$e.existsSync(`${dir}/questions.json`)) {
|
|
599
654
|
return prompts;
|
|
600
655
|
}
|
|
601
656
|
|
|
602
657
|
try {
|
|
603
|
-
const json = JSON.parse(fs$
|
|
658
|
+
const json = JSON.parse(fs$e.readFileSync(`${dir}/questions.json`));
|
|
604
659
|
|
|
605
660
|
if (Array.isArray(json) && json.length > 0) {
|
|
606
661
|
json.forEach((item, index) => {
|
|
@@ -633,7 +688,7 @@ const isQuestionType = result => {
|
|
|
633
688
|
};
|
|
634
689
|
|
|
635
690
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
636
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
691
|
+
const prompts = parseTemplateQuestions(resolve$e(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
637
692
|
const metadata = metalsmith.metadata();
|
|
638
693
|
const filteredPrompts = prompts.filter(prompt => {
|
|
639
694
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -642,7 +697,7 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
|
642
697
|
|
|
643
698
|
return true;
|
|
644
699
|
});
|
|
645
|
-
inquirer.prompt(filteredPrompts).then(res => {
|
|
700
|
+
inquirer$1.prompt(filteredPrompts).then(res => {
|
|
646
701
|
for (const prompt of filteredPrompts) {
|
|
647
702
|
metadata[prompt.name] = res[prompt.name];
|
|
648
703
|
}
|
|
@@ -663,7 +718,7 @@ const render = render_1;
|
|
|
663
718
|
const ask = ask_1;
|
|
664
719
|
const FILES_TO_IGNORE = ignoreFiles;
|
|
665
720
|
|
|
666
|
-
const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, reject) => {
|
|
721
|
+
const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolve, reject) => {
|
|
667
722
|
Metalsmith(buildDir).metadata(preMetadata).ignore(FILES_TO_IGNORE).clean(false).use(ask(buildDir)).source('./').destination(distDir).use(render).build(err => {
|
|
668
723
|
if (err) {
|
|
669
724
|
reject(err);
|
|
@@ -675,97 +730,142 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
675
730
|
|
|
676
731
|
var generator_1 = generator$1;
|
|
677
732
|
|
|
678
|
-
const path$
|
|
679
|
-
const fs$
|
|
733
|
+
const path$b = require$$1__default$2;
|
|
734
|
+
const fs$d = require$$0__default$2;
|
|
680
735
|
const shelljs$6 = require$$0__default$3;
|
|
736
|
+
const inquirer = require$$1__default$4;
|
|
681
737
|
const {
|
|
682
738
|
TEMPLATE_DIR,
|
|
683
|
-
|
|
684
|
-
|
|
739
|
+
TEMPLATE_URL,
|
|
740
|
+
TEMPLATE_NAME,
|
|
741
|
+
TEMPLATE_TKIT_DIR,
|
|
742
|
+
CREATE_TEMPLATE_QUESTION
|
|
685
743
|
} = require$$4;
|
|
686
744
|
const {
|
|
687
|
-
|
|
688
|
-
createTask: createTask$2,
|
|
689
|
-
resolve: resolve$c
|
|
745
|
+
resolve: resolve$d
|
|
690
746
|
} = widgets;
|
|
691
747
|
const io$2 = io$3;
|
|
692
748
|
const {
|
|
693
|
-
fail: fail$
|
|
749
|
+
fail: fail$9,
|
|
694
750
|
succeed: succeed$1,
|
|
695
|
-
info: info$
|
|
751
|
+
info: info$a
|
|
696
752
|
} = log$1;
|
|
697
753
|
const generator = generator_1;
|
|
754
|
+
const request = require$$9__default;
|
|
755
|
+
const unzip = require$$10__default;
|
|
698
756
|
/**
|
|
699
757
|
* 如果该目录下面存在文件,换个名字
|
|
700
758
|
* @param { string } targetDir 当前文件夹
|
|
701
759
|
* @returns { undefined }
|
|
702
760
|
*/
|
|
703
761
|
|
|
704
|
-
async function
|
|
762
|
+
async function createProjectDir(targetDir) {
|
|
705
763
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
706
|
-
if (fs$
|
|
764
|
+
if (fs$d.existsSync(targetDir)) {
|
|
707
765
|
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
708
|
-
fail$
|
|
766
|
+
fail$9('该目录名已经存在,换个项目名字吧~');
|
|
709
767
|
process.exit(1);
|
|
710
768
|
}
|
|
711
769
|
} else {
|
|
712
770
|
shelljs$6.mkdir('-p', targetDir);
|
|
713
771
|
}
|
|
714
772
|
}
|
|
773
|
+
/**
|
|
774
|
+
* 下载和解压远程的小程序模板
|
|
775
|
+
* @param {string} templateDir
|
|
776
|
+
* @param {string} templateUrl
|
|
777
|
+
* @param {string} templateName
|
|
778
|
+
* @returns
|
|
779
|
+
*/
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
|
|
783
|
+
return new Promise((resolve, reject) => {
|
|
784
|
+
const localZipPath = `${templateDir}/${templateName}.zip`;
|
|
785
|
+
const stream = fs$d.createWriteStream(localZipPath);
|
|
786
|
+
request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
|
|
787
|
+
if (err) {
|
|
788
|
+
reject(err);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
fs$d.createReadStream(localZipPath).pipe(unzip.Extract({
|
|
793
|
+
path: templateDir
|
|
794
|
+
})).on('close', err => {
|
|
795
|
+
if (err) {
|
|
796
|
+
reject(err);
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
resolve();
|
|
801
|
+
});
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
}
|
|
715
805
|
/**
|
|
716
806
|
* 创建本地小程序运行环境
|
|
717
|
-
* @param { string }
|
|
718
|
-
* @param { string }
|
|
807
|
+
* @param { string } projectType 项目类型
|
|
808
|
+
* @param { string } projectName 项目名称
|
|
719
809
|
*/
|
|
720
810
|
|
|
721
811
|
|
|
722
|
-
async function create(
|
|
812
|
+
async function create(projectName) {
|
|
723
813
|
const cwd = process.cwd();
|
|
724
|
-
const targetDir = path$
|
|
725
|
-
const
|
|
726
|
-
|
|
814
|
+
const targetDir = path$b.resolve(cwd, projectName);
|
|
815
|
+
const {
|
|
816
|
+
projectType
|
|
817
|
+
} = await inquirer.prompt(CREATE_TEMPLATE_QUESTION); // 创建项目目录
|
|
727
818
|
|
|
728
|
-
|
|
819
|
+
await createProjectDir(targetDir); // 新创建缓存目录
|
|
729
820
|
|
|
730
|
-
|
|
821
|
+
if (fs$d.existsSync(TEMPLATE_DIR)) {
|
|
822
|
+
shelljs$6.rm('-rf', TEMPLATE_DIR);
|
|
823
|
+
}
|
|
731
824
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}).then(() => {
|
|
736
|
-
shelljs$6.cd(appName);
|
|
825
|
+
fs$d.mkdirSync(TEMPLATE_DIR, {
|
|
826
|
+
recursive: true
|
|
827
|
+
}); // 下载和解压模板
|
|
737
828
|
|
|
738
|
-
|
|
829
|
+
await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
739
830
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
831
|
+
generator(path$b.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
|
|
832
|
+
shelljs$6.cd(projectName);
|
|
833
|
+
const hookFilePath = resolve$d(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
|
|
834
|
+
|
|
835
|
+
if (fs$d.existsSync(hookFilePath)) {
|
|
836
|
+
const hooks = require(hookFilePath);
|
|
837
|
+
|
|
838
|
+
if (hooks.afterCreate) {
|
|
839
|
+
hooks.afterCreate.forEach(item => {
|
|
840
|
+
if (typeof item === 'function') {
|
|
841
|
+
item.call(null, shelljs$6, {
|
|
842
|
+
projectName
|
|
843
|
+
});
|
|
844
|
+
} else {
|
|
845
|
+
shelljs$6.exec(item);
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
shelljs$6.rm('-rf', resolve$d(projectName, TEMPLATE_TKIT_DIR));
|
|
750
851
|
}
|
|
751
852
|
|
|
752
|
-
shelljs$6.rm('-rf', resolve$c(appName, TEMPLATE_TKIT_DIR));
|
|
753
853
|
succeed$1('项目创建完成.');
|
|
754
854
|
}).catch(err => {
|
|
755
|
-
fail$
|
|
756
|
-
info$
|
|
855
|
+
fail$9(err.message);
|
|
856
|
+
info$a('详细的错误信息:', err);
|
|
757
857
|
});
|
|
758
858
|
}
|
|
759
859
|
|
|
760
860
|
var create_1 = create;
|
|
761
861
|
|
|
762
|
-
var
|
|
862
|
+
var tmsMpconfig = {exports: {}};
|
|
763
863
|
|
|
764
|
-
var defaultTmsConfig
|
|
864
|
+
var defaultTmsConfig = {
|
|
765
865
|
// 全局的环境配置项
|
|
766
866
|
envData: {},
|
|
767
867
|
// 模块配置信息
|
|
768
|
-
modules:
|
|
868
|
+
modules: {},
|
|
769
869
|
cloudDir: 'cloud',
|
|
770
870
|
// 第三方依赖代码需要拷贝到本项目的
|
|
771
871
|
dependencies: {},
|
|
@@ -783,280 +883,249 @@ var defaultTmsConfig$1 = {
|
|
|
783
883
|
/**
|
|
784
884
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
785
885
|
*/
|
|
786
|
-
const loadash = require$$0__default$6;
|
|
787
|
-
const fs$9 = require$$0__default$2;
|
|
788
|
-
const {
|
|
789
|
-
TMS_CONFIG_FILENAME,
|
|
790
|
-
MODULE_CONFIG_FILENAME,
|
|
791
|
-
TMS_PRIVATE_FILENAME
|
|
792
|
-
} = require$$4;
|
|
793
|
-
const {
|
|
794
|
-
resolve: resolve$b,
|
|
795
|
-
isObject,
|
|
796
|
-
isArray
|
|
797
|
-
} = widgets;
|
|
798
|
-
const defaultTmsConfig = defaultTmsConfig$1;
|
|
799
|
-
const {
|
|
800
|
-
fail: fail$6
|
|
801
|
-
} = log$1;
|
|
802
|
-
const path$8 = require$$1__default$2;
|
|
803
|
-
/**
|
|
804
|
-
* 读取tms.config.js
|
|
805
|
-
* @param env {string} 环境变量
|
|
806
|
-
*/
|
|
807
886
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
887
|
+
(function (module) {
|
|
888
|
+
/* eslint-disable no-param-reassign, no-nested-ternary */
|
|
889
|
+
const loadash = require$$0__default$6;
|
|
890
|
+
const fs = require$$0__default$2;
|
|
891
|
+
const {
|
|
892
|
+
TMS_CONFIG_FILENAME,
|
|
893
|
+
MODULE_CONFIG_FILENAME,
|
|
894
|
+
TMS_PRIVATE_FILENAME
|
|
895
|
+
} = require$$4;
|
|
896
|
+
const {
|
|
897
|
+
resolve,
|
|
898
|
+
isObject,
|
|
899
|
+
isArray
|
|
900
|
+
} = widgets;
|
|
901
|
+
const defaultTmsConfig$1 = defaultTmsConfig;
|
|
902
|
+
const {
|
|
903
|
+
fail
|
|
904
|
+
} = log$1;
|
|
905
|
+
/**
|
|
906
|
+
* 读取tms.config.js
|
|
907
|
+
* @param env {string} 环境变量
|
|
908
|
+
*/
|
|
815
909
|
|
|
816
|
-
const
|
|
910
|
+
const readTmsConfig = function (env) {
|
|
911
|
+
const tmsConfigPath = resolve(TMS_CONFIG_FILENAME);
|
|
817
912
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
913
|
+
if (!fs.existsSync(tmsConfigPath)) {
|
|
914
|
+
fail('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
915
|
+
process.exit(1);
|
|
916
|
+
}
|
|
821
917
|
|
|
822
|
-
|
|
918
|
+
const tmsConfigFn = require(tmsConfigPath);
|
|
823
919
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
}; //
|
|
920
|
+
const tmsConfig = tmsConfigFn({
|
|
921
|
+
env
|
|
922
|
+
}); // 合并默认值
|
|
827
923
|
|
|
924
|
+
return loadash.mergeWith(defaultTmsConfig$1, tmsConfig);
|
|
925
|
+
};
|
|
926
|
+
/**
|
|
927
|
+
* 读取tms.private.config.js
|
|
928
|
+
*/
|
|
828
929
|
|
|
829
|
-
const convertModules = modules => {
|
|
830
|
-
const newModules = [];
|
|
831
|
-
modules.forEach(module => {
|
|
832
|
-
const newModule = {};
|
|
833
930
|
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
name: path$8.basename(module),
|
|
838
|
-
path: module
|
|
839
|
-
});
|
|
840
|
-
} else if (typeof module === 'object') {
|
|
841
|
-
Object.assign(newModule, module);
|
|
931
|
+
const readTmsPrivateCf = function () {
|
|
932
|
+
let tmsPrivateCf = {};
|
|
933
|
+
const tmsPrivatePath = resolve(TMS_PRIVATE_FILENAME);
|
|
842
934
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
}
|
|
935
|
+
if (fs.existsSync(tmsPrivatePath)) {
|
|
936
|
+
tmsPrivateCf = require(tmsPrivatePath);
|
|
846
937
|
}
|
|
847
938
|
|
|
848
|
-
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
939
|
+
return tmsPrivateCf;
|
|
940
|
+
};
|
|
941
|
+
/**
|
|
942
|
+
* 从tms.config.json中检索用户传入的有效modules
|
|
943
|
+
* @param { object } tmsConfig
|
|
944
|
+
* @param { array } modules
|
|
945
|
+
* @returns
|
|
946
|
+
*/
|
|
855
947
|
|
|
856
948
|
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
|
|
949
|
+
const checkModules = function (tmsConfig, modules, isQuit = false) {
|
|
950
|
+
const targetModules = [];
|
|
951
|
+
modules.forEach(moduleName => {
|
|
952
|
+
const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
|
|
953
|
+
module && targetModules.push(module);
|
|
954
|
+
});
|
|
860
955
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
956
|
+
if (targetModules.length === 0) {
|
|
957
|
+
fail(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
|
|
958
|
+
>name字段与module.config.json的name字段是否一致`);
|
|
959
|
+
isQuit && process.exit(1);
|
|
960
|
+
}
|
|
864
961
|
|
|
962
|
+
return targetModules;
|
|
963
|
+
};
|
|
964
|
+
/**
|
|
965
|
+
* 适配处理module.config.json的字段
|
|
966
|
+
* @param { object } fileContent module.config.json的内容
|
|
967
|
+
* @param { string } appName 小程序的名称
|
|
968
|
+
*/
|
|
865
969
|
|
|
866
|
-
if (tmsPrivateCf.modules instanceof Array) {
|
|
867
|
-
Object.assign(tmsPrivateCf.modules, {
|
|
868
|
-
include: tmsPrivateCf.modules
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
970
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
* 从tms.config.json中检索用户传入的有效modules
|
|
876
|
-
* @param { object } tmsConfig
|
|
877
|
-
* @param { array } modules
|
|
878
|
-
* @returns
|
|
879
|
-
*/
|
|
971
|
+
function adaptMpCgContent(fileContent, appName) {
|
|
972
|
+
const handleContent = function (appName, current) {
|
|
973
|
+
let res = current;
|
|
880
974
|
|
|
975
|
+
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
976
|
+
res = { ...current,
|
|
977
|
+
...current.mpConfig[appName]
|
|
978
|
+
};
|
|
979
|
+
}
|
|
881
980
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
module && targetModules.push(module);
|
|
887
|
-
});
|
|
981
|
+
delete res.mpConfig;
|
|
982
|
+
delete res.isSubpackages;
|
|
983
|
+
return res;
|
|
984
|
+
};
|
|
888
985
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
986
|
+
let content = fileContent;
|
|
987
|
+
|
|
988
|
+
if (isArray(content)) {
|
|
989
|
+
let i = content.length - 1;
|
|
990
|
+
|
|
991
|
+
while (i >= 0) {
|
|
992
|
+
content[i] = handleContent(appName, content[i]);
|
|
993
|
+
i--; // eslint-disable-line
|
|
994
|
+
}
|
|
995
|
+
} else {
|
|
996
|
+
content = handleContent(appName, content);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
return content;
|
|
893
1000
|
}
|
|
1001
|
+
/**
|
|
1002
|
+
* 获取模块module.config.json中的配置信息
|
|
1003
|
+
* @param {array} modules 用户要编译的模块列表
|
|
1004
|
+
* @param { string } appName 小程序的名称
|
|
1005
|
+
* @param {boolean} notFindIsQuit 找不到配置文件是否退出
|
|
1006
|
+
*/
|
|
894
1007
|
|
|
895
|
-
return targetModules;
|
|
896
|
-
};
|
|
897
|
-
/**
|
|
898
|
-
* 适配处理module.config.json的字段
|
|
899
|
-
* @param { object } fileContent module.config.json的内容
|
|
900
|
-
* @param { string } appName 小程序的名称
|
|
901
|
-
*/
|
|
902
1008
|
|
|
1009
|
+
function getModulesConfig(modules = [], appName, notFindIsQuit) {
|
|
1010
|
+
const modulesConfig = [];
|
|
1011
|
+
modules.forEach(moduleItem => {
|
|
1012
|
+
if (!moduleItem.path) {
|
|
1013
|
+
throw new Error(`${moduleItem.moduleName}模块路径配置没有找到`);
|
|
1014
|
+
}
|
|
903
1015
|
|
|
904
|
-
|
|
905
|
-
const handleContent = function (appName, current) {
|
|
906
|
-
let res = current;
|
|
1016
|
+
const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
|
|
907
1017
|
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
}
|
|
1018
|
+
if (!fs.existsSync(moduleConfigPath)) {
|
|
1019
|
+
if (notFindIsQuit) {
|
|
1020
|
+
throw new Error(`${moduleItem.moduleName}模块的配置文件module.config.json在${moduleItem.path}目录下没有找到`);
|
|
1021
|
+
}
|
|
913
1022
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
return res;
|
|
917
|
-
};
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
918
1025
|
|
|
919
|
-
|
|
1026
|
+
let moduleConfig;
|
|
920
1027
|
|
|
921
|
-
|
|
922
|
-
|
|
1028
|
+
try {
|
|
1029
|
+
moduleConfig = JSON.parse(fs.readFileSync(moduleConfigPath, 'utf-8'));
|
|
1030
|
+
} catch (e) {
|
|
1031
|
+
throw new Error(`${moduleConfigPath}json解析报错: ${e}`);
|
|
1032
|
+
} // 兼容历史逻辑,后续可删除--- start
|
|
923
1033
|
|
|
924
|
-
while (i >= 0) {
|
|
925
|
-
content[i] = handleContent(appName, content[i]);
|
|
926
|
-
i--; // eslint-disable-line
|
|
927
|
-
}
|
|
928
|
-
} else {
|
|
929
|
-
if (appName && content.mpConfig && content.mpConfig[appName]) {
|
|
930
|
-
content = { ...content,
|
|
931
|
-
...content.mpConfig[appName]
|
|
932
|
-
};
|
|
933
|
-
delete content.mpConfig;
|
|
934
|
-
delete content.isSubpackages;
|
|
935
|
-
}
|
|
936
1034
|
|
|
937
|
-
|
|
938
|
-
|
|
1035
|
+
if (!moduleItem.moduleName) moduleItem.moduleName = moduleItem.name;
|
|
1036
|
+
delete moduleItem.name;
|
|
1037
|
+
let subPackages = isObject(moduleConfig) && moduleConfig.subPackages ? moduleConfig.subPackages : isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
|
|
1038
|
+
subPackages = adaptMpCgContent(subPackages, appName);
|
|
1039
|
+
let dependencies = moduleConfig.dependencies || [];
|
|
1040
|
+
subPackages.forEach(item => {
|
|
1041
|
+
item.path = moduleItem.path;
|
|
939
1042
|
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
* @param { string } moduleConfigFilename moduleConfig的文件名
|
|
947
|
-
*/
|
|
1043
|
+
if (item.dependencies) {
|
|
1044
|
+
dependencies = dependencies.concat(item.dependencies);
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
moduleItem.subPackages = subPackages;
|
|
1048
|
+
moduleItem.dependencies = dependencies; // 兼容逻辑--- end
|
|
948
1049
|
|
|
1050
|
+
modulesConfig.push(moduleItem);
|
|
1051
|
+
});
|
|
1052
|
+
return modulesConfig;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* 获取分包内容 (读取module.config.json的配置项)
|
|
1056
|
+
* @param {array} modules
|
|
1057
|
+
* @returns
|
|
1058
|
+
*/
|
|
949
1059
|
|
|
950
|
-
function getModuleConfig(modules = [], appName, moduleConfigFilename) {
|
|
951
|
-
const modulesConfig = {};
|
|
952
|
-
modules.forEach(({
|
|
953
|
-
path
|
|
954
|
-
}) => {
|
|
955
|
-
const moduleConfigPath = resolve$b(path, moduleConfigFilename);
|
|
956
1060
|
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1061
|
+
const getSubPackages = modules => {
|
|
1062
|
+
const newSubPackages = [];
|
|
1063
|
+
modules.forEach(module => {
|
|
1064
|
+
(module.subPackages || []).forEach(item => {
|
|
1065
|
+
newSubPackages.push({
|
|
1066
|
+
path: module.path,
|
|
1067
|
+
...item
|
|
1068
|
+
});
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
return newSubPackages;
|
|
1072
|
+
};
|
|
1073
|
+
/**
|
|
1074
|
+
* 获取所有的模块,合并模块的依赖模块
|
|
1075
|
+
* @param { object } tmsConfig
|
|
1076
|
+
* @param {array} modules
|
|
1077
|
+
* @param {boolean} notFindIsQuit 找不到配置文件是否退出
|
|
1078
|
+
* @returns
|
|
1079
|
+
*/
|
|
971
1080
|
|
|
972
1081
|
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
modules.forEach(({
|
|
976
|
-
path: relativePath,
|
|
977
|
-
name: moduleName
|
|
978
|
-
}, moduleIndex) => {
|
|
979
|
-
const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME);
|
|
1082
|
+
const getModulesByMergeDepModules = (tmsConfig, modules, notFindIsQuit = false) => {
|
|
1083
|
+
const allModules = new Map();
|
|
980
1084
|
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1085
|
+
function dfs(tmsConfig, modules) {
|
|
1086
|
+
modules.forEach(moduleItem => {
|
|
1087
|
+
const [moduleConfig = {}] = getModulesConfig([moduleItem], tmsConfig.appName, notFindIsQuit);
|
|
1088
|
+
|
|
1089
|
+
if (!allModules.has(moduleItem.moduleName)) {
|
|
1090
|
+
allModules.set(moduleItem.moduleName, { ...moduleItem,
|
|
1091
|
+
...moduleConfig
|
|
1092
|
+
});
|
|
1093
|
+
const dependenciesModules = [];
|
|
1094
|
+
((moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies) || []).forEach(dependenciesModule => {
|
|
1095
|
+
tmsConfig.modules.all.forEach(module => {
|
|
1096
|
+
if (dependenciesModule === module.moduleName) {
|
|
1097
|
+
dependenciesModules.push({ ...module
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
994
1100
|
});
|
|
995
|
-
}
|
|
996
|
-
});
|
|
1101
|
+
});
|
|
997
1102
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1103
|
+
if (dependenciesModules.length) {
|
|
1104
|
+
dfs(tmsConfig, dependenciesModules);
|
|
1105
|
+
}
|
|
1001
1106
|
}
|
|
1002
|
-
} catch (e) {
|
|
1003
|
-
fail$6(`${moduleConfigPath}配置错误: ${e}`);
|
|
1004
|
-
newModules.push({ ...modules[moduleIndex]
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
} else {
|
|
1008
|
-
newModules.push({ ...modules[moduleIndex]
|
|
1009
1107
|
});
|
|
1010
1108
|
}
|
|
1011
|
-
});
|
|
1012
|
-
return newModules;
|
|
1013
|
-
};
|
|
1014
|
-
/**
|
|
1015
|
-
* 分包依赖了分包的模块 合并所依赖的modules
|
|
1016
|
-
* @param { object } tmsConfig
|
|
1017
|
-
* @param {array} modules
|
|
1018
|
-
* @param {string} moduleDir
|
|
1019
|
-
* @returns
|
|
1020
|
-
*/
|
|
1021
1109
|
|
|
1110
|
+
dfs(tmsConfig, modules);
|
|
1111
|
+
const modulesArr = [];
|
|
1022
1112
|
|
|
1023
|
-
const
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
name: moduleName
|
|
1027
|
-
}) => {
|
|
1028
|
-
moduleNames.push(moduleName);
|
|
1029
|
-
});
|
|
1030
|
-
let mergeModules = modules;
|
|
1031
|
-
let isOver = true;
|
|
1032
|
-
modules.forEach(({
|
|
1033
|
-
dependencies: dependencyModules
|
|
1034
|
-
}) => {
|
|
1035
|
-
dependencyModules === null || dependencyModules === void 0 ? void 0 : dependencyModules.forEach(item => {
|
|
1036
|
-
// 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
|
|
1037
|
-
// 否则递归处理,根据name找到相关配置加到modules里
|
|
1038
|
-
if (moduleNames.indexOf(item) === -1) {
|
|
1039
|
-
const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
|
|
1040
|
-
|
|
1041
|
-
if (tmpModules.length > 0) {
|
|
1042
|
-
isOver = false;
|
|
1043
|
-
mergeModules = [...mergeModules, ...tmpModules];
|
|
1044
|
-
mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
});
|
|
1048
|
-
});
|
|
1049
|
-
return isOver ? mergeModules : subModulesMergeDepModules$2(tmsConfig, mergeModules);
|
|
1050
|
-
};
|
|
1113
|
+
for (const module of allModules.values()) {
|
|
1114
|
+
modulesArr.push(module);
|
|
1115
|
+
}
|
|
1051
1116
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1117
|
+
return modulesArr;
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
module.exports = {
|
|
1121
|
+
readTmsConfig,
|
|
1122
|
+
readTmsPrivateCf,
|
|
1123
|
+
getModulesConfig,
|
|
1124
|
+
checkModules,
|
|
1125
|
+
getSubPackages,
|
|
1126
|
+
getModulesByMergeDepModules
|
|
1127
|
+
};
|
|
1128
|
+
})(tmsMpconfig);
|
|
1060
1129
|
|
|
1061
1130
|
const global$6 = {
|
|
1062
1131
|
data: {},
|
|
@@ -1084,258 +1153,238 @@ var global_1 = {
|
|
|
1084
1153
|
};
|
|
1085
1154
|
|
|
1086
1155
|
const {
|
|
1087
|
-
fail: fail$
|
|
1156
|
+
fail: fail$8
|
|
1088
1157
|
} = log$1;
|
|
1089
1158
|
const {
|
|
1090
1159
|
global: global$5
|
|
1091
1160
|
} = global_1;
|
|
1092
1161
|
|
|
1093
|
-
function handleError$
|
|
1162
|
+
function handleError$6(error, isQuit = false) {
|
|
1094
1163
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1164
|
+
|
|
1165
|
+
if (isQuit) {
|
|
1166
|
+
fail$8(errMsg);
|
|
1167
|
+
process.exit(1);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1095
1170
|
const isDev = global$5.getData('isDev');
|
|
1096
1171
|
|
|
1097
1172
|
if (isDev) {
|
|
1098
|
-
fail$
|
|
1173
|
+
fail$8(errMsg);
|
|
1099
1174
|
} else {
|
|
1100
|
-
fail$
|
|
1175
|
+
fail$8(errMsg);
|
|
1101
1176
|
process.exit(1);
|
|
1102
1177
|
}
|
|
1103
1178
|
}
|
|
1104
1179
|
|
|
1105
1180
|
var handleError_1 = {
|
|
1106
|
-
handleError: handleError$
|
|
1181
|
+
handleError: handleError$6
|
|
1107
1182
|
};
|
|
1108
1183
|
|
|
1109
1184
|
/**
|
|
1110
1185
|
* 生成编译后的app.json
|
|
1111
1186
|
*/
|
|
1187
|
+
/* eslint-disable no-param-reassign */
|
|
1112
1188
|
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
* @param { object } appJson appJson信息
|
|
1139
|
-
* @param { array } mainPackages 小程序主包信息
|
|
1140
|
-
* @returns { object } appJson小程序主页配置信息
|
|
1141
|
-
*/
|
|
1142
|
-
|
|
1143
|
-
function updateMainPackages(appJson, mainPackages = []) {
|
|
1144
|
-
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1145
|
-
|
|
1146
|
-
if (foundMainPackages.length === 0) {
|
|
1147
|
-
// 没找到主包
|
|
1148
|
-
foundMainPackages = [appJson.subpackages[0]];
|
|
1149
|
-
} // 拼装 app.pages
|
|
1150
|
-
|
|
1189
|
+
const fs$c = require$$0__default$2;
|
|
1190
|
+
const {
|
|
1191
|
+
getSubPackages: getSubPackages$3,
|
|
1192
|
+
getModulesConfig
|
|
1193
|
+
} = tmsMpconfig.exports;
|
|
1194
|
+
const {
|
|
1195
|
+
fail: fail$7,
|
|
1196
|
+
info: info$9
|
|
1197
|
+
} = log$1;
|
|
1198
|
+
const {
|
|
1199
|
+
resolve: resolve$c,
|
|
1200
|
+
filterField: filterField$3
|
|
1201
|
+
} = widgets;
|
|
1202
|
+
const {
|
|
1203
|
+
handleError: handleError$5
|
|
1204
|
+
} = handleError_1;
|
|
1205
|
+
const {
|
|
1206
|
+
global: global$4
|
|
1207
|
+
} = global_1;
|
|
1208
|
+
/**
|
|
1209
|
+
* 更新appJson里面的主包配置
|
|
1210
|
+
* @param { object } appJson appJson信息
|
|
1211
|
+
* @param { array } mainPackages 小程序主包信息
|
|
1212
|
+
* @returns { object } appJson小程序主页配置信息
|
|
1213
|
+
*/
|
|
1151
1214
|
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
fail(`主包 ${subpackage} 不能没有 pages`);
|
|
1155
|
-
process.exit(-1);
|
|
1156
|
-
}
|
|
1215
|
+
function updateMainPackages(appJson, mainPackages = []) {
|
|
1216
|
+
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1157
1217
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1218
|
+
if (foundMainPackages.length === 0) {
|
|
1219
|
+
// 没找到主包
|
|
1220
|
+
foundMainPackages = [appJson.subpackages[0]];
|
|
1221
|
+
} // 拼装 app.pages
|
|
1161
1222
|
|
|
1162
|
-
if (subpackage.plugins) {
|
|
1163
|
-
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1164
|
-
}
|
|
1165
|
-
}); // 去掉 subpackages 中的主包配置
|
|
1166
1223
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
* 获取app.json内容
|
|
1173
|
-
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1174
|
-
* @returns
|
|
1175
|
-
*/
|
|
1224
|
+
foundMainPackages.forEach(subpackage => {
|
|
1225
|
+
if (!subpackage.pages || !subpackage.pages.length) {
|
|
1226
|
+
fail$7(`主包 ${subpackage} 不能没有 pages`);
|
|
1227
|
+
process.exit(-1);
|
|
1228
|
+
}
|
|
1176
1229
|
|
|
1230
|
+
subpackage.pages.forEach(page => {
|
|
1231
|
+
appJson.pages.push(`${subpackage.root}/${page}`);
|
|
1232
|
+
});
|
|
1177
1233
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
fail(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1181
|
-
process.exit(1);
|
|
1234
|
+
if (subpackage.plugins) {
|
|
1235
|
+
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1182
1236
|
}
|
|
1237
|
+
}); // 去掉 subpackages 中的主包配置
|
|
1183
1238
|
|
|
1184
|
-
|
|
1239
|
+
const foundMainPackageNames = foundMainPackages.map(item => item.name);
|
|
1240
|
+
appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
|
|
1241
|
+
return appJson;
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* 获取app.json内容
|
|
1245
|
+
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1246
|
+
* @returns
|
|
1247
|
+
*/
|
|
1185
1248
|
|
|
1186
|
-
appJson.subpackages = [];
|
|
1187
|
-
appJson.pages = []; // appJson.plugins = {};
|
|
1188
1249
|
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
* @param {Object} appJson
|
|
1195
|
-
* @param {Object} modulesConfigs
|
|
1196
|
-
*/
|
|
1250
|
+
const getAppJsonContent = sourceAppJsonPath => {
|
|
1251
|
+
if (!fs$c.existsSync(sourceAppJsonPath)) {
|
|
1252
|
+
fail$7(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1253
|
+
process.exit(1);
|
|
1254
|
+
}
|
|
1197
1255
|
|
|
1256
|
+
const appJson = JSON.parse(fs$c.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1198
1257
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1258
|
+
appJson.subpackages = [];
|
|
1259
|
+
appJson.pages = [];
|
|
1260
|
+
return appJson;
|
|
1261
|
+
};
|
|
1262
|
+
/**
|
|
1263
|
+
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1264
|
+
* @param {Object} appJson appjson
|
|
1265
|
+
*/
|
|
1205
1266
|
|
|
1206
|
-
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
1207
|
-
};
|
|
1208
|
-
/**
|
|
1209
|
-
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1210
|
-
* @param {Object} appJson appjson
|
|
1211
|
-
*/
|
|
1212
1267
|
|
|
1268
|
+
const fixAppJson = appJson => {
|
|
1269
|
+
const {
|
|
1270
|
+
subpackages
|
|
1271
|
+
} = appJson;
|
|
1272
|
+
const pluginsMap = {};
|
|
1273
|
+
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1274
|
+
const subps = subpackages.map(subp => {
|
|
1275
|
+
const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList'];
|
|
1276
|
+
const objOfFileType = ['preloadRule'];
|
|
1277
|
+
Object.keys(subp).forEach(key => {
|
|
1278
|
+
if (key === 'plugins') {
|
|
1279
|
+
Object.keys(subp.plugins).forEach(pk => {
|
|
1280
|
+
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
1281
|
+
});
|
|
1282
|
+
} // 分包里数组类型字段,提到appjson最上层
|
|
1213
1283
|
|
|
1214
|
-
const fixAppJson = appJson => {
|
|
1215
|
-
const {
|
|
1216
|
-
subpackages
|
|
1217
|
-
} = appJson;
|
|
1218
|
-
const pluginsMap = {};
|
|
1219
|
-
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1220
|
-
const subps = subpackages.map(subp => {
|
|
1221
|
-
const invalidKeys = [];
|
|
1222
|
-
Object.keys(subp).forEach(key => {
|
|
1223
|
-
if (key === 'dependencies') {
|
|
1224
|
-
// eslint-disable-next-line
|
|
1225
|
-
delete subp.dependencies;
|
|
1226
|
-
return;
|
|
1227
|
-
}
|
|
1228
1284
|
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1285
|
+
if (arrOfFileType.indexOf(key) > -1) {
|
|
1286
|
+
const preVal = appJson[key];
|
|
1287
|
+
preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
1288
|
+
} // 分包里对象类型字段,提到appjson最上层
|
|
1235
1289
|
|
|
1236
|
-
if (MODULE_CONFIG_INVALID_KEY.indexOf(key) > -1) {
|
|
1237
|
-
// 如果分包配置中有不支持的key,则错误提醒
|
|
1238
|
-
invalidKeys.push(key);
|
|
1239
|
-
return;
|
|
1240
|
-
}
|
|
1241
1290
|
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
if (invalidKeys.length) {
|
|
1251
|
-
fail(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
1291
|
+
if (objOfFileType.indexOf(key) > -1) {
|
|
1292
|
+
const preloadRuleMap = appJson[key] || {};
|
|
1293
|
+
subp[key] && Object.keys(subp[key]).forEach(page => {
|
|
1294
|
+
if (!preloadRuleMap[page]) {
|
|
1295
|
+
preloadRuleMap[page] = subp[key][page];
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
appJson[key] = preloadRuleMap;
|
|
1252
1299
|
}
|
|
1300
|
+
});
|
|
1301
|
+
return filterField$3(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
|
|
1302
|
+
}); // 如果plugins重复,则错误提示
|
|
1253
1303
|
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
1259
|
-
if (pluginsMap[pk].length > 1) {
|
|
1260
|
-
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
1261
|
-
}
|
|
1304
|
+
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
1305
|
+
if (pluginsMap[pk].length > 1) {
|
|
1306
|
+
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
1307
|
+
}
|
|
1262
1308
|
|
|
1263
|
-
|
|
1264
|
-
|
|
1309
|
+
return '';
|
|
1310
|
+
}).reduce((pre, cur) => pre + cur, '');
|
|
1265
1311
|
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1312
|
+
if (pluginsErrMsg) {
|
|
1313
|
+
throw new Error(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1314
|
+
}
|
|
1269
1315
|
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1316
|
+
appJson.subpackages = subps;
|
|
1317
|
+
};
|
|
1318
|
+
/**
|
|
1319
|
+
* 动态生成编译后的app.json
|
|
1320
|
+
* @param {object} tmsConfig
|
|
1321
|
+
* @param {array} modules 用户要编译的模块列表
|
|
1322
|
+
* @returns
|
|
1323
|
+
*/
|
|
1278
1324
|
|
|
1279
1325
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1326
|
+
function buildOutputAppJson$2(tmsConfig, modules) {
|
|
1327
|
+
try {
|
|
1328
|
+
var _tmsConfig$hooks;
|
|
1283
1329
|
|
|
1284
|
-
|
|
1285
|
-
|
|
1330
|
+
// 获取所有模块,合并模块依赖的模块
|
|
1331
|
+
const modulesConfig = getModulesConfig(modules, tmsConfig.appName, false); // 获取所有的分包
|
|
1286
1332
|
|
|
1287
|
-
|
|
1333
|
+
const subPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
|
|
1288
1334
|
|
|
1289
|
-
|
|
1335
|
+
const appJson = getAppJsonContent(resolve$c('./app.json')); // 更新app.json中的subpackages
|
|
1290
1336
|
|
|
1291
|
-
|
|
1337
|
+
appJson.subpackages = subPackages;
|
|
1338
|
+
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name)); // 处理appJson中重复||冲突的地方
|
|
1292
1339
|
|
|
1293
|
-
|
|
1294
|
-
fs.writeFileSync(resolve(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1340
|
+
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1295
1341
|
|
|
1296
|
-
|
|
1297
|
-
|
|
1342
|
+
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1343
|
+
fs$c.writeFileSync(resolve$c(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1298
1344
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
module,
|
|
1302
|
-
appJson,
|
|
1303
|
-
isDev: global.getData('isDev')
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1345
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1346
|
+
var _tmsConfig$hooks2;
|
|
1306
1347
|
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1348
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1349
|
+
tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
|
|
1350
|
+
modules,
|
|
1351
|
+
appJson,
|
|
1352
|
+
isDev: global$4.getData('isDev')
|
|
1353
|
+
});
|
|
1310
1354
|
}
|
|
1355
|
+
|
|
1356
|
+
return appJson;
|
|
1357
|
+
} catch (e) {
|
|
1358
|
+
handleError$5(`生成app.json出现错误: ${e}`);
|
|
1359
|
+
info$9(e);
|
|
1311
1360
|
}
|
|
1361
|
+
}
|
|
1312
1362
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
})(buildAppJson);
|
|
1363
|
+
var buildAppJson = {
|
|
1364
|
+
buildOutputAppJson: buildOutputAppJson$2
|
|
1365
|
+
};
|
|
1317
1366
|
|
|
1318
1367
|
/**
|
|
1319
1368
|
* 下载第三方代码
|
|
1320
1369
|
*/
|
|
1321
1370
|
const MetalSmith = require$$0__default$5;
|
|
1322
|
-
const crypto$
|
|
1371
|
+
const crypto$2 = require$$1__default$5;
|
|
1323
1372
|
const {
|
|
1324
1373
|
downloadRepoForGit,
|
|
1325
1374
|
pullRepoForGit,
|
|
1326
|
-
resolve: resolve$
|
|
1375
|
+
resolve: resolve$b
|
|
1327
1376
|
} = widgets;
|
|
1328
1377
|
const {
|
|
1329
|
-
fail: fail$
|
|
1330
|
-
info: info$
|
|
1378
|
+
fail: fail$6,
|
|
1379
|
+
info: info$8
|
|
1331
1380
|
} = log$1;
|
|
1332
|
-
const fs$
|
|
1381
|
+
const fs$b = require$$0__default$2;
|
|
1333
1382
|
const shelljs$5 = require$$0__default$3;
|
|
1334
1383
|
const {
|
|
1335
1384
|
handleError: handleError$4
|
|
1336
1385
|
} = handleError_1;
|
|
1337
1386
|
const {
|
|
1338
|
-
global: global$
|
|
1387
|
+
global: global$3
|
|
1339
1388
|
} = global_1;
|
|
1340
1389
|
/**
|
|
1341
1390
|
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
@@ -1345,15 +1394,15 @@ const {
|
|
|
1345
1394
|
*/
|
|
1346
1395
|
|
|
1347
1396
|
function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
1348
|
-
var
|
|
1397
|
+
var _tmsConfig$gitAccount;
|
|
1349
1398
|
|
|
1350
1399
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1351
|
-
const
|
|
1400
|
+
const tmsConfig = global$3.getData('tmsConfig');
|
|
1352
1401
|
let gitUrl = httpRepoUrl;
|
|
1353
1402
|
const {
|
|
1354
1403
|
username = '',
|
|
1355
1404
|
pass = ''
|
|
1356
|
-
} = (
|
|
1405
|
+
} = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
|
|
1357
1406
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
1358
1407
|
|
|
1359
1408
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -1376,7 +1425,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1376
1425
|
return new Promise((resolve, reject) => {
|
|
1377
1426
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1378
1427
|
if (e) {
|
|
1379
|
-
fail$
|
|
1428
|
+
fail$6(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1380
1429
|
reject(e);
|
|
1381
1430
|
}
|
|
1382
1431
|
|
|
@@ -1394,7 +1443,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1394
1443
|
|
|
1395
1444
|
function md5ByGitUrlBranch(gitUrl, branch) {
|
|
1396
1445
|
const newBranch = branch && typeof branch === 'string' ? branch : 'master';
|
|
1397
|
-
return crypto$
|
|
1446
|
+
return crypto$2.createHash('md5').update(JSON.stringify({
|
|
1398
1447
|
gitUrl,
|
|
1399
1448
|
branch: newBranch
|
|
1400
1449
|
})).digest('hex');
|
|
@@ -1463,16 +1512,16 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1463
1512
|
path: gitPath = ''
|
|
1464
1513
|
},
|
|
1465
1514
|
path,
|
|
1466
|
-
|
|
1515
|
+
moduleName
|
|
1467
1516
|
} = moduleInfo; // 处理仓库权限问题
|
|
1468
1517
|
|
|
1469
|
-
const gitUrl = replaceGitUrlAccount(httpRepoUrl,
|
|
1518
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName); // 根据gitUrl与branch计算md5
|
|
1470
1519
|
|
|
1471
1520
|
const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
|
|
1472
1521
|
|
|
1473
|
-
const sourcePath = resolve$
|
|
1522
|
+
const sourcePath = resolve$b(sourceDir, md5Key); // 模块源码要放到目标目录
|
|
1474
1523
|
|
|
1475
|
-
const targetPath = resolve$
|
|
1524
|
+
const targetPath = resolve$b(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
|
|
1476
1525
|
|
|
1477
1526
|
const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
|
|
1478
1527
|
|
|
@@ -1482,7 +1531,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1482
1531
|
targetPath
|
|
1483
1532
|
},
|
|
1484
1533
|
fn: async (sourceModulePath, targetPath) => {
|
|
1485
|
-
if (fs$
|
|
1534
|
+
if (fs$b.existsSync(targetPath)) {
|
|
1486
1535
|
shelljs$5.rm('-rf', `${targetPath}/*`);
|
|
1487
1536
|
}
|
|
1488
1537
|
|
|
@@ -1497,14 +1546,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1497
1546
|
} else {
|
|
1498
1547
|
let promiseTask;
|
|
1499
1548
|
|
|
1500
|
-
if (fs$
|
|
1549
|
+
if (fs$b.existsSync(sourcePath) && fs$b.existsSync(`${sourcePath}/.git`)) {
|
|
1501
1550
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1502
|
-
info$
|
|
1551
|
+
info$8(`git pull:${httpRepoUrl}`);
|
|
1503
1552
|
return pullRepoForGit(sourcePath, branch);
|
|
1504
1553
|
};
|
|
1505
1554
|
} else {
|
|
1506
1555
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1507
|
-
info$
|
|
1556
|
+
info$8(`git clone: ${httpRepoUrl}`);
|
|
1508
1557
|
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
1509
1558
|
};
|
|
1510
1559
|
}
|
|
@@ -1540,12 +1589,12 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
|
1540
1589
|
buildGitTag,
|
|
1541
1590
|
httpRepoUrl
|
|
1542
1591
|
},
|
|
1543
|
-
|
|
1592
|
+
moduleName
|
|
1544
1593
|
} = moduleInfo;
|
|
1545
|
-
const gitUrl = replaceGitUrlAccount(httpRepoUrl,
|
|
1594
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
|
|
1546
1595
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1547
1596
|
|
|
1548
|
-
if (!fs$
|
|
1597
|
+
if (!fs$b.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1549
1598
|
return true;
|
|
1550
1599
|
}
|
|
1551
1600
|
}
|
|
@@ -1559,7 +1608,7 @@ var cloneModules_1 = {
|
|
|
1559
1608
|
};
|
|
1560
1609
|
|
|
1561
1610
|
const ci = require$$0__default$7;
|
|
1562
|
-
const path$
|
|
1611
|
+
const path$a = require$$1__default$2;
|
|
1563
1612
|
/**
|
|
1564
1613
|
* 获取小程序ci的Project对象
|
|
1565
1614
|
* @returns {Object} 小程序ci对象
|
|
@@ -1573,7 +1622,7 @@ const getMpCi = ({
|
|
|
1573
1622
|
}) => {
|
|
1574
1623
|
var _cfgJsonContent$packO;
|
|
1575
1624
|
|
|
1576
|
-
const cfgJsonContent = require(path$
|
|
1625
|
+
const cfgJsonContent = require(path$a.join(projectPath, 'project.config.json'));
|
|
1577
1626
|
|
|
1578
1627
|
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
1579
1628
|
value
|
|
@@ -1639,18 +1688,68 @@ var mpCi = {
|
|
|
1639
1688
|
buildMpNpm: buildMpNpm$1
|
|
1640
1689
|
};
|
|
1641
1690
|
|
|
1691
|
+
const fs$a = require$$0__default$2;
|
|
1692
|
+
const path$9 = require$$1__default$2;
|
|
1693
|
+
const {
|
|
1694
|
+
CACHE_FILE,
|
|
1695
|
+
CACHE_DIR: CACHE_DIR$2
|
|
1696
|
+
} = require$$4;
|
|
1697
|
+
const {
|
|
1698
|
+
ensureDirExist: ensureDirExist$1
|
|
1699
|
+
} = io$3;
|
|
1700
|
+
|
|
1701
|
+
function getCache$1(projectDir, type) {
|
|
1702
|
+
var _content$projectDir;
|
|
1703
|
+
|
|
1704
|
+
const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
|
|
1705
|
+
|
|
1706
|
+
if (!fs$a.existsSync(filePath)) {
|
|
1707
|
+
return null;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
const content = require(filePath);
|
|
1711
|
+
|
|
1712
|
+
return content === null || content === void 0 ? void 0 : (_content$projectDir = content[projectDir]) === null || _content$projectDir === void 0 ? void 0 : _content$projectDir[type];
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
function setCache$1(projectDir, type = 'miniprogram_npm', data) {
|
|
1716
|
+
const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
|
|
1717
|
+
|
|
1718
|
+
if (!fs$a.existsSync(filePath)) {
|
|
1719
|
+
const dir = path$9.dirname(filePath);
|
|
1720
|
+
ensureDirExist$1(dir);
|
|
1721
|
+
fs$a.writeFileSync(filePath, '{}');
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
const content = require(filePath);
|
|
1725
|
+
|
|
1726
|
+
if (!content[projectDir]) {
|
|
1727
|
+
content[projectDir] = {};
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
content[projectDir] = {
|
|
1731
|
+
[type]: data
|
|
1732
|
+
};
|
|
1733
|
+
fs$a.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
var cache = {
|
|
1737
|
+
setCache: setCache$1,
|
|
1738
|
+
getCache: getCache$1
|
|
1739
|
+
};
|
|
1740
|
+
|
|
1642
1741
|
/**
|
|
1643
1742
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1644
1743
|
*/
|
|
1645
|
-
const fs$
|
|
1744
|
+
const fs$9 = require$$0__default$2;
|
|
1646
1745
|
const fsExtra = require$$1__default$6;
|
|
1647
|
-
const crypto = require$$1__default$5;
|
|
1648
|
-
const path$
|
|
1746
|
+
const crypto$1 = require$$1__default$5;
|
|
1747
|
+
const path$8 = require$$1__default$2;
|
|
1649
1748
|
const shell = require$$0__default$3;
|
|
1650
|
-
const glob = require$$
|
|
1749
|
+
const glob = require$$6__default;
|
|
1651
1750
|
const log = log$1;
|
|
1652
1751
|
const {
|
|
1653
|
-
npmInstall
|
|
1752
|
+
npmInstall: npmInstall$1
|
|
1654
1753
|
} = widgets;
|
|
1655
1754
|
const {
|
|
1656
1755
|
handleError: handleError$3
|
|
@@ -1677,22 +1776,29 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1677
1776
|
const npmTasksMap = new Map();
|
|
1678
1777
|
|
|
1679
1778
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1680
|
-
const packageContent = fs$
|
|
1681
|
-
|
|
1779
|
+
const packageContent = fs$9.readFileSync(packageJsonPath);
|
|
1780
|
+
let packageJson;
|
|
1781
|
+
|
|
1782
|
+
try {
|
|
1783
|
+
packageJson = JSON.parse(packageContent);
|
|
1784
|
+
} catch (e) {
|
|
1785
|
+
throw new Error(`${packageJsonPath}json解析出现错误:${e}`);
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1682
1788
|
const md5Obj = {
|
|
1683
1789
|
dependencies: packageJson.dependencies || {}
|
|
1684
1790
|
};
|
|
1685
1791
|
|
|
1686
1792
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1687
|
-
const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1688
|
-
const cacheNMPath = path$
|
|
1689
|
-
const cacheNMTarFile = path$
|
|
1793
|
+
const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1794
|
+
const cacheNMPath = path$8.join(cacheDir, md5Key);
|
|
1795
|
+
const cacheNMTarFile = path$8.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1690
1796
|
|
|
1691
1797
|
const callback = {
|
|
1692
1798
|
params: {
|
|
1693
1799
|
cacheNMPath,
|
|
1694
1800
|
cacheNMTarFile,
|
|
1695
|
-
packageJsonDir: path$
|
|
1801
|
+
packageJsonDir: path$8.dirname(packageJsonPath),
|
|
1696
1802
|
shell
|
|
1697
1803
|
},
|
|
1698
1804
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
@@ -1721,7 +1827,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1721
1827
|
fsExtra.emptydirSync(cacheNMPath);
|
|
1722
1828
|
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
1723
1829
|
log.info(`npm install: ${packageJsonPath}`);
|
|
1724
|
-
return npmInstall(cacheNMPath).then(() => {
|
|
1830
|
+
return npmInstall$1(cacheNMPath).then(() => {
|
|
1725
1831
|
const newShellJsOption = { ...shellJsOption,
|
|
1726
1832
|
cwd: cacheNMPath
|
|
1727
1833
|
};
|
|
@@ -1749,7 +1855,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1749
1855
|
}; // 遍历安装指定目录下所有项目的npm依赖
|
|
1750
1856
|
|
|
1751
1857
|
|
|
1752
|
-
const
|
|
1858
|
+
const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
1753
1859
|
const cwd = process.cwd();
|
|
1754
1860
|
const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
|
|
1755
1861
|
|
|
@@ -1768,11 +1874,12 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
|
1768
1874
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1769
1875
|
return Promise.all(callArr);
|
|
1770
1876
|
}).catch(e => {
|
|
1771
|
-
handleError$3(`npm install ${params.packageJsonPath}出现错误:${e}
|
|
1877
|
+
handleError$3(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
|
|
1772
1878
|
}));
|
|
1773
1879
|
});
|
|
1774
1880
|
await Promise.all(arrPromises);
|
|
1775
1881
|
shell.cd(cwd);
|
|
1882
|
+
return packageJsonFiles;
|
|
1776
1883
|
};
|
|
1777
1884
|
/**
|
|
1778
1885
|
* 递归查找指定条件的文件
|
|
@@ -1793,7 +1900,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1793
1900
|
|
|
1794
1901
|
const find = (startPath, filter) => {
|
|
1795
1902
|
// 目录不存在
|
|
1796
|
-
if (!fs$
|
|
1903
|
+
if (!fs$9.existsSync(startPath)) {
|
|
1797
1904
|
log.fail(`${startPath}目录不存在`);
|
|
1798
1905
|
process.exit(-1);
|
|
1799
1906
|
return;
|
|
@@ -1806,10 +1913,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1806
1913
|
return;
|
|
1807
1914
|
}
|
|
1808
1915
|
|
|
1809
|
-
const files = fs$
|
|
1916
|
+
const files = fs$9.readdirSync(startPath);
|
|
1810
1917
|
files.forEach(file => {
|
|
1811
|
-
const filename = path$
|
|
1812
|
-
const stat = fs$
|
|
1918
|
+
const filename = path$8.join(startPath, file);
|
|
1919
|
+
const stat = fs$9.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1813
1920
|
|
|
1814
1921
|
if (stat.isDirectory()) {
|
|
1815
1922
|
find(filename, filter);
|
|
@@ -1835,7 +1942,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1835
1942
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1836
1943
|
|
|
1837
1944
|
const cwd = contextDir || dirPath;
|
|
1838
|
-
const result = [path$
|
|
1945
|
+
const result = [path$8.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1839
1946
|
|
|
1840
1947
|
subRoots.forEach(subRoot => {
|
|
1841
1948
|
if (!subRoot.root) {
|
|
@@ -1843,7 +1950,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1843
1950
|
process.exit(1);
|
|
1844
1951
|
}
|
|
1845
1952
|
|
|
1846
|
-
const toppath = path$
|
|
1953
|
+
const toppath = path$8.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1847
1954
|
|
|
1848
1955
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1849
1956
|
result.push(...list);
|
|
@@ -1859,7 +1966,7 @@ function cloudNpmInstall(contextDir) {
|
|
|
1859
1966
|
}
|
|
1860
1967
|
|
|
1861
1968
|
files.forEach(file => {
|
|
1862
|
-
const dir = path$
|
|
1969
|
+
const dir = path$8.dirname(file);
|
|
1863
1970
|
shell.cd(dir);
|
|
1864
1971
|
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1865
1972
|
silent: false
|
|
@@ -1872,12 +1979,147 @@ function cloudNpmInstall(contextDir) {
|
|
|
1872
1979
|
|
|
1873
1980
|
var npm = {
|
|
1874
1981
|
cloudNpmInstall,
|
|
1875
|
-
|
|
1982
|
+
npmInstallAll: npmInstallAll$1,
|
|
1876
1983
|
findAllPackageJson
|
|
1877
1984
|
};
|
|
1878
1985
|
|
|
1986
|
+
const crypto = require$$1__default$5;
|
|
1987
|
+
const fs$8 = require$$0__default$2;
|
|
1988
|
+
|
|
1989
|
+
function fileMd5$1(filePath) {
|
|
1990
|
+
return new Promise((resolve, reject) => {
|
|
1991
|
+
const md5sum = crypto.createHash('md5');
|
|
1992
|
+
const stream = fs$8.ReadStream(filePath);
|
|
1993
|
+
stream.on('data', d => {
|
|
1994
|
+
md5sum.update(d);
|
|
1995
|
+
});
|
|
1996
|
+
stream.on('error', err => {
|
|
1997
|
+
reject(err);
|
|
1998
|
+
});
|
|
1999
|
+
stream.on('end', () => {
|
|
2000
|
+
const hash = md5sum.digest('hex');
|
|
2001
|
+
resolve(hash);
|
|
2002
|
+
});
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
var md5 = {
|
|
2007
|
+
fileMd5: fileMd5$1
|
|
2008
|
+
};
|
|
2009
|
+
|
|
2010
|
+
const fs$7 = require$$0__default$2;
|
|
2011
|
+
const semver$1 = require$$1__default$7;
|
|
2012
|
+
const {
|
|
2013
|
+
resolve: resolve$a
|
|
2014
|
+
} = widgets;
|
|
2015
|
+
const path$7 = require$$1__default$2;
|
|
1879
2016
|
const shelljs$4 = require$$0__default$3;
|
|
2017
|
+
const {
|
|
2018
|
+
handleError: handleError$2
|
|
2019
|
+
} = handleError_1;
|
|
2020
|
+
|
|
2021
|
+
const getLatestVersion = npmName => {
|
|
2022
|
+
const data = shelljs$4.exec(`npm view ${npmName} version`);
|
|
2023
|
+
return data.stdout || '0.0.0';
|
|
2024
|
+
}; // 收集package.json
|
|
2025
|
+
|
|
2026
|
+
|
|
2027
|
+
function collectHasPackageJson(modules, cwd, outputDir) {
|
|
2028
|
+
const packageJsonName = 'package.json'; // 查找文件名
|
|
2029
|
+
// 1.1根目录的package.json
|
|
2030
|
+
|
|
2031
|
+
const packageArr = [{
|
|
2032
|
+
srcPackageDir: path$7.join(cwd, packageJsonName),
|
|
2033
|
+
destNpmDir: resolve$a(outputDir, 'node_modules')
|
|
2034
|
+
}]; // 1.2模块的package.json
|
|
2035
|
+
|
|
2036
|
+
modules.forEach(item => {
|
|
2037
|
+
const srcPackageDir = path$7.join(cwd, item.path, 'package.json');
|
|
2038
|
+
|
|
2039
|
+
if (fs$7.existsSync(srcPackageDir)) {
|
|
2040
|
+
packageArr.push({
|
|
2041
|
+
srcPackageDir,
|
|
2042
|
+
destNpmDir: resolve$a(outputDir, item.root, 'node_modules')
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
return packageArr;
|
|
2047
|
+
} // 读取package.json的依赖
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
function readPackageDependencies(srcPackageDir) {
|
|
2051
|
+
const packageJson = fs$7.readFileSync(srcPackageDir, 'utf-8');
|
|
2052
|
+
let dependencies = {};
|
|
2053
|
+
|
|
2054
|
+
try {
|
|
2055
|
+
const json = packageJson ? JSON.parse(packageJson) : {};
|
|
2056
|
+
dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
|
|
2057
|
+
} catch (e) {
|
|
2058
|
+
handleError$2(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
return dependencies;
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
2065
|
+
* @param {*} modules 模块
|
|
2066
|
+
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
2067
|
+
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
2068
|
+
* @returns
|
|
2069
|
+
*/
|
|
2070
|
+
|
|
2071
|
+
|
|
2072
|
+
const isDependenciesUpdate$1 = (modules, cwd, outputDir) => {
|
|
2073
|
+
// 步骤1. 收集package.json
|
|
2074
|
+
const packageArr = collectHasPackageJson(modules, cwd, outputDir); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
2075
|
+
|
|
2076
|
+
return checkPackageVersion$1(packageArr);
|
|
2077
|
+
}; // 比较package.json的依赖与node_modules依赖的版本号
|
|
2078
|
+
|
|
2079
|
+
|
|
2080
|
+
const checkPackageVersion$1 = packageArr => {
|
|
2081
|
+
for (const item of packageArr) {
|
|
2082
|
+
const dependencies = readPackageDependencies(item.srcPackageDir);
|
|
2083
|
+
const dependenciesKeys = Object.keys(dependencies);
|
|
2084
|
+
|
|
2085
|
+
for (const key of dependenciesKeys) {
|
|
2086
|
+
const depPath = path$7.join(item.destNpmDir, key);
|
|
2087
|
+
|
|
2088
|
+
if (!fs$7.existsSync(depPath)) {
|
|
2089
|
+
return true;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
const depPackagePath = path$7.join(depPath, 'package.json');
|
|
2093
|
+
|
|
2094
|
+
if (fs$7.existsSync(depPackagePath)) {
|
|
2095
|
+
const packageData = require(depPackagePath);
|
|
2096
|
+
|
|
2097
|
+
if (dependencies[key] === 'latest') {
|
|
2098
|
+
dependencies[key] = getLatestVersion(key);
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
if (packageData.version === 'latest') {
|
|
2102
|
+
packageData.version = getLatestVersion(key);
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
|
|
2106
|
+
return true;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
return false;
|
|
2113
|
+
};
|
|
2114
|
+
|
|
2115
|
+
var checkDependencies = {
|
|
2116
|
+
isDependenciesUpdate: isDependenciesUpdate$1,
|
|
2117
|
+
checkPackageVersion: checkPackageVersion$1
|
|
2118
|
+
};
|
|
2119
|
+
|
|
2120
|
+
const shelljs$3 = require$$0__default$3;
|
|
1880
2121
|
const fs$6 = require$$0__default$2;
|
|
2122
|
+
const path$6 = require$$1__default$2;
|
|
1881
2123
|
const io$1 = io$3;
|
|
1882
2124
|
const {
|
|
1883
2125
|
createTask: createTask$1,
|
|
@@ -1886,167 +2128,189 @@ const {
|
|
|
1886
2128
|
const {
|
|
1887
2129
|
buildMpNpm
|
|
1888
2130
|
} = mpCi;
|
|
2131
|
+
const {
|
|
2132
|
+
setCache,
|
|
2133
|
+
getCache
|
|
2134
|
+
} = cache;
|
|
1889
2135
|
const {
|
|
1890
2136
|
CACHE_DIR: CACHE_DIR$1
|
|
1891
2137
|
} = require$$4;
|
|
1892
2138
|
const {
|
|
1893
|
-
|
|
2139
|
+
npmInstallAll
|
|
1894
2140
|
} = npm;
|
|
1895
2141
|
const {
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
const {
|
|
1899
|
-
fail: fail$3
|
|
2142
|
+
fail: fail$5,
|
|
2143
|
+
info: info$7
|
|
1900
2144
|
} = log$1;
|
|
2145
|
+
const {
|
|
2146
|
+
fileMd5
|
|
2147
|
+
} = md5;
|
|
2148
|
+
const {
|
|
2149
|
+
isDependenciesUpdate
|
|
2150
|
+
} = checkDependencies;
|
|
2151
|
+
|
|
2152
|
+
async function install$2(tmsConfig, modules, useCache = true) {
|
|
2153
|
+
const cwd = process.cwd();
|
|
2154
|
+
const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, modules, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
|
|
2155
|
+
|
|
2156
|
+
if (!npmInstallRes.isCache) {
|
|
2157
|
+
// 构建miniprogram_npm, 不使用缓存
|
|
2158
|
+
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, modules, false);
|
|
2159
|
+
} else {
|
|
2160
|
+
// 构建miniprogram_npm
|
|
2161
|
+
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, modules, useCache);
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
shelljs$3.cd(cwd);
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
async function npmInstall(tmsConfig, modules, useCache) {
|
|
2168
|
+
// 如果依赖没有更新和使用缓存数据(则命中缓存)
|
|
2169
|
+
if (!isDependenciesUpdate(modules, resolve$9('./'), tmsConfig.outputDir) && useCache) {
|
|
2170
|
+
info$7('node_modules命中缓存');
|
|
2171
|
+
return {
|
|
2172
|
+
isCache: true
|
|
2173
|
+
};
|
|
2174
|
+
} // 拷贝模块的package.json到编译输出目录
|
|
2175
|
+
|
|
1901
2176
|
|
|
1902
|
-
async function install$2(tmsConfig, modules) {
|
|
1903
|
-
// 拷贝模块的package.json到编译输出目录
|
|
1904
2177
|
modules.forEach(item => {
|
|
1905
2178
|
const outputModuleDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
|
|
1906
2179
|
|
|
1907
2180
|
if (!fs$6.existsSync(resolve$9(item.path))) {
|
|
1908
|
-
fail$
|
|
2181
|
+
fail$5(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1909
2182
|
process.exit(1);
|
|
1910
2183
|
}
|
|
1911
2184
|
|
|
1912
2185
|
io$1.ensureDirExist(outputModuleDir);
|
|
1913
2186
|
const modulePackagePath = resolve$9(item.path, 'package.json');
|
|
1914
|
-
if (fs$6.existsSync(modulePackagePath)) shelljs$
|
|
1915
|
-
}); // 小程序npm install
|
|
1916
|
-
|
|
1917
|
-
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
1918
|
-
const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1919
|
-
|
|
1920
|
-
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1921
|
-
appId: tmsConfig.appId,
|
|
1922
|
-
projectPath: resolve$9('./'),
|
|
1923
|
-
privateKey: tmsPrivateCf.privateKey
|
|
2187
|
+
if (fs$6.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1924
2188
|
});
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
const semver$1 = require$$1__default$7;
|
|
1931
|
-
const {
|
|
1932
|
-
resolve: resolve$8
|
|
1933
|
-
} = widgets;
|
|
1934
|
-
const path$5 = require$$1__default$2;
|
|
1935
|
-
const shelljs$3 = require$$0__default$3;
|
|
1936
|
-
const {
|
|
1937
|
-
handleError: handleError$2
|
|
1938
|
-
} = handleError_1;
|
|
1939
|
-
|
|
1940
|
-
const getLatestVersion = npmName => {
|
|
1941
|
-
const data = shelljs$3.exec(`npm view ${npmName} version`);
|
|
1942
|
-
return data.stdout || '0.0.0';
|
|
1943
|
-
};
|
|
1944
|
-
/**
|
|
1945
|
-
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
1946
|
-
* @param {*} modules 模块
|
|
1947
|
-
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
1948
|
-
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
1949
|
-
* @returns
|
|
1950
|
-
*/
|
|
2189
|
+
await npmInstallAll(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
2190
|
+
return {
|
|
2191
|
+
isCache: false
|
|
2192
|
+
};
|
|
2193
|
+
} // 构建miniprogram_npm
|
|
1951
2194
|
|
|
1952
2195
|
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
const
|
|
1956
|
-
// 1.1根目录的package.json
|
|
2196
|
+
async function mpCiInstall(tmsConfig, modules, useCache) {
|
|
2197
|
+
const packageJsonFiles = [];
|
|
2198
|
+
const rootPackFile = resolve$9(`${tmsConfig.outputDir}/package.json`);
|
|
1957
2199
|
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
}]; // 1.2模块的package.json
|
|
2200
|
+
if (fs$6.existsSync(rootPackFile)) {
|
|
2201
|
+
packageJsonFiles.push(rootPackFile);
|
|
2202
|
+
}
|
|
1962
2203
|
|
|
1963
2204
|
modules.forEach(item => {
|
|
1964
|
-
const
|
|
1965
|
-
|
|
1966
|
-
if (fs$5.existsSync(srcPackageDir)) {
|
|
1967
|
-
packageArr.push({
|
|
1968
|
-
srcPackageDir,
|
|
1969
|
-
destNpmDir: resolve$8(outputDir, item.root, 'node_modules')
|
|
1970
|
-
});
|
|
1971
|
-
}
|
|
1972
|
-
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1973
|
-
|
|
1974
|
-
for (const item of packageArr) {
|
|
1975
|
-
const packageJson = fs$5.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1976
|
-
let dependencies = {};
|
|
2205
|
+
const packageJsonFile = resolve$9(`${tmsConfig.outputDir}/${item.root}/package.json`);
|
|
1977
2206
|
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
1981
|
-
} catch (e) {
|
|
1982
|
-
handleError$2(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
2207
|
+
if (fs$6.existsSync(packageJsonFile)) {
|
|
2208
|
+
packageJsonFiles.push(packageJsonFile);
|
|
1983
2209
|
}
|
|
2210
|
+
});
|
|
2211
|
+
let isCache = false;
|
|
2212
|
+
const statusMap = {
|
|
2213
|
+
success: 1,
|
|
2214
|
+
doing: 2
|
|
2215
|
+
};
|
|
1984
2216
|
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
const
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
2217
|
+
if (useCache) {
|
|
2218
|
+
let flag = true;
|
|
2219
|
+
await Promise.all(packageJsonFiles.map(async item => {
|
|
2220
|
+
const packageDir = path$6.dirname(item);
|
|
2221
|
+
const mpDir = resolve$9(`${packageDir}/miniprogram_npm`);
|
|
2222
|
+
const md5Value = await getMNPMd5(packageDir);
|
|
2223
|
+
const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
|
|
2224
|
+
// 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
|
|
2225
|
+
|
|
2226
|
+
if ((preCache === null || preCache === void 0 ? void 0 : preCache.status) !== statusMap.success || (preCache === null || preCache === void 0 ? void 0 : preCache.md5) !== md5Value) {
|
|
2227
|
+
flag = false;
|
|
1992
2228
|
}
|
|
2229
|
+
}));
|
|
2230
|
+
isCache = flag;
|
|
2231
|
+
}
|
|
1993
2232
|
|
|
1994
|
-
|
|
2233
|
+
if (isCache) {
|
|
2234
|
+
info$7('miniprogram_npm命中缓存');
|
|
2235
|
+
return;
|
|
2236
|
+
} // 即将构建,在cache中标记开始
|
|
1995
2237
|
|
|
1996
|
-
if (fs$5.existsSync(depPackagePath)) {
|
|
1997
|
-
const packageData = require(depPackagePath);
|
|
1998
2238
|
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2239
|
+
await Promise.all(packageJsonFiles.map(async item => {
|
|
2240
|
+
const packageDir = path$6.dirname(item);
|
|
2241
|
+
const mpDir = resolve$9(`${packageDir}/miniprogram_npm`);
|
|
2242
|
+
setCache(mpDir, 'miniprogram_npm', {
|
|
2243
|
+
md5: '',
|
|
2244
|
+
status: statusMap.doing
|
|
2245
|
+
});
|
|
2246
|
+
}));
|
|
2247
|
+
await buildMpNpm({
|
|
2248
|
+
appId: tmsConfig.appId,
|
|
2249
|
+
projectPath: resolve$9('./'),
|
|
2250
|
+
privateKey: tmsConfig.privateKey
|
|
2251
|
+
}); // 构建成功后,计算md5写入cache
|
|
2252
|
+
|
|
2253
|
+
await Promise.all(packageJsonFiles.map(async item => {
|
|
2254
|
+
const packageDir = path$6.dirname(item);
|
|
2255
|
+
const mpDir = resolve$9(`${packageDir}/miniprogram_npm`);
|
|
2256
|
+
const md5Value = await getMNPMd5(packageDir);
|
|
2257
|
+
setCache(mpDir, 'miniprogram_npm', {
|
|
2258
|
+
md5: md5Value,
|
|
2259
|
+
status: statusMap.success
|
|
2260
|
+
});
|
|
2261
|
+
}));
|
|
2262
|
+
} // 计算miniprogram_npm压缩文件的md5值
|
|
2002
2263
|
|
|
2003
|
-
if (packageData.version === 'latest') {
|
|
2004
|
-
packageData.version = getLatestVersion(key);
|
|
2005
|
-
}
|
|
2006
2264
|
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2265
|
+
async function getMNPMd5(cwd) {
|
|
2266
|
+
const shellJsOption = {
|
|
2267
|
+
async: false,
|
|
2268
|
+
silent: true
|
|
2269
|
+
};
|
|
2270
|
+
shelljs$3.cd(cwd);
|
|
2271
|
+
|
|
2272
|
+
if (fs$6.existsSync('miniprogram_npm')) {
|
|
2273
|
+
shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
|
|
2274
|
+
cwd,
|
|
2275
|
+
...shellJsOption
|
|
2276
|
+
});
|
|
2277
|
+
const tarDir = path$6.join(cwd, './miniprogram_npm.tar.gz');
|
|
2278
|
+
const md5Value = await fileMd5(tarDir);
|
|
2279
|
+
shelljs$3.rm('-rf', tarDir);
|
|
2280
|
+
return md5Value;
|
|
2012
2281
|
}
|
|
2013
2282
|
|
|
2014
|
-
return
|
|
2015
|
-
}
|
|
2283
|
+
return '';
|
|
2284
|
+
}
|
|
2016
2285
|
|
|
2017
|
-
var
|
|
2018
|
-
checkDependencies: checkDependencies$1
|
|
2019
|
-
};
|
|
2286
|
+
var install_1 = install$2;
|
|
2020
2287
|
|
|
2021
2288
|
const shelljs$2 = require$$0__default$3;
|
|
2022
|
-
const fs$
|
|
2289
|
+
const fs$5 = require$$0__default$2;
|
|
2023
2290
|
const io = io$3;
|
|
2024
2291
|
const {
|
|
2025
|
-
resolve: resolve$
|
|
2292
|
+
resolve: resolve$8,
|
|
2026
2293
|
createTask
|
|
2027
2294
|
} = widgets;
|
|
2028
2295
|
const {
|
|
2029
|
-
buildOutputAppJson
|
|
2030
|
-
} = buildAppJson
|
|
2296
|
+
buildOutputAppJson: buildOutputAppJson$1
|
|
2297
|
+
} = buildAppJson;
|
|
2031
2298
|
const {
|
|
2032
2299
|
MODULE_CODE_DIR,
|
|
2033
|
-
DEFAULT_COPY_CONFIG
|
|
2300
|
+
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
|
|
2034
2301
|
} = require$$4;
|
|
2035
2302
|
const {
|
|
2036
2303
|
cloneModules
|
|
2037
2304
|
} = cloneModules_1;
|
|
2038
2305
|
const {
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
} = tmsMpconfig;
|
|
2306
|
+
getModulesByMergeDepModules: getModulesByMergeDepModules$2,
|
|
2307
|
+
getSubPackages: getSubPackages$2
|
|
2308
|
+
} = tmsMpconfig.exports;
|
|
2042
2309
|
const {
|
|
2043
|
-
fail: fail$
|
|
2044
|
-
info: info$
|
|
2310
|
+
fail: fail$4,
|
|
2311
|
+
info: info$6
|
|
2045
2312
|
} = log$1;
|
|
2046
2313
|
const install$1 = install_1;
|
|
2047
|
-
const {
|
|
2048
|
-
checkDependencies
|
|
2049
|
-
} = checkDependencies_1;
|
|
2050
2314
|
/**
|
|
2051
2315
|
* 拷贝相关配置文件到编译输出目录
|
|
2052
2316
|
* @param { object } tmsConfig
|
|
@@ -2056,11 +2320,11 @@ const {
|
|
|
2056
2320
|
*/
|
|
2057
2321
|
|
|
2058
2322
|
const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
2059
|
-
const outputDir = resolve$
|
|
2323
|
+
const outputDir = resolve$8(tmsConfig.outputDir);
|
|
2060
2324
|
io.ensureDirExist(outputDir);
|
|
2061
2325
|
defaultFiles.forEach(item => {
|
|
2062
|
-
if (fs$
|
|
2063
|
-
shelljs$2.cp('-rf', resolve$
|
|
2326
|
+
if (fs$5.existsSync(resolve$8(item))) {
|
|
2327
|
+
shelljs$2.cp('-rf', resolve$8(item), resolve$8(tmsConfig.outputDir, item));
|
|
2064
2328
|
}
|
|
2065
2329
|
});
|
|
2066
2330
|
};
|
|
@@ -2078,7 +2342,7 @@ function checkConfig(targetModules) {
|
|
|
2078
2342
|
} // 判断源码目录是否有该模块
|
|
2079
2343
|
|
|
2080
2344
|
|
|
2081
|
-
if (item.path && !fs$
|
|
2345
|
+
if (item.path && !fs$5.existsSync(resolve$8(item.path))) {
|
|
2082
2346
|
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2083
2347
|
}
|
|
2084
2348
|
}
|
|
@@ -2088,42 +2352,38 @@ function checkConfig(targetModules) {
|
|
|
2088
2352
|
|
|
2089
2353
|
async function task(tmsConfig, targetModules) {
|
|
2090
2354
|
// 下载和移动代码
|
|
2091
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$
|
|
2355
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$8('./'), targetModules); // 获取所有模块,合并模块依赖的模块
|
|
2092
2356
|
|
|
2093
|
-
|
|
2357
|
+
const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
|
|
2094
2358
|
|
|
2095
|
-
|
|
2096
|
-
checkConfig(
|
|
2359
|
+
const newSubPackages = getSubPackages$2(newModules);
|
|
2360
|
+
checkConfig(newSubPackages); // 拷贝相关配置文件到输出目录
|
|
2097
2361
|
|
|
2098
|
-
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
|
|
2362
|
+
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
|
|
2099
2363
|
|
|
2100
|
-
|
|
2101
|
-
await install$1(tmsConfig, newModules);
|
|
2102
|
-
} // 动态生成编译后的app.json;
|
|
2364
|
+
await install$1(tmsConfig, newSubPackages); // 动态生成编译后的app.json;
|
|
2103
2365
|
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2366
|
+
await createTask(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
2367
|
+
return {
|
|
2368
|
+
modules: newModules,
|
|
2369
|
+
subPackages: newSubPackages
|
|
2370
|
+
};
|
|
2107
2371
|
}
|
|
2108
2372
|
|
|
2109
2373
|
async function init$5(tmsConfig, targetModules) {
|
|
2110
2374
|
try {
|
|
2111
|
-
const
|
|
2112
|
-
return
|
|
2113
|
-
targetModules: newModules
|
|
2114
|
-
};
|
|
2375
|
+
const taskRes = await task(tmsConfig, targetModules);
|
|
2376
|
+
return taskRes;
|
|
2115
2377
|
} catch (error) {
|
|
2116
2378
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
2117
|
-
fail$
|
|
2118
|
-
info$
|
|
2379
|
+
fail$4(`初始化流程出现错误${errMsg}`);
|
|
2380
|
+
info$6('详细的错误信息', error);
|
|
2119
2381
|
process.exit(1);
|
|
2120
2382
|
}
|
|
2121
2383
|
}
|
|
2122
2384
|
|
|
2123
2385
|
var init_1 = init$5;
|
|
2124
2386
|
|
|
2125
|
-
var dev$3 = {exports: {}};
|
|
2126
|
-
|
|
2127
2387
|
/* eslint-disable no-param-reassign */
|
|
2128
2388
|
const strip = require$$0__default$8; // 匹配规则
|
|
2129
2389
|
|
|
@@ -2160,16 +2420,16 @@ var findCssImport = {
|
|
|
2160
2420
|
|
|
2161
2421
|
/* eslint-disable no-param-reassign */
|
|
2162
2422
|
const {
|
|
2163
|
-
fail: fail$
|
|
2423
|
+
fail: fail$3
|
|
2164
2424
|
} = log$1;
|
|
2165
2425
|
|
|
2166
2426
|
function pluginError$3(error, isWatch) {
|
|
2167
2427
|
const errMsg = error.message;
|
|
2168
2428
|
|
|
2169
2429
|
if (isWatch) {
|
|
2170
|
-
fail$
|
|
2430
|
+
fail$3(errMsg);
|
|
2171
2431
|
} else {
|
|
2172
|
-
fail$
|
|
2432
|
+
fail$3(errMsg);
|
|
2173
2433
|
process.exit(1);
|
|
2174
2434
|
}
|
|
2175
2435
|
}
|
|
@@ -2181,7 +2441,7 @@ var pluginError_1 = {
|
|
|
2181
2441
|
/* eslint-disable no-param-reassign */
|
|
2182
2442
|
const through$2 = require$$0__default$9;
|
|
2183
2443
|
const precinct = require$$1__default$8;
|
|
2184
|
-
const path$
|
|
2444
|
+
const path$5 = require$$1__default$2;
|
|
2185
2445
|
const {
|
|
2186
2446
|
findCssImports
|
|
2187
2447
|
} = findCssImport;
|
|
@@ -2191,9 +2451,9 @@ const {
|
|
|
2191
2451
|
diffContentCopyFile: diffContentCopyFile$2
|
|
2192
2452
|
} = io$3;
|
|
2193
2453
|
const {
|
|
2194
|
-
resolve: resolve$
|
|
2454
|
+
resolve: resolve$7
|
|
2195
2455
|
} = widgets;
|
|
2196
|
-
const fs$
|
|
2456
|
+
const fs$4 = require$$0__default$2;
|
|
2197
2457
|
const {
|
|
2198
2458
|
pluginError: pluginError$2
|
|
2199
2459
|
} = pluginError_1;
|
|
@@ -2206,16 +2466,16 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2206
2466
|
let contents = '';
|
|
2207
2467
|
|
|
2208
2468
|
try {
|
|
2209
|
-
contents = fs$
|
|
2469
|
+
contents = fs$4.readFileSync(anaFileOriginFile, 'utf8');
|
|
2210
2470
|
} catch (e) {
|
|
2211
2471
|
pluginError$2(e, isWatch);
|
|
2212
2472
|
}
|
|
2213
2473
|
|
|
2214
|
-
const deps = cssFilter.indexOf(path$
|
|
2474
|
+
const deps = cssFilter.indexOf(path$5.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2215
2475
|
deps.forEach(depItem => {
|
|
2216
2476
|
if (depItem.startsWith('.')) {
|
|
2217
2477
|
// 被依赖文件的存在的绝对路径
|
|
2218
|
-
const depOriginPath = path$
|
|
2478
|
+
const depOriginPath = path$5.join(path$5.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2219
2479
|
|
|
2220
2480
|
const {
|
|
2221
2481
|
ext: extAlias,
|
|
@@ -2223,12 +2483,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2223
2483
|
extPath
|
|
2224
2484
|
} = ext$2(depOriginPath, extensions);
|
|
2225
2485
|
|
|
2226
|
-
if (!fs$
|
|
2486
|
+
if (!fs$4.existsSync(depOriginFile)) {
|
|
2227
2487
|
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2228
2488
|
return;
|
|
2229
2489
|
}
|
|
2230
2490
|
|
|
2231
|
-
const depDestPath = resolve$
|
|
2491
|
+
const depDestPath = resolve$7(path$5.dirname(anaFileDestFile), depItem);
|
|
2232
2492
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2233
2493
|
|
|
2234
2494
|
if (!resDep.has(depDestFile)) {
|
|
@@ -2252,19 +2512,19 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2252
2512
|
const stream = through$2.obj(function (file, enc, cb) {
|
|
2253
2513
|
// 依赖分析的文件
|
|
2254
2514
|
const anaFileOriginFile = file.history[0];
|
|
2255
|
-
const anaFileRelativeModule = path$
|
|
2256
|
-
const anaFileDestFile = resolve$
|
|
2515
|
+
const anaFileRelativeModule = path$5.relative(resolve$7(module.from), anaFileOriginFile);
|
|
2516
|
+
const anaFileDestFile = resolve$7(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2257
2517
|
|
|
2258
2518
|
if (file.isBuffer()) {
|
|
2259
2519
|
let contents = String(file.contents);
|
|
2260
|
-
const deps = cssFilter.indexOf(path$
|
|
2520
|
+
const deps = cssFilter.indexOf(path$5.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2261
2521
|
const copyModules = new Map();
|
|
2262
2522
|
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2263
2523
|
const includePath = tmsConfig.dependencies[includeName];
|
|
2264
2524
|
deps.forEach(depItem => {
|
|
2265
2525
|
if (depItem.indexOf(includeName) > -1) {
|
|
2266
2526
|
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
2267
|
-
const depOriginPath = path$
|
|
2527
|
+
const depOriginPath = path$5.join(path$5.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2268
2528
|
|
|
2269
2529
|
const {
|
|
2270
2530
|
ext: extAlias,
|
|
@@ -2282,7 +2542,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2282
2542
|
const regRes = depItem.match(reg) || [];
|
|
2283
2543
|
|
|
2284
2544
|
if (regRes[2]) {
|
|
2285
|
-
const depDestPath = resolve$
|
|
2545
|
+
const depDestPath = resolve$7(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2286
2546
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2287
2547
|
|
|
2288
2548
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2290,7 +2550,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2290
2550
|
depOriginFile,
|
|
2291
2551
|
depDestFile,
|
|
2292
2552
|
beforeDepPath: depItem,
|
|
2293
|
-
afterDepPath: path$
|
|
2553
|
+
afterDepPath: path$5.relative(path$5.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2294
2554
|
});
|
|
2295
2555
|
}
|
|
2296
2556
|
}
|
|
@@ -2328,16 +2588,16 @@ var mpCommonDep_1 = {
|
|
|
2328
2588
|
|
|
2329
2589
|
/* eslint-disable no-param-reassign */
|
|
2330
2590
|
const through$1 = require$$0__default$9;
|
|
2331
|
-
const path$
|
|
2591
|
+
const path$4 = require$$1__default$2;
|
|
2332
2592
|
const {
|
|
2333
2593
|
ext: ext$1,
|
|
2334
2594
|
fileInDir: fileInDir$1,
|
|
2335
2595
|
diffContentCopyFile: diffContentCopyFile$1
|
|
2336
2596
|
} = io$3;
|
|
2337
2597
|
const {
|
|
2338
|
-
resolve: resolve$
|
|
2598
|
+
resolve: resolve$6
|
|
2339
2599
|
} = widgets;
|
|
2340
|
-
const fs$
|
|
2600
|
+
const fs$3 = require$$0__default$2;
|
|
2341
2601
|
const {
|
|
2342
2602
|
pluginError: pluginError$1
|
|
2343
2603
|
} = pluginError_1;
|
|
@@ -2349,8 +2609,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2349
2609
|
const stream = through$1.obj(function (file, enc, cb) {
|
|
2350
2610
|
// 当前分析的文件的路径
|
|
2351
2611
|
const anaFileOriginFile = file.history[0];
|
|
2352
|
-
const anaFileRelativeModule = path$
|
|
2353
|
-
const anaFileDestFile = resolve$
|
|
2612
|
+
const anaFileRelativeModule = path$4.relative(resolve$6(module.from), anaFileOriginFile);
|
|
2613
|
+
const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2354
2614
|
|
|
2355
2615
|
if (file.isBuffer()) {
|
|
2356
2616
|
let contents = String(file.contents);
|
|
@@ -2370,7 +2630,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2370
2630
|
const componentPath = contents.usingComponents[componentKey];
|
|
2371
2631
|
|
|
2372
2632
|
if (componentPath.indexOf(includeName) > -1) {
|
|
2373
|
-
const depOriginPath = path$
|
|
2633
|
+
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
|
|
2374
2634
|
|
|
2375
2635
|
const {
|
|
2376
2636
|
ext: extAlias,
|
|
@@ -2389,7 +2649,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2389
2649
|
const regRes = componentPath.match(reg) || [];
|
|
2390
2650
|
|
|
2391
2651
|
if (regRes[2]) {
|
|
2392
|
-
const depDestPath = resolve$
|
|
2652
|
+
const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2393
2653
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2394
2654
|
|
|
2395
2655
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2398,7 +2658,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2398
2658
|
depOriginExt: extAlias,
|
|
2399
2659
|
depDestFile,
|
|
2400
2660
|
beforeDepPath: componentPath,
|
|
2401
|
-
afterDepPath: path$
|
|
2661
|
+
afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2402
2662
|
});
|
|
2403
2663
|
}
|
|
2404
2664
|
}
|
|
@@ -2423,7 +2683,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2423
2683
|
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2424
2684
|
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2425
2685
|
|
|
2426
|
-
if (fs$
|
|
2686
|
+
if (fs$3.existsSync(originFile)) {
|
|
2427
2687
|
diffContentCopyFile$1(originFile, destFile);
|
|
2428
2688
|
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2429
2689
|
|
|
@@ -2457,15 +2717,15 @@ var mpJsonDep_1 = {
|
|
|
2457
2717
|
/* eslint-disable no-param-reassign */
|
|
2458
2718
|
const through = require$$0__default$9;
|
|
2459
2719
|
const htmlparser2 = require$$1__default$9;
|
|
2460
|
-
const fs$
|
|
2461
|
-
const path$
|
|
2720
|
+
const fs$2 = require$$0__default$2;
|
|
2721
|
+
const path$3 = require$$1__default$2;
|
|
2462
2722
|
const {
|
|
2463
2723
|
diffContentCopyFile,
|
|
2464
2724
|
ext,
|
|
2465
2725
|
fileInDir
|
|
2466
2726
|
} = io$3;
|
|
2467
2727
|
const {
|
|
2468
|
-
resolve: resolve$
|
|
2728
|
+
resolve: resolve$5
|
|
2469
2729
|
} = widgets;
|
|
2470
2730
|
const {
|
|
2471
2731
|
dfsFindCommonDep
|
|
@@ -2504,7 +2764,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2504
2764
|
let contents = '';
|
|
2505
2765
|
|
|
2506
2766
|
try {
|
|
2507
|
-
contents = fs$
|
|
2767
|
+
contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
|
|
2508
2768
|
} catch (e) {
|
|
2509
2769
|
pluginError(e, isWatch);
|
|
2510
2770
|
}
|
|
@@ -2514,7 +2774,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2514
2774
|
var _attributes$src;
|
|
2515
2775
|
|
|
2516
2776
|
if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
|
|
2517
|
-
const depOriginPath = path$
|
|
2777
|
+
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
|
|
2518
2778
|
|
|
2519
2779
|
const {
|
|
2520
2780
|
ext,
|
|
@@ -2522,12 +2782,12 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2522
2782
|
extPath
|
|
2523
2783
|
} = extFile(name, depOriginPath);
|
|
2524
2784
|
|
|
2525
|
-
if (!fs$
|
|
2785
|
+
if (!fs$2.existsSync(depOriginFile)) {
|
|
2526
2786
|
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2527
2787
|
return;
|
|
2528
2788
|
}
|
|
2529
2789
|
|
|
2530
|
-
const depDestPath = path$
|
|
2790
|
+
const depDestPath = path$3.join(path$3.dirname(anaFileDestFile), attributes.src);
|
|
2531
2791
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
|
|
2532
2792
|
|
|
2533
2793
|
if (['import', 'include'].indexOf(name) > -1) {
|
|
@@ -2579,8 +2839,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2579
2839
|
const stream = through.obj(function (file, enc, cb) {
|
|
2580
2840
|
// 依赖分析的文件
|
|
2581
2841
|
const anaFileOriginFile = file.history[0];
|
|
2582
|
-
const anaFileRelativeModule = path$
|
|
2583
|
-
const anaFileDestFile = resolve$
|
|
2842
|
+
const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2843
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2584
2844
|
|
|
2585
2845
|
if (file.isBuffer()) {
|
|
2586
2846
|
let contents = String(file.contents);
|
|
@@ -2590,7 +2850,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2590
2850
|
const nameFilter = ['import', 'include', 'wxs'];
|
|
2591
2851
|
|
|
2592
2852
|
if (nameFilter.indexOf(name) > -1 && attributes.src) {
|
|
2593
|
-
const depOriginPath = path$
|
|
2853
|
+
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
|
|
2594
2854
|
|
|
2595
2855
|
const {
|
|
2596
2856
|
ext,
|
|
@@ -2611,7 +2871,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2611
2871
|
const regRes = attributes.src.match(reg) || [];
|
|
2612
2872
|
|
|
2613
2873
|
if (regRes[2]) {
|
|
2614
|
-
const depDestPath = resolve$
|
|
2874
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2615
2875
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2616
2876
|
|
|
2617
2877
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2619,7 +2879,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2619
2879
|
depOriginFile,
|
|
2620
2880
|
depDestFile,
|
|
2621
2881
|
beforeDepPath: attributes.src,
|
|
2622
|
-
afterDepPath: path$
|
|
2882
|
+
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
|
|
2623
2883
|
});
|
|
2624
2884
|
}
|
|
2625
2885
|
}
|
|
@@ -2638,7 +2898,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2638
2898
|
beforeDepPath,
|
|
2639
2899
|
afterDepPath
|
|
2640
2900
|
}) => {
|
|
2641
|
-
if (fs$
|
|
2901
|
+
if (fs$2.existsSync(depOriginFile)) {
|
|
2642
2902
|
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2643
2903
|
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2644
2904
|
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
@@ -2694,10 +2954,10 @@ const {
|
|
|
2694
2954
|
// const base64 = require('./plugins/postcss-font-base64');
|
|
2695
2955
|
|
|
2696
2956
|
const {
|
|
2697
|
-
fail
|
|
2957
|
+
fail: fail$2
|
|
2698
2958
|
} = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
2699
2959
|
|
|
2700
|
-
var compile = function (tmsConfig, {
|
|
2960
|
+
var compile$1 = function (tmsConfig, {
|
|
2701
2961
|
glob,
|
|
2702
2962
|
destPath,
|
|
2703
2963
|
srcOption,
|
|
@@ -2719,11 +2979,11 @@ var compile = function (tmsConfig, {
|
|
|
2719
2979
|
});
|
|
2720
2980
|
return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
2721
2981
|
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
|
|
2722
|
-
fail(`mpCommonDep编译报错${err}`);
|
|
2982
|
+
fail$2(`mpCommonDep编译报错${err}`);
|
|
2723
2983
|
}).pipe(dest(newDestPath, {
|
|
2724
2984
|
overwrite: true
|
|
2725
2985
|
})).on('error', err => {
|
|
2726
|
-
fail(`js编译报错${err}`);
|
|
2986
|
+
fail$2(`js编译报错${err}`);
|
|
2727
2987
|
});
|
|
2728
2988
|
}
|
|
2729
2989
|
});
|
|
@@ -2738,7 +2998,7 @@ var compile = function (tmsConfig, {
|
|
|
2738
2998
|
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2739
2999
|
});
|
|
2740
3000
|
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
|
|
2741
|
-
fail(`mpCommonDep编译报错${err}`);
|
|
3001
|
+
fail$2(`mpCommonDep编译报错${err}`);
|
|
2742
3002
|
}) // .pipe(postcss([base64()]))
|
|
2743
3003
|
// .on('error', (err) => {
|
|
2744
3004
|
// fail(`postcss编译报错${err}`);
|
|
@@ -2748,7 +3008,7 @@ var compile = function (tmsConfig, {
|
|
|
2748
3008
|
// precision: 2, // 小数最大精度,默认为6
|
|
2749
3009
|
// }))
|
|
2750
3010
|
.pipe(dest(newDestPath)).on('error', err => {
|
|
2751
|
-
fail(`wxss编译报错${err}`);
|
|
3011
|
+
fail$2(`wxss编译报错${err}`);
|
|
2752
3012
|
});
|
|
2753
3013
|
}
|
|
2754
3014
|
});
|
|
@@ -2763,9 +3023,9 @@ var compile = function (tmsConfig, {
|
|
|
2763
3023
|
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2764
3024
|
});
|
|
2765
3025
|
return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
|
|
2766
|
-
fail(`mpJsonDep编译报错${err}`);
|
|
3026
|
+
fail$2(`mpJsonDep编译报错${err}`);
|
|
2767
3027
|
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2768
|
-
fail(`json编译报错${err}`);
|
|
3028
|
+
fail$2(`json编译报错${err}`);
|
|
2769
3029
|
});
|
|
2770
3030
|
}
|
|
2771
3031
|
});
|
|
@@ -2780,9 +3040,9 @@ var compile = function (tmsConfig, {
|
|
|
2780
3040
|
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2781
3041
|
});
|
|
2782
3042
|
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
|
|
2783
|
-
fail(`mpWxmlDep编译报错${err}`);
|
|
3043
|
+
fail$2(`mpWxmlDep编译报错${err}`);
|
|
2784
3044
|
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2785
|
-
fail(`wxml编译报错${err}`);
|
|
3045
|
+
fail$2(`wxml编译报错${err}`);
|
|
2786
3046
|
});
|
|
2787
3047
|
}
|
|
2788
3048
|
});
|
|
@@ -2801,7 +3061,7 @@ var compile = function (tmsConfig, {
|
|
|
2801
3061
|
// fail(`image编译报错${err}`);
|
|
2802
3062
|
// })
|
|
2803
3063
|
.pipe(dest(newDestPath)).on('error', err => {
|
|
2804
|
-
fail(`image编译报错${err}`);
|
|
3064
|
+
fail$2(`image编译报错${err}`);
|
|
2805
3065
|
});
|
|
2806
3066
|
}
|
|
2807
3067
|
});
|
|
@@ -2816,7 +3076,7 @@ var compile = function (tmsConfig, {
|
|
|
2816
3076
|
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2817
3077
|
});
|
|
2818
3078
|
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
2819
|
-
fail(`编译报错${err}`);
|
|
3079
|
+
fail$2(`编译报错${err}`);
|
|
2820
3080
|
});
|
|
2821
3081
|
}
|
|
2822
3082
|
});
|
|
@@ -2830,18 +3090,18 @@ var compile = function (tmsConfig, {
|
|
|
2830
3090
|
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
2831
3091
|
|
|
2832
3092
|
const assign = require$$0__default$b;
|
|
2833
|
-
const path$
|
|
3093
|
+
const path$2 = require$$1__default$2;
|
|
2834
3094
|
const PluginError = require$$2__default$1;
|
|
2835
3095
|
const fancyLog = require$$3__default;
|
|
2836
3096
|
const colors = require$$4__default;
|
|
2837
|
-
const chokidar = require$$5__default
|
|
3097
|
+
const chokidar = require$$5__default;
|
|
2838
3098
|
const {
|
|
2839
3099
|
Duplex
|
|
2840
|
-
} = require$$6__default;
|
|
3100
|
+
} = require$$6__default$1;
|
|
2841
3101
|
const vinyl = require$$7__default;
|
|
2842
3102
|
const File = require$$8__default;
|
|
2843
|
-
const anymatch = require$$9__default;
|
|
2844
|
-
const pathIsAbsolute = require$$10__default;
|
|
3103
|
+
const anymatch = require$$9__default$1;
|
|
3104
|
+
const pathIsAbsolute = require$$10__default$1;
|
|
2845
3105
|
const globParent = require$$11__default;
|
|
2846
3106
|
const slash = require$$12__default;
|
|
2847
3107
|
|
|
@@ -2861,7 +3121,7 @@ function normalizeGlobs(globs) {
|
|
|
2861
3121
|
return globs;
|
|
2862
3122
|
}
|
|
2863
3123
|
|
|
2864
|
-
function watch$
|
|
3124
|
+
function watch$2(globs, opts, cb) {
|
|
2865
3125
|
globs = normalizeGlobs(globs);
|
|
2866
3126
|
|
|
2867
3127
|
if (typeof opts === 'function') {
|
|
@@ -2869,16 +3129,16 @@ function watch$1(globs, opts, cb) {
|
|
|
2869
3129
|
opts = {};
|
|
2870
3130
|
}
|
|
2871
3131
|
|
|
2872
|
-
opts = assign({}, watch$
|
|
3132
|
+
opts = assign({}, watch$2._defaultOptions, opts);
|
|
2873
3133
|
|
|
2874
3134
|
cb = cb || function () {};
|
|
2875
3135
|
|
|
2876
3136
|
function resolveFilepath(filepath) {
|
|
2877
3137
|
if (pathIsAbsolute(filepath)) {
|
|
2878
|
-
return path$
|
|
3138
|
+
return path$2.normalize(filepath);
|
|
2879
3139
|
}
|
|
2880
3140
|
|
|
2881
|
-
return path$
|
|
3141
|
+
return path$2.resolve(opts.cwd || process.cwd(), filepath);
|
|
2882
3142
|
}
|
|
2883
3143
|
|
|
2884
3144
|
function resolveGlob(glob) {
|
|
@@ -2934,7 +3194,7 @@ function watch$1(globs, opts, cb) {
|
|
|
2934
3194
|
let glob;
|
|
2935
3195
|
let currentFilepath = filepath;
|
|
2936
3196
|
|
|
2937
|
-
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$
|
|
3197
|
+
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$2.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
2938
3198
|
|
|
2939
3199
|
|
|
2940
3200
|
if (!glob) {
|
|
@@ -2943,7 +3203,7 @@ function watch$1(globs, opts, cb) {
|
|
|
2943
3203
|
}
|
|
2944
3204
|
|
|
2945
3205
|
if (!baseForced) {
|
|
2946
|
-
fileOpts.base = path$
|
|
3206
|
+
fileOpts.base = path$2.normalize(globParent(glob));
|
|
2947
3207
|
} // Do not stat deleted files
|
|
2948
3208
|
|
|
2949
3209
|
|
|
@@ -2994,54 +3254,76 @@ function watch$1(globs, opts, cb) {
|
|
|
2994
3254
|
// Avoid modifying gulp-watch's default options inside a library/reusable package, please.
|
|
2995
3255
|
|
|
2996
3256
|
|
|
2997
|
-
watch$
|
|
3257
|
+
watch$2._defaultOptions = {
|
|
2998
3258
|
events: ['add', 'change', 'unlink'],
|
|
2999
3259
|
ignoreInitial: true,
|
|
3000
3260
|
readDelay: 10
|
|
3001
3261
|
};
|
|
3002
|
-
var gulpWatch = watch$
|
|
3262
|
+
var gulpWatch = watch$2;
|
|
3003
3263
|
|
|
3004
|
-
|
|
3005
|
-
const
|
|
3264
|
+
/* eslint-disable no-restricted-syntax */
|
|
3265
|
+
const watch$1 = gulpWatch;
|
|
3266
|
+
const path$1 = require$$1__default$2;
|
|
3006
3267
|
const shellJs = require$$0__default$3;
|
|
3007
3268
|
const {
|
|
3008
|
-
info: info$
|
|
3009
|
-
warn: warn$1
|
|
3269
|
+
info: info$5,
|
|
3270
|
+
warn: warn$1,
|
|
3271
|
+
fail: fail$1
|
|
3010
3272
|
} = log$1;
|
|
3011
3273
|
const {
|
|
3012
|
-
resolve: resolve$
|
|
3274
|
+
resolve: resolve$4
|
|
3013
3275
|
} = widgets;
|
|
3014
3276
|
const {
|
|
3015
3277
|
global: global$2
|
|
3016
3278
|
} = global_1;
|
|
3279
|
+
const {
|
|
3280
|
+
checkPackageVersion
|
|
3281
|
+
} = checkDependencies;
|
|
3017
3282
|
const {
|
|
3018
3283
|
findAllFilesOfDir
|
|
3019
3284
|
} = io$3;
|
|
3020
3285
|
const TIP_MAP = {
|
|
3021
|
-
'package.json':
|
|
3022
|
-
|
|
3286
|
+
'package.json': {
|
|
3287
|
+
tip: '依赖版本有变动,请重新执行tmskit run dev',
|
|
3288
|
+
check: (sourceFile, targetFile) => {
|
|
3289
|
+
const targetArr = targetFile.split('/');
|
|
3290
|
+
targetArr[targetArr.length - 1] = 'node_modules';
|
|
3291
|
+
const packageArr = [{
|
|
3292
|
+
srcPackageDir: sourceFile,
|
|
3293
|
+
destNpmDir: targetArr.join('/')
|
|
3294
|
+
}];
|
|
3295
|
+
return checkPackageVersion(packageArr);
|
|
3296
|
+
}
|
|
3297
|
+
},
|
|
3298
|
+
'module.config.json': {
|
|
3299
|
+
tip: '若dependencies字段有变动,请重新执行tmskit run dev才会生效',
|
|
3300
|
+
check: () => true
|
|
3301
|
+
}
|
|
3023
3302
|
};
|
|
3024
3303
|
|
|
3025
|
-
const logTip = (fileName, tipMap) => {
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3304
|
+
const logTip = (fileName, sourceFile, targetFile, tipMap) => {
|
|
3305
|
+
try {
|
|
3306
|
+
for (const item in tipMap) {
|
|
3307
|
+
if (fileName.indexOf(item) > -1 && tipMap[item].check(sourceFile, targetFile)) {
|
|
3308
|
+
warn$1(`${fileName}有更新, ${tipMap[item].tip}`);
|
|
3309
|
+
return;
|
|
3310
|
+
}
|
|
3031
3311
|
}
|
|
3032
|
-
}
|
|
3033
3312
|
|
|
3034
|
-
|
|
3313
|
+
info$5(`${fileName}有更新`);
|
|
3314
|
+
} catch (e) {
|
|
3315
|
+
fail$1(`${sourceFile}文件更新提示出现错误: ${e.message}`);
|
|
3316
|
+
}
|
|
3035
3317
|
};
|
|
3036
3318
|
|
|
3037
3319
|
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
3038
|
-
const sourceFileRelativeModule = path.relative(resolve$
|
|
3039
|
-
const targetFile = resolve$
|
|
3320
|
+
const sourceFileRelativeModule = path$1.relative(resolve$4(module.from), sourceFile);
|
|
3321
|
+
const targetFile = resolve$4(outputDir, module.to, sourceFileRelativeModule);
|
|
3040
3322
|
return targetFile;
|
|
3041
3323
|
};
|
|
3042
3324
|
|
|
3043
3325
|
var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
3044
|
-
watch(globValue, { // readDelay: 100,
|
|
3326
|
+
watch$1(globValue, { // readDelay: 100,
|
|
3045
3327
|
...watchOptions
|
|
3046
3328
|
}, vinyl => {
|
|
3047
3329
|
const sourceFile = vinyl.history[0];
|
|
@@ -3050,15 +3332,15 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3050
3332
|
const tmsConfig = global$2.getData('tmsConfig');
|
|
3051
3333
|
|
|
3052
3334
|
if (vinyl.event === 'addDir') {
|
|
3053
|
-
info$
|
|
3335
|
+
info$5(`更新${sourceFileName}目录`);
|
|
3054
3336
|
const files = findAllFilesOfDir(sourceFile);
|
|
3055
3337
|
|
|
3056
3338
|
for (const file of files) {
|
|
3057
3339
|
const fileDirArr = file.replace(/\\/g, '/').split('/');
|
|
3058
3340
|
const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
|
|
3059
3341
|
const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
|
|
3060
|
-
logTip(fileName, TIP_MAP);
|
|
3061
|
-
callback([file], path.dirname(targetFile));
|
|
3342
|
+
logTip(fileName, sourceFile, targetFile, TIP_MAP);
|
|
3343
|
+
callback([file], path$1.dirname(targetFile));
|
|
3062
3344
|
}
|
|
3063
3345
|
|
|
3064
3346
|
return;
|
|
@@ -3067,246 +3349,254 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3067
3349
|
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
3068
3350
|
|
|
3069
3351
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
3070
|
-
info$
|
|
3352
|
+
info$5(`删除${sourceFileName}`);
|
|
3071
3353
|
shellJs.rm('-rf', targetFile);
|
|
3072
3354
|
return;
|
|
3073
3355
|
}
|
|
3074
3356
|
|
|
3075
|
-
logTip(sourceFileName, TIP_MAP);
|
|
3076
|
-
return callback([sourceFile], path.dirname(targetFile));
|
|
3357
|
+
logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
|
|
3358
|
+
return callback([sourceFile], path$1.dirname(targetFile));
|
|
3077
3359
|
});
|
|
3078
3360
|
};
|
|
3079
3361
|
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
function excludeGlob(glob) {
|
|
3107
|
-
const otherArr = new Set();
|
|
3108
|
-
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
3109
|
-
Object.keys(glob).forEach(globKey => {
|
|
3110
|
-
if (typeof glob[globKey] === 'string') {
|
|
3111
|
-
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
3112
|
-
otherArr.add(data);
|
|
3113
|
-
}
|
|
3362
|
+
const path = require$$1__default$2;
|
|
3363
|
+
const fs$1 = require$$0__default$2;
|
|
3364
|
+
const ora = require$$2__default;
|
|
3365
|
+
const chalk$2 = require$$0__default;
|
|
3366
|
+
const {
|
|
3367
|
+
parallel,
|
|
3368
|
+
series
|
|
3369
|
+
} = require$$0__default$a;
|
|
3370
|
+
const {
|
|
3371
|
+
resolve: resolve$3,
|
|
3372
|
+
mergeMap,
|
|
3373
|
+
filterField: filterField$2
|
|
3374
|
+
} = widgets;
|
|
3375
|
+
const {
|
|
3376
|
+
buildOutputAppJson
|
|
3377
|
+
} = buildAppJson;
|
|
3378
|
+
const {
|
|
3379
|
+
DEFAULT_COPY_CONFIG
|
|
3380
|
+
} = require$$4;
|
|
3381
|
+
const compile = compile$1;
|
|
3382
|
+
const watch = watch_1;
|
|
3383
|
+
const {
|
|
3384
|
+
info: info$4
|
|
3385
|
+
} = log$1;
|
|
3386
|
+
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
3114
3387
|
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
});
|
|
3124
|
-
return Array.from(otherArr);
|
|
3125
|
-
}
|
|
3388
|
+
function excludeGlob(glob) {
|
|
3389
|
+
const otherArr = new Set();
|
|
3390
|
+
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
3391
|
+
Object.keys(glob).forEach(globKey => {
|
|
3392
|
+
if (typeof glob[globKey] === 'string') {
|
|
3393
|
+
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
3394
|
+
otherArr.add(data);
|
|
3395
|
+
}
|
|
3126
3396
|
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3397
|
+
if (Array.isArray(glob[globKey])) {
|
|
3398
|
+
glob[globKey].forEach(value => {
|
|
3399
|
+
if (typeof value === 'string') {
|
|
3400
|
+
const data = value.startsWith('!') ? value : `!${value}`;
|
|
3401
|
+
otherArr.add(data);
|
|
3402
|
+
}
|
|
3403
|
+
});
|
|
3404
|
+
}
|
|
3405
|
+
});
|
|
3406
|
+
return Array.from(otherArr);
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
function adaptPath(pathDir, cwd = '') {
|
|
3410
|
+
let newPath = pathDir;
|
|
3411
|
+
newPath = newPath.startsWith('/') ? newPath : resolve$3(cwd, newPath);
|
|
3412
|
+
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
3413
|
+
return newPath;
|
|
3414
|
+
}
|
|
3415
|
+
|
|
3416
|
+
var dev$3 = async (tmsConfig, modules, subPackages, isDev = true) => {
|
|
3417
|
+
const compileTasksMap = new Map(); // 监听根目录的文件
|
|
3418
|
+
|
|
3419
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3420
|
+
glob: {
|
|
3421
|
+
json: DEFAULT_COPY_CONFIG.map(item => resolve$3(item))
|
|
3422
|
+
},
|
|
3423
|
+
module: {
|
|
3424
|
+
from: resolve$3(),
|
|
3425
|
+
to: resolve$3(tmsConfig.outputDir)
|
|
3426
|
+
},
|
|
3427
|
+
destPath: resolve$3(tmsConfig.outputDir),
|
|
3428
|
+
srcOption: {
|
|
3429
|
+
allowEmpty: true
|
|
3430
|
+
},
|
|
3431
|
+
isDev
|
|
3432
|
+
})); // 监听模块的文件
|
|
3433
|
+
|
|
3434
|
+
for (let pkg of subPackages) {
|
|
3435
|
+
// 处理默认参数
|
|
3436
|
+
pkg = { ...{
|
|
3437
|
+
exclude: []
|
|
3438
|
+
},
|
|
3439
|
+
...pkg
|
|
3440
|
+
};
|
|
3441
|
+
const packagePath = adaptPath(pkg.path);
|
|
3442
|
+
|
|
3443
|
+
if (isDev) {
|
|
3444
|
+
// 监听模块配置文件
|
|
3445
|
+
watch([`${packagePath}/**/module.config.json`], {
|
|
3446
|
+
events: watchEvents
|
|
3447
|
+
}, () => buildOutputAppJson(tmsConfig, modules, isDev), {
|
|
3448
|
+
from: packagePath,
|
|
3449
|
+
to: packagePath
|
|
3450
|
+
});
|
|
3451
|
+
}
|
|
3133
3452
|
|
|
3134
|
-
|
|
3135
|
-
|
|
3453
|
+
const excludes = pkg.exclude.map(ePath => {
|
|
3454
|
+
const newPath = adaptPath(ePath, packagePath);
|
|
3455
|
+
const ext = path.extname(ePath).slice(1);
|
|
3136
3456
|
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
// js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
3457
|
+
if (ext) {
|
|
3458
|
+
return `!${resolve$3(packagePath, newPath)}`;
|
|
3459
|
+
}
|
|
3141
3460
|
|
|
3461
|
+
return `!${resolve$3(packagePath, newPath)}/**/*`;
|
|
3462
|
+
});
|
|
3463
|
+
const glob = {
|
|
3464
|
+
js: [`${packagePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
3465
|
+
json: [`${packagePath}/**/*.json`, `!${packagePath}/**/module.config.json`, ...excludes],
|
|
3466
|
+
wxss: [`${packagePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
|
|
3467
|
+
wxml: [`${packagePath}/**/*.wxml`, ...excludes],
|
|
3468
|
+
image: [`${packagePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
3469
|
+
};
|
|
3470
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3471
|
+
glob: { ...glob,
|
|
3472
|
+
other: [`${packagePath}/**/*`, ...excludeGlob(glob)]
|
|
3142
3473
|
},
|
|
3474
|
+
destPath: resolve$3(tmsConfig.outputDir, pkg.root),
|
|
3143
3475
|
module: {
|
|
3144
|
-
from:
|
|
3145
|
-
to:
|
|
3476
|
+
from: pkg.path,
|
|
3477
|
+
to: pkg.root
|
|
3146
3478
|
},
|
|
3147
|
-
destPath: resolve(tmsConfig.outputDir),
|
|
3148
3479
|
srcOption: {
|
|
3149
3480
|
allowEmpty: true
|
|
3150
3481
|
},
|
|
3151
3482
|
isDev
|
|
3152
|
-
}));
|
|
3483
|
+
}));
|
|
3484
|
+
} // 静态资源目录-拷贝
|
|
3153
3485
|
|
|
3154
|
-
for (let module of newModules) {
|
|
3155
|
-
// 处理默认参数
|
|
3156
|
-
module = { ...{
|
|
3157
|
-
exclude: []
|
|
3158
|
-
},
|
|
3159
|
-
...module
|
|
3160
|
-
};
|
|
3161
|
-
const modulePath = adaptPath(module.path);
|
|
3162
3486
|
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3487
|
+
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
3488
|
+
for (const item of tmsConfig.static) {
|
|
3489
|
+
item.from = adaptPath(item.from);
|
|
3490
|
+
item.to = adaptPath(item.to);
|
|
3491
|
+
let glob = {};
|
|
3492
|
+
const ext = path.extname(item.from).slice(1);
|
|
3493
|
+
|
|
3494
|
+
if (ext) {
|
|
3495
|
+
glob[ext] = [item.from];
|
|
3496
|
+
} else {
|
|
3497
|
+
glob = {
|
|
3498
|
+
js: [`${item.from}/**/*.{js,ts,wxs}`],
|
|
3499
|
+
json: [`${item.from}/**/*.json`],
|
|
3500
|
+
wxss: [`${item.from}/**/*.{less,wxss,scss,sass,styl}`],
|
|
3501
|
+
wxml: [`${item.from}/**/*.wxml`],
|
|
3502
|
+
image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
|
|
3503
|
+
};
|
|
3504
|
+
glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
|
|
3171
3505
|
}
|
|
3172
3506
|
|
|
3173
|
-
const
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
|
|
3178
|
-
wxml: [`${modulePath}/**/*.wxml`, ...excludes],
|
|
3179
|
-
image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
3180
|
-
};
|
|
3181
|
-
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
3182
|
-
glob: { ...glob,
|
|
3183
|
-
other: [`${modulePath}/**/*`, ...excludeGlob(glob)]
|
|
3184
|
-
},
|
|
3185
|
-
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
3507
|
+
const from = fs$1.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
3508
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3509
|
+
glob,
|
|
3510
|
+
destPath: item.to,
|
|
3186
3511
|
module: {
|
|
3187
|
-
from
|
|
3188
|
-
to:
|
|
3512
|
+
from,
|
|
3513
|
+
to: item.to
|
|
3189
3514
|
},
|
|
3190
3515
|
srcOption: {
|
|
3191
3516
|
allowEmpty: true
|
|
3192
3517
|
},
|
|
3193
3518
|
isDev
|
|
3194
3519
|
}));
|
|
3195
|
-
} // 静态资源目录-拷贝
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
3199
|
-
for (const item of tmsConfig.static) {
|
|
3200
|
-
item.from = adaptPath(item.from);
|
|
3201
|
-
item.to = adaptPath(item.to);
|
|
3202
|
-
let glob = {};
|
|
3203
|
-
const ext = path.extname(item.from).slice(1);
|
|
3204
|
-
|
|
3205
|
-
if (ext) {
|
|
3206
|
-
glob[ext] = [item.from];
|
|
3207
|
-
} else {
|
|
3208
|
-
glob = {
|
|
3209
|
-
js: [`${item.from}/**/*.{js,ts,wxs}`],
|
|
3210
|
-
json: [`${item.from}/**/*.json`],
|
|
3211
|
-
wxss: [`${item.from}/**/*.{less,wxss}`],
|
|
3212
|
-
wxml: [`${item.from}/**/*.wxml`],
|
|
3213
|
-
image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
|
|
3214
|
-
};
|
|
3215
|
-
glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
|
|
3216
|
-
}
|
|
3217
|
-
|
|
3218
|
-
const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
3219
|
-
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
3220
|
-
glob,
|
|
3221
|
-
destPath: item.to,
|
|
3222
|
-
module: {
|
|
3223
|
-
from,
|
|
3224
|
-
to: item.to
|
|
3225
|
-
},
|
|
3226
|
-
srcOption: {
|
|
3227
|
-
allowEmpty: true
|
|
3228
|
-
},
|
|
3229
|
-
isDev
|
|
3230
|
-
}));
|
|
3231
|
-
}
|
|
3232
3520
|
}
|
|
3521
|
+
}
|
|
3233
3522
|
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
function start(cb) {
|
|
3239
|
-
info('启动编译...');
|
|
3240
|
-
spinner.start();
|
|
3241
|
-
sTime = new Date().getTime();
|
|
3242
|
-
cb();
|
|
3243
|
-
}
|
|
3523
|
+
let sTime;
|
|
3524
|
+
let eTime;
|
|
3525
|
+
const spinner = ora();
|
|
3244
3526
|
|
|
3245
|
-
|
|
3246
|
-
|
|
3527
|
+
function start(cb) {
|
|
3528
|
+
info$4('启动编译...');
|
|
3529
|
+
spinner.start();
|
|
3530
|
+
sTime = new Date().getTime();
|
|
3531
|
+
cb();
|
|
3532
|
+
}
|
|
3247
3533
|
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3534
|
+
async function end(cb) {
|
|
3535
|
+
var _tmsConfig$hooks;
|
|
3536
|
+
|
|
3537
|
+
if (isDev) {
|
|
3538
|
+
// 监听app.json
|
|
3539
|
+
watch([resolve$3('app.json')], {
|
|
3540
|
+
ignoreInitial: false,
|
|
3541
|
+
events: watchEvents
|
|
3542
|
+
}, () => buildOutputAppJson(tmsConfig, modules, isDev), {
|
|
3543
|
+
from: resolve$3(),
|
|
3544
|
+
to: resolve$3(tmsConfig.outputDir)
|
|
3545
|
+
}); // 监听其他文件
|
|
3546
|
+
|
|
3547
|
+
compileTasksMap.forEach(({
|
|
3548
|
+
taskFn,
|
|
3549
|
+
module
|
|
3550
|
+
}, globValue) => {
|
|
3551
|
+
watch(globValue, {
|
|
3552
|
+
ignoreInitial: true,
|
|
3252
3553
|
events: watchEvents
|
|
3253
|
-
},
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
compileTasksMap.forEach(({
|
|
3259
|
-
taskFn,
|
|
3260
|
-
module
|
|
3261
|
-
}, globValue) => {
|
|
3262
|
-
watch(globValue, {
|
|
3263
|
-
ignoreInitial: true,
|
|
3264
|
-
events: watchEvents
|
|
3265
|
-
}, taskFn, module);
|
|
3266
|
-
});
|
|
3267
|
-
} else {
|
|
3268
|
-
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
3269
|
-
}
|
|
3270
|
-
|
|
3271
|
-
eTime = new Date().getTime() - sTime;
|
|
3554
|
+
}, taskFn, module);
|
|
3555
|
+
});
|
|
3556
|
+
} else {
|
|
3557
|
+
buildOutputAppJson(tmsConfig, modules, isDev);
|
|
3558
|
+
}
|
|
3272
3559
|
|
|
3273
|
-
|
|
3274
|
-
var _tmsConfig$hooks2;
|
|
3560
|
+
eTime = new Date().getTime() - sTime;
|
|
3275
3561
|
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
tmsConfig,
|
|
3279
|
-
modules: newModules
|
|
3280
|
-
}));
|
|
3281
|
-
}
|
|
3562
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
|
|
3563
|
+
var _tmsConfig$hooks2;
|
|
3282
3564
|
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3565
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3566
|
+
isDev,
|
|
3567
|
+
tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
|
|
3568
|
+
modules
|
|
3569
|
+
}));
|
|
3286
3570
|
}
|
|
3287
3571
|
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
compileTasks.push(taskFn);
|
|
3293
|
-
}); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
3572
|
+
spinner.succeed(chalk$2.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
3573
|
+
spinner.stop();
|
|
3574
|
+
cb();
|
|
3575
|
+
}
|
|
3294
3576
|
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3577
|
+
const compileTasks = [];
|
|
3578
|
+
compileTasksMap.forEach(({
|
|
3579
|
+
taskFn
|
|
3580
|
+
}) => {
|
|
3581
|
+
compileTasks.push(taskFn);
|
|
3582
|
+
}); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
3583
|
+
|
|
3584
|
+
series(start, parallel(...compileTasks), end)();
|
|
3585
|
+
};
|
|
3298
3586
|
|
|
3299
3587
|
const shelljs$1 = require$$0__default$3;
|
|
3300
|
-
const compileDev = dev$3
|
|
3588
|
+
const compileDev = dev$3;
|
|
3301
3589
|
const {
|
|
3302
|
-
resolve: resolve$2
|
|
3590
|
+
resolve: resolve$2,
|
|
3591
|
+
filterField: filterField$1
|
|
3303
3592
|
} = widgets;
|
|
3304
3593
|
const init$4 = init_1;
|
|
3305
3594
|
const {
|
|
3306
|
-
|
|
3307
|
-
|
|
3595
|
+
getModulesByMergeDepModules: getModulesByMergeDepModules$1,
|
|
3596
|
+
getSubPackages: getSubPackages$1
|
|
3597
|
+
} = tmsMpconfig.exports;
|
|
3308
3598
|
const {
|
|
3309
|
-
info: info$
|
|
3599
|
+
info: info$3
|
|
3310
3600
|
} = log$1;
|
|
3311
3601
|
const {
|
|
3312
3602
|
global: global$1
|
|
@@ -3315,12 +3605,15 @@ const {
|
|
|
3315
3605
|
CACHE_DIR
|
|
3316
3606
|
} = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
3317
3607
|
|
|
3318
|
-
function
|
|
3319
|
-
|
|
3320
|
-
const
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3608
|
+
function delOtherPackages(tmsConfig, targetSubPackages) {
|
|
3609
|
+
// 获取所有模块,合并模块依赖的模块
|
|
3610
|
+
const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all); // 获取所有的分包
|
|
3611
|
+
|
|
3612
|
+
const allSubPackages = getSubPackages$1(allModules);
|
|
3613
|
+
const targetSubPackagesName = targetSubPackages.map(item => item.name);
|
|
3614
|
+
allSubPackages.forEach(item => {
|
|
3615
|
+
if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
|
|
3616
|
+
const moduleRootDir = resolve$2(`${tmsConfig.outputDir}/${item.root}`);
|
|
3324
3617
|
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
3325
3618
|
silent: true
|
|
3326
3619
|
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
@@ -3329,10 +3622,9 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
3329
3622
|
});
|
|
3330
3623
|
}
|
|
3331
3624
|
|
|
3332
|
-
async function dev$2(tmsConfig, targetModules
|
|
3625
|
+
async function dev$2(tmsConfig, targetModules) {
|
|
3333
3626
|
var _tmsConfig$hooks;
|
|
3334
3627
|
|
|
3335
|
-
let newModules = targetModules;
|
|
3336
3628
|
const {
|
|
3337
3629
|
noCache
|
|
3338
3630
|
} = global$1.getData('cmd');
|
|
@@ -3343,57 +3635,62 @@ async function dev$2(tmsConfig, targetModules, env) {
|
|
|
3343
3635
|
} // 初始化操作
|
|
3344
3636
|
|
|
3345
3637
|
|
|
3346
|
-
const
|
|
3347
|
-
|
|
3348
|
-
|
|
3638
|
+
const {
|
|
3639
|
+
subPackages,
|
|
3640
|
+
modules: newModules
|
|
3641
|
+
} = await init$4(tmsConfig, targetModules);
|
|
3642
|
+
info$3('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
|
|
3349
3643
|
|
|
3350
3644
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3351
3645
|
var _tmsConfig$hooks2;
|
|
3352
3646
|
|
|
3353
3647
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3354
3648
|
isDev: true,
|
|
3355
|
-
tmsConfig,
|
|
3649
|
+
tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
|
|
3356
3650
|
modules: newModules
|
|
3357
3651
|
}));
|
|
3358
3652
|
}
|
|
3359
|
-
|
|
3360
|
-
compileDev(tmsConfig, newModules,
|
|
3653
|
+
delOtherPackages(tmsConfig, subPackages);
|
|
3654
|
+
compileDev(tmsConfig, newModules, subPackages, true);
|
|
3361
3655
|
}
|
|
3362
3656
|
|
|
3363
3657
|
var dev_1 = dev$2;
|
|
3364
3658
|
|
|
3365
|
-
const dev$1 = dev$3
|
|
3659
|
+
const dev$1 = dev$3;
|
|
3366
3660
|
|
|
3367
|
-
var build$2 = async (tmsConfig, newModules) => {
|
|
3368
|
-
dev$1(tmsConfig, newModules,
|
|
3661
|
+
var build$2 = async (tmsConfig, newModules, subPackages, isDev) => {
|
|
3662
|
+
dev$1(tmsConfig, newModules, subPackages, isDev);
|
|
3369
3663
|
};
|
|
3370
3664
|
|
|
3371
3665
|
const shelljs = require$$0__default$3;
|
|
3372
3666
|
const {
|
|
3373
|
-
resolve: resolve$1
|
|
3667
|
+
resolve: resolve$1,
|
|
3668
|
+
filterField
|
|
3374
3669
|
} = widgets;
|
|
3375
3670
|
const init$3 = init_1;
|
|
3376
3671
|
const compileBuild = build$2;
|
|
3377
3672
|
|
|
3378
|
-
async function build$1(tmsConfig, targetModules
|
|
3673
|
+
async function build$1(tmsConfig, targetModules) {
|
|
3379
3674
|
var _tmsConfig$hooks;
|
|
3380
3675
|
|
|
3381
3676
|
// 开始构建前,清理输出目录
|
|
3382
3677
|
await shelljs.rm('-rf', resolve$1(tmsConfig.outputDir));
|
|
3383
3678
|
const {
|
|
3384
|
-
|
|
3679
|
+
modules: newModules,
|
|
3680
|
+
subPackages
|
|
3385
3681
|
} = await init$3(tmsConfig, targetModules);
|
|
3682
|
+
const isDev = false;
|
|
3386
3683
|
|
|
3387
3684
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3388
3685
|
var _tmsConfig$hooks2;
|
|
3389
3686
|
|
|
3390
3687
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3391
|
-
isDev
|
|
3392
|
-
tmsConfig,
|
|
3688
|
+
isDev,
|
|
3689
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3393
3690
|
modules: newModules
|
|
3394
3691
|
}));
|
|
3395
3692
|
}
|
|
3396
|
-
compileBuild(tmsConfig, newModules,
|
|
3693
|
+
compileBuild(tmsConfig, newModules, subPackages, isDev);
|
|
3397
3694
|
}
|
|
3398
3695
|
|
|
3399
3696
|
var build_1 = build$1;
|
|
@@ -3463,11 +3760,17 @@ var cloud$1 = async tmsConfig => {
|
|
|
3463
3760
|
}
|
|
3464
3761
|
};
|
|
3465
3762
|
|
|
3763
|
+
/* eslint-disable no-param-reassign */
|
|
3764
|
+
const loadash = require$$0__default$6;
|
|
3466
3765
|
const init$2 = init_1;
|
|
3467
3766
|
const dev = dev_1;
|
|
3468
3767
|
const build = build_1;
|
|
3469
3768
|
const install = install_1;
|
|
3470
3769
|
const cloud = cloud$1;
|
|
3770
|
+
const {
|
|
3771
|
+
fail,
|
|
3772
|
+
info: info$2
|
|
3773
|
+
} = log$1;
|
|
3471
3774
|
const {
|
|
3472
3775
|
global
|
|
3473
3776
|
} = global_1;
|
|
@@ -3475,9 +3778,9 @@ const {
|
|
|
3475
3778
|
readTmsConfig,
|
|
3476
3779
|
readTmsPrivateCf,
|
|
3477
3780
|
checkModules,
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
} = tmsMpconfig;
|
|
3781
|
+
getModulesByMergeDepModules,
|
|
3782
|
+
getSubPackages
|
|
3783
|
+
} = tmsMpconfig.exports;
|
|
3481
3784
|
|
|
3482
3785
|
const handleModuleArg = cmd => {
|
|
3483
3786
|
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
@@ -3495,88 +3798,121 @@ const handleModuleArg = cmd => {
|
|
|
3495
3798
|
*/
|
|
3496
3799
|
|
|
3497
3800
|
|
|
3498
|
-
const getSpecificModules = (moduleArg,
|
|
3801
|
+
const getSpecificModules = (moduleArg, modules) => {
|
|
3499
3802
|
if (moduleArg.length > 0) {
|
|
3500
3803
|
return moduleArg;
|
|
3501
|
-
}
|
|
3804
|
+
}
|
|
3502
3805
|
|
|
3806
|
+
const {
|
|
3807
|
+
all,
|
|
3808
|
+
include,
|
|
3809
|
+
exclude,
|
|
3810
|
+
blockRemote
|
|
3811
|
+
} = modules; // 单模块或多模块开发-用户在tms.private.js指定的模块
|
|
3812
|
+
|
|
3813
|
+
if ((include === null || include === void 0 ? void 0 : include.length) > 0) {
|
|
3814
|
+
return include;
|
|
3815
|
+
}
|
|
3503
3816
|
|
|
3504
|
-
if (
|
|
3505
|
-
|
|
3817
|
+
if ((exclude === null || exclude === void 0 ? void 0 : exclude.length) > 0) {
|
|
3818
|
+
return all.filter(module => !exclude.includes(module.moduleName)).map(item => item.moduleName);
|
|
3819
|
+
}
|
|
3506
3820
|
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3821
|
+
if (blockRemote === true) {
|
|
3822
|
+
return all.filter(module => module.repoInfo === undefined).map(item => item.moduleName);
|
|
3823
|
+
}
|
|
3510
3824
|
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3825
|
+
return all.map(item => item.moduleName);
|
|
3826
|
+
};
|
|
3827
|
+
/**
|
|
3828
|
+
* 合并tms.config.js 与 tms.private.config.js的配置项
|
|
3829
|
+
* @param {*} tmsConfig
|
|
3830
|
+
* @param {*} tmsPrivateCf
|
|
3831
|
+
* @returns
|
|
3832
|
+
*/
|
|
3833
|
+
|
|
3834
|
+
|
|
3835
|
+
const mergeConfig = (tmsConfig, tmsPrivateCf) => {
|
|
3836
|
+
const modules = {};
|
|
3837
|
+
|
|
3838
|
+
if (Array.isArray(tmsConfig.modules)) {
|
|
3839
|
+
modules.all = tmsConfig.modules;
|
|
3840
|
+
tmsConfig.modules = modules;
|
|
3841
|
+
} // 合并默认值
|
|
3514
3842
|
|
|
3515
|
-
if (modulePrivateCfg.blockRemote === true) {
|
|
3516
|
-
return moduleAll.filter(module => module.repoInfo === undefined).map(item => item.name);
|
|
3517
|
-
}
|
|
3518
|
-
}
|
|
3519
3843
|
|
|
3520
|
-
|
|
3844
|
+
const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
|
|
3845
|
+
if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
|
|
3846
|
+
return objValue.concat(srcValue);
|
|
3847
|
+
}
|
|
3848
|
+
});
|
|
3849
|
+
return res;
|
|
3521
3850
|
};
|
|
3522
3851
|
|
|
3523
3852
|
async function run(commandName, cmd) {
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3853
|
+
try {
|
|
3854
|
+
// 用户本地的私有项目配置
|
|
3855
|
+
const tmsPrivateCf = readTmsPrivateCf();
|
|
3856
|
+
const {
|
|
3857
|
+
env = tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : tmsPrivateCf.env
|
|
3858
|
+
} = cmd;
|
|
3859
|
+
let tmsConfig = readTmsConfig(env);
|
|
3860
|
+
tmsConfig = mergeConfig(tmsConfig, tmsPrivateCf); // 处理module参数
|
|
3530
3861
|
|
|
3531
|
-
|
|
3532
|
-
|
|
3862
|
+
const specificModules = getSpecificModules(handleModuleArg(cmd), tmsConfig.modules);
|
|
3863
|
+
const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])], true); // 获取所有模块,合并模块依赖的模块
|
|
3533
3864
|
|
|
3534
|
-
|
|
3865
|
+
const newModules = getModulesByMergeDepModules(tmsConfig, modules); // 获取所有的分包
|
|
3535
3866
|
|
|
3536
|
-
|
|
3867
|
+
const subPackages = getSubPackages(newModules); // 缓存数据
|
|
3537
3868
|
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
});
|
|
3869
|
+
global.setData({
|
|
3870
|
+
env,
|
|
3871
|
+
cmd,
|
|
3872
|
+
tmsConfig
|
|
3873
|
+
});
|
|
3544
3874
|
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3875
|
+
switch (commandName) {
|
|
3876
|
+
case 'init':
|
|
3877
|
+
init$2(tmsConfig, newModules);
|
|
3878
|
+
return;
|
|
3549
3879
|
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3880
|
+
case 'dev':
|
|
3881
|
+
global.setData('isDev', true);
|
|
3882
|
+
dev(tmsConfig, newModules);
|
|
3883
|
+
return;
|
|
3554
3884
|
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3885
|
+
case 'cloud':
|
|
3886
|
+
cloud(tmsConfig);
|
|
3887
|
+
return;
|
|
3558
3888
|
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3889
|
+
case 'install':
|
|
3890
|
+
install(tmsConfig, subPackages, false);
|
|
3891
|
+
return;
|
|
3562
3892
|
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3893
|
+
case 'build':
|
|
3894
|
+
global.setData('isDev', false);
|
|
3895
|
+
build(tmsConfig, newModules);
|
|
3896
|
+
return;
|
|
3567
3897
|
|
|
3568
|
-
|
|
3569
|
-
|
|
3898
|
+
default:
|
|
3899
|
+
return;
|
|
3900
|
+
}
|
|
3901
|
+
} catch (error) {
|
|
3902
|
+
const errMsg = typeof error === 'object' ? error.message : error;
|
|
3903
|
+
fail(`构建出现错误: ${errMsg}`);
|
|
3904
|
+
info$2('详细错误信息', error);
|
|
3905
|
+
process.exit(1);
|
|
3570
3906
|
}
|
|
3571
3907
|
}
|
|
3572
3908
|
|
|
3573
3909
|
var run_1 = run;
|
|
3574
3910
|
|
|
3575
3911
|
var entry = [{
|
|
3576
|
-
command: 'create <
|
|
3912
|
+
command: 'create <project-name>',
|
|
3577
3913
|
description: '创建新的应用',
|
|
3578
|
-
action:
|
|
3579
|
-
create_1(
|
|
3914
|
+
action: projectName => {
|
|
3915
|
+
create_1(projectName);
|
|
3580
3916
|
}
|
|
3581
3917
|
}, {
|
|
3582
3918
|
name: 'run',
|
|
@@ -3627,7 +3963,7 @@ var entry = [{
|
|
|
3627
3963
|
|
|
3628
3964
|
var require$$7 = {
|
|
3629
3965
|
name: "@tmsfe/tmskit",
|
|
3630
|
-
version: "0.0.
|
|
3966
|
+
version: "0.0.20",
|
|
3631
3967
|
description: "tmskit",
|
|
3632
3968
|
main: "dist/index.cjs",
|
|
3633
3969
|
bin: {
|
|
@@ -3668,21 +4004,16 @@ var require$$7 = {
|
|
|
3668
4004
|
dependencies: {
|
|
3669
4005
|
"ansi-colors": "1.1.0",
|
|
3670
4006
|
anymatch: "^1.3.0",
|
|
3671
|
-
"fancy-log": "1.3.2",
|
|
3672
|
-
"glob-parent": "^3.0.1",
|
|
3673
|
-
"path-is-absolute": "^1.0.1",
|
|
3674
|
-
"readable-stream": "^2.2.2",
|
|
3675
|
-
slash: "^1.0.0",
|
|
3676
|
-
vinyl: "^2.1.0",
|
|
3677
|
-
"vinyl-file": "^2.0.0",
|
|
3678
4007
|
async: "^3.2.2",
|
|
3679
4008
|
chalk: "^4.1.0",
|
|
3680
4009
|
chokidar: "^3.5.3",
|
|
3681
4010
|
commander: "^8.3.0",
|
|
3682
4011
|
"copy-webpack-plugin": "^9.1.0",
|
|
3683
4012
|
ejs: "^3.1.5",
|
|
4013
|
+
"fancy-log": "1.3.2",
|
|
3684
4014
|
"fs-extra": "^10.0.1",
|
|
3685
4015
|
"glob-ignore": "^1.0.2",
|
|
4016
|
+
"glob-parent": "^3.0.1",
|
|
3686
4017
|
gulp: "^4.0.2",
|
|
3687
4018
|
"gulp-watch": "^5.0.1",
|
|
3688
4019
|
htmlparser2: "^7.2.0",
|
|
@@ -3694,13 +4025,20 @@ var require$$7 = {
|
|
|
3694
4025
|
moment: "^2.29.2",
|
|
3695
4026
|
"object-assign": "^4.0.1",
|
|
3696
4027
|
ora: "^5.1.0",
|
|
4028
|
+
"path-is-absolute": "^1.0.1",
|
|
3697
4029
|
"plugin-error": "^1.0.0",
|
|
3698
4030
|
postcss: "^8.4.6",
|
|
3699
4031
|
precinct: "^8.3.1",
|
|
4032
|
+
"readable-stream": "^2.2.2",
|
|
3700
4033
|
"replace-ext": "^2.0.0",
|
|
4034
|
+
request: "^2.88.2",
|
|
3701
4035
|
shelljs: "^0.8.4",
|
|
4036
|
+
slash: "^1.0.0",
|
|
3702
4037
|
"strip-comments": "^2.0.1",
|
|
3703
4038
|
through2: "^4.0.2",
|
|
4039
|
+
unzipper: "^0.10.11",
|
|
4040
|
+
vinyl: "^2.1.0",
|
|
4041
|
+
"vinyl-file": "^2.0.0",
|
|
3704
4042
|
"vinyl-sourcemaps-apply": "^0.2.0"
|
|
3705
4043
|
},
|
|
3706
4044
|
engines: {
|