@tmsfe/tmskit 0.0.15 → 0.0.16
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/build/publish.sh +34 -0
- package/dist/index.cjs.js +700 -415
- package/main.js +0 -0
- package/package.json +12 -1
- package/src/compile/compile.js +56 -35
- package/src/compile/dev.js +27 -23
- package/src/compile/plugins/gulp-watch/index.js +172 -0
- package/src/compile/watch.js +51 -15
- package/src/core/buildAppJson.js +3 -0
- package/src/entry.js +1 -1
- package/src/scripts/run/dev/index.js +12 -8
- package/src/scripts/run/init/index.js +27 -15
- package/src/scripts/run/install/index.js +18 -9
- package/src/utils/io.js +20 -0
- package/src/utils/log.js +4 -4
- package/src/utils/widgets.js +3 -3
- package/CHANGELOG.md +0 -26
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
|
* 打印绿底黑字格式的文字
|
|
@@ -102,7 +124,7 @@ const succeed$1 = (message = '') => {
|
|
|
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,25 +133,25 @@ const succeed$1 = (message = '') => {
|
|
|
111
133
|
*/
|
|
112
134
|
|
|
113
135
|
|
|
114
|
-
const warn = message => {
|
|
115
|
-
console.log(
|
|
136
|
+
const warn$1 = 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
144
|
succeed: succeed$1,
|
|
123
|
-
warn,
|
|
145
|
+
warn: warn$1,
|
|
124
146
|
info: info$9
|
|
125
147
|
};
|
|
126
148
|
|
|
127
149
|
const program$1 = require$$0__default$1;
|
|
128
150
|
const leven = require$$1__default$1;
|
|
129
151
|
const ora = require$$2__default;
|
|
130
|
-
const path$
|
|
152
|
+
const path$c = require$$1__default$2;
|
|
131
153
|
const fs$d = require$$0__default$2;
|
|
132
|
-
const shelljs$
|
|
154
|
+
const shelljs$7 = require$$0__default$3;
|
|
133
155
|
const {
|
|
134
156
|
info: info$8
|
|
135
157
|
} = log$1;
|
|
@@ -141,8 +163,8 @@ const shelljsOptions = {
|
|
|
141
163
|
|
|
142
164
|
const cwd = process.cwd();
|
|
143
165
|
|
|
144
|
-
function resolve$
|
|
145
|
-
return path$
|
|
166
|
+
function resolve$e(...args) {
|
|
167
|
+
return path$c.resolve(cwd, ...args);
|
|
146
168
|
}
|
|
147
169
|
/**
|
|
148
170
|
* 用户输入命令时,进行提示
|
|
@@ -199,19 +221,19 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
199
221
|
return new Promise((resolve, reject) => {
|
|
200
222
|
// 如果目标目录不存在
|
|
201
223
|
if (fs$d.existsSync(dest)) {
|
|
202
|
-
shelljs$
|
|
224
|
+
shelljs$7.rm('-rf', path$c.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
|
};
|
|
@@ -311,11 +334,11 @@ const mergeMap = function (obj, src) {
|
|
|
311
334
|
};
|
|
312
335
|
|
|
313
336
|
const relativeCwdPath$1 = function (file) {
|
|
314
|
-
return path$
|
|
337
|
+
return path$c.relative(process.cwd(), file);
|
|
315
338
|
};
|
|
316
339
|
|
|
317
340
|
var widgets = {
|
|
318
|
-
resolve: resolve$
|
|
341
|
+
resolve: resolve$e,
|
|
319
342
|
isObject: isObject$2,
|
|
320
343
|
isArray: isArray$1,
|
|
321
344
|
createTask: createTask$3,
|
|
@@ -328,20 +351,20 @@ var widgets = {
|
|
|
328
351
|
relativeCwdPath: relativeCwdPath$1
|
|
329
352
|
};
|
|
330
353
|
|
|
331
|
-
const path$
|
|
354
|
+
const path$b = require('path');
|
|
332
355
|
|
|
333
356
|
const os = require('os'); // 用户目录
|
|
334
357
|
|
|
335
358
|
|
|
336
359
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
337
360
|
|
|
338
|
-
const CACHE_DIR$
|
|
361
|
+
const CACHE_DIR$2 = path$b.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
339
362
|
|
|
340
|
-
const TEMPLATE_DIR$1 = path$
|
|
363
|
+
const TEMPLATE_DIR$1 = path$b.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
341
364
|
|
|
342
|
-
const MODULE_CODE_DIR$
|
|
365
|
+
const MODULE_CODE_DIR$1 = path$b.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
|
|
343
366
|
|
|
344
|
-
const TEMPLATE_PATH$1 = path$
|
|
367
|
+
const TEMPLATE_PATH$1 = path$b.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
345
368
|
|
|
346
369
|
const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
|
|
347
370
|
|
|
@@ -355,7 +378,7 @@ const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
|
355
378
|
const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
|
|
356
379
|
|
|
357
380
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
358
|
-
app: path$
|
|
381
|
+
app: path$b.resolve(process.cwd(), 'app')
|
|
359
382
|
}; // 默认从源码拷贝到编译后的配置
|
|
360
383
|
|
|
361
384
|
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
|
|
@@ -369,7 +392,7 @@ const MODULE_CONFIG_INVALID_KEY$1 = ['entranceDeclare', 'entryPagePath'];
|
|
|
369
392
|
var constant = /*#__PURE__*/Object.freeze({
|
|
370
393
|
__proto__: null,
|
|
371
394
|
HOME_DIR: HOME_DIR,
|
|
372
|
-
CACHE_DIR: CACHE_DIR$
|
|
395
|
+
CACHE_DIR: CACHE_DIR$2,
|
|
373
396
|
TEMPLATE_DIR: TEMPLATE_DIR$1,
|
|
374
397
|
TEMPLATE_PATH: TEMPLATE_PATH$1,
|
|
375
398
|
TMS_NAME: TMS_NAME$1,
|
|
@@ -379,7 +402,7 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
379
402
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
380
403
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
381
404
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
382
|
-
MODULE_CODE_DIR: MODULE_CODE_DIR$
|
|
405
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
383
406
|
ENV: ENV,
|
|
384
407
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
385
408
|
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1,
|
|
@@ -389,7 +412,7 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
389
412
|
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
390
413
|
|
|
391
414
|
const fs$c = require$$0__default$2;
|
|
392
|
-
const path$
|
|
415
|
+
const path$a = require$$1__default$2;
|
|
393
416
|
const {
|
|
394
417
|
info: info$7
|
|
395
418
|
} = log$1;
|
|
@@ -433,7 +456,7 @@ const copyFile = function (src, dest) {
|
|
|
433
456
|
fs$c.unlinkSync(dest);
|
|
434
457
|
}
|
|
435
458
|
|
|
436
|
-
const dir = path$
|
|
459
|
+
const dir = path$a.dirname(dest);
|
|
437
460
|
ensureDirExist(dir);
|
|
438
461
|
fs$c.copyFileSync(src, dest);
|
|
439
462
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
@@ -493,7 +516,7 @@ const fileInDir$3 = (dir, file) => {
|
|
|
493
516
|
return false;
|
|
494
517
|
}
|
|
495
518
|
|
|
496
|
-
const relativePath = path$
|
|
519
|
+
const relativePath = path$a.relative(dir, file);
|
|
497
520
|
|
|
498
521
|
if (relativePath.startsWith('..')) {
|
|
499
522
|
return false;
|
|
@@ -502,14 +525,37 @@ const fileInDir$3 = (dir, file) => {
|
|
|
502
525
|
return true;
|
|
503
526
|
};
|
|
504
527
|
|
|
505
|
-
|
|
528
|
+
function findAllFilesOfDir$1(dir) {
|
|
529
|
+
const list = [];
|
|
530
|
+
|
|
531
|
+
function listFile(dir) {
|
|
532
|
+
const arr = fs$c.readdirSync(dir);
|
|
533
|
+
arr.forEach(item => {
|
|
534
|
+
const fullPath = path$a.join(dir, item);
|
|
535
|
+
const stats = fs$c.statSync(fullPath);
|
|
536
|
+
|
|
537
|
+
if (stats.isDirectory()) {
|
|
538
|
+
listFile(fullPath);
|
|
539
|
+
} else {
|
|
540
|
+
list.push(fullPath);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
return list;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
listFile(dir);
|
|
547
|
+
return list;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
var io$3 = {
|
|
506
551
|
isDirEmpty,
|
|
507
552
|
copyFile,
|
|
508
553
|
diffContentCopyFile: diffContentCopyFile$3,
|
|
509
554
|
ensureDirExist,
|
|
510
555
|
ext: ext$3,
|
|
511
556
|
fileInDir: fileInDir$3,
|
|
512
|
-
isFile
|
|
557
|
+
isFile,
|
|
558
|
+
findAllFilesOfDir: findAllFilesOfDir$1
|
|
513
559
|
};
|
|
514
560
|
|
|
515
561
|
const async = require$$0__default$4;
|
|
@@ -535,7 +581,7 @@ var render_1 = render$1;
|
|
|
535
581
|
const fs$b = require$$0__default$2;
|
|
536
582
|
const inquirer = require$$1__default$4;
|
|
537
583
|
const {
|
|
538
|
-
resolve: resolve$
|
|
584
|
+
resolve: resolve$d
|
|
539
585
|
} = widgets;
|
|
540
586
|
const {
|
|
541
587
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
@@ -587,7 +633,7 @@ const isQuestionType = result => {
|
|
|
587
633
|
};
|
|
588
634
|
|
|
589
635
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
590
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
636
|
+
const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
591
637
|
const metadata = metalsmith.metadata();
|
|
592
638
|
const filteredPrompts = prompts.filter(prompt => {
|
|
593
639
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -629,9 +675,9 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
629
675
|
|
|
630
676
|
var generator_1 = generator$1;
|
|
631
677
|
|
|
632
|
-
const path$
|
|
678
|
+
const path$9 = require$$1__default$2;
|
|
633
679
|
const fs$a = require$$0__default$2;
|
|
634
|
-
const shelljs$
|
|
680
|
+
const shelljs$6 = require$$0__default$3;
|
|
635
681
|
const {
|
|
636
682
|
TEMPLATE_DIR,
|
|
637
683
|
TEMPLATE_PATH,
|
|
@@ -640,9 +686,9 @@ const {
|
|
|
640
686
|
const {
|
|
641
687
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
642
688
|
createTask: createTask$2,
|
|
643
|
-
resolve: resolve$
|
|
689
|
+
resolve: resolve$c
|
|
644
690
|
} = widgets;
|
|
645
|
-
const io$
|
|
691
|
+
const io$2 = io$3;
|
|
646
692
|
const {
|
|
647
693
|
fail: fail$8,
|
|
648
694
|
succeed,
|
|
@@ -658,12 +704,12 @@ const generator = generator_1;
|
|
|
658
704
|
async function createAppDir(targetDir) {
|
|
659
705
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
660
706
|
if (fs$a.existsSync(targetDir)) {
|
|
661
|
-
if (!(await io$
|
|
707
|
+
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
662
708
|
fail$8('该目录名已经存在,换个项目名字吧~');
|
|
663
709
|
process.exit(1);
|
|
664
710
|
}
|
|
665
711
|
} else {
|
|
666
|
-
shelljs$
|
|
712
|
+
shelljs$6.mkdir('-p', targetDir);
|
|
667
713
|
}
|
|
668
714
|
}
|
|
669
715
|
/**
|
|
@@ -675,35 +721,35 @@ async function createAppDir(targetDir) {
|
|
|
675
721
|
|
|
676
722
|
async function create(appName) {
|
|
677
723
|
const cwd = process.cwd();
|
|
678
|
-
const targetDir = path$
|
|
724
|
+
const targetDir = path$9.resolve(cwd, appName);
|
|
679
725
|
const appType = 'mp';
|
|
680
726
|
await createAppDir(targetDir); // 创建缓存目录
|
|
681
727
|
|
|
682
|
-
io$
|
|
728
|
+
io$2.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
|
|
683
729
|
|
|
684
730
|
await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
685
731
|
|
|
686
|
-
generator(path$
|
|
732
|
+
generator(path$9.join(TEMPLATE_PATH, appType), targetDir, {
|
|
687
733
|
appName,
|
|
688
734
|
appType
|
|
689
735
|
}).then(() => {
|
|
690
|
-
shelljs$
|
|
736
|
+
shelljs$6.cd(appName);
|
|
691
737
|
|
|
692
|
-
const hooks = require(resolve$
|
|
738
|
+
const hooks = require(resolve$c(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
693
739
|
|
|
694
740
|
if (hooks.afterCreate) {
|
|
695
741
|
hooks.afterCreate.forEach(item => {
|
|
696
742
|
if (typeof item === 'function') {
|
|
697
|
-
item.call(null, shelljs$
|
|
743
|
+
item.call(null, shelljs$6, {
|
|
698
744
|
appName
|
|
699
745
|
});
|
|
700
746
|
} else {
|
|
701
|
-
shelljs$
|
|
747
|
+
shelljs$6.exec(item);
|
|
702
748
|
}
|
|
703
749
|
});
|
|
704
750
|
}
|
|
705
751
|
|
|
706
|
-
shelljs$
|
|
752
|
+
shelljs$6.rm('-rf', resolve$c(appName, TEMPLATE_TKIT_DIR));
|
|
707
753
|
succeed('项目创建完成.');
|
|
708
754
|
}).catch(err => {
|
|
709
755
|
fail$8(err.message);
|
|
@@ -743,7 +789,7 @@ const {
|
|
|
743
789
|
TMS_PRIVATE_FILENAME
|
|
744
790
|
} = require$$4;
|
|
745
791
|
const {
|
|
746
|
-
resolve: resolve$
|
|
792
|
+
resolve: resolve$b,
|
|
747
793
|
isObject: isObject$1,
|
|
748
794
|
isArray
|
|
749
795
|
} = widgets;
|
|
@@ -751,14 +797,14 @@ const defaultTmsConfig = defaultTmsConfig$1;
|
|
|
751
797
|
const {
|
|
752
798
|
fail: fail$7
|
|
753
799
|
} = log$1;
|
|
754
|
-
const path$
|
|
800
|
+
const path$8 = require$$1__default$2;
|
|
755
801
|
/**
|
|
756
802
|
* 读取tms.config.js
|
|
757
803
|
* @param env {string} 环境变量
|
|
758
804
|
*/
|
|
759
805
|
|
|
760
806
|
const readTmsConfig$1 = function (env) {
|
|
761
|
-
const tmsConfigPath = resolve$
|
|
807
|
+
const tmsConfigPath = resolve$b(TMS_CONFIG_FILENAME);
|
|
762
808
|
|
|
763
809
|
if (!fs$9.existsSync(tmsConfigPath)) {
|
|
764
810
|
fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
@@ -786,14 +832,14 @@ const convertModules = modules => {
|
|
|
786
832
|
if (typeof module === 'string') {
|
|
787
833
|
// 路径字符串
|
|
788
834
|
Object.assign(newModule, {
|
|
789
|
-
name: path$
|
|
835
|
+
name: path$8.basename(module),
|
|
790
836
|
path: module
|
|
791
837
|
});
|
|
792
838
|
} else if (typeof module === 'object') {
|
|
793
839
|
Object.assign(newModule, module);
|
|
794
840
|
|
|
795
841
|
if (module.name === undefined) {
|
|
796
|
-
newModule.name = path$
|
|
842
|
+
newModule.name = path$8.basename(module.path);
|
|
797
843
|
}
|
|
798
844
|
}
|
|
799
845
|
|
|
@@ -808,7 +854,7 @@ const convertModules = modules => {
|
|
|
808
854
|
|
|
809
855
|
const readTmsPrivateCf$1 = function () {
|
|
810
856
|
let tmsPrivateCf = {};
|
|
811
|
-
const tmsPrivatePath = resolve$
|
|
857
|
+
const tmsPrivatePath = resolve$b(TMS_PRIVATE_FILENAME);
|
|
812
858
|
|
|
813
859
|
if (fs$9.existsSync(tmsPrivatePath)) {
|
|
814
860
|
tmsPrivateCf = require(tmsPrivatePath);
|
|
@@ -902,7 +948,7 @@ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
|
|
|
902
948
|
modules.forEach(({
|
|
903
949
|
path
|
|
904
950
|
}) => {
|
|
905
|
-
const moduleConfigPath = resolve$
|
|
951
|
+
const moduleConfigPath = resolve$b(path, moduleConfigFilename);
|
|
906
952
|
|
|
907
953
|
if (fs$9.existsSync(moduleConfigPath)) {
|
|
908
954
|
const content = fs$9.readFileSync(moduleConfigPath, 'utf-8');
|
|
@@ -926,7 +972,7 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
926
972
|
path: relativePath,
|
|
927
973
|
name: moduleName
|
|
928
974
|
}, moduleIndex) => {
|
|
929
|
-
const moduleConfigPath = resolve$
|
|
975
|
+
const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
930
976
|
|
|
931
977
|
if (fs$9.existsSync(moduleConfigPath)) {
|
|
932
978
|
try {
|
|
@@ -1073,7 +1119,7 @@ const {
|
|
|
1073
1119
|
fail: fail$5
|
|
1074
1120
|
} = log$1;
|
|
1075
1121
|
const {
|
|
1076
|
-
resolve: resolve$
|
|
1122
|
+
resolve: resolve$a,
|
|
1077
1123
|
isObject
|
|
1078
1124
|
} = widgets;
|
|
1079
1125
|
const {
|
|
@@ -1231,17 +1277,26 @@ const fixAppJson = appJson => {
|
|
|
1231
1277
|
|
|
1232
1278
|
function buildOutputAppJson$1(tmsConfig, modules) {
|
|
1233
1279
|
try {
|
|
1280
|
+
var _tmsConfig$hooks;
|
|
1281
|
+
|
|
1234
1282
|
// 获取当前 modules 下的所有子模块的配置内容
|
|
1235
1283
|
const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1236
1284
|
|
|
1237
|
-
const appJson = getAppJsonContent(resolve$
|
|
1285
|
+
const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
|
|
1238
1286
|
|
|
1239
1287
|
updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
|
|
1240
1288
|
|
|
1241
1289
|
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1242
1290
|
|
|
1243
1291
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1244
|
-
fs$8.writeFileSync(resolve$
|
|
1292
|
+
fs$8.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1293
|
+
|
|
1294
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1295
|
+
var _tmsConfig$hooks2;
|
|
1296
|
+
|
|
1297
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson(appJson);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1245
1300
|
return appJson;
|
|
1246
1301
|
} catch (e) {
|
|
1247
1302
|
handleError$3(`生成app.json出现错误: ${e}`);
|
|
@@ -1260,14 +1315,14 @@ const crypto$1 = require$$1__default$5;
|
|
|
1260
1315
|
const {
|
|
1261
1316
|
downloadRepoForGit,
|
|
1262
1317
|
pullRepoForGit,
|
|
1263
|
-
resolve: resolve$
|
|
1318
|
+
resolve: resolve$9
|
|
1264
1319
|
} = widgets;
|
|
1265
1320
|
const {
|
|
1266
1321
|
fail: fail$4,
|
|
1267
1322
|
info: info$5
|
|
1268
1323
|
} = log$1;
|
|
1269
1324
|
const fs$7 = require$$0__default$2;
|
|
1270
|
-
const shelljs$
|
|
1325
|
+
const shelljs$5 = require$$0__default$3;
|
|
1271
1326
|
const {
|
|
1272
1327
|
handleError: handleError$2
|
|
1273
1328
|
} = handleError_1;
|
|
@@ -1366,7 +1421,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1366
1421
|
}));
|
|
1367
1422
|
});
|
|
1368
1423
|
await Promise.all(arrPromises);
|
|
1369
|
-
shelljs$
|
|
1424
|
+
shelljs$5.cd(cwd);
|
|
1370
1425
|
}
|
|
1371
1426
|
/**
|
|
1372
1427
|
* 收集下载模块代码的任务
|
|
@@ -1407,9 +1462,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1407
1462
|
|
|
1408
1463
|
const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
|
|
1409
1464
|
|
|
1410
|
-
const sourcePath = resolve$
|
|
1465
|
+
const sourcePath = resolve$9(sourceDir, md5Key); // 模块源码要放到目标目录
|
|
1411
1466
|
|
|
1412
|
-
const targetPath = resolve$
|
|
1467
|
+
const targetPath = resolve$9(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
|
|
1413
1468
|
|
|
1414
1469
|
const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
|
|
1415
1470
|
|
|
@@ -1420,7 +1475,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1420
1475
|
},
|
|
1421
1476
|
fn: async (sourceModulePath, targetPath) => {
|
|
1422
1477
|
if (fs$7.existsSync(targetPath)) {
|
|
1423
|
-
shelljs$
|
|
1478
|
+
shelljs$5.rm('-rf', `${targetPath}/*`);
|
|
1424
1479
|
}
|
|
1425
1480
|
|
|
1426
1481
|
await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
|
|
@@ -1470,7 +1525,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1470
1525
|
*/
|
|
1471
1526
|
|
|
1472
1527
|
|
|
1473
|
-
function checkRemoteModGitUrlBranch
|
|
1528
|
+
function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
1474
1529
|
if (moduleInfo.repoInfo) {
|
|
1475
1530
|
const {
|
|
1476
1531
|
repoInfo: {
|
|
@@ -1492,11 +1547,11 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
|
|
|
1492
1547
|
|
|
1493
1548
|
var cloneModules_1 = {
|
|
1494
1549
|
cloneModules: cloneModules$1,
|
|
1495
|
-
checkRemoteModGitUrlBranch
|
|
1550
|
+
checkRemoteModGitUrlBranch
|
|
1496
1551
|
};
|
|
1497
1552
|
|
|
1498
1553
|
const ci = require$$0__default$7;
|
|
1499
|
-
const path$
|
|
1554
|
+
const path$7 = require$$1__default$2;
|
|
1500
1555
|
/**
|
|
1501
1556
|
* 获取小程序ci的Project对象
|
|
1502
1557
|
* @returns {Object} 小程序ci对象
|
|
@@ -1510,7 +1565,7 @@ const getMpCi = ({
|
|
|
1510
1565
|
}) => {
|
|
1511
1566
|
var _cfgJsonContent$packO;
|
|
1512
1567
|
|
|
1513
|
-
const cfgJsonContent = require(path$
|
|
1568
|
+
const cfgJsonContent = require(path$7.join(projectPath, 'project.config.json'));
|
|
1514
1569
|
|
|
1515
1570
|
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
1571
|
value
|
|
@@ -1582,7 +1637,7 @@ var mpCi = {
|
|
|
1582
1637
|
const fs$6 = require$$0__default$2;
|
|
1583
1638
|
const fsExtra = require$$1__default$6;
|
|
1584
1639
|
const crypto = require$$1__default$5;
|
|
1585
|
-
const path$
|
|
1640
|
+
const path$6 = require$$1__default$2;
|
|
1586
1641
|
const shell = require$$0__default$3;
|
|
1587
1642
|
const glob = require$$5__default;
|
|
1588
1643
|
const log = log$1;
|
|
@@ -1622,14 +1677,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1622
1677
|
|
|
1623
1678
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1624
1679
|
const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1625
|
-
const cacheNMPath = path$
|
|
1626
|
-
const cacheNMTarFile = path$
|
|
1680
|
+
const cacheNMPath = path$6.join(cacheDir, md5Key);
|
|
1681
|
+
const cacheNMTarFile = path$6.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1627
1682
|
|
|
1628
1683
|
const callback = {
|
|
1629
1684
|
params: {
|
|
1630
1685
|
cacheNMPath,
|
|
1631
1686
|
cacheNMTarFile,
|
|
1632
|
-
packageJsonDir: path$
|
|
1687
|
+
packageJsonDir: path$6.dirname(packageJsonPath),
|
|
1633
1688
|
shell
|
|
1634
1689
|
},
|
|
1635
1690
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
@@ -1745,7 +1800,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1745
1800
|
|
|
1746
1801
|
const files = fs$6.readdirSync(startPath);
|
|
1747
1802
|
files.forEach(file => {
|
|
1748
|
-
const filename = path$
|
|
1803
|
+
const filename = path$6.join(startPath, file);
|
|
1749
1804
|
const stat = fs$6.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1750
1805
|
|
|
1751
1806
|
if (stat.isDirectory()) {
|
|
@@ -1772,7 +1827,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1772
1827
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1773
1828
|
|
|
1774
1829
|
const cwd = contextDir || dirPath;
|
|
1775
|
-
const result = [path$
|
|
1830
|
+
const result = [path$6.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1776
1831
|
|
|
1777
1832
|
subRoots.forEach(subRoot => {
|
|
1778
1833
|
if (!subRoot.root) {
|
|
@@ -1780,7 +1835,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1780
1835
|
process.exit(1);
|
|
1781
1836
|
}
|
|
1782
1837
|
|
|
1783
|
-
const toppath = path$
|
|
1838
|
+
const toppath = path$6.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1784
1839
|
|
|
1785
1840
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1786
1841
|
result.push(...list);
|
|
@@ -1788,7 +1843,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1788
1843
|
return result;
|
|
1789
1844
|
};
|
|
1790
1845
|
|
|
1791
|
-
function cloudNpmInstall
|
|
1846
|
+
function cloudNpmInstall(contextDir) {
|
|
1792
1847
|
return new Promise((resolve, reject) => {
|
|
1793
1848
|
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
1794
1849
|
if (err) {
|
|
@@ -1796,7 +1851,7 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1796
1851
|
}
|
|
1797
1852
|
|
|
1798
1853
|
files.forEach(file => {
|
|
1799
|
-
const dir = path$
|
|
1854
|
+
const dir = path$6.dirname(file);
|
|
1800
1855
|
shell.cd(dir);
|
|
1801
1856
|
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1802
1857
|
silent: false
|
|
@@ -1808,57 +1863,165 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1808
1863
|
}
|
|
1809
1864
|
|
|
1810
1865
|
var npm = {
|
|
1811
|
-
cloudNpmInstall
|
|
1866
|
+
cloudNpmInstall,
|
|
1812
1867
|
mpNpmInstallAll: mpNpmInstallAll$1,
|
|
1813
1868
|
findAllPackageJson
|
|
1814
1869
|
};
|
|
1815
1870
|
|
|
1871
|
+
const shelljs$4 = require$$0__default$3;
|
|
1872
|
+
const fs$5 = require$$0__default$2;
|
|
1873
|
+
const io$1 = io$3;
|
|
1816
1874
|
const {
|
|
1817
1875
|
createTask: createTask$1,
|
|
1818
|
-
resolve: resolve$
|
|
1876
|
+
resolve: resolve$8
|
|
1819
1877
|
} = widgets;
|
|
1820
1878
|
const {
|
|
1821
1879
|
buildMpNpm
|
|
1822
1880
|
} = mpCi;
|
|
1823
1881
|
const {
|
|
1824
|
-
CACHE_DIR
|
|
1882
|
+
CACHE_DIR: CACHE_DIR$1
|
|
1825
1883
|
} = require$$4;
|
|
1826
1884
|
const {
|
|
1827
|
-
cloudNpmInstall,
|
|
1828
1885
|
mpNpmInstallAll
|
|
1829
1886
|
} = npm;
|
|
1830
1887
|
const {
|
|
1831
1888
|
global: global$3
|
|
1832
1889
|
} = global_1;
|
|
1890
|
+
const {
|
|
1891
|
+
fail: fail$3
|
|
1892
|
+
} = log$1;
|
|
1893
|
+
|
|
1894
|
+
async function install$2(tmsConfig, modules) {
|
|
1895
|
+
// 拷贝模块的package.json到编译输出目录
|
|
1896
|
+
modules.forEach(item => {
|
|
1897
|
+
const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
|
|
1898
|
+
|
|
1899
|
+
if (!fs$5.existsSync(resolve$8(item.path))) {
|
|
1900
|
+
fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1901
|
+
process.exit(1);
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
io$1.ensureDirExist(outputModuleDir);
|
|
1905
|
+
const modulePackagePath = resolve$8(item.path, 'package.json');
|
|
1906
|
+
if (fs$5.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1907
|
+
}); // 小程序npm install
|
|
1833
1908
|
|
|
1834
|
-
|
|
1835
|
-
// 小程序npm install
|
|
1836
|
-
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
|
|
1909
|
+
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
1837
1910
|
const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1838
1911
|
|
|
1839
1912
|
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1840
1913
|
appId: tmsConfig.appId,
|
|
1841
|
-
projectPath: resolve$
|
|
1914
|
+
projectPath: resolve$8('./'),
|
|
1842
1915
|
privateKey: tmsPrivateCf.privateKey
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$9(tmsConfig.cloudDir));
|
|
1916
|
+
});
|
|
1846
1917
|
}
|
|
1847
1918
|
|
|
1848
1919
|
var install_1 = install$2;
|
|
1849
1920
|
|
|
1921
|
+
const fs$4 = require$$0__default$2;
|
|
1922
|
+
const semver$1 = require$$1__default$7;
|
|
1923
|
+
const {
|
|
1924
|
+
resolve: resolve$7
|
|
1925
|
+
} = widgets;
|
|
1926
|
+
const path$5 = require$$1__default$2;
|
|
1850
1927
|
const shelljs$3 = require$$0__default$3;
|
|
1851
|
-
const fs$5 = require$$0__default$2;
|
|
1852
|
-
const io = io$2;
|
|
1853
1928
|
const {
|
|
1854
|
-
|
|
1929
|
+
handleError
|
|
1930
|
+
} = handleError_1;
|
|
1931
|
+
|
|
1932
|
+
const getLatestVersion = npmName => {
|
|
1933
|
+
const data = shelljs$3.exec(`npm view ${npmName} version`);
|
|
1934
|
+
return data.stdout || '0.0.0';
|
|
1935
|
+
};
|
|
1936
|
+
/**
|
|
1937
|
+
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
1938
|
+
* @param {*} modules 模块
|
|
1939
|
+
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
1940
|
+
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
1941
|
+
* @returns
|
|
1942
|
+
*/
|
|
1943
|
+
|
|
1944
|
+
|
|
1945
|
+
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
1946
|
+
// 步骤1. 收集package.json
|
|
1947
|
+
const packageJsonName = 'package.json'; // 查找文件名
|
|
1948
|
+
// 1.1根目录的package.json
|
|
1949
|
+
|
|
1950
|
+
const packageArr = [{
|
|
1951
|
+
srcPackageDir: path$5.join(cwd, packageJsonName),
|
|
1952
|
+
destNpmDir: resolve$7(outputDir, 'node_modules')
|
|
1953
|
+
}]; // 1.2模块的package.json
|
|
1954
|
+
|
|
1955
|
+
modules.forEach(item => {
|
|
1956
|
+
const srcPackageDir = path$5.join(cwd, item.path, 'package.json');
|
|
1957
|
+
|
|
1958
|
+
if (fs$4.existsSync(srcPackageDir)) {
|
|
1959
|
+
packageArr.push({
|
|
1960
|
+
srcPackageDir,
|
|
1961
|
+
destNpmDir: resolve$7(outputDir, item.root, 'node_modules')
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1965
|
+
|
|
1966
|
+
for (const item of packageArr) {
|
|
1967
|
+
const packageJson = fs$4.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1968
|
+
let dependencies = {};
|
|
1969
|
+
|
|
1970
|
+
try {
|
|
1971
|
+
const json = JSON.parse(packageJson);
|
|
1972
|
+
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
1973
|
+
} catch (e) {
|
|
1974
|
+
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
const dependenciesKeys = Object.keys(dependencies);
|
|
1978
|
+
|
|
1979
|
+
for (const key of dependenciesKeys) {
|
|
1980
|
+
const depPath = path$5.join(item.destNpmDir, key);
|
|
1981
|
+
|
|
1982
|
+
if (!fs$4.existsSync(depPath)) {
|
|
1983
|
+
return true;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
const depPackagePath = path$5.join(depPath, 'package.json');
|
|
1987
|
+
|
|
1988
|
+
if (fs$4.existsSync(depPackagePath)) {
|
|
1989
|
+
const packageData = require(depPackagePath);
|
|
1990
|
+
|
|
1991
|
+
if (dependencies[key] === 'latest') {
|
|
1992
|
+
dependencies[key] = getLatestVersion(key);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
if (packageData.version === 'latest') {
|
|
1996
|
+
packageData.version = getLatestVersion(key);
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
|
|
2000
|
+
return true;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
return false;
|
|
2007
|
+
};
|
|
2008
|
+
|
|
2009
|
+
var checkDependencies_1 = {
|
|
2010
|
+
checkDependencies: checkDependencies$1
|
|
2011
|
+
};
|
|
2012
|
+
|
|
2013
|
+
const shelljs$2 = require$$0__default$3;
|
|
2014
|
+
const fs$3 = require$$0__default$2;
|
|
2015
|
+
const io = io$3;
|
|
2016
|
+
const {
|
|
2017
|
+
resolve: resolve$6,
|
|
1855
2018
|
createTask
|
|
1856
2019
|
} = widgets;
|
|
1857
2020
|
const {
|
|
1858
2021
|
buildOutputAppJson
|
|
1859
2022
|
} = buildAppJson;
|
|
1860
2023
|
const {
|
|
1861
|
-
MODULE_CODE_DIR
|
|
2024
|
+
MODULE_CODE_DIR,
|
|
1862
2025
|
DEFAULT_COPY_CONFIG
|
|
1863
2026
|
} = require$$4;
|
|
1864
2027
|
const {
|
|
@@ -1869,10 +2032,13 @@ const {
|
|
|
1869
2032
|
subModulesMergeDepModules: subModulesMergeDepModules$1
|
|
1870
2033
|
} = tmsMpconfig;
|
|
1871
2034
|
const {
|
|
1872
|
-
fail: fail$
|
|
2035
|
+
fail: fail$2,
|
|
1873
2036
|
info: info$4
|
|
1874
2037
|
} = log$1;
|
|
1875
2038
|
const install$1 = install_1;
|
|
2039
|
+
const {
|
|
2040
|
+
checkDependencies
|
|
2041
|
+
} = checkDependencies_1;
|
|
1876
2042
|
/**
|
|
1877
2043
|
* 拷贝相关配置文件到编译输出目录
|
|
1878
2044
|
* @param { object } tmsConfig
|
|
@@ -1881,40 +2047,52 @@ const install$1 = install_1;
|
|
|
1881
2047
|
* @returns
|
|
1882
2048
|
*/
|
|
1883
2049
|
|
|
1884
|
-
const cpFilesToOutput = function (tmsConfig,
|
|
1885
|
-
const outputDir = resolve$
|
|
2050
|
+
const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
2051
|
+
const outputDir = resolve$6(tmsConfig.outputDir);
|
|
1886
2052
|
io.ensureDirExist(outputDir);
|
|
1887
2053
|
defaultFiles.forEach(item => {
|
|
1888
|
-
if (fs$
|
|
1889
|
-
shelljs$
|
|
2054
|
+
if (fs$3.existsSync(resolve$6(item))) {
|
|
2055
|
+
shelljs$2.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
|
|
1890
2056
|
}
|
|
1891
|
-
});
|
|
2057
|
+
});
|
|
2058
|
+
};
|
|
2059
|
+
/**
|
|
2060
|
+
* 校验相关配置项
|
|
2061
|
+
* @param {*} targetModules
|
|
2062
|
+
* @returns
|
|
2063
|
+
*/
|
|
1892
2064
|
|
|
1893
|
-
targetModules.forEach(item => {
|
|
1894
|
-
const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
|
|
1895
2065
|
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
2066
|
+
function checkConfig(targetModules) {
|
|
2067
|
+
for (const item of targetModules) {
|
|
2068
|
+
if (!item.root) {
|
|
2069
|
+
throw new Error(`检查${item.name} module.config.json的root字段`);
|
|
2070
|
+
} // 判断源码目录是否有该模块
|
|
2071
|
+
|
|
2072
|
+
|
|
2073
|
+
if (item.path && !fs$3.existsSync(resolve$6(item.path))) {
|
|
2074
|
+
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1899
2075
|
}
|
|
2076
|
+
}
|
|
1900
2077
|
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
if (fs$5.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1904
|
-
});
|
|
1905
|
-
};
|
|
2078
|
+
return true;
|
|
2079
|
+
}
|
|
1906
2080
|
|
|
1907
2081
|
async function task(tmsConfig, targetModules) {
|
|
1908
2082
|
// 下载和移动代码
|
|
1909
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR
|
|
2083
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1910
2084
|
|
|
1911
2085
|
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
1912
2086
|
|
|
1913
|
-
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2087
|
+
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2088
|
+
checkConfig(newModules); // 拷贝相关配置文件到输出目录
|
|
2089
|
+
|
|
2090
|
+
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
|
|
1914
2091
|
|
|
1915
|
-
|
|
2092
|
+
if (checkDependencies(newModules, resolve$6('./'), tmsConfig.outputDir)) {
|
|
2093
|
+
await install$1(tmsConfig, newModules);
|
|
2094
|
+
} // 动态生成编译后的app.json;
|
|
1916
2095
|
|
|
1917
|
-
await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
|
|
1918
2096
|
|
|
1919
2097
|
await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
1920
2098
|
return newModules;
|
|
@@ -1928,7 +2106,7 @@ async function init$5(tmsConfig, targetModules) {
|
|
|
1928
2106
|
};
|
|
1929
2107
|
} catch (error) {
|
|
1930
2108
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1931
|
-
fail$
|
|
2109
|
+
fail$2(`初始化流程出现错误${errMsg}`);
|
|
1932
2110
|
info$4('详细的错误信息', error);
|
|
1933
2111
|
process.exit(1);
|
|
1934
2112
|
}
|
|
@@ -1974,16 +2152,16 @@ var findCssImport = {
|
|
|
1974
2152
|
|
|
1975
2153
|
/* eslint-disable no-param-reassign */
|
|
1976
2154
|
const {
|
|
1977
|
-
fail: fail$
|
|
2155
|
+
fail: fail$1
|
|
1978
2156
|
} = log$1;
|
|
1979
2157
|
|
|
1980
2158
|
function pluginError$3(error, isWatch) {
|
|
1981
2159
|
const errMsg = error.message;
|
|
1982
2160
|
|
|
1983
2161
|
if (isWatch) {
|
|
1984
|
-
fail$
|
|
2162
|
+
fail$1(errMsg);
|
|
1985
2163
|
} else {
|
|
1986
|
-
fail$
|
|
2164
|
+
fail$1(errMsg);
|
|
1987
2165
|
process.exit(1);
|
|
1988
2166
|
}
|
|
1989
2167
|
}
|
|
@@ -1994,7 +2172,7 @@ var pluginError_1 = {
|
|
|
1994
2172
|
|
|
1995
2173
|
/* eslint-disable no-param-reassign */
|
|
1996
2174
|
const through$2 = require$$0__default$9;
|
|
1997
|
-
const precinct = require$$1__default$
|
|
2175
|
+
const precinct = require$$1__default$8;
|
|
1998
2176
|
const path$4 = require$$1__default$2;
|
|
1999
2177
|
const {
|
|
2000
2178
|
findCssImports
|
|
@@ -2003,11 +2181,11 @@ const {
|
|
|
2003
2181
|
ext: ext$2,
|
|
2004
2182
|
fileInDir: fileInDir$2,
|
|
2005
2183
|
diffContentCopyFile: diffContentCopyFile$2
|
|
2006
|
-
} = io$
|
|
2184
|
+
} = io$3;
|
|
2007
2185
|
const {
|
|
2008
|
-
resolve: resolve$
|
|
2186
|
+
resolve: resolve$5
|
|
2009
2187
|
} = widgets;
|
|
2010
|
-
const fs$
|
|
2188
|
+
const fs$2 = require$$0__default$2;
|
|
2011
2189
|
const {
|
|
2012
2190
|
pluginError: pluginError$2
|
|
2013
2191
|
} = pluginError_1;
|
|
@@ -2020,7 +2198,7 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2020
2198
|
let contents = '';
|
|
2021
2199
|
|
|
2022
2200
|
try {
|
|
2023
|
-
contents = fs$
|
|
2201
|
+
contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
|
|
2024
2202
|
} catch (e) {
|
|
2025
2203
|
pluginError$2(e, isWatch);
|
|
2026
2204
|
}
|
|
@@ -2037,12 +2215,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2037
2215
|
extPath
|
|
2038
2216
|
} = ext$2(depOriginPath, extensions);
|
|
2039
2217
|
|
|
2040
|
-
if (!fs$
|
|
2218
|
+
if (!fs$2.existsSync(depOriginFile)) {
|
|
2041
2219
|
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2042
2220
|
return;
|
|
2043
2221
|
}
|
|
2044
2222
|
|
|
2045
|
-
const depDestPath = resolve$
|
|
2223
|
+
const depDestPath = resolve$5(path$4.dirname(anaFileDestFile), depItem);
|
|
2046
2224
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2047
2225
|
|
|
2048
2226
|
if (!resDep.has(depDestFile)) {
|
|
@@ -2066,8 +2244,8 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2066
2244
|
const stream = through$2.obj(function (file, enc, cb) {
|
|
2067
2245
|
// 依赖分析的文件
|
|
2068
2246
|
const anaFileOriginFile = file.history[0];
|
|
2069
|
-
const anaFileRelativeModule = path$4.relative(resolve$
|
|
2070
|
-
const anaFileDestFile = resolve$
|
|
2247
|
+
const anaFileRelativeModule = path$4.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2248
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2071
2249
|
|
|
2072
2250
|
if (file.isBuffer()) {
|
|
2073
2251
|
let contents = String(file.contents);
|
|
@@ -2096,7 +2274,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2096
2274
|
const regRes = depItem.match(reg) || [];
|
|
2097
2275
|
|
|
2098
2276
|
if (regRes[2]) {
|
|
2099
|
-
const depDestPath = resolve$
|
|
2277
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2100
2278
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2101
2279
|
|
|
2102
2280
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2147,11 +2325,11 @@ const {
|
|
|
2147
2325
|
ext: ext$1,
|
|
2148
2326
|
fileInDir: fileInDir$1,
|
|
2149
2327
|
diffContentCopyFile: diffContentCopyFile$1
|
|
2150
|
-
} = io$
|
|
2328
|
+
} = io$3;
|
|
2151
2329
|
const {
|
|
2152
|
-
resolve: resolve$
|
|
2330
|
+
resolve: resolve$4
|
|
2153
2331
|
} = widgets;
|
|
2154
|
-
const fs$
|
|
2332
|
+
const fs$1 = require$$0__default$2;
|
|
2155
2333
|
const {
|
|
2156
2334
|
pluginError: pluginError$1
|
|
2157
2335
|
} = pluginError_1;
|
|
@@ -2163,8 +2341,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2163
2341
|
const stream = through$1.obj(function (file, enc, cb) {
|
|
2164
2342
|
// 当前分析的文件的路径
|
|
2165
2343
|
const anaFileOriginFile = file.history[0];
|
|
2166
|
-
const anaFileRelativeModule = path$3.relative(resolve$
|
|
2167
|
-
const anaFileDestFile = resolve$
|
|
2344
|
+
const anaFileRelativeModule = path$3.relative(resolve$4(module.from), anaFileOriginFile);
|
|
2345
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2168
2346
|
|
|
2169
2347
|
if (file.isBuffer()) {
|
|
2170
2348
|
let contents = String(file.contents);
|
|
@@ -2203,7 +2381,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2203
2381
|
const regRes = componentPath.match(reg) || [];
|
|
2204
2382
|
|
|
2205
2383
|
if (regRes[2]) {
|
|
2206
|
-
const depDestPath = resolve$
|
|
2384
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2207
2385
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2208
2386
|
|
|
2209
2387
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2237,7 +2415,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2237
2415
|
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2238
2416
|
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2239
2417
|
|
|
2240
|
-
if (fs$
|
|
2418
|
+
if (fs$1.existsSync(originFile)) {
|
|
2241
2419
|
diffContentCopyFile$1(originFile, destFile);
|
|
2242
2420
|
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2243
2421
|
|
|
@@ -2270,16 +2448,16 @@ var mpJsonDep_1 = {
|
|
|
2270
2448
|
|
|
2271
2449
|
/* eslint-disable no-param-reassign */
|
|
2272
2450
|
const through = require$$0__default$9;
|
|
2273
|
-
const htmlparser2 = require$$1__default$
|
|
2274
|
-
const fs
|
|
2451
|
+
const htmlparser2 = require$$1__default$9;
|
|
2452
|
+
const fs = require$$0__default$2;
|
|
2275
2453
|
const path$2 = require$$1__default$2;
|
|
2276
2454
|
const {
|
|
2277
2455
|
diffContentCopyFile,
|
|
2278
2456
|
ext,
|
|
2279
2457
|
fileInDir
|
|
2280
|
-
} = io$
|
|
2458
|
+
} = io$3;
|
|
2281
2459
|
const {
|
|
2282
|
-
resolve: resolve$
|
|
2460
|
+
resolve: resolve$3
|
|
2283
2461
|
} = widgets;
|
|
2284
2462
|
const {
|
|
2285
2463
|
dfsFindCommonDep
|
|
@@ -2318,7 +2496,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2318
2496
|
let contents = '';
|
|
2319
2497
|
|
|
2320
2498
|
try {
|
|
2321
|
-
contents = fs
|
|
2499
|
+
contents = fs.readFileSync(anaFileOriginFile, 'utf8');
|
|
2322
2500
|
} catch (e) {
|
|
2323
2501
|
pluginError(e, isWatch);
|
|
2324
2502
|
}
|
|
@@ -2336,7 +2514,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2336
2514
|
extPath
|
|
2337
2515
|
} = extFile(name, depOriginPath);
|
|
2338
2516
|
|
|
2339
|
-
if (!fs
|
|
2517
|
+
if (!fs.existsSync(depOriginFile)) {
|
|
2340
2518
|
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2341
2519
|
return;
|
|
2342
2520
|
}
|
|
@@ -2393,8 +2571,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2393
2571
|
const stream = through.obj(function (file, enc, cb) {
|
|
2394
2572
|
// 依赖分析的文件
|
|
2395
2573
|
const anaFileOriginFile = file.history[0];
|
|
2396
|
-
const anaFileRelativeModule = path$2.relative(resolve$
|
|
2397
|
-
const anaFileDestFile = resolve$
|
|
2574
|
+
const anaFileRelativeModule = path$2.relative(resolve$3(module.from), anaFileOriginFile);
|
|
2575
|
+
const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2398
2576
|
|
|
2399
2577
|
if (file.isBuffer()) {
|
|
2400
2578
|
let contents = String(file.contents);
|
|
@@ -2425,7 +2603,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2425
2603
|
const regRes = attributes.src.match(reg) || [];
|
|
2426
2604
|
|
|
2427
2605
|
if (regRes[2]) {
|
|
2428
|
-
const depDestPath = resolve$
|
|
2606
|
+
const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2429
2607
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2430
2608
|
|
|
2431
2609
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2452,7 +2630,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2452
2630
|
beforeDepPath,
|
|
2453
2631
|
afterDepPath
|
|
2454
2632
|
}) => {
|
|
2455
|
-
if (fs
|
|
2633
|
+
if (fs.existsSync(depOriginFile)) {
|
|
2456
2634
|
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2457
2635
|
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2458
2636
|
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
@@ -2508,7 +2686,7 @@ const {
|
|
|
2508
2686
|
// const base64 = require('./plugins/postcss-font-base64');
|
|
2509
2687
|
|
|
2510
2688
|
const {
|
|
2511
|
-
fail
|
|
2689
|
+
fail
|
|
2512
2690
|
} = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
2513
2691
|
|
|
2514
2692
|
var compile = function (tmsConfig, {
|
|
@@ -2516,7 +2694,7 @@ var compile = function (tmsConfig, {
|
|
|
2516
2694
|
destPath,
|
|
2517
2695
|
srcOption,
|
|
2518
2696
|
module,
|
|
2519
|
-
|
|
2697
|
+
isDev
|
|
2520
2698
|
}) {
|
|
2521
2699
|
const compileTasksMap = new Map();
|
|
2522
2700
|
Object.keys(glob).forEach(globKey => {
|
|
@@ -2526,14 +2704,18 @@ var compile = function (tmsConfig, {
|
|
|
2526
2704
|
case 'js':
|
|
2527
2705
|
compileTasksMap.set(globValue, {
|
|
2528
2706
|
module,
|
|
2529
|
-
taskFn: () => {
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
const srcPipe = src$1(
|
|
2707
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2708
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2709
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2710
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2533
2711
|
});
|
|
2534
2712
|
return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
2535
|
-
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'],
|
|
2536
|
-
fail
|
|
2713
|
+
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
|
|
2714
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
2715
|
+
}).pipe(dest(newDestPath, {
|
|
2716
|
+
overwrite: true
|
|
2717
|
+
})).on('error', err => {
|
|
2718
|
+
fail(`js编译报错${err}`);
|
|
2537
2719
|
});
|
|
2538
2720
|
}
|
|
2539
2721
|
});
|
|
@@ -2542,13 +2724,13 @@ var compile = function (tmsConfig, {
|
|
|
2542
2724
|
case 'wxss':
|
|
2543
2725
|
compileTasksMap.set(globValue, {
|
|
2544
2726
|
module,
|
|
2545
|
-
taskFn: () => {
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
const srcPipe = src$1(
|
|
2727
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2728
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2729
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2730
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2549
2731
|
});
|
|
2550
|
-
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'],
|
|
2551
|
-
fail
|
|
2732
|
+
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
|
|
2733
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
2552
2734
|
}) // .pipe(postcss([base64()]))
|
|
2553
2735
|
// .on('error', (err) => {
|
|
2554
2736
|
// fail(`postcss编译报错${err}`);
|
|
@@ -2557,7 +2739,9 @@ var compile = function (tmsConfig, {
|
|
|
2557
2739
|
// designWidth: 375, // 设计稿宽度,默认为750
|
|
2558
2740
|
// precision: 2, // 小数最大精度,默认为6
|
|
2559
2741
|
// }))
|
|
2560
|
-
.pipe(dest(
|
|
2742
|
+
.pipe(dest(newDestPath)).on('error', err => {
|
|
2743
|
+
fail(`wxss编译报错${err}`);
|
|
2744
|
+
});
|
|
2561
2745
|
}
|
|
2562
2746
|
});
|
|
2563
2747
|
break;
|
|
@@ -2565,14 +2749,16 @@ var compile = function (tmsConfig, {
|
|
|
2565
2749
|
case 'json':
|
|
2566
2750
|
compileTasksMap.set(globValue, {
|
|
2567
2751
|
module,
|
|
2568
|
-
taskFn: () => {
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
const srcPipe = src$1(
|
|
2752
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2753
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2754
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2755
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2756
|
+
});
|
|
2757
|
+
return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
|
|
2758
|
+
fail(`mpJsonDep编译报错${err}`);
|
|
2759
|
+
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2760
|
+
fail(`json编译报错${err}`);
|
|
2572
2761
|
});
|
|
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
2762
|
}
|
|
2577
2763
|
});
|
|
2578
2764
|
break;
|
|
@@ -2580,12 +2766,16 @@ var compile = function (tmsConfig, {
|
|
|
2580
2766
|
case 'wxml':
|
|
2581
2767
|
compileTasksMap.set(globValue, {
|
|
2582
2768
|
module,
|
|
2583
|
-
taskFn: () => {
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
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(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
|
|
2775
|
+
fail(`mpWxmlDep编译报错${err}`);
|
|
2776
|
+
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2777
|
+
fail(`wxml编译报错${err}`);
|
|
2587
2778
|
});
|
|
2588
|
-
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isWatch)).pipe(dest(destPath));
|
|
2589
2779
|
}
|
|
2590
2780
|
});
|
|
2591
2781
|
break;
|
|
@@ -2593,16 +2783,18 @@ var compile = function (tmsConfig, {
|
|
|
2593
2783
|
case 'image':
|
|
2594
2784
|
compileTasksMap.set(globValue, {
|
|
2595
2785
|
module,
|
|
2596
|
-
taskFn: () => {
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
const srcPipe = src$1(
|
|
2786
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2787
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2788
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2789
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2600
2790
|
});
|
|
2601
2791
|
return srcPipe // .pipe(cache(image()))
|
|
2602
2792
|
// .on('error', (err) => {
|
|
2603
2793
|
// fail(`image编译报错${err}`);
|
|
2604
2794
|
// })
|
|
2605
|
-
.pipe(dest(
|
|
2795
|
+
.pipe(dest(newDestPath)).on('error', err => {
|
|
2796
|
+
fail(`image编译报错${err}`);
|
|
2797
|
+
});
|
|
2606
2798
|
}
|
|
2607
2799
|
});
|
|
2608
2800
|
break;
|
|
@@ -2610,12 +2802,14 @@ var compile = function (tmsConfig, {
|
|
|
2610
2802
|
case 'other':
|
|
2611
2803
|
compileTasksMap.set(globValue, {
|
|
2612
2804
|
module,
|
|
2613
|
-
taskFn: () => {
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
const srcPipe = src$1(
|
|
2805
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2806
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2807
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2808
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2809
|
+
});
|
|
2810
|
+
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
2811
|
+
fail(`编译报错${err}`);
|
|
2617
2812
|
});
|
|
2618
|
-
return srcPipe.pipe(dest(destPath));
|
|
2619
2813
|
}
|
|
2620
2814
|
});
|
|
2621
2815
|
break;
|
|
@@ -2624,39 +2818,254 @@ var compile = function (tmsConfig, {
|
|
|
2624
2818
|
return compileTasksMap;
|
|
2625
2819
|
};
|
|
2626
2820
|
|
|
2627
|
-
|
|
2821
|
+
/* eslint-disable */
|
|
2822
|
+
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
2823
|
+
|
|
2824
|
+
const assign = require$$0__default$b;
|
|
2628
2825
|
const path$1 = require$$1__default$2;
|
|
2826
|
+
const PluginError = require$$2__default$1;
|
|
2827
|
+
const fancyLog = require$$3__default;
|
|
2828
|
+
const colors = require$$4__default;
|
|
2829
|
+
const chokidar = require$$5__default$1;
|
|
2830
|
+
const {
|
|
2831
|
+
Duplex
|
|
2832
|
+
} = require$$6__default;
|
|
2833
|
+
const vinyl = require$$7__default;
|
|
2834
|
+
const File = require$$8__default;
|
|
2835
|
+
const anymatch = require$$9__default;
|
|
2836
|
+
const pathIsAbsolute = require$$10__default;
|
|
2837
|
+
const globParent = require$$11__default;
|
|
2838
|
+
const slash = require$$12__default;
|
|
2839
|
+
|
|
2840
|
+
function normalizeGlobs(globs) {
|
|
2841
|
+
if (!globs) {
|
|
2842
|
+
throw new PluginError('gulp-watch', 'glob argument required');
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
if (typeof globs === 'string') {
|
|
2846
|
+
globs = [globs];
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
if (!Array.isArray(globs)) {
|
|
2850
|
+
throw new PluginError('gulp-watch', `glob should be String or Array, not ${typeof globs}`);
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
return globs;
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2856
|
+
function watch$1(globs, opts, cb) {
|
|
2857
|
+
globs = normalizeGlobs(globs);
|
|
2858
|
+
|
|
2859
|
+
if (typeof opts === 'function') {
|
|
2860
|
+
cb = opts;
|
|
2861
|
+
opts = {};
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
opts = assign({}, watch$1._defaultOptions, opts);
|
|
2865
|
+
|
|
2866
|
+
cb = cb || function () {};
|
|
2867
|
+
|
|
2868
|
+
function resolveFilepath(filepath) {
|
|
2869
|
+
if (pathIsAbsolute(filepath)) {
|
|
2870
|
+
return path$1.normalize(filepath);
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2873
|
+
return path$1.resolve(opts.cwd || process.cwd(), filepath);
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
function resolveGlob(glob) {
|
|
2877
|
+
let mod = '';
|
|
2878
|
+
|
|
2879
|
+
if (glob[0] === '!') {
|
|
2880
|
+
mod = glob[0];
|
|
2881
|
+
glob = glob.slice(1);
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
return mod + slash(resolveFilepath(glob));
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
globs = globs.map(resolveGlob);
|
|
2888
|
+
const baseForced = Boolean(opts.base);
|
|
2889
|
+
const outputStream = new Duplex({
|
|
2890
|
+
objectMode: true,
|
|
2891
|
+
allowHalfOpen: true
|
|
2892
|
+
});
|
|
2893
|
+
|
|
2894
|
+
outputStream._write = function _write(file, enc, done) {
|
|
2895
|
+
cb(file);
|
|
2896
|
+
this.push(file);
|
|
2897
|
+
done();
|
|
2898
|
+
};
|
|
2899
|
+
|
|
2900
|
+
outputStream._read = function _read() {};
|
|
2901
|
+
|
|
2902
|
+
const watcher = chokidar.watch(globs, opts);
|
|
2903
|
+
opts.events.forEach(ev => {
|
|
2904
|
+
watcher.on(ev, processEvent.bind(undefined, ev));
|
|
2905
|
+
});
|
|
2906
|
+
['add', 'change', 'unlink', 'addDir', 'unlinkDir', 'error', 'ready', 'raw'].forEach(ev => {
|
|
2907
|
+
watcher.on(ev, outputStream.emit.bind(outputStream, ev));
|
|
2908
|
+
});
|
|
2909
|
+
|
|
2910
|
+
outputStream.add = function add(newGlobs) {
|
|
2911
|
+
newGlobs = normalizeGlobs(newGlobs).map(resolveGlob);
|
|
2912
|
+
watcher.add(newGlobs);
|
|
2913
|
+
globs.push.apply(globs, newGlobs);
|
|
2914
|
+
};
|
|
2915
|
+
|
|
2916
|
+
outputStream.unwatch = watcher.unwatch.bind(watcher);
|
|
2917
|
+
|
|
2918
|
+
outputStream.close = function () {
|
|
2919
|
+
watcher.close();
|
|
2920
|
+
this.emit('end');
|
|
2921
|
+
};
|
|
2922
|
+
|
|
2923
|
+
function processEvent(event, filepath) {
|
|
2924
|
+
filepath = resolveFilepath(filepath);
|
|
2925
|
+
const fileOpts = assign({}, opts);
|
|
2926
|
+
let glob;
|
|
2927
|
+
let currentFilepath = filepath;
|
|
2928
|
+
|
|
2929
|
+
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$1.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
2930
|
+
|
|
2931
|
+
|
|
2932
|
+
if (!glob) {
|
|
2933
|
+
console.error('[gulp-watch]没有匹配到glob');
|
|
2934
|
+
return;
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
if (!baseForced) {
|
|
2938
|
+
fileOpts.base = path$1.normalize(globParent(glob));
|
|
2939
|
+
} // Do not stat deleted files
|
|
2940
|
+
|
|
2941
|
+
|
|
2942
|
+
if (event === 'unlink' || event === 'unlinkDir' || event === 'addDir') {
|
|
2943
|
+
fileOpts.path = filepath;
|
|
2944
|
+
write(event, null, new File(fileOpts));
|
|
2945
|
+
return;
|
|
2946
|
+
} // Workaround for early read
|
|
2947
|
+
|
|
2948
|
+
|
|
2949
|
+
setTimeout(() => {
|
|
2950
|
+
vinyl.read(filepath, fileOpts).then(file => {
|
|
2951
|
+
write(event, null, file);
|
|
2952
|
+
});
|
|
2953
|
+
}, opts.readDelay);
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
function write(event, err, file) {
|
|
2957
|
+
if (err) {
|
|
2958
|
+
outputStream.emit('error', err);
|
|
2959
|
+
return;
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
if (opts.verbose) {
|
|
2963
|
+
log(event, file);
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
file.event = event;
|
|
2967
|
+
outputStream.push(file);
|
|
2968
|
+
cb(file);
|
|
2969
|
+
}
|
|
2970
|
+
|
|
2971
|
+
function log(event, file) {
|
|
2972
|
+
event = event[event.length - 1] === 'e' ? `${event}d` : `${event}ed`;
|
|
2973
|
+
const msg = [colors.magenta(file.relative), 'was', event];
|
|
2974
|
+
|
|
2975
|
+
if (opts.name) {
|
|
2976
|
+
msg.unshift(`${colors.cyan(opts.name)} saw`);
|
|
2977
|
+
}
|
|
2978
|
+
|
|
2979
|
+
fancyLog.info.apply(null, msg);
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
return outputStream;
|
|
2983
|
+
} // This is not part of the public API as that would lead to global state (singleton) pollution,
|
|
2984
|
+
// and allow unexpected interference between unrelated modules that make use of gulp-watch.
|
|
2985
|
+
// This can be useful for unit tests and root application configuration, though.
|
|
2986
|
+
// Avoid modifying gulp-watch's default options inside a library/reusable package, please.
|
|
2987
|
+
|
|
2988
|
+
|
|
2989
|
+
watch$1._defaultOptions = {
|
|
2990
|
+
events: ['add', 'change', 'unlink'],
|
|
2991
|
+
ignoreInitial: true,
|
|
2992
|
+
readDelay: 10
|
|
2993
|
+
};
|
|
2994
|
+
var gulpWatch = watch$1;
|
|
2995
|
+
|
|
2996
|
+
const watch = gulpWatch;
|
|
2997
|
+
const path = require$$1__default$2;
|
|
2629
2998
|
const shellJs = require$$0__default$3;
|
|
2630
2999
|
const {
|
|
2631
|
-
info: info$3
|
|
3000
|
+
info: info$3,
|
|
3001
|
+
warn
|
|
2632
3002
|
} = log$1;
|
|
2633
3003
|
const {
|
|
2634
|
-
resolve: resolve$
|
|
3004
|
+
resolve: resolve$2
|
|
2635
3005
|
} = widgets;
|
|
2636
3006
|
const {
|
|
2637
3007
|
global: global$2
|
|
2638
3008
|
} = global_1;
|
|
3009
|
+
const {
|
|
3010
|
+
findAllFilesOfDir
|
|
3011
|
+
} = io$3;
|
|
3012
|
+
const TIP_MAP = {
|
|
3013
|
+
'package.json': '若依赖有变动,请重新执行tmskit run dev',
|
|
3014
|
+
'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效'
|
|
3015
|
+
};
|
|
3016
|
+
|
|
3017
|
+
const logTip = (fileName, tipMap) => {
|
|
3018
|
+
// eslint-disable-next-line
|
|
3019
|
+
for (const item in tipMap) {
|
|
3020
|
+
if (fileName.indexOf(item) > -1) {
|
|
3021
|
+
warn(`${fileName}有更新, ${tipMap[item]}`);
|
|
3022
|
+
return;
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
info$3(`${fileName}有更新`);
|
|
3027
|
+
};
|
|
2639
3028
|
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
3029
|
+
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
3030
|
+
const sourceFileRelativeModule = path.relative(resolve$2(module.from), sourceFile);
|
|
3031
|
+
const targetFile = resolve$2(outputDir, module.to, sourceFileRelativeModule);
|
|
3032
|
+
return targetFile;
|
|
3033
|
+
};
|
|
3034
|
+
|
|
3035
|
+
var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
3036
|
+
watch(globValue, { // readDelay: 100,
|
|
2643
3037
|
...watchOptions
|
|
2644
3038
|
}, vinyl => {
|
|
2645
|
-
const
|
|
2646
|
-
const
|
|
2647
|
-
const
|
|
3039
|
+
const sourceFile = vinyl.history[0];
|
|
3040
|
+
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
3041
|
+
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
3042
|
+
const tmsConfig = global$2.getData('tmsConfig');
|
|
3043
|
+
|
|
3044
|
+
if (vinyl.event === 'addDir') {
|
|
3045
|
+
info$3(`更新${sourceFileName}目录`);
|
|
3046
|
+
const files = findAllFilesOfDir(sourceFile);
|
|
3047
|
+
|
|
3048
|
+
for (const file of files) {
|
|
3049
|
+
const fileDirArr = file.replace(/\\/g, '/').split('/');
|
|
3050
|
+
const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
|
|
3051
|
+
const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
|
|
3052
|
+
logTip(fileName, TIP_MAP);
|
|
3053
|
+
callback([file], path.dirname(targetFile));
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
return;
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
2648
3060
|
|
|
2649
3061
|
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);
|
|
3062
|
+
info$3(`删除${sourceFileName}`);
|
|
3063
|
+
shellJs.rm('-rf', targetFile);
|
|
2655
3064
|
return;
|
|
2656
3065
|
}
|
|
2657
3066
|
|
|
2658
|
-
|
|
2659
|
-
return callback(
|
|
3067
|
+
logTip(sourceFileName, TIP_MAP);
|
|
3068
|
+
return callback([sourceFile], path.dirname(targetFile));
|
|
2660
3069
|
});
|
|
2661
3070
|
};
|
|
2662
3071
|
|
|
@@ -2683,7 +3092,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2683
3092
|
const {
|
|
2684
3093
|
info
|
|
2685
3094
|
} = log$1;
|
|
2686
|
-
const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
|
|
3095
|
+
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
2687
3096
|
|
|
2688
3097
|
function excludeGlob(glob) {
|
|
2689
3098
|
const otherArr = new Set();
|
|
@@ -2713,16 +3122,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2713
3122
|
return newPath;
|
|
2714
3123
|
}
|
|
2715
3124
|
|
|
2716
|
-
module.exports = async (tmsConfig, newModules,
|
|
3125
|
+
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
2717
3126
|
const compileTasksMap = new Map(); // 监听app.json
|
|
2718
3127
|
|
|
2719
|
-
if (
|
|
3128
|
+
if (isDev) {
|
|
2720
3129
|
watch([resolve('app.json')], {
|
|
2721
3130
|
ignoreInitial: false,
|
|
2722
3131
|
events: watchEvents
|
|
2723
|
-
}, () => buildOutputAppJson(tmsConfig, newModules,
|
|
3132
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3133
|
+
from: resolve(),
|
|
3134
|
+
to: resolve(tmsConfig.outputDir)
|
|
3135
|
+
});
|
|
2724
3136
|
} else {
|
|
2725
|
-
buildOutputAppJson(tmsConfig, newModules,
|
|
3137
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
2726
3138
|
} // 监听根目录的文件
|
|
2727
3139
|
|
|
2728
3140
|
|
|
@@ -2733,14 +3145,14 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2733
3145
|
|
|
2734
3146
|
},
|
|
2735
3147
|
module: {
|
|
2736
|
-
from:
|
|
2737
|
-
to:
|
|
3148
|
+
from: resolve(),
|
|
3149
|
+
to: resolve(tmsConfig.outputDir)
|
|
2738
3150
|
},
|
|
2739
3151
|
destPath: resolve(tmsConfig.outputDir),
|
|
2740
3152
|
srcOption: {
|
|
2741
3153
|
allowEmpty: true
|
|
2742
3154
|
},
|
|
2743
|
-
|
|
3155
|
+
isDev
|
|
2744
3156
|
})); // 监听模块的文件
|
|
2745
3157
|
|
|
2746
3158
|
for (let module of newModules) {
|
|
@@ -2750,16 +3162,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2750
3162
|
},
|
|
2751
3163
|
...module
|
|
2752
3164
|
};
|
|
3165
|
+
const modulePath = adaptPath(module.path);
|
|
2753
3166
|
|
|
2754
|
-
if (
|
|
3167
|
+
if (isDev) {
|
|
2755
3168
|
// 监听模块配置文件
|
|
2756
|
-
watch([`${
|
|
3169
|
+
watch([`${modulePath}/**/module.config.json`], {
|
|
2757
3170
|
events: watchEvents
|
|
2758
|
-
}, () => buildOutputAppJson(tmsConfig, newModules,
|
|
3171
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3172
|
+
from: modulePath,
|
|
3173
|
+
to: modulePath
|
|
3174
|
+
});
|
|
2759
3175
|
}
|
|
2760
3176
|
|
|
2761
3177
|
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
2762
|
-
const modulePath = adaptPath(module.path);
|
|
2763
3178
|
const glob = {
|
|
2764
3179
|
js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
2765
3180
|
json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
|
|
@@ -2779,7 +3194,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2779
3194
|
srcOption: {
|
|
2780
3195
|
allowEmpty: true
|
|
2781
3196
|
},
|
|
2782
|
-
|
|
3197
|
+
isDev
|
|
2783
3198
|
}));
|
|
2784
3199
|
} // 静态资源目录-拷贝
|
|
2785
3200
|
|
|
@@ -2815,7 +3230,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2815
3230
|
srcOption: {
|
|
2816
3231
|
allowEmpty: true
|
|
2817
3232
|
},
|
|
2818
|
-
|
|
3233
|
+
isDev
|
|
2819
3234
|
}));
|
|
2820
3235
|
}
|
|
2821
3236
|
}
|
|
@@ -2824,8 +3239,17 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2824
3239
|
let eTime;
|
|
2825
3240
|
const spinner = ora();
|
|
2826
3241
|
|
|
2827
|
-
function
|
|
2828
|
-
|
|
3242
|
+
function start(cb) {
|
|
3243
|
+
info('启动编译...');
|
|
3244
|
+
spinner.start();
|
|
3245
|
+
sTime = new Date().getTime();
|
|
3246
|
+
cb();
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
async function end(cb) {
|
|
3250
|
+
var _tmsConfig$hooks;
|
|
3251
|
+
|
|
3252
|
+
if (isDev) {
|
|
2829
3253
|
compileTasksMap.forEach(({
|
|
2830
3254
|
taskFn,
|
|
2831
3255
|
module
|
|
@@ -2838,15 +3262,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2838
3262
|
}
|
|
2839
3263
|
|
|
2840
3264
|
eTime = new Date().getTime() - sTime;
|
|
2841
|
-
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即刻预览。`);
|
|
2842
|
-
spinner.stop();
|
|
2843
|
-
cb();
|
|
2844
|
-
}
|
|
2845
3265
|
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
3266
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
|
|
3267
|
+
var _tmsConfig$hooks2;
|
|
3268
|
+
|
|
3269
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3270
|
+
isDev,
|
|
3271
|
+
tmsConfig,
|
|
3272
|
+
modules: newModules
|
|
3273
|
+
}));
|
|
3274
|
+
}
|
|
3275
|
+
|
|
3276
|
+
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
|
|
3277
|
+
spinner.stop();
|
|
2850
3278
|
cb();
|
|
2851
3279
|
}
|
|
2852
3280
|
|
|
@@ -2860,185 +3288,12 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2860
3288
|
};
|
|
2861
3289
|
})(dev$3);
|
|
2862
3290
|
|
|
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
3291
|
const shelljs$1 = require$$0__default$3;
|
|
3034
3292
|
const compileDev = dev$3.exports;
|
|
3035
3293
|
const {
|
|
3036
3294
|
resolve: resolve$1
|
|
3037
3295
|
} = widgets;
|
|
3038
3296
|
const init$4 = init_1;
|
|
3039
|
-
const {
|
|
3040
|
-
isInit
|
|
3041
|
-
} = isInIt;
|
|
3042
3297
|
const {
|
|
3043
3298
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
3044
3299
|
} = tmsMpconfig;
|
|
@@ -3047,7 +3302,10 @@ const {
|
|
|
3047
3302
|
} = log$1;
|
|
3048
3303
|
const {
|
|
3049
3304
|
global: global$1
|
|
3050
|
-
} = global_1;
|
|
3305
|
+
} = global_1;
|
|
3306
|
+
const {
|
|
3307
|
+
CACHE_DIR
|
|
3308
|
+
} = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
3051
3309
|
|
|
3052
3310
|
function delOtherModule(tmsConfig, targetModules) {
|
|
3053
3311
|
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
|
|
@@ -3064,16 +3322,32 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
3064
3322
|
}
|
|
3065
3323
|
|
|
3066
3324
|
async function dev$2(tmsConfig, targetModules, env) {
|
|
3325
|
+
var _tmsConfig$hooks;
|
|
3326
|
+
|
|
3067
3327
|
let newModules = targetModules;
|
|
3068
|
-
const
|
|
3328
|
+
const {
|
|
3329
|
+
noCache
|
|
3330
|
+
} = global$1.getData('cmd');
|
|
3331
|
+
|
|
3332
|
+
if (noCache) {
|
|
3333
|
+
shelljs$1.rm('-rf', resolve$1(tmsConfig.outputDir));
|
|
3334
|
+
shelljs$1.rm('-rf', CACHE_DIR);
|
|
3335
|
+
} // 初始化操作
|
|
3069
3336
|
|
|
3070
|
-
if (isLatest || isInit(tmsConfig, targetModules, resolve$1('dist'))) {
|
|
3071
|
-
// init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
|
|
3072
|
-
const initData = await init$4(tmsConfig, newModules);
|
|
3073
|
-
newModules = initData.targetModules;
|
|
3074
|
-
}
|
|
3075
3337
|
|
|
3338
|
+
const initData = await init$4(tmsConfig, newModules);
|
|
3339
|
+
newModules = initData.targetModules;
|
|
3076
3340
|
info$2('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
3341
|
+
|
|
3342
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3343
|
+
var _tmsConfig$hooks2;
|
|
3344
|
+
|
|
3345
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3346
|
+
isDev: true,
|
|
3347
|
+
tmsConfig,
|
|
3348
|
+
modules: newModules
|
|
3349
|
+
}));
|
|
3350
|
+
}
|
|
3077
3351
|
delOtherModule(tmsConfig, newModules);
|
|
3078
3352
|
compileDev(tmsConfig, newModules, env);
|
|
3079
3353
|
}
|
|
@@ -3228,7 +3502,7 @@ var entry = [{
|
|
|
3228
3502
|
}, {
|
|
3229
3503
|
command: 'dev',
|
|
3230
3504
|
description: 'dev 打包编译',
|
|
3231
|
-
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-
|
|
3505
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-noCache, --noCache', '不使用缓存功能']],
|
|
3232
3506
|
action: cmd => {
|
|
3233
3507
|
run_1('dev', cmd);
|
|
3234
3508
|
}
|
|
@@ -3256,13 +3530,14 @@ var entry = [{
|
|
|
3256
3530
|
|
|
3257
3531
|
var require$$7 = {
|
|
3258
3532
|
name: "@tmsfe/tmskit",
|
|
3259
|
-
version: "0.0.
|
|
3533
|
+
version: "0.0.16",
|
|
3260
3534
|
description: "tmskit",
|
|
3261
3535
|
main: "dist/index.cjs",
|
|
3262
3536
|
bin: {
|
|
3263
3537
|
tmskit: "main.js"
|
|
3264
3538
|
},
|
|
3265
3539
|
files: [
|
|
3540
|
+
"build",
|
|
3266
3541
|
"src",
|
|
3267
3542
|
"dist",
|
|
3268
3543
|
"main.js",
|
|
@@ -3294,8 +3569,18 @@ var require$$7 = {
|
|
|
3294
3569
|
"rollup-plugin-typescript2": "0.27.0"
|
|
3295
3570
|
},
|
|
3296
3571
|
dependencies: {
|
|
3572
|
+
"ansi-colors": "1.1.0",
|
|
3573
|
+
anymatch: "^1.3.0",
|
|
3574
|
+
"fancy-log": "1.3.2",
|
|
3575
|
+
"glob-parent": "^3.0.1",
|
|
3576
|
+
"path-is-absolute": "^1.0.1",
|
|
3577
|
+
"readable-stream": "^2.2.2",
|
|
3578
|
+
slash: "^1.0.0",
|
|
3579
|
+
vinyl: "^2.1.0",
|
|
3580
|
+
"vinyl-file": "^2.0.0",
|
|
3297
3581
|
async: "^3.2.2",
|
|
3298
3582
|
chalk: "^4.1.0",
|
|
3583
|
+
chokidar: "^3.5.3",
|
|
3299
3584
|
commander: "^8.3.0",
|
|
3300
3585
|
"copy-webpack-plugin": "^9.1.0",
|
|
3301
3586
|
ejs: "^3.1.5",
|
|
@@ -3329,7 +3614,7 @@ var require$$7 = {
|
|
|
3329
3614
|
}
|
|
3330
3615
|
};
|
|
3331
3616
|
|
|
3332
|
-
const semver = require$$1__default$
|
|
3617
|
+
const semver = require$$1__default$7;
|
|
3333
3618
|
const packageJson = require$$7;
|
|
3334
3619
|
const chalk$1 = require$$0__default;
|
|
3335
3620
|
const {
|