@tmsfe/tmskit 0.0.14 → 0.0.15-beta.3
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 +10 -1
- package/dist/index.cjs.js +466 -440
- package/package.json +4 -2
- package/src/compile/compile.js +56 -35
- package/src/compile/dev.js +25 -21
- package/src/compile/watch.js +31 -14
- package/src/core/buildAppJson.js +3 -0
- package/src/entry.js +1 -1
- package/src/scripts/run/dev/index.js +12 -9
- package/src/scripts/run/init/index.js +26 -2
- package/src/scripts/run/install/index.js +2 -9
- package/src/utils/log.js +4 -4
- package/src/utils/widgets.js +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -5,25 +5,25 @@ var require$$1 = require('moment');
|
|
|
5
5
|
var require$$0$1 = require('commander');
|
|
6
6
|
var require$$1$1 = require('leven');
|
|
7
7
|
var require$$2 = require('ora');
|
|
8
|
-
var require$$
|
|
8
|
+
var require$$3 = require('path');
|
|
9
9
|
var require$$0$2 = require('fs');
|
|
10
10
|
var require$$0$3 = require('shelljs');
|
|
11
11
|
var require$$0$4 = require('async');
|
|
12
|
-
var require$$1$
|
|
13
|
-
var require$$1$
|
|
12
|
+
var require$$1$2 = require('ejs');
|
|
13
|
+
var require$$1$3 = require('inquirer');
|
|
14
14
|
var require$$0$5 = require('metalsmith');
|
|
15
15
|
var require$$0$6 = require('lodash');
|
|
16
|
-
var require$$1$
|
|
16
|
+
var require$$1$4 = require('crypto');
|
|
17
17
|
var require$$0$7 = require('miniprogram-ci');
|
|
18
18
|
var require$$5 = require('glob-ignore');
|
|
19
|
-
var require$$1$
|
|
19
|
+
var require$$1$5 = require('fs-extra');
|
|
20
|
+
var require$$1$6 = require('semver');
|
|
20
21
|
var require$$0$8 = require('strip-comments');
|
|
21
22
|
var require$$0$9 = require('through2');
|
|
22
23
|
var require$$1$7 = require('precinct');
|
|
23
24
|
var require$$1$8 = require('htmlparser2');
|
|
24
25
|
var require$$0$a = require('gulp');
|
|
25
26
|
var require$$0$b = require('gulp-watch');
|
|
26
|
-
var require$$1$9 = require('semver');
|
|
27
27
|
|
|
28
28
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
29
29
|
|
|
@@ -32,17 +32,18 @@ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
|
32
32
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
33
33
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
34
34
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
35
|
-
var require$$
|
|
35
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
36
36
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
37
37
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
38
38
|
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
39
|
+
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
39
40
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
40
|
-
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
41
41
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
42
42
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
43
|
-
var require$$1__default$
|
|
43
|
+
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
44
44
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
45
45
|
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
46
|
+
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
46
47
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
47
48
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
48
49
|
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
@@ -50,7 +51,6 @@ var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
|
50
51
|
var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
|
|
51
52
|
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
52
53
|
var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
|
|
53
|
-
var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
|
|
54
54
|
|
|
55
55
|
function getAugmentedNamespace(n) {
|
|
56
56
|
if (n.__esModule) return n;
|
|
@@ -83,12 +83,12 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
83
83
|
* @returns {undefined} 无
|
|
84
84
|
*/
|
|
85
85
|
|
|
86
|
-
const fail$
|
|
86
|
+
const fail$8 = (message = '') => {
|
|
87
87
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
88
88
|
|
|
89
89
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
90
90
|
|
|
91
|
-
console.log(
|
|
91
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
94
94
|
* 打印绿底黑字格式的文字
|
|
@@ -102,7 +102,7 @@ const succeed$1 = (message = '') => {
|
|
|
102
102
|
|
|
103
103
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
104
104
|
|
|
105
|
-
console.log(
|
|
105
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
106
106
|
};
|
|
107
107
|
/**
|
|
108
108
|
* 打印warn提示
|
|
@@ -111,24 +111,24 @@ const succeed$1 = (message = '') => {
|
|
|
111
111
|
*/
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
const warn = message => {
|
|
115
|
-
console.log(
|
|
114
|
+
const warn$1 = message => {
|
|
115
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
const info$9 = (...args) => console.log(
|
|
118
|
+
const info$9 = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
119
119
|
|
|
120
120
|
var log$1 = {
|
|
121
|
-
fail: fail$
|
|
121
|
+
fail: fail$8,
|
|
122
122
|
succeed: succeed$1,
|
|
123
|
-
warn,
|
|
123
|
+
warn: warn$1,
|
|
124
124
|
info: info$9
|
|
125
125
|
};
|
|
126
126
|
|
|
127
127
|
const program$1 = require$$0__default$1;
|
|
128
128
|
const leven = require$$1__default$1;
|
|
129
129
|
const ora = require$$2__default;
|
|
130
|
-
const path$b = require$$
|
|
131
|
-
const fs$
|
|
130
|
+
const path$b = require$$3__default;
|
|
131
|
+
const fs$c = require$$0__default$2;
|
|
132
132
|
const shelljs$6 = require$$0__default$3;
|
|
133
133
|
const {
|
|
134
134
|
info: info$8
|
|
@@ -141,7 +141,7 @@ const shelljsOptions = {
|
|
|
141
141
|
|
|
142
142
|
const cwd = process.cwd();
|
|
143
143
|
|
|
144
|
-
function resolve$
|
|
144
|
+
function resolve$e(...args) {
|
|
145
145
|
return path$b.resolve(cwd, ...args);
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
@@ -198,7 +198,7 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
198
198
|
const cwd = process.cwd();
|
|
199
199
|
return new Promise((resolve, reject) => {
|
|
200
200
|
// 如果目标目录不存在
|
|
201
|
-
if (fs$
|
|
201
|
+
if (fs$c.existsSync(dest)) {
|
|
202
202
|
shelljs$6.rm('-rf', path$b.join(dest));
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -282,10 +282,11 @@ const cost = start => Date.now() - start;
|
|
|
282
282
|
function createTask$3(task, startText, endText) {
|
|
283
283
|
return async (...args) => {
|
|
284
284
|
const start = Date.now();
|
|
285
|
-
const spinner = ora(
|
|
285
|
+
const spinner = ora();
|
|
286
|
+
info$8(startText);
|
|
286
287
|
spinner.start();
|
|
287
288
|
const result = await task(...args);
|
|
288
|
-
endText && spinner.succeed(`${endText},
|
|
289
|
+
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
289
290
|
spinner.stop();
|
|
290
291
|
return result;
|
|
291
292
|
};
|
|
@@ -315,7 +316,7 @@ const relativeCwdPath$1 = function (file) {
|
|
|
315
316
|
};
|
|
316
317
|
|
|
317
318
|
var widgets = {
|
|
318
|
-
resolve: resolve$
|
|
319
|
+
resolve: resolve$e,
|
|
319
320
|
isObject: isObject$2,
|
|
320
321
|
isArray: isArray$1,
|
|
321
322
|
createTask: createTask$3,
|
|
@@ -335,11 +336,11 @@ const os = require('os'); // 用户目录
|
|
|
335
336
|
|
|
336
337
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
337
338
|
|
|
338
|
-
const CACHE_DIR$
|
|
339
|
+
const CACHE_DIR$2 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
339
340
|
|
|
340
|
-
const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$
|
|
341
|
+
const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
341
342
|
|
|
342
|
-
const MODULE_CODE_DIR$
|
|
343
|
+
const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
|
|
343
344
|
|
|
344
345
|
const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
345
346
|
|
|
@@ -369,7 +370,7 @@ const MODULE_CONFIG_INVALID_KEY$1 = ['entranceDeclare', 'entryPagePath'];
|
|
|
369
370
|
var constant = /*#__PURE__*/Object.freeze({
|
|
370
371
|
__proto__: null,
|
|
371
372
|
HOME_DIR: HOME_DIR,
|
|
372
|
-
CACHE_DIR: CACHE_DIR$
|
|
373
|
+
CACHE_DIR: CACHE_DIR$2,
|
|
373
374
|
TEMPLATE_DIR: TEMPLATE_DIR$1,
|
|
374
375
|
TEMPLATE_PATH: TEMPLATE_PATH$1,
|
|
375
376
|
TMS_NAME: TMS_NAME$1,
|
|
@@ -379,7 +380,7 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
379
380
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
380
381
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
381
382
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
382
|
-
MODULE_CODE_DIR: MODULE_CODE_DIR$
|
|
383
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
383
384
|
ENV: ENV,
|
|
384
385
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
385
386
|
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1,
|
|
@@ -388,8 +389,8 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
388
389
|
|
|
389
390
|
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
390
391
|
|
|
391
|
-
const fs$
|
|
392
|
-
const path$9 = require$$
|
|
392
|
+
const fs$b = require$$0__default$2;
|
|
393
|
+
const path$9 = require$$3__default;
|
|
393
394
|
const {
|
|
394
395
|
info: info$7
|
|
395
396
|
} = log$1;
|
|
@@ -402,12 +403,12 @@ const {
|
|
|
402
403
|
* @returns
|
|
403
404
|
*/
|
|
404
405
|
|
|
405
|
-
const isDirEmpty = dirname => fs$
|
|
406
|
+
const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
406
407
|
|
|
407
408
|
|
|
408
409
|
const isFile = pathName => {
|
|
409
410
|
try {
|
|
410
|
-
const stat = fs$
|
|
411
|
+
const stat = fs$b.lstatSync(pathName);
|
|
411
412
|
return stat.isFile();
|
|
412
413
|
} catch {
|
|
413
414
|
return false;
|
|
@@ -420,8 +421,8 @@ const isFile = pathName => {
|
|
|
420
421
|
|
|
421
422
|
|
|
422
423
|
const ensureDirExist = dirname => {
|
|
423
|
-
if (!fs$
|
|
424
|
-
fs$
|
|
424
|
+
if (!fs$b.existsSync(dirname)) {
|
|
425
|
+
fs$b.mkdirSync(dirname, {
|
|
425
426
|
recursive: true
|
|
426
427
|
});
|
|
427
428
|
}
|
|
@@ -429,20 +430,20 @@ const ensureDirExist = dirname => {
|
|
|
429
430
|
|
|
430
431
|
|
|
431
432
|
const copyFile = function (src, dest) {
|
|
432
|
-
if (fs$
|
|
433
|
-
fs$
|
|
433
|
+
if (fs$b.existsSync(dest)) {
|
|
434
|
+
fs$b.unlinkSync(dest);
|
|
434
435
|
}
|
|
435
436
|
|
|
436
437
|
const dir = path$9.dirname(dest);
|
|
437
438
|
ensureDirExist(dir);
|
|
438
|
-
fs$
|
|
439
|
+
fs$b.copyFileSync(src, dest);
|
|
439
440
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
440
441
|
|
|
441
442
|
|
|
442
443
|
function diffContentCopyFile$3(originFile, destFile) {
|
|
443
|
-
if (fs$
|
|
444
|
-
const depDestContent = fs$
|
|
445
|
-
const depOriginContent = fs$
|
|
444
|
+
if (fs$b.existsSync(destFile)) {
|
|
445
|
+
const depDestContent = fs$b.readFileSync(destFile, 'utf8');
|
|
446
|
+
const depOriginContent = fs$b.readFileSync(originFile, 'utf8');
|
|
446
447
|
|
|
447
448
|
if (depDestContent !== depOriginContent) {
|
|
448
449
|
info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
@@ -460,7 +461,7 @@ function ext$3(filePath, extensions) {
|
|
|
460
461
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
461
462
|
|
|
462
463
|
try {
|
|
463
|
-
const stat = fs$
|
|
464
|
+
const stat = fs$b.lstatSync(newFilePath);
|
|
464
465
|
|
|
465
466
|
if (stat.isDirectory()) {
|
|
466
467
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -471,7 +472,7 @@ function ext$3(filePath, extensions) {
|
|
|
471
472
|
for (const ext of extensions) {
|
|
472
473
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
473
474
|
|
|
474
|
-
if (fs$
|
|
475
|
+
if (fs$b.existsSync(file)) {
|
|
475
476
|
return {
|
|
476
477
|
ext,
|
|
477
478
|
extPath: extPath + ext,
|
|
@@ -489,7 +490,7 @@ function ext$3(filePath, extensions) {
|
|
|
489
490
|
|
|
490
491
|
|
|
491
492
|
const fileInDir$3 = (dir, file) => {
|
|
492
|
-
if (!fs$
|
|
493
|
+
if (!fs$b.existsSync(dir) || !fs$b.existsSync(file)) {
|
|
493
494
|
return false;
|
|
494
495
|
}
|
|
495
496
|
|
|
@@ -513,7 +514,7 @@ var io$2 = {
|
|
|
513
514
|
};
|
|
514
515
|
|
|
515
516
|
const async = require$$0__default$4;
|
|
516
|
-
const ejs = require$$1__default$
|
|
517
|
+
const ejs = require$$1__default$2;
|
|
517
518
|
|
|
518
519
|
const render$1 = (files, metalsmith, next) => {
|
|
519
520
|
const keys = Object.keys(files);
|
|
@@ -532,10 +533,10 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
532
533
|
|
|
533
534
|
var render_1 = render$1;
|
|
534
535
|
|
|
535
|
-
const fs$
|
|
536
|
-
const inquirer = require$$1__default$
|
|
536
|
+
const fs$a = require$$0__default$2;
|
|
537
|
+
const inquirer = require$$1__default$3;
|
|
537
538
|
const {
|
|
538
|
-
resolve: resolve$
|
|
539
|
+
resolve: resolve$d
|
|
539
540
|
} = widgets;
|
|
540
541
|
const {
|
|
541
542
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
@@ -549,12 +550,12 @@ const {
|
|
|
549
550
|
const parseTemplateQuestions = dir => {
|
|
550
551
|
let prompts = [];
|
|
551
552
|
|
|
552
|
-
if (!fs$
|
|
553
|
+
if (!fs$a.existsSync(`${dir}/questions.json`)) {
|
|
553
554
|
return prompts;
|
|
554
555
|
}
|
|
555
556
|
|
|
556
557
|
try {
|
|
557
|
-
const json = JSON.parse(fs$
|
|
558
|
+
const json = JSON.parse(fs$a.readFileSync(`${dir}/questions.json`));
|
|
558
559
|
|
|
559
560
|
if (Array.isArray(json) && json.length > 0) {
|
|
560
561
|
json.forEach((item, index) => {
|
|
@@ -587,7 +588,7 @@ const isQuestionType = result => {
|
|
|
587
588
|
};
|
|
588
589
|
|
|
589
590
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
590
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
591
|
+
const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
591
592
|
const metadata = metalsmith.metadata();
|
|
592
593
|
const filteredPrompts = prompts.filter(prompt => {
|
|
593
594
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -629,8 +630,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
629
630
|
|
|
630
631
|
var generator_1 = generator$1;
|
|
631
632
|
|
|
632
|
-
const path$8 = require$$
|
|
633
|
-
const fs$
|
|
633
|
+
const path$8 = require$$3__default;
|
|
634
|
+
const fs$9 = require$$0__default$2;
|
|
634
635
|
const shelljs$5 = require$$0__default$3;
|
|
635
636
|
const {
|
|
636
637
|
TEMPLATE_DIR,
|
|
@@ -640,11 +641,11 @@ const {
|
|
|
640
641
|
const {
|
|
641
642
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
642
643
|
createTask: createTask$2,
|
|
643
|
-
resolve: resolve$
|
|
644
|
+
resolve: resolve$c
|
|
644
645
|
} = widgets;
|
|
645
646
|
const io$1 = io$2;
|
|
646
647
|
const {
|
|
647
|
-
fail: fail$
|
|
648
|
+
fail: fail$7,
|
|
648
649
|
succeed,
|
|
649
650
|
info: info$6
|
|
650
651
|
} = log$1;
|
|
@@ -657,9 +658,9 @@ const generator = generator_1;
|
|
|
657
658
|
|
|
658
659
|
async function createAppDir(targetDir) {
|
|
659
660
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
660
|
-
if (fs$
|
|
661
|
+
if (fs$9.existsSync(targetDir)) {
|
|
661
662
|
if (!(await io$1.isDirEmpty(targetDir))) {
|
|
662
|
-
fail$
|
|
663
|
+
fail$7('该目录名已经存在,换个项目名字吧~');
|
|
663
664
|
process.exit(1);
|
|
664
665
|
}
|
|
665
666
|
} else {
|
|
@@ -689,7 +690,7 @@ async function create(appName) {
|
|
|
689
690
|
}).then(() => {
|
|
690
691
|
shelljs$5.cd(appName);
|
|
691
692
|
|
|
692
|
-
const hooks = require(resolve$
|
|
693
|
+
const hooks = require(resolve$c(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
693
694
|
|
|
694
695
|
if (hooks.afterCreate) {
|
|
695
696
|
hooks.afterCreate.forEach(item => {
|
|
@@ -703,10 +704,10 @@ async function create(appName) {
|
|
|
703
704
|
});
|
|
704
705
|
}
|
|
705
706
|
|
|
706
|
-
shelljs$5.rm('-rf', resolve$
|
|
707
|
+
shelljs$5.rm('-rf', resolve$c(appName, TEMPLATE_TKIT_DIR));
|
|
707
708
|
succeed('项目创建完成.');
|
|
708
709
|
}).catch(err => {
|
|
709
|
-
fail$
|
|
710
|
+
fail$7(err.message);
|
|
710
711
|
info$6('详细的错误信息:', err);
|
|
711
712
|
});
|
|
712
713
|
}
|
|
@@ -736,32 +737,32 @@ var defaultTmsConfig$1 = {
|
|
|
736
737
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
737
738
|
*/
|
|
738
739
|
const loadash = require$$0__default$6;
|
|
739
|
-
const fs$
|
|
740
|
+
const fs$8 = require$$0__default$2;
|
|
740
741
|
const {
|
|
741
742
|
TMS_CONFIG_FILENAME,
|
|
742
743
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
743
744
|
TMS_PRIVATE_FILENAME
|
|
744
745
|
} = require$$4;
|
|
745
746
|
const {
|
|
746
|
-
resolve: resolve$
|
|
747
|
+
resolve: resolve$b,
|
|
747
748
|
isObject: isObject$1,
|
|
748
749
|
isArray
|
|
749
750
|
} = widgets;
|
|
750
751
|
const defaultTmsConfig = defaultTmsConfig$1;
|
|
751
752
|
const {
|
|
752
|
-
fail: fail$
|
|
753
|
+
fail: fail$6
|
|
753
754
|
} = log$1;
|
|
754
|
-
const path$7 = require$$
|
|
755
|
+
const path$7 = require$$3__default;
|
|
755
756
|
/**
|
|
756
757
|
* 读取tms.config.js
|
|
757
758
|
* @param env {string} 环境变量
|
|
758
759
|
*/
|
|
759
760
|
|
|
760
761
|
const readTmsConfig$1 = function (env) {
|
|
761
|
-
const tmsConfigPath = resolve$
|
|
762
|
+
const tmsConfigPath = resolve$b(TMS_CONFIG_FILENAME);
|
|
762
763
|
|
|
763
|
-
if (!fs$
|
|
764
|
-
fail$
|
|
764
|
+
if (!fs$8.existsSync(tmsConfigPath)) {
|
|
765
|
+
fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
765
766
|
process.exit(1);
|
|
766
767
|
}
|
|
767
768
|
|
|
@@ -808,9 +809,9 @@ const convertModules = modules => {
|
|
|
808
809
|
|
|
809
810
|
const readTmsPrivateCf$1 = function () {
|
|
810
811
|
let tmsPrivateCf = {};
|
|
811
|
-
const tmsPrivatePath = resolve$
|
|
812
|
+
const tmsPrivatePath = resolve$b(TMS_PRIVATE_FILENAME);
|
|
812
813
|
|
|
813
|
-
if (fs$
|
|
814
|
+
if (fs$8.existsSync(tmsPrivatePath)) {
|
|
814
815
|
tmsPrivateCf = require(tmsPrivatePath);
|
|
815
816
|
} // 处理modules字段
|
|
816
817
|
|
|
@@ -839,7 +840,7 @@ const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
|
|
|
839
840
|
});
|
|
840
841
|
|
|
841
842
|
if (targetModules.length === 0) {
|
|
842
|
-
fail$
|
|
843
|
+
fail$6(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
|
|
843
844
|
>name字段与module.config.json的name字段是否一致`);
|
|
844
845
|
isQuit && process.exit(1);
|
|
845
846
|
}
|
|
@@ -902,10 +903,10 @@ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
|
|
|
902
903
|
modules.forEach(({
|
|
903
904
|
path
|
|
904
905
|
}) => {
|
|
905
|
-
const moduleConfigPath = resolve$
|
|
906
|
+
const moduleConfigPath = resolve$b(path, moduleConfigFilename);
|
|
906
907
|
|
|
907
|
-
if (fs$
|
|
908
|
-
const content = fs$
|
|
908
|
+
if (fs$8.existsSync(moduleConfigPath)) {
|
|
909
|
+
const content = fs$8.readFileSync(moduleConfigPath, 'utf-8');
|
|
909
910
|
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
910
911
|
}
|
|
911
912
|
});
|
|
@@ -926,12 +927,12 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
926
927
|
path: relativePath,
|
|
927
928
|
name: moduleName
|
|
928
929
|
}, moduleIndex) => {
|
|
929
|
-
const moduleConfigPath = resolve$
|
|
930
|
+
const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
930
931
|
|
|
931
|
-
if (fs$
|
|
932
|
+
if (fs$8.existsSync(moduleConfigPath)) {
|
|
932
933
|
try {
|
|
933
934
|
let findModule = false;
|
|
934
|
-
let moduleConfigContent = fs$
|
|
935
|
+
let moduleConfigContent = fs$8.readFileSync(moduleConfigPath, 'utf-8');
|
|
935
936
|
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
936
937
|
const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
937
938
|
getValidModules$1(moduleContentArr).forEach(({
|
|
@@ -946,11 +947,11 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
946
947
|
});
|
|
947
948
|
|
|
948
949
|
if (!findModule) {
|
|
949
|
-
fail$
|
|
950
|
+
fail$6(`启动模块${moduleName}在${moduleConfigPath}没有找到或pages为空,请检查配置`);
|
|
950
951
|
process.exit(1);
|
|
951
952
|
}
|
|
952
953
|
} catch (e) {
|
|
953
|
-
fail$
|
|
954
|
+
fail$6(`${moduleConfigPath}配置错误: ${e}`);
|
|
954
955
|
newModules.push({ ...modules[moduleIndex]
|
|
955
956
|
});
|
|
956
957
|
}
|
|
@@ -1035,7 +1036,7 @@ var global_1 = {
|
|
|
1035
1036
|
};
|
|
1036
1037
|
|
|
1037
1038
|
const {
|
|
1038
|
-
fail: fail$
|
|
1039
|
+
fail: fail$5
|
|
1039
1040
|
} = log$1;
|
|
1040
1041
|
const {
|
|
1041
1042
|
global: global$5
|
|
@@ -1046,9 +1047,9 @@ function handleError$4(error) {
|
|
|
1046
1047
|
const isDev = global$5.getData('isDev');
|
|
1047
1048
|
|
|
1048
1049
|
if (isDev) {
|
|
1049
|
-
fail$
|
|
1050
|
+
fail$5(errMsg);
|
|
1050
1051
|
} else {
|
|
1051
|
-
fail$
|
|
1052
|
+
fail$5(errMsg);
|
|
1052
1053
|
process.exit(1);
|
|
1053
1054
|
}
|
|
1054
1055
|
}
|
|
@@ -1060,7 +1061,7 @@ var handleError_1 = {
|
|
|
1060
1061
|
/**
|
|
1061
1062
|
* 生成编译后的app.json
|
|
1062
1063
|
*/
|
|
1063
|
-
const fs$
|
|
1064
|
+
const fs$7 = require$$0__default$2;
|
|
1064
1065
|
const {
|
|
1065
1066
|
MODULE_CONFIG_FILENAME,
|
|
1066
1067
|
MODULE_CONFIG_INVALID_KEY
|
|
@@ -1070,10 +1071,10 @@ const {
|
|
|
1070
1071
|
getValidModules
|
|
1071
1072
|
} = tmsMpconfig;
|
|
1072
1073
|
const {
|
|
1073
|
-
fail: fail$
|
|
1074
|
+
fail: fail$4
|
|
1074
1075
|
} = log$1;
|
|
1075
1076
|
const {
|
|
1076
|
-
resolve: resolve$
|
|
1077
|
+
resolve: resolve$a,
|
|
1077
1078
|
isObject
|
|
1078
1079
|
} = widgets;
|
|
1079
1080
|
const {
|
|
@@ -1097,7 +1098,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1097
1098
|
|
|
1098
1099
|
foundMainPackages.forEach(subpackage => {
|
|
1099
1100
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
1100
|
-
fail$
|
|
1101
|
+
fail$4(`主包 ${subpackage} 不能没有 pages`);
|
|
1101
1102
|
process.exit(-1);
|
|
1102
1103
|
}
|
|
1103
1104
|
|
|
@@ -1123,12 +1124,12 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1123
1124
|
|
|
1124
1125
|
|
|
1125
1126
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
1126
|
-
if (!fs$
|
|
1127
|
-
fail$
|
|
1127
|
+
if (!fs$7.existsSync(sourceAppJsonPath)) {
|
|
1128
|
+
fail$4(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1128
1129
|
process.exit(1);
|
|
1129
1130
|
}
|
|
1130
1131
|
|
|
1131
|
-
const appJson = JSON.parse(fs$
|
|
1132
|
+
const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1132
1133
|
|
|
1133
1134
|
appJson.subpackages = [];
|
|
1134
1135
|
appJson.pages = []; // appJson.plugins = {};
|
|
@@ -1198,7 +1199,7 @@ const fixAppJson = appJson => {
|
|
|
1198
1199
|
});
|
|
1199
1200
|
|
|
1200
1201
|
if (invalidKeys.length) {
|
|
1201
|
-
fail$
|
|
1202
|
+
fail$4(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
1202
1203
|
} // eslint-disable-next-line
|
|
1203
1204
|
|
|
1204
1205
|
|
|
@@ -1215,7 +1216,7 @@ const fixAppJson = appJson => {
|
|
|
1215
1216
|
}).reduce((pre, cur) => pre + cur, '');
|
|
1216
1217
|
|
|
1217
1218
|
if (pluginsErrMsg) {
|
|
1218
|
-
fail$
|
|
1219
|
+
fail$4(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1219
1220
|
} // eslint-disable-next-line
|
|
1220
1221
|
|
|
1221
1222
|
|
|
@@ -1231,17 +1232,26 @@ const fixAppJson = appJson => {
|
|
|
1231
1232
|
|
|
1232
1233
|
function buildOutputAppJson$1(tmsConfig, modules) {
|
|
1233
1234
|
try {
|
|
1235
|
+
var _tmsConfig$hooks;
|
|
1236
|
+
|
|
1234
1237
|
// 获取当前 modules 下的所有子模块的配置内容
|
|
1235
1238
|
const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1236
1239
|
|
|
1237
|
-
const appJson = getAppJsonContent(resolve$
|
|
1240
|
+
const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
|
|
1238
1241
|
|
|
1239
1242
|
updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
|
|
1240
1243
|
|
|
1241
1244
|
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1242
1245
|
|
|
1243
1246
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1244
|
-
fs$
|
|
1247
|
+
fs$7.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1248
|
+
|
|
1249
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1250
|
+
var _tmsConfig$hooks2;
|
|
1251
|
+
|
|
1252
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson(appJson);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1245
1255
|
return appJson;
|
|
1246
1256
|
} catch (e) {
|
|
1247
1257
|
handleError$3(`生成app.json出现错误: ${e}`);
|
|
@@ -1256,17 +1266,17 @@ var buildAppJson = {
|
|
|
1256
1266
|
* 下载第三方代码
|
|
1257
1267
|
*/
|
|
1258
1268
|
const MetalSmith = require$$0__default$5;
|
|
1259
|
-
const crypto$1 = require$$1__default$
|
|
1269
|
+
const crypto$1 = require$$1__default$4;
|
|
1260
1270
|
const {
|
|
1261
1271
|
downloadRepoForGit,
|
|
1262
1272
|
pullRepoForGit,
|
|
1263
|
-
resolve: resolve$
|
|
1273
|
+
resolve: resolve$9
|
|
1264
1274
|
} = widgets;
|
|
1265
1275
|
const {
|
|
1266
|
-
fail: fail$
|
|
1276
|
+
fail: fail$3,
|
|
1267
1277
|
info: info$5
|
|
1268
1278
|
} = log$1;
|
|
1269
|
-
const fs$
|
|
1279
|
+
const fs$6 = require$$0__default$2;
|
|
1270
1280
|
const shelljs$4 = require$$0__default$3;
|
|
1271
1281
|
const {
|
|
1272
1282
|
handleError: handleError$2
|
|
@@ -1313,7 +1323,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1313
1323
|
return new Promise((resolve, reject) => {
|
|
1314
1324
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1315
1325
|
if (e) {
|
|
1316
|
-
fail$
|
|
1326
|
+
fail$3(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1317
1327
|
reject(e);
|
|
1318
1328
|
}
|
|
1319
1329
|
|
|
@@ -1407,9 +1417,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1407
1417
|
|
|
1408
1418
|
const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
|
|
1409
1419
|
|
|
1410
|
-
const sourcePath = resolve$
|
|
1420
|
+
const sourcePath = resolve$9(sourceDir, md5Key); // 模块源码要放到目标目录
|
|
1411
1421
|
|
|
1412
|
-
const targetPath = resolve$
|
|
1422
|
+
const targetPath = resolve$9(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
|
|
1413
1423
|
|
|
1414
1424
|
const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
|
|
1415
1425
|
|
|
@@ -1419,7 +1429,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1419
1429
|
targetPath
|
|
1420
1430
|
},
|
|
1421
1431
|
fn: async (sourceModulePath, targetPath) => {
|
|
1422
|
-
if (fs$
|
|
1432
|
+
if (fs$6.existsSync(targetPath)) {
|
|
1423
1433
|
shelljs$4.rm('-rf', `${targetPath}/*`);
|
|
1424
1434
|
}
|
|
1425
1435
|
|
|
@@ -1434,7 +1444,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1434
1444
|
} else {
|
|
1435
1445
|
let promiseTask;
|
|
1436
1446
|
|
|
1437
|
-
if (fs$
|
|
1447
|
+
if (fs$6.existsSync(sourcePath) && fs$6.existsSync(`${sourcePath}/.git`)) {
|
|
1438
1448
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1439
1449
|
info$5(`git pull:${httpRepoUrl}`);
|
|
1440
1450
|
return pullRepoForGit(sourcePath, branch);
|
|
@@ -1470,7 +1480,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1470
1480
|
*/
|
|
1471
1481
|
|
|
1472
1482
|
|
|
1473
|
-
function checkRemoteModGitUrlBranch
|
|
1483
|
+
function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
1474
1484
|
if (moduleInfo.repoInfo) {
|
|
1475
1485
|
const {
|
|
1476
1486
|
repoInfo: {
|
|
@@ -1482,7 +1492,7 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
|
|
|
1482
1492
|
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
|
|
1483
1493
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1484
1494
|
|
|
1485
|
-
if (!fs$
|
|
1495
|
+
if (!fs$6.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1486
1496
|
return true;
|
|
1487
1497
|
}
|
|
1488
1498
|
}
|
|
@@ -1492,11 +1502,11 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
|
|
|
1492
1502
|
|
|
1493
1503
|
var cloneModules_1 = {
|
|
1494
1504
|
cloneModules: cloneModules$1,
|
|
1495
|
-
checkRemoteModGitUrlBranch
|
|
1505
|
+
checkRemoteModGitUrlBranch
|
|
1496
1506
|
};
|
|
1497
1507
|
|
|
1498
1508
|
const ci = require$$0__default$7;
|
|
1499
|
-
const path$6 = require$$
|
|
1509
|
+
const path$6 = require$$3__default;
|
|
1500
1510
|
/**
|
|
1501
1511
|
* 获取小程序ci的Project对象
|
|
1502
1512
|
* @returns {Object} 小程序ci对象
|
|
@@ -1579,10 +1589,10 @@ var mpCi = {
|
|
|
1579
1589
|
/**
|
|
1580
1590
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1581
1591
|
*/
|
|
1582
|
-
const fs$
|
|
1583
|
-
const fsExtra = require$$1__default$
|
|
1584
|
-
const crypto = require$$1__default$
|
|
1585
|
-
const path$5 = require$$
|
|
1592
|
+
const fs$5 = require$$0__default$2;
|
|
1593
|
+
const fsExtra = require$$1__default$5;
|
|
1594
|
+
const crypto = require$$1__default$4;
|
|
1595
|
+
const path$5 = require$$3__default;
|
|
1586
1596
|
const shell = require$$0__default$3;
|
|
1587
1597
|
const glob = require$$5__default;
|
|
1588
1598
|
const log = log$1;
|
|
@@ -1614,7 +1624,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1614
1624
|
const npmTasksMap = new Map();
|
|
1615
1625
|
|
|
1616
1626
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1617
|
-
const packageContent = fs$
|
|
1627
|
+
const packageContent = fs$5.readFileSync(packageJsonPath);
|
|
1618
1628
|
const packageJson = JSON.parse(packageContent);
|
|
1619
1629
|
const md5Obj = {
|
|
1620
1630
|
dependencies: packageJson.dependencies || {}
|
|
@@ -1730,7 +1740,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1730
1740
|
|
|
1731
1741
|
const find = (startPath, filter) => {
|
|
1732
1742
|
// 目录不存在
|
|
1733
|
-
if (!fs$
|
|
1743
|
+
if (!fs$5.existsSync(startPath)) {
|
|
1734
1744
|
log.fail(`${startPath}目录不存在`);
|
|
1735
1745
|
process.exit(-1);
|
|
1736
1746
|
return;
|
|
@@ -1743,10 +1753,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1743
1753
|
return;
|
|
1744
1754
|
}
|
|
1745
1755
|
|
|
1746
|
-
const files = fs$
|
|
1756
|
+
const files = fs$5.readdirSync(startPath);
|
|
1747
1757
|
files.forEach(file => {
|
|
1748
1758
|
const filename = path$5.join(startPath, file);
|
|
1749
|
-
const stat = fs$
|
|
1759
|
+
const stat = fs$5.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1750
1760
|
|
|
1751
1761
|
if (stat.isDirectory()) {
|
|
1752
1762
|
find(filename, filter);
|
|
@@ -1788,7 +1798,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1788
1798
|
return result;
|
|
1789
1799
|
};
|
|
1790
1800
|
|
|
1791
|
-
function cloudNpmInstall
|
|
1801
|
+
function cloudNpmInstall(contextDir) {
|
|
1792
1802
|
return new Promise((resolve, reject) => {
|
|
1793
1803
|
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
1794
1804
|
if (err) {
|
|
@@ -1808,57 +1818,146 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1808
1818
|
}
|
|
1809
1819
|
|
|
1810
1820
|
var npm = {
|
|
1811
|
-
cloudNpmInstall
|
|
1821
|
+
cloudNpmInstall,
|
|
1812
1822
|
mpNpmInstallAll: mpNpmInstallAll$1,
|
|
1813
1823
|
findAllPackageJson
|
|
1814
1824
|
};
|
|
1815
1825
|
|
|
1816
1826
|
const {
|
|
1817
1827
|
createTask: createTask$1,
|
|
1818
|
-
resolve: resolve$
|
|
1828
|
+
resolve: resolve$8
|
|
1819
1829
|
} = widgets;
|
|
1820
1830
|
const {
|
|
1821
1831
|
buildMpNpm
|
|
1822
1832
|
} = mpCi;
|
|
1823
1833
|
const {
|
|
1824
|
-
CACHE_DIR
|
|
1834
|
+
CACHE_DIR: CACHE_DIR$1
|
|
1825
1835
|
} = require$$4;
|
|
1826
1836
|
const {
|
|
1827
|
-
cloudNpmInstall,
|
|
1828
1837
|
mpNpmInstallAll
|
|
1829
1838
|
} = npm;
|
|
1830
1839
|
const {
|
|
1831
1840
|
global: global$3
|
|
1832
1841
|
} = global_1;
|
|
1833
1842
|
|
|
1834
|
-
async function install$2(tmsConfig, modules
|
|
1843
|
+
async function install$2(tmsConfig, modules) {
|
|
1835
1844
|
// 小程序npm install
|
|
1836
|
-
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$
|
|
1845
|
+
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
1837
1846
|
const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1838
1847
|
|
|
1839
1848
|
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1840
1849
|
appId: tmsConfig.appId,
|
|
1841
|
-
projectPath: resolve$
|
|
1850
|
+
projectPath: resolve$8('./'),
|
|
1842
1851
|
privateKey: tmsPrivateCf.privateKey
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$9(tmsConfig.cloudDir));
|
|
1852
|
+
});
|
|
1846
1853
|
}
|
|
1847
1854
|
|
|
1848
1855
|
var install_1 = install$2;
|
|
1849
1856
|
|
|
1857
|
+
const fs$4 = require$$0__default$2;
|
|
1858
|
+
const semver$1 = require$$1__default$6;
|
|
1859
|
+
const {
|
|
1860
|
+
resolve: resolve$7
|
|
1861
|
+
} = widgets;
|
|
1862
|
+
const path$4 = require$$3__default;
|
|
1850
1863
|
const shelljs$3 = require$$0__default$3;
|
|
1851
|
-
const
|
|
1864
|
+
const {
|
|
1865
|
+
handleError
|
|
1866
|
+
} = handleError_1;
|
|
1867
|
+
|
|
1868
|
+
const getLatestVersion = npmName => {
|
|
1869
|
+
const data = shelljs$3.exec(`npm view ${npmName} version`);
|
|
1870
|
+
return data.stdout || '0.0.0';
|
|
1871
|
+
};
|
|
1872
|
+
/**
|
|
1873
|
+
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
1874
|
+
* @param {*} modules 模块
|
|
1875
|
+
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
1876
|
+
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
1877
|
+
* @returns
|
|
1878
|
+
*/
|
|
1879
|
+
|
|
1880
|
+
|
|
1881
|
+
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
1882
|
+
// 步骤1. 收集package.json
|
|
1883
|
+
const packageJsonName = 'package.json'; // 查找文件名
|
|
1884
|
+
// 1.1根目录的package.json
|
|
1885
|
+
|
|
1886
|
+
const packageArr = [{
|
|
1887
|
+
srcPackageDir: path$4.join(cwd, packageJsonName),
|
|
1888
|
+
destNpmDir: resolve$7(outputDir, 'node_modules')
|
|
1889
|
+
}]; // 1.2模块的package.json
|
|
1890
|
+
|
|
1891
|
+
modules.forEach(item => {
|
|
1892
|
+
const srcPackageDir = path$4.join(cwd, item.path, 'package.json');
|
|
1893
|
+
|
|
1894
|
+
if (fs$4.existsSync(srcPackageDir)) {
|
|
1895
|
+
packageArr.push({
|
|
1896
|
+
srcPackageDir,
|
|
1897
|
+
destNpmDir: resolve$7(outputDir, item.root, 'node_modules')
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1901
|
+
|
|
1902
|
+
for (const item of packageArr) {
|
|
1903
|
+
const packageJson = fs$4.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1904
|
+
let dependencies = {};
|
|
1905
|
+
|
|
1906
|
+
try {
|
|
1907
|
+
const json = JSON.parse(packageJson);
|
|
1908
|
+
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
1909
|
+
} catch (e) {
|
|
1910
|
+
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
const dependenciesKeys = Object.keys(dependencies);
|
|
1914
|
+
|
|
1915
|
+
for (const key of dependenciesKeys) {
|
|
1916
|
+
const depPath = path$4.join(item.destNpmDir, key);
|
|
1917
|
+
|
|
1918
|
+
if (!fs$4.existsSync(depPath)) {
|
|
1919
|
+
return true;
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
const depPackagePath = path$4.join(depPath, 'package.json');
|
|
1923
|
+
|
|
1924
|
+
if (fs$4.existsSync(depPackagePath)) {
|
|
1925
|
+
const packageData = require(depPackagePath);
|
|
1926
|
+
|
|
1927
|
+
if (dependencies[key] === 'latest') {
|
|
1928
|
+
dependencies[key] = getLatestVersion(key);
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
if (packageData.version === 'latest') {
|
|
1932
|
+
packageData.version = getLatestVersion(key);
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
|
|
1936
|
+
return true;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
return false;
|
|
1943
|
+
};
|
|
1944
|
+
|
|
1945
|
+
var checkDependencies_1 = {
|
|
1946
|
+
checkDependencies: checkDependencies$1
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
const shelljs$2 = require$$0__default$3;
|
|
1950
|
+
const fs$3 = require$$0__default$2;
|
|
1852
1951
|
const io = io$2;
|
|
1853
1952
|
const {
|
|
1854
|
-
resolve: resolve$
|
|
1953
|
+
resolve: resolve$6,
|
|
1855
1954
|
createTask
|
|
1856
1955
|
} = widgets;
|
|
1857
1956
|
const {
|
|
1858
1957
|
buildOutputAppJson
|
|
1859
1958
|
} = buildAppJson;
|
|
1860
1959
|
const {
|
|
1861
|
-
MODULE_CODE_DIR
|
|
1960
|
+
MODULE_CODE_DIR,
|
|
1862
1961
|
DEFAULT_COPY_CONFIG
|
|
1863
1962
|
} = require$$4;
|
|
1864
1963
|
const {
|
|
@@ -1869,10 +1968,13 @@ const {
|
|
|
1869
1968
|
subModulesMergeDepModules: subModulesMergeDepModules$1
|
|
1870
1969
|
} = tmsMpconfig;
|
|
1871
1970
|
const {
|
|
1872
|
-
fail: fail$
|
|
1971
|
+
fail: fail$2,
|
|
1873
1972
|
info: info$4
|
|
1874
1973
|
} = log$1;
|
|
1875
1974
|
const install$1 = install_1;
|
|
1975
|
+
const {
|
|
1976
|
+
checkDependencies
|
|
1977
|
+
} = checkDependencies_1;
|
|
1876
1978
|
/**
|
|
1877
1979
|
* 拷贝相关配置文件到编译输出目录
|
|
1878
1980
|
* @param { object } tmsConfig
|
|
@@ -1882,39 +1984,64 @@ const install$1 = install_1;
|
|
|
1882
1984
|
*/
|
|
1883
1985
|
|
|
1884
1986
|
const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
1885
|
-
const outputDir = resolve$
|
|
1987
|
+
const outputDir = resolve$6(tmsConfig.outputDir);
|
|
1886
1988
|
io.ensureDirExist(outputDir);
|
|
1887
1989
|
defaultFiles.forEach(item => {
|
|
1888
|
-
if (fs$
|
|
1889
|
-
shelljs$
|
|
1990
|
+
if (fs$3.existsSync(resolve$6(item))) {
|
|
1991
|
+
shelljs$2.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
|
|
1890
1992
|
}
|
|
1891
1993
|
}); // 拷贝模块的package.json到编译输出目录
|
|
1892
1994
|
|
|
1893
1995
|
targetModules.forEach(item => {
|
|
1894
|
-
const outputModuleDir = resolve$
|
|
1996
|
+
const outputModuleDir = resolve$6(`${tmsConfig.outputDir}/${item.root}`);
|
|
1895
1997
|
|
|
1896
|
-
if (!fs$
|
|
1897
|
-
fail$
|
|
1998
|
+
if (!fs$3.existsSync(resolve$6(item.path))) {
|
|
1999
|
+
fail$2(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1898
2000
|
process.exit(1);
|
|
1899
2001
|
}
|
|
1900
2002
|
|
|
1901
2003
|
io.ensureDirExist(outputModuleDir);
|
|
1902
|
-
const modulePackagePath = resolve$
|
|
1903
|
-
if (fs$
|
|
2004
|
+
const modulePackagePath = resolve$6(item.path, 'package.json');
|
|
2005
|
+
if (fs$3.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1904
2006
|
});
|
|
1905
2007
|
};
|
|
2008
|
+
/**
|
|
2009
|
+
* 校验相关配置项
|
|
2010
|
+
* @param {*} targetModules
|
|
2011
|
+
* @returns
|
|
2012
|
+
*/
|
|
2013
|
+
|
|
2014
|
+
|
|
2015
|
+
function checkConfig(targetModules) {
|
|
2016
|
+
for (const item of targetModules) {
|
|
2017
|
+
if (!item.root) {
|
|
2018
|
+
throw new Error(`检查${item.name} module.config.json的root字段`);
|
|
2019
|
+
} // 判断源码目录是否有该模块
|
|
2020
|
+
|
|
2021
|
+
|
|
2022
|
+
if (item.path && !fs$3.existsSync(resolve$6(item.path))) {
|
|
2023
|
+
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
return true;
|
|
2028
|
+
}
|
|
1906
2029
|
|
|
1907
2030
|
async function task(tmsConfig, targetModules) {
|
|
1908
2031
|
// 下载和移动代码
|
|
1909
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR
|
|
2032
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1910
2033
|
|
|
1911
2034
|
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
1912
2035
|
|
|
1913
|
-
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2036
|
+
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2037
|
+
checkConfig(newModules); // 拷贝相关配置文件到输出目录
|
|
1914
2038
|
|
|
1915
2039
|
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
|
|
1916
2040
|
|
|
1917
|
-
|
|
2041
|
+
if (checkDependencies(newModules, resolve$6('./'), tmsConfig.outputDir)) {
|
|
2042
|
+
await install$1(tmsConfig, newModules);
|
|
2043
|
+
} // 动态生成编译后的app.json;
|
|
2044
|
+
|
|
1918
2045
|
|
|
1919
2046
|
await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
1920
2047
|
return newModules;
|
|
@@ -1928,7 +2055,7 @@ async function init$5(tmsConfig, targetModules) {
|
|
|
1928
2055
|
};
|
|
1929
2056
|
} catch (error) {
|
|
1930
2057
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1931
|
-
fail$
|
|
2058
|
+
fail$2(`初始化流程出现错误${errMsg}`);
|
|
1932
2059
|
info$4('详细的错误信息', error);
|
|
1933
2060
|
process.exit(1);
|
|
1934
2061
|
}
|
|
@@ -1974,16 +2101,16 @@ var findCssImport = {
|
|
|
1974
2101
|
|
|
1975
2102
|
/* eslint-disable no-param-reassign */
|
|
1976
2103
|
const {
|
|
1977
|
-
fail: fail$
|
|
2104
|
+
fail: fail$1
|
|
1978
2105
|
} = log$1;
|
|
1979
2106
|
|
|
1980
2107
|
function pluginError$3(error, isWatch) {
|
|
1981
2108
|
const errMsg = error.message;
|
|
1982
2109
|
|
|
1983
2110
|
if (isWatch) {
|
|
1984
|
-
fail$
|
|
2111
|
+
fail$1(errMsg);
|
|
1985
2112
|
} else {
|
|
1986
|
-
fail$
|
|
2113
|
+
fail$1(errMsg);
|
|
1987
2114
|
process.exit(1);
|
|
1988
2115
|
}
|
|
1989
2116
|
}
|
|
@@ -1995,7 +2122,7 @@ var pluginError_1 = {
|
|
|
1995
2122
|
/* eslint-disable no-param-reassign */
|
|
1996
2123
|
const through$2 = require$$0__default$9;
|
|
1997
2124
|
const precinct = require$$1__default$7;
|
|
1998
|
-
const path$
|
|
2125
|
+
const path$3 = require$$3__default;
|
|
1999
2126
|
const {
|
|
2000
2127
|
findCssImports
|
|
2001
2128
|
} = findCssImport;
|
|
@@ -2005,9 +2132,9 @@ const {
|
|
|
2005
2132
|
diffContentCopyFile: diffContentCopyFile$2
|
|
2006
2133
|
} = io$2;
|
|
2007
2134
|
const {
|
|
2008
|
-
resolve: resolve$
|
|
2135
|
+
resolve: resolve$5
|
|
2009
2136
|
} = widgets;
|
|
2010
|
-
const fs$
|
|
2137
|
+
const fs$2 = require$$0__default$2;
|
|
2011
2138
|
const {
|
|
2012
2139
|
pluginError: pluginError$2
|
|
2013
2140
|
} = pluginError_1;
|
|
@@ -2020,16 +2147,16 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2020
2147
|
let contents = '';
|
|
2021
2148
|
|
|
2022
2149
|
try {
|
|
2023
|
-
contents = fs$
|
|
2150
|
+
contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
|
|
2024
2151
|
} catch (e) {
|
|
2025
2152
|
pluginError$2(e, isWatch);
|
|
2026
2153
|
}
|
|
2027
2154
|
|
|
2028
|
-
const deps = cssFilter.indexOf(path$
|
|
2155
|
+
const deps = cssFilter.indexOf(path$3.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2029
2156
|
deps.forEach(depItem => {
|
|
2030
2157
|
if (depItem.startsWith('.')) {
|
|
2031
2158
|
// 被依赖文件的存在的绝对路径
|
|
2032
|
-
const depOriginPath = path$
|
|
2159
|
+
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2033
2160
|
|
|
2034
2161
|
const {
|
|
2035
2162
|
ext: extAlias,
|
|
@@ -2037,12 +2164,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2037
2164
|
extPath
|
|
2038
2165
|
} = ext$2(depOriginPath, extensions);
|
|
2039
2166
|
|
|
2040
|
-
if (!fs$
|
|
2167
|
+
if (!fs$2.existsSync(depOriginFile)) {
|
|
2041
2168
|
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2042
2169
|
return;
|
|
2043
2170
|
}
|
|
2044
2171
|
|
|
2045
|
-
const depDestPath = resolve$
|
|
2172
|
+
const depDestPath = resolve$5(path$3.dirname(anaFileDestFile), depItem);
|
|
2046
2173
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2047
2174
|
|
|
2048
2175
|
if (!resDep.has(depDestFile)) {
|
|
@@ -2066,19 +2193,19 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2066
2193
|
const stream = through$2.obj(function (file, enc, cb) {
|
|
2067
2194
|
// 依赖分析的文件
|
|
2068
2195
|
const anaFileOriginFile = file.history[0];
|
|
2069
|
-
const anaFileRelativeModule = path$
|
|
2070
|
-
const anaFileDestFile = resolve$
|
|
2196
|
+
const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2197
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2071
2198
|
|
|
2072
2199
|
if (file.isBuffer()) {
|
|
2073
2200
|
let contents = String(file.contents);
|
|
2074
|
-
const deps = cssFilter.indexOf(path$
|
|
2201
|
+
const deps = cssFilter.indexOf(path$3.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2075
2202
|
const copyModules = new Map();
|
|
2076
2203
|
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2077
2204
|
const includePath = tmsConfig.dependencies[includeName];
|
|
2078
2205
|
deps.forEach(depItem => {
|
|
2079
2206
|
if (depItem.indexOf(includeName) > -1) {
|
|
2080
2207
|
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
2081
|
-
const depOriginPath = path$
|
|
2208
|
+
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2082
2209
|
|
|
2083
2210
|
const {
|
|
2084
2211
|
ext: extAlias,
|
|
@@ -2096,7 +2223,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2096
2223
|
const regRes = depItem.match(reg) || [];
|
|
2097
2224
|
|
|
2098
2225
|
if (regRes[2]) {
|
|
2099
|
-
const depDestPath = resolve$
|
|
2226
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2100
2227
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2101
2228
|
|
|
2102
2229
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2104,7 +2231,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2104
2231
|
depOriginFile,
|
|
2105
2232
|
depDestFile,
|
|
2106
2233
|
beforeDepPath: depItem,
|
|
2107
|
-
afterDepPath: path$
|
|
2234
|
+
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2108
2235
|
});
|
|
2109
2236
|
}
|
|
2110
2237
|
}
|
|
@@ -2142,16 +2269,16 @@ var mpCommonDep_1 = {
|
|
|
2142
2269
|
|
|
2143
2270
|
/* eslint-disable no-param-reassign */
|
|
2144
2271
|
const through$1 = require$$0__default$9;
|
|
2145
|
-
const path$
|
|
2272
|
+
const path$2 = require$$3__default;
|
|
2146
2273
|
const {
|
|
2147
2274
|
ext: ext$1,
|
|
2148
2275
|
fileInDir: fileInDir$1,
|
|
2149
2276
|
diffContentCopyFile: diffContentCopyFile$1
|
|
2150
2277
|
} = io$2;
|
|
2151
2278
|
const {
|
|
2152
|
-
resolve: resolve$
|
|
2279
|
+
resolve: resolve$4
|
|
2153
2280
|
} = widgets;
|
|
2154
|
-
const fs$
|
|
2281
|
+
const fs$1 = require$$0__default$2;
|
|
2155
2282
|
const {
|
|
2156
2283
|
pluginError: pluginError$1
|
|
2157
2284
|
} = pluginError_1;
|
|
@@ -2163,8 +2290,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2163
2290
|
const stream = through$1.obj(function (file, enc, cb) {
|
|
2164
2291
|
// 当前分析的文件的路径
|
|
2165
2292
|
const anaFileOriginFile = file.history[0];
|
|
2166
|
-
const anaFileRelativeModule = path$
|
|
2167
|
-
const anaFileDestFile = resolve$
|
|
2293
|
+
const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
|
|
2294
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2168
2295
|
|
|
2169
2296
|
if (file.isBuffer()) {
|
|
2170
2297
|
let contents = String(file.contents);
|
|
@@ -2184,7 +2311,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2184
2311
|
const componentPath = contents.usingComponents[componentKey];
|
|
2185
2312
|
|
|
2186
2313
|
if (componentPath.indexOf(includeName) > -1) {
|
|
2187
|
-
const depOriginPath = path$
|
|
2314
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
|
|
2188
2315
|
|
|
2189
2316
|
const {
|
|
2190
2317
|
ext: extAlias,
|
|
@@ -2203,7 +2330,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2203
2330
|
const regRes = componentPath.match(reg) || [];
|
|
2204
2331
|
|
|
2205
2332
|
if (regRes[2]) {
|
|
2206
|
-
const depDestPath = resolve$
|
|
2333
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2207
2334
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2208
2335
|
|
|
2209
2336
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2212,7 +2339,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2212
2339
|
depOriginExt: extAlias,
|
|
2213
2340
|
depDestFile,
|
|
2214
2341
|
beforeDepPath: componentPath,
|
|
2215
|
-
afterDepPath: path$
|
|
2342
|
+
afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2216
2343
|
});
|
|
2217
2344
|
}
|
|
2218
2345
|
}
|
|
@@ -2237,7 +2364,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2237
2364
|
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2238
2365
|
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2239
2366
|
|
|
2240
|
-
if (fs$
|
|
2367
|
+
if (fs$1.existsSync(originFile)) {
|
|
2241
2368
|
diffContentCopyFile$1(originFile, destFile);
|
|
2242
2369
|
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2243
2370
|
|
|
@@ -2271,15 +2398,15 @@ var mpJsonDep_1 = {
|
|
|
2271
2398
|
/* eslint-disable no-param-reassign */
|
|
2272
2399
|
const through = require$$0__default$9;
|
|
2273
2400
|
const htmlparser2 = require$$1__default$8;
|
|
2274
|
-
const fs
|
|
2275
|
-
const path$
|
|
2401
|
+
const fs = require$$0__default$2;
|
|
2402
|
+
const path$1 = require$$3__default;
|
|
2276
2403
|
const {
|
|
2277
2404
|
diffContentCopyFile,
|
|
2278
2405
|
ext,
|
|
2279
2406
|
fileInDir
|
|
2280
2407
|
} = io$2;
|
|
2281
2408
|
const {
|
|
2282
|
-
resolve: resolve$
|
|
2409
|
+
resolve: resolve$3
|
|
2283
2410
|
} = widgets;
|
|
2284
2411
|
const {
|
|
2285
2412
|
dfsFindCommonDep
|
|
@@ -2318,7 +2445,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2318
2445
|
let contents = '';
|
|
2319
2446
|
|
|
2320
2447
|
try {
|
|
2321
|
-
contents = fs
|
|
2448
|
+
contents = fs.readFileSync(anaFileOriginFile, 'utf8');
|
|
2322
2449
|
} catch (e) {
|
|
2323
2450
|
pluginError(e, isWatch);
|
|
2324
2451
|
}
|
|
@@ -2328,7 +2455,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2328
2455
|
var _attributes$src;
|
|
2329
2456
|
|
|
2330
2457
|
if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
|
|
2331
|
-
const depOriginPath = path$
|
|
2458
|
+
const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
|
|
2332
2459
|
|
|
2333
2460
|
const {
|
|
2334
2461
|
ext,
|
|
@@ -2336,12 +2463,12 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2336
2463
|
extPath
|
|
2337
2464
|
} = extFile(name, depOriginPath);
|
|
2338
2465
|
|
|
2339
|
-
if (!fs
|
|
2466
|
+
if (!fs.existsSync(depOriginFile)) {
|
|
2340
2467
|
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2341
2468
|
return;
|
|
2342
2469
|
}
|
|
2343
2470
|
|
|
2344
|
-
const depDestPath = path$
|
|
2471
|
+
const depDestPath = path$1.join(path$1.dirname(anaFileDestFile), attributes.src);
|
|
2345
2472
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
|
|
2346
2473
|
|
|
2347
2474
|
if (['import', 'include'].indexOf(name) > -1) {
|
|
@@ -2393,8 +2520,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2393
2520
|
const stream = through.obj(function (file, enc, cb) {
|
|
2394
2521
|
// 依赖分析的文件
|
|
2395
2522
|
const anaFileOriginFile = file.history[0];
|
|
2396
|
-
const anaFileRelativeModule = path$
|
|
2397
|
-
const anaFileDestFile = resolve$
|
|
2523
|
+
const anaFileRelativeModule = path$1.relative(resolve$3(module.from), anaFileOriginFile);
|
|
2524
|
+
const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2398
2525
|
|
|
2399
2526
|
if (file.isBuffer()) {
|
|
2400
2527
|
let contents = String(file.contents);
|
|
@@ -2404,7 +2531,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2404
2531
|
const nameFilter = ['import', 'include', 'wxs'];
|
|
2405
2532
|
|
|
2406
2533
|
if (nameFilter.indexOf(name) > -1 && attributes.src) {
|
|
2407
|
-
const depOriginPath = path$
|
|
2534
|
+
const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
|
|
2408
2535
|
|
|
2409
2536
|
const {
|
|
2410
2537
|
ext,
|
|
@@ -2425,7 +2552,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2425
2552
|
const regRes = attributes.src.match(reg) || [];
|
|
2426
2553
|
|
|
2427
2554
|
if (regRes[2]) {
|
|
2428
|
-
const depDestPath = resolve$
|
|
2555
|
+
const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2429
2556
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2430
2557
|
|
|
2431
2558
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2433,7 +2560,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2433
2560
|
depOriginFile,
|
|
2434
2561
|
depDestFile,
|
|
2435
2562
|
beforeDepPath: attributes.src,
|
|
2436
|
-
afterDepPath: path$
|
|
2563
|
+
afterDepPath: path$1.relative(path$1.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
|
|
2437
2564
|
});
|
|
2438
2565
|
}
|
|
2439
2566
|
}
|
|
@@ -2452,7 +2579,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2452
2579
|
beforeDepPath,
|
|
2453
2580
|
afterDepPath
|
|
2454
2581
|
}) => {
|
|
2455
|
-
if (fs
|
|
2582
|
+
if (fs.existsSync(depOriginFile)) {
|
|
2456
2583
|
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2457
2584
|
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2458
2585
|
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
@@ -2508,7 +2635,7 @@ const {
|
|
|
2508
2635
|
// const base64 = require('./plugins/postcss-font-base64');
|
|
2509
2636
|
|
|
2510
2637
|
const {
|
|
2511
|
-
fail
|
|
2638
|
+
fail
|
|
2512
2639
|
} = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
2513
2640
|
|
|
2514
2641
|
var compile = function (tmsConfig, {
|
|
@@ -2516,7 +2643,7 @@ var compile = function (tmsConfig, {
|
|
|
2516
2643
|
destPath,
|
|
2517
2644
|
srcOption,
|
|
2518
2645
|
module,
|
|
2519
|
-
|
|
2646
|
+
isDev
|
|
2520
2647
|
}) {
|
|
2521
2648
|
const compileTasksMap = new Map();
|
|
2522
2649
|
Object.keys(glob).forEach(globKey => {
|
|
@@ -2526,14 +2653,18 @@ var compile = function (tmsConfig, {
|
|
|
2526
2653
|
case 'js':
|
|
2527
2654
|
compileTasksMap.set(globValue, {
|
|
2528
2655
|
module,
|
|
2529
|
-
taskFn: () => {
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
const srcPipe = src$1(
|
|
2656
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2657
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2658
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2659
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2533
2660
|
});
|
|
2534
2661
|
return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
2535
|
-
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'],
|
|
2536
|
-
fail
|
|
2662
|
+
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
|
|
2663
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
2664
|
+
}).pipe(dest(newDestPath, {
|
|
2665
|
+
overwrite: true
|
|
2666
|
+
})).on('error', err => {
|
|
2667
|
+
fail(`js编译报错${err}`);
|
|
2537
2668
|
});
|
|
2538
2669
|
}
|
|
2539
2670
|
});
|
|
@@ -2542,13 +2673,13 @@ var compile = function (tmsConfig, {
|
|
|
2542
2673
|
case 'wxss':
|
|
2543
2674
|
compileTasksMap.set(globValue, {
|
|
2544
2675
|
module,
|
|
2545
|
-
taskFn: () => {
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
const srcPipe = src$1(
|
|
2676
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2677
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2678
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2679
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2549
2680
|
});
|
|
2550
|
-
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'],
|
|
2551
|
-
fail
|
|
2681
|
+
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
|
|
2682
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
2552
2683
|
}) // .pipe(postcss([base64()]))
|
|
2553
2684
|
// .on('error', (err) => {
|
|
2554
2685
|
// fail(`postcss编译报错${err}`);
|
|
@@ -2557,7 +2688,9 @@ var compile = function (tmsConfig, {
|
|
|
2557
2688
|
// designWidth: 375, // 设计稿宽度,默认为750
|
|
2558
2689
|
// precision: 2, // 小数最大精度,默认为6
|
|
2559
2690
|
// }))
|
|
2560
|
-
.pipe(dest(
|
|
2691
|
+
.pipe(dest(newDestPath)).on('error', err => {
|
|
2692
|
+
fail(`wxss编译报错${err}`);
|
|
2693
|
+
});
|
|
2561
2694
|
}
|
|
2562
2695
|
});
|
|
2563
2696
|
break;
|
|
@@ -2565,14 +2698,16 @@ var compile = function (tmsConfig, {
|
|
|
2565
2698
|
case 'json':
|
|
2566
2699
|
compileTasksMap.set(globValue, {
|
|
2567
2700
|
module,
|
|
2568
|
-
taskFn: () => {
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
const srcPipe = src$1(
|
|
2701
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2702
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2703
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2704
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2705
|
+
});
|
|
2706
|
+
return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
|
|
2707
|
+
fail(`mpJsonDep编译报错${err}`);
|
|
2708
|
+
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2709
|
+
fail(`json编译报错${err}`);
|
|
2572
2710
|
});
|
|
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
2711
|
}
|
|
2577
2712
|
});
|
|
2578
2713
|
break;
|
|
@@ -2580,12 +2715,16 @@ var compile = function (tmsConfig, {
|
|
|
2580
2715
|
case 'wxml':
|
|
2581
2716
|
compileTasksMap.set(globValue, {
|
|
2582
2717
|
module,
|
|
2583
|
-
taskFn: () => {
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
const srcPipe = src$1(
|
|
2718
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2719
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2720
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2721
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2722
|
+
});
|
|
2723
|
+
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
|
|
2724
|
+
fail(`mpWxmlDep编译报错${err}`);
|
|
2725
|
+
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2726
|
+
fail(`wxml编译报错${err}`);
|
|
2587
2727
|
});
|
|
2588
|
-
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isWatch)).pipe(dest(destPath));
|
|
2589
2728
|
}
|
|
2590
2729
|
});
|
|
2591
2730
|
break;
|
|
@@ -2593,16 +2732,18 @@ var compile = function (tmsConfig, {
|
|
|
2593
2732
|
case 'image':
|
|
2594
2733
|
compileTasksMap.set(globValue, {
|
|
2595
2734
|
module,
|
|
2596
|
-
taskFn: () => {
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
const srcPipe = src$1(
|
|
2735
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2736
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2737
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2738
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2600
2739
|
});
|
|
2601
2740
|
return srcPipe // .pipe(cache(image()))
|
|
2602
2741
|
// .on('error', (err) => {
|
|
2603
2742
|
// fail(`image编译报错${err}`);
|
|
2604
2743
|
// })
|
|
2605
|
-
.pipe(dest(
|
|
2744
|
+
.pipe(dest(newDestPath)).on('error', err => {
|
|
2745
|
+
fail(`image编译报错${err}`);
|
|
2746
|
+
});
|
|
2606
2747
|
}
|
|
2607
2748
|
});
|
|
2608
2749
|
break;
|
|
@@ -2610,12 +2751,14 @@ var compile = function (tmsConfig, {
|
|
|
2610
2751
|
case 'other':
|
|
2611
2752
|
compileTasksMap.set(globValue, {
|
|
2612
2753
|
module,
|
|
2613
|
-
taskFn: () => {
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
const srcPipe = src$1(
|
|
2754
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2755
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2756
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2757
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2758
|
+
});
|
|
2759
|
+
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
2760
|
+
fail(`编译报错${err}`);
|
|
2617
2761
|
});
|
|
2618
|
-
return srcPipe.pipe(dest(destPath));
|
|
2619
2762
|
}
|
|
2620
2763
|
});
|
|
2621
2764
|
break;
|
|
@@ -2625,43 +2768,59 @@ var compile = function (tmsConfig, {
|
|
|
2625
2768
|
};
|
|
2626
2769
|
|
|
2627
2770
|
const watch = require$$0__default$b;
|
|
2628
|
-
const path
|
|
2771
|
+
const path = require$$3__default;
|
|
2629
2772
|
const shellJs = require$$0__default$3;
|
|
2630
2773
|
const {
|
|
2631
|
-
info: info$3
|
|
2774
|
+
info: info$3,
|
|
2775
|
+
warn
|
|
2632
2776
|
} = log$1;
|
|
2633
2777
|
const {
|
|
2634
|
-
resolve: resolve$
|
|
2778
|
+
resolve: resolve$2
|
|
2635
2779
|
} = widgets;
|
|
2636
2780
|
const {
|
|
2637
2781
|
global: global$2
|
|
2638
2782
|
} = global_1;
|
|
2783
|
+
const TIP_MAP = {
|
|
2784
|
+
'package.json': '若依赖有变动,请重新执行tmskit run dev',
|
|
2785
|
+
'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效'
|
|
2786
|
+
};
|
|
2787
|
+
|
|
2788
|
+
const logTip = (fileName, tipMap) => {
|
|
2789
|
+
// eslint-disable-next-line
|
|
2790
|
+
for (const item in tipMap) {
|
|
2791
|
+
if (fileName.indexOf(item) > -1) {
|
|
2792
|
+
warn(`${fileName}有更新, ${tipMap[item]}`);
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2639
2796
|
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2797
|
+
info$3(`${fileName}有更新`);
|
|
2798
|
+
};
|
|
2799
|
+
|
|
2800
|
+
var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
2801
|
+
watch(globValue, { // readDelay: 100,
|
|
2643
2802
|
...watchOptions
|
|
2644
2803
|
}, vinyl => {
|
|
2645
|
-
const
|
|
2646
|
-
const
|
|
2647
|
-
const
|
|
2804
|
+
const sourceFile = vinyl.history[0];
|
|
2805
|
+
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
2806
|
+
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
2807
|
+
const tmsConfig = global$2.getData('tmsConfig');
|
|
2808
|
+
const sourceFileRelativeModule = path.relative(resolve$2(module.from), sourceFile);
|
|
2809
|
+
const targetFile = resolve$2(tmsConfig.outputDir, module.to, sourceFileRelativeModule);
|
|
2648
2810
|
|
|
2649
2811
|
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);
|
|
2812
|
+
info$3(`删除${sourceFileName}`);
|
|
2813
|
+
shellJs.rm('-rf', targetFile);
|
|
2655
2814
|
return;
|
|
2656
2815
|
}
|
|
2657
2816
|
|
|
2658
|
-
|
|
2659
|
-
return callback(
|
|
2817
|
+
logTip(sourceFileName, TIP_MAP);
|
|
2818
|
+
return callback([sourceFile], path.dirname(targetFile));
|
|
2660
2819
|
});
|
|
2661
2820
|
};
|
|
2662
2821
|
|
|
2663
2822
|
(function (module) {
|
|
2664
|
-
const path = require$$
|
|
2823
|
+
const path = require$$3__default;
|
|
2665
2824
|
const fs = require$$0__default$2;
|
|
2666
2825
|
const ora = require$$2__default;
|
|
2667
2826
|
const {
|
|
@@ -2713,16 +2872,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2713
2872
|
return newPath;
|
|
2714
2873
|
}
|
|
2715
2874
|
|
|
2716
|
-
module.exports = async (tmsConfig, newModules,
|
|
2875
|
+
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
2717
2876
|
const compileTasksMap = new Map(); // 监听app.json
|
|
2718
2877
|
|
|
2719
|
-
if (
|
|
2878
|
+
if (isDev) {
|
|
2720
2879
|
watch([resolve('app.json')], {
|
|
2721
2880
|
ignoreInitial: false,
|
|
2722
2881
|
events: watchEvents
|
|
2723
|
-
}, () => buildOutputAppJson(tmsConfig, newModules,
|
|
2882
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
2883
|
+
from: resolve(),
|
|
2884
|
+
to: resolve(tmsConfig.outputDir)
|
|
2885
|
+
});
|
|
2724
2886
|
} else {
|
|
2725
|
-
buildOutputAppJson(tmsConfig, newModules,
|
|
2887
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
2726
2888
|
} // 监听根目录的文件
|
|
2727
2889
|
|
|
2728
2890
|
|
|
@@ -2733,14 +2895,14 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2733
2895
|
|
|
2734
2896
|
},
|
|
2735
2897
|
module: {
|
|
2736
|
-
from:
|
|
2737
|
-
to:
|
|
2898
|
+
from: resolve(),
|
|
2899
|
+
to: resolve(tmsConfig.outputDir)
|
|
2738
2900
|
},
|
|
2739
2901
|
destPath: resolve(tmsConfig.outputDir),
|
|
2740
2902
|
srcOption: {
|
|
2741
2903
|
allowEmpty: true
|
|
2742
2904
|
},
|
|
2743
|
-
|
|
2905
|
+
isDev
|
|
2744
2906
|
})); // 监听模块的文件
|
|
2745
2907
|
|
|
2746
2908
|
for (let module of newModules) {
|
|
@@ -2750,16 +2912,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2750
2912
|
},
|
|
2751
2913
|
...module
|
|
2752
2914
|
};
|
|
2915
|
+
const modulePath = adaptPath(module.path);
|
|
2753
2916
|
|
|
2754
|
-
if (
|
|
2917
|
+
if (isDev) {
|
|
2755
2918
|
// 监听模块配置文件
|
|
2756
|
-
watch([`${
|
|
2919
|
+
watch([`${modulePath}/**/module.config.json`], {
|
|
2757
2920
|
events: watchEvents
|
|
2758
|
-
}, () => buildOutputAppJson(tmsConfig, newModules,
|
|
2921
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
2922
|
+
from: modulePath,
|
|
2923
|
+
to: modulePath
|
|
2924
|
+
});
|
|
2759
2925
|
}
|
|
2760
2926
|
|
|
2761
2927
|
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
2762
|
-
const modulePath = adaptPath(module.path);
|
|
2763
2928
|
const glob = {
|
|
2764
2929
|
js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
2765
2930
|
json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
|
|
@@ -2779,7 +2944,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2779
2944
|
srcOption: {
|
|
2780
2945
|
allowEmpty: true
|
|
2781
2946
|
},
|
|
2782
|
-
|
|
2947
|
+
isDev
|
|
2783
2948
|
}));
|
|
2784
2949
|
} // 静态资源目录-拷贝
|
|
2785
2950
|
|
|
@@ -2815,7 +2980,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2815
2980
|
srcOption: {
|
|
2816
2981
|
allowEmpty: true
|
|
2817
2982
|
},
|
|
2818
|
-
|
|
2983
|
+
isDev
|
|
2819
2984
|
}));
|
|
2820
2985
|
}
|
|
2821
2986
|
}
|
|
@@ -2824,8 +2989,17 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2824
2989
|
let eTime;
|
|
2825
2990
|
const spinner = ora();
|
|
2826
2991
|
|
|
2992
|
+
function start(cb) {
|
|
2993
|
+
info('启动编译...');
|
|
2994
|
+
spinner.start();
|
|
2995
|
+
sTime = new Date().getTime();
|
|
2996
|
+
cb();
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2827
2999
|
function end(cb) {
|
|
2828
|
-
|
|
3000
|
+
var _tmsConfig$hooks;
|
|
3001
|
+
|
|
3002
|
+
if (isDev) {
|
|
2829
3003
|
compileTasksMap.forEach(({
|
|
2830
3004
|
taskFn,
|
|
2831
3005
|
module
|
|
@@ -2838,15 +3012,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2838
3012
|
}
|
|
2839
3013
|
|
|
2840
3014
|
eTime = new Date().getTime() - sTime;
|
|
2841
|
-
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即刻预览。`);
|
|
2842
|
-
spinner.stop();
|
|
2843
|
-
cb();
|
|
2844
|
-
}
|
|
2845
3015
|
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
3016
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
|
|
3017
|
+
var _tmsConfig$hooks2;
|
|
3018
|
+
|
|
3019
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3020
|
+
isDev,
|
|
3021
|
+
tmsConfig,
|
|
3022
|
+
modules: newModules
|
|
3023
|
+
});
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
|
|
3027
|
+
spinner.stop();
|
|
2850
3028
|
cb();
|
|
2851
3029
|
}
|
|
2852
3030
|
|
|
@@ -2860,185 +3038,12 @@ var watch_1 = function (glob, watchOptions, callback, module) {
|
|
|
2860
3038
|
};
|
|
2861
3039
|
})(dev$3);
|
|
2862
3040
|
|
|
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
3041
|
const shelljs$1 = require$$0__default$3;
|
|
3034
3042
|
const compileDev = dev$3.exports;
|
|
3035
3043
|
const {
|
|
3036
3044
|
resolve: resolve$1
|
|
3037
3045
|
} = widgets;
|
|
3038
3046
|
const init$4 = init_1;
|
|
3039
|
-
const {
|
|
3040
|
-
isInit
|
|
3041
|
-
} = isInIt;
|
|
3042
3047
|
const {
|
|
3043
3048
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
3044
3049
|
} = tmsMpconfig;
|
|
@@ -3047,7 +3052,10 @@ const {
|
|
|
3047
3052
|
} = log$1;
|
|
3048
3053
|
const {
|
|
3049
3054
|
global: global$1
|
|
3050
|
-
} = global_1;
|
|
3055
|
+
} = global_1;
|
|
3056
|
+
const {
|
|
3057
|
+
CACHE_DIR
|
|
3058
|
+
} = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
3051
3059
|
|
|
3052
3060
|
function delOtherModule(tmsConfig, targetModules) {
|
|
3053
3061
|
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
|
|
@@ -3064,16 +3072,32 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
3064
3072
|
}
|
|
3065
3073
|
|
|
3066
3074
|
async function dev$2(tmsConfig, targetModules, env) {
|
|
3075
|
+
var _tmsConfig$hooks;
|
|
3076
|
+
|
|
3067
3077
|
let newModules = targetModules;
|
|
3068
|
-
const
|
|
3078
|
+
const {
|
|
3079
|
+
noCache
|
|
3080
|
+
} = global$1.getData('cmd');
|
|
3069
3081
|
|
|
3070
|
-
if (
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
}
|
|
3082
|
+
if (noCache) {
|
|
3083
|
+
shelljs$1.rm('-rf', resolve$1('dist'));
|
|
3084
|
+
shelljs$1.rm('-rf', CACHE_DIR);
|
|
3085
|
+
} // 初始化操作
|
|
3075
3086
|
|
|
3087
|
+
|
|
3088
|
+
const initData = await init$4(tmsConfig, newModules);
|
|
3089
|
+
newModules = initData.targetModules;
|
|
3076
3090
|
info$2('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
3091
|
+
|
|
3092
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3093
|
+
var _tmsConfig$hooks2;
|
|
3094
|
+
|
|
3095
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3096
|
+
isDev: true,
|
|
3097
|
+
tmsConfig,
|
|
3098
|
+
modules: newModules
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3077
3101
|
delOtherModule(tmsConfig, newModules);
|
|
3078
3102
|
compileDev(tmsConfig, newModules, env);
|
|
3079
3103
|
}
|
|
@@ -3228,7 +3252,7 @@ var entry = [{
|
|
|
3228
3252
|
}, {
|
|
3229
3253
|
command: 'dev',
|
|
3230
3254
|
description: 'dev 打包编译',
|
|
3231
|
-
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-
|
|
3255
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-noCache, --noCache', '不使用缓存功能']],
|
|
3232
3256
|
action: cmd => {
|
|
3233
3257
|
run_1('dev', cmd);
|
|
3234
3258
|
}
|
|
@@ -3256,7 +3280,7 @@ var entry = [{
|
|
|
3256
3280
|
|
|
3257
3281
|
var require$$7 = {
|
|
3258
3282
|
name: "@tmsfe/tmskit",
|
|
3259
|
-
version: "0.0.
|
|
3283
|
+
version: "0.0.15-beta.3",
|
|
3260
3284
|
description: "tmskit",
|
|
3261
3285
|
main: "dist/index.cjs",
|
|
3262
3286
|
bin: {
|
|
@@ -3273,7 +3297,8 @@ var require$$7 = {
|
|
|
3273
3297
|
build: "rollup -c --environment TARGET:tmskit",
|
|
3274
3298
|
"pub:patch": "sh build/publish.sh patch",
|
|
3275
3299
|
"pub:minor": "sh build/publish.sh minor",
|
|
3276
|
-
"pub:major": "sh build/publish.sh major"
|
|
3300
|
+
"pub:major": "sh build/publish.sh major",
|
|
3301
|
+
postinstall: "cd node_modules/gulp-watch && npm install chokidar@3.5.3"
|
|
3277
3302
|
},
|
|
3278
3303
|
author: "tms·web",
|
|
3279
3304
|
license: "ISC",
|
|
@@ -3312,6 +3337,7 @@ var require$$7 = {
|
|
|
3312
3337
|
moment: "^2.29.1",
|
|
3313
3338
|
"object-assign": "^4.0.1",
|
|
3314
3339
|
ora: "^5.1.0",
|
|
3340
|
+
"patch-package": "^6.4.7",
|
|
3315
3341
|
"plugin-error": "^1.0.0",
|
|
3316
3342
|
postcss: "^8.4.6",
|
|
3317
3343
|
precinct: "^8.3.1",
|
|
@@ -3329,7 +3355,7 @@ var require$$7 = {
|
|
|
3329
3355
|
}
|
|
3330
3356
|
};
|
|
3331
3357
|
|
|
3332
|
-
const semver = require$$1__default$
|
|
3358
|
+
const semver = require$$1__default$6;
|
|
3333
3359
|
const packageJson = require$$7;
|
|
3334
3360
|
const chalk$1 = require$$0__default;
|
|
3335
3361
|
const {
|