@tmsfe/tmskit 0.0.12 → 0.0.15-beta.0
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 +32 -0
- package/README.md +6 -1
- package/dist/index.cjs.js +667 -546
- package/main.js +0 -0
- package/package.json +6 -5
- package/src/compile/compile.js +131 -50
- package/src/compile/dev.js +64 -24
- package/src/compile/watch.js +46 -0
- package/src/core/buildAppJson.js +3 -0
- package/src/core/cloneModules.js +7 -3
- package/src/core/isInIt.js +2 -6
- package/src/core/mpCi.js +1 -1
- package/src/core/npm.js +9 -6
- package/src/core/symbolicLink.js +13 -7
- package/src/core/tmsMpconfig.js +13 -8
- package/src/entry.js +1 -1
- package/src/index.js +1 -4
- package/src/scripts/run/dev/index.js +12 -8
- package/src/scripts/run/index.js +11 -6
- package/src/scripts/run/init/index.js +26 -9
- package/src/scripts/run/install/index.js +2 -9
- package/src/utils/io.js +3 -2
- package/src/utils/log.js +5 -4
- package/src/utils/widgets.js +22 -5
package/dist/index.cjs.js
CHANGED
|
@@ -1,58 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var require$$0 = require('chalk');
|
|
4
|
+
var require$$1 = require('moment');
|
|
4
5
|
var require$$0$1 = require('commander');
|
|
5
|
-
var require$$1 = require('leven');
|
|
6
|
+
var require$$1$1 = require('leven');
|
|
6
7
|
var require$$2 = require('ora');
|
|
7
8
|
var require$$3 = require('path');
|
|
8
9
|
var require$$0$2 = require('fs');
|
|
9
10
|
var require$$0$3 = require('shelljs');
|
|
10
11
|
var require$$0$4 = require('async');
|
|
11
|
-
var require$$1$
|
|
12
|
-
var require$$1$
|
|
12
|
+
var require$$1$2 = require('ejs');
|
|
13
|
+
var require$$1$3 = require('inquirer');
|
|
13
14
|
var require$$0$5 = require('metalsmith');
|
|
14
15
|
var require$$0$6 = require('lodash');
|
|
15
|
-
var require$$1$
|
|
16
|
+
var require$$1$4 = require('crypto');
|
|
16
17
|
var require$$0$7 = require('miniprogram-ci');
|
|
17
18
|
var require$$5 = require('glob-ignore');
|
|
18
|
-
var require$$1$
|
|
19
|
-
var require$$
|
|
19
|
+
var require$$1$5 = require('fs-extra');
|
|
20
|
+
var require$$1$6 = require('semver');
|
|
20
21
|
var require$$0$8 = require('strip-comments');
|
|
21
22
|
var require$$0$9 = require('through2');
|
|
22
|
-
var require$$1$
|
|
23
|
-
var require$$1$
|
|
23
|
+
var require$$1$7 = require('precinct');
|
|
24
|
+
var require$$1$8 = require('htmlparser2');
|
|
24
25
|
var require$$0$a = require('gulp');
|
|
25
|
-
var require$$
|
|
26
|
-
var require$$2$1 = require('gulp-watch');
|
|
27
|
-
var require$$1$8 = require('semver');
|
|
26
|
+
var require$$0$b = require('gulp-watch');
|
|
28
27
|
|
|
29
28
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
30
29
|
|
|
31
30
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
32
|
-
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
33
31
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
32
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
33
|
+
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
34
34
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
35
35
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
36
36
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
37
37
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
38
38
|
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
39
|
-
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
40
39
|
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
40
|
+
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
41
41
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
42
42
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
43
|
-
var require$$1__default$
|
|
43
|
+
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
44
44
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
45
45
|
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
46
|
-
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
47
|
-
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
48
|
-
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
49
|
-
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
50
46
|
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
51
47
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
52
|
-
var require$$0__default$
|
|
48
|
+
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
49
|
+
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
53
50
|
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
54
|
-
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
55
51
|
var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
|
|
52
|
+
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
53
|
+
var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
|
|
56
54
|
|
|
57
55
|
function getAugmentedNamespace(n) {
|
|
58
56
|
if (n.__esModule) return n;
|
|
@@ -72,6 +70,7 @@ function getAugmentedNamespace(n) {
|
|
|
72
70
|
var src$2 = {};
|
|
73
71
|
|
|
74
72
|
const chalk$3 = require$$0__default;
|
|
73
|
+
const moment = require$$1__default;
|
|
75
74
|
/**
|
|
76
75
|
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
77
76
|
*/
|
|
@@ -84,12 +83,12 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
84
83
|
* @returns {undefined} 无
|
|
85
84
|
*/
|
|
86
85
|
|
|
87
|
-
const fail$
|
|
86
|
+
const fail$8 = (message = '') => {
|
|
88
87
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
89
88
|
|
|
90
89
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
91
90
|
|
|
92
|
-
console.log(`${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
91
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
93
92
|
};
|
|
94
93
|
/**
|
|
95
94
|
* 打印绿底黑字格式的文字
|
|
@@ -103,7 +102,7 @@ const succeed$1 = (message = '') => {
|
|
|
103
102
|
|
|
104
103
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
105
104
|
|
|
106
|
-
console.log(`${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
105
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
107
106
|
};
|
|
108
107
|
/**
|
|
109
108
|
* 打印warn提示
|
|
@@ -112,24 +111,24 @@ const succeed$1 = (message = '') => {
|
|
|
112
111
|
*/
|
|
113
112
|
|
|
114
113
|
|
|
115
|
-
const warn = message => {
|
|
116
|
-
console.log(chalk$3.yellow(message));
|
|
114
|
+
const warn$1 = message => {
|
|
115
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
|
|
117
116
|
};
|
|
118
117
|
|
|
119
|
-
const info$9 = (...args) => console.log(...args);
|
|
118
|
+
const info$9 = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
120
119
|
|
|
121
120
|
var log$1 = {
|
|
122
|
-
fail: fail$
|
|
121
|
+
fail: fail$8,
|
|
123
122
|
succeed: succeed$1,
|
|
124
|
-
warn,
|
|
123
|
+
warn: warn$1,
|
|
125
124
|
info: info$9
|
|
126
125
|
};
|
|
127
126
|
|
|
128
127
|
const program$1 = require$$0__default$1;
|
|
129
|
-
const leven = require$$1__default;
|
|
128
|
+
const leven = require$$1__default$1;
|
|
130
129
|
const ora = require$$2__default;
|
|
131
|
-
const path$
|
|
132
|
-
const fs$
|
|
130
|
+
const path$b = require$$3__default;
|
|
131
|
+
const fs$c = require$$0__default$2;
|
|
133
132
|
const shelljs$6 = require$$0__default$3;
|
|
134
133
|
const {
|
|
135
134
|
info: info$8
|
|
@@ -142,8 +141,8 @@ const shelljsOptions = {
|
|
|
142
141
|
|
|
143
142
|
const cwd = process.cwd();
|
|
144
143
|
|
|
145
|
-
function resolve$
|
|
146
|
-
return path$
|
|
144
|
+
function resolve$e(...args) {
|
|
145
|
+
return path$b.resolve(cwd, ...args);
|
|
147
146
|
}
|
|
148
147
|
/**
|
|
149
148
|
* 用户输入命令时,进行提示
|
|
@@ -199,8 +198,8 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
199
198
|
const cwd = process.cwd();
|
|
200
199
|
return new Promise((resolve, reject) => {
|
|
201
200
|
// 如果目标目录不存在
|
|
202
|
-
if (fs$
|
|
203
|
-
shelljs$6.rm('-rf', path$
|
|
201
|
+
if (fs$c.existsSync(dest)) {
|
|
202
|
+
shelljs$6.rm('-rf', path$b.join(dest));
|
|
204
203
|
}
|
|
205
204
|
|
|
206
205
|
shelljs$6.mkdir('-p', dest);
|
|
@@ -251,7 +250,7 @@ function pullRepoForGit$1(dest, branch) {
|
|
|
251
250
|
|
|
252
251
|
function npmInstall$1(dir) {
|
|
253
252
|
return new Promise((resolve, reject) => {
|
|
254
|
-
shelljs$6.exec('
|
|
253
|
+
shelljs$6.exec('npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
255
254
|
cwd: dir,
|
|
256
255
|
silent: true
|
|
257
256
|
}, (code, stdout, stderr) => {
|
|
@@ -283,11 +282,11 @@ const cost = start => Date.now() - start;
|
|
|
283
282
|
function createTask$3(task, startText, endText) {
|
|
284
283
|
return async (...args) => {
|
|
285
284
|
const start = Date.now();
|
|
286
|
-
const spinner = ora(
|
|
285
|
+
const spinner = ora();
|
|
286
|
+
info$8(startText);
|
|
287
287
|
spinner.start();
|
|
288
|
-
info$8('\n');
|
|
289
288
|
const result = await task(...args);
|
|
290
|
-
endText && spinner.succeed(`${endText},
|
|
289
|
+
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
291
290
|
spinner.stop();
|
|
292
291
|
return result;
|
|
293
292
|
};
|
|
@@ -300,8 +299,24 @@ function createTask$3(task, startText, endText) {
|
|
|
300
299
|
|
|
301
300
|
const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
|
|
302
301
|
|
|
302
|
+
const mergeMap = function (obj, src) {
|
|
303
|
+
for (const [k, v] of src) {
|
|
304
|
+
if (obj.has(k)) {
|
|
305
|
+
obj.set(k, obj.get(k) + v);
|
|
306
|
+
} else {
|
|
307
|
+
obj.set(k, v);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return obj;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const relativeCwdPath$1 = function (file) {
|
|
315
|
+
return path$b.relative(process.cwd(), file);
|
|
316
|
+
};
|
|
317
|
+
|
|
303
318
|
var widgets = {
|
|
304
|
-
resolve: resolve$
|
|
319
|
+
resolve: resolve$e,
|
|
305
320
|
isObject: isObject$2,
|
|
306
321
|
isArray: isArray$1,
|
|
307
322
|
createTask: createTask$3,
|
|
@@ -309,37 +324,39 @@ var widgets = {
|
|
|
309
324
|
pullRepoForGit: pullRepoForGit$1,
|
|
310
325
|
suggestCommands: suggestCommands$1,
|
|
311
326
|
camelize,
|
|
312
|
-
npmInstall: npmInstall$1
|
|
327
|
+
npmInstall: npmInstall$1,
|
|
328
|
+
mergeMap,
|
|
329
|
+
relativeCwdPath: relativeCwdPath$1
|
|
313
330
|
};
|
|
314
331
|
|
|
315
|
-
const path$
|
|
332
|
+
const path$a = require('path');
|
|
316
333
|
|
|
317
334
|
const os = require('os'); // 用户目录
|
|
318
335
|
|
|
319
336
|
|
|
320
337
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
321
338
|
|
|
322
|
-
const CACHE_DIR$
|
|
339
|
+
const CACHE_DIR$2 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
323
340
|
|
|
324
|
-
const TEMPLATE_DIR$1 = path$
|
|
341
|
+
const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
325
342
|
|
|
326
|
-
const MODULE_CODE_DIR$
|
|
343
|
+
const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
|
|
327
344
|
|
|
328
|
-
const TEMPLATE_PATH$1 = path$
|
|
345
|
+
const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
329
346
|
|
|
330
|
-
const TMS_NAME$
|
|
347
|
+
const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
|
|
331
348
|
|
|
332
349
|
const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
|
|
333
350
|
const TMS_PRIVATE_FILENAME$1 = 'tms.private.config.js'; // 模块代码的默认在modules子目录
|
|
334
351
|
|
|
335
352
|
const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目录
|
|
336
353
|
|
|
337
|
-
const DEFAULT_CLOUD_MODULE_DIR
|
|
354
|
+
const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
338
355
|
|
|
339
|
-
const MODULE_CONFIG_FILENAME$
|
|
356
|
+
const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
|
|
340
357
|
|
|
341
358
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
342
|
-
app: path$
|
|
359
|
+
app: path$a.resolve(process.cwd(), 'app')
|
|
343
360
|
}; // 默认从源码拷贝到编译后的配置
|
|
344
361
|
|
|
345
362
|
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
|
|
@@ -353,42 +370,45 @@ const MODULE_CONFIG_INVALID_KEY$1 = ['entranceDeclare', 'entryPagePath'];
|
|
|
353
370
|
var constant = /*#__PURE__*/Object.freeze({
|
|
354
371
|
__proto__: null,
|
|
355
372
|
HOME_DIR: HOME_DIR,
|
|
356
|
-
CACHE_DIR: CACHE_DIR$
|
|
373
|
+
CACHE_DIR: CACHE_DIR$2,
|
|
357
374
|
TEMPLATE_DIR: TEMPLATE_DIR$1,
|
|
358
375
|
TEMPLATE_PATH: TEMPLATE_PATH$1,
|
|
359
|
-
TMS_NAME: TMS_NAME$
|
|
376
|
+
TMS_NAME: TMS_NAME$1,
|
|
360
377
|
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
|
|
361
378
|
TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME$1,
|
|
362
379
|
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
|
|
363
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$
|
|
380
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
364
381
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
365
382
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
366
|
-
MODULE_CODE_DIR: MODULE_CODE_DIR$
|
|
383
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
367
384
|
ENV: ENV,
|
|
368
385
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
369
386
|
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1,
|
|
370
|
-
DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
|
|
387
|
+
DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
|
|
371
388
|
});
|
|
372
389
|
|
|
373
390
|
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
374
391
|
|
|
375
|
-
const fs$
|
|
376
|
-
const path$
|
|
392
|
+
const fs$b = require$$0__default$2;
|
|
393
|
+
const path$9 = require$$3__default;
|
|
377
394
|
const {
|
|
378
395
|
info: info$7
|
|
379
396
|
} = log$1;
|
|
397
|
+
const {
|
|
398
|
+
relativeCwdPath
|
|
399
|
+
} = widgets;
|
|
380
400
|
/**
|
|
381
401
|
* 判断目录是否为空
|
|
382
402
|
* @param {string} dirname 目录名
|
|
383
403
|
* @returns
|
|
384
404
|
*/
|
|
385
405
|
|
|
386
|
-
const isDirEmpty = dirname => fs$
|
|
406
|
+
const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
387
407
|
|
|
388
408
|
|
|
389
409
|
const isFile = pathName => {
|
|
390
410
|
try {
|
|
391
|
-
const stat = fs$
|
|
411
|
+
const stat = fs$b.lstatSync(pathName);
|
|
392
412
|
return stat.isFile();
|
|
393
413
|
} catch {
|
|
394
414
|
return false;
|
|
@@ -401,8 +421,8 @@ const isFile = pathName => {
|
|
|
401
421
|
|
|
402
422
|
|
|
403
423
|
const ensureDirExist = dirname => {
|
|
404
|
-
if (!fs$
|
|
405
|
-
fs$
|
|
424
|
+
if (!fs$b.existsSync(dirname)) {
|
|
425
|
+
fs$b.mkdirSync(dirname, {
|
|
406
426
|
recursive: true
|
|
407
427
|
});
|
|
408
428
|
}
|
|
@@ -410,27 +430,27 @@ const ensureDirExist = dirname => {
|
|
|
410
430
|
|
|
411
431
|
|
|
412
432
|
const copyFile = function (src, dest) {
|
|
413
|
-
if (fs$
|
|
414
|
-
fs$
|
|
433
|
+
if (fs$b.existsSync(dest)) {
|
|
434
|
+
fs$b.unlinkSync(dest);
|
|
415
435
|
}
|
|
416
436
|
|
|
417
|
-
const dir = path$
|
|
437
|
+
const dir = path$9.dirname(dest);
|
|
418
438
|
ensureDirExist(dir);
|
|
419
|
-
fs$
|
|
439
|
+
fs$b.copyFileSync(src, dest);
|
|
420
440
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
421
441
|
|
|
422
442
|
|
|
423
443
|
function diffContentCopyFile$3(originFile, destFile) {
|
|
424
|
-
if (fs$
|
|
425
|
-
const depDestContent = fs$
|
|
426
|
-
const depOriginContent = fs$
|
|
444
|
+
if (fs$b.existsSync(destFile)) {
|
|
445
|
+
const depDestContent = fs$b.readFileSync(destFile, 'utf8');
|
|
446
|
+
const depOriginContent = fs$b.readFileSync(originFile, 'utf8');
|
|
427
447
|
|
|
428
448
|
if (depDestContent !== depOriginContent) {
|
|
429
|
-
info$7(`拷贝${originFile}内容到${destFile}`);
|
|
449
|
+
info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
430
450
|
copyFile(originFile, destFile);
|
|
431
451
|
}
|
|
432
452
|
} else {
|
|
433
|
-
info$7(`拷贝${originFile}内容到${destFile}`);
|
|
453
|
+
info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
434
454
|
copyFile(originFile, destFile);
|
|
435
455
|
}
|
|
436
456
|
} // 添加后缀
|
|
@@ -441,7 +461,7 @@ function ext$3(filePath, extensions) {
|
|
|
441
461
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
442
462
|
|
|
443
463
|
try {
|
|
444
|
-
const stat = fs$
|
|
464
|
+
const stat = fs$b.lstatSync(newFilePath);
|
|
445
465
|
|
|
446
466
|
if (stat.isDirectory()) {
|
|
447
467
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -452,7 +472,7 @@ function ext$3(filePath, extensions) {
|
|
|
452
472
|
for (const ext of extensions) {
|
|
453
473
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
454
474
|
|
|
455
|
-
if (fs$
|
|
475
|
+
if (fs$b.existsSync(file)) {
|
|
456
476
|
return {
|
|
457
477
|
ext,
|
|
458
478
|
extPath: extPath + ext,
|
|
@@ -470,11 +490,11 @@ function ext$3(filePath, extensions) {
|
|
|
470
490
|
|
|
471
491
|
|
|
472
492
|
const fileInDir$3 = (dir, file) => {
|
|
473
|
-
if (!fs$
|
|
493
|
+
if (!fs$b.existsSync(dir) || !fs$b.existsSync(file)) {
|
|
474
494
|
return false;
|
|
475
495
|
}
|
|
476
496
|
|
|
477
|
-
const relativePath = path$
|
|
497
|
+
const relativePath = path$9.relative(dir, file);
|
|
478
498
|
|
|
479
499
|
if (relativePath.startsWith('..')) {
|
|
480
500
|
return false;
|
|
@@ -494,7 +514,7 @@ var io$2 = {
|
|
|
494
514
|
};
|
|
495
515
|
|
|
496
516
|
const async = require$$0__default$4;
|
|
497
|
-
const ejs = require$$1__default$
|
|
517
|
+
const ejs = require$$1__default$2;
|
|
498
518
|
|
|
499
519
|
const render$1 = (files, metalsmith, next) => {
|
|
500
520
|
const keys = Object.keys(files);
|
|
@@ -513,10 +533,10 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
513
533
|
|
|
514
534
|
var render_1 = render$1;
|
|
515
535
|
|
|
516
|
-
const fs$
|
|
517
|
-
const inquirer = require$$1__default$
|
|
536
|
+
const fs$a = require$$0__default$2;
|
|
537
|
+
const inquirer = require$$1__default$3;
|
|
518
538
|
const {
|
|
519
|
-
resolve: resolve$
|
|
539
|
+
resolve: resolve$d
|
|
520
540
|
} = widgets;
|
|
521
541
|
const {
|
|
522
542
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
@@ -530,12 +550,12 @@ const {
|
|
|
530
550
|
const parseTemplateQuestions = dir => {
|
|
531
551
|
let prompts = [];
|
|
532
552
|
|
|
533
|
-
if (!fs$
|
|
553
|
+
if (!fs$a.existsSync(`${dir}/questions.json`)) {
|
|
534
554
|
return prompts;
|
|
535
555
|
}
|
|
536
556
|
|
|
537
557
|
try {
|
|
538
|
-
const json = JSON.parse(fs$
|
|
558
|
+
const json = JSON.parse(fs$a.readFileSync(`${dir}/questions.json`));
|
|
539
559
|
|
|
540
560
|
if (Array.isArray(json) && json.length > 0) {
|
|
541
561
|
json.forEach((item, index) => {
|
|
@@ -568,7 +588,7 @@ const isQuestionType = result => {
|
|
|
568
588
|
};
|
|
569
589
|
|
|
570
590
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
571
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
591
|
+
const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
572
592
|
const metadata = metalsmith.metadata();
|
|
573
593
|
const filteredPrompts = prompts.filter(prompt => {
|
|
574
594
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -610,8 +630,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
610
630
|
|
|
611
631
|
var generator_1 = generator$1;
|
|
612
632
|
|
|
613
|
-
const path$
|
|
614
|
-
const fs$
|
|
633
|
+
const path$8 = require$$3__default;
|
|
634
|
+
const fs$9 = require$$0__default$2;
|
|
615
635
|
const shelljs$5 = require$$0__default$3;
|
|
616
636
|
const {
|
|
617
637
|
TEMPLATE_DIR,
|
|
@@ -621,11 +641,11 @@ const {
|
|
|
621
641
|
const {
|
|
622
642
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
623
643
|
createTask: createTask$2,
|
|
624
|
-
resolve: resolve$
|
|
644
|
+
resolve: resolve$c
|
|
625
645
|
} = widgets;
|
|
626
646
|
const io$1 = io$2;
|
|
627
647
|
const {
|
|
628
|
-
fail: fail$
|
|
648
|
+
fail: fail$7,
|
|
629
649
|
succeed,
|
|
630
650
|
info: info$6
|
|
631
651
|
} = log$1;
|
|
@@ -638,9 +658,9 @@ const generator = generator_1;
|
|
|
638
658
|
|
|
639
659
|
async function createAppDir(targetDir) {
|
|
640
660
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
641
|
-
if (fs$
|
|
661
|
+
if (fs$9.existsSync(targetDir)) {
|
|
642
662
|
if (!(await io$1.isDirEmpty(targetDir))) {
|
|
643
|
-
fail$
|
|
663
|
+
fail$7('该目录名已经存在,换个项目名字吧~');
|
|
644
664
|
process.exit(1);
|
|
645
665
|
}
|
|
646
666
|
} else {
|
|
@@ -656,7 +676,7 @@ async function createAppDir(targetDir) {
|
|
|
656
676
|
|
|
657
677
|
async function create(appName) {
|
|
658
678
|
const cwd = process.cwd();
|
|
659
|
-
const targetDir = path$
|
|
679
|
+
const targetDir = path$8.resolve(cwd, appName);
|
|
660
680
|
const appType = 'mp';
|
|
661
681
|
await createAppDir(targetDir); // 创建缓存目录
|
|
662
682
|
|
|
@@ -664,13 +684,13 @@ async function create(appName) {
|
|
|
664
684
|
|
|
665
685
|
await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
666
686
|
|
|
667
|
-
generator(path$
|
|
687
|
+
generator(path$8.join(TEMPLATE_PATH, appType), targetDir, {
|
|
668
688
|
appName,
|
|
669
689
|
appType
|
|
670
690
|
}).then(() => {
|
|
671
691
|
shelljs$5.cd(appName);
|
|
672
692
|
|
|
673
|
-
const hooks = require(resolve$
|
|
693
|
+
const hooks = require(resolve$c(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
674
694
|
|
|
675
695
|
if (hooks.afterCreate) {
|
|
676
696
|
hooks.afterCreate.forEach(item => {
|
|
@@ -684,10 +704,10 @@ async function create(appName) {
|
|
|
684
704
|
});
|
|
685
705
|
}
|
|
686
706
|
|
|
687
|
-
shelljs$5.rm('-rf', resolve$
|
|
707
|
+
shelljs$5.rm('-rf', resolve$c(appName, TEMPLATE_TKIT_DIR));
|
|
688
708
|
succeed('项目创建完成.');
|
|
689
709
|
}).catch(err => {
|
|
690
|
-
fail$
|
|
710
|
+
fail$7(err.message);
|
|
691
711
|
info$6('详细的错误信息:', err);
|
|
692
712
|
});
|
|
693
713
|
}
|
|
@@ -717,33 +737,32 @@ var defaultTmsConfig$1 = {
|
|
|
717
737
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
718
738
|
*/
|
|
719
739
|
const loadash = require$$0__default$6;
|
|
720
|
-
const fs$
|
|
740
|
+
const fs$8 = require$$0__default$2;
|
|
721
741
|
const {
|
|
722
|
-
TMS_NAME: TMS_NAME$1,
|
|
723
742
|
TMS_CONFIG_FILENAME,
|
|
724
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$
|
|
743
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
725
744
|
TMS_PRIVATE_FILENAME
|
|
726
745
|
} = require$$4;
|
|
727
746
|
const {
|
|
728
|
-
resolve: resolve$
|
|
747
|
+
resolve: resolve$b,
|
|
729
748
|
isObject: isObject$1,
|
|
730
749
|
isArray
|
|
731
750
|
} = widgets;
|
|
732
751
|
const defaultTmsConfig = defaultTmsConfig$1;
|
|
733
752
|
const {
|
|
734
|
-
fail: fail$
|
|
753
|
+
fail: fail$6
|
|
735
754
|
} = log$1;
|
|
736
|
-
const path$
|
|
755
|
+
const path$7 = require$$3__default;
|
|
737
756
|
/**
|
|
738
757
|
* 读取tms.config.js
|
|
739
758
|
* @param env {string} 环境变量
|
|
740
759
|
*/
|
|
741
760
|
|
|
742
761
|
const readTmsConfig$1 = function (env) {
|
|
743
|
-
const tmsConfigPath = resolve$
|
|
762
|
+
const tmsConfigPath = resolve$b(TMS_CONFIG_FILENAME);
|
|
744
763
|
|
|
745
|
-
if (!fs$
|
|
746
|
-
fail$
|
|
764
|
+
if (!fs$8.existsSync(tmsConfigPath)) {
|
|
765
|
+
fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
747
766
|
process.exit(1);
|
|
748
767
|
}
|
|
749
768
|
|
|
@@ -768,14 +787,14 @@ const convertModules = modules => {
|
|
|
768
787
|
if (typeof module === 'string') {
|
|
769
788
|
// 路径字符串
|
|
770
789
|
Object.assign(newModule, {
|
|
771
|
-
name: path$
|
|
790
|
+
name: path$7.basename(module),
|
|
772
791
|
path: module
|
|
773
792
|
});
|
|
774
793
|
} else if (typeof module === 'object') {
|
|
775
794
|
Object.assign(newModule, module);
|
|
776
795
|
|
|
777
796
|
if (module.name === undefined) {
|
|
778
|
-
newModule.name = path$
|
|
797
|
+
newModule.name = path$7.basename(module.path);
|
|
779
798
|
}
|
|
780
799
|
}
|
|
781
800
|
|
|
@@ -790,9 +809,9 @@ const convertModules = modules => {
|
|
|
790
809
|
|
|
791
810
|
const readTmsPrivateCf$1 = function () {
|
|
792
811
|
let tmsPrivateCf = {};
|
|
793
|
-
const tmsPrivatePath = resolve$
|
|
812
|
+
const tmsPrivatePath = resolve$b(TMS_PRIVATE_FILENAME);
|
|
794
813
|
|
|
795
|
-
if (fs$
|
|
814
|
+
if (fs$8.existsSync(tmsPrivatePath)) {
|
|
796
815
|
tmsPrivateCf = require(tmsPrivatePath);
|
|
797
816
|
} // 处理modules字段
|
|
798
817
|
|
|
@@ -813,7 +832,7 @@ const readTmsPrivateCf$1 = function () {
|
|
|
813
832
|
*/
|
|
814
833
|
|
|
815
834
|
|
|
816
|
-
const checkModules$1 = function (tmsConfig, modules) {
|
|
835
|
+
const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
|
|
817
836
|
const targetModules = [];
|
|
818
837
|
modules.forEach(moduleName => {
|
|
819
838
|
const module = tmsConfig.modules.find(module => module.name === moduleName);
|
|
@@ -821,8 +840,9 @@ const checkModules$1 = function (tmsConfig, modules) {
|
|
|
821
840
|
});
|
|
822
841
|
|
|
823
842
|
if (targetModules.length === 0) {
|
|
824
|
-
fail$
|
|
825
|
-
|
|
843
|
+
fail$6(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
|
|
844
|
+
>name字段与module.config.json的name字段是否一致`);
|
|
845
|
+
isQuit && process.exit(1);
|
|
826
846
|
}
|
|
827
847
|
|
|
828
848
|
return targetModules;
|
|
@@ -883,10 +903,10 @@ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
|
|
|
883
903
|
modules.forEach(({
|
|
884
904
|
path
|
|
885
905
|
}) => {
|
|
886
|
-
const moduleConfigPath = resolve$
|
|
906
|
+
const moduleConfigPath = resolve$b(path, moduleConfigFilename);
|
|
887
907
|
|
|
888
|
-
if (fs$
|
|
889
|
-
const content = fs$
|
|
908
|
+
if (fs$8.existsSync(moduleConfigPath)) {
|
|
909
|
+
const content = fs$8.readFileSync(moduleConfigPath, 'utf-8');
|
|
890
910
|
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
891
911
|
}
|
|
892
912
|
});
|
|
@@ -907,12 +927,12 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
907
927
|
path: relativePath,
|
|
908
928
|
name: moduleName
|
|
909
929
|
}, moduleIndex) => {
|
|
910
|
-
const moduleConfigPath = resolve$
|
|
930
|
+
const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
911
931
|
|
|
912
|
-
if (fs$
|
|
932
|
+
if (fs$8.existsSync(moduleConfigPath)) {
|
|
913
933
|
try {
|
|
914
934
|
let findModule = false;
|
|
915
|
-
let moduleConfigContent = fs$
|
|
935
|
+
let moduleConfigContent = fs$8.readFileSync(moduleConfigPath, 'utf-8');
|
|
916
936
|
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
917
937
|
const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
918
938
|
getValidModules$1(moduleContentArr).forEach(({
|
|
@@ -927,11 +947,11 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
927
947
|
});
|
|
928
948
|
|
|
929
949
|
if (!findModule) {
|
|
930
|
-
fail$
|
|
950
|
+
fail$6(`启动模块${moduleName}在${moduleConfigPath}没有找到或pages为空,请检查配置`);
|
|
931
951
|
process.exit(1);
|
|
932
952
|
}
|
|
933
953
|
} catch (e) {
|
|
934
|
-
fail$
|
|
954
|
+
fail$6(`${moduleConfigPath}配置错误: ${e}`);
|
|
935
955
|
newModules.push({ ...modules[moduleIndex]
|
|
936
956
|
});
|
|
937
957
|
}
|
|
@@ -967,10 +987,13 @@ const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
|
|
|
967
987
|
// 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
|
|
968
988
|
// 否则递归处理,根据name找到相关配置加到modules里
|
|
969
989
|
if (moduleNames.indexOf(item) === -1) {
|
|
970
|
-
isOver = false;
|
|
971
990
|
const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
|
|
972
|
-
|
|
973
|
-
|
|
991
|
+
|
|
992
|
+
if (tmpModules.length > 0) {
|
|
993
|
+
isOver = false;
|
|
994
|
+
mergeModules = [...mergeModules, ...tmpModules];
|
|
995
|
+
mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
|
|
996
|
+
}
|
|
974
997
|
}
|
|
975
998
|
});
|
|
976
999
|
});
|
|
@@ -987,7 +1010,7 @@ var tmsMpconfig = {
|
|
|
987
1010
|
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
988
1011
|
};
|
|
989
1012
|
|
|
990
|
-
const global$
|
|
1013
|
+
const global$6 = {
|
|
991
1014
|
data: {},
|
|
992
1015
|
|
|
993
1016
|
setData(...args) {
|
|
@@ -1009,38 +1032,38 @@ const global$5 = {
|
|
|
1009
1032
|
|
|
1010
1033
|
};
|
|
1011
1034
|
var global_1 = {
|
|
1012
|
-
global: global$
|
|
1035
|
+
global: global$6
|
|
1013
1036
|
};
|
|
1014
1037
|
|
|
1015
1038
|
const {
|
|
1016
|
-
fail: fail$
|
|
1039
|
+
fail: fail$5
|
|
1017
1040
|
} = log$1;
|
|
1018
1041
|
const {
|
|
1019
|
-
global: global$
|
|
1042
|
+
global: global$5
|
|
1020
1043
|
} = global_1;
|
|
1021
1044
|
|
|
1022
|
-
function handleError$
|
|
1045
|
+
function handleError$4(error) {
|
|
1023
1046
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1024
|
-
const isDev = global$
|
|
1047
|
+
const isDev = global$5.getData('isDev');
|
|
1025
1048
|
|
|
1026
1049
|
if (isDev) {
|
|
1027
|
-
fail$
|
|
1050
|
+
fail$5(errMsg);
|
|
1028
1051
|
} else {
|
|
1029
|
-
fail$
|
|
1052
|
+
fail$5(errMsg);
|
|
1030
1053
|
process.exit(1);
|
|
1031
1054
|
}
|
|
1032
1055
|
}
|
|
1033
1056
|
|
|
1034
1057
|
var handleError_1 = {
|
|
1035
|
-
handleError: handleError$
|
|
1058
|
+
handleError: handleError$4
|
|
1036
1059
|
};
|
|
1037
1060
|
|
|
1038
1061
|
/**
|
|
1039
1062
|
* 生成编译后的app.json
|
|
1040
1063
|
*/
|
|
1041
|
-
const fs$
|
|
1064
|
+
const fs$7 = require$$0__default$2;
|
|
1042
1065
|
const {
|
|
1043
|
-
MODULE_CONFIG_FILENAME
|
|
1066
|
+
MODULE_CONFIG_FILENAME,
|
|
1044
1067
|
MODULE_CONFIG_INVALID_KEY
|
|
1045
1068
|
} = require$$4;
|
|
1046
1069
|
const {
|
|
@@ -1048,14 +1071,14 @@ const {
|
|
|
1048
1071
|
getValidModules
|
|
1049
1072
|
} = tmsMpconfig;
|
|
1050
1073
|
const {
|
|
1051
|
-
fail: fail$
|
|
1074
|
+
fail: fail$4
|
|
1052
1075
|
} = log$1;
|
|
1053
1076
|
const {
|
|
1054
|
-
resolve: resolve$
|
|
1077
|
+
resolve: resolve$a,
|
|
1055
1078
|
isObject
|
|
1056
1079
|
} = widgets;
|
|
1057
1080
|
const {
|
|
1058
|
-
handleError: handleError$
|
|
1081
|
+
handleError: handleError$3
|
|
1059
1082
|
} = handleError_1;
|
|
1060
1083
|
/**
|
|
1061
1084
|
* 更新appJson里面的主包配置
|
|
@@ -1075,7 +1098,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1075
1098
|
|
|
1076
1099
|
foundMainPackages.forEach(subpackage => {
|
|
1077
1100
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
1078
|
-
fail$
|
|
1101
|
+
fail$4(`主包 ${subpackage} 不能没有 pages`);
|
|
1079
1102
|
process.exit(-1);
|
|
1080
1103
|
}
|
|
1081
1104
|
|
|
@@ -1101,12 +1124,12 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1101
1124
|
|
|
1102
1125
|
|
|
1103
1126
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
1104
|
-
if (!fs$
|
|
1105
|
-
fail$
|
|
1127
|
+
if (!fs$7.existsSync(sourceAppJsonPath)) {
|
|
1128
|
+
fail$4(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1106
1129
|
process.exit(1);
|
|
1107
1130
|
}
|
|
1108
1131
|
|
|
1109
|
-
const appJson = JSON.parse(fs$
|
|
1132
|
+
const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1110
1133
|
|
|
1111
1134
|
appJson.subpackages = [];
|
|
1112
1135
|
appJson.pages = []; // appJson.plugins = {};
|
|
@@ -1176,7 +1199,7 @@ const fixAppJson = appJson => {
|
|
|
1176
1199
|
});
|
|
1177
1200
|
|
|
1178
1201
|
if (invalidKeys.length) {
|
|
1179
|
-
fail$
|
|
1202
|
+
fail$4(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
1180
1203
|
} // eslint-disable-next-line
|
|
1181
1204
|
|
|
1182
1205
|
|
|
@@ -1193,7 +1216,7 @@ const fixAppJson = appJson => {
|
|
|
1193
1216
|
}).reduce((pre, cur) => pre + cur, '');
|
|
1194
1217
|
|
|
1195
1218
|
if (pluginsErrMsg) {
|
|
1196
|
-
fail$
|
|
1219
|
+
fail$4(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1197
1220
|
} // eslint-disable-next-line
|
|
1198
1221
|
|
|
1199
1222
|
|
|
@@ -1209,20 +1232,29 @@ const fixAppJson = appJson => {
|
|
|
1209
1232
|
|
|
1210
1233
|
function buildOutputAppJson$1(tmsConfig, modules) {
|
|
1211
1234
|
try {
|
|
1235
|
+
var _tmsConfig$hooks;
|
|
1236
|
+
|
|
1212
1237
|
// 获取当前 modules 下的所有子模块的配置内容
|
|
1213
|
-
const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME
|
|
1238
|
+
const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1214
1239
|
|
|
1215
|
-
const appJson = getAppJsonContent(resolve$
|
|
1240
|
+
const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
|
|
1216
1241
|
|
|
1217
1242
|
updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
|
|
1218
1243
|
|
|
1219
1244
|
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1220
1245
|
|
|
1221
1246
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1222
|
-
fs$
|
|
1247
|
+
fs$7.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1248
|
+
|
|
1249
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1250
|
+
var _tmsConfig$hooks2;
|
|
1251
|
+
|
|
1252
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson(appJson);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1223
1255
|
return appJson;
|
|
1224
1256
|
} catch (e) {
|
|
1225
|
-
handleError$
|
|
1257
|
+
handleError$3(`生成app.json出现错误: ${e}`);
|
|
1226
1258
|
}
|
|
1227
1259
|
}
|
|
1228
1260
|
|
|
@@ -1230,63 +1262,27 @@ var buildAppJson = {
|
|
|
1230
1262
|
buildOutputAppJson: buildOutputAppJson$1
|
|
1231
1263
|
};
|
|
1232
1264
|
|
|
1233
|
-
const fs$8 = require$$0__default$2;
|
|
1234
|
-
const {
|
|
1235
|
-
resolve: resolve$a
|
|
1236
|
-
} = widgets;
|
|
1237
|
-
const {
|
|
1238
|
-
handleError: handleError$3
|
|
1239
|
-
} = handleError_1;
|
|
1240
|
-
const {
|
|
1241
|
-
DEFAULT_CLOUD_MODULE_DIR
|
|
1242
|
-
} = require$$4;
|
|
1243
|
-
/**
|
|
1244
|
-
* 根据相关配置创建软链接
|
|
1245
|
-
* @param { object } tmsConfig
|
|
1246
|
-
*/
|
|
1247
|
-
|
|
1248
|
-
const symLink$1 = tmsConfig => {
|
|
1249
|
-
try {
|
|
1250
|
-
if (tmsConfig.cloudModules) {
|
|
1251
|
-
tmsConfig.cloudModules.forEach(item => {
|
|
1252
|
-
const path = resolve$a(DEFAULT_CLOUD_MODULE_DIR, item.name);
|
|
1253
|
-
fs$8.access(path, fs$8.constants.F_OK, res => {
|
|
1254
|
-
if (res) {
|
|
1255
|
-
fs$8.symlinkSync(resolve$a(item.path), path);
|
|
1256
|
-
}
|
|
1257
|
-
});
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
} catch (e) {
|
|
1261
|
-
handleError$3(`创建软链错误: ${e}`);
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
|
|
1265
|
-
var symbolicLink = {
|
|
1266
|
-
symLink: symLink$1
|
|
1267
|
-
};
|
|
1268
|
-
|
|
1269
1265
|
/**
|
|
1270
1266
|
* 下载第三方代码
|
|
1271
1267
|
*/
|
|
1272
1268
|
const MetalSmith = require$$0__default$5;
|
|
1273
|
-
const crypto$1 = require$$1__default$
|
|
1269
|
+
const crypto$1 = require$$1__default$4;
|
|
1274
1270
|
const {
|
|
1275
1271
|
downloadRepoForGit,
|
|
1276
1272
|
pullRepoForGit,
|
|
1277
1273
|
resolve: resolve$9
|
|
1278
1274
|
} = widgets;
|
|
1279
1275
|
const {
|
|
1280
|
-
fail: fail$
|
|
1276
|
+
fail: fail$3,
|
|
1281
1277
|
info: info$5
|
|
1282
1278
|
} = log$1;
|
|
1283
|
-
const fs$
|
|
1279
|
+
const fs$6 = require$$0__default$2;
|
|
1284
1280
|
const shelljs$4 = require$$0__default$3;
|
|
1285
1281
|
const {
|
|
1286
1282
|
handleError: handleError$2
|
|
1287
1283
|
} = handleError_1;
|
|
1288
1284
|
const {
|
|
1289
|
-
global: global$
|
|
1285
|
+
global: global$4
|
|
1290
1286
|
} = global_1;
|
|
1291
1287
|
/**
|
|
1292
1288
|
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
@@ -1296,15 +1292,15 @@ const {
|
|
|
1296
1292
|
*/
|
|
1297
1293
|
|
|
1298
1294
|
function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
1299
|
-
var _tmsPrivateCf$gitAcco;
|
|
1295
|
+
var _tmsPrivateCf$gitAcco, _tmsPrivateCf$gitAcco2;
|
|
1300
1296
|
|
|
1301
1297
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1302
|
-
const tmsPrivateCf = global$
|
|
1298
|
+
const tmsPrivateCf = global$4.getData('tmsPrivateCf');
|
|
1303
1299
|
let gitUrl = httpRepoUrl;
|
|
1304
1300
|
const {
|
|
1305
1301
|
username = '',
|
|
1306
1302
|
pass = ''
|
|
1307
|
-
} = (tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : (_tmsPrivateCf$gitAcco = tmsPrivateCf.gitAccout) === null || _tmsPrivateCf$gitAcco === void 0 ? void 0 : _tmsPrivateCf$gitAcco[moduleName]) || {};
|
|
1303
|
+
} = (tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : (_tmsPrivateCf$gitAcco = tmsPrivateCf.gitAccout) === null || _tmsPrivateCf$gitAcco === void 0 ? void 0 : _tmsPrivateCf$gitAcco[moduleName]) || (tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : (_tmsPrivateCf$gitAcco2 = tmsPrivateCf.gitAccount) === null || _tmsPrivateCf$gitAcco2 === void 0 ? void 0 : _tmsPrivateCf$gitAcco2[moduleName]) || {};
|
|
1308
1304
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
1309
1305
|
|
|
1310
1306
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -1327,7 +1323,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1327
1323
|
return new Promise((resolve, reject) => {
|
|
1328
1324
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1329
1325
|
if (e) {
|
|
1330
|
-
fail$
|
|
1326
|
+
fail$3(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1331
1327
|
reject(e);
|
|
1332
1328
|
}
|
|
1333
1329
|
|
|
@@ -1359,7 +1355,8 @@ function md5ByGitUrlBranch(gitUrl, branch) {
|
|
|
1359
1355
|
|
|
1360
1356
|
|
|
1361
1357
|
async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
1362
|
-
// 收集下载模块代码的任务
|
|
1358
|
+
const cwd = process.cwd(); // 收集下载模块代码的任务
|
|
1359
|
+
|
|
1363
1360
|
const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules); // 开始执行下载和移动代码的任务
|
|
1364
1361
|
|
|
1365
1362
|
const arrPromises = [];
|
|
@@ -1379,6 +1376,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1379
1376
|
}));
|
|
1380
1377
|
});
|
|
1381
1378
|
await Promise.all(arrPromises);
|
|
1379
|
+
shelljs$4.cd(cwd);
|
|
1382
1380
|
}
|
|
1383
1381
|
/**
|
|
1384
1382
|
* 收集下载模块代码的任务
|
|
@@ -1431,7 +1429,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1431
1429
|
targetPath
|
|
1432
1430
|
},
|
|
1433
1431
|
fn: async (sourceModulePath, targetPath) => {
|
|
1434
|
-
if (fs$
|
|
1432
|
+
if (fs$6.existsSync(targetPath)) {
|
|
1435
1433
|
shelljs$4.rm('-rf', `${targetPath}/*`);
|
|
1436
1434
|
}
|
|
1437
1435
|
|
|
@@ -1446,14 +1444,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1446
1444
|
} else {
|
|
1447
1445
|
let promiseTask;
|
|
1448
1446
|
|
|
1449
|
-
if (fs$
|
|
1447
|
+
if (fs$6.existsSync(sourcePath) && fs$6.existsSync(`${sourcePath}/.git`)) {
|
|
1450
1448
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1451
|
-
info$5(`git pull
|
|
1449
|
+
info$5(`git pull:${httpRepoUrl}`);
|
|
1452
1450
|
return pullRepoForGit(sourcePath, branch);
|
|
1453
1451
|
};
|
|
1454
1452
|
} else {
|
|
1455
1453
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1456
|
-
info$5(`git clone
|
|
1454
|
+
info$5(`git clone: ${httpRepoUrl}`);
|
|
1457
1455
|
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
1458
1456
|
};
|
|
1459
1457
|
}
|
|
@@ -1482,7 +1480,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1482
1480
|
*/
|
|
1483
1481
|
|
|
1484
1482
|
|
|
1485
|
-
function checkRemoteModGitUrlBranch
|
|
1483
|
+
function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
1486
1484
|
if (moduleInfo.repoInfo) {
|
|
1487
1485
|
const {
|
|
1488
1486
|
repoInfo: {
|
|
@@ -1494,7 +1492,7 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
|
|
|
1494
1492
|
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
|
|
1495
1493
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1496
1494
|
|
|
1497
|
-
if (!fs$
|
|
1495
|
+
if (!fs$6.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1498
1496
|
return true;
|
|
1499
1497
|
}
|
|
1500
1498
|
}
|
|
@@ -1504,11 +1502,11 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
|
|
|
1504
1502
|
|
|
1505
1503
|
var cloneModules_1 = {
|
|
1506
1504
|
cloneModules: cloneModules$1,
|
|
1507
|
-
checkRemoteModGitUrlBranch
|
|
1505
|
+
checkRemoteModGitUrlBranch
|
|
1508
1506
|
};
|
|
1509
1507
|
|
|
1510
1508
|
const ci = require$$0__default$7;
|
|
1511
|
-
const path$
|
|
1509
|
+
const path$6 = require$$3__default;
|
|
1512
1510
|
/**
|
|
1513
1511
|
* 获取小程序ci的Project对象
|
|
1514
1512
|
* @returns {Object} 小程序ci对象
|
|
@@ -1522,7 +1520,7 @@ const getMpCi = ({
|
|
|
1522
1520
|
}) => {
|
|
1523
1521
|
var _cfgJsonContent$packO;
|
|
1524
1522
|
|
|
1525
|
-
const cfgJsonContent = require(path$
|
|
1523
|
+
const cfgJsonContent = require(path$6.join(projectPath, 'project.config.json'));
|
|
1526
1524
|
|
|
1527
1525
|
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
1528
1526
|
value
|
|
@@ -1532,7 +1530,7 @@ const getMpCi = ({
|
|
|
1532
1530
|
privateKey,
|
|
1533
1531
|
type,
|
|
1534
1532
|
projectPath,
|
|
1535
|
-
ignores: ['node_modules/**/*', ...ignores]
|
|
1533
|
+
ignores: ['node_modules/**/*', 'cloud/**/*', ...ignores]
|
|
1536
1534
|
});
|
|
1537
1535
|
}; // 用小程序ci工具构建小程序
|
|
1538
1536
|
|
|
@@ -1591,10 +1589,10 @@ var mpCi = {
|
|
|
1591
1589
|
/**
|
|
1592
1590
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1593
1591
|
*/
|
|
1594
|
-
const fs$
|
|
1595
|
-
const fsExtra = require$$1__default$
|
|
1596
|
-
const crypto = require$$1__default$
|
|
1597
|
-
const path$
|
|
1592
|
+
const fs$5 = require$$0__default$2;
|
|
1593
|
+
const fsExtra = require$$1__default$5;
|
|
1594
|
+
const crypto = require$$1__default$4;
|
|
1595
|
+
const path$5 = require$$3__default;
|
|
1598
1596
|
const shell = require$$0__default$3;
|
|
1599
1597
|
const glob = require$$5__default;
|
|
1600
1598
|
const log = log$1;
|
|
@@ -1604,9 +1602,6 @@ const {
|
|
|
1604
1602
|
const {
|
|
1605
1603
|
handleError: handleError$1
|
|
1606
1604
|
} = handleError_1;
|
|
1607
|
-
const {
|
|
1608
|
-
info: info$4
|
|
1609
|
-
} = require$$9__default;
|
|
1610
1605
|
const shellJsOption = {
|
|
1611
1606
|
async: false,
|
|
1612
1607
|
silent: true
|
|
@@ -1629,7 +1624,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1629
1624
|
const npmTasksMap = new Map();
|
|
1630
1625
|
|
|
1631
1626
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1632
|
-
const packageContent = fs$
|
|
1627
|
+
const packageContent = fs$5.readFileSync(packageJsonPath);
|
|
1633
1628
|
const packageJson = JSON.parse(packageContent);
|
|
1634
1629
|
const md5Obj = {
|
|
1635
1630
|
dependencies: packageJson.dependencies || {}
|
|
@@ -1637,14 +1632,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1637
1632
|
|
|
1638
1633
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1639
1634
|
const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1640
|
-
const cacheNMPath = path$
|
|
1641
|
-
const cacheNMTarFile = path$
|
|
1635
|
+
const cacheNMPath = path$5.join(cacheDir, md5Key);
|
|
1636
|
+
const cacheNMTarFile = path$5.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1642
1637
|
|
|
1643
1638
|
const callback = {
|
|
1644
1639
|
params: {
|
|
1645
1640
|
cacheNMPath,
|
|
1646
1641
|
cacheNMTarFile,
|
|
1647
|
-
packageJsonDir: path$
|
|
1642
|
+
packageJsonDir: path$5.dirname(packageJsonPath),
|
|
1648
1643
|
shell
|
|
1649
1644
|
},
|
|
1650
1645
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
@@ -1653,8 +1648,9 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1653
1648
|
const newShellJsOption = { ...shellJsOption,
|
|
1654
1649
|
cwd: packageJsonDir
|
|
1655
1650
|
};
|
|
1656
|
-
shell.
|
|
1657
|
-
shell.exec('
|
|
1651
|
+
shell.cd(packageJsonDir);
|
|
1652
|
+
shell.exec('tar -xvf ./node_modules.tar.gz -C ./', newShellJsOption);
|
|
1653
|
+
shell.rm('-rf', './node_modules.tar.gz');
|
|
1658
1654
|
}
|
|
1659
1655
|
};
|
|
1660
1656
|
|
|
@@ -1671,13 +1667,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1671
1667
|
promiseTask = (packageJsonPath, cacheNMPath, shell) => {
|
|
1672
1668
|
fsExtra.emptydirSync(cacheNMPath);
|
|
1673
1669
|
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
1674
|
-
info
|
|
1670
|
+
log.info(`npm install: ${packageJsonPath}`);
|
|
1675
1671
|
return npmInstall(cacheNMPath).then(() => {
|
|
1676
1672
|
const newShellJsOption = { ...shellJsOption,
|
|
1677
1673
|
cwd: cacheNMPath
|
|
1678
1674
|
};
|
|
1679
|
-
shell.
|
|
1680
|
-
shell.exec('
|
|
1675
|
+
shell.cd(cacheNMPath);
|
|
1676
|
+
shell.exec('tar -cvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
|
|
1677
|
+
shell.rm('-rf', './node_modules');
|
|
1681
1678
|
});
|
|
1682
1679
|
};
|
|
1683
1680
|
}
|
|
@@ -1700,6 +1697,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1700
1697
|
|
|
1701
1698
|
|
|
1702
1699
|
const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
1700
|
+
const cwd = process.cwd();
|
|
1703
1701
|
const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
|
|
1704
1702
|
|
|
1705
1703
|
const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir); // 开始执行npm install和回调(移动)的任务
|
|
@@ -1721,6 +1719,7 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
|
1721
1719
|
}));
|
|
1722
1720
|
});
|
|
1723
1721
|
await Promise.all(arrPromises);
|
|
1722
|
+
shell.cd(cwd);
|
|
1724
1723
|
};
|
|
1725
1724
|
/**
|
|
1726
1725
|
* 递归查找指定条件的文件
|
|
@@ -1741,7 +1740,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1741
1740
|
|
|
1742
1741
|
const find = (startPath, filter) => {
|
|
1743
1742
|
// 目录不存在
|
|
1744
|
-
if (!fs$
|
|
1743
|
+
if (!fs$5.existsSync(startPath)) {
|
|
1745
1744
|
log.fail(`${startPath}目录不存在`);
|
|
1746
1745
|
process.exit(-1);
|
|
1747
1746
|
return;
|
|
@@ -1754,10 +1753,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1754
1753
|
return;
|
|
1755
1754
|
}
|
|
1756
1755
|
|
|
1757
|
-
const files = fs$
|
|
1756
|
+
const files = fs$5.readdirSync(startPath);
|
|
1758
1757
|
files.forEach(file => {
|
|
1759
|
-
const filename = path$
|
|
1760
|
-
const stat = fs$
|
|
1758
|
+
const filename = path$5.join(startPath, file);
|
|
1759
|
+
const stat = fs$5.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1761
1760
|
|
|
1762
1761
|
if (stat.isDirectory()) {
|
|
1763
1762
|
find(filename, filter);
|
|
@@ -1783,7 +1782,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1783
1782
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1784
1783
|
|
|
1785
1784
|
const cwd = contextDir || dirPath;
|
|
1786
|
-
const result = [path$
|
|
1785
|
+
const result = [path$5.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1787
1786
|
|
|
1788
1787
|
subRoots.forEach(subRoot => {
|
|
1789
1788
|
if (!subRoot.root) {
|
|
@@ -1791,7 +1790,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1791
1790
|
process.exit(1);
|
|
1792
1791
|
}
|
|
1793
1792
|
|
|
1794
|
-
const toppath = path$
|
|
1793
|
+
const toppath = path$5.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1795
1794
|
|
|
1796
1795
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1797
1796
|
result.push(...list);
|
|
@@ -1799,7 +1798,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1799
1798
|
return result;
|
|
1800
1799
|
};
|
|
1801
1800
|
|
|
1802
|
-
function cloudNpmInstall
|
|
1801
|
+
function cloudNpmInstall(contextDir) {
|
|
1803
1802
|
return new Promise((resolve, reject) => {
|
|
1804
1803
|
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
1805
1804
|
if (err) {
|
|
@@ -1807,7 +1806,7 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1807
1806
|
}
|
|
1808
1807
|
|
|
1809
1808
|
files.forEach(file => {
|
|
1810
|
-
const dir = path$
|
|
1809
|
+
const dir = path$5.dirname(file);
|
|
1811
1810
|
shell.cd(dir);
|
|
1812
1811
|
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1813
1812
|
silent: false
|
|
@@ -1819,7 +1818,7 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1819
1818
|
}
|
|
1820
1819
|
|
|
1821
1820
|
var npm = {
|
|
1822
|
-
cloudNpmInstall
|
|
1821
|
+
cloudNpmInstall,
|
|
1823
1822
|
mpNpmInstallAll: mpNpmInstallAll$1,
|
|
1824
1823
|
findAllPackageJson
|
|
1825
1824
|
};
|
|
@@ -1832,47 +1831,133 @@ const {
|
|
|
1832
1831
|
buildMpNpm
|
|
1833
1832
|
} = mpCi;
|
|
1834
1833
|
const {
|
|
1835
|
-
CACHE_DIR
|
|
1834
|
+
CACHE_DIR: CACHE_DIR$1
|
|
1836
1835
|
} = require$$4;
|
|
1837
1836
|
const {
|
|
1838
|
-
cloudNpmInstall,
|
|
1839
1837
|
mpNpmInstallAll
|
|
1840
1838
|
} = npm;
|
|
1841
1839
|
const {
|
|
1842
|
-
global: global$
|
|
1840
|
+
global: global$3
|
|
1843
1841
|
} = global_1;
|
|
1844
1842
|
|
|
1845
|
-
async function install$2(tmsConfig, modules
|
|
1843
|
+
async function install$2(tmsConfig, modules) {
|
|
1846
1844
|
// 小程序npm install
|
|
1847
|
-
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
|
|
1848
|
-
const tmsPrivateCf = global$
|
|
1845
|
+
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
1846
|
+
const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1849
1847
|
|
|
1850
1848
|
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1851
1849
|
appId: tmsConfig.appId,
|
|
1852
1850
|
projectPath: resolve$8('./'),
|
|
1853
1851
|
privateKey: tmsPrivateCf.privateKey
|
|
1854
|
-
});
|
|
1855
|
-
|
|
1856
|
-
isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$8(tmsConfig.cloudDir));
|
|
1852
|
+
});
|
|
1857
1853
|
}
|
|
1858
1854
|
|
|
1859
1855
|
var install_1 = install$2;
|
|
1860
1856
|
|
|
1857
|
+
const fs$4 = require$$0__default$2;
|
|
1858
|
+
const semver$1 = require$$1__default$6;
|
|
1859
|
+
const {
|
|
1860
|
+
resolve: resolve$7
|
|
1861
|
+
} = widgets;
|
|
1862
|
+
const path$4 = require$$3__default;
|
|
1861
1863
|
const shelljs$3 = require$$0__default$3;
|
|
1862
|
-
const
|
|
1864
|
+
const {
|
|
1865
|
+
handleError
|
|
1866
|
+
} = handleError_1;
|
|
1867
|
+
|
|
1868
|
+
const getLatestVersion = npmName => {
|
|
1869
|
+
const data = shelljs$3.exec(`npm view ${npmName} version`);
|
|
1870
|
+
return data.stdout || '0.0.0';
|
|
1871
|
+
};
|
|
1872
|
+
/**
|
|
1873
|
+
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
1874
|
+
* @param {*} modules 模块
|
|
1875
|
+
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
1876
|
+
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
1877
|
+
* @returns
|
|
1878
|
+
*/
|
|
1879
|
+
|
|
1880
|
+
|
|
1881
|
+
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
1882
|
+
// 步骤1. 收集package.json
|
|
1883
|
+
const packageJsonName = 'package.json'; // 查找文件名
|
|
1884
|
+
// 1.1根目录的package.json
|
|
1885
|
+
|
|
1886
|
+
const packageArr = [{
|
|
1887
|
+
srcPackageDir: path$4.join(cwd, packageJsonName),
|
|
1888
|
+
destNpmDir: resolve$7(outputDir, 'node_modules')
|
|
1889
|
+
}]; // 1.2模块的package.json
|
|
1890
|
+
|
|
1891
|
+
modules.forEach(item => {
|
|
1892
|
+
const srcPackageDir = path$4.join(cwd, item.path, 'package.json');
|
|
1893
|
+
|
|
1894
|
+
if (fs$4.existsSync(srcPackageDir)) {
|
|
1895
|
+
packageArr.push({
|
|
1896
|
+
srcPackageDir,
|
|
1897
|
+
destNpmDir: resolve$7(outputDir, item.root, 'node_modules')
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1901
|
+
|
|
1902
|
+
for (const item of packageArr) {
|
|
1903
|
+
const packageJson = fs$4.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1904
|
+
let dependencies = {};
|
|
1905
|
+
|
|
1906
|
+
try {
|
|
1907
|
+
const json = JSON.parse(packageJson);
|
|
1908
|
+
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
1909
|
+
} catch (e) {
|
|
1910
|
+
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
const dependenciesKeys = Object.keys(dependencies);
|
|
1914
|
+
|
|
1915
|
+
for (const key of dependenciesKeys) {
|
|
1916
|
+
const depPath = path$4.join(item.destNpmDir, key);
|
|
1917
|
+
|
|
1918
|
+
if (!fs$4.existsSync(depPath)) {
|
|
1919
|
+
return true;
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
const depPackagePath = path$4.join(depPath, 'package.json');
|
|
1923
|
+
|
|
1924
|
+
if (fs$4.existsSync(depPackagePath)) {
|
|
1925
|
+
const packageData = require(depPackagePath);
|
|
1926
|
+
|
|
1927
|
+
if (dependencies[key] === 'latest') {
|
|
1928
|
+
dependencies[key] = getLatestVersion(key);
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
if (packageData.version === 'latest') {
|
|
1932
|
+
packageData.version = getLatestVersion(key);
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
|
|
1936
|
+
return true;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
return false;
|
|
1943
|
+
};
|
|
1944
|
+
|
|
1945
|
+
var checkDependencies_1 = {
|
|
1946
|
+
checkDependencies: checkDependencies$1
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
const shelljs$2 = require$$0__default$3;
|
|
1950
|
+
const fs$3 = require$$0__default$2;
|
|
1863
1951
|
const io = io$2;
|
|
1864
1952
|
const {
|
|
1865
|
-
resolve: resolve$
|
|
1953
|
+
resolve: resolve$6,
|
|
1866
1954
|
createTask
|
|
1867
1955
|
} = widgets;
|
|
1868
1956
|
const {
|
|
1869
1957
|
buildOutputAppJson
|
|
1870
1958
|
} = buildAppJson;
|
|
1871
1959
|
const {
|
|
1872
|
-
|
|
1873
|
-
} = symbolicLink;
|
|
1874
|
-
const {
|
|
1875
|
-
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
1960
|
+
MODULE_CODE_DIR,
|
|
1876
1961
|
DEFAULT_COPY_CONFIG
|
|
1877
1962
|
} = require$$4;
|
|
1878
1963
|
const {
|
|
@@ -1883,10 +1968,13 @@ const {
|
|
|
1883
1968
|
subModulesMergeDepModules: subModulesMergeDepModules$1
|
|
1884
1969
|
} = tmsMpconfig;
|
|
1885
1970
|
const {
|
|
1886
|
-
fail: fail$
|
|
1887
|
-
info: info$
|
|
1971
|
+
fail: fail$2,
|
|
1972
|
+
info: info$4
|
|
1888
1973
|
} = log$1;
|
|
1889
1974
|
const install$1 = install_1;
|
|
1975
|
+
const {
|
|
1976
|
+
checkDependencies
|
|
1977
|
+
} = checkDependencies_1;
|
|
1890
1978
|
/**
|
|
1891
1979
|
* 拷贝相关配置文件到编译输出目录
|
|
1892
1980
|
* @param { object } tmsConfig
|
|
@@ -1896,42 +1984,66 @@ const install$1 = install_1;
|
|
|
1896
1984
|
*/
|
|
1897
1985
|
|
|
1898
1986
|
const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
1899
|
-
const outputDir = resolve$
|
|
1987
|
+
const outputDir = resolve$6(tmsConfig.outputDir);
|
|
1900
1988
|
io.ensureDirExist(outputDir);
|
|
1901
1989
|
defaultFiles.forEach(item => {
|
|
1902
|
-
if (fs$
|
|
1903
|
-
shelljs$
|
|
1990
|
+
if (fs$3.existsSync(resolve$6(item))) {
|
|
1991
|
+
shelljs$2.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
|
|
1904
1992
|
}
|
|
1905
1993
|
}); // 拷贝模块的package.json到编译输出目录
|
|
1906
1994
|
|
|
1907
1995
|
targetModules.forEach(item => {
|
|
1908
|
-
const outputModuleDir = resolve$
|
|
1996
|
+
const outputModuleDir = resolve$6(`${tmsConfig.outputDir}/${item.root}`);
|
|
1909
1997
|
|
|
1910
|
-
if (!fs$
|
|
1911
|
-
fail$
|
|
1998
|
+
if (!fs$3.existsSync(resolve$6(item.path))) {
|
|
1999
|
+
fail$2(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1912
2000
|
process.exit(1);
|
|
1913
2001
|
}
|
|
1914
2002
|
|
|
1915
2003
|
io.ensureDirExist(outputModuleDir);
|
|
1916
|
-
const modulePackagePath = resolve$
|
|
1917
|
-
if (fs$
|
|
2004
|
+
const modulePackagePath = resolve$6(item.path, 'package.json');
|
|
2005
|
+
if (fs$3.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1918
2006
|
});
|
|
1919
2007
|
};
|
|
2008
|
+
/**
|
|
2009
|
+
* 校验相关配置项
|
|
2010
|
+
* @param {*} targetModules
|
|
2011
|
+
* @returns
|
|
2012
|
+
*/
|
|
2013
|
+
|
|
2014
|
+
|
|
2015
|
+
function checkConfig(targetModules) {
|
|
2016
|
+
for (const item of targetModules) {
|
|
2017
|
+
if (!item.root) {
|
|
2018
|
+
throw new Error(`检查${item.name} module.config.json的root字段`);
|
|
2019
|
+
} // 判断源码目录是否有该模块
|
|
2020
|
+
|
|
2021
|
+
|
|
2022
|
+
if (item.path && !fs$3.existsSync(resolve$6(item.path))) {
|
|
2023
|
+
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
return true;
|
|
2028
|
+
}
|
|
1920
2029
|
|
|
1921
2030
|
async function task(tmsConfig, targetModules) {
|
|
1922
2031
|
// 下载和移动代码
|
|
1923
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR
|
|
2032
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1924
2033
|
|
|
1925
2034
|
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
1926
2035
|
|
|
1927
|
-
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2036
|
+
newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
|
|
2037
|
+
checkConfig(newModules); // 拷贝相关配置文件到输出目录
|
|
1928
2038
|
|
|
1929
2039
|
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
|
|
1930
2040
|
|
|
1931
|
-
|
|
2041
|
+
if (checkDependencies(newModules, resolve$6('./'), tmsConfig.outputDir)) {
|
|
2042
|
+
await install$1(tmsConfig, newModules);
|
|
2043
|
+
} // 动态生成编译后的app.json;
|
|
2044
|
+
|
|
1932
2045
|
|
|
1933
2046
|
await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
1934
|
-
await createTask(symLink, '开始创建软链接', '创建软链接完成')(tmsConfig);
|
|
1935
2047
|
return newModules;
|
|
1936
2048
|
}
|
|
1937
2049
|
|
|
@@ -1943,8 +2055,8 @@ async function init$5(tmsConfig, targetModules) {
|
|
|
1943
2055
|
};
|
|
1944
2056
|
} catch (error) {
|
|
1945
2057
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1946
|
-
fail$
|
|
1947
|
-
info$
|
|
2058
|
+
fail$2(`初始化流程出现错误${errMsg}`);
|
|
2059
|
+
info$4('详细的错误信息', error);
|
|
1948
2060
|
process.exit(1);
|
|
1949
2061
|
}
|
|
1950
2062
|
}
|
|
@@ -1989,16 +2101,16 @@ var findCssImport = {
|
|
|
1989
2101
|
|
|
1990
2102
|
/* eslint-disable no-param-reassign */
|
|
1991
2103
|
const {
|
|
1992
|
-
fail: fail$
|
|
2104
|
+
fail: fail$1
|
|
1993
2105
|
} = log$1;
|
|
1994
2106
|
|
|
1995
2107
|
function pluginError$3(error, isWatch) {
|
|
1996
2108
|
const errMsg = error.message;
|
|
1997
2109
|
|
|
1998
2110
|
if (isWatch) {
|
|
1999
|
-
fail$
|
|
2111
|
+
fail$1(errMsg);
|
|
2000
2112
|
} else {
|
|
2001
|
-
fail$
|
|
2113
|
+
fail$1(errMsg);
|
|
2002
2114
|
process.exit(1);
|
|
2003
2115
|
}
|
|
2004
2116
|
}
|
|
@@ -2009,7 +2121,7 @@ var pluginError_1 = {
|
|
|
2009
2121
|
|
|
2010
2122
|
/* eslint-disable no-param-reassign */
|
|
2011
2123
|
const through$2 = require$$0__default$9;
|
|
2012
|
-
const precinct = require$$1__default$
|
|
2124
|
+
const precinct = require$$1__default$7;
|
|
2013
2125
|
const path$3 = require$$3__default;
|
|
2014
2126
|
const {
|
|
2015
2127
|
findCssImports
|
|
@@ -2020,9 +2132,9 @@ const {
|
|
|
2020
2132
|
diffContentCopyFile: diffContentCopyFile$2
|
|
2021
2133
|
} = io$2;
|
|
2022
2134
|
const {
|
|
2023
|
-
resolve: resolve$
|
|
2135
|
+
resolve: resolve$5
|
|
2024
2136
|
} = widgets;
|
|
2025
|
-
const fs$
|
|
2137
|
+
const fs$2 = require$$0__default$2;
|
|
2026
2138
|
const {
|
|
2027
2139
|
pluginError: pluginError$2
|
|
2028
2140
|
} = pluginError_1;
|
|
@@ -2035,7 +2147,7 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2035
2147
|
let contents = '';
|
|
2036
2148
|
|
|
2037
2149
|
try {
|
|
2038
|
-
contents = fs$
|
|
2150
|
+
contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
|
|
2039
2151
|
} catch (e) {
|
|
2040
2152
|
pluginError$2(e, isWatch);
|
|
2041
2153
|
}
|
|
@@ -2052,12 +2164,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2052
2164
|
extPath
|
|
2053
2165
|
} = ext$2(depOriginPath, extensions);
|
|
2054
2166
|
|
|
2055
|
-
if (!fs$
|
|
2167
|
+
if (!fs$2.existsSync(depOriginFile)) {
|
|
2056
2168
|
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2057
2169
|
return;
|
|
2058
2170
|
}
|
|
2059
2171
|
|
|
2060
|
-
const depDestPath = resolve$
|
|
2172
|
+
const depDestPath = resolve$5(path$3.dirname(anaFileDestFile), depItem);
|
|
2061
2173
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2062
2174
|
|
|
2063
2175
|
if (!resDep.has(depDestFile)) {
|
|
@@ -2081,8 +2193,8 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2081
2193
|
const stream = through$2.obj(function (file, enc, cb) {
|
|
2082
2194
|
// 依赖分析的文件
|
|
2083
2195
|
const anaFileOriginFile = file.history[0];
|
|
2084
|
-
const anaFileRelativeModule = path$3.relative(resolve$
|
|
2085
|
-
const anaFileDestFile = resolve$
|
|
2196
|
+
const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2197
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2086
2198
|
|
|
2087
2199
|
if (file.isBuffer()) {
|
|
2088
2200
|
let contents = String(file.contents);
|
|
@@ -2111,7 +2223,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2111
2223
|
const regRes = depItem.match(reg) || [];
|
|
2112
2224
|
|
|
2113
2225
|
if (regRes[2]) {
|
|
2114
|
-
const depDestPath = resolve$
|
|
2226
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2115
2227
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2116
2228
|
|
|
2117
2229
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2164,9 +2276,9 @@ const {
|
|
|
2164
2276
|
diffContentCopyFile: diffContentCopyFile$1
|
|
2165
2277
|
} = io$2;
|
|
2166
2278
|
const {
|
|
2167
|
-
resolve: resolve$
|
|
2279
|
+
resolve: resolve$4
|
|
2168
2280
|
} = widgets;
|
|
2169
|
-
const fs$
|
|
2281
|
+
const fs$1 = require$$0__default$2;
|
|
2170
2282
|
const {
|
|
2171
2283
|
pluginError: pluginError$1
|
|
2172
2284
|
} = pluginError_1;
|
|
@@ -2178,8 +2290,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2178
2290
|
const stream = through$1.obj(function (file, enc, cb) {
|
|
2179
2291
|
// 当前分析的文件的路径
|
|
2180
2292
|
const anaFileOriginFile = file.history[0];
|
|
2181
|
-
const anaFileRelativeModule = path$2.relative(resolve$
|
|
2182
|
-
const anaFileDestFile = resolve$
|
|
2293
|
+
const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
|
|
2294
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2183
2295
|
|
|
2184
2296
|
if (file.isBuffer()) {
|
|
2185
2297
|
let contents = String(file.contents);
|
|
@@ -2218,7 +2330,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2218
2330
|
const regRes = componentPath.match(reg) || [];
|
|
2219
2331
|
|
|
2220
2332
|
if (regRes[2]) {
|
|
2221
|
-
const depDestPath = resolve$
|
|
2333
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2222
2334
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2223
2335
|
|
|
2224
2336
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2252,7 +2364,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2252
2364
|
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2253
2365
|
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2254
2366
|
|
|
2255
|
-
if (fs$
|
|
2367
|
+
if (fs$1.existsSync(originFile)) {
|
|
2256
2368
|
diffContentCopyFile$1(originFile, destFile);
|
|
2257
2369
|
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2258
2370
|
|
|
@@ -2285,8 +2397,8 @@ var mpJsonDep_1 = {
|
|
|
2285
2397
|
|
|
2286
2398
|
/* eslint-disable no-param-reassign */
|
|
2287
2399
|
const through = require$$0__default$9;
|
|
2288
|
-
const htmlparser2 = require$$1__default$
|
|
2289
|
-
const fs
|
|
2400
|
+
const htmlparser2 = require$$1__default$8;
|
|
2401
|
+
const fs = require$$0__default$2;
|
|
2290
2402
|
const path$1 = require$$3__default;
|
|
2291
2403
|
const {
|
|
2292
2404
|
diffContentCopyFile,
|
|
@@ -2294,7 +2406,7 @@ const {
|
|
|
2294
2406
|
fileInDir
|
|
2295
2407
|
} = io$2;
|
|
2296
2408
|
const {
|
|
2297
|
-
resolve: resolve$
|
|
2409
|
+
resolve: resolve$3
|
|
2298
2410
|
} = widgets;
|
|
2299
2411
|
const {
|
|
2300
2412
|
dfsFindCommonDep
|
|
@@ -2333,7 +2445,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2333
2445
|
let contents = '';
|
|
2334
2446
|
|
|
2335
2447
|
try {
|
|
2336
|
-
contents = fs
|
|
2448
|
+
contents = fs.readFileSync(anaFileOriginFile, 'utf8');
|
|
2337
2449
|
} catch (e) {
|
|
2338
2450
|
pluginError(e, isWatch);
|
|
2339
2451
|
}
|
|
@@ -2351,7 +2463,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2351
2463
|
extPath
|
|
2352
2464
|
} = extFile(name, depOriginPath);
|
|
2353
2465
|
|
|
2354
|
-
if (!fs
|
|
2466
|
+
if (!fs.existsSync(depOriginFile)) {
|
|
2355
2467
|
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2356
2468
|
return;
|
|
2357
2469
|
}
|
|
@@ -2408,8 +2520,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2408
2520
|
const stream = through.obj(function (file, enc, cb) {
|
|
2409
2521
|
// 依赖分析的文件
|
|
2410
2522
|
const anaFileOriginFile = file.history[0];
|
|
2411
|
-
const anaFileRelativeModule = path$1.relative(resolve$
|
|
2412
|
-
const anaFileDestFile = resolve$
|
|
2523
|
+
const anaFileRelativeModule = path$1.relative(resolve$3(module.from), anaFileOriginFile);
|
|
2524
|
+
const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2413
2525
|
|
|
2414
2526
|
if (file.isBuffer()) {
|
|
2415
2527
|
let contents = String(file.contents);
|
|
@@ -2440,7 +2552,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2440
2552
|
const regRes = attributes.src.match(reg) || [];
|
|
2441
2553
|
|
|
2442
2554
|
if (regRes[2]) {
|
|
2443
|
-
const depDestPath = resolve$
|
|
2555
|
+
const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2444
2556
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2445
2557
|
|
|
2446
2558
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2467,7 +2579,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2467
2579
|
beforeDepPath,
|
|
2468
2580
|
afterDepPath
|
|
2469
2581
|
}) => {
|
|
2470
|
-
if (fs
|
|
2582
|
+
if (fs.existsSync(depOriginFile)) {
|
|
2471
2583
|
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2472
2584
|
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2473
2585
|
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
@@ -2505,11 +2617,9 @@ var mpWxmlDep_1 = {
|
|
|
2505
2617
|
|
|
2506
2618
|
const {
|
|
2507
2619
|
src: src$1,
|
|
2508
|
-
dest
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
const px2rpx = require$$1__default$7;
|
|
2512
|
-
const watch = require$$2__default$1; // const cache = require('gulp-cache');
|
|
2620
|
+
dest
|
|
2621
|
+
} = require$$0__default$a; // const px2rpx = require('gulp-px-to-rpx');
|
|
2622
|
+
// const cache = require('gulp-cache');
|
|
2513
2623
|
// const image = require('gulp-image');
|
|
2514
2624
|
// const replaceEnv = require('./plugins/replaceEnv');
|
|
2515
2625
|
|
|
@@ -2525,88 +2635,201 @@ const {
|
|
|
2525
2635
|
// const base64 = require('./plugins/postcss-font-base64');
|
|
2526
2636
|
|
|
2527
2637
|
const {
|
|
2528
|
-
fail
|
|
2529
|
-
} = log$1;
|
|
2530
|
-
|
|
2531
|
-
const since = task => file => lastRun(task) > file.stat.ctime ? lastRun(task) : 0;
|
|
2638
|
+
fail
|
|
2639
|
+
} = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
2532
2640
|
|
|
2533
2641
|
var compile = function (tmsConfig, {
|
|
2534
2642
|
glob,
|
|
2535
2643
|
destPath,
|
|
2536
2644
|
srcOption,
|
|
2537
2645
|
module,
|
|
2538
|
-
|
|
2539
|
-
events: ['change', 'add', 'unlink']
|
|
2540
|
-
},
|
|
2541
|
-
isWatch
|
|
2646
|
+
isDev
|
|
2542
2647
|
}) {
|
|
2648
|
+
const compileTasksMap = new Map();
|
|
2543
2649
|
Object.keys(glob).forEach(globKey => {
|
|
2544
2650
|
const globValue = glob[globKey];
|
|
2545
2651
|
|
|
2546
|
-
const task = () => src$1(globValue, { ...srcOption,
|
|
2547
|
-
since: since(task)
|
|
2548
|
-
});
|
|
2549
|
-
|
|
2550
|
-
let srcPipe = task();
|
|
2551
|
-
|
|
2552
|
-
if (isWatch) {
|
|
2553
|
-
srcPipe = srcPipe.pipe(watch(globValue, watchOption));
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
2652
|
switch (globKey) {
|
|
2557
2653
|
case 'js':
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2654
|
+
compileTasksMap.set(globValue, {
|
|
2655
|
+
module,
|
|
2656
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2657
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2658
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2659
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2660
|
+
});
|
|
2661
|
+
return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
2662
|
+
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
|
|
2663
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
2664
|
+
}).pipe(dest(newDestPath, {
|
|
2665
|
+
overwrite: true
|
|
2666
|
+
})).on('error', err => {
|
|
2667
|
+
fail(`js编译报错${err}`);
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2561
2670
|
});
|
|
2562
2671
|
break;
|
|
2563
2672
|
|
|
2564
2673
|
case 'wxss':
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2674
|
+
compileTasksMap.set(globValue, {
|
|
2675
|
+
module,
|
|
2676
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2677
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2678
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2679
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2680
|
+
});
|
|
2681
|
+
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
|
|
2682
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
2683
|
+
}) // .pipe(postcss([base64()]))
|
|
2684
|
+
// .on('error', (err) => {
|
|
2685
|
+
// fail(`postcss编译报错${err}`);
|
|
2686
|
+
// })
|
|
2687
|
+
// .pipe(px2rpx({
|
|
2688
|
+
// designWidth: 375, // 设计稿宽度,默认为750
|
|
2689
|
+
// precision: 2, // 小数最大精度,默认为6
|
|
2690
|
+
// }))
|
|
2691
|
+
.pipe(dest(newDestPath)).on('error', err => {
|
|
2692
|
+
fail(`wxss编译报错${err}`);
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
});
|
|
2577
2696
|
break;
|
|
2578
2697
|
|
|
2579
2698
|
case 'json':
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2699
|
+
compileTasksMap.set(globValue, {
|
|
2700
|
+
module,
|
|
2701
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2702
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2703
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2704
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2705
|
+
});
|
|
2706
|
+
return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
|
|
2707
|
+
fail(`mpJsonDep编译报错${err}`);
|
|
2708
|
+
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2709
|
+
fail(`json编译报错${err}`);
|
|
2710
|
+
});
|
|
2711
|
+
}
|
|
2712
|
+
});
|
|
2583
2713
|
break;
|
|
2584
2714
|
|
|
2585
2715
|
case 'wxml':
|
|
2586
|
-
|
|
2716
|
+
compileTasksMap.set(globValue, {
|
|
2717
|
+
module,
|
|
2718
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2719
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2720
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2721
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2722
|
+
});
|
|
2723
|
+
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
|
|
2724
|
+
fail(`mpWxmlDep编译报错${err}`);
|
|
2725
|
+
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2726
|
+
fail(`wxml编译报错${err}`);
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
});
|
|
2587
2730
|
break;
|
|
2588
2731
|
|
|
2589
2732
|
case 'image':
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2733
|
+
compileTasksMap.set(globValue, {
|
|
2734
|
+
module,
|
|
2735
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2736
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2737
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2738
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2739
|
+
});
|
|
2740
|
+
return srcPipe // .pipe(cache(image()))
|
|
2741
|
+
// .on('error', (err) => {
|
|
2742
|
+
// fail(`image编译报错${err}`);
|
|
2743
|
+
// })
|
|
2744
|
+
.pipe(dest(newDestPath)).on('error', err => {
|
|
2745
|
+
fail(`image编译报错${err}`);
|
|
2746
|
+
});
|
|
2747
|
+
}
|
|
2748
|
+
});
|
|
2595
2749
|
break;
|
|
2596
2750
|
|
|
2597
2751
|
case 'other':
|
|
2598
|
-
|
|
2752
|
+
compileTasksMap.set(globValue, {
|
|
2753
|
+
module,
|
|
2754
|
+
taskFn: (sourceFile, targetPath) => {
|
|
2755
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2756
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
2757
|
+
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2758
|
+
});
|
|
2759
|
+
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
2760
|
+
fail(`编译报错${err}`);
|
|
2761
|
+
});
|
|
2762
|
+
}
|
|
2763
|
+
});
|
|
2599
2764
|
break;
|
|
2600
2765
|
}
|
|
2601
2766
|
});
|
|
2767
|
+
return compileTasksMap;
|
|
2768
|
+
};
|
|
2769
|
+
|
|
2770
|
+
const watch = require$$0__default$b;
|
|
2771
|
+
const path = require$$3__default;
|
|
2772
|
+
const shellJs = require$$0__default$3;
|
|
2773
|
+
const {
|
|
2774
|
+
info: info$3,
|
|
2775
|
+
warn
|
|
2776
|
+
} = log$1;
|
|
2777
|
+
const {
|
|
2778
|
+
resolve: resolve$2
|
|
2779
|
+
} = widgets;
|
|
2780
|
+
const {
|
|
2781
|
+
global: global$2
|
|
2782
|
+
} = global_1;
|
|
2783
|
+
const TIP_MAP = {
|
|
2784
|
+
'package.json': '若依赖有变动,请重新执行tmskit run dev',
|
|
2785
|
+
'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效'
|
|
2786
|
+
};
|
|
2787
|
+
|
|
2788
|
+
const logTip = (fileName, tipMap) => {
|
|
2789
|
+
// eslint-disable-next-line
|
|
2790
|
+
for (const item in tipMap) {
|
|
2791
|
+
if (fileName.indexOf(item) > -1) {
|
|
2792
|
+
warn(`${fileName}有更新, ${tipMap[item]}`);
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
info$3(`${fileName}有更新`);
|
|
2798
|
+
};
|
|
2799
|
+
|
|
2800
|
+
var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
2801
|
+
watch(globValue, { // readDelay: 100,
|
|
2802
|
+
...watchOptions
|
|
2803
|
+
}, vinyl => {
|
|
2804
|
+
const sourceFile = vinyl.history[0];
|
|
2805
|
+
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
2806
|
+
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
2807
|
+
const tmsConfig = global$2.getData('tmsConfig');
|
|
2808
|
+
const sourceFileRelativeModule = path.relative(resolve$2(module.from), sourceFile);
|
|
2809
|
+
const targetFile = resolve$2(tmsConfig.outputDir, module.to, sourceFileRelativeModule);
|
|
2810
|
+
|
|
2811
|
+
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
2812
|
+
info$3(`删除${sourceFileName}`);
|
|
2813
|
+
shellJs.rm('-rf', targetFile);
|
|
2814
|
+
return;
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
logTip(sourceFileName, TIP_MAP);
|
|
2818
|
+
return callback([sourceFile], path.dirname(targetFile));
|
|
2819
|
+
});
|
|
2602
2820
|
};
|
|
2603
2821
|
|
|
2604
2822
|
(function (module) {
|
|
2605
2823
|
const path = require$$3__default;
|
|
2606
2824
|
const fs = require$$0__default$2;
|
|
2607
|
-
const
|
|
2825
|
+
const ora = require$$2__default;
|
|
2826
|
+
const {
|
|
2827
|
+
parallel,
|
|
2828
|
+
series
|
|
2829
|
+
} = require$$0__default$a;
|
|
2608
2830
|
const {
|
|
2609
|
-
resolve
|
|
2831
|
+
resolve,
|
|
2832
|
+
mergeMap
|
|
2610
2833
|
} = widgets;
|
|
2611
2834
|
const {
|
|
2612
2835
|
buildOutputAppJson
|
|
@@ -2615,6 +2838,11 @@ var compile = function (tmsConfig, {
|
|
|
2615
2838
|
DEFAULT_COPY_CONFIG
|
|
2616
2839
|
} = require$$4;
|
|
2617
2840
|
const compile$1 = compile;
|
|
2841
|
+
const watch = watch_1;
|
|
2842
|
+
const {
|
|
2843
|
+
info
|
|
2844
|
+
} = log$1;
|
|
2845
|
+
const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
|
|
2618
2846
|
|
|
2619
2847
|
function excludeGlob(glob) {
|
|
2620
2848
|
const otherArr = new Set();
|
|
@@ -2644,36 +2872,38 @@ var compile = function (tmsConfig, {
|
|
|
2644
2872
|
return newPath;
|
|
2645
2873
|
}
|
|
2646
2874
|
|
|
2647
|
-
module.exports = async (tmsConfig, newModules,
|
|
2648
|
-
// 监听app.json
|
|
2649
|
-
|
|
2650
|
-
|
|
2875
|
+
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
2876
|
+
const compileTasksMap = new Map(); // 监听app.json
|
|
2877
|
+
|
|
2878
|
+
if (isDev) {
|
|
2879
|
+
watch([resolve('app.json')], {
|
|
2651
2880
|
ignoreInitial: false,
|
|
2652
|
-
events:
|
|
2653
|
-
}, () => {
|
|
2654
|
-
|
|
2881
|
+
events: watchEvents
|
|
2882
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
2883
|
+
from: resolve(),
|
|
2884
|
+
to: resolve(tmsConfig.outputDir)
|
|
2655
2885
|
});
|
|
2656
2886
|
} else {
|
|
2657
|
-
buildOutputAppJson(tmsConfig, newModules,
|
|
2887
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
2658
2888
|
} // 监听根目录的文件
|
|
2659
2889
|
|
|
2660
2890
|
|
|
2661
|
-
compile$1(tmsConfig, {
|
|
2891
|
+
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
2662
2892
|
glob: {
|
|
2663
2893
|
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)) // wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
2664
2894
|
// js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
2665
2895
|
|
|
2666
2896
|
},
|
|
2667
2897
|
module: {
|
|
2668
|
-
from:
|
|
2669
|
-
to:
|
|
2898
|
+
from: resolve(),
|
|
2899
|
+
to: resolve(tmsConfig.outputDir)
|
|
2670
2900
|
},
|
|
2671
2901
|
destPath: resolve(tmsConfig.outputDir),
|
|
2672
2902
|
srcOption: {
|
|
2673
2903
|
allowEmpty: true
|
|
2674
2904
|
},
|
|
2675
|
-
|
|
2676
|
-
}); // 监听模块的文件
|
|
2905
|
+
isDev
|
|
2906
|
+
})); // 监听模块的文件
|
|
2677
2907
|
|
|
2678
2908
|
for (let module of newModules) {
|
|
2679
2909
|
// 处理默认参数
|
|
@@ -2682,26 +2912,27 @@ var compile = function (tmsConfig, {
|
|
|
2682
2912
|
},
|
|
2683
2913
|
...module
|
|
2684
2914
|
};
|
|
2915
|
+
const modulePath = adaptPath(module.path);
|
|
2685
2916
|
|
|
2686
|
-
if (
|
|
2917
|
+
if (isDev) {
|
|
2687
2918
|
// 监听模块配置文件
|
|
2688
|
-
watch(`${
|
|
2689
|
-
events:
|
|
2690
|
-
}, () => {
|
|
2691
|
-
|
|
2919
|
+
watch([`${modulePath}/**/module.config.json`], {
|
|
2920
|
+
events: watchEvents
|
|
2921
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
2922
|
+
from: modulePath,
|
|
2923
|
+
to: modulePath
|
|
2692
2924
|
});
|
|
2693
2925
|
}
|
|
2694
2926
|
|
|
2695
2927
|
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
2696
|
-
const modulePath = adaptPath(module.path);
|
|
2697
2928
|
const glob = {
|
|
2698
2929
|
js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
2699
|
-
json: [`${modulePath}/**/*.json`, ...excludes],
|
|
2930
|
+
json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
|
|
2700
2931
|
wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
|
|
2701
2932
|
wxml: [`${modulePath}/**/*.wxml`, ...excludes],
|
|
2702
2933
|
image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
2703
2934
|
};
|
|
2704
|
-
compile$1(tmsConfig, {
|
|
2935
|
+
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
2705
2936
|
glob: { ...glob,
|
|
2706
2937
|
other: [`${modulePath}/**/*`, ...excludeGlob(glob)]
|
|
2707
2938
|
},
|
|
@@ -2713,8 +2944,8 @@ var compile = function (tmsConfig, {
|
|
|
2713
2944
|
srcOption: {
|
|
2714
2945
|
allowEmpty: true
|
|
2715
2946
|
},
|
|
2716
|
-
|
|
2717
|
-
});
|
|
2947
|
+
isDev
|
|
2948
|
+
}));
|
|
2718
2949
|
} // 静态资源目录-拷贝
|
|
2719
2950
|
|
|
2720
2951
|
|
|
@@ -2739,7 +2970,7 @@ var compile = function (tmsConfig, {
|
|
|
2739
2970
|
}
|
|
2740
2971
|
|
|
2741
2972
|
const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
2742
|
-
compile$1(tmsConfig, {
|
|
2973
|
+
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
2743
2974
|
glob,
|
|
2744
2975
|
destPath: item.to,
|
|
2745
2976
|
module: {
|
|
@@ -2749,188 +2980,63 @@ var compile = function (tmsConfig, {
|
|
|
2749
2980
|
srcOption: {
|
|
2750
2981
|
allowEmpty: true
|
|
2751
2982
|
},
|
|
2752
|
-
|
|
2753
|
-
});
|
|
2983
|
+
isDev
|
|
2984
|
+
}));
|
|
2754
2985
|
}
|
|
2755
2986
|
}
|
|
2756
|
-
};
|
|
2757
|
-
})(dev$3);
|
|
2758
|
-
|
|
2759
|
-
const fs$1 = require$$0__default$2;
|
|
2760
|
-
const semver$1 = require$$1__default$8;
|
|
2761
|
-
const {
|
|
2762
|
-
resolve: resolve$3
|
|
2763
|
-
} = widgets;
|
|
2764
|
-
const path = require$$3__default;
|
|
2765
|
-
const shelljs$2 = require$$0__default$3;
|
|
2766
|
-
const {
|
|
2767
|
-
handleError
|
|
2768
|
-
} = handleError_1;
|
|
2769
|
-
|
|
2770
|
-
const getLatestVersion = npmName => {
|
|
2771
|
-
const data = shelljs$2.exec(`npm view ${npmName} version`);
|
|
2772
|
-
return data.stdout || '0.0.0';
|
|
2773
|
-
};
|
|
2774
|
-
/**
|
|
2775
|
-
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
2776
|
-
* @param {*} modules 模块
|
|
2777
|
-
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
2778
|
-
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
2779
|
-
* @returns
|
|
2780
|
-
*/
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
2784
|
-
// 步骤1. 收集package.json
|
|
2785
|
-
const packageJsonName = 'package.json'; // 查找文件名
|
|
2786
|
-
// 1.1根目录的package.json
|
|
2787
|
-
|
|
2788
|
-
const packageArr = [{
|
|
2789
|
-
srcPackageDir: path.join(cwd, packageJsonName),
|
|
2790
|
-
destNpmDir: resolve$3(outputDir, 'node_modules')
|
|
2791
|
-
}]; // 1.2模块的package.json
|
|
2792
|
-
|
|
2793
|
-
modules.forEach(item => {
|
|
2794
|
-
const srcPackageDir = path.join(cwd, item.path, 'package.json');
|
|
2795
|
-
|
|
2796
|
-
if (fs$1.existsSync(srcPackageDir)) {
|
|
2797
|
-
packageArr.push({
|
|
2798
|
-
srcPackageDir,
|
|
2799
|
-
destNpmDir: resolve$3(outputDir, item.root, 'node_modules')
|
|
2800
|
-
});
|
|
2801
|
-
}
|
|
2802
|
-
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
2803
2987
|
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2988
|
+
let sTime;
|
|
2989
|
+
let eTime;
|
|
2990
|
+
const spinner = ora();
|
|
2807
2991
|
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2992
|
+
function start(cb) {
|
|
2993
|
+
info('启动编译...');
|
|
2994
|
+
spinner.start();
|
|
2995
|
+
sTime = new Date().getTime();
|
|
2996
|
+
cb();
|
|
2813
2997
|
}
|
|
2814
2998
|
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2999
|
+
function end(cb) {
|
|
3000
|
+
var _tmsConfig$hooks;
|
|
3001
|
+
|
|
3002
|
+
if (isDev) {
|
|
3003
|
+
compileTasksMap.forEach(({
|
|
3004
|
+
taskFn,
|
|
3005
|
+
module
|
|
3006
|
+
}, globValue) => {
|
|
3007
|
+
watch(globValue, {
|
|
3008
|
+
ignoreInitial: true,
|
|
3009
|
+
events: watchEvents
|
|
3010
|
+
}, taskFn, module);
|
|
3011
|
+
});
|
|
2822
3012
|
}
|
|
2823
3013
|
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
if (fs$1.existsSync(depPackagePath)) {
|
|
2827
|
-
const packageData = require(depPackagePath);
|
|
2828
|
-
|
|
2829
|
-
if (dependencies[key] === 'latest') {
|
|
2830
|
-
dependencies[key] = getLatestVersion(key);
|
|
2831
|
-
}
|
|
3014
|
+
eTime = new Date().getTime() - sTime;
|
|
2832
3015
|
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
}
|
|
3016
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
|
|
3017
|
+
var _tmsConfig$hooks2;
|
|
2836
3018
|
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
3019
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3020
|
+
isDev,
|
|
3021
|
+
tmsConfig,
|
|
3022
|
+
modules: newModules
|
|
3023
|
+
});
|
|
2840
3024
|
}
|
|
2841
|
-
}
|
|
2842
|
-
}
|
|
2843
|
-
|
|
2844
|
-
return false;
|
|
2845
|
-
};
|
|
2846
3025
|
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
const fs = require$$0__default$2;
|
|
2852
|
-
const {
|
|
2853
|
-
resolve: resolve$2
|
|
2854
|
-
} = widgets;
|
|
2855
|
-
const {
|
|
2856
|
-
MODULE_CONFIG_FILENAME,
|
|
2857
|
-
MODULE_CODE_DIR
|
|
2858
|
-
} = require$$4;
|
|
2859
|
-
const {
|
|
2860
|
-
checkRemoteModGitUrlBranch
|
|
2861
|
-
} = cloneModules_1;
|
|
2862
|
-
const {
|
|
2863
|
-
checkDependencies
|
|
2864
|
-
} = checkDependencies_1;
|
|
2865
|
-
const {
|
|
2866
|
-
fail
|
|
2867
|
-
} = log$1;
|
|
2868
|
-
|
|
2869
|
-
function checkModule(targetModules, contextDir) {
|
|
2870
|
-
// 判断\源码\dist\是否存在用户指定的模块
|
|
2871
|
-
for (const item of targetModules) {
|
|
2872
|
-
// 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
|
|
2873
|
-
if (!item.root) {
|
|
2874
|
-
return true;
|
|
2875
|
-
} // 判断dist目录是否有该模块
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
|
|
2879
|
-
return true;
|
|
2880
|
-
} // 判断第三方远程模块git地址与branch是否有更新
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
|
|
2884
|
-
return true;
|
|
2885
|
-
} // 判断源码目录是否有该模块
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
if (item.path && !fs.existsSync(resolve$2(item.path))) {
|
|
2889
|
-
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2890
|
-
process.exit(1);
|
|
3026
|
+
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
|
|
3027
|
+
spinner.stop();
|
|
3028
|
+
cb();
|
|
2891
3029
|
}
|
|
2892
|
-
}
|
|
2893
|
-
|
|
2894
|
-
return false;
|
|
2895
|
-
}
|
|
2896
|
-
|
|
2897
|
-
function isInit$1(tmsConfig, targetModules, contextDir) {
|
|
2898
|
-
// 判断是否存在dist目录
|
|
2899
|
-
if (!fs.existsSync(contextDir)) {
|
|
2900
|
-
return true;
|
|
2901
|
-
} // 判断dist是否存在node_modules
|
|
2902
|
-
|
|
2903
3030
|
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
}
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
if (!fs.existsSync(`${contextDir}/app.json`)) {
|
|
2915
|
-
return true;
|
|
2916
|
-
} // 判断模块信息
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
if (checkModule(targetModules, contextDir)) {
|
|
2920
|
-
return true;
|
|
2921
|
-
} // 判断package.json的版本是否有新的版本
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
if (checkDependencies(targetModules, resolve$2('./'), tmsConfig.outputDir)) {
|
|
2925
|
-
return true;
|
|
2926
|
-
}
|
|
2927
|
-
|
|
2928
|
-
return false;
|
|
2929
|
-
}
|
|
2930
|
-
|
|
2931
|
-
var isInIt = {
|
|
2932
|
-
isInit: isInit$1
|
|
2933
|
-
};
|
|
3031
|
+
const compileTasks = [];
|
|
3032
|
+
compileTasksMap.forEach(({
|
|
3033
|
+
taskFn
|
|
3034
|
+
}) => {
|
|
3035
|
+
compileTasks.push(taskFn);
|
|
3036
|
+
});
|
|
3037
|
+
series(start, parallel(...compileTasks), end)();
|
|
3038
|
+
};
|
|
3039
|
+
})(dev$3);
|
|
2934
3040
|
|
|
2935
3041
|
const shelljs$1 = require$$0__default$3;
|
|
2936
3042
|
const compileDev = dev$3.exports;
|
|
@@ -2938,9 +3044,6 @@ const {
|
|
|
2938
3044
|
resolve: resolve$1
|
|
2939
3045
|
} = widgets;
|
|
2940
3046
|
const init$4 = init_1;
|
|
2941
|
-
const {
|
|
2942
|
-
isInit
|
|
2943
|
-
} = isInIt;
|
|
2944
3047
|
const {
|
|
2945
3048
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
2946
3049
|
} = tmsMpconfig;
|
|
@@ -2949,7 +3052,10 @@ const {
|
|
|
2949
3052
|
} = log$1;
|
|
2950
3053
|
const {
|
|
2951
3054
|
global: global$1
|
|
2952
|
-
} = global_1;
|
|
3055
|
+
} = global_1;
|
|
3056
|
+
const {
|
|
3057
|
+
CACHE_DIR
|
|
3058
|
+
} = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
2953
3059
|
|
|
2954
3060
|
function delOtherModule(tmsConfig, targetModules) {
|
|
2955
3061
|
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
|
|
@@ -2966,16 +3072,32 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
2966
3072
|
}
|
|
2967
3073
|
|
|
2968
3074
|
async function dev$2(tmsConfig, targetModules, env) {
|
|
3075
|
+
var _tmsConfig$hooks;
|
|
3076
|
+
|
|
2969
3077
|
let newModules = targetModules;
|
|
2970
|
-
const
|
|
3078
|
+
const {
|
|
3079
|
+
noCache
|
|
3080
|
+
} = global$1.getData('cmd');
|
|
3081
|
+
|
|
3082
|
+
if (noCache) {
|
|
3083
|
+
shelljs$1.rm('-rf', resolve$1('dist'));
|
|
3084
|
+
shelljs$1.rm('-rf', CACHE_DIR);
|
|
3085
|
+
} // 初始化操作
|
|
2971
3086
|
|
|
2972
|
-
if (isLatest || isInit(tmsConfig, targetModules, resolve$1('dist'))) {
|
|
2973
|
-
// init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
|
|
2974
|
-
const initData = await init$4(tmsConfig, newModules);
|
|
2975
|
-
newModules = initData.targetModules;
|
|
2976
|
-
}
|
|
2977
3087
|
|
|
3088
|
+
const initData = await init$4(tmsConfig, newModules);
|
|
3089
|
+
newModules = initData.targetModules;
|
|
2978
3090
|
info$2('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
3091
|
+
|
|
3092
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3093
|
+
var _tmsConfig$hooks2;
|
|
3094
|
+
|
|
3095
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3096
|
+
isDev: true,
|
|
3097
|
+
tmsConfig,
|
|
3098
|
+
modules: newModules
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
2979
3101
|
delOtherModule(tmsConfig, newModules);
|
|
2980
3102
|
compileDev(tmsConfig, newModules, env);
|
|
2981
3103
|
}
|
|
@@ -3071,7 +3193,7 @@ async function run(commandName, cmd) {
|
|
|
3071
3193
|
const tmsConfig = readTmsConfig(env); // 处理module参数
|
|
3072
3194
|
|
|
3073
3195
|
const specificModules = getSpecificModules(handleModuleArg(cmd), tmsPrivateCf.modules, tmsConfig.modules);
|
|
3074
|
-
const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])]); // tms.config.js的modules 合并 module.config.json的配置项
|
|
3196
|
+
const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])], true); // tms.config.js的modules 合并 module.config.json的配置项
|
|
3075
3197
|
|
|
3076
3198
|
let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
3077
3199
|
|
|
@@ -3080,7 +3202,8 @@ async function run(commandName, cmd) {
|
|
|
3080
3202
|
global.setData({
|
|
3081
3203
|
env,
|
|
3082
3204
|
cmd,
|
|
3083
|
-
tmsPrivateCf
|
|
3205
|
+
tmsPrivateCf,
|
|
3206
|
+
tmsConfig
|
|
3084
3207
|
});
|
|
3085
3208
|
|
|
3086
3209
|
switch (commandName) {
|
|
@@ -3129,7 +3252,7 @@ var entry = [{
|
|
|
3129
3252
|
}, {
|
|
3130
3253
|
command: 'dev',
|
|
3131
3254
|
description: 'dev 打包编译',
|
|
3132
|
-
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-
|
|
3255
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-noCache, --noCache', '不使用缓存功能']],
|
|
3133
3256
|
action: cmd => {
|
|
3134
3257
|
run_1('dev', cmd);
|
|
3135
3258
|
}
|
|
@@ -3157,7 +3280,7 @@ var entry = [{
|
|
|
3157
3280
|
|
|
3158
3281
|
var require$$7 = {
|
|
3159
3282
|
name: "@tmsfe/tmskit",
|
|
3160
|
-
version: "0.0.
|
|
3283
|
+
version: "0.0.15-beta.0",
|
|
3161
3284
|
description: "tmskit",
|
|
3162
3285
|
main: "dist/index.cjs",
|
|
3163
3286
|
bin: {
|
|
@@ -3171,7 +3294,10 @@ var require$$7 = {
|
|
|
3171
3294
|
],
|
|
3172
3295
|
scripts: {
|
|
3173
3296
|
dev: "rollup -wc --environment TARGET:tmskit",
|
|
3174
|
-
build: "rollup -c --environment TARGET:tmskit"
|
|
3297
|
+
build: "rollup -c --environment TARGET:tmskit",
|
|
3298
|
+
"pub:patch": "sh build/publish.sh patch",
|
|
3299
|
+
"pub:minor": "sh build/publish.sh minor",
|
|
3300
|
+
"pub:major": "sh build/publish.sh major"
|
|
3175
3301
|
},
|
|
3176
3302
|
author: "tms·web",
|
|
3177
3303
|
license: "ISC",
|
|
@@ -3200,9 +3326,6 @@ var require$$7 = {
|
|
|
3200
3326
|
"fs-extra": "^10.0.1",
|
|
3201
3327
|
"glob-ignore": "^1.0.2",
|
|
3202
3328
|
gulp: "^4.0.2",
|
|
3203
|
-
"gulp-cache": "^1.1.3",
|
|
3204
|
-
"gulp-postcss": "^9.0.1",
|
|
3205
|
-
"gulp-px-to-rpx": "^1.0.7",
|
|
3206
3329
|
"gulp-watch": "^5.0.1",
|
|
3207
3330
|
htmlparser2: "^7.2.0",
|
|
3208
3331
|
inquirer: "^7.3.3",
|
|
@@ -3210,6 +3333,7 @@ var require$$7 = {
|
|
|
3210
3333
|
lodash: "^4.17.21",
|
|
3211
3334
|
metalsmith: "^2.3.0",
|
|
3212
3335
|
"miniprogram-ci": "1.4.13",
|
|
3336
|
+
moment: "^2.29.1",
|
|
3213
3337
|
"object-assign": "^4.0.1",
|
|
3214
3338
|
ora: "^5.1.0",
|
|
3215
3339
|
"plugin-error": "^1.0.0",
|
|
@@ -3229,7 +3353,7 @@ var require$$7 = {
|
|
|
3229
3353
|
}
|
|
3230
3354
|
};
|
|
3231
3355
|
|
|
3232
|
-
const semver = require$$1__default$
|
|
3356
|
+
const semver = require$$1__default$6;
|
|
3233
3357
|
const packageJson = require$$7;
|
|
3234
3358
|
const chalk$1 = require$$0__default;
|
|
3235
3359
|
const {
|
|
@@ -3305,15 +3429,12 @@ function registerCommand(program, commands) {
|
|
|
3305
3429
|
|
|
3306
3430
|
registerCommand(program, commands);
|
|
3307
3431
|
program.on('--help', () => {
|
|
3308
|
-
info();
|
|
3309
3432
|
info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
3310
|
-
info();
|
|
3311
3433
|
}); // 捕获未注册的命令
|
|
3312
3434
|
|
|
3313
3435
|
program.arguments('<command>').action(cmd => {
|
|
3314
3436
|
program.outputHelp();
|
|
3315
|
-
info(`
|
|
3316
|
-
info();
|
|
3437
|
+
info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
|
|
3317
3438
|
suggestCommands(cmd);
|
|
3318
3439
|
process.exitCode = 1;
|
|
3319
3440
|
});
|