@tmsfe/tmskit 0.0.15 → 0.0.18
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 +20 -2
- package/README.md +2 -3
- package/build/publish.sh +34 -0
- package/dist/index.cjs.js +964 -602
- package/package.json +13 -2
- package/src/compile/compile.js +56 -35
- package/src/compile/dev.js +40 -31
- package/src/compile/plugins/gulp-watch/index.js +172 -0
- package/src/compile/plugins/mpJsonDep.js +1 -1
- package/src/compile/watch.js +51 -15
- package/src/config/constant.js +1 -3
- package/src/config/defaultTmsConfig.js +1 -1
- package/src/core/buildAppJson.js +43 -44
- package/src/core/cloneModules.js +3 -3
- package/src/core/tmsMpconfig.js +19 -57
- package/src/entry.js +12 -1
- package/src/scripts/run/build/index.js +7 -1
- package/src/scripts/run/cloud/index.js +12 -0
- package/src/scripts/run/dev/index.js +18 -10
- package/src/scripts/run/index.js +37 -16
- package/src/scripts/run/init/index.js +27 -15
- package/src/scripts/run/install/index.js +19 -12
- package/src/utils/io.js +20 -0
- package/src/utils/log.js +4 -4
- package/src/utils/widgets.js +20 -3
package/dist/index.cjs.js
CHANGED
|
@@ -17,13 +17,24 @@ var require$$1$5 = require('crypto');
|
|
|
17
17
|
var require$$0$7 = require('miniprogram-ci');
|
|
18
18
|
var require$$5 = require('glob-ignore');
|
|
19
19
|
var require$$1$6 = require('fs-extra');
|
|
20
|
+
var require$$1$7 = require('semver');
|
|
20
21
|
var require$$0$8 = require('strip-comments');
|
|
21
22
|
var require$$0$9 = require('through2');
|
|
22
|
-
var require$$1$
|
|
23
|
-
var require$$1$
|
|
23
|
+
var require$$1$8 = require('precinct');
|
|
24
|
+
var require$$1$9 = require('htmlparser2');
|
|
24
25
|
var require$$0$a = require('gulp');
|
|
25
|
-
var require$$0$b = require('
|
|
26
|
-
var require$$
|
|
26
|
+
var require$$0$b = require('object-assign');
|
|
27
|
+
var require$$3 = require('fancy-log');
|
|
28
|
+
var require$$4$1 = require('ansi-colors');
|
|
29
|
+
var require$$5$1 = require('chokidar');
|
|
30
|
+
var require$$6 = require('readable-stream');
|
|
31
|
+
var require$$7$1 = require('vinyl-file');
|
|
32
|
+
var require$$8 = require('vinyl');
|
|
33
|
+
var require$$9 = require('anymatch');
|
|
34
|
+
var require$$11 = require('glob-parent');
|
|
35
|
+
var require$$2$1 = require('plugin-error');
|
|
36
|
+
var require$$10 = require('path-is-absolute');
|
|
37
|
+
var require$$12 = require('slash');
|
|
27
38
|
|
|
28
39
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
29
40
|
|
|
@@ -44,13 +55,24 @@ var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
|
44
55
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
45
56
|
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
46
57
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
58
|
+
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
47
59
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
48
60
|
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
49
|
-
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
50
61
|
var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
|
|
62
|
+
var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
|
|
51
63
|
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
52
64
|
var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
|
|
53
|
-
var require$$
|
|
65
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
66
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
|
|
67
|
+
var require$$5__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
|
|
68
|
+
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
69
|
+
var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7$1);
|
|
70
|
+
var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
|
|
71
|
+
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
72
|
+
var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
|
|
73
|
+
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
74
|
+
var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
|
|
75
|
+
var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12);
|
|
54
76
|
|
|
55
77
|
function getAugmentedNamespace(n) {
|
|
56
78
|
if (n.__esModule) return n;
|
|
@@ -88,7 +110,7 @@ const fail$9 = (message = '') => {
|
|
|
88
110
|
|
|
89
111
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
90
112
|
|
|
91
|
-
console.log(
|
|
113
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
92
114
|
};
|
|
93
115
|
/**
|
|
94
116
|
* 打印绿底黑字格式的文字
|
|
@@ -97,12 +119,12 @@ const fail$9 = (message = '') => {
|
|
|
97
119
|
*/
|
|
98
120
|
|
|
99
121
|
|
|
100
|
-
const succeed$
|
|
122
|
+
const succeed$2 = (message = '') => {
|
|
101
123
|
const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
|
|
102
124
|
|
|
103
125
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
104
126
|
|
|
105
|
-
console.log(
|
|
127
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
106
128
|
};
|
|
107
129
|
/**
|
|
108
130
|
* 打印warn提示
|
|
@@ -111,16 +133,16 @@ const succeed$1 = (message = '') => {
|
|
|
111
133
|
*/
|
|
112
134
|
|
|
113
135
|
|
|
114
|
-
const warn = message => {
|
|
115
|
-
console.log(
|
|
136
|
+
const warn$2 = message => {
|
|
137
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
|
|
116
138
|
};
|
|
117
139
|
|
|
118
|
-
const info$9 = (...args) => console.log(
|
|
140
|
+
const info$9 = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
119
141
|
|
|
120
142
|
var log$1 = {
|
|
121
143
|
fail: fail$9,
|
|
122
|
-
succeed: succeed$
|
|
123
|
-
warn,
|
|
144
|
+
succeed: succeed$2,
|
|
145
|
+
warn: warn$2,
|
|
124
146
|
info: info$9
|
|
125
147
|
};
|
|
126
148
|
|
|
@@ -128,8 +150,8 @@ const program$1 = require$$0__default$1;
|
|
|
128
150
|
const leven = require$$1__default$1;
|
|
129
151
|
const ora = require$$2__default;
|
|
130
152
|
const path$b = require$$1__default$2;
|
|
131
|
-
const fs$
|
|
132
|
-
const shelljs$
|
|
153
|
+
const fs$e = require$$0__default$2;
|
|
154
|
+
const shelljs$7 = require$$0__default$3;
|
|
133
155
|
const {
|
|
134
156
|
info: info$8
|
|
135
157
|
} = log$1;
|
|
@@ -198,20 +220,20 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
198
220
|
const cwd = process.cwd();
|
|
199
221
|
return new Promise((resolve, reject) => {
|
|
200
222
|
// 如果目标目录不存在
|
|
201
|
-
if (fs$
|
|
202
|
-
shelljs$
|
|
223
|
+
if (fs$e.existsSync(dest)) {
|
|
224
|
+
shelljs$7.rm('-rf', path$b.join(dest));
|
|
203
225
|
}
|
|
204
226
|
|
|
205
|
-
shelljs$
|
|
206
|
-
shelljs$
|
|
207
|
-
shelljs$
|
|
227
|
+
shelljs$7.mkdir('-p', dest);
|
|
228
|
+
shelljs$7.cd(dest);
|
|
229
|
+
shelljs$7.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
|
|
208
230
|
silent: true
|
|
209
231
|
}, (code, stdout, stderr) => {
|
|
210
232
|
if (code !== 0) {
|
|
211
233
|
reject(stderr);
|
|
212
234
|
}
|
|
213
235
|
|
|
214
|
-
shelljs$
|
|
236
|
+
shelljs$7.cd(cwd);
|
|
215
237
|
resolve();
|
|
216
238
|
});
|
|
217
239
|
});
|
|
@@ -227,16 +249,16 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
227
249
|
function pullRepoForGit$1(dest, branch) {
|
|
228
250
|
const cwd = process.cwd();
|
|
229
251
|
return new Promise((resolve, reject) => {
|
|
230
|
-
shelljs$
|
|
231
|
-
shelljs$
|
|
232
|
-
shelljs$
|
|
252
|
+
shelljs$7.cd(dest);
|
|
253
|
+
shelljs$7.exec('git config pull.rebase false', shelljsOptions);
|
|
254
|
+
shelljs$7.exec(`git pull origin ${branch}`, {
|
|
233
255
|
silent: true
|
|
234
256
|
}, (code, stdout, stderr) => {
|
|
235
257
|
if (code !== 0) {
|
|
236
258
|
reject(stderr);
|
|
237
259
|
}
|
|
238
260
|
|
|
239
|
-
shelljs$
|
|
261
|
+
shelljs$7.cd(cwd);
|
|
240
262
|
resolve();
|
|
241
263
|
});
|
|
242
264
|
});
|
|
@@ -250,7 +272,7 @@ function pullRepoForGit$1(dest, branch) {
|
|
|
250
272
|
|
|
251
273
|
function npmInstall$1(dir) {
|
|
252
274
|
return new Promise((resolve, reject) => {
|
|
253
|
-
shelljs$
|
|
275
|
+
shelljs$7.exec('npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
254
276
|
cwd: dir,
|
|
255
277
|
silent: true
|
|
256
278
|
}, (code, stdout, stderr) => {
|
|
@@ -282,10 +304,11 @@ const cost = start => Date.now() - start;
|
|
|
282
304
|
function createTask$3(task, startText, endText) {
|
|
283
305
|
return async (...args) => {
|
|
284
306
|
const start = Date.now();
|
|
285
|
-
const spinner = ora(
|
|
307
|
+
const spinner = ora();
|
|
308
|
+
info$8(startText);
|
|
286
309
|
spinner.start();
|
|
287
310
|
const result = await task(...args);
|
|
288
|
-
endText && spinner.succeed(`${endText},
|
|
311
|
+
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
289
312
|
spinner.stop();
|
|
290
313
|
return result;
|
|
291
314
|
};
|
|
@@ -313,6 +336,24 @@ const mergeMap = function (obj, src) {
|
|
|
313
336
|
const relativeCwdPath$1 = function (file) {
|
|
314
337
|
return path$b.relative(process.cwd(), file);
|
|
315
338
|
};
|
|
339
|
+
/**
|
|
340
|
+
* 从一个对象中,检索出去几个字段
|
|
341
|
+
* @param {*} obj
|
|
342
|
+
* @param {*} name
|
|
343
|
+
* @returns
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
const filterField$3 = (obj, filterNames = []) => {
|
|
348
|
+
const newObj = { ...obj
|
|
349
|
+
};
|
|
350
|
+
filterNames.forEach(name => {
|
|
351
|
+
if (newObj[name]) {
|
|
352
|
+
delete newObj[name];
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
return newObj;
|
|
356
|
+
};
|
|
316
357
|
|
|
317
358
|
var widgets = {
|
|
318
359
|
resolve: resolve$f,
|
|
@@ -325,7 +366,8 @@ var widgets = {
|
|
|
325
366
|
camelize,
|
|
326
367
|
npmInstall: npmInstall$1,
|
|
327
368
|
mergeMap,
|
|
328
|
-
relativeCwdPath: relativeCwdPath$1
|
|
369
|
+
relativeCwdPath: relativeCwdPath$1,
|
|
370
|
+
filterField: filterField$3
|
|
329
371
|
};
|
|
330
372
|
|
|
331
373
|
const path$a = require('path');
|
|
@@ -335,13 +377,13 @@ const os = require('os'); // 用户目录
|
|
|
335
377
|
|
|
336
378
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
337
379
|
|
|
338
|
-
const CACHE_DIR$
|
|
380
|
+
const CACHE_DIR$2 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
339
381
|
|
|
340
|
-
const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$
|
|
382
|
+
const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
341
383
|
|
|
342
|
-
const MODULE_CODE_DIR$
|
|
384
|
+
const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
|
|
343
385
|
|
|
344
|
-
const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/
|
|
386
|
+
const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tmskit-template'); // 脚手架的名称
|
|
345
387
|
|
|
346
388
|
const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
|
|
347
389
|
|
|
@@ -364,12 +406,11 @@ const ENV = {
|
|
|
364
406
|
prod: 'production'
|
|
365
407
|
};
|
|
366
408
|
const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
367
|
-
const MODULE_CONFIG_INVALID_KEY$1 = ['entranceDeclare', 'entryPagePath'];
|
|
368
409
|
|
|
369
410
|
var constant = /*#__PURE__*/Object.freeze({
|
|
370
411
|
__proto__: null,
|
|
371
412
|
HOME_DIR: HOME_DIR,
|
|
372
|
-
CACHE_DIR: CACHE_DIR$
|
|
413
|
+
CACHE_DIR: CACHE_DIR$2,
|
|
373
414
|
TEMPLATE_DIR: TEMPLATE_DIR$1,
|
|
374
415
|
TEMPLATE_PATH: TEMPLATE_PATH$1,
|
|
375
416
|
TMS_NAME: TMS_NAME$1,
|
|
@@ -379,16 +420,15 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
379
420
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
380
421
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
381
422
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
382
|
-
MODULE_CODE_DIR: MODULE_CODE_DIR$
|
|
423
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
383
424
|
ENV: ENV,
|
|
384
425
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
385
|
-
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1,
|
|
386
426
|
DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
|
|
387
427
|
});
|
|
388
428
|
|
|
389
429
|
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
390
430
|
|
|
391
|
-
const fs$
|
|
431
|
+
const fs$d = require$$0__default$2;
|
|
392
432
|
const path$9 = require$$1__default$2;
|
|
393
433
|
const {
|
|
394
434
|
info: info$7
|
|
@@ -402,12 +442,12 @@ const {
|
|
|
402
442
|
* @returns
|
|
403
443
|
*/
|
|
404
444
|
|
|
405
|
-
const isDirEmpty = dirname => fs$
|
|
445
|
+
const isDirEmpty = dirname => fs$d.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
406
446
|
|
|
407
447
|
|
|
408
448
|
const isFile = pathName => {
|
|
409
449
|
try {
|
|
410
|
-
const stat = fs$
|
|
450
|
+
const stat = fs$d.lstatSync(pathName);
|
|
411
451
|
return stat.isFile();
|
|
412
452
|
} catch {
|
|
413
453
|
return false;
|
|
@@ -419,9 +459,9 @@ const isFile = pathName => {
|
|
|
419
459
|
*/
|
|
420
460
|
|
|
421
461
|
|
|
422
|
-
const ensureDirExist = dirname => {
|
|
423
|
-
if (!fs$
|
|
424
|
-
fs$
|
|
462
|
+
const ensureDirExist$1 = dirname => {
|
|
463
|
+
if (!fs$d.existsSync(dirname)) {
|
|
464
|
+
fs$d.mkdirSync(dirname, {
|
|
425
465
|
recursive: true
|
|
426
466
|
});
|
|
427
467
|
}
|
|
@@ -429,20 +469,20 @@ const ensureDirExist = dirname => {
|
|
|
429
469
|
|
|
430
470
|
|
|
431
471
|
const copyFile = function (src, dest) {
|
|
432
|
-
if (fs$
|
|
433
|
-
fs$
|
|
472
|
+
if (fs$d.existsSync(dest)) {
|
|
473
|
+
fs$d.unlinkSync(dest);
|
|
434
474
|
}
|
|
435
475
|
|
|
436
476
|
const dir = path$9.dirname(dest);
|
|
437
|
-
ensureDirExist(dir);
|
|
438
|
-
fs$
|
|
477
|
+
ensureDirExist$1(dir);
|
|
478
|
+
fs$d.copyFileSync(src, dest);
|
|
439
479
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
440
480
|
|
|
441
481
|
|
|
442
482
|
function diffContentCopyFile$3(originFile, destFile) {
|
|
443
|
-
if (fs$
|
|
444
|
-
const depDestContent = fs$
|
|
445
|
-
const depOriginContent = fs$
|
|
483
|
+
if (fs$d.existsSync(destFile)) {
|
|
484
|
+
const depDestContent = fs$d.readFileSync(destFile, 'utf8');
|
|
485
|
+
const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
|
|
446
486
|
|
|
447
487
|
if (depDestContent !== depOriginContent) {
|
|
448
488
|
info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
@@ -460,7 +500,7 @@ function ext$3(filePath, extensions) {
|
|
|
460
500
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
461
501
|
|
|
462
502
|
try {
|
|
463
|
-
const stat = fs$
|
|
503
|
+
const stat = fs$d.lstatSync(newFilePath);
|
|
464
504
|
|
|
465
505
|
if (stat.isDirectory()) {
|
|
466
506
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -471,7 +511,7 @@ function ext$3(filePath, extensions) {
|
|
|
471
511
|
for (const ext of extensions) {
|
|
472
512
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
473
513
|
|
|
474
|
-
if (fs$
|
|
514
|
+
if (fs$d.existsSync(file)) {
|
|
475
515
|
return {
|
|
476
516
|
ext,
|
|
477
517
|
extPath: extPath + ext,
|
|
@@ -489,7 +529,7 @@ function ext$3(filePath, extensions) {
|
|
|
489
529
|
|
|
490
530
|
|
|
491
531
|
const fileInDir$3 = (dir, file) => {
|
|
492
|
-
if (!fs$
|
|
532
|
+
if (!fs$d.existsSync(dir) || !fs$d.existsSync(file)) {
|
|
493
533
|
return false;
|
|
494
534
|
}
|
|
495
535
|
|
|
@@ -502,14 +542,37 @@ const fileInDir$3 = (dir, file) => {
|
|
|
502
542
|
return true;
|
|
503
543
|
};
|
|
504
544
|
|
|
505
|
-
|
|
545
|
+
function findAllFilesOfDir$1(dir) {
|
|
546
|
+
const list = [];
|
|
547
|
+
|
|
548
|
+
function listFile(dir) {
|
|
549
|
+
const arr = fs$d.readdirSync(dir);
|
|
550
|
+
arr.forEach(item => {
|
|
551
|
+
const fullPath = path$9.join(dir, item);
|
|
552
|
+
const stats = fs$d.statSync(fullPath);
|
|
553
|
+
|
|
554
|
+
if (stats.isDirectory()) {
|
|
555
|
+
listFile(fullPath);
|
|
556
|
+
} else {
|
|
557
|
+
list.push(fullPath);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
return list;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
listFile(dir);
|
|
564
|
+
return list;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
var io$3 = {
|
|
506
568
|
isDirEmpty,
|
|
507
569
|
copyFile,
|
|
508
570
|
diffContentCopyFile: diffContentCopyFile$3,
|
|
509
|
-
ensureDirExist,
|
|
571
|
+
ensureDirExist: ensureDirExist$1,
|
|
510
572
|
ext: ext$3,
|
|
511
573
|
fileInDir: fileInDir$3,
|
|
512
|
-
isFile
|
|
574
|
+
isFile,
|
|
575
|
+
findAllFilesOfDir: findAllFilesOfDir$1
|
|
513
576
|
};
|
|
514
577
|
|
|
515
578
|
const async = require$$0__default$4;
|
|
@@ -532,7 +595,7 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
532
595
|
|
|
533
596
|
var render_1 = render$1;
|
|
534
597
|
|
|
535
|
-
const fs$
|
|
598
|
+
const fs$c = require$$0__default$2;
|
|
536
599
|
const inquirer = require$$1__default$4;
|
|
537
600
|
const {
|
|
538
601
|
resolve: resolve$e
|
|
@@ -549,12 +612,12 @@ const {
|
|
|
549
612
|
const parseTemplateQuestions = dir => {
|
|
550
613
|
let prompts = [];
|
|
551
614
|
|
|
552
|
-
if (!fs$
|
|
615
|
+
if (!fs$c.existsSync(`${dir}/questions.json`)) {
|
|
553
616
|
return prompts;
|
|
554
617
|
}
|
|
555
618
|
|
|
556
619
|
try {
|
|
557
|
-
const json = JSON.parse(fs$
|
|
620
|
+
const json = JSON.parse(fs$c.readFileSync(`${dir}/questions.json`));
|
|
558
621
|
|
|
559
622
|
if (Array.isArray(json) && json.length > 0) {
|
|
560
623
|
json.forEach((item, index) => {
|
|
@@ -630,8 +693,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
630
693
|
var generator_1 = generator$1;
|
|
631
694
|
|
|
632
695
|
const path$8 = require$$1__default$2;
|
|
633
|
-
const fs$
|
|
634
|
-
const shelljs$
|
|
696
|
+
const fs$b = require$$0__default$2;
|
|
697
|
+
const shelljs$6 = require$$0__default$3;
|
|
635
698
|
const {
|
|
636
699
|
TEMPLATE_DIR,
|
|
637
700
|
TEMPLATE_PATH,
|
|
@@ -642,10 +705,10 @@ const {
|
|
|
642
705
|
createTask: createTask$2,
|
|
643
706
|
resolve: resolve$d
|
|
644
707
|
} = widgets;
|
|
645
|
-
const io$
|
|
708
|
+
const io$2 = io$3;
|
|
646
709
|
const {
|
|
647
710
|
fail: fail$8,
|
|
648
|
-
succeed,
|
|
711
|
+
succeed: succeed$1,
|
|
649
712
|
info: info$6
|
|
650
713
|
} = log$1;
|
|
651
714
|
const generator = generator_1;
|
|
@@ -657,13 +720,13 @@ const generator = generator_1;
|
|
|
657
720
|
|
|
658
721
|
async function createAppDir(targetDir) {
|
|
659
722
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
660
|
-
if (fs$
|
|
661
|
-
if (!(await io$
|
|
723
|
+
if (fs$b.existsSync(targetDir)) {
|
|
724
|
+
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
662
725
|
fail$8('该目录名已经存在,换个项目名字吧~');
|
|
663
726
|
process.exit(1);
|
|
664
727
|
}
|
|
665
728
|
} else {
|
|
666
|
-
shelljs$
|
|
729
|
+
shelljs$6.mkdir('-p', targetDir);
|
|
667
730
|
}
|
|
668
731
|
}
|
|
669
732
|
/**
|
|
@@ -679,7 +742,7 @@ async function create(appName) {
|
|
|
679
742
|
const appType = 'mp';
|
|
680
743
|
await createAppDir(targetDir); // 创建缓存目录
|
|
681
744
|
|
|
682
|
-
io$
|
|
745
|
+
io$2.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
|
|
683
746
|
|
|
684
747
|
await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
685
748
|
|
|
@@ -687,24 +750,24 @@ async function create(appName) {
|
|
|
687
750
|
appName,
|
|
688
751
|
appType
|
|
689
752
|
}).then(() => {
|
|
690
|
-
shelljs$
|
|
753
|
+
shelljs$6.cd(appName);
|
|
691
754
|
|
|
692
755
|
const hooks = require(resolve$d(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
693
756
|
|
|
694
757
|
if (hooks.afterCreate) {
|
|
695
758
|
hooks.afterCreate.forEach(item => {
|
|
696
759
|
if (typeof item === 'function') {
|
|
697
|
-
item.call(null, shelljs$
|
|
760
|
+
item.call(null, shelljs$6, {
|
|
698
761
|
appName
|
|
699
762
|
});
|
|
700
763
|
} else {
|
|
701
|
-
shelljs$
|
|
764
|
+
shelljs$6.exec(item);
|
|
702
765
|
}
|
|
703
766
|
});
|
|
704
767
|
}
|
|
705
768
|
|
|
706
|
-
shelljs$
|
|
707
|
-
succeed('项目创建完成.');
|
|
769
|
+
shelljs$6.rm('-rf', resolve$d(appName, TEMPLATE_TKIT_DIR));
|
|
770
|
+
succeed$1('项目创建完成.');
|
|
708
771
|
}).catch(err => {
|
|
709
772
|
fail$8(err.message);
|
|
710
773
|
info$6('详细的错误信息:', err);
|
|
@@ -717,7 +780,7 @@ var defaultTmsConfig$1 = {
|
|
|
717
780
|
// 全局的环境配置项
|
|
718
781
|
envData: {},
|
|
719
782
|
// 模块配置信息
|
|
720
|
-
modules:
|
|
783
|
+
modules: {},
|
|
721
784
|
cloudDir: 'cloud',
|
|
722
785
|
// 第三方依赖代码需要拷贝到本项目的
|
|
723
786
|
dependencies: {},
|
|
@@ -735,8 +798,8 @@ var defaultTmsConfig$1 = {
|
|
|
735
798
|
/**
|
|
736
799
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
737
800
|
*/
|
|
738
|
-
const loadash = require$$0__default$6;
|
|
739
|
-
const fs$
|
|
801
|
+
const loadash$1 = require$$0__default$6;
|
|
802
|
+
const fs$a = require$$0__default$2;
|
|
740
803
|
const {
|
|
741
804
|
TMS_CONFIG_FILENAME,
|
|
742
805
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
@@ -751,7 +814,6 @@ const defaultTmsConfig = defaultTmsConfig$1;
|
|
|
751
814
|
const {
|
|
752
815
|
fail: fail$7
|
|
753
816
|
} = log$1;
|
|
754
|
-
const path$7 = require$$1__default$2;
|
|
755
817
|
/**
|
|
756
818
|
* 读取tms.config.js
|
|
757
819
|
* @param env {string} 环境变量
|
|
@@ -760,7 +822,7 @@ const path$7 = require$$1__default$2;
|
|
|
760
822
|
const readTmsConfig$1 = function (env) {
|
|
761
823
|
const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
|
|
762
824
|
|
|
763
|
-
if (!fs$
|
|
825
|
+
if (!fs$a.existsSync(tmsConfigPath)) {
|
|
764
826
|
fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
765
827
|
process.exit(1);
|
|
766
828
|
}
|
|
@@ -771,35 +833,8 @@ const readTmsConfig$1 = function (env) {
|
|
|
771
833
|
env
|
|
772
834
|
}); // 合并默认值
|
|
773
835
|
|
|
774
|
-
loadash.mergeWith(tmsConfig, defaultTmsConfig);
|
|
775
|
-
|
|
776
|
-
tmsConfig.modules = convertModules(tmsConfig.modules);
|
|
836
|
+
loadash$1.mergeWith(tmsConfig, defaultTmsConfig);
|
|
777
837
|
return tmsConfig;
|
|
778
|
-
}; // convertModules 处理默认值
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
const convertModules = modules => {
|
|
782
|
-
const newModules = [];
|
|
783
|
-
modules.forEach(module => {
|
|
784
|
-
const newModule = {};
|
|
785
|
-
|
|
786
|
-
if (typeof module === 'string') {
|
|
787
|
-
// 路径字符串
|
|
788
|
-
Object.assign(newModule, {
|
|
789
|
-
name: path$7.basename(module),
|
|
790
|
-
path: module
|
|
791
|
-
});
|
|
792
|
-
} else if (typeof module === 'object') {
|
|
793
|
-
Object.assign(newModule, module);
|
|
794
|
-
|
|
795
|
-
if (module.name === undefined) {
|
|
796
|
-
newModule.name = path$7.basename(module.path);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
newModules.push(newModule);
|
|
801
|
-
});
|
|
802
|
-
return newModules;
|
|
803
838
|
};
|
|
804
839
|
/**
|
|
805
840
|
* 读取tms.private.config.js
|
|
@@ -810,15 +845,8 @@ const readTmsPrivateCf$1 = function () {
|
|
|
810
845
|
let tmsPrivateCf = {};
|
|
811
846
|
const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
|
|
812
847
|
|
|
813
|
-
if (fs$
|
|
848
|
+
if (fs$a.existsSync(tmsPrivatePath)) {
|
|
814
849
|
tmsPrivateCf = require(tmsPrivatePath);
|
|
815
|
-
} // 处理modules字段
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
if (tmsPrivateCf.modules instanceof Array) {
|
|
819
|
-
Object.assign(tmsPrivateCf.modules, {
|
|
820
|
-
include: tmsPrivateCf.modules
|
|
821
|
-
});
|
|
822
850
|
}
|
|
823
851
|
|
|
824
852
|
return tmsPrivateCf;
|
|
@@ -834,7 +862,7 @@ const readTmsPrivateCf$1 = function () {
|
|
|
834
862
|
const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
|
|
835
863
|
const targetModules = [];
|
|
836
864
|
modules.forEach(moduleName => {
|
|
837
|
-
const module = tmsConfig.modules.find(module => module.name === moduleName);
|
|
865
|
+
const module = tmsConfig.modules.all.find(module => module.name === moduleName);
|
|
838
866
|
module && targetModules.push(module);
|
|
839
867
|
});
|
|
840
868
|
|
|
@@ -846,18 +874,6 @@ const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
|
|
|
846
874
|
|
|
847
875
|
return targetModules;
|
|
848
876
|
};
|
|
849
|
-
/**
|
|
850
|
-
* 过滤页面为空的分包
|
|
851
|
-
* @param {Array} moduleCfg 模块配置内容
|
|
852
|
-
* @returns pages不为空的分包
|
|
853
|
-
*/
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
const getValidModules$1 = moduleCfg => {
|
|
857
|
-
// 过滤 pages 为空的情况
|
|
858
|
-
const validModules = moduleCfg.filter(item => item.pages.length > 0);
|
|
859
|
-
return validModules;
|
|
860
|
-
};
|
|
861
877
|
/**
|
|
862
878
|
* 适配处理module.config.json的字段
|
|
863
879
|
* @param { object } fileContent module.config.json的内容
|
|
@@ -866,25 +882,31 @@ const getValidModules$1 = moduleCfg => {
|
|
|
866
882
|
|
|
867
883
|
|
|
868
884
|
function adaptMpCgContent(fileContent, appName) {
|
|
869
|
-
const
|
|
885
|
+
const handleContent = function (appName, current) {
|
|
886
|
+
let res = current;
|
|
887
|
+
|
|
888
|
+
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
889
|
+
res = { ...current,
|
|
890
|
+
...current.mpConfig[appName]
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
delete res.mpConfig;
|
|
895
|
+
delete res.isSubpackages;
|
|
896
|
+
return res;
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
let content = JSON.parse(fileContent);
|
|
870
900
|
|
|
871
901
|
if (isArray(content)) {
|
|
872
902
|
let i = content.length - 1;
|
|
873
903
|
|
|
874
904
|
while (i >= 0) {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
878
|
-
current = { ...current,
|
|
879
|
-
...current.mpConfig[appName]
|
|
880
|
-
};
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
delete current.mpConfig;
|
|
884
|
-
delete current.isSubpackages;
|
|
885
|
-
content[i] = current;
|
|
905
|
+
content[i] = handleContent(appName, content[i]);
|
|
886
906
|
i--; // eslint-disable-line
|
|
887
907
|
}
|
|
908
|
+
} else {
|
|
909
|
+
content = handleContent(appName, content);
|
|
888
910
|
}
|
|
889
911
|
|
|
890
912
|
return content;
|
|
@@ -904,8 +926,8 @@ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
|
|
|
904
926
|
}) => {
|
|
905
927
|
const moduleConfigPath = resolve$c(path, moduleConfigFilename);
|
|
906
928
|
|
|
907
|
-
if (fs$
|
|
908
|
-
const content = fs$
|
|
929
|
+
if (fs$a.existsSync(moduleConfigPath)) {
|
|
930
|
+
const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
909
931
|
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
910
932
|
}
|
|
911
933
|
});
|
|
@@ -928,13 +950,13 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
928
950
|
}, moduleIndex) => {
|
|
929
951
|
const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
930
952
|
|
|
931
|
-
if (fs$
|
|
953
|
+
if (fs$a.existsSync(moduleConfigPath)) {
|
|
932
954
|
try {
|
|
933
955
|
let findModule = false;
|
|
934
|
-
let moduleConfigContent = fs$
|
|
956
|
+
let moduleConfigContent = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
935
957
|
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
936
958
|
const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
937
|
-
|
|
959
|
+
moduleContentArr.forEach(({
|
|
938
960
|
name
|
|
939
961
|
}, moduleContentArrIndex) => {
|
|
940
962
|
if (name === moduleName) {
|
|
@@ -946,7 +968,7 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
946
968
|
});
|
|
947
969
|
|
|
948
970
|
if (!findModule) {
|
|
949
|
-
fail$7(`启动模块${moduleName}在${moduleConfigPath}
|
|
971
|
+
fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
|
|
950
972
|
process.exit(1);
|
|
951
973
|
}
|
|
952
974
|
} catch (e) {
|
|
@@ -1003,7 +1025,6 @@ var tmsMpconfig = {
|
|
|
1003
1025
|
readTmsConfig: readTmsConfig$1,
|
|
1004
1026
|
readTmsPrivateCf: readTmsPrivateCf$1,
|
|
1005
1027
|
getModuleConfig: getModuleConfig$1,
|
|
1006
|
-
getValidModules: getValidModules$1,
|
|
1007
1028
|
checkModules: checkModules$1,
|
|
1008
1029
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
1009
1030
|
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
@@ -1041,7 +1062,7 @@ const {
|
|
|
1041
1062
|
global: global$5
|
|
1042
1063
|
} = global_1;
|
|
1043
1064
|
|
|
1044
|
-
function handleError$
|
|
1065
|
+
function handleError$6(error) {
|
|
1045
1066
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1046
1067
|
const isDev = global$5.getData('isDev');
|
|
1047
1068
|
|
|
@@ -1054,31 +1075,35 @@ function handleError$4(error) {
|
|
|
1054
1075
|
}
|
|
1055
1076
|
|
|
1056
1077
|
var handleError_1 = {
|
|
1057
|
-
handleError: handleError$
|
|
1078
|
+
handleError: handleError$6
|
|
1058
1079
|
};
|
|
1059
1080
|
|
|
1060
1081
|
/**
|
|
1061
1082
|
* 生成编译后的app.json
|
|
1062
1083
|
*/
|
|
1063
|
-
|
|
1084
|
+
/* eslint-disable no-param-reassign */
|
|
1085
|
+
|
|
1086
|
+
const fs$9 = require$$0__default$2;
|
|
1064
1087
|
const {
|
|
1065
|
-
MODULE_CONFIG_FILENAME
|
|
1066
|
-
MODULE_CONFIG_INVALID_KEY
|
|
1088
|
+
MODULE_CONFIG_FILENAME
|
|
1067
1089
|
} = require$$4;
|
|
1068
1090
|
const {
|
|
1069
|
-
getModuleConfig
|
|
1070
|
-
getValidModules
|
|
1091
|
+
getModuleConfig
|
|
1071
1092
|
} = tmsMpconfig;
|
|
1072
1093
|
const {
|
|
1073
1094
|
fail: fail$5
|
|
1074
1095
|
} = log$1;
|
|
1075
1096
|
const {
|
|
1076
1097
|
resolve: resolve$b,
|
|
1077
|
-
isObject
|
|
1098
|
+
isObject,
|
|
1099
|
+
filterField: filterField$2
|
|
1078
1100
|
} = widgets;
|
|
1079
1101
|
const {
|
|
1080
|
-
handleError: handleError$
|
|
1102
|
+
handleError: handleError$5
|
|
1081
1103
|
} = handleError_1;
|
|
1104
|
+
const {
|
|
1105
|
+
global: global$4
|
|
1106
|
+
} = global_1;
|
|
1082
1107
|
/**
|
|
1083
1108
|
* 更新appJson里面的主包配置
|
|
1084
1109
|
* @param { object } appJson appJson信息
|
|
@@ -1110,8 +1135,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1110
1135
|
}
|
|
1111
1136
|
}); // 去掉 subpackages 中的主包配置
|
|
1112
1137
|
|
|
1113
|
-
const foundMainPackageNames = foundMainPackages.map(item => item.name);
|
|
1114
|
-
|
|
1138
|
+
const foundMainPackageNames = foundMainPackages.map(item => item.name);
|
|
1115
1139
|
appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
|
|
1116
1140
|
return appJson;
|
|
1117
1141
|
}
|
|
@@ -1123,35 +1147,32 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1123
1147
|
|
|
1124
1148
|
|
|
1125
1149
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
1126
|
-
if (!fs$
|
|
1150
|
+
if (!fs$9.existsSync(sourceAppJsonPath)) {
|
|
1127
1151
|
fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1128
1152
|
process.exit(1);
|
|
1129
1153
|
}
|
|
1130
1154
|
|
|
1131
|
-
const appJson = JSON.parse(fs$
|
|
1155
|
+
const appJson = JSON.parse(fs$9.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1132
1156
|
|
|
1133
1157
|
appJson.subpackages = [];
|
|
1134
|
-
appJson.pages = [];
|
|
1135
|
-
|
|
1136
|
-
delete appJson.entranceDeclare;
|
|
1158
|
+
appJson.pages = [];
|
|
1137
1159
|
return appJson;
|
|
1138
1160
|
};
|
|
1139
1161
|
/**
|
|
1140
1162
|
* 更新app.json中的subpackages
|
|
1141
1163
|
* @param {Object} appJson
|
|
1142
|
-
* @param {Object}
|
|
1164
|
+
* @param {Object} modulesConfigs
|
|
1143
1165
|
*/
|
|
1144
1166
|
|
|
1145
1167
|
|
|
1146
|
-
const updateSubpackages = (appJson,
|
|
1168
|
+
const updateSubpackages = (appJson, modulesConfigs) => {
|
|
1147
1169
|
// eslint-disable-next-line
|
|
1148
|
-
for (const
|
|
1149
|
-
const moduleInfo = isObject(
|
|
1150
|
-
|
|
1151
|
-
const validModules = getValidModules(moduleInfo); // eslint-disable-next-line
|
|
1152
|
-
|
|
1153
|
-
appJson.subpackages = appJson.subpackages.concat(validModules);
|
|
1170
|
+
for (const modulePath in modulesConfigs) {
|
|
1171
|
+
const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
|
|
1172
|
+
appJson.subpackages = appJson.subpackages.concat(moduleInfo);
|
|
1154
1173
|
}
|
|
1174
|
+
|
|
1175
|
+
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
1155
1176
|
};
|
|
1156
1177
|
/**
|
|
1157
1178
|
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
@@ -1166,44 +1187,33 @@ const fixAppJson = appJson => {
|
|
|
1166
1187
|
const pluginsMap = {};
|
|
1167
1188
|
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1168
1189
|
const subps = subpackages.map(subp => {
|
|
1169
|
-
const
|
|
1190
|
+
const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList'];
|
|
1191
|
+
const objOfFileType = ['preloadRule'];
|
|
1170
1192
|
Object.keys(subp).forEach(key => {
|
|
1171
|
-
if (key === 'dependencies') {
|
|
1172
|
-
// eslint-disable-next-line
|
|
1173
|
-
delete subp.dependencies;
|
|
1174
|
-
return;
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
1193
|
if (key === 'plugins') {
|
|
1178
1194
|
Object.keys(subp.plugins).forEach(pk => {
|
|
1179
1195
|
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
1180
1196
|
});
|
|
1181
|
-
|
|
1182
|
-
}
|
|
1197
|
+
} // 分包里数组类型字段,提到appjson最上层
|
|
1183
1198
|
|
|
1184
|
-
if (MODULE_CONFIG_INVALID_KEY.indexOf(key) > -1) {
|
|
1185
|
-
// 如果分包配置中有不支持的key,则错误提醒
|
|
1186
|
-
invalidKeys.push(key);
|
|
1187
|
-
return;
|
|
1188
|
-
}
|
|
1189
1199
|
|
|
1190
|
-
if (
|
|
1191
|
-
|
|
1192
|
-
|
|
1200
|
+
if (arrOfFileType.indexOf(key) > -1) {
|
|
1201
|
+
const preVal = appJson[key];
|
|
1202
|
+
preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
1203
|
+
} // 分包里对象类型字段,提到appjson最上层
|
|
1193
1204
|
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1205
|
+
|
|
1206
|
+
if (objOfFileType.indexOf(key) > -1) {
|
|
1207
|
+
const preloadRuleMap = appJson[key] || {};
|
|
1208
|
+
subp[key] && Object.keys(subp[key]).forEach(page => {
|
|
1209
|
+
if (!preloadRuleMap[page]) {
|
|
1210
|
+
preloadRuleMap[page] = subp[key][page];
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
appJson[key] = preloadRuleMap;
|
|
1197
1214
|
}
|
|
1198
1215
|
});
|
|
1199
|
-
|
|
1200
|
-
if (invalidKeys.length) {
|
|
1201
|
-
fail$5(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
1202
|
-
} // eslint-disable-next-line
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
invalidKeys.concat(['requiredBackgroundModes', 'embeddedAppIdList']).forEach(k => delete subp[k]);
|
|
1206
|
-
return subp;
|
|
1216
|
+
return filterField$2(subp, [...arrOfFileType, ...objOfFileType, 'dependencies']);
|
|
1207
1217
|
}); // 如果plugins重复,则错误提示
|
|
1208
1218
|
|
|
1209
1219
|
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
@@ -1215,9 +1225,8 @@ const fixAppJson = appJson => {
|
|
|
1215
1225
|
}).reduce((pre, cur) => pre + cur, '');
|
|
1216
1226
|
|
|
1217
1227
|
if (pluginsErrMsg) {
|
|
1218
|
-
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1228
|
+
throw new Error(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1229
|
+
}
|
|
1221
1230
|
|
|
1222
1231
|
appJson.subpackages = subps;
|
|
1223
1232
|
};
|
|
@@ -1231,20 +1240,34 @@ const fixAppJson = appJson => {
|
|
|
1231
1240
|
|
|
1232
1241
|
function buildOutputAppJson$1(tmsConfig, modules) {
|
|
1233
1242
|
try {
|
|
1243
|
+
var _tmsConfig$hooks;
|
|
1244
|
+
|
|
1234
1245
|
// 获取当前 modules 下的所有子模块的配置内容
|
|
1235
|
-
const
|
|
1246
|
+
const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1236
1247
|
|
|
1237
1248
|
const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
|
|
1238
1249
|
|
|
1239
|
-
updateSubpackages(appJson,
|
|
1250
|
+
updateSubpackages(appJson, modulesConfigs); // 处理appJson中重复||冲突的地方
|
|
1240
1251
|
|
|
1241
1252
|
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1242
1253
|
|
|
1243
1254
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1244
|
-
fs$
|
|
1255
|
+
fs$9.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1256
|
+
|
|
1257
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1258
|
+
var _tmsConfig$hooks2;
|
|
1259
|
+
|
|
1260
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1261
|
+
tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
|
|
1262
|
+
modules,
|
|
1263
|
+
appJson,
|
|
1264
|
+
isDev: global$4.getData('isDev')
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1245
1268
|
return appJson;
|
|
1246
1269
|
} catch (e) {
|
|
1247
|
-
handleError$
|
|
1270
|
+
handleError$5(`生成app.json出现错误: ${e}`);
|
|
1248
1271
|
}
|
|
1249
1272
|
}
|
|
1250
1273
|
|
|
@@ -1266,13 +1289,13 @@ const {
|
|
|
1266
1289
|
fail: fail$4,
|
|
1267
1290
|
info: info$5
|
|
1268
1291
|
} = log$1;
|
|
1269
|
-
const fs$
|
|
1270
|
-
const shelljs$
|
|
1292
|
+
const fs$8 = require$$0__default$2;
|
|
1293
|
+
const shelljs$5 = require$$0__default$3;
|
|
1271
1294
|
const {
|
|
1272
|
-
handleError: handleError$
|
|
1295
|
+
handleError: handleError$4
|
|
1273
1296
|
} = handleError_1;
|
|
1274
1297
|
const {
|
|
1275
|
-
global: global$
|
|
1298
|
+
global: global$3
|
|
1276
1299
|
} = global_1;
|
|
1277
1300
|
/**
|
|
1278
1301
|
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
@@ -1282,15 +1305,15 @@ const {
|
|
|
1282
1305
|
*/
|
|
1283
1306
|
|
|
1284
1307
|
function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
1285
|
-
var
|
|
1308
|
+
var _tmsConfig$gitAccout, _tmsConfig$gitAccount;
|
|
1286
1309
|
|
|
1287
1310
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1288
|
-
const
|
|
1311
|
+
const tmsConfig = global$3.getData('tmsConfig');
|
|
1289
1312
|
let gitUrl = httpRepoUrl;
|
|
1290
1313
|
const {
|
|
1291
1314
|
username = '',
|
|
1292
1315
|
pass = ''
|
|
1293
|
-
} = (
|
|
1316
|
+
} = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccout = tmsConfig.gitAccout) === null || _tmsConfig$gitAccout === void 0 ? void 0 : _tmsConfig$gitAccout[moduleName]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
|
|
1294
1317
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
1295
1318
|
|
|
1296
1319
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -1362,11 +1385,11 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1362
1385
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1363
1386
|
return Promise.all(callArr);
|
|
1364
1387
|
}).catch(e => {
|
|
1365
|
-
handleError$
|
|
1388
|
+
handleError$4(`下载代码${params.httpRepoUrl}出现错误:${e}`);
|
|
1366
1389
|
}));
|
|
1367
1390
|
});
|
|
1368
1391
|
await Promise.all(arrPromises);
|
|
1369
|
-
shelljs$
|
|
1392
|
+
shelljs$5.cd(cwd);
|
|
1370
1393
|
}
|
|
1371
1394
|
/**
|
|
1372
1395
|
* 收集下载模块代码的任务
|
|
@@ -1419,8 +1442,8 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1419
1442
|
targetPath
|
|
1420
1443
|
},
|
|
1421
1444
|
fn: async (sourceModulePath, targetPath) => {
|
|
1422
|
-
if (fs$
|
|
1423
|
-
shelljs$
|
|
1445
|
+
if (fs$8.existsSync(targetPath)) {
|
|
1446
|
+
shelljs$5.rm('-rf', `${targetPath}/*`);
|
|
1424
1447
|
}
|
|
1425
1448
|
|
|
1426
1449
|
await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
|
|
@@ -1434,7 +1457,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1434
1457
|
} else {
|
|
1435
1458
|
let promiseTask;
|
|
1436
1459
|
|
|
1437
|
-
if (fs$
|
|
1460
|
+
if (fs$8.existsSync(sourcePath) && fs$8.existsSync(`${sourcePath}/.git`)) {
|
|
1438
1461
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1439
1462
|
info$5(`git pull:${httpRepoUrl}`);
|
|
1440
1463
|
return pullRepoForGit(sourcePath, branch);
|
|
@@ -1470,7 +1493,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1470
1493
|
*/
|
|
1471
1494
|
|
|
1472
1495
|
|
|
1473
|
-
function checkRemoteModGitUrlBranch
|
|
1496
|
+
function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
1474
1497
|
if (moduleInfo.repoInfo) {
|
|
1475
1498
|
const {
|
|
1476
1499
|
repoInfo: {
|
|
@@ -1482,7 +1505,7 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
|
|
|
1482
1505
|
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
|
|
1483
1506
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1484
1507
|
|
|
1485
|
-
if (!fs$
|
|
1508
|
+
if (!fs$8.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1486
1509
|
return true;
|
|
1487
1510
|
}
|
|
1488
1511
|
}
|
|
@@ -1492,11 +1515,11 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
|
|
|
1492
1515
|
|
|
1493
1516
|
var cloneModules_1 = {
|
|
1494
1517
|
cloneModules: cloneModules$1,
|
|
1495
|
-
checkRemoteModGitUrlBranch
|
|
1518
|
+
checkRemoteModGitUrlBranch
|
|
1496
1519
|
};
|
|
1497
1520
|
|
|
1498
1521
|
const ci = require$$0__default$7;
|
|
1499
|
-
const path$
|
|
1522
|
+
const path$7 = require$$1__default$2;
|
|
1500
1523
|
/**
|
|
1501
1524
|
* 获取小程序ci的Project对象
|
|
1502
1525
|
* @returns {Object} 小程序ci对象
|
|
@@ -1510,7 +1533,7 @@ const getMpCi = ({
|
|
|
1510
1533
|
}) => {
|
|
1511
1534
|
var _cfgJsonContent$packO;
|
|
1512
1535
|
|
|
1513
|
-
const cfgJsonContent = require(path$
|
|
1536
|
+
const cfgJsonContent = require(path$7.join(projectPath, 'project.config.json'));
|
|
1514
1537
|
|
|
1515
1538
|
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
1516
1539
|
value
|
|
@@ -1579,10 +1602,10 @@ var mpCi = {
|
|
|
1579
1602
|
/**
|
|
1580
1603
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1581
1604
|
*/
|
|
1582
|
-
const fs$
|
|
1605
|
+
const fs$7 = require$$0__default$2;
|
|
1583
1606
|
const fsExtra = require$$1__default$6;
|
|
1584
1607
|
const crypto = require$$1__default$5;
|
|
1585
|
-
const path$
|
|
1608
|
+
const path$6 = require$$1__default$2;
|
|
1586
1609
|
const shell = require$$0__default$3;
|
|
1587
1610
|
const glob = require$$5__default;
|
|
1588
1611
|
const log = log$1;
|
|
@@ -1590,7 +1613,7 @@ const {
|
|
|
1590
1613
|
npmInstall
|
|
1591
1614
|
} = widgets;
|
|
1592
1615
|
const {
|
|
1593
|
-
handleError: handleError$
|
|
1616
|
+
handleError: handleError$3
|
|
1594
1617
|
} = handleError_1;
|
|
1595
1618
|
const shellJsOption = {
|
|
1596
1619
|
async: false,
|
|
@@ -1614,7 +1637,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1614
1637
|
const npmTasksMap = new Map();
|
|
1615
1638
|
|
|
1616
1639
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1617
|
-
const packageContent = fs$
|
|
1640
|
+
const packageContent = fs$7.readFileSync(packageJsonPath);
|
|
1618
1641
|
const packageJson = JSON.parse(packageContent);
|
|
1619
1642
|
const md5Obj = {
|
|
1620
1643
|
dependencies: packageJson.dependencies || {}
|
|
@@ -1622,14 +1645,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1622
1645
|
|
|
1623
1646
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1624
1647
|
const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1625
|
-
const cacheNMPath = path$
|
|
1626
|
-
const cacheNMTarFile = path$
|
|
1648
|
+
const cacheNMPath = path$6.join(cacheDir, md5Key);
|
|
1649
|
+
const cacheNMTarFile = path$6.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1627
1650
|
|
|
1628
1651
|
const callback = {
|
|
1629
1652
|
params: {
|
|
1630
1653
|
cacheNMPath,
|
|
1631
1654
|
cacheNMTarFile,
|
|
1632
|
-
packageJsonDir: path$
|
|
1655
|
+
packageJsonDir: path$6.dirname(packageJsonPath),
|
|
1633
1656
|
shell
|
|
1634
1657
|
},
|
|
1635
1658
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
@@ -1705,7 +1728,7 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
|
1705
1728
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1706
1729
|
return Promise.all(callArr);
|
|
1707
1730
|
}).catch(e => {
|
|
1708
|
-
handleError$
|
|
1731
|
+
handleError$3(`npm install ${params.packageJsonPath}出现错误:${e}`);
|
|
1709
1732
|
}));
|
|
1710
1733
|
});
|
|
1711
1734
|
await Promise.all(arrPromises);
|
|
@@ -1730,7 +1753,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1730
1753
|
|
|
1731
1754
|
const find = (startPath, filter) => {
|
|
1732
1755
|
// 目录不存在
|
|
1733
|
-
if (!fs$
|
|
1756
|
+
if (!fs$7.existsSync(startPath)) {
|
|
1734
1757
|
log.fail(`${startPath}目录不存在`);
|
|
1735
1758
|
process.exit(-1);
|
|
1736
1759
|
return;
|
|
@@ -1743,10 +1766,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1743
1766
|
return;
|
|
1744
1767
|
}
|
|
1745
1768
|
|
|
1746
|
-
const files = fs$
|
|
1769
|
+
const files = fs$7.readdirSync(startPath);
|
|
1747
1770
|
files.forEach(file => {
|
|
1748
|
-
const filename = path$
|
|
1749
|
-
const stat = fs$
|
|
1771
|
+
const filename = path$6.join(startPath, file);
|
|
1772
|
+
const stat = fs$7.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1750
1773
|
|
|
1751
1774
|
if (stat.isDirectory()) {
|
|
1752
1775
|
find(filename, filter);
|
|
@@ -1772,7 +1795,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1772
1795
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1773
1796
|
|
|
1774
1797
|
const cwd = contextDir || dirPath;
|
|
1775
|
-
const result = [path$
|
|
1798
|
+
const result = [path$6.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1776
1799
|
|
|
1777
1800
|
subRoots.forEach(subRoot => {
|
|
1778
1801
|
if (!subRoot.root) {
|
|
@@ -1780,7 +1803,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1780
1803
|
process.exit(1);
|
|
1781
1804
|
}
|
|
1782
1805
|
|
|
1783
|
-
const toppath = path$
|
|
1806
|
+
const toppath = path$6.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1784
1807
|
|
|
1785
1808
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1786
1809
|
result.push(...list);
|
|
@@ -1788,7 +1811,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1788
1811
|
return result;
|
|
1789
1812
|
};
|
|
1790
1813
|
|
|
1791
|
-
function cloudNpmInstall
|
|
1814
|
+
function cloudNpmInstall(contextDir) {
|
|
1792
1815
|
return new Promise((resolve, reject) => {
|
|
1793
1816
|
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
1794
1817
|
if (err) {
|
|
@@ -1796,7 +1819,7 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1796
1819
|
}
|
|
1797
1820
|
|
|
1798
1821
|
files.forEach(file => {
|
|
1799
|
-
const dir = path$
|
|
1822
|
+
const dir = path$6.dirname(file);
|
|
1800
1823
|
shell.cd(dir);
|
|
1801
1824
|
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1802
1825
|
silent: false
|
|
@@ -1808,11 +1831,14 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1808
1831
|
}
|
|
1809
1832
|
|
|
1810
1833
|
var npm = {
|
|
1811
|
-
cloudNpmInstall
|
|
1834
|
+
cloudNpmInstall,
|
|
1812
1835
|
mpNpmInstallAll: mpNpmInstallAll$1,
|
|
1813
1836
|
findAllPackageJson
|
|
1814
1837
|
};
|
|
1815
1838
|
|
|
1839
|
+
const shelljs$4 = require$$0__default$3;
|
|
1840
|
+
const fs$6 = require$$0__default$2;
|
|
1841
|
+
const io$1 = io$3;
|
|
1816
1842
|
const {
|
|
1817
1843
|
createTask: createTask$1,
|
|
1818
1844
|
resolve: resolve$9
|
|
@@ -1821,44 +1847,145 @@ const {
|
|
|
1821
1847
|
buildMpNpm
|
|
1822
1848
|
} = mpCi;
|
|
1823
1849
|
const {
|
|
1824
|
-
CACHE_DIR
|
|
1850
|
+
CACHE_DIR: CACHE_DIR$1
|
|
1825
1851
|
} = require$$4;
|
|
1826
1852
|
const {
|
|
1827
|
-
cloudNpmInstall,
|
|
1828
1853
|
mpNpmInstallAll
|
|
1829
1854
|
} = npm;
|
|
1830
1855
|
const {
|
|
1831
|
-
|
|
1832
|
-
} =
|
|
1856
|
+
fail: fail$3
|
|
1857
|
+
} = log$1;
|
|
1858
|
+
|
|
1859
|
+
async function install$2(tmsConfig, modules) {
|
|
1860
|
+
// 拷贝模块的package.json到编译输出目录
|
|
1861
|
+
modules.forEach(item => {
|
|
1862
|
+
const outputModuleDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
|
|
1863
|
+
|
|
1864
|
+
if (!fs$6.existsSync(resolve$9(item.path))) {
|
|
1865
|
+
fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1866
|
+
process.exit(1);
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
io$1.ensureDirExist(outputModuleDir);
|
|
1870
|
+
const modulePackagePath = resolve$9(item.path, 'package.json');
|
|
1871
|
+
if (fs$6.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1872
|
+
}); // 小程序npm install
|
|
1833
1873
|
|
|
1834
|
-
|
|
1835
|
-
// 小程序npm install
|
|
1836
|
-
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
|
|
1837
|
-
const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1874
|
+
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`); // 构建miniprogram_npm
|
|
1838
1875
|
|
|
1839
1876
|
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1840
1877
|
appId: tmsConfig.appId,
|
|
1841
1878
|
projectPath: resolve$9('./'),
|
|
1842
|
-
privateKey:
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$9(tmsConfig.cloudDir));
|
|
1879
|
+
privateKey: tmsConfig.privateKey
|
|
1880
|
+
});
|
|
1846
1881
|
}
|
|
1847
1882
|
|
|
1848
1883
|
var install_1 = install$2;
|
|
1849
1884
|
|
|
1850
|
-
const shelljs$3 = require$$0__default$3;
|
|
1851
1885
|
const fs$5 = require$$0__default$2;
|
|
1852
|
-
const
|
|
1886
|
+
const semver$1 = require$$1__default$7;
|
|
1887
|
+
const {
|
|
1888
|
+
resolve: resolve$8
|
|
1889
|
+
} = widgets;
|
|
1890
|
+
const path$5 = require$$1__default$2;
|
|
1891
|
+
const shelljs$3 = require$$0__default$3;
|
|
1892
|
+
const {
|
|
1893
|
+
handleError: handleError$2
|
|
1894
|
+
} = handleError_1;
|
|
1895
|
+
|
|
1896
|
+
const getLatestVersion = npmName => {
|
|
1897
|
+
const data = shelljs$3.exec(`npm view ${npmName} version`);
|
|
1898
|
+
return data.stdout || '0.0.0';
|
|
1899
|
+
};
|
|
1900
|
+
/**
|
|
1901
|
+
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
1902
|
+
* @param {*} modules 模块
|
|
1903
|
+
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
1904
|
+
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
1905
|
+
* @returns
|
|
1906
|
+
*/
|
|
1907
|
+
|
|
1908
|
+
|
|
1909
|
+
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
1910
|
+
// 步骤1. 收集package.json
|
|
1911
|
+
const packageJsonName = 'package.json'; // 查找文件名
|
|
1912
|
+
// 1.1根目录的package.json
|
|
1913
|
+
|
|
1914
|
+
const packageArr = [{
|
|
1915
|
+
srcPackageDir: path$5.join(cwd, packageJsonName),
|
|
1916
|
+
destNpmDir: resolve$8(outputDir, 'node_modules')
|
|
1917
|
+
}]; // 1.2模块的package.json
|
|
1918
|
+
|
|
1919
|
+
modules.forEach(item => {
|
|
1920
|
+
const srcPackageDir = path$5.join(cwd, item.path, 'package.json');
|
|
1921
|
+
|
|
1922
|
+
if (fs$5.existsSync(srcPackageDir)) {
|
|
1923
|
+
packageArr.push({
|
|
1924
|
+
srcPackageDir,
|
|
1925
|
+
destNpmDir: resolve$8(outputDir, item.root, 'node_modules')
|
|
1926
|
+
});
|
|
1927
|
+
}
|
|
1928
|
+
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1929
|
+
|
|
1930
|
+
for (const item of packageArr) {
|
|
1931
|
+
const packageJson = fs$5.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1932
|
+
let dependencies = {};
|
|
1933
|
+
|
|
1934
|
+
try {
|
|
1935
|
+
const json = JSON.parse(packageJson);
|
|
1936
|
+
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
1937
|
+
} catch (e) {
|
|
1938
|
+
handleError$2(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
const dependenciesKeys = Object.keys(dependencies);
|
|
1942
|
+
|
|
1943
|
+
for (const key of dependenciesKeys) {
|
|
1944
|
+
const depPath = path$5.join(item.destNpmDir, key);
|
|
1945
|
+
|
|
1946
|
+
if (!fs$5.existsSync(depPath)) {
|
|
1947
|
+
return true;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
const depPackagePath = path$5.join(depPath, 'package.json');
|
|
1951
|
+
|
|
1952
|
+
if (fs$5.existsSync(depPackagePath)) {
|
|
1953
|
+
const packageData = require(depPackagePath);
|
|
1954
|
+
|
|
1955
|
+
if (dependencies[key] === 'latest') {
|
|
1956
|
+
dependencies[key] = getLatestVersion(key);
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
if (packageData.version === 'latest') {
|
|
1960
|
+
packageData.version = getLatestVersion(key);
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
|
|
1964
|
+
return true;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
return false;
|
|
1971
|
+
};
|
|
1972
|
+
|
|
1973
|
+
var checkDependencies_1 = {
|
|
1974
|
+
checkDependencies: checkDependencies$1
|
|
1975
|
+
};
|
|
1976
|
+
|
|
1977
|
+
const shelljs$2 = require$$0__default$3;
|
|
1978
|
+
const fs$4 = require$$0__default$2;
|
|
1979
|
+
const io = io$3;
|
|
1853
1980
|
const {
|
|
1854
|
-
resolve: resolve$
|
|
1981
|
+
resolve: resolve$7,
|
|
1855
1982
|
createTask
|
|
1856
1983
|
} = widgets;
|
|
1857
1984
|
const {
|
|
1858
1985
|
buildOutputAppJson
|
|
1859
1986
|
} = buildAppJson;
|
|
1860
1987
|
const {
|
|
1861
|
-
MODULE_CODE_DIR
|
|
1988
|
+
MODULE_CODE_DIR,
|
|
1862
1989
|
DEFAULT_COPY_CONFIG
|
|
1863
1990
|
} = require$$4;
|
|
1864
1991
|
const {
|
|
@@ -1869,10 +1996,13 @@ const {
|
|
|
1869
1996
|
subModulesMergeDepModules: subModulesMergeDepModules$1
|
|
1870
1997
|
} = tmsMpconfig;
|
|
1871
1998
|
const {
|
|
1872
|
-
fail: fail$
|
|
1999
|
+
fail: fail$2,
|
|
1873
2000
|
info: info$4
|
|
1874
2001
|
} = log$1;
|
|
1875
2002
|
const install$1 = install_1;
|
|
2003
|
+
const {
|
|
2004
|
+
checkDependencies
|
|
2005
|
+
} = checkDependencies_1;
|
|
1876
2006
|
/**
|
|
1877
2007
|
* 拷贝相关配置文件到编译输出目录
|
|
1878
2008
|
* @param { object } tmsConfig
|
|
@@ -1881,40 +2011,52 @@ const install$1 = install_1;
|
|
|
1881
2011
|
* @returns
|
|
1882
2012
|
*/
|
|
1883
2013
|
|
|
1884
|
-
const cpFilesToOutput = function (tmsConfig,
|
|
1885
|
-
const outputDir = resolve$
|
|
2014
|
+
const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
2015
|
+
const outputDir = resolve$7(tmsConfig.outputDir);
|
|
1886
2016
|
io.ensureDirExist(outputDir);
|
|
1887
2017
|
defaultFiles.forEach(item => {
|
|
1888
|
-
if (fs$
|
|
1889
|
-
shelljs$
|
|
2018
|
+
if (fs$4.existsSync(resolve$7(item))) {
|
|
2019
|
+
shelljs$2.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
|
|
1890
2020
|
}
|
|
1891
|
-
});
|
|
2021
|
+
});
|
|
2022
|
+
};
|
|
2023
|
+
/**
|
|
2024
|
+
* 校验相关配置项
|
|
2025
|
+
* @param {*} targetModules
|
|
2026
|
+
* @returns
|
|
2027
|
+
*/
|
|
1892
2028
|
|
|
1893
|
-
targetModules.forEach(item => {
|
|
1894
|
-
const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
|
|
1895
2029
|
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
2030
|
+
function checkConfig(targetModules) {
|
|
2031
|
+
for (const item of targetModules) {
|
|
2032
|
+
if (!item.root) {
|
|
2033
|
+
throw new Error(`检查${item.name} module.config.json的root字段`);
|
|
2034
|
+
} // 判断源码目录是否有该模块
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
if (item.path && !fs$4.existsSync(resolve$7(item.path))) {
|
|
2038
|
+
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1899
2039
|
}
|
|
2040
|
+
}
|
|
1900
2041
|
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
if (fs$5.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1904
|
-
});
|
|
1905
|
-
};
|
|
2042
|
+
return true;
|
|
2043
|
+
}
|
|
1906
2044
|
|
|
1907
2045
|
async function task(tmsConfig, targetModules) {
|
|
1908
2046
|
// 下载和移动代码
|
|
1909
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR
|
|
2047
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$7('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1910
2048
|
|
|
1911
2049
|
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
1912
2050
|
|
|
1913
|
-
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2051
|
+
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2052
|
+
checkConfig(newModules); // 拷贝相关配置文件到输出目录
|
|
1914
2053
|
|
|
1915
|
-
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig,
|
|
2054
|
+
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
|
|
2055
|
+
|
|
2056
|
+
if (checkDependencies(newModules, resolve$7('./'), tmsConfig.outputDir)) {
|
|
2057
|
+
await install$1(tmsConfig, newModules);
|
|
2058
|
+
} // 动态生成编译后的app.json;
|
|
1916
2059
|
|
|
1917
|
-
await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
|
|
1918
2060
|
|
|
1919
2061
|
await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
1920
2062
|
return newModules;
|
|
@@ -1928,7 +2070,7 @@ async function init$5(tmsConfig, targetModules) {
|
|
|
1928
2070
|
};
|
|
1929
2071
|
} catch (error) {
|
|
1930
2072
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1931
|
-
fail$
|
|
2073
|
+
fail$2(`初始化流程出现错误${errMsg}`);
|
|
1932
2074
|
info$4('详细的错误信息', error);
|
|
1933
2075
|
process.exit(1);
|
|
1934
2076
|
}
|
|
@@ -1974,16 +2116,16 @@ var findCssImport = {
|
|
|
1974
2116
|
|
|
1975
2117
|
/* eslint-disable no-param-reassign */
|
|
1976
2118
|
const {
|
|
1977
|
-
fail: fail$
|
|
2119
|
+
fail: fail$1
|
|
1978
2120
|
} = log$1;
|
|
1979
2121
|
|
|
1980
2122
|
function pluginError$3(error, isWatch) {
|
|
1981
2123
|
const errMsg = error.message;
|
|
1982
2124
|
|
|
1983
2125
|
if (isWatch) {
|
|
1984
|
-
fail$
|
|
2126
|
+
fail$1(errMsg);
|
|
1985
2127
|
} else {
|
|
1986
|
-
fail$
|
|
2128
|
+
fail$1(errMsg);
|
|
1987
2129
|
process.exit(1);
|
|
1988
2130
|
}
|
|
1989
2131
|
}
|
|
@@ -1994,7 +2136,7 @@ var pluginError_1 = {
|
|
|
1994
2136
|
|
|
1995
2137
|
/* eslint-disable no-param-reassign */
|
|
1996
2138
|
const through$2 = require$$0__default$9;
|
|
1997
|
-
const precinct = require$$1__default$
|
|
2139
|
+
const precinct = require$$1__default$8;
|
|
1998
2140
|
const path$4 = require$$1__default$2;
|
|
1999
2141
|
const {
|
|
2000
2142
|
findCssImports
|
|
@@ -2003,11 +2145,11 @@ const {
|
|
|
2003
2145
|
ext: ext$2,
|
|
2004
2146
|
fileInDir: fileInDir$2,
|
|
2005
2147
|
diffContentCopyFile: diffContentCopyFile$2
|
|
2006
|
-
} = io$
|
|
2148
|
+
} = io$3;
|
|
2007
2149
|
const {
|
|
2008
|
-
resolve: resolve$
|
|
2150
|
+
resolve: resolve$6
|
|
2009
2151
|
} = widgets;
|
|
2010
|
-
const fs$
|
|
2152
|
+
const fs$3 = require$$0__default$2;
|
|
2011
2153
|
const {
|
|
2012
2154
|
pluginError: pluginError$2
|
|
2013
2155
|
} = pluginError_1;
|
|
@@ -2020,7 +2162,7 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2020
2162
|
let contents = '';
|
|
2021
2163
|
|
|
2022
2164
|
try {
|
|
2023
|
-
contents = fs$
|
|
2165
|
+
contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
|
|
2024
2166
|
} catch (e) {
|
|
2025
2167
|
pluginError$2(e, isWatch);
|
|
2026
2168
|
}
|
|
@@ -2037,12 +2179,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2037
2179
|
extPath
|
|
2038
2180
|
} = ext$2(depOriginPath, extensions);
|
|
2039
2181
|
|
|
2040
|
-
if (!fs$
|
|
2182
|
+
if (!fs$3.existsSync(depOriginFile)) {
|
|
2041
2183
|
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2042
2184
|
return;
|
|
2043
2185
|
}
|
|
2044
2186
|
|
|
2045
|
-
const depDestPath = resolve$
|
|
2187
|
+
const depDestPath = resolve$6(path$4.dirname(anaFileDestFile), depItem);
|
|
2046
2188
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2047
2189
|
|
|
2048
2190
|
if (!resDep.has(depDestFile)) {
|
|
@@ -2066,8 +2208,8 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2066
2208
|
const stream = through$2.obj(function (file, enc, cb) {
|
|
2067
2209
|
// 依赖分析的文件
|
|
2068
2210
|
const anaFileOriginFile = file.history[0];
|
|
2069
|
-
const anaFileRelativeModule = path$4.relative(resolve$
|
|
2070
|
-
const anaFileDestFile = resolve$
|
|
2211
|
+
const anaFileRelativeModule = path$4.relative(resolve$6(module.from), anaFileOriginFile);
|
|
2212
|
+
const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2071
2213
|
|
|
2072
2214
|
if (file.isBuffer()) {
|
|
2073
2215
|
let contents = String(file.contents);
|
|
@@ -2096,7 +2238,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2096
2238
|
const regRes = depItem.match(reg) || [];
|
|
2097
2239
|
|
|
2098
2240
|
if (regRes[2]) {
|
|
2099
|
-
const depDestPath = resolve$
|
|
2241
|
+
const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2100
2242
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2101
2243
|
|
|
2102
2244
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2147,11 +2289,11 @@ const {
|
|
|
2147
2289
|
ext: ext$1,
|
|
2148
2290
|
fileInDir: fileInDir$1,
|
|
2149
2291
|
diffContentCopyFile: diffContentCopyFile$1
|
|
2150
|
-
} = io$
|
|
2292
|
+
} = io$3;
|
|
2151
2293
|
const {
|
|
2152
|
-
resolve: resolve$
|
|
2294
|
+
resolve: resolve$5
|
|
2153
2295
|
} = widgets;
|
|
2154
|
-
const fs$
|
|
2296
|
+
const fs$2 = require$$0__default$2;
|
|
2155
2297
|
const {
|
|
2156
2298
|
pluginError: pluginError$1
|
|
2157
2299
|
} = pluginError_1;
|
|
@@ -2163,8 +2305,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2163
2305
|
const stream = through$1.obj(function (file, enc, cb) {
|
|
2164
2306
|
// 当前分析的文件的路径
|
|
2165
2307
|
const anaFileOriginFile = file.history[0];
|
|
2166
|
-
const anaFileRelativeModule = path$3.relative(resolve$
|
|
2167
|
-
const anaFileDestFile = resolve$
|
|
2308
|
+
const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2309
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2168
2310
|
|
|
2169
2311
|
if (file.isBuffer()) {
|
|
2170
2312
|
let contents = String(file.contents);
|
|
@@ -2199,11 +2341,11 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2199
2341
|
} // eslint-disable-next-line
|
|
2200
2342
|
|
|
2201
2343
|
|
|
2202
|
-
const reg = new RegExp(`^(
|
|
2344
|
+
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2203
2345
|
const regRes = componentPath.match(reg) || [];
|
|
2204
2346
|
|
|
2205
2347
|
if (regRes[2]) {
|
|
2206
|
-
const depDestPath = resolve$
|
|
2348
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2207
2349
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2208
2350
|
|
|
2209
2351
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2237,7 +2379,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2237
2379
|
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2238
2380
|
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2239
2381
|
|
|
2240
|
-
if (fs$
|
|
2382
|
+
if (fs$2.existsSync(originFile)) {
|
|
2241
2383
|
diffContentCopyFile$1(originFile, destFile);
|
|
2242
2384
|
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2243
2385
|
|
|
@@ -2270,16 +2412,16 @@ var mpJsonDep_1 = {
|
|
|
2270
2412
|
|
|
2271
2413
|
/* eslint-disable no-param-reassign */
|
|
2272
2414
|
const through = require$$0__default$9;
|
|
2273
|
-
const htmlparser2 = require$$1__default$
|
|
2274
|
-
const fs$
|
|
2415
|
+
const htmlparser2 = require$$1__default$9;
|
|
2416
|
+
const fs$1 = require$$0__default$2;
|
|
2275
2417
|
const path$2 = require$$1__default$2;
|
|
2276
2418
|
const {
|
|
2277
2419
|
diffContentCopyFile,
|
|
2278
2420
|
ext,
|
|
2279
2421
|
fileInDir
|
|
2280
|
-
} = io$
|
|
2422
|
+
} = io$3;
|
|
2281
2423
|
const {
|
|
2282
|
-
resolve: resolve$
|
|
2424
|
+
resolve: resolve$4
|
|
2283
2425
|
} = widgets;
|
|
2284
2426
|
const {
|
|
2285
2427
|
dfsFindCommonDep
|
|
@@ -2318,7 +2460,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2318
2460
|
let contents = '';
|
|
2319
2461
|
|
|
2320
2462
|
try {
|
|
2321
|
-
contents = fs$
|
|
2463
|
+
contents = fs$1.readFileSync(anaFileOriginFile, 'utf8');
|
|
2322
2464
|
} catch (e) {
|
|
2323
2465
|
pluginError(e, isWatch);
|
|
2324
2466
|
}
|
|
@@ -2336,7 +2478,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2336
2478
|
extPath
|
|
2337
2479
|
} = extFile(name, depOriginPath);
|
|
2338
2480
|
|
|
2339
|
-
if (!fs$
|
|
2481
|
+
if (!fs$1.existsSync(depOriginFile)) {
|
|
2340
2482
|
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2341
2483
|
return;
|
|
2342
2484
|
}
|
|
@@ -2393,8 +2535,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2393
2535
|
const stream = through.obj(function (file, enc, cb) {
|
|
2394
2536
|
// 依赖分析的文件
|
|
2395
2537
|
const anaFileOriginFile = file.history[0];
|
|
2396
|
-
const anaFileRelativeModule = path$2.relative(resolve$
|
|
2397
|
-
const anaFileDestFile = resolve$
|
|
2538
|
+
const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
|
|
2539
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2398
2540
|
|
|
2399
2541
|
if (file.isBuffer()) {
|
|
2400
2542
|
let contents = String(file.contents);
|
|
@@ -2425,7 +2567,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2425
2567
|
const regRes = attributes.src.match(reg) || [];
|
|
2426
2568
|
|
|
2427
2569
|
if (regRes[2]) {
|
|
2428
|
-
const depDestPath = resolve$
|
|
2570
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2429
2571
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2430
2572
|
|
|
2431
2573
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2452,7 +2594,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2452
2594
|
beforeDepPath,
|
|
2453
2595
|
afterDepPath
|
|
2454
2596
|
}) => {
|
|
2455
|
-
if (fs$
|
|
2597
|
+
if (fs$1.existsSync(depOriginFile)) {
|
|
2456
2598
|
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2457
2599
|
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2458
2600
|
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
@@ -2508,7 +2650,7 @@ const {
|
|
|
2508
2650
|
// const base64 = require('./plugins/postcss-font-base64');
|
|
2509
2651
|
|
|
2510
2652
|
const {
|
|
2511
|
-
fail
|
|
2653
|
+
fail
|
|
2512
2654
|
} = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
2513
2655
|
|
|
2514
2656
|
var compile = function (tmsConfig, {
|
|
@@ -2516,7 +2658,7 @@ var compile = function (tmsConfig, {
|
|
|
2516
2658
|
destPath,
|
|
2517
2659
|
srcOption,
|
|
2518
2660
|
module,
|
|
2519
|
-
|
|
2661
|
+
isDev
|
|
2520
2662
|
}) {
|
|
2521
2663
|
const compileTasksMap = new Map();
|
|
2522
2664
|
Object.keys(glob).forEach(globKey => {
|
|
@@ -2526,14 +2668,18 @@ var compile = function (tmsConfig, {
|
|
|
2526
2668
|
case 'js':
|
|
2527
2669
|
compileTasksMap.set(globValue, {
|
|
2528
2670
|
module,
|
|
2529
|
-
taskFn: () => {
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
const srcPipe = src$1(
|
|
2671
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2672
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2673
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2674
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2533
2675
|
});
|
|
2534
2676
|
return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
2535
|
-
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'],
|
|
2536
|
-
fail
|
|
2677
|
+
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
|
|
2678
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
2679
|
+
}).pipe(dest(newDestPath, {
|
|
2680
|
+
overwrite: true
|
|
2681
|
+
})).on('error', err => {
|
|
2682
|
+
fail(`js编译报错${err}`);
|
|
2537
2683
|
});
|
|
2538
2684
|
}
|
|
2539
2685
|
});
|
|
@@ -2542,13 +2688,13 @@ var compile = function (tmsConfig, {
|
|
|
2542
2688
|
case 'wxss':
|
|
2543
2689
|
compileTasksMap.set(globValue, {
|
|
2544
2690
|
module,
|
|
2545
|
-
taskFn: () => {
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
const srcPipe = src$1(
|
|
2691
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2692
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2693
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2694
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2549
2695
|
});
|
|
2550
|
-
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'],
|
|
2551
|
-
fail
|
|
2696
|
+
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
|
|
2697
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
2552
2698
|
}) // .pipe(postcss([base64()]))
|
|
2553
2699
|
// .on('error', (err) => {
|
|
2554
2700
|
// fail(`postcss编译报错${err}`);
|
|
@@ -2557,7 +2703,9 @@ var compile = function (tmsConfig, {
|
|
|
2557
2703
|
// designWidth: 375, // 设计稿宽度,默认为750
|
|
2558
2704
|
// precision: 2, // 小数最大精度,默认为6
|
|
2559
2705
|
// }))
|
|
2560
|
-
.pipe(dest(
|
|
2706
|
+
.pipe(dest(newDestPath)).on('error', err => {
|
|
2707
|
+
fail(`wxss编译报错${err}`);
|
|
2708
|
+
});
|
|
2561
2709
|
}
|
|
2562
2710
|
});
|
|
2563
2711
|
break;
|
|
@@ -2565,14 +2713,16 @@ var compile = function (tmsConfig, {
|
|
|
2565
2713
|
case 'json':
|
|
2566
2714
|
compileTasksMap.set(globValue, {
|
|
2567
2715
|
module,
|
|
2568
|
-
taskFn: () => {
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
const srcPipe = src$1(
|
|
2716
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2717
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2718
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2719
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2720
|
+
});
|
|
2721
|
+
return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
|
|
2722
|
+
fail(`mpJsonDep编译报错${err}`);
|
|
2723
|
+
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2724
|
+
fail(`json编译报错${err}`);
|
|
2572
2725
|
});
|
|
2573
|
-
return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
|
|
2574
|
-
fail$1(`mpJsonDep编译报错${err}`);
|
|
2575
|
-
}).pipe(dest(destPath));
|
|
2576
2726
|
}
|
|
2577
2727
|
});
|
|
2578
2728
|
break;
|
|
@@ -2580,12 +2730,16 @@ var compile = function (tmsConfig, {
|
|
|
2580
2730
|
case 'wxml':
|
|
2581
2731
|
compileTasksMap.set(globValue, {
|
|
2582
2732
|
module,
|
|
2583
|
-
taskFn: () => {
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
const srcPipe = src$1(
|
|
2733
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2734
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2735
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2736
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2737
|
+
});
|
|
2738
|
+
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
|
|
2739
|
+
fail(`mpWxmlDep编译报错${err}`);
|
|
2740
|
+
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2741
|
+
fail(`wxml编译报错${err}`);
|
|
2587
2742
|
});
|
|
2588
|
-
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isWatch)).pipe(dest(destPath));
|
|
2589
2743
|
}
|
|
2590
2744
|
});
|
|
2591
2745
|
break;
|
|
@@ -2593,16 +2747,18 @@ var compile = function (tmsConfig, {
|
|
|
2593
2747
|
case 'image':
|
|
2594
2748
|
compileTasksMap.set(globValue, {
|
|
2595
2749
|
module,
|
|
2596
|
-
taskFn: () => {
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
const srcPipe = src$1(
|
|
2750
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2751
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2752
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2753
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2600
2754
|
});
|
|
2601
2755
|
return srcPipe // .pipe(cache(image()))
|
|
2602
2756
|
// .on('error', (err) => {
|
|
2603
2757
|
// fail(`image编译报错${err}`);
|
|
2604
2758
|
// })
|
|
2605
|
-
.pipe(dest(
|
|
2759
|
+
.pipe(dest(newDestPath)).on('error', err => {
|
|
2760
|
+
fail(`image编译报错${err}`);
|
|
2761
|
+
});
|
|
2606
2762
|
}
|
|
2607
2763
|
});
|
|
2608
2764
|
break;
|
|
@@ -2610,12 +2766,14 @@ var compile = function (tmsConfig, {
|
|
|
2610
2766
|
case 'other':
|
|
2611
2767
|
compileTasksMap.set(globValue, {
|
|
2612
2768
|
module,
|
|
2613
|
-
taskFn: () => {
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
const srcPipe = src$1(
|
|
2769
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2770
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2771
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2772
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2773
|
+
});
|
|
2774
|
+
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
2775
|
+
fail(`编译报错${err}`);
|
|
2617
2776
|
});
|
|
2618
|
-
return srcPipe.pipe(dest(destPath));
|
|
2619
2777
|
}
|
|
2620
2778
|
});
|
|
2621
2779
|
break;
|
|
@@ -2624,39 +2782,254 @@ var compile = function (tmsConfig, {
|
|
|
2624
2782
|
return compileTasksMap;
|
|
2625
2783
|
};
|
|
2626
2784
|
|
|
2627
|
-
|
|
2785
|
+
/* eslint-disable */
|
|
2786
|
+
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
2787
|
+
|
|
2788
|
+
const assign = require$$0__default$b;
|
|
2628
2789
|
const path$1 = require$$1__default$2;
|
|
2790
|
+
const PluginError = require$$2__default$1;
|
|
2791
|
+
const fancyLog = require$$3__default;
|
|
2792
|
+
const colors = require$$4__default;
|
|
2793
|
+
const chokidar = require$$5__default$1;
|
|
2794
|
+
const {
|
|
2795
|
+
Duplex
|
|
2796
|
+
} = require$$6__default;
|
|
2797
|
+
const vinyl = require$$7__default;
|
|
2798
|
+
const File = require$$8__default;
|
|
2799
|
+
const anymatch = require$$9__default;
|
|
2800
|
+
const pathIsAbsolute = require$$10__default;
|
|
2801
|
+
const globParent = require$$11__default;
|
|
2802
|
+
const slash = require$$12__default;
|
|
2803
|
+
|
|
2804
|
+
function normalizeGlobs(globs) {
|
|
2805
|
+
if (!globs) {
|
|
2806
|
+
throw new PluginError('gulp-watch', 'glob argument required');
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
if (typeof globs === 'string') {
|
|
2810
|
+
globs = [globs];
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2813
|
+
if (!Array.isArray(globs)) {
|
|
2814
|
+
throw new PluginError('gulp-watch', `glob should be String or Array, not ${typeof globs}`);
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
return globs;
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
function watch$1(globs, opts, cb) {
|
|
2821
|
+
globs = normalizeGlobs(globs);
|
|
2822
|
+
|
|
2823
|
+
if (typeof opts === 'function') {
|
|
2824
|
+
cb = opts;
|
|
2825
|
+
opts = {};
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
opts = assign({}, watch$1._defaultOptions, opts);
|
|
2829
|
+
|
|
2830
|
+
cb = cb || function () {};
|
|
2831
|
+
|
|
2832
|
+
function resolveFilepath(filepath) {
|
|
2833
|
+
if (pathIsAbsolute(filepath)) {
|
|
2834
|
+
return path$1.normalize(filepath);
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
return path$1.resolve(opts.cwd || process.cwd(), filepath);
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
function resolveGlob(glob) {
|
|
2841
|
+
let mod = '';
|
|
2842
|
+
|
|
2843
|
+
if (glob[0] === '!') {
|
|
2844
|
+
mod = glob[0];
|
|
2845
|
+
glob = glob.slice(1);
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
return mod + slash(resolveFilepath(glob));
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
globs = globs.map(resolveGlob);
|
|
2852
|
+
const baseForced = Boolean(opts.base);
|
|
2853
|
+
const outputStream = new Duplex({
|
|
2854
|
+
objectMode: true,
|
|
2855
|
+
allowHalfOpen: true
|
|
2856
|
+
});
|
|
2857
|
+
|
|
2858
|
+
outputStream._write = function _write(file, enc, done) {
|
|
2859
|
+
cb(file);
|
|
2860
|
+
this.push(file);
|
|
2861
|
+
done();
|
|
2862
|
+
};
|
|
2863
|
+
|
|
2864
|
+
outputStream._read = function _read() {};
|
|
2865
|
+
|
|
2866
|
+
const watcher = chokidar.watch(globs, opts);
|
|
2867
|
+
opts.events.forEach(ev => {
|
|
2868
|
+
watcher.on(ev, processEvent.bind(undefined, ev));
|
|
2869
|
+
});
|
|
2870
|
+
['add', 'change', 'unlink', 'addDir', 'unlinkDir', 'error', 'ready', 'raw'].forEach(ev => {
|
|
2871
|
+
watcher.on(ev, outputStream.emit.bind(outputStream, ev));
|
|
2872
|
+
});
|
|
2873
|
+
|
|
2874
|
+
outputStream.add = function add(newGlobs) {
|
|
2875
|
+
newGlobs = normalizeGlobs(newGlobs).map(resolveGlob);
|
|
2876
|
+
watcher.add(newGlobs);
|
|
2877
|
+
globs.push.apply(globs, newGlobs);
|
|
2878
|
+
};
|
|
2879
|
+
|
|
2880
|
+
outputStream.unwatch = watcher.unwatch.bind(watcher);
|
|
2881
|
+
|
|
2882
|
+
outputStream.close = function () {
|
|
2883
|
+
watcher.close();
|
|
2884
|
+
this.emit('end');
|
|
2885
|
+
};
|
|
2886
|
+
|
|
2887
|
+
function processEvent(event, filepath) {
|
|
2888
|
+
filepath = resolveFilepath(filepath);
|
|
2889
|
+
const fileOpts = assign({}, opts);
|
|
2890
|
+
let glob;
|
|
2891
|
+
let currentFilepath = filepath;
|
|
2892
|
+
|
|
2893
|
+
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$1.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
2894
|
+
|
|
2895
|
+
|
|
2896
|
+
if (!glob) {
|
|
2897
|
+
console.error('[gulp-watch]没有匹配到glob');
|
|
2898
|
+
return;
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2901
|
+
if (!baseForced) {
|
|
2902
|
+
fileOpts.base = path$1.normalize(globParent(glob));
|
|
2903
|
+
} // Do not stat deleted files
|
|
2904
|
+
|
|
2905
|
+
|
|
2906
|
+
if (event === 'unlink' || event === 'unlinkDir' || event === 'addDir') {
|
|
2907
|
+
fileOpts.path = filepath;
|
|
2908
|
+
write(event, null, new File(fileOpts));
|
|
2909
|
+
return;
|
|
2910
|
+
} // Workaround for early read
|
|
2911
|
+
|
|
2912
|
+
|
|
2913
|
+
setTimeout(() => {
|
|
2914
|
+
vinyl.read(filepath, fileOpts).then(file => {
|
|
2915
|
+
write(event, null, file);
|
|
2916
|
+
});
|
|
2917
|
+
}, opts.readDelay);
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
function write(event, err, file) {
|
|
2921
|
+
if (err) {
|
|
2922
|
+
outputStream.emit('error', err);
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
if (opts.verbose) {
|
|
2927
|
+
log(event, file);
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
file.event = event;
|
|
2931
|
+
outputStream.push(file);
|
|
2932
|
+
cb(file);
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
function log(event, file) {
|
|
2936
|
+
event = event[event.length - 1] === 'e' ? `${event}d` : `${event}ed`;
|
|
2937
|
+
const msg = [colors.magenta(file.relative), 'was', event];
|
|
2938
|
+
|
|
2939
|
+
if (opts.name) {
|
|
2940
|
+
msg.unshift(`${colors.cyan(opts.name)} saw`);
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
fancyLog.info.apply(null, msg);
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2946
|
+
return outputStream;
|
|
2947
|
+
} // This is not part of the public API as that would lead to global state (singleton) pollution,
|
|
2948
|
+
// and allow unexpected interference between unrelated modules that make use of gulp-watch.
|
|
2949
|
+
// This can be useful for unit tests and root application configuration, though.
|
|
2950
|
+
// Avoid modifying gulp-watch's default options inside a library/reusable package, please.
|
|
2951
|
+
|
|
2952
|
+
|
|
2953
|
+
watch$1._defaultOptions = {
|
|
2954
|
+
events: ['add', 'change', 'unlink'],
|
|
2955
|
+
ignoreInitial: true,
|
|
2956
|
+
readDelay: 10
|
|
2957
|
+
};
|
|
2958
|
+
var gulpWatch = watch$1;
|
|
2959
|
+
|
|
2960
|
+
const watch = gulpWatch;
|
|
2961
|
+
const path = require$$1__default$2;
|
|
2629
2962
|
const shellJs = require$$0__default$3;
|
|
2630
2963
|
const {
|
|
2631
|
-
info: info$3
|
|
2964
|
+
info: info$3,
|
|
2965
|
+
warn: warn$1
|
|
2632
2966
|
} = log$1;
|
|
2633
2967
|
const {
|
|
2634
|
-
resolve: resolve$
|
|
2968
|
+
resolve: resolve$3
|
|
2635
2969
|
} = widgets;
|
|
2636
2970
|
const {
|
|
2637
2971
|
global: global$2
|
|
2638
2972
|
} = global_1;
|
|
2973
|
+
const {
|
|
2974
|
+
findAllFilesOfDir
|
|
2975
|
+
} = io$3;
|
|
2976
|
+
const TIP_MAP = {
|
|
2977
|
+
'package.json': '若依赖有变动,请重新执行tmskit run dev',
|
|
2978
|
+
'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效'
|
|
2979
|
+
};
|
|
2980
|
+
|
|
2981
|
+
const logTip = (fileName, tipMap) => {
|
|
2982
|
+
// eslint-disable-next-line
|
|
2983
|
+
for (const item in tipMap) {
|
|
2984
|
+
if (fileName.indexOf(item) > -1) {
|
|
2985
|
+
warn$1(`${fileName}有更新, ${tipMap[item]}`);
|
|
2986
|
+
return;
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
info$3(`${fileName}有更新`);
|
|
2991
|
+
};
|
|
2639
2992
|
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2993
|
+
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
2994
|
+
const sourceFileRelativeModule = path.relative(resolve$3(module.from), sourceFile);
|
|
2995
|
+
const targetFile = resolve$3(outputDir, module.to, sourceFileRelativeModule);
|
|
2996
|
+
return targetFile;
|
|
2997
|
+
};
|
|
2998
|
+
|
|
2999
|
+
var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
3000
|
+
watch(globValue, { // readDelay: 100,
|
|
2643
3001
|
...watchOptions
|
|
2644
3002
|
}, vinyl => {
|
|
2645
|
-
const
|
|
2646
|
-
const
|
|
2647
|
-
const
|
|
3003
|
+
const sourceFile = vinyl.history[0];
|
|
3004
|
+
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
3005
|
+
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
3006
|
+
const tmsConfig = global$2.getData('tmsConfig');
|
|
3007
|
+
|
|
3008
|
+
if (vinyl.event === 'addDir') {
|
|
3009
|
+
info$3(`更新${sourceFileName}目录`);
|
|
3010
|
+
const files = findAllFilesOfDir(sourceFile);
|
|
3011
|
+
|
|
3012
|
+
for (const file of files) {
|
|
3013
|
+
const fileDirArr = file.replace(/\\/g, '/').split('/');
|
|
3014
|
+
const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
|
|
3015
|
+
const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
|
|
3016
|
+
logTip(fileName, TIP_MAP);
|
|
3017
|
+
callback([file], path.dirname(targetFile));
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
return;
|
|
3021
|
+
}
|
|
3022
|
+
|
|
3023
|
+
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
2648
3024
|
|
|
2649
3025
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2653
|
-
info$3(`删除${fileName}`);
|
|
2654
|
-
shellJs.rm('-rf', anaFileDestFile);
|
|
3026
|
+
info$3(`删除${sourceFileName}`);
|
|
3027
|
+
shellJs.rm('-rf', targetFile);
|
|
2655
3028
|
return;
|
|
2656
3029
|
}
|
|
2657
3030
|
|
|
2658
|
-
|
|
2659
|
-
return callback(
|
|
3031
|
+
logTip(sourceFileName, TIP_MAP);
|
|
3032
|
+
return callback([sourceFile], path.dirname(targetFile));
|
|
2660
3033
|
});
|
|
2661
3034
|
};
|
|
2662
3035
|
|
|
@@ -2664,13 +3037,15 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2664
3037
|
const path = require$$1__default$2;
|
|
2665
3038
|
const fs = require$$0__default$2;
|
|
2666
3039
|
const ora = require$$2__default;
|
|
3040
|
+
const chalk = require$$0__default;
|
|
2667
3041
|
const {
|
|
2668
3042
|
parallel,
|
|
2669
3043
|
series
|
|
2670
3044
|
} = require$$0__default$a;
|
|
2671
3045
|
const {
|
|
2672
3046
|
resolve,
|
|
2673
|
-
mergeMap
|
|
3047
|
+
mergeMap,
|
|
3048
|
+
filterField
|
|
2674
3049
|
} = widgets;
|
|
2675
3050
|
const {
|
|
2676
3051
|
buildOutputAppJson
|
|
@@ -2683,7 +3058,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2683
3058
|
const {
|
|
2684
3059
|
info
|
|
2685
3060
|
} = log$1;
|
|
2686
|
-
const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
|
|
3061
|
+
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
2687
3062
|
|
|
2688
3063
|
function excludeGlob(glob) {
|
|
2689
3064
|
const otherArr = new Set();
|
|
@@ -2713,18 +3088,8 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2713
3088
|
return newPath;
|
|
2714
3089
|
}
|
|
2715
3090
|
|
|
2716
|
-
module.exports = async (tmsConfig, newModules,
|
|
2717
|
-
const compileTasksMap = new Map(); //
|
|
2718
|
-
|
|
2719
|
-
if (isWatch) {
|
|
2720
|
-
watch([resolve('app.json')], {
|
|
2721
|
-
ignoreInitial: false,
|
|
2722
|
-
events: watchEvents
|
|
2723
|
-
}, () => buildOutputAppJson(tmsConfig, newModules, isWatch));
|
|
2724
|
-
} else {
|
|
2725
|
-
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
2726
|
-
} // 监听根目录的文件
|
|
2727
|
-
|
|
3091
|
+
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
3092
|
+
const compileTasksMap = new Map(); // 监听根目录的文件
|
|
2728
3093
|
|
|
2729
3094
|
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
2730
3095
|
glob: {
|
|
@@ -2733,14 +3098,14 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2733
3098
|
|
|
2734
3099
|
},
|
|
2735
3100
|
module: {
|
|
2736
|
-
from:
|
|
2737
|
-
to:
|
|
3101
|
+
from: resolve(),
|
|
3102
|
+
to: resolve(tmsConfig.outputDir)
|
|
2738
3103
|
},
|
|
2739
3104
|
destPath: resolve(tmsConfig.outputDir),
|
|
2740
3105
|
srcOption: {
|
|
2741
3106
|
allowEmpty: true
|
|
2742
3107
|
},
|
|
2743
|
-
|
|
3108
|
+
isDev
|
|
2744
3109
|
})); // 监听模块的文件
|
|
2745
3110
|
|
|
2746
3111
|
for (let module of newModules) {
|
|
@@ -2750,16 +3115,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2750
3115
|
},
|
|
2751
3116
|
...module
|
|
2752
3117
|
};
|
|
3118
|
+
const modulePath = adaptPath(module.path);
|
|
2753
3119
|
|
|
2754
|
-
if (
|
|
3120
|
+
if (isDev) {
|
|
2755
3121
|
// 监听模块配置文件
|
|
2756
|
-
watch([`${
|
|
3122
|
+
watch([`${modulePath}/**/module.config.json`], {
|
|
2757
3123
|
events: watchEvents
|
|
2758
|
-
}, () => buildOutputAppJson(tmsConfig, newModules,
|
|
3124
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3125
|
+
from: modulePath,
|
|
3126
|
+
to: modulePath
|
|
3127
|
+
});
|
|
2759
3128
|
}
|
|
2760
3129
|
|
|
2761
3130
|
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
2762
|
-
const modulePath = adaptPath(module.path);
|
|
2763
3131
|
const glob = {
|
|
2764
3132
|
js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
2765
3133
|
json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
|
|
@@ -2779,7 +3147,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2779
3147
|
srcOption: {
|
|
2780
3148
|
allowEmpty: true
|
|
2781
3149
|
},
|
|
2782
|
-
|
|
3150
|
+
isDev
|
|
2783
3151
|
}));
|
|
2784
3152
|
} // 静态资源目录-拷贝
|
|
2785
3153
|
|
|
@@ -2815,7 +3183,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2815
3183
|
srcOption: {
|
|
2816
3184
|
allowEmpty: true
|
|
2817
3185
|
},
|
|
2818
|
-
|
|
3186
|
+
isDev
|
|
2819
3187
|
}));
|
|
2820
3188
|
}
|
|
2821
3189
|
}
|
|
@@ -2824,8 +3192,26 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2824
3192
|
let eTime;
|
|
2825
3193
|
const spinner = ora();
|
|
2826
3194
|
|
|
2827
|
-
function
|
|
2828
|
-
|
|
3195
|
+
function start(cb) {
|
|
3196
|
+
info('启动编译...');
|
|
3197
|
+
spinner.start();
|
|
3198
|
+
sTime = new Date().getTime();
|
|
3199
|
+
cb();
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
async function end(cb) {
|
|
3203
|
+
var _tmsConfig$hooks;
|
|
3204
|
+
|
|
3205
|
+
if (isDev) {
|
|
3206
|
+
// 监听app.json
|
|
3207
|
+
watch([resolve('app.json')], {
|
|
3208
|
+
ignoreInitial: false,
|
|
3209
|
+
events: watchEvents
|
|
3210
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3211
|
+
from: resolve(),
|
|
3212
|
+
to: resolve(tmsConfig.outputDir)
|
|
3213
|
+
}); // 监听其他文件
|
|
3214
|
+
|
|
2829
3215
|
compileTasksMap.forEach(({
|
|
2830
3216
|
taskFn,
|
|
2831
3217
|
module
|
|
@@ -2835,18 +3221,24 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2835
3221
|
events: watchEvents
|
|
2836
3222
|
}, taskFn, module);
|
|
2837
3223
|
});
|
|
3224
|
+
} else {
|
|
3225
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
2838
3226
|
}
|
|
2839
3227
|
|
|
2840
3228
|
eTime = new Date().getTime() - sTime;
|
|
2841
|
-
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即刻预览。`);
|
|
2842
|
-
spinner.stop();
|
|
2843
|
-
cb();
|
|
2844
|
-
}
|
|
2845
3229
|
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
3230
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
|
|
3231
|
+
var _tmsConfig$hooks2;
|
|
3232
|
+
|
|
3233
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3234
|
+
isDev,
|
|
3235
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3236
|
+
modules: newModules
|
|
3237
|
+
}));
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
3241
|
+
spinner.stop();
|
|
2850
3242
|
cb();
|
|
2851
3243
|
}
|
|
2852
3244
|
|
|
@@ -2855,190 +3247,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2855
3247
|
taskFn
|
|
2856
3248
|
}) => {
|
|
2857
3249
|
compileTasks.push(taskFn);
|
|
2858
|
-
});
|
|
3250
|
+
}); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
3251
|
+
|
|
2859
3252
|
series(start, parallel(...compileTasks), end)();
|
|
2860
3253
|
};
|
|
2861
3254
|
})(dev$3);
|
|
2862
3255
|
|
|
2863
|
-
const fs$1 = require$$0__default$2;
|
|
2864
|
-
const semver$1 = require$$1__default$9;
|
|
2865
|
-
const {
|
|
2866
|
-
resolve: resolve$3
|
|
2867
|
-
} = widgets;
|
|
2868
|
-
const path = require$$1__default$2;
|
|
2869
|
-
const shelljs$2 = require$$0__default$3;
|
|
2870
|
-
const {
|
|
2871
|
-
handleError
|
|
2872
|
-
} = handleError_1;
|
|
2873
|
-
|
|
2874
|
-
const getLatestVersion = npmName => {
|
|
2875
|
-
const data = shelljs$2.exec(`npm view ${npmName} version`);
|
|
2876
|
-
return data.stdout || '0.0.0';
|
|
2877
|
-
};
|
|
2878
|
-
/**
|
|
2879
|
-
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
2880
|
-
* @param {*} modules 模块
|
|
2881
|
-
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
2882
|
-
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
2883
|
-
* @returns
|
|
2884
|
-
*/
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
2888
|
-
// 步骤1. 收集package.json
|
|
2889
|
-
const packageJsonName = 'package.json'; // 查找文件名
|
|
2890
|
-
// 1.1根目录的package.json
|
|
2891
|
-
|
|
2892
|
-
const packageArr = [{
|
|
2893
|
-
srcPackageDir: path.join(cwd, packageJsonName),
|
|
2894
|
-
destNpmDir: resolve$3(outputDir, 'node_modules')
|
|
2895
|
-
}]; // 1.2模块的package.json
|
|
2896
|
-
|
|
2897
|
-
modules.forEach(item => {
|
|
2898
|
-
const srcPackageDir = path.join(cwd, item.path, 'package.json');
|
|
2899
|
-
|
|
2900
|
-
if (fs$1.existsSync(srcPackageDir)) {
|
|
2901
|
-
packageArr.push({
|
|
2902
|
-
srcPackageDir,
|
|
2903
|
-
destNpmDir: resolve$3(outputDir, item.root, 'node_modules')
|
|
2904
|
-
});
|
|
2905
|
-
}
|
|
2906
|
-
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
2907
|
-
|
|
2908
|
-
for (const item of packageArr) {
|
|
2909
|
-
const packageJson = fs$1.readFileSync(item.srcPackageDir, 'utf-8');
|
|
2910
|
-
let dependencies = {};
|
|
2911
|
-
|
|
2912
|
-
try {
|
|
2913
|
-
const json = JSON.parse(packageJson);
|
|
2914
|
-
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
2915
|
-
} catch (e) {
|
|
2916
|
-
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
2917
|
-
}
|
|
2918
|
-
|
|
2919
|
-
const dependenciesKeys = Object.keys(dependencies);
|
|
2920
|
-
|
|
2921
|
-
for (const key of dependenciesKeys) {
|
|
2922
|
-
const depPath = path.join(item.destNpmDir, key);
|
|
2923
|
-
|
|
2924
|
-
if (!fs$1.existsSync(depPath)) {
|
|
2925
|
-
return true;
|
|
2926
|
-
}
|
|
2927
|
-
|
|
2928
|
-
const depPackagePath = path.join(depPath, 'package.json');
|
|
2929
|
-
|
|
2930
|
-
if (fs$1.existsSync(depPackagePath)) {
|
|
2931
|
-
const packageData = require(depPackagePath);
|
|
2932
|
-
|
|
2933
|
-
if (dependencies[key] === 'latest') {
|
|
2934
|
-
dependencies[key] = getLatestVersion(key);
|
|
2935
|
-
}
|
|
2936
|
-
|
|
2937
|
-
if (packageData.version === 'latest') {
|
|
2938
|
-
packageData.version = getLatestVersion(key);
|
|
2939
|
-
}
|
|
2940
|
-
|
|
2941
|
-
if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
|
|
2942
|
-
return true;
|
|
2943
|
-
}
|
|
2944
|
-
}
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
|
|
2948
|
-
return false;
|
|
2949
|
-
};
|
|
2950
|
-
|
|
2951
|
-
var checkDependencies_1 = {
|
|
2952
|
-
checkDependencies: checkDependencies$1
|
|
2953
|
-
};
|
|
2954
|
-
|
|
2955
|
-
const fs = require$$0__default$2;
|
|
2956
|
-
const {
|
|
2957
|
-
resolve: resolve$2
|
|
2958
|
-
} = widgets;
|
|
2959
|
-
const {
|
|
2960
|
-
MODULE_CODE_DIR
|
|
2961
|
-
} = require$$4;
|
|
2962
|
-
const {
|
|
2963
|
-
checkRemoteModGitUrlBranch
|
|
2964
|
-
} = cloneModules_1;
|
|
2965
|
-
const {
|
|
2966
|
-
checkDependencies
|
|
2967
|
-
} = checkDependencies_1;
|
|
2968
|
-
const {
|
|
2969
|
-
fail
|
|
2970
|
-
} = log$1;
|
|
2971
|
-
|
|
2972
|
-
function checkModule(targetModules) {
|
|
2973
|
-
// 判断\源码\dist\是否存在用户指定的模块
|
|
2974
|
-
for (const item of targetModules) {
|
|
2975
|
-
// 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
|
|
2976
|
-
if (!item.root) {
|
|
2977
|
-
return true;
|
|
2978
|
-
} // 判断第三方远程模块git地址与branch是否有更新
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
|
|
2982
|
-
return true;
|
|
2983
|
-
} // 判断源码目录是否有该模块
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
if (item.path && !fs.existsSync(resolve$2(item.path))) {
|
|
2987
|
-
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2988
|
-
process.exit(1);
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
|
|
2992
|
-
return false;
|
|
2993
|
-
}
|
|
2994
|
-
|
|
2995
|
-
function isInit$1(tmsConfig, targetModules, contextDir) {
|
|
2996
|
-
// 判断是否存在dist目录
|
|
2997
|
-
if (!fs.existsSync(contextDir)) {
|
|
2998
|
-
return true;
|
|
2999
|
-
} // 判断dist是否存在node_modules
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
if (!fs.existsSync(`${contextDir}/node_modules`)) {
|
|
3003
|
-
return true;
|
|
3004
|
-
} // 判断dist是否存在miniprogram_npm
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
if (!fs.existsSync(`${contextDir}/miniprogram_npm`)) {
|
|
3008
|
-
return true;
|
|
3009
|
-
} // 判断dist是否存在app.json
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
if (!fs.existsSync(`${contextDir}/app.json`)) {
|
|
3013
|
-
return true;
|
|
3014
|
-
} // 判断模块信息
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
if (checkModule(targetModules)) {
|
|
3018
|
-
return true;
|
|
3019
|
-
} // 判断package.json的版本是否有新的版本
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
if (checkDependencies(targetModules, resolve$2('./'), tmsConfig.outputDir)) {
|
|
3023
|
-
return true;
|
|
3024
|
-
}
|
|
3025
|
-
|
|
3026
|
-
return false;
|
|
3027
|
-
}
|
|
3028
|
-
|
|
3029
|
-
var isInIt = {
|
|
3030
|
-
isInit: isInit$1
|
|
3031
|
-
};
|
|
3032
|
-
|
|
3033
3256
|
const shelljs$1 = require$$0__default$3;
|
|
3034
3257
|
const compileDev = dev$3.exports;
|
|
3035
3258
|
const {
|
|
3036
|
-
resolve: resolve$
|
|
3259
|
+
resolve: resolve$2,
|
|
3260
|
+
filterField: filterField$1
|
|
3037
3261
|
} = widgets;
|
|
3038
3262
|
const init$4 = init_1;
|
|
3039
|
-
const {
|
|
3040
|
-
isInit
|
|
3041
|
-
} = isInIt;
|
|
3042
3263
|
const {
|
|
3043
3264
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
3044
3265
|
} = tmsMpconfig;
|
|
@@ -3047,14 +3268,17 @@ const {
|
|
|
3047
3268
|
} = log$1;
|
|
3048
3269
|
const {
|
|
3049
3270
|
global: global$1
|
|
3050
|
-
} = global_1;
|
|
3271
|
+
} = global_1;
|
|
3272
|
+
const {
|
|
3273
|
+
CACHE_DIR
|
|
3274
|
+
} = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
3051
3275
|
|
|
3052
3276
|
function delOtherModule(tmsConfig, targetModules) {
|
|
3053
|
-
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
|
|
3277
|
+
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules.all, tmsConfig.appName);
|
|
3054
3278
|
const targetModulesName = targetModules.map(item => item.name);
|
|
3055
3279
|
modules.forEach(item => {
|
|
3056
3280
|
if (item.root && targetModulesName.indexOf(item.name) === -1) {
|
|
3057
|
-
const moduleRootDir = resolve$
|
|
3281
|
+
const moduleRootDir = resolve$2(`dist/${item.root}`);
|
|
3058
3282
|
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
3059
3283
|
silent: true
|
|
3060
3284
|
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
@@ -3064,16 +3288,32 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
3064
3288
|
}
|
|
3065
3289
|
|
|
3066
3290
|
async function dev$2(tmsConfig, targetModules, env) {
|
|
3291
|
+
var _tmsConfig$hooks;
|
|
3292
|
+
|
|
3067
3293
|
let newModules = targetModules;
|
|
3068
|
-
const
|
|
3294
|
+
const {
|
|
3295
|
+
noCache
|
|
3296
|
+
} = global$1.getData('cmd');
|
|
3069
3297
|
|
|
3070
|
-
if (
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
}
|
|
3298
|
+
if (noCache) {
|
|
3299
|
+
shelljs$1.rm('-rf', resolve$2(tmsConfig.outputDir));
|
|
3300
|
+
shelljs$1.rm('-rf', CACHE_DIR);
|
|
3301
|
+
} // 初始化操作
|
|
3075
3302
|
|
|
3303
|
+
|
|
3304
|
+
const initData = await init$4(tmsConfig, newModules);
|
|
3305
|
+
newModules = initData.targetModules;
|
|
3076
3306
|
info$2('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
3307
|
+
|
|
3308
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3309
|
+
var _tmsConfig$hooks2;
|
|
3310
|
+
|
|
3311
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3312
|
+
isDev: true,
|
|
3313
|
+
tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
|
|
3314
|
+
modules: newModules
|
|
3315
|
+
}));
|
|
3316
|
+
}
|
|
3077
3317
|
delOtherModule(tmsConfig, newModules);
|
|
3078
3318
|
compileDev(tmsConfig, newModules, env);
|
|
3079
3319
|
}
|
|
@@ -3088,26 +3328,107 @@ var build$2 = async (tmsConfig, newModules) => {
|
|
|
3088
3328
|
|
|
3089
3329
|
const shelljs = require$$0__default$3;
|
|
3090
3330
|
const {
|
|
3091
|
-
resolve
|
|
3331
|
+
resolve: resolve$1,
|
|
3332
|
+
filterField
|
|
3092
3333
|
} = widgets;
|
|
3093
3334
|
const init$3 = init_1;
|
|
3094
3335
|
const compileBuild = build$2;
|
|
3095
3336
|
|
|
3096
3337
|
async function build$1(tmsConfig, targetModules, env) {
|
|
3338
|
+
var _tmsConfig$hooks;
|
|
3339
|
+
|
|
3097
3340
|
// 开始构建前,清理输出目录
|
|
3098
|
-
await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
3341
|
+
await shelljs.rm('-rf', resolve$1(tmsConfig.outputDir));
|
|
3099
3342
|
const {
|
|
3100
3343
|
targetModules: newModules
|
|
3101
3344
|
} = await init$3(tmsConfig, targetModules);
|
|
3345
|
+
|
|
3346
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3347
|
+
var _tmsConfig$hooks2;
|
|
3348
|
+
|
|
3349
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3350
|
+
isDev: false,
|
|
3351
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3352
|
+
modules: newModules
|
|
3353
|
+
}));
|
|
3354
|
+
}
|
|
3102
3355
|
compileBuild(tmsConfig, newModules, env);
|
|
3103
3356
|
}
|
|
3104
3357
|
|
|
3105
3358
|
var build_1 = build$1;
|
|
3106
3359
|
|
|
3360
|
+
const fs = require$$0__default$2;
|
|
3361
|
+
const {
|
|
3362
|
+
resolve
|
|
3363
|
+
} = widgets;
|
|
3364
|
+
const {
|
|
3365
|
+
handleError: handleError$1
|
|
3366
|
+
} = handleError_1;
|
|
3367
|
+
const {
|
|
3368
|
+
ensureDirExist
|
|
3369
|
+
} = io$3;
|
|
3370
|
+
const {
|
|
3371
|
+
warn
|
|
3372
|
+
} = log$1;
|
|
3373
|
+
/**
|
|
3374
|
+
* 根据相关配置创建软链接
|
|
3375
|
+
* @param { object } tmsConfig
|
|
3376
|
+
*/
|
|
3377
|
+
|
|
3378
|
+
const symLink$1 = tmsConfig => {
|
|
3379
|
+
try {
|
|
3380
|
+
ensureDirExist(resolve(tmsConfig.cloudDir));
|
|
3381
|
+
|
|
3382
|
+
if (tmsConfig.cloudModules) {
|
|
3383
|
+
tmsConfig.cloudModules.forEach(item => {
|
|
3384
|
+
const sourcePath = resolve(item.path);
|
|
3385
|
+
const targetPath = resolve(tmsConfig.cloudDir, item.name);
|
|
3386
|
+
|
|
3387
|
+
if (!fs.existsSync(sourcePath)) {
|
|
3388
|
+
warn(`云函数${sourcePath}不存在`);
|
|
3389
|
+
return;
|
|
3390
|
+
}
|
|
3391
|
+
|
|
3392
|
+
if (!fs.existsSync(targetPath)) {
|
|
3393
|
+
fs.symlinkSync(sourcePath, targetPath);
|
|
3394
|
+
}
|
|
3395
|
+
});
|
|
3396
|
+
}
|
|
3397
|
+
} catch (e) {
|
|
3398
|
+
handleError$1(`创建软链错误: ${e}`);
|
|
3399
|
+
}
|
|
3400
|
+
};
|
|
3401
|
+
|
|
3402
|
+
var symbolicLink = {
|
|
3403
|
+
symLink: symLink$1
|
|
3404
|
+
};
|
|
3405
|
+
|
|
3406
|
+
const {
|
|
3407
|
+
symLink
|
|
3408
|
+
} = symbolicLink;
|
|
3409
|
+
const {
|
|
3410
|
+
handleError
|
|
3411
|
+
} = handleError_1;
|
|
3412
|
+
const {
|
|
3413
|
+
succeed
|
|
3414
|
+
} = log$1;
|
|
3415
|
+
|
|
3416
|
+
var cloud$1 = async tmsConfig => {
|
|
3417
|
+
try {
|
|
3418
|
+
await symLink(tmsConfig);
|
|
3419
|
+
succeed('云函数创建软链成功');
|
|
3420
|
+
} catch (e) {
|
|
3421
|
+
handleError(`创建软链错误: ${e}`);
|
|
3422
|
+
}
|
|
3423
|
+
};
|
|
3424
|
+
|
|
3425
|
+
/* eslint-disable no-param-reassign */
|
|
3426
|
+
const loadash = require$$0__default$6;
|
|
3107
3427
|
const init$2 = init_1;
|
|
3108
3428
|
const dev = dev_1;
|
|
3109
3429
|
const build = build_1;
|
|
3110
3430
|
const install = install_1;
|
|
3431
|
+
const cloud = cloud$1;
|
|
3111
3432
|
const {
|
|
3112
3433
|
global
|
|
3113
3434
|
} = global_1;
|
|
@@ -3135,40 +3456,60 @@ const handleModuleArg = cmd => {
|
|
|
3135
3456
|
*/
|
|
3136
3457
|
|
|
3137
3458
|
|
|
3138
|
-
const getSpecificModules = (moduleArg,
|
|
3459
|
+
const getSpecificModules = (moduleArg, modules) => {
|
|
3139
3460
|
if (moduleArg.length > 0) {
|
|
3140
3461
|
return moduleArg;
|
|
3141
|
-
}
|
|
3462
|
+
}
|
|
3142
3463
|
|
|
3464
|
+
const {
|
|
3465
|
+
all,
|
|
3466
|
+
include,
|
|
3467
|
+
exclude,
|
|
3468
|
+
blockRemote
|
|
3469
|
+
} = modules; // 单模块或多模块开发-用户在tms.private.js指定的模块
|
|
3470
|
+
|
|
3471
|
+
if ((include === null || include === void 0 ? void 0 : include.length) > 0) {
|
|
3472
|
+
return include;
|
|
3473
|
+
}
|
|
3143
3474
|
|
|
3144
|
-
if (
|
|
3145
|
-
|
|
3475
|
+
if ((exclude === null || exclude === void 0 ? void 0 : exclude.length) > 0) {
|
|
3476
|
+
return all.filter(module => !exclude.includes(module.name)).map(item => item.name);
|
|
3477
|
+
}
|
|
3146
3478
|
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3479
|
+
if (blockRemote === true) {
|
|
3480
|
+
return all.filter(module => module.repoInfo === undefined).map(item => item.name);
|
|
3481
|
+
}
|
|
3150
3482
|
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
}
|
|
3483
|
+
return all.map(item => item.name);
|
|
3484
|
+
};
|
|
3154
3485
|
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3486
|
+
const mergeConfig = (tmsConfig, tmsPrivateCf) => {
|
|
3487
|
+
const modules = {};
|
|
3488
|
+
|
|
3489
|
+
if (Array.isArray(tmsConfig.modules)) {
|
|
3490
|
+
modules.all = tmsConfig.modules;
|
|
3491
|
+
tmsConfig.modules = modules;
|
|
3492
|
+
} // 合并默认值
|
|
3159
3493
|
|
|
3160
|
-
|
|
3494
|
+
|
|
3495
|
+
const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
|
|
3496
|
+
if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
|
|
3497
|
+
return objValue.concat(srcValue);
|
|
3498
|
+
}
|
|
3499
|
+
});
|
|
3500
|
+
return res;
|
|
3161
3501
|
};
|
|
3162
3502
|
|
|
3163
3503
|
async function run(commandName, cmd) {
|
|
3164
|
-
//
|
|
3504
|
+
// 用户本地的私有项目配置
|
|
3165
3505
|
const tmsPrivateCf = readTmsPrivateCf();
|
|
3166
3506
|
const {
|
|
3167
3507
|
env = tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : tmsPrivateCf.env
|
|
3168
3508
|
} = cmd;
|
|
3169
|
-
|
|
3509
|
+
let tmsConfig = readTmsConfig(env);
|
|
3510
|
+
tmsConfig = mergeConfig(tmsConfig, tmsPrivateCf); // 处理module参数
|
|
3170
3511
|
|
|
3171
|
-
const specificModules = getSpecificModules(handleModuleArg(cmd),
|
|
3512
|
+
const specificModules = getSpecificModules(handleModuleArg(cmd), tmsConfig.modules);
|
|
3172
3513
|
const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])], true); // tms.config.js的modules 合并 module.config.json的配置项
|
|
3173
3514
|
|
|
3174
3515
|
let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
@@ -3178,7 +3519,6 @@ async function run(commandName, cmd) {
|
|
|
3178
3519
|
global.setData({
|
|
3179
3520
|
env,
|
|
3180
3521
|
cmd,
|
|
3181
|
-
tmsPrivateCf,
|
|
3182
3522
|
tmsConfig
|
|
3183
3523
|
});
|
|
3184
3524
|
|
|
@@ -3192,6 +3532,10 @@ async function run(commandName, cmd) {
|
|
|
3192
3532
|
dev(tmsConfig, newModules, env);
|
|
3193
3533
|
return;
|
|
3194
3534
|
|
|
3535
|
+
case 'cloud':
|
|
3536
|
+
cloud(tmsConfig, env);
|
|
3537
|
+
return;
|
|
3538
|
+
|
|
3195
3539
|
case 'install':
|
|
3196
3540
|
install(tmsConfig, newModules, env);
|
|
3197
3541
|
return;
|
|
@@ -3228,10 +3572,17 @@ var entry = [{
|
|
|
3228
3572
|
}, {
|
|
3229
3573
|
command: 'dev',
|
|
3230
3574
|
description: 'dev 打包编译',
|
|
3231
|
-
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-
|
|
3575
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-noCache, --noCache', '不使用缓存功能']],
|
|
3232
3576
|
action: cmd => {
|
|
3233
3577
|
run_1('dev', cmd);
|
|
3234
3578
|
}
|
|
3579
|
+
}, {
|
|
3580
|
+
command: 'cloud',
|
|
3581
|
+
description: '云函数开发',
|
|
3582
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
3583
|
+
action: cmd => {
|
|
3584
|
+
run_1('cloud', cmd);
|
|
3585
|
+
}
|
|
3235
3586
|
}, {
|
|
3236
3587
|
command: 'build',
|
|
3237
3588
|
description: 'prod 打包编译',
|
|
@@ -3256,13 +3607,14 @@ var entry = [{
|
|
|
3256
3607
|
|
|
3257
3608
|
var require$$7 = {
|
|
3258
3609
|
name: "@tmsfe/tmskit",
|
|
3259
|
-
version: "0.0.
|
|
3610
|
+
version: "0.0.18",
|
|
3260
3611
|
description: "tmskit",
|
|
3261
3612
|
main: "dist/index.cjs",
|
|
3262
3613
|
bin: {
|
|
3263
3614
|
tmskit: "main.js"
|
|
3264
3615
|
},
|
|
3265
3616
|
files: [
|
|
3617
|
+
"build",
|
|
3266
3618
|
"src",
|
|
3267
3619
|
"dist",
|
|
3268
3620
|
"main.js",
|
|
@@ -3294,8 +3646,18 @@ var require$$7 = {
|
|
|
3294
3646
|
"rollup-plugin-typescript2": "0.27.0"
|
|
3295
3647
|
},
|
|
3296
3648
|
dependencies: {
|
|
3649
|
+
"ansi-colors": "1.1.0",
|
|
3650
|
+
anymatch: "^1.3.0",
|
|
3651
|
+
"fancy-log": "1.3.2",
|
|
3652
|
+
"glob-parent": "^3.0.1",
|
|
3653
|
+
"path-is-absolute": "^1.0.1",
|
|
3654
|
+
"readable-stream": "^2.2.2",
|
|
3655
|
+
slash: "^1.0.0",
|
|
3656
|
+
vinyl: "^2.1.0",
|
|
3657
|
+
"vinyl-file": "^2.0.0",
|
|
3297
3658
|
async: "^3.2.2",
|
|
3298
3659
|
chalk: "^4.1.0",
|
|
3660
|
+
chokidar: "^3.5.3",
|
|
3299
3661
|
commander: "^8.3.0",
|
|
3300
3662
|
"copy-webpack-plugin": "^9.1.0",
|
|
3301
3663
|
ejs: "^3.1.5",
|
|
@@ -3309,7 +3671,7 @@ var require$$7 = {
|
|
|
3309
3671
|
lodash: "^4.17.21",
|
|
3310
3672
|
metalsmith: "^2.3.0",
|
|
3311
3673
|
"miniprogram-ci": "1.4.13",
|
|
3312
|
-
moment: "^2.29.
|
|
3674
|
+
moment: "^2.29.2",
|
|
3313
3675
|
"object-assign": "^4.0.1",
|
|
3314
3676
|
ora: "^5.1.0",
|
|
3315
3677
|
"plugin-error": "^1.0.0",
|
|
@@ -3329,7 +3691,7 @@ var require$$7 = {
|
|
|
3329
3691
|
}
|
|
3330
3692
|
};
|
|
3331
3693
|
|
|
3332
|
-
const semver = require$$1__default$
|
|
3694
|
+
const semver = require$$1__default$7;
|
|
3333
3695
|
const packageJson = require$$7;
|
|
3334
3696
|
const chalk$1 = require$$0__default;
|
|
3335
3697
|
const {
|