@tmsfe/tmskit 0.0.15-beta.5 → 0.0.17
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 -2
- package/README.md +2 -3
- package/dist/index.cjs.js +809 -454
- package/package.json +12 -4
- package/src/compile/dev.js +16 -15
- package/src/compile/plugins/gulp-watch/index.js +172 -0
- package/src/compile/plugins/mpJsonDep.js +1 -1
- package/src/compile/watch.js +22 -3
- package/src/core/buildAppJson.js +14 -17
- package/src/core/tmsMpconfig.js +22 -25
- package/src/entry.js +11 -0
- package/src/scripts/run/build/index.js +3 -0
- package/src/scripts/run/cloud/index.js +12 -0
- package/src/scripts/run/dev/index.js +3 -2
- package/src/scripts/run/index.js +4 -0
- package/src/scripts/run/init/index.js +2 -14
- package/src/scripts/run/install/index.js +16 -0
- package/src/utils/io.js +20 -0
- package/build/postInstall.js +0 -15
package/dist/index.cjs.js
CHANGED
|
@@ -5,25 +5,36 @@ 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$$1$2 = 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$3 = require('ejs');
|
|
13
|
+
var require$$1$4 = 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$5 = require('crypto');
|
|
17
17
|
var require$$0$7 = require('miniprogram-ci');
|
|
18
18
|
var require$$5 = require('glob-ignore');
|
|
19
|
-
var require$$1$
|
|
20
|
-
var require$$1$
|
|
19
|
+
var require$$1$6 = require('fs-extra');
|
|
20
|
+
var require$$1$7 = require('semver');
|
|
21
21
|
var require$$0$8 = require('strip-comments');
|
|
22
22
|
var require$$0$9 = require('through2');
|
|
23
|
-
var require$$1$
|
|
24
|
-
var require$$1$
|
|
23
|
+
var require$$1$8 = require('precinct');
|
|
24
|
+
var require$$1$9 = require('htmlparser2');
|
|
25
25
|
var require$$0$a = require('gulp');
|
|
26
|
-
var require$$0$b = 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
|
|
|
@@ -32,25 +43,36 @@ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
|
32
43
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
33
44
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
34
45
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
35
|
-
var require$$
|
|
46
|
+
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
36
47
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
37
48
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
38
49
|
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
39
|
-
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
40
50
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
51
|
+
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
41
52
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
42
53
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
43
|
-
var require$$1__default$
|
|
54
|
+
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
|
-
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
47
57
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
58
|
+
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
48
59
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
49
60
|
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
50
|
-
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
51
61
|
var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
|
|
62
|
+
var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
|
|
52
63
|
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
53
64
|
var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
|
|
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;
|
|
@@ -97,7 +119,7 @@ const fail$8 = (message = '') => {
|
|
|
97
119
|
*/
|
|
98
120
|
|
|
99
121
|
|
|
100
|
-
const succeed$
|
|
122
|
+
const succeed$2 = (message = '') => {
|
|
101
123
|
const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
|
|
102
124
|
|
|
103
125
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
@@ -111,7 +133,7 @@ const succeed$1 = (message = '') => {
|
|
|
111
133
|
*/
|
|
112
134
|
|
|
113
135
|
|
|
114
|
-
const warn$
|
|
136
|
+
const warn$2 = message => {
|
|
115
137
|
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
|
|
116
138
|
};
|
|
117
139
|
|
|
@@ -119,17 +141,17 @@ const info$9 = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss'
|
|
|
119
141
|
|
|
120
142
|
var log$1 = {
|
|
121
143
|
fail: fail$8,
|
|
122
|
-
succeed: succeed$
|
|
123
|
-
warn: warn$
|
|
144
|
+
succeed: succeed$2,
|
|
145
|
+
warn: warn$2,
|
|
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$
|
|
131
|
-
const fs$
|
|
132
|
-
const shelljs$
|
|
152
|
+
const path$c = require$$1__default$2;
|
|
153
|
+
const fs$d = require$$0__default$2;
|
|
154
|
+
const shelljs$7 = require$$0__default$3;
|
|
133
155
|
const {
|
|
134
156
|
info: info$8
|
|
135
157
|
} = log$1;
|
|
@@ -142,7 +164,7 @@ const shelljsOptions = {
|
|
|
142
164
|
const cwd = process.cwd();
|
|
143
165
|
|
|
144
166
|
function resolve$e(...args) {
|
|
145
|
-
return path$
|
|
167
|
+
return path$c.resolve(cwd, ...args);
|
|
146
168
|
}
|
|
147
169
|
/**
|
|
148
170
|
* 用户输入命令时,进行提示
|
|
@@ -172,7 +194,7 @@ const suggestCommands$1 = unknownCommand => {
|
|
|
172
194
|
*/
|
|
173
195
|
|
|
174
196
|
|
|
175
|
-
function isObject$
|
|
197
|
+
function isObject$1(obj) {
|
|
176
198
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
177
199
|
}
|
|
178
200
|
/**
|
|
@@ -198,20 +220,20 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
198
220
|
const cwd = process.cwd();
|
|
199
221
|
return new Promise((resolve, reject) => {
|
|
200
222
|
// 如果目标目录不存在
|
|
201
|
-
if (fs$
|
|
202
|
-
shelljs$
|
|
223
|
+
if (fs$d.existsSync(dest)) {
|
|
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) => {
|
|
@@ -312,12 +334,12 @@ const mergeMap = function (obj, src) {
|
|
|
312
334
|
};
|
|
313
335
|
|
|
314
336
|
const relativeCwdPath$1 = function (file) {
|
|
315
|
-
return path$
|
|
337
|
+
return path$c.relative(process.cwd(), file);
|
|
316
338
|
};
|
|
317
339
|
|
|
318
340
|
var widgets = {
|
|
319
341
|
resolve: resolve$e,
|
|
320
|
-
isObject: isObject$
|
|
342
|
+
isObject: isObject$1,
|
|
321
343
|
isArray: isArray$1,
|
|
322
344
|
createTask: createTask$3,
|
|
323
345
|
downloadRepoForGit: downloadRepoForGit$2,
|
|
@@ -329,20 +351,20 @@ var widgets = {
|
|
|
329
351
|
relativeCwdPath: relativeCwdPath$1
|
|
330
352
|
};
|
|
331
353
|
|
|
332
|
-
const path$
|
|
354
|
+
const path$b = require('path');
|
|
333
355
|
|
|
334
356
|
const os = require('os'); // 用户目录
|
|
335
357
|
|
|
336
358
|
|
|
337
359
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
338
360
|
|
|
339
|
-
const CACHE_DIR$2 = path$
|
|
361
|
+
const CACHE_DIR$2 = path$b.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
340
362
|
|
|
341
|
-
const TEMPLATE_DIR$1 = path$
|
|
363
|
+
const TEMPLATE_DIR$1 = path$b.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
342
364
|
|
|
343
|
-
const MODULE_CODE_DIR$1 = path$
|
|
365
|
+
const MODULE_CODE_DIR$1 = path$b.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
|
|
344
366
|
|
|
345
|
-
const TEMPLATE_PATH$1 = path$
|
|
367
|
+
const TEMPLATE_PATH$1 = path$b.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
346
368
|
|
|
347
369
|
const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
|
|
348
370
|
|
|
@@ -353,10 +375,10 @@ const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目
|
|
|
353
375
|
|
|
354
376
|
const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
355
377
|
|
|
356
|
-
const MODULE_CONFIG_FILENAME$
|
|
378
|
+
const MODULE_CONFIG_FILENAME$1 = 'module.config.json'; // 默认的webpack entry
|
|
357
379
|
|
|
358
380
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
359
|
-
app: path$
|
|
381
|
+
app: path$b.resolve(process.cwd(), 'app')
|
|
360
382
|
}; // 默认从源码拷贝到编译后的配置
|
|
361
383
|
|
|
362
384
|
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
|
|
@@ -365,7 +387,7 @@ const ENV = {
|
|
|
365
387
|
prod: 'production'
|
|
366
388
|
};
|
|
367
389
|
const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
368
|
-
const MODULE_CONFIG_INVALID_KEY
|
|
390
|
+
const MODULE_CONFIG_INVALID_KEY = ['entranceDeclare', 'entryPagePath'];
|
|
369
391
|
|
|
370
392
|
var constant = /*#__PURE__*/Object.freeze({
|
|
371
393
|
__proto__: null,
|
|
@@ -377,20 +399,20 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
377
399
|
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
|
|
378
400
|
TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME$1,
|
|
379
401
|
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
|
|
380
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$
|
|
402
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
381
403
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
382
404
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
383
405
|
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
384
406
|
ENV: ENV,
|
|
385
407
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
386
|
-
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY
|
|
408
|
+
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY,
|
|
387
409
|
DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
|
|
388
410
|
});
|
|
389
411
|
|
|
390
412
|
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
391
413
|
|
|
392
|
-
const fs$
|
|
393
|
-
const path$
|
|
414
|
+
const fs$c = require$$0__default$2;
|
|
415
|
+
const path$a = require$$1__default$2;
|
|
394
416
|
const {
|
|
395
417
|
info: info$7
|
|
396
418
|
} = log$1;
|
|
@@ -403,12 +425,12 @@ const {
|
|
|
403
425
|
* @returns
|
|
404
426
|
*/
|
|
405
427
|
|
|
406
|
-
const isDirEmpty = dirname => fs$
|
|
428
|
+
const isDirEmpty = dirname => fs$c.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
407
429
|
|
|
408
430
|
|
|
409
431
|
const isFile = pathName => {
|
|
410
432
|
try {
|
|
411
|
-
const stat = fs$
|
|
433
|
+
const stat = fs$c.lstatSync(pathName);
|
|
412
434
|
return stat.isFile();
|
|
413
435
|
} catch {
|
|
414
436
|
return false;
|
|
@@ -420,9 +442,9 @@ const isFile = pathName => {
|
|
|
420
442
|
*/
|
|
421
443
|
|
|
422
444
|
|
|
423
|
-
const ensureDirExist = dirname => {
|
|
424
|
-
if (!fs$
|
|
425
|
-
fs$
|
|
445
|
+
const ensureDirExist$1 = dirname => {
|
|
446
|
+
if (!fs$c.existsSync(dirname)) {
|
|
447
|
+
fs$c.mkdirSync(dirname, {
|
|
426
448
|
recursive: true
|
|
427
449
|
});
|
|
428
450
|
}
|
|
@@ -430,20 +452,20 @@ const ensureDirExist = dirname => {
|
|
|
430
452
|
|
|
431
453
|
|
|
432
454
|
const copyFile = function (src, dest) {
|
|
433
|
-
if (fs$
|
|
434
|
-
fs$
|
|
455
|
+
if (fs$c.existsSync(dest)) {
|
|
456
|
+
fs$c.unlinkSync(dest);
|
|
435
457
|
}
|
|
436
458
|
|
|
437
|
-
const dir = path$
|
|
438
|
-
ensureDirExist(dir);
|
|
439
|
-
fs$
|
|
459
|
+
const dir = path$a.dirname(dest);
|
|
460
|
+
ensureDirExist$1(dir);
|
|
461
|
+
fs$c.copyFileSync(src, dest);
|
|
440
462
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
441
463
|
|
|
442
464
|
|
|
443
465
|
function diffContentCopyFile$3(originFile, destFile) {
|
|
444
|
-
if (fs$
|
|
445
|
-
const depDestContent = fs$
|
|
446
|
-
const depOriginContent = fs$
|
|
466
|
+
if (fs$c.existsSync(destFile)) {
|
|
467
|
+
const depDestContent = fs$c.readFileSync(destFile, 'utf8');
|
|
468
|
+
const depOriginContent = fs$c.readFileSync(originFile, 'utf8');
|
|
447
469
|
|
|
448
470
|
if (depDestContent !== depOriginContent) {
|
|
449
471
|
info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
@@ -461,7 +483,7 @@ function ext$3(filePath, extensions) {
|
|
|
461
483
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
462
484
|
|
|
463
485
|
try {
|
|
464
|
-
const stat = fs$
|
|
486
|
+
const stat = fs$c.lstatSync(newFilePath);
|
|
465
487
|
|
|
466
488
|
if (stat.isDirectory()) {
|
|
467
489
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -472,7 +494,7 @@ function ext$3(filePath, extensions) {
|
|
|
472
494
|
for (const ext of extensions) {
|
|
473
495
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
474
496
|
|
|
475
|
-
if (fs$
|
|
497
|
+
if (fs$c.existsSync(file)) {
|
|
476
498
|
return {
|
|
477
499
|
ext,
|
|
478
500
|
extPath: extPath + ext,
|
|
@@ -490,11 +512,11 @@ function ext$3(filePath, extensions) {
|
|
|
490
512
|
|
|
491
513
|
|
|
492
514
|
const fileInDir$3 = (dir, file) => {
|
|
493
|
-
if (!fs$
|
|
515
|
+
if (!fs$c.existsSync(dir) || !fs$c.existsSync(file)) {
|
|
494
516
|
return false;
|
|
495
517
|
}
|
|
496
518
|
|
|
497
|
-
const relativePath = path$
|
|
519
|
+
const relativePath = path$a.relative(dir, file);
|
|
498
520
|
|
|
499
521
|
if (relativePath.startsWith('..')) {
|
|
500
522
|
return false;
|
|
@@ -503,18 +525,41 @@ const fileInDir$3 = (dir, file) => {
|
|
|
503
525
|
return true;
|
|
504
526
|
};
|
|
505
527
|
|
|
506
|
-
|
|
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 = {
|
|
507
551
|
isDirEmpty,
|
|
508
552
|
copyFile,
|
|
509
553
|
diffContentCopyFile: diffContentCopyFile$3,
|
|
510
|
-
ensureDirExist,
|
|
554
|
+
ensureDirExist: ensureDirExist$1,
|
|
511
555
|
ext: ext$3,
|
|
512
556
|
fileInDir: fileInDir$3,
|
|
513
|
-
isFile
|
|
557
|
+
isFile,
|
|
558
|
+
findAllFilesOfDir: findAllFilesOfDir$1
|
|
514
559
|
};
|
|
515
560
|
|
|
516
561
|
const async = require$$0__default$4;
|
|
517
|
-
const ejs = require$$1__default$
|
|
562
|
+
const ejs = require$$1__default$3;
|
|
518
563
|
|
|
519
564
|
const render$1 = (files, metalsmith, next) => {
|
|
520
565
|
const keys = Object.keys(files);
|
|
@@ -533,8 +578,8 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
533
578
|
|
|
534
579
|
var render_1 = render$1;
|
|
535
580
|
|
|
536
|
-
const fs$
|
|
537
|
-
const inquirer = require$$1__default$
|
|
581
|
+
const fs$b = require$$0__default$2;
|
|
582
|
+
const inquirer = require$$1__default$4;
|
|
538
583
|
const {
|
|
539
584
|
resolve: resolve$d
|
|
540
585
|
} = widgets;
|
|
@@ -550,12 +595,12 @@ const {
|
|
|
550
595
|
const parseTemplateQuestions = dir => {
|
|
551
596
|
let prompts = [];
|
|
552
597
|
|
|
553
|
-
if (!fs$
|
|
598
|
+
if (!fs$b.existsSync(`${dir}/questions.json`)) {
|
|
554
599
|
return prompts;
|
|
555
600
|
}
|
|
556
601
|
|
|
557
602
|
try {
|
|
558
|
-
const json = JSON.parse(fs$
|
|
603
|
+
const json = JSON.parse(fs$b.readFileSync(`${dir}/questions.json`));
|
|
559
604
|
|
|
560
605
|
if (Array.isArray(json) && json.length > 0) {
|
|
561
606
|
json.forEach((item, index) => {
|
|
@@ -630,9 +675,9 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
630
675
|
|
|
631
676
|
var generator_1 = generator$1;
|
|
632
677
|
|
|
633
|
-
const path$
|
|
634
|
-
const fs$
|
|
635
|
-
const shelljs$
|
|
678
|
+
const path$9 = require$$1__default$2;
|
|
679
|
+
const fs$a = require$$0__default$2;
|
|
680
|
+
const shelljs$6 = require$$0__default$3;
|
|
636
681
|
const {
|
|
637
682
|
TEMPLATE_DIR,
|
|
638
683
|
TEMPLATE_PATH,
|
|
@@ -643,10 +688,10 @@ const {
|
|
|
643
688
|
createTask: createTask$2,
|
|
644
689
|
resolve: resolve$c
|
|
645
690
|
} = widgets;
|
|
646
|
-
const io$
|
|
691
|
+
const io$2 = io$3;
|
|
647
692
|
const {
|
|
648
693
|
fail: fail$7,
|
|
649
|
-
succeed,
|
|
694
|
+
succeed: succeed$1,
|
|
650
695
|
info: info$6
|
|
651
696
|
} = log$1;
|
|
652
697
|
const generator = generator_1;
|
|
@@ -658,13 +703,13 @@ const generator = generator_1;
|
|
|
658
703
|
|
|
659
704
|
async function createAppDir(targetDir) {
|
|
660
705
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
661
|
-
if (fs$
|
|
662
|
-
if (!(await io$
|
|
706
|
+
if (fs$a.existsSync(targetDir)) {
|
|
707
|
+
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
663
708
|
fail$7('该目录名已经存在,换个项目名字吧~');
|
|
664
709
|
process.exit(1);
|
|
665
710
|
}
|
|
666
711
|
} else {
|
|
667
|
-
shelljs$
|
|
712
|
+
shelljs$6.mkdir('-p', targetDir);
|
|
668
713
|
}
|
|
669
714
|
}
|
|
670
715
|
/**
|
|
@@ -676,36 +721,36 @@ async function createAppDir(targetDir) {
|
|
|
676
721
|
|
|
677
722
|
async function create(appName) {
|
|
678
723
|
const cwd = process.cwd();
|
|
679
|
-
const targetDir = path$
|
|
724
|
+
const targetDir = path$9.resolve(cwd, appName);
|
|
680
725
|
const appType = 'mp';
|
|
681
726
|
await createAppDir(targetDir); // 创建缓存目录
|
|
682
727
|
|
|
683
|
-
io$
|
|
728
|
+
io$2.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
|
|
684
729
|
|
|
685
730
|
await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
686
731
|
|
|
687
|
-
generator(path$
|
|
732
|
+
generator(path$9.join(TEMPLATE_PATH, appType), targetDir, {
|
|
688
733
|
appName,
|
|
689
734
|
appType
|
|
690
735
|
}).then(() => {
|
|
691
|
-
shelljs$
|
|
736
|
+
shelljs$6.cd(appName);
|
|
692
737
|
|
|
693
738
|
const hooks = require(resolve$c(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
694
739
|
|
|
695
740
|
if (hooks.afterCreate) {
|
|
696
741
|
hooks.afterCreate.forEach(item => {
|
|
697
742
|
if (typeof item === 'function') {
|
|
698
|
-
item.call(null, shelljs$
|
|
743
|
+
item.call(null, shelljs$6, {
|
|
699
744
|
appName
|
|
700
745
|
});
|
|
701
746
|
} else {
|
|
702
|
-
shelljs$
|
|
747
|
+
shelljs$6.exec(item);
|
|
703
748
|
}
|
|
704
749
|
});
|
|
705
750
|
}
|
|
706
751
|
|
|
707
|
-
shelljs$
|
|
708
|
-
succeed('项目创建完成.');
|
|
752
|
+
shelljs$6.rm('-rf', resolve$c(appName, TEMPLATE_TKIT_DIR));
|
|
753
|
+
succeed$1('项目创建完成.');
|
|
709
754
|
}).catch(err => {
|
|
710
755
|
fail$7(err.message);
|
|
711
756
|
info$6('详细的错误信息:', err);
|
|
@@ -714,6 +759,8 @@ async function create(appName) {
|
|
|
714
759
|
|
|
715
760
|
var create_1 = create;
|
|
716
761
|
|
|
762
|
+
var buildAppJson = {exports: {}};
|
|
763
|
+
|
|
717
764
|
var defaultTmsConfig$1 = {
|
|
718
765
|
// 全局的环境配置项
|
|
719
766
|
envData: {},
|
|
@@ -737,22 +784,22 @@ var defaultTmsConfig$1 = {
|
|
|
737
784
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
738
785
|
*/
|
|
739
786
|
const loadash = require$$0__default$6;
|
|
740
|
-
const fs$
|
|
787
|
+
const fs$9 = require$$0__default$2;
|
|
741
788
|
const {
|
|
742
789
|
TMS_CONFIG_FILENAME,
|
|
743
|
-
MODULE_CONFIG_FILENAME
|
|
790
|
+
MODULE_CONFIG_FILENAME,
|
|
744
791
|
TMS_PRIVATE_FILENAME
|
|
745
792
|
} = require$$4;
|
|
746
793
|
const {
|
|
747
794
|
resolve: resolve$b,
|
|
748
|
-
isObject
|
|
795
|
+
isObject,
|
|
749
796
|
isArray
|
|
750
797
|
} = widgets;
|
|
751
798
|
const defaultTmsConfig = defaultTmsConfig$1;
|
|
752
799
|
const {
|
|
753
800
|
fail: fail$6
|
|
754
801
|
} = log$1;
|
|
755
|
-
const path$
|
|
802
|
+
const path$8 = require$$1__default$2;
|
|
756
803
|
/**
|
|
757
804
|
* 读取tms.config.js
|
|
758
805
|
* @param env {string} 环境变量
|
|
@@ -761,7 +808,7 @@ const path$7 = require$$3__default;
|
|
|
761
808
|
const readTmsConfig$1 = function (env) {
|
|
762
809
|
const tmsConfigPath = resolve$b(TMS_CONFIG_FILENAME);
|
|
763
810
|
|
|
764
|
-
if (!fs$
|
|
811
|
+
if (!fs$9.existsSync(tmsConfigPath)) {
|
|
765
812
|
fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
766
813
|
process.exit(1);
|
|
767
814
|
}
|
|
@@ -787,14 +834,14 @@ const convertModules = modules => {
|
|
|
787
834
|
if (typeof module === 'string') {
|
|
788
835
|
// 路径字符串
|
|
789
836
|
Object.assign(newModule, {
|
|
790
|
-
name: path$
|
|
837
|
+
name: path$8.basename(module),
|
|
791
838
|
path: module
|
|
792
839
|
});
|
|
793
840
|
} else if (typeof module === 'object') {
|
|
794
841
|
Object.assign(newModule, module);
|
|
795
842
|
|
|
796
843
|
if (module.name === undefined) {
|
|
797
|
-
newModule.name = path$
|
|
844
|
+
newModule.name = path$8.basename(module.path);
|
|
798
845
|
}
|
|
799
846
|
}
|
|
800
847
|
|
|
@@ -811,7 +858,7 @@ const readTmsPrivateCf$1 = function () {
|
|
|
811
858
|
let tmsPrivateCf = {};
|
|
812
859
|
const tmsPrivatePath = resolve$b(TMS_PRIVATE_FILENAME);
|
|
813
860
|
|
|
814
|
-
if (fs$
|
|
861
|
+
if (fs$9.existsSync(tmsPrivatePath)) {
|
|
815
862
|
tmsPrivateCf = require(tmsPrivatePath);
|
|
816
863
|
} // 处理modules字段
|
|
817
864
|
|
|
@@ -847,18 +894,6 @@ const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
|
|
|
847
894
|
|
|
848
895
|
return targetModules;
|
|
849
896
|
};
|
|
850
|
-
/**
|
|
851
|
-
* 过滤页面为空的分包
|
|
852
|
-
* @param {Array} moduleCfg 模块配置内容
|
|
853
|
-
* @returns pages不为空的分包
|
|
854
|
-
*/
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
const getValidModules$1 = moduleCfg => {
|
|
858
|
-
// 过滤 pages 为空的情况
|
|
859
|
-
const validModules = moduleCfg.filter(item => item.pages.length > 0);
|
|
860
|
-
return validModules;
|
|
861
|
-
};
|
|
862
897
|
/**
|
|
863
898
|
* 适配处理module.config.json的字段
|
|
864
899
|
* @param { object } fileContent module.config.json的内容
|
|
@@ -867,25 +902,39 @@ const getValidModules$1 = moduleCfg => {
|
|
|
867
902
|
|
|
868
903
|
|
|
869
904
|
function adaptMpCgContent(fileContent, appName) {
|
|
870
|
-
const
|
|
905
|
+
const handleContent = function (appName, current) {
|
|
906
|
+
let res = current;
|
|
907
|
+
|
|
908
|
+
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
909
|
+
res = { ...current,
|
|
910
|
+
...current.mpConfig[appName]
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
delete res.mpConfig;
|
|
915
|
+
delete res.isSubpackages;
|
|
916
|
+
return res;
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
let content = JSON.parse(fileContent);
|
|
871
920
|
|
|
872
921
|
if (isArray(content)) {
|
|
873
922
|
let i = content.length - 1;
|
|
874
923
|
|
|
875
924
|
while (i >= 0) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
879
|
-
current = { ...current,
|
|
880
|
-
...current.mpConfig[appName]
|
|
881
|
-
};
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
delete current.mpConfig;
|
|
885
|
-
delete current.isSubpackages;
|
|
886
|
-
content[i] = current;
|
|
925
|
+
content[i] = handleContent(appName, content[i]);
|
|
887
926
|
i--; // eslint-disable-line
|
|
888
927
|
}
|
|
928
|
+
} else {
|
|
929
|
+
if (appName && content.mpConfig && content.mpConfig[appName]) {
|
|
930
|
+
content = { ...content,
|
|
931
|
+
...content.mpConfig[appName]
|
|
932
|
+
};
|
|
933
|
+
delete content.mpConfig;
|
|
934
|
+
delete content.isSubpackages;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
content = handleContent(appName, content);
|
|
889
938
|
}
|
|
890
939
|
|
|
891
940
|
return content;
|
|
@@ -898,15 +947,15 @@ function adaptMpCgContent(fileContent, appName) {
|
|
|
898
947
|
*/
|
|
899
948
|
|
|
900
949
|
|
|
901
|
-
function getModuleConfig
|
|
950
|
+
function getModuleConfig(modules = [], appName, moduleConfigFilename) {
|
|
902
951
|
const modulesConfig = {};
|
|
903
952
|
modules.forEach(({
|
|
904
953
|
path
|
|
905
954
|
}) => {
|
|
906
955
|
const moduleConfigPath = resolve$b(path, moduleConfigFilename);
|
|
907
956
|
|
|
908
|
-
if (fs$
|
|
909
|
-
const content = fs$
|
|
957
|
+
if (fs$9.existsSync(moduleConfigPath)) {
|
|
958
|
+
const content = fs$9.readFileSync(moduleConfigPath, 'utf-8');
|
|
910
959
|
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
911
960
|
}
|
|
912
961
|
});
|
|
@@ -927,15 +976,15 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
927
976
|
path: relativePath,
|
|
928
977
|
name: moduleName
|
|
929
978
|
}, moduleIndex) => {
|
|
930
|
-
const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME
|
|
979
|
+
const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME);
|
|
931
980
|
|
|
932
|
-
if (fs$
|
|
981
|
+
if (fs$9.existsSync(moduleConfigPath)) {
|
|
933
982
|
try {
|
|
934
983
|
let findModule = false;
|
|
935
|
-
let moduleConfigContent = fs$
|
|
984
|
+
let moduleConfigContent = fs$9.readFileSync(moduleConfigPath, 'utf-8');
|
|
936
985
|
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
937
|
-
const moduleContentArr = isObject
|
|
938
|
-
|
|
986
|
+
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
987
|
+
moduleContentArr.forEach(({
|
|
939
988
|
name
|
|
940
989
|
}, moduleContentArrIndex) => {
|
|
941
990
|
if (name === moduleName) {
|
|
@@ -947,7 +996,7 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
947
996
|
});
|
|
948
997
|
|
|
949
998
|
if (!findModule) {
|
|
950
|
-
fail$6(`启动模块${moduleName}在${moduleConfigPath}
|
|
999
|
+
fail$6(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
|
|
951
1000
|
process.exit(1);
|
|
952
1001
|
}
|
|
953
1002
|
} catch (e) {
|
|
@@ -1003,8 +1052,7 @@ const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
|
|
|
1003
1052
|
var tmsMpconfig = {
|
|
1004
1053
|
readTmsConfig: readTmsConfig$1,
|
|
1005
1054
|
readTmsPrivateCf: readTmsPrivateCf$1,
|
|
1006
|
-
getModuleConfig
|
|
1007
|
-
getValidModules: getValidModules$1,
|
|
1055
|
+
getModuleConfig,
|
|
1008
1056
|
checkModules: checkModules$1,
|
|
1009
1057
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
1010
1058
|
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
@@ -1042,7 +1090,7 @@ const {
|
|
|
1042
1090
|
global: global$5
|
|
1043
1091
|
} = global_1;
|
|
1044
1092
|
|
|
1045
|
-
function handleError$
|
|
1093
|
+
function handleError$5(error) {
|
|
1046
1094
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1047
1095
|
const isDev = global$5.getData('isDev');
|
|
1048
1096
|
|
|
@@ -1055,231 +1103,236 @@ function handleError$4(error) {
|
|
|
1055
1103
|
}
|
|
1056
1104
|
|
|
1057
1105
|
var handleError_1 = {
|
|
1058
|
-
handleError: handleError$
|
|
1106
|
+
handleError: handleError$5
|
|
1059
1107
|
};
|
|
1060
1108
|
|
|
1061
1109
|
/**
|
|
1062
1110
|
* 生成编译后的app.json
|
|
1063
1111
|
*/
|
|
1064
|
-
const fs$7 = require$$0__default$2;
|
|
1065
|
-
const {
|
|
1066
|
-
MODULE_CONFIG_FILENAME,
|
|
1067
|
-
MODULE_CONFIG_INVALID_KEY
|
|
1068
|
-
} = require$$4;
|
|
1069
|
-
const {
|
|
1070
|
-
getModuleConfig,
|
|
1071
|
-
getValidModules
|
|
1072
|
-
} = tmsMpconfig;
|
|
1073
|
-
const {
|
|
1074
|
-
fail: fail$4
|
|
1075
|
-
} = log$1;
|
|
1076
|
-
const {
|
|
1077
|
-
resolve: resolve$a,
|
|
1078
|
-
isObject
|
|
1079
|
-
} = widgets;
|
|
1080
|
-
const {
|
|
1081
|
-
handleError: handleError$3
|
|
1082
|
-
} = handleError_1;
|
|
1083
|
-
/**
|
|
1084
|
-
* 更新appJson里面的主包配置
|
|
1085
|
-
* @param { object } appJson appJson信息
|
|
1086
|
-
* @param { array } mainPackages 小程序主包信息
|
|
1087
|
-
* @returns { object } appJson小程序主页配置信息
|
|
1088
|
-
*/
|
|
1089
|
-
|
|
1090
|
-
function updateMainPackages(appJson, mainPackages = []) {
|
|
1091
|
-
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1092
|
-
|
|
1093
|
-
if (foundMainPackages.length === 0) {
|
|
1094
|
-
// 没找到主包
|
|
1095
|
-
foundMainPackages = [appJson.subpackages[0]];
|
|
1096
|
-
} // 拼装 app.pages
|
|
1097
1112
|
|
|
1113
|
+
(function (module) {
|
|
1114
|
+
/* eslint-disable no-param-reassign */
|
|
1115
|
+
const fs = require$$0__default$2;
|
|
1116
|
+
const {
|
|
1117
|
+
MODULE_CONFIG_FILENAME,
|
|
1118
|
+
MODULE_CONFIG_INVALID_KEY
|
|
1119
|
+
} = require$$4;
|
|
1120
|
+
const {
|
|
1121
|
+
getModuleConfig
|
|
1122
|
+
} = tmsMpconfig;
|
|
1123
|
+
const {
|
|
1124
|
+
fail
|
|
1125
|
+
} = log$1;
|
|
1126
|
+
const {
|
|
1127
|
+
resolve,
|
|
1128
|
+
isObject
|
|
1129
|
+
} = widgets;
|
|
1130
|
+
const {
|
|
1131
|
+
handleError
|
|
1132
|
+
} = handleError_1;
|
|
1133
|
+
const {
|
|
1134
|
+
global
|
|
1135
|
+
} = global_1;
|
|
1136
|
+
/**
|
|
1137
|
+
* 更新appJson里面的主包配置
|
|
1138
|
+
* @param { object } appJson appJson信息
|
|
1139
|
+
* @param { array } mainPackages 小程序主包信息
|
|
1140
|
+
* @returns { object } appJson小程序主页配置信息
|
|
1141
|
+
*/
|
|
1098
1142
|
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
fail$4(`主包 ${subpackage} 不能没有 pages`);
|
|
1102
|
-
process.exit(-1);
|
|
1103
|
-
}
|
|
1143
|
+
function updateMainPackages(appJson, mainPackages = []) {
|
|
1144
|
+
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1104
1145
|
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1146
|
+
if (foundMainPackages.length === 0) {
|
|
1147
|
+
// 没找到主包
|
|
1148
|
+
foundMainPackages = [appJson.subpackages[0]];
|
|
1149
|
+
} // 拼装 app.pages
|
|
1108
1150
|
|
|
1109
|
-
if (subpackage.plugins) {
|
|
1110
|
-
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1111
|
-
}
|
|
1112
|
-
}); // 去掉 subpackages 中的主包配置
|
|
1113
1151
|
|
|
1114
|
-
|
|
1152
|
+
foundMainPackages.forEach(subpackage => {
|
|
1153
|
+
if (!subpackage.pages || !subpackage.pages.length) {
|
|
1154
|
+
fail(`主包 ${subpackage} 不能没有 pages`);
|
|
1155
|
+
process.exit(-1);
|
|
1156
|
+
}
|
|
1115
1157
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* 获取app.json内容
|
|
1121
|
-
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1122
|
-
* @returns
|
|
1123
|
-
*/
|
|
1158
|
+
subpackage.pages.forEach(page => {
|
|
1159
|
+
appJson.pages.push(`${subpackage.root}/${page}`);
|
|
1160
|
+
});
|
|
1124
1161
|
|
|
1162
|
+
if (subpackage.plugins) {
|
|
1163
|
+
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1164
|
+
}
|
|
1165
|
+
}); // 去掉 subpackages 中的主包配置
|
|
1125
1166
|
|
|
1126
|
-
const
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
process.exit(1);
|
|
1167
|
+
const foundMainPackageNames = foundMainPackages.map(item => item.name);
|
|
1168
|
+
appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
|
|
1169
|
+
return appJson;
|
|
1130
1170
|
}
|
|
1171
|
+
/**
|
|
1172
|
+
* 获取app.json内容
|
|
1173
|
+
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1174
|
+
* @returns
|
|
1175
|
+
*/
|
|
1131
1176
|
|
|
1132
|
-
const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1133
1177
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1178
|
+
const getAppJsonContent = sourceAppJsonPath => {
|
|
1179
|
+
if (!fs.existsSync(sourceAppJsonPath)) {
|
|
1180
|
+
fail(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1181
|
+
process.exit(1);
|
|
1182
|
+
}
|
|
1136
1183
|
|
|
1137
|
-
|
|
1138
|
-
return appJson;
|
|
1139
|
-
};
|
|
1140
|
-
/**
|
|
1141
|
-
* 更新app.json中的subpackages
|
|
1142
|
-
* @param {Object} appJson
|
|
1143
|
-
* @param {Object} modulesConfig
|
|
1144
|
-
*/
|
|
1184
|
+
const appJson = JSON.parse(fs.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1145
1185
|
|
|
1186
|
+
appJson.subpackages = [];
|
|
1187
|
+
appJson.pages = []; // appJson.plugins = {};
|
|
1146
1188
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1189
|
+
delete appJson.entranceDeclare;
|
|
1190
|
+
return appJson;
|
|
1191
|
+
};
|
|
1192
|
+
/**
|
|
1193
|
+
* 更新app.json中的subpackages
|
|
1194
|
+
* @param {Object} appJson
|
|
1195
|
+
* @param {Object} modulesConfigs
|
|
1196
|
+
*/
|
|
1151
1197
|
|
|
1152
|
-
const validModules = getValidModules(moduleInfo); // eslint-disable-next-line
|
|
1153
1198
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
*/
|
|
1199
|
+
const updateSubpackages = (appJson, modulesConfigs) => {
|
|
1200
|
+
// eslint-disable-next-line
|
|
1201
|
+
for (const modulePath in modulesConfigs) {
|
|
1202
|
+
const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
|
|
1203
|
+
appJson.subpackages = appJson.subpackages.concat(moduleInfo);
|
|
1204
|
+
}
|
|
1161
1205
|
|
|
1206
|
+
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
1207
|
+
};
|
|
1208
|
+
/**
|
|
1209
|
+
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1210
|
+
* @param {Object} appJson appjson
|
|
1211
|
+
*/
|
|
1162
1212
|
|
|
1163
|
-
const fixAppJson = appJson => {
|
|
1164
|
-
const {
|
|
1165
|
-
subpackages
|
|
1166
|
-
} = appJson;
|
|
1167
|
-
const pluginsMap = {};
|
|
1168
|
-
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1169
|
-
const subps = subpackages.map(subp => {
|
|
1170
|
-
const invalidKeys = [];
|
|
1171
|
-
Object.keys(subp).forEach(key => {
|
|
1172
|
-
if (key === 'dependencies') {
|
|
1173
|
-
// eslint-disable-next-line
|
|
1174
|
-
delete subp.dependencies;
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
1213
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1214
|
+
const fixAppJson = appJson => {
|
|
1215
|
+
const {
|
|
1216
|
+
subpackages
|
|
1217
|
+
} = appJson;
|
|
1218
|
+
const pluginsMap = {};
|
|
1219
|
+
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1220
|
+
const subps = subpackages.map(subp => {
|
|
1221
|
+
const invalidKeys = [];
|
|
1222
|
+
Object.keys(subp).forEach(key => {
|
|
1223
|
+
if (key === 'dependencies') {
|
|
1224
|
+
// eslint-disable-next-line
|
|
1225
|
+
delete subp.dependencies;
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1184
1228
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1229
|
+
if (key === 'plugins') {
|
|
1230
|
+
Object.keys(subp.plugins).forEach(pk => {
|
|
1231
|
+
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
1232
|
+
});
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1190
1235
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1236
|
+
if (MODULE_CONFIG_INVALID_KEY.indexOf(key) > -1) {
|
|
1237
|
+
// 如果分包配置中有不支持的key,则错误提醒
|
|
1238
|
+
invalidKeys.push(key);
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1194
1241
|
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1242
|
+
if (['requiredBackgroundModes', 'embeddedAppIdList'].indexOf(key) > -1) {
|
|
1243
|
+
// 提到appjson最上层处理
|
|
1244
|
+
const preVal = appJson[key];
|
|
1245
|
+
preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
if (invalidKeys.length) {
|
|
1251
|
+
fail(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
1198
1252
|
}
|
|
1199
|
-
});
|
|
1200
1253
|
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
} //
|
|
1254
|
+
invalidKeys.concat(['requiredBackgroundModes', 'embeddedAppIdList']).forEach(k => delete subp[k]);
|
|
1255
|
+
return subp;
|
|
1256
|
+
}); // 如果plugins重复,则错误提示
|
|
1204
1257
|
|
|
1258
|
+
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
1259
|
+
if (pluginsMap[pk].length > 1) {
|
|
1260
|
+
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
1261
|
+
}
|
|
1205
1262
|
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
}); // 如果plugins重复,则错误提示
|
|
1263
|
+
return '';
|
|
1264
|
+
}).reduce((pre, cur) => pre + cur, '');
|
|
1209
1265
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
1266
|
+
if (pluginsErrMsg) {
|
|
1267
|
+
fail(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1213
1268
|
}
|
|
1214
1269
|
|
|
1215
|
-
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1270
|
+
appJson.subpackages = subps;
|
|
1271
|
+
};
|
|
1272
|
+
/**
|
|
1273
|
+
* 动态生成编译后的app.json
|
|
1274
|
+
* @param {object} tmsConfig
|
|
1275
|
+
* @param {array} modules 用户要编译的模块列表
|
|
1276
|
+
* @returns
|
|
1277
|
+
*/
|
|
1222
1278
|
|
|
1223
|
-
appJson.subpackages = subps;
|
|
1224
|
-
};
|
|
1225
|
-
/**
|
|
1226
|
-
* 动态生成编译后的app.json
|
|
1227
|
-
* @param {object} tmsConfig
|
|
1228
|
-
* @param {array} modules 用户要编译的模块列表
|
|
1229
|
-
* @returns
|
|
1230
|
-
*/
|
|
1231
1279
|
|
|
1280
|
+
function buildOutputAppJson(tmsConfig, modules) {
|
|
1281
|
+
try {
|
|
1282
|
+
var _tmsConfig$hooks;
|
|
1232
1283
|
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
var _tmsConfig$hooks;
|
|
1284
|
+
// 获取当前 modules 下的所有子模块的配置内容
|
|
1285
|
+
const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1236
1286
|
|
|
1237
|
-
|
|
1238
|
-
const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1287
|
+
const appJson = getAppJsonContent(resolve('./app.json')); // 更新app.json中的subpackages
|
|
1239
1288
|
|
|
1240
|
-
|
|
1289
|
+
updateSubpackages(appJson, modulesConfigs); // 处理appJson中重复||冲突的地方
|
|
1241
1290
|
|
|
1242
|
-
|
|
1291
|
+
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1243
1292
|
|
|
1244
|
-
|
|
1293
|
+
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1294
|
+
fs.writeFileSync(resolve(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1245
1295
|
|
|
1246
|
-
|
|
1247
|
-
|
|
1296
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1297
|
+
var _tmsConfig$hooks2;
|
|
1248
1298
|
|
|
1249
|
-
|
|
1250
|
-
|
|
1299
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1300
|
+
tmsConfig,
|
|
1301
|
+
module,
|
|
1302
|
+
appJson,
|
|
1303
|
+
isDev: global.getData('isDev')
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1251
1306
|
|
|
1252
|
-
|
|
1307
|
+
return appJson;
|
|
1308
|
+
} catch (e) {
|
|
1309
|
+
handleError(`生成app.json出现错误: ${e}`);
|
|
1253
1310
|
}
|
|
1254
|
-
|
|
1255
|
-
return appJson;
|
|
1256
|
-
} catch (e) {
|
|
1257
|
-
handleError$3(`生成app.json出现错误: ${e}`);
|
|
1258
1311
|
}
|
|
1259
|
-
}
|
|
1260
1312
|
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
};
|
|
1313
|
+
module.exports = {
|
|
1314
|
+
buildOutputAppJson
|
|
1315
|
+
};
|
|
1316
|
+
})(buildAppJson);
|
|
1264
1317
|
|
|
1265
1318
|
/**
|
|
1266
1319
|
* 下载第三方代码
|
|
1267
1320
|
*/
|
|
1268
1321
|
const MetalSmith = require$$0__default$5;
|
|
1269
|
-
const crypto$1 = require$$1__default$
|
|
1322
|
+
const crypto$1 = require$$1__default$5;
|
|
1270
1323
|
const {
|
|
1271
1324
|
downloadRepoForGit,
|
|
1272
1325
|
pullRepoForGit,
|
|
1273
|
-
resolve: resolve$
|
|
1326
|
+
resolve: resolve$a
|
|
1274
1327
|
} = widgets;
|
|
1275
1328
|
const {
|
|
1276
|
-
fail: fail$
|
|
1329
|
+
fail: fail$4,
|
|
1277
1330
|
info: info$5
|
|
1278
1331
|
} = log$1;
|
|
1279
|
-
const fs$
|
|
1280
|
-
const shelljs$
|
|
1332
|
+
const fs$8 = require$$0__default$2;
|
|
1333
|
+
const shelljs$5 = require$$0__default$3;
|
|
1281
1334
|
const {
|
|
1282
|
-
handleError: handleError$
|
|
1335
|
+
handleError: handleError$4
|
|
1283
1336
|
} = handleError_1;
|
|
1284
1337
|
const {
|
|
1285
1338
|
global: global$4
|
|
@@ -1323,7 +1376,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1323
1376
|
return new Promise((resolve, reject) => {
|
|
1324
1377
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1325
1378
|
if (e) {
|
|
1326
|
-
fail$
|
|
1379
|
+
fail$4(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1327
1380
|
reject(e);
|
|
1328
1381
|
}
|
|
1329
1382
|
|
|
@@ -1372,11 +1425,11 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1372
1425
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1373
1426
|
return Promise.all(callArr);
|
|
1374
1427
|
}).catch(e => {
|
|
1375
|
-
handleError$
|
|
1428
|
+
handleError$4(`下载代码${params.httpRepoUrl}出现错误:${e}`);
|
|
1376
1429
|
}));
|
|
1377
1430
|
});
|
|
1378
1431
|
await Promise.all(arrPromises);
|
|
1379
|
-
shelljs$
|
|
1432
|
+
shelljs$5.cd(cwd);
|
|
1380
1433
|
}
|
|
1381
1434
|
/**
|
|
1382
1435
|
* 收集下载模块代码的任务
|
|
@@ -1417,9 +1470,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1417
1470
|
|
|
1418
1471
|
const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
|
|
1419
1472
|
|
|
1420
|
-
const sourcePath = resolve$
|
|
1473
|
+
const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
|
|
1421
1474
|
|
|
1422
|
-
const targetPath = resolve$
|
|
1475
|
+
const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
|
|
1423
1476
|
|
|
1424
1477
|
const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
|
|
1425
1478
|
|
|
@@ -1429,8 +1482,8 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1429
1482
|
targetPath
|
|
1430
1483
|
},
|
|
1431
1484
|
fn: async (sourceModulePath, targetPath) => {
|
|
1432
|
-
if (fs$
|
|
1433
|
-
shelljs$
|
|
1485
|
+
if (fs$8.existsSync(targetPath)) {
|
|
1486
|
+
shelljs$5.rm('-rf', `${targetPath}/*`);
|
|
1434
1487
|
}
|
|
1435
1488
|
|
|
1436
1489
|
await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
|
|
@@ -1444,7 +1497,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1444
1497
|
} else {
|
|
1445
1498
|
let promiseTask;
|
|
1446
1499
|
|
|
1447
|
-
if (fs$
|
|
1500
|
+
if (fs$8.existsSync(sourcePath) && fs$8.existsSync(`${sourcePath}/.git`)) {
|
|
1448
1501
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1449
1502
|
info$5(`git pull:${httpRepoUrl}`);
|
|
1450
1503
|
return pullRepoForGit(sourcePath, branch);
|
|
@@ -1492,7 +1545,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
|
1492
1545
|
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
|
|
1493
1546
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1494
1547
|
|
|
1495
|
-
if (!fs$
|
|
1548
|
+
if (!fs$8.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1496
1549
|
return true;
|
|
1497
1550
|
}
|
|
1498
1551
|
}
|
|
@@ -1506,7 +1559,7 @@ var cloneModules_1 = {
|
|
|
1506
1559
|
};
|
|
1507
1560
|
|
|
1508
1561
|
const ci = require$$0__default$7;
|
|
1509
|
-
const path$
|
|
1562
|
+
const path$7 = require$$1__default$2;
|
|
1510
1563
|
/**
|
|
1511
1564
|
* 获取小程序ci的Project对象
|
|
1512
1565
|
* @returns {Object} 小程序ci对象
|
|
@@ -1520,7 +1573,7 @@ const getMpCi = ({
|
|
|
1520
1573
|
}) => {
|
|
1521
1574
|
var _cfgJsonContent$packO;
|
|
1522
1575
|
|
|
1523
|
-
const cfgJsonContent = require(path$
|
|
1576
|
+
const cfgJsonContent = require(path$7.join(projectPath, 'project.config.json'));
|
|
1524
1577
|
|
|
1525
1578
|
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
1526
1579
|
value
|
|
@@ -1589,10 +1642,10 @@ var mpCi = {
|
|
|
1589
1642
|
/**
|
|
1590
1643
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1591
1644
|
*/
|
|
1592
|
-
const fs$
|
|
1593
|
-
const fsExtra = require$$1__default$
|
|
1594
|
-
const crypto = require$$1__default$
|
|
1595
|
-
const path$
|
|
1645
|
+
const fs$7 = require$$0__default$2;
|
|
1646
|
+
const fsExtra = require$$1__default$6;
|
|
1647
|
+
const crypto = require$$1__default$5;
|
|
1648
|
+
const path$6 = require$$1__default$2;
|
|
1596
1649
|
const shell = require$$0__default$3;
|
|
1597
1650
|
const glob = require$$5__default;
|
|
1598
1651
|
const log = log$1;
|
|
@@ -1600,7 +1653,7 @@ const {
|
|
|
1600
1653
|
npmInstall
|
|
1601
1654
|
} = widgets;
|
|
1602
1655
|
const {
|
|
1603
|
-
handleError: handleError$
|
|
1656
|
+
handleError: handleError$3
|
|
1604
1657
|
} = handleError_1;
|
|
1605
1658
|
const shellJsOption = {
|
|
1606
1659
|
async: false,
|
|
@@ -1624,7 +1677,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1624
1677
|
const npmTasksMap = new Map();
|
|
1625
1678
|
|
|
1626
1679
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1627
|
-
const packageContent = fs$
|
|
1680
|
+
const packageContent = fs$7.readFileSync(packageJsonPath);
|
|
1628
1681
|
const packageJson = JSON.parse(packageContent);
|
|
1629
1682
|
const md5Obj = {
|
|
1630
1683
|
dependencies: packageJson.dependencies || {}
|
|
@@ -1632,14 +1685,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1632
1685
|
|
|
1633
1686
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1634
1687
|
const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1635
|
-
const cacheNMPath = path$
|
|
1636
|
-
const cacheNMTarFile = path$
|
|
1688
|
+
const cacheNMPath = path$6.join(cacheDir, md5Key);
|
|
1689
|
+
const cacheNMTarFile = path$6.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1637
1690
|
|
|
1638
1691
|
const callback = {
|
|
1639
1692
|
params: {
|
|
1640
1693
|
cacheNMPath,
|
|
1641
1694
|
cacheNMTarFile,
|
|
1642
|
-
packageJsonDir: path$
|
|
1695
|
+
packageJsonDir: path$6.dirname(packageJsonPath),
|
|
1643
1696
|
shell
|
|
1644
1697
|
},
|
|
1645
1698
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
@@ -1715,7 +1768,7 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
|
1715
1768
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1716
1769
|
return Promise.all(callArr);
|
|
1717
1770
|
}).catch(e => {
|
|
1718
|
-
handleError$
|
|
1771
|
+
handleError$3(`npm install ${params.packageJsonPath}出现错误:${e}`);
|
|
1719
1772
|
}));
|
|
1720
1773
|
});
|
|
1721
1774
|
await Promise.all(arrPromises);
|
|
@@ -1740,7 +1793,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1740
1793
|
|
|
1741
1794
|
const find = (startPath, filter) => {
|
|
1742
1795
|
// 目录不存在
|
|
1743
|
-
if (!fs$
|
|
1796
|
+
if (!fs$7.existsSync(startPath)) {
|
|
1744
1797
|
log.fail(`${startPath}目录不存在`);
|
|
1745
1798
|
process.exit(-1);
|
|
1746
1799
|
return;
|
|
@@ -1753,10 +1806,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1753
1806
|
return;
|
|
1754
1807
|
}
|
|
1755
1808
|
|
|
1756
|
-
const files = fs$
|
|
1809
|
+
const files = fs$7.readdirSync(startPath);
|
|
1757
1810
|
files.forEach(file => {
|
|
1758
|
-
const filename = path$
|
|
1759
|
-
const stat = fs$
|
|
1811
|
+
const filename = path$6.join(startPath, file);
|
|
1812
|
+
const stat = fs$7.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1760
1813
|
|
|
1761
1814
|
if (stat.isDirectory()) {
|
|
1762
1815
|
find(filename, filter);
|
|
@@ -1782,7 +1835,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1782
1835
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1783
1836
|
|
|
1784
1837
|
const cwd = contextDir || dirPath;
|
|
1785
|
-
const result = [path$
|
|
1838
|
+
const result = [path$6.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1786
1839
|
|
|
1787
1840
|
subRoots.forEach(subRoot => {
|
|
1788
1841
|
if (!subRoot.root) {
|
|
@@ -1790,7 +1843,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1790
1843
|
process.exit(1);
|
|
1791
1844
|
}
|
|
1792
1845
|
|
|
1793
|
-
const toppath = path$
|
|
1846
|
+
const toppath = path$6.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1794
1847
|
|
|
1795
1848
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1796
1849
|
result.push(...list);
|
|
@@ -1806,7 +1859,7 @@ function cloudNpmInstall(contextDir) {
|
|
|
1806
1859
|
}
|
|
1807
1860
|
|
|
1808
1861
|
files.forEach(file => {
|
|
1809
|
-
const dir = path$
|
|
1862
|
+
const dir = path$6.dirname(file);
|
|
1810
1863
|
shell.cd(dir);
|
|
1811
1864
|
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1812
1865
|
silent: false
|
|
@@ -1823,9 +1876,12 @@ var npm = {
|
|
|
1823
1876
|
findAllPackageJson
|
|
1824
1877
|
};
|
|
1825
1878
|
|
|
1879
|
+
const shelljs$4 = require$$0__default$3;
|
|
1880
|
+
const fs$6 = require$$0__default$2;
|
|
1881
|
+
const io$1 = io$3;
|
|
1826
1882
|
const {
|
|
1827
1883
|
createTask: createTask$1,
|
|
1828
|
-
resolve: resolve$
|
|
1884
|
+
resolve: resolve$9
|
|
1829
1885
|
} = widgets;
|
|
1830
1886
|
const {
|
|
1831
1887
|
buildMpNpm
|
|
@@ -1839,30 +1895,46 @@ const {
|
|
|
1839
1895
|
const {
|
|
1840
1896
|
global: global$3
|
|
1841
1897
|
} = global_1;
|
|
1898
|
+
const {
|
|
1899
|
+
fail: fail$3
|
|
1900
|
+
} = log$1;
|
|
1842
1901
|
|
|
1843
1902
|
async function install$2(tmsConfig, modules) {
|
|
1844
|
-
//
|
|
1845
|
-
|
|
1903
|
+
// 拷贝模块的package.json到编译输出目录
|
|
1904
|
+
modules.forEach(item => {
|
|
1905
|
+
const outputModuleDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
|
|
1906
|
+
|
|
1907
|
+
if (!fs$6.existsSync(resolve$9(item.path))) {
|
|
1908
|
+
fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1909
|
+
process.exit(1);
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
io$1.ensureDirExist(outputModuleDir);
|
|
1913
|
+
const modulePackagePath = resolve$9(item.path, 'package.json');
|
|
1914
|
+
if (fs$6.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1915
|
+
}); // 小程序npm install
|
|
1916
|
+
|
|
1917
|
+
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
1846
1918
|
const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1847
1919
|
|
|
1848
1920
|
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1849
1921
|
appId: tmsConfig.appId,
|
|
1850
|
-
projectPath: resolve$
|
|
1922
|
+
projectPath: resolve$9('./'),
|
|
1851
1923
|
privateKey: tmsPrivateCf.privateKey
|
|
1852
1924
|
});
|
|
1853
1925
|
}
|
|
1854
1926
|
|
|
1855
1927
|
var install_1 = install$2;
|
|
1856
1928
|
|
|
1857
|
-
const fs$
|
|
1858
|
-
const semver$1 = require$$1__default$
|
|
1929
|
+
const fs$5 = require$$0__default$2;
|
|
1930
|
+
const semver$1 = require$$1__default$7;
|
|
1859
1931
|
const {
|
|
1860
|
-
resolve: resolve$
|
|
1932
|
+
resolve: resolve$8
|
|
1861
1933
|
} = widgets;
|
|
1862
|
-
const path$
|
|
1934
|
+
const path$5 = require$$1__default$2;
|
|
1863
1935
|
const shelljs$3 = require$$0__default$3;
|
|
1864
1936
|
const {
|
|
1865
|
-
handleError
|
|
1937
|
+
handleError: handleError$2
|
|
1866
1938
|
} = handleError_1;
|
|
1867
1939
|
|
|
1868
1940
|
const getLatestVersion = npmName => {
|
|
@@ -1884,44 +1956,44 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
|
1884
1956
|
// 1.1根目录的package.json
|
|
1885
1957
|
|
|
1886
1958
|
const packageArr = [{
|
|
1887
|
-
srcPackageDir: path$
|
|
1888
|
-
destNpmDir: resolve$
|
|
1959
|
+
srcPackageDir: path$5.join(cwd, packageJsonName),
|
|
1960
|
+
destNpmDir: resolve$8(outputDir, 'node_modules')
|
|
1889
1961
|
}]; // 1.2模块的package.json
|
|
1890
1962
|
|
|
1891
1963
|
modules.forEach(item => {
|
|
1892
|
-
const srcPackageDir = path$
|
|
1964
|
+
const srcPackageDir = path$5.join(cwd, item.path, 'package.json');
|
|
1893
1965
|
|
|
1894
|
-
if (fs$
|
|
1966
|
+
if (fs$5.existsSync(srcPackageDir)) {
|
|
1895
1967
|
packageArr.push({
|
|
1896
1968
|
srcPackageDir,
|
|
1897
|
-
destNpmDir: resolve$
|
|
1969
|
+
destNpmDir: resolve$8(outputDir, item.root, 'node_modules')
|
|
1898
1970
|
});
|
|
1899
1971
|
}
|
|
1900
1972
|
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1901
1973
|
|
|
1902
1974
|
for (const item of packageArr) {
|
|
1903
|
-
const packageJson = fs$
|
|
1975
|
+
const packageJson = fs$5.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1904
1976
|
let dependencies = {};
|
|
1905
1977
|
|
|
1906
1978
|
try {
|
|
1907
1979
|
const json = JSON.parse(packageJson);
|
|
1908
1980
|
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
1909
1981
|
} catch (e) {
|
|
1910
|
-
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
1982
|
+
handleError$2(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
1911
1983
|
}
|
|
1912
1984
|
|
|
1913
1985
|
const dependenciesKeys = Object.keys(dependencies);
|
|
1914
1986
|
|
|
1915
1987
|
for (const key of dependenciesKeys) {
|
|
1916
|
-
const depPath = path$
|
|
1988
|
+
const depPath = path$5.join(item.destNpmDir, key);
|
|
1917
1989
|
|
|
1918
|
-
if (!fs$
|
|
1990
|
+
if (!fs$5.existsSync(depPath)) {
|
|
1919
1991
|
return true;
|
|
1920
1992
|
}
|
|
1921
1993
|
|
|
1922
|
-
const depPackagePath = path$
|
|
1994
|
+
const depPackagePath = path$5.join(depPath, 'package.json');
|
|
1923
1995
|
|
|
1924
|
-
if (fs$
|
|
1996
|
+
if (fs$5.existsSync(depPackagePath)) {
|
|
1925
1997
|
const packageData = require(depPackagePath);
|
|
1926
1998
|
|
|
1927
1999
|
if (dependencies[key] === 'latest') {
|
|
@@ -1947,15 +2019,15 @@ var checkDependencies_1 = {
|
|
|
1947
2019
|
};
|
|
1948
2020
|
|
|
1949
2021
|
const shelljs$2 = require$$0__default$3;
|
|
1950
|
-
const fs$
|
|
1951
|
-
const io = io$
|
|
2022
|
+
const fs$4 = require$$0__default$2;
|
|
2023
|
+
const io = io$3;
|
|
1952
2024
|
const {
|
|
1953
|
-
resolve: resolve$
|
|
2025
|
+
resolve: resolve$7,
|
|
1954
2026
|
createTask
|
|
1955
2027
|
} = widgets;
|
|
1956
2028
|
const {
|
|
1957
2029
|
buildOutputAppJson
|
|
1958
|
-
} = buildAppJson;
|
|
2030
|
+
} = buildAppJson.exports;
|
|
1959
2031
|
const {
|
|
1960
2032
|
MODULE_CODE_DIR,
|
|
1961
2033
|
DEFAULT_COPY_CONFIG
|
|
@@ -1983,26 +2055,13 @@ const {
|
|
|
1983
2055
|
* @returns
|
|
1984
2056
|
*/
|
|
1985
2057
|
|
|
1986
|
-
const cpFilesToOutput = function (tmsConfig,
|
|
1987
|
-
const outputDir = resolve$
|
|
2058
|
+
const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
2059
|
+
const outputDir = resolve$7(tmsConfig.outputDir);
|
|
1988
2060
|
io.ensureDirExist(outputDir);
|
|
1989
2061
|
defaultFiles.forEach(item => {
|
|
1990
|
-
if (fs$
|
|
1991
|
-
shelljs$2.cp('-rf', resolve$
|
|
1992
|
-
}
|
|
1993
|
-
}); // 拷贝模块的package.json到编译输出目录
|
|
1994
|
-
|
|
1995
|
-
targetModules.forEach(item => {
|
|
1996
|
-
const outputModuleDir = resolve$6(`${tmsConfig.outputDir}/${item.root}`);
|
|
1997
|
-
|
|
1998
|
-
if (!fs$3.existsSync(resolve$6(item.path))) {
|
|
1999
|
-
fail$2(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2000
|
-
process.exit(1);
|
|
2062
|
+
if (fs$4.existsSync(resolve$7(item))) {
|
|
2063
|
+
shelljs$2.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
|
|
2001
2064
|
}
|
|
2002
|
-
|
|
2003
|
-
io.ensureDirExist(outputModuleDir);
|
|
2004
|
-
const modulePackagePath = resolve$6(item.path, 'package.json');
|
|
2005
|
-
if (fs$3.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
2006
2065
|
});
|
|
2007
2066
|
};
|
|
2008
2067
|
/**
|
|
@@ -2019,7 +2078,7 @@ function checkConfig(targetModules) {
|
|
|
2019
2078
|
} // 判断源码目录是否有该模块
|
|
2020
2079
|
|
|
2021
2080
|
|
|
2022
|
-
if (item.path && !fs$
|
|
2081
|
+
if (item.path && !fs$4.existsSync(resolve$7(item.path))) {
|
|
2023
2082
|
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2024
2083
|
}
|
|
2025
2084
|
}
|
|
@@ -2029,16 +2088,16 @@ function checkConfig(targetModules) {
|
|
|
2029
2088
|
|
|
2030
2089
|
async function task(tmsConfig, targetModules) {
|
|
2031
2090
|
// 下载和移动代码
|
|
2032
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$
|
|
2091
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$7('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
2033
2092
|
|
|
2034
2093
|
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
2035
2094
|
|
|
2036
2095
|
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2037
2096
|
checkConfig(newModules); // 拷贝相关配置文件到输出目录
|
|
2038
2097
|
|
|
2039
|
-
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig,
|
|
2098
|
+
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
|
|
2040
2099
|
|
|
2041
|
-
if (checkDependencies(newModules, resolve$
|
|
2100
|
+
if (checkDependencies(newModules, resolve$7('./'), tmsConfig.outputDir)) {
|
|
2042
2101
|
await install$1(tmsConfig, newModules);
|
|
2043
2102
|
} // 动态生成编译后的app.json;
|
|
2044
2103
|
|
|
@@ -2121,8 +2180,8 @@ var pluginError_1 = {
|
|
|
2121
2180
|
|
|
2122
2181
|
/* eslint-disable no-param-reassign */
|
|
2123
2182
|
const through$2 = require$$0__default$9;
|
|
2124
|
-
const precinct = require$$1__default$
|
|
2125
|
-
const path$
|
|
2183
|
+
const precinct = require$$1__default$8;
|
|
2184
|
+
const path$4 = require$$1__default$2;
|
|
2126
2185
|
const {
|
|
2127
2186
|
findCssImports
|
|
2128
2187
|
} = findCssImport;
|
|
@@ -2130,11 +2189,11 @@ const {
|
|
|
2130
2189
|
ext: ext$2,
|
|
2131
2190
|
fileInDir: fileInDir$2,
|
|
2132
2191
|
diffContentCopyFile: diffContentCopyFile$2
|
|
2133
|
-
} = io$
|
|
2192
|
+
} = io$3;
|
|
2134
2193
|
const {
|
|
2135
|
-
resolve: resolve$
|
|
2194
|
+
resolve: resolve$6
|
|
2136
2195
|
} = widgets;
|
|
2137
|
-
const fs$
|
|
2196
|
+
const fs$3 = require$$0__default$2;
|
|
2138
2197
|
const {
|
|
2139
2198
|
pluginError: pluginError$2
|
|
2140
2199
|
} = pluginError_1;
|
|
@@ -2147,16 +2206,16 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2147
2206
|
let contents = '';
|
|
2148
2207
|
|
|
2149
2208
|
try {
|
|
2150
|
-
contents = fs$
|
|
2209
|
+
contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
|
|
2151
2210
|
} catch (e) {
|
|
2152
2211
|
pluginError$2(e, isWatch);
|
|
2153
2212
|
}
|
|
2154
2213
|
|
|
2155
|
-
const deps = cssFilter.indexOf(path$
|
|
2214
|
+
const deps = cssFilter.indexOf(path$4.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2156
2215
|
deps.forEach(depItem => {
|
|
2157
2216
|
if (depItem.startsWith('.')) {
|
|
2158
2217
|
// 被依赖文件的存在的绝对路径
|
|
2159
|
-
const depOriginPath = path$
|
|
2218
|
+
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2160
2219
|
|
|
2161
2220
|
const {
|
|
2162
2221
|
ext: extAlias,
|
|
@@ -2164,12 +2223,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2164
2223
|
extPath
|
|
2165
2224
|
} = ext$2(depOriginPath, extensions);
|
|
2166
2225
|
|
|
2167
|
-
if (!fs$
|
|
2226
|
+
if (!fs$3.existsSync(depOriginFile)) {
|
|
2168
2227
|
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2169
2228
|
return;
|
|
2170
2229
|
}
|
|
2171
2230
|
|
|
2172
|
-
const depDestPath = resolve$
|
|
2231
|
+
const depDestPath = resolve$6(path$4.dirname(anaFileDestFile), depItem);
|
|
2173
2232
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2174
2233
|
|
|
2175
2234
|
if (!resDep.has(depDestFile)) {
|
|
@@ -2193,19 +2252,19 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2193
2252
|
const stream = through$2.obj(function (file, enc, cb) {
|
|
2194
2253
|
// 依赖分析的文件
|
|
2195
2254
|
const anaFileOriginFile = file.history[0];
|
|
2196
|
-
const anaFileRelativeModule = path$
|
|
2197
|
-
const anaFileDestFile = resolve$
|
|
2255
|
+
const anaFileRelativeModule = path$4.relative(resolve$6(module.from), anaFileOriginFile);
|
|
2256
|
+
const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2198
2257
|
|
|
2199
2258
|
if (file.isBuffer()) {
|
|
2200
2259
|
let contents = String(file.contents);
|
|
2201
|
-
const deps = cssFilter.indexOf(path$
|
|
2260
|
+
const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2202
2261
|
const copyModules = new Map();
|
|
2203
2262
|
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2204
2263
|
const includePath = tmsConfig.dependencies[includeName];
|
|
2205
2264
|
deps.forEach(depItem => {
|
|
2206
2265
|
if (depItem.indexOf(includeName) > -1) {
|
|
2207
2266
|
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
2208
|
-
const depOriginPath = path$
|
|
2267
|
+
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2209
2268
|
|
|
2210
2269
|
const {
|
|
2211
2270
|
ext: extAlias,
|
|
@@ -2223,7 +2282,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2223
2282
|
const regRes = depItem.match(reg) || [];
|
|
2224
2283
|
|
|
2225
2284
|
if (regRes[2]) {
|
|
2226
|
-
const depDestPath = resolve$
|
|
2285
|
+
const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2227
2286
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2228
2287
|
|
|
2229
2288
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2231,7 +2290,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2231
2290
|
depOriginFile,
|
|
2232
2291
|
depDestFile,
|
|
2233
2292
|
beforeDepPath: depItem,
|
|
2234
|
-
afterDepPath: path$
|
|
2293
|
+
afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2235
2294
|
});
|
|
2236
2295
|
}
|
|
2237
2296
|
}
|
|
@@ -2269,16 +2328,16 @@ var mpCommonDep_1 = {
|
|
|
2269
2328
|
|
|
2270
2329
|
/* eslint-disable no-param-reassign */
|
|
2271
2330
|
const through$1 = require$$0__default$9;
|
|
2272
|
-
const path$
|
|
2331
|
+
const path$3 = require$$1__default$2;
|
|
2273
2332
|
const {
|
|
2274
2333
|
ext: ext$1,
|
|
2275
2334
|
fileInDir: fileInDir$1,
|
|
2276
2335
|
diffContentCopyFile: diffContentCopyFile$1
|
|
2277
|
-
} = io$
|
|
2336
|
+
} = io$3;
|
|
2278
2337
|
const {
|
|
2279
|
-
resolve: resolve$
|
|
2338
|
+
resolve: resolve$5
|
|
2280
2339
|
} = widgets;
|
|
2281
|
-
const fs$
|
|
2340
|
+
const fs$2 = require$$0__default$2;
|
|
2282
2341
|
const {
|
|
2283
2342
|
pluginError: pluginError$1
|
|
2284
2343
|
} = pluginError_1;
|
|
@@ -2290,8 +2349,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2290
2349
|
const stream = through$1.obj(function (file, enc, cb) {
|
|
2291
2350
|
// 当前分析的文件的路径
|
|
2292
2351
|
const anaFileOriginFile = file.history[0];
|
|
2293
|
-
const anaFileRelativeModule = path$
|
|
2294
|
-
const anaFileDestFile = resolve$
|
|
2352
|
+
const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2353
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2295
2354
|
|
|
2296
2355
|
if (file.isBuffer()) {
|
|
2297
2356
|
let contents = String(file.contents);
|
|
@@ -2311,7 +2370,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2311
2370
|
const componentPath = contents.usingComponents[componentKey];
|
|
2312
2371
|
|
|
2313
2372
|
if (componentPath.indexOf(includeName) > -1) {
|
|
2314
|
-
const depOriginPath = path$
|
|
2373
|
+
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
|
|
2315
2374
|
|
|
2316
2375
|
const {
|
|
2317
2376
|
ext: extAlias,
|
|
@@ -2326,11 +2385,11 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2326
2385
|
} // eslint-disable-next-line
|
|
2327
2386
|
|
|
2328
2387
|
|
|
2329
|
-
const reg = new RegExp(`^(
|
|
2388
|
+
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2330
2389
|
const regRes = componentPath.match(reg) || [];
|
|
2331
2390
|
|
|
2332
2391
|
if (regRes[2]) {
|
|
2333
|
-
const depDestPath = resolve$
|
|
2392
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2334
2393
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2335
2394
|
|
|
2336
2395
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2339,7 +2398,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2339
2398
|
depOriginExt: extAlias,
|
|
2340
2399
|
depDestFile,
|
|
2341
2400
|
beforeDepPath: componentPath,
|
|
2342
|
-
afterDepPath: path$
|
|
2401
|
+
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2343
2402
|
});
|
|
2344
2403
|
}
|
|
2345
2404
|
}
|
|
@@ -2364,7 +2423,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2364
2423
|
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2365
2424
|
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2366
2425
|
|
|
2367
|
-
if (fs$
|
|
2426
|
+
if (fs$2.existsSync(originFile)) {
|
|
2368
2427
|
diffContentCopyFile$1(originFile, destFile);
|
|
2369
2428
|
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2370
2429
|
|
|
@@ -2397,16 +2456,16 @@ var mpJsonDep_1 = {
|
|
|
2397
2456
|
|
|
2398
2457
|
/* eslint-disable no-param-reassign */
|
|
2399
2458
|
const through = require$$0__default$9;
|
|
2400
|
-
const htmlparser2 = require$$1__default$
|
|
2401
|
-
const fs = require$$0__default$2;
|
|
2402
|
-
const path$
|
|
2459
|
+
const htmlparser2 = require$$1__default$9;
|
|
2460
|
+
const fs$1 = require$$0__default$2;
|
|
2461
|
+
const path$2 = require$$1__default$2;
|
|
2403
2462
|
const {
|
|
2404
2463
|
diffContentCopyFile,
|
|
2405
2464
|
ext,
|
|
2406
2465
|
fileInDir
|
|
2407
|
-
} = io$
|
|
2466
|
+
} = io$3;
|
|
2408
2467
|
const {
|
|
2409
|
-
resolve: resolve$
|
|
2468
|
+
resolve: resolve$4
|
|
2410
2469
|
} = widgets;
|
|
2411
2470
|
const {
|
|
2412
2471
|
dfsFindCommonDep
|
|
@@ -2445,7 +2504,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2445
2504
|
let contents = '';
|
|
2446
2505
|
|
|
2447
2506
|
try {
|
|
2448
|
-
contents = fs.readFileSync(anaFileOriginFile, 'utf8');
|
|
2507
|
+
contents = fs$1.readFileSync(anaFileOriginFile, 'utf8');
|
|
2449
2508
|
} catch (e) {
|
|
2450
2509
|
pluginError(e, isWatch);
|
|
2451
2510
|
}
|
|
@@ -2455,7 +2514,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2455
2514
|
var _attributes$src;
|
|
2456
2515
|
|
|
2457
2516
|
if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
|
|
2458
|
-
const depOriginPath = path$
|
|
2517
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
|
|
2459
2518
|
|
|
2460
2519
|
const {
|
|
2461
2520
|
ext,
|
|
@@ -2463,12 +2522,12 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2463
2522
|
extPath
|
|
2464
2523
|
} = extFile(name, depOriginPath);
|
|
2465
2524
|
|
|
2466
|
-
if (!fs.existsSync(depOriginFile)) {
|
|
2525
|
+
if (!fs$1.existsSync(depOriginFile)) {
|
|
2467
2526
|
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2468
2527
|
return;
|
|
2469
2528
|
}
|
|
2470
2529
|
|
|
2471
|
-
const depDestPath = path$
|
|
2530
|
+
const depDestPath = path$2.join(path$2.dirname(anaFileDestFile), attributes.src);
|
|
2472
2531
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
|
|
2473
2532
|
|
|
2474
2533
|
if (['import', 'include'].indexOf(name) > -1) {
|
|
@@ -2520,8 +2579,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2520
2579
|
const stream = through.obj(function (file, enc, cb) {
|
|
2521
2580
|
// 依赖分析的文件
|
|
2522
2581
|
const anaFileOriginFile = file.history[0];
|
|
2523
|
-
const anaFileRelativeModule = path$
|
|
2524
|
-
const anaFileDestFile = resolve$
|
|
2582
|
+
const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
|
|
2583
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2525
2584
|
|
|
2526
2585
|
if (file.isBuffer()) {
|
|
2527
2586
|
let contents = String(file.contents);
|
|
@@ -2531,7 +2590,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2531
2590
|
const nameFilter = ['import', 'include', 'wxs'];
|
|
2532
2591
|
|
|
2533
2592
|
if (nameFilter.indexOf(name) > -1 && attributes.src) {
|
|
2534
|
-
const depOriginPath = path$
|
|
2593
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
|
|
2535
2594
|
|
|
2536
2595
|
const {
|
|
2537
2596
|
ext,
|
|
@@ -2552,7 +2611,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2552
2611
|
const regRes = attributes.src.match(reg) || [];
|
|
2553
2612
|
|
|
2554
2613
|
if (regRes[2]) {
|
|
2555
|
-
const depDestPath = resolve$
|
|
2614
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2556
2615
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2557
2616
|
|
|
2558
2617
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2560,7 +2619,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2560
2619
|
depOriginFile,
|
|
2561
2620
|
depDestFile,
|
|
2562
2621
|
beforeDepPath: attributes.src,
|
|
2563
|
-
afterDepPath: path$
|
|
2622
|
+
afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
|
|
2564
2623
|
});
|
|
2565
2624
|
}
|
|
2566
2625
|
}
|
|
@@ -2579,7 +2638,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2579
2638
|
beforeDepPath,
|
|
2580
2639
|
afterDepPath
|
|
2581
2640
|
}) => {
|
|
2582
|
-
if (fs.existsSync(depOriginFile)) {
|
|
2641
|
+
if (fs$1.existsSync(depOriginFile)) {
|
|
2583
2642
|
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2584
2643
|
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2585
2644
|
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
@@ -2767,19 +2826,197 @@ var compile = function (tmsConfig, {
|
|
|
2767
2826
|
return compileTasksMap;
|
|
2768
2827
|
};
|
|
2769
2828
|
|
|
2770
|
-
|
|
2771
|
-
|
|
2829
|
+
/* eslint-disable */
|
|
2830
|
+
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
2831
|
+
|
|
2832
|
+
const assign = require$$0__default$b;
|
|
2833
|
+
const path$1 = require$$1__default$2;
|
|
2834
|
+
const PluginError = require$$2__default$1;
|
|
2835
|
+
const fancyLog = require$$3__default;
|
|
2836
|
+
const colors = require$$4__default;
|
|
2837
|
+
const chokidar = require$$5__default$1;
|
|
2838
|
+
const {
|
|
2839
|
+
Duplex
|
|
2840
|
+
} = require$$6__default;
|
|
2841
|
+
const vinyl = require$$7__default;
|
|
2842
|
+
const File = require$$8__default;
|
|
2843
|
+
const anymatch = require$$9__default;
|
|
2844
|
+
const pathIsAbsolute = require$$10__default;
|
|
2845
|
+
const globParent = require$$11__default;
|
|
2846
|
+
const slash = require$$12__default;
|
|
2847
|
+
|
|
2848
|
+
function normalizeGlobs(globs) {
|
|
2849
|
+
if (!globs) {
|
|
2850
|
+
throw new PluginError('gulp-watch', 'glob argument required');
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
if (typeof globs === 'string') {
|
|
2854
|
+
globs = [globs];
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
if (!Array.isArray(globs)) {
|
|
2858
|
+
throw new PluginError('gulp-watch', `glob should be String or Array, not ${typeof globs}`);
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
return globs;
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
function watch$1(globs, opts, cb) {
|
|
2865
|
+
globs = normalizeGlobs(globs);
|
|
2866
|
+
|
|
2867
|
+
if (typeof opts === 'function') {
|
|
2868
|
+
cb = opts;
|
|
2869
|
+
opts = {};
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2872
|
+
opts = assign({}, watch$1._defaultOptions, opts);
|
|
2873
|
+
|
|
2874
|
+
cb = cb || function () {};
|
|
2875
|
+
|
|
2876
|
+
function resolveFilepath(filepath) {
|
|
2877
|
+
if (pathIsAbsolute(filepath)) {
|
|
2878
|
+
return path$1.normalize(filepath);
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
return path$1.resolve(opts.cwd || process.cwd(), filepath);
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
function resolveGlob(glob) {
|
|
2885
|
+
let mod = '';
|
|
2886
|
+
|
|
2887
|
+
if (glob[0] === '!') {
|
|
2888
|
+
mod = glob[0];
|
|
2889
|
+
glob = glob.slice(1);
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
return mod + slash(resolveFilepath(glob));
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
globs = globs.map(resolveGlob);
|
|
2896
|
+
const baseForced = Boolean(opts.base);
|
|
2897
|
+
const outputStream = new Duplex({
|
|
2898
|
+
objectMode: true,
|
|
2899
|
+
allowHalfOpen: true
|
|
2900
|
+
});
|
|
2901
|
+
|
|
2902
|
+
outputStream._write = function _write(file, enc, done) {
|
|
2903
|
+
cb(file);
|
|
2904
|
+
this.push(file);
|
|
2905
|
+
done();
|
|
2906
|
+
};
|
|
2907
|
+
|
|
2908
|
+
outputStream._read = function _read() {};
|
|
2909
|
+
|
|
2910
|
+
const watcher = chokidar.watch(globs, opts);
|
|
2911
|
+
opts.events.forEach(ev => {
|
|
2912
|
+
watcher.on(ev, processEvent.bind(undefined, ev));
|
|
2913
|
+
});
|
|
2914
|
+
['add', 'change', 'unlink', 'addDir', 'unlinkDir', 'error', 'ready', 'raw'].forEach(ev => {
|
|
2915
|
+
watcher.on(ev, outputStream.emit.bind(outputStream, ev));
|
|
2916
|
+
});
|
|
2917
|
+
|
|
2918
|
+
outputStream.add = function add(newGlobs) {
|
|
2919
|
+
newGlobs = normalizeGlobs(newGlobs).map(resolveGlob);
|
|
2920
|
+
watcher.add(newGlobs);
|
|
2921
|
+
globs.push.apply(globs, newGlobs);
|
|
2922
|
+
};
|
|
2923
|
+
|
|
2924
|
+
outputStream.unwatch = watcher.unwatch.bind(watcher);
|
|
2925
|
+
|
|
2926
|
+
outputStream.close = function () {
|
|
2927
|
+
watcher.close();
|
|
2928
|
+
this.emit('end');
|
|
2929
|
+
};
|
|
2930
|
+
|
|
2931
|
+
function processEvent(event, filepath) {
|
|
2932
|
+
filepath = resolveFilepath(filepath);
|
|
2933
|
+
const fileOpts = assign({}, opts);
|
|
2934
|
+
let glob;
|
|
2935
|
+
let currentFilepath = filepath;
|
|
2936
|
+
|
|
2937
|
+
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$1.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
2938
|
+
|
|
2939
|
+
|
|
2940
|
+
if (!glob) {
|
|
2941
|
+
console.error('[gulp-watch]没有匹配到glob');
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
if (!baseForced) {
|
|
2946
|
+
fileOpts.base = path$1.normalize(globParent(glob));
|
|
2947
|
+
} // Do not stat deleted files
|
|
2948
|
+
|
|
2949
|
+
|
|
2950
|
+
if (event === 'unlink' || event === 'unlinkDir' || event === 'addDir') {
|
|
2951
|
+
fileOpts.path = filepath;
|
|
2952
|
+
write(event, null, new File(fileOpts));
|
|
2953
|
+
return;
|
|
2954
|
+
} // Workaround for early read
|
|
2955
|
+
|
|
2956
|
+
|
|
2957
|
+
setTimeout(() => {
|
|
2958
|
+
vinyl.read(filepath, fileOpts).then(file => {
|
|
2959
|
+
write(event, null, file);
|
|
2960
|
+
});
|
|
2961
|
+
}, opts.readDelay);
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
function write(event, err, file) {
|
|
2965
|
+
if (err) {
|
|
2966
|
+
outputStream.emit('error', err);
|
|
2967
|
+
return;
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
if (opts.verbose) {
|
|
2971
|
+
log(event, file);
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
file.event = event;
|
|
2975
|
+
outputStream.push(file);
|
|
2976
|
+
cb(file);
|
|
2977
|
+
}
|
|
2978
|
+
|
|
2979
|
+
function log(event, file) {
|
|
2980
|
+
event = event[event.length - 1] === 'e' ? `${event}d` : `${event}ed`;
|
|
2981
|
+
const msg = [colors.magenta(file.relative), 'was', event];
|
|
2982
|
+
|
|
2983
|
+
if (opts.name) {
|
|
2984
|
+
msg.unshift(`${colors.cyan(opts.name)} saw`);
|
|
2985
|
+
}
|
|
2986
|
+
|
|
2987
|
+
fancyLog.info.apply(null, msg);
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
return outputStream;
|
|
2991
|
+
} // This is not part of the public API as that would lead to global state (singleton) pollution,
|
|
2992
|
+
// and allow unexpected interference between unrelated modules that make use of gulp-watch.
|
|
2993
|
+
// This can be useful for unit tests and root application configuration, though.
|
|
2994
|
+
// Avoid modifying gulp-watch's default options inside a library/reusable package, please.
|
|
2995
|
+
|
|
2996
|
+
|
|
2997
|
+
watch$1._defaultOptions = {
|
|
2998
|
+
events: ['add', 'change', 'unlink'],
|
|
2999
|
+
ignoreInitial: true,
|
|
3000
|
+
readDelay: 10
|
|
3001
|
+
};
|
|
3002
|
+
var gulpWatch = watch$1;
|
|
3003
|
+
|
|
3004
|
+
const watch = gulpWatch;
|
|
3005
|
+
const path = require$$1__default$2;
|
|
2772
3006
|
const shellJs = require$$0__default$3;
|
|
2773
3007
|
const {
|
|
2774
3008
|
info: info$3,
|
|
2775
|
-
warn
|
|
3009
|
+
warn: warn$1
|
|
2776
3010
|
} = log$1;
|
|
2777
3011
|
const {
|
|
2778
|
-
resolve: resolve$
|
|
3012
|
+
resolve: resolve$3
|
|
2779
3013
|
} = widgets;
|
|
2780
3014
|
const {
|
|
2781
3015
|
global: global$2
|
|
2782
3016
|
} = global_1;
|
|
3017
|
+
const {
|
|
3018
|
+
findAllFilesOfDir
|
|
3019
|
+
} = io$3;
|
|
2783
3020
|
const TIP_MAP = {
|
|
2784
3021
|
'package.json': '若依赖有变动,请重新执行tmskit run dev',
|
|
2785
3022
|
'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效'
|
|
@@ -2789,7 +3026,7 @@ const logTip = (fileName, tipMap) => {
|
|
|
2789
3026
|
// eslint-disable-next-line
|
|
2790
3027
|
for (const item in tipMap) {
|
|
2791
3028
|
if (fileName.indexOf(item) > -1) {
|
|
2792
|
-
warn(`${fileName}有更新, ${tipMap[item]}`);
|
|
3029
|
+
warn$1(`${fileName}有更新, ${tipMap[item]}`);
|
|
2793
3030
|
return;
|
|
2794
3031
|
}
|
|
2795
3032
|
}
|
|
@@ -2797,6 +3034,12 @@ const logTip = (fileName, tipMap) => {
|
|
|
2797
3034
|
info$3(`${fileName}有更新`);
|
|
2798
3035
|
};
|
|
2799
3036
|
|
|
3037
|
+
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
3038
|
+
const sourceFileRelativeModule = path.relative(resolve$3(module.from), sourceFile);
|
|
3039
|
+
const targetFile = resolve$3(outputDir, module.to, sourceFileRelativeModule);
|
|
3040
|
+
return targetFile;
|
|
3041
|
+
};
|
|
3042
|
+
|
|
2800
3043
|
var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
2801
3044
|
watch(globValue, { // readDelay: 100,
|
|
2802
3045
|
...watchOptions
|
|
@@ -2805,8 +3048,23 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
2805
3048
|
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
2806
3049
|
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
2807
3050
|
const tmsConfig = global$2.getData('tmsConfig');
|
|
2808
|
-
|
|
2809
|
-
|
|
3051
|
+
|
|
3052
|
+
if (vinyl.event === 'addDir') {
|
|
3053
|
+
info$3(`更新${sourceFileName}目录`);
|
|
3054
|
+
const files = findAllFilesOfDir(sourceFile);
|
|
3055
|
+
|
|
3056
|
+
for (const file of files) {
|
|
3057
|
+
const fileDirArr = file.replace(/\\/g, '/').split('/');
|
|
3058
|
+
const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
|
|
3059
|
+
const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
|
|
3060
|
+
logTip(fileName, TIP_MAP);
|
|
3061
|
+
callback([file], path.dirname(targetFile));
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
return;
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
2810
3068
|
|
|
2811
3069
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
2812
3070
|
info$3(`删除${sourceFileName}`);
|
|
@@ -2820,9 +3078,10 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
2820
3078
|
};
|
|
2821
3079
|
|
|
2822
3080
|
(function (module) {
|
|
2823
|
-
const path = require$$
|
|
3081
|
+
const path = require$$1__default$2;
|
|
2824
3082
|
const fs = require$$0__default$2;
|
|
2825
3083
|
const ora = require$$2__default;
|
|
3084
|
+
const chalk = require$$0__default;
|
|
2826
3085
|
const {
|
|
2827
3086
|
parallel,
|
|
2828
3087
|
series
|
|
@@ -2833,7 +3092,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
2833
3092
|
} = widgets;
|
|
2834
3093
|
const {
|
|
2835
3094
|
buildOutputAppJson
|
|
2836
|
-
} = buildAppJson;
|
|
3095
|
+
} = buildAppJson.exports;
|
|
2837
3096
|
const {
|
|
2838
3097
|
DEFAULT_COPY_CONFIG
|
|
2839
3098
|
} = require$$4;
|
|
@@ -2842,7 +3101,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
2842
3101
|
const {
|
|
2843
3102
|
info
|
|
2844
3103
|
} = log$1;
|
|
2845
|
-
const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
|
|
3104
|
+
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
2846
3105
|
|
|
2847
3106
|
function excludeGlob(glob) {
|
|
2848
3107
|
const otherArr = new Set();
|
|
@@ -2873,20 +3132,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
2873
3132
|
}
|
|
2874
3133
|
|
|
2875
3134
|
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
2876
|
-
const compileTasksMap = new Map(); //
|
|
2877
|
-
|
|
2878
|
-
if (isDev) {
|
|
2879
|
-
watch([resolve('app.json')], {
|
|
2880
|
-
ignoreInitial: false,
|
|
2881
|
-
events: watchEvents
|
|
2882
|
-
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
2883
|
-
from: resolve(),
|
|
2884
|
-
to: resolve(tmsConfig.outputDir)
|
|
2885
|
-
});
|
|
2886
|
-
} else {
|
|
2887
|
-
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
2888
|
-
} // 监听根目录的文件
|
|
2889
|
-
|
|
3135
|
+
const compileTasksMap = new Map(); // 监听根目录的文件
|
|
2890
3136
|
|
|
2891
3137
|
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
2892
3138
|
glob: {
|
|
@@ -2996,10 +3242,19 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
2996
3242
|
cb();
|
|
2997
3243
|
}
|
|
2998
3244
|
|
|
2999
|
-
function end(cb) {
|
|
3245
|
+
async function end(cb) {
|
|
3000
3246
|
var _tmsConfig$hooks;
|
|
3001
3247
|
|
|
3002
3248
|
if (isDev) {
|
|
3249
|
+
// 监听app.json
|
|
3250
|
+
watch([resolve('app.json')], {
|
|
3251
|
+
ignoreInitial: false,
|
|
3252
|
+
events: watchEvents
|
|
3253
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3254
|
+
from: resolve(),
|
|
3255
|
+
to: resolve(tmsConfig.outputDir)
|
|
3256
|
+
}); // 监听其他文件
|
|
3257
|
+
|
|
3003
3258
|
compileTasksMap.forEach(({
|
|
3004
3259
|
taskFn,
|
|
3005
3260
|
module
|
|
@@ -3009,6 +3264,8 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3009
3264
|
events: watchEvents
|
|
3010
3265
|
}, taskFn, module);
|
|
3011
3266
|
});
|
|
3267
|
+
} else {
|
|
3268
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
3012
3269
|
}
|
|
3013
3270
|
|
|
3014
3271
|
eTime = new Date().getTime() - sTime;
|
|
@@ -3016,14 +3273,14 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3016
3273
|
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
3274
|
var _tmsConfig$hooks2;
|
|
3018
3275
|
|
|
3019
|
-
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3276
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3020
3277
|
isDev,
|
|
3021
3278
|
tmsConfig,
|
|
3022
3279
|
modules: newModules
|
|
3023
|
-
});
|
|
3280
|
+
}));
|
|
3024
3281
|
}
|
|
3025
3282
|
|
|
3026
|
-
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
|
|
3283
|
+
spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
3027
3284
|
spinner.stop();
|
|
3028
3285
|
cb();
|
|
3029
3286
|
}
|
|
@@ -3033,7 +3290,8 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3033
3290
|
taskFn
|
|
3034
3291
|
}) => {
|
|
3035
3292
|
compileTasks.push(taskFn);
|
|
3036
|
-
});
|
|
3293
|
+
}); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
3294
|
+
|
|
3037
3295
|
series(start, parallel(...compileTasks), end)();
|
|
3038
3296
|
};
|
|
3039
3297
|
})(dev$3);
|
|
@@ -3041,7 +3299,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3041
3299
|
const shelljs$1 = require$$0__default$3;
|
|
3042
3300
|
const compileDev = dev$3.exports;
|
|
3043
3301
|
const {
|
|
3044
|
-
resolve: resolve$
|
|
3302
|
+
resolve: resolve$2
|
|
3045
3303
|
} = widgets;
|
|
3046
3304
|
const init$4 = init_1;
|
|
3047
3305
|
const {
|
|
@@ -3062,7 +3320,7 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
3062
3320
|
const targetModulesName = targetModules.map(item => item.name);
|
|
3063
3321
|
modules.forEach(item => {
|
|
3064
3322
|
if (item.root && targetModulesName.indexOf(item.name) === -1) {
|
|
3065
|
-
const moduleRootDir = resolve$
|
|
3323
|
+
const moduleRootDir = resolve$2(`dist/${item.root}`);
|
|
3066
3324
|
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
3067
3325
|
silent: true
|
|
3068
3326
|
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
@@ -3080,7 +3338,7 @@ async function dev$2(tmsConfig, targetModules, env) {
|
|
|
3080
3338
|
} = global$1.getData('cmd');
|
|
3081
3339
|
|
|
3082
3340
|
if (noCache) {
|
|
3083
|
-
shelljs$1.rm('-rf', resolve$
|
|
3341
|
+
shelljs$1.rm('-rf', resolve$2(tmsConfig.outputDir));
|
|
3084
3342
|
shelljs$1.rm('-rf', CACHE_DIR);
|
|
3085
3343
|
} // 初始化操作
|
|
3086
3344
|
|
|
@@ -3092,11 +3350,11 @@ async function dev$2(tmsConfig, targetModules, env) {
|
|
|
3092
3350
|
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
3351
|
var _tmsConfig$hooks2;
|
|
3094
3352
|
|
|
3095
|
-
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3353
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3096
3354
|
isDev: true,
|
|
3097
3355
|
tmsConfig,
|
|
3098
3356
|
modules: newModules
|
|
3099
|
-
});
|
|
3357
|
+
}));
|
|
3100
3358
|
}
|
|
3101
3359
|
delOtherModule(tmsConfig, newModules);
|
|
3102
3360
|
compileDev(tmsConfig, newModules, env);
|
|
@@ -3112,26 +3370,104 @@ var build$2 = async (tmsConfig, newModules) => {
|
|
|
3112
3370
|
|
|
3113
3371
|
const shelljs = require$$0__default$3;
|
|
3114
3372
|
const {
|
|
3115
|
-
resolve
|
|
3373
|
+
resolve: resolve$1
|
|
3116
3374
|
} = widgets;
|
|
3117
3375
|
const init$3 = init_1;
|
|
3118
3376
|
const compileBuild = build$2;
|
|
3119
3377
|
|
|
3120
3378
|
async function build$1(tmsConfig, targetModules, env) {
|
|
3379
|
+
var _tmsConfig$hooks;
|
|
3380
|
+
|
|
3121
3381
|
// 开始构建前,清理输出目录
|
|
3122
|
-
await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
3382
|
+
await shelljs.rm('-rf', resolve$1(tmsConfig.outputDir));
|
|
3123
3383
|
const {
|
|
3124
3384
|
targetModules: newModules
|
|
3125
3385
|
} = await init$3(tmsConfig, targetModules);
|
|
3386
|
+
|
|
3387
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3388
|
+
var _tmsConfig$hooks2;
|
|
3389
|
+
|
|
3390
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3391
|
+
isDev: false,
|
|
3392
|
+
tmsConfig,
|
|
3393
|
+
modules: newModules
|
|
3394
|
+
}));
|
|
3395
|
+
}
|
|
3126
3396
|
compileBuild(tmsConfig, newModules, env);
|
|
3127
3397
|
}
|
|
3128
3398
|
|
|
3129
3399
|
var build_1 = build$1;
|
|
3130
3400
|
|
|
3401
|
+
const fs = require$$0__default$2;
|
|
3402
|
+
const {
|
|
3403
|
+
resolve
|
|
3404
|
+
} = widgets;
|
|
3405
|
+
const {
|
|
3406
|
+
handleError: handleError$1
|
|
3407
|
+
} = handleError_1;
|
|
3408
|
+
const {
|
|
3409
|
+
ensureDirExist
|
|
3410
|
+
} = io$3;
|
|
3411
|
+
const {
|
|
3412
|
+
warn
|
|
3413
|
+
} = log$1;
|
|
3414
|
+
/**
|
|
3415
|
+
* 根据相关配置创建软链接
|
|
3416
|
+
* @param { object } tmsConfig
|
|
3417
|
+
*/
|
|
3418
|
+
|
|
3419
|
+
const symLink$1 = tmsConfig => {
|
|
3420
|
+
try {
|
|
3421
|
+
ensureDirExist(resolve(tmsConfig.cloudDir));
|
|
3422
|
+
|
|
3423
|
+
if (tmsConfig.cloudModules) {
|
|
3424
|
+
tmsConfig.cloudModules.forEach(item => {
|
|
3425
|
+
const sourcePath = resolve(item.path);
|
|
3426
|
+
const targetPath = resolve(tmsConfig.cloudDir, item.name);
|
|
3427
|
+
|
|
3428
|
+
if (!fs.existsSync(sourcePath)) {
|
|
3429
|
+
warn(`云函数${sourcePath}不存在`);
|
|
3430
|
+
return;
|
|
3431
|
+
}
|
|
3432
|
+
|
|
3433
|
+
if (!fs.existsSync(targetPath)) {
|
|
3434
|
+
fs.symlinkSync(sourcePath, targetPath);
|
|
3435
|
+
}
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3438
|
+
} catch (e) {
|
|
3439
|
+
handleError$1(`创建软链错误: ${e}`);
|
|
3440
|
+
}
|
|
3441
|
+
};
|
|
3442
|
+
|
|
3443
|
+
var symbolicLink = {
|
|
3444
|
+
symLink: symLink$1
|
|
3445
|
+
};
|
|
3446
|
+
|
|
3447
|
+
const {
|
|
3448
|
+
symLink
|
|
3449
|
+
} = symbolicLink;
|
|
3450
|
+
const {
|
|
3451
|
+
handleError
|
|
3452
|
+
} = handleError_1;
|
|
3453
|
+
const {
|
|
3454
|
+
succeed
|
|
3455
|
+
} = log$1;
|
|
3456
|
+
|
|
3457
|
+
var cloud$1 = async tmsConfig => {
|
|
3458
|
+
try {
|
|
3459
|
+
await symLink(tmsConfig);
|
|
3460
|
+
succeed('云函数创建软链成功');
|
|
3461
|
+
} catch (e) {
|
|
3462
|
+
handleError(`创建软链错误: ${e}`);
|
|
3463
|
+
}
|
|
3464
|
+
};
|
|
3465
|
+
|
|
3131
3466
|
const init$2 = init_1;
|
|
3132
3467
|
const dev = dev_1;
|
|
3133
3468
|
const build = build_1;
|
|
3134
3469
|
const install = install_1;
|
|
3470
|
+
const cloud = cloud$1;
|
|
3135
3471
|
const {
|
|
3136
3472
|
global
|
|
3137
3473
|
} = global_1;
|
|
@@ -3216,6 +3552,10 @@ async function run(commandName, cmd) {
|
|
|
3216
3552
|
dev(tmsConfig, newModules, env);
|
|
3217
3553
|
return;
|
|
3218
3554
|
|
|
3555
|
+
case 'cloud':
|
|
3556
|
+
cloud(tmsConfig, env);
|
|
3557
|
+
return;
|
|
3558
|
+
|
|
3219
3559
|
case 'install':
|
|
3220
3560
|
install(tmsConfig, newModules, env);
|
|
3221
3561
|
return;
|
|
@@ -3256,6 +3596,13 @@ var entry = [{
|
|
|
3256
3596
|
action: cmd => {
|
|
3257
3597
|
run_1('dev', cmd);
|
|
3258
3598
|
}
|
|
3599
|
+
}, {
|
|
3600
|
+
command: 'cloud',
|
|
3601
|
+
description: '云函数开发',
|
|
3602
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
3603
|
+
action: cmd => {
|
|
3604
|
+
run_1('cloud', cmd);
|
|
3605
|
+
}
|
|
3259
3606
|
}, {
|
|
3260
3607
|
command: 'build',
|
|
3261
3608
|
description: 'prod 打包编译',
|
|
@@ -3280,7 +3627,7 @@ var entry = [{
|
|
|
3280
3627
|
|
|
3281
3628
|
var require$$7 = {
|
|
3282
3629
|
name: "@tmsfe/tmskit",
|
|
3283
|
-
version: "0.0.
|
|
3630
|
+
version: "0.0.17",
|
|
3284
3631
|
description: "tmskit",
|
|
3285
3632
|
main: "dist/index.cjs",
|
|
3286
3633
|
bin: {
|
|
@@ -3298,8 +3645,7 @@ var require$$7 = {
|
|
|
3298
3645
|
build: "rollup -c --environment TARGET:tmskit",
|
|
3299
3646
|
"pub:patch": "sh build/publish.sh patch",
|
|
3300
3647
|
"pub:minor": "sh build/publish.sh minor",
|
|
3301
|
-
"pub:major": "sh build/publish.sh major"
|
|
3302
|
-
postinstall: "node build/postinstall.js"
|
|
3648
|
+
"pub:major": "sh build/publish.sh major"
|
|
3303
3649
|
},
|
|
3304
3650
|
author: "tms·web",
|
|
3305
3651
|
license: "ISC",
|
|
@@ -3320,6 +3666,15 @@ var require$$7 = {
|
|
|
3320
3666
|
"rollup-plugin-typescript2": "0.27.0"
|
|
3321
3667
|
},
|
|
3322
3668
|
dependencies: {
|
|
3669
|
+
"ansi-colors": "1.1.0",
|
|
3670
|
+
anymatch: "^1.3.0",
|
|
3671
|
+
"fancy-log": "1.3.2",
|
|
3672
|
+
"glob-parent": "^3.0.1",
|
|
3673
|
+
"path-is-absolute": "^1.0.1",
|
|
3674
|
+
"readable-stream": "^2.2.2",
|
|
3675
|
+
slash: "^1.0.0",
|
|
3676
|
+
vinyl: "^2.1.0",
|
|
3677
|
+
"vinyl-file": "^2.0.0",
|
|
3323
3678
|
async: "^3.2.2",
|
|
3324
3679
|
chalk: "^4.1.0",
|
|
3325
3680
|
chokidar: "^3.5.3",
|
|
@@ -3336,7 +3691,7 @@ var require$$7 = {
|
|
|
3336
3691
|
lodash: "^4.17.21",
|
|
3337
3692
|
metalsmith: "^2.3.0",
|
|
3338
3693
|
"miniprogram-ci": "1.4.13",
|
|
3339
|
-
moment: "^2.29.
|
|
3694
|
+
moment: "^2.29.2",
|
|
3340
3695
|
"object-assign": "^4.0.1",
|
|
3341
3696
|
ora: "^5.1.0",
|
|
3342
3697
|
"plugin-error": "^1.0.0",
|
|
@@ -3356,7 +3711,7 @@ var require$$7 = {
|
|
|
3356
3711
|
}
|
|
3357
3712
|
};
|
|
3358
3713
|
|
|
3359
|
-
const semver = require$$1__default$
|
|
3714
|
+
const semver = require$$1__default$7;
|
|
3360
3715
|
const packageJson = require$$7;
|
|
3361
3716
|
const chalk$1 = require$$0__default;
|
|
3362
3717
|
const {
|