@tmsfe/tmskit 0.0.5-beta.4 → 0.0.6
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/README.md +2 -0
- package/dist/index.cjs.js +603 -414
- package/package.json +8 -2
- package/src/config/constant.js +2 -1
- package/src/config/defaultTmsConfig.js +8 -10
- package/src/gulp/build.js +0 -3
- package/src/gulp/compile.js +7 -7
- package/src/gulp/dev.js +12 -18
- package/src/gulp/plugins/mpCommonDep.js +6 -6
- package/src/gulp/plugins/mpJsonDep.js +6 -6
- package/src/gulp/plugins/mpWxmlDep.js +6 -6
- package/src/gulp/plugins/postcss-font-base64.js +1 -1
- package/src/gulp/{replaceEnv.js → plugins/replaceEnv.js} +1 -1
- package/src/index.js +0 -1
- package/src/scripts/run/build/index.js +3 -2
- package/src/scripts/run/dev/index.js +28 -11
- package/src/scripts/run/index.js +26 -21
- package/src/scripts/run/init/index.js +23 -16
- package/src/scripts/run/install/index.js +3 -5
- package/src/utils/buildAppJson.js +46 -25
- package/src/utils/checkDependencies.js +6 -6
- package/src/utils/cloneModules.js +39 -13
- package/src/utils/handleError.js +16 -0
- package/src/utils/io.js +1 -1
- package/src/utils/mpCiUtils.js +0 -1
- package/src/utils/npmUtils.js +53 -35
- package/src/utils/tkitUtils.js +90 -16
- package/src/utils/widgets.js +11 -14
- package/src/webpack/base.js +0 -65
- package/src/webpack/build.js +0 -21
- package/src/webpack/buildServer.js +0 -34
- package/src/webpack/dev.js +0 -31
- package/src/webpack/devServer.js +0 -37
- package/src/webpack/plugins/entryExtractPlugin/index.js +0 -28
- package/src/webpack/utils.js +0 -244
package/dist/index.cjs.js
CHANGED
|
@@ -3,18 +3,20 @@
|
|
|
3
3
|
var require$$0 = require('commander');
|
|
4
4
|
var require$$1 = require('leven');
|
|
5
5
|
var require$$2 = require('ora');
|
|
6
|
-
var require$$
|
|
6
|
+
var require$$3$1 = require('path');
|
|
7
7
|
var require$$0$1 = require('fs');
|
|
8
|
-
var require$$
|
|
8
|
+
var require$$4 = require('shelljs');
|
|
9
9
|
var require$$6$1 = require('download-git-repo');
|
|
10
10
|
var require$$0$2 = require('chalk');
|
|
11
11
|
var require$$0$3 = require('async');
|
|
12
|
-
var require$$1$
|
|
13
|
-
var require$$1$
|
|
12
|
+
var require$$1$1 = require('ejs');
|
|
13
|
+
var require$$1$2 = require('inquirer');
|
|
14
14
|
var require$$0$4 = require('metalsmith');
|
|
15
15
|
var require$$0$5 = require('lodash');
|
|
16
16
|
var require$$0$6 = require('miniprogram-ci');
|
|
17
|
-
var require$$
|
|
17
|
+
var require$$5 = require('glob-ignore');
|
|
18
|
+
var require$$1$3 = require('fs-extra');
|
|
19
|
+
var require$$2$1 = require('crypto');
|
|
18
20
|
var require$$0$7 = require('through2');
|
|
19
21
|
var require$$0$8 = require('strip-comments');
|
|
20
22
|
var require$$1$4 = require('precinct');
|
|
@@ -22,10 +24,8 @@ var require$$1$5 = require('htmlparser2');
|
|
|
22
24
|
var require$$0$9 = require('postcss');
|
|
23
25
|
var require$$0$a = require('gulp');
|
|
24
26
|
var require$$1$6 = require('gulp-px-to-rpx');
|
|
25
|
-
var require$$2$
|
|
27
|
+
var require$$2$2 = require('gulp-postcss');
|
|
26
28
|
var require$$3$2 = require('gulp-watch');
|
|
27
|
-
var require$$4 = require('gulp-cache');
|
|
28
|
-
var require$$5$1 = require('gulp-image');
|
|
29
29
|
var require$$1$7 = require('semver');
|
|
30
30
|
|
|
31
31
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
@@ -33,18 +33,20 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
33
33
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
34
34
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
35
35
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
36
|
-
var require$$
|
|
36
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
37
37
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
38
|
-
var require$$
|
|
38
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
39
39
|
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
|
|
40
40
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
41
41
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
42
|
+
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
42
43
|
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
43
|
-
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
44
44
|
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
45
45
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
46
46
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
47
|
-
var require$$
|
|
47
|
+
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
48
|
+
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
49
|
+
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
48
50
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
49
51
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
50
52
|
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
@@ -52,10 +54,8 @@ var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
|
52
54
|
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
53
55
|
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
54
56
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
55
|
-
var require$$2__default$
|
|
57
|
+
var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
|
|
56
58
|
var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
|
|
57
|
-
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
58
|
-
var require$$5__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
|
|
59
59
|
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
60
60
|
|
|
61
61
|
function getAugmentedNamespace(n) {
|
|
@@ -78,19 +78,19 @@ var src$2 = {};
|
|
|
78
78
|
const program$1 = require$$0__default;
|
|
79
79
|
const leven = require$$1__default;
|
|
80
80
|
const ora = require$$2__default;
|
|
81
|
-
const path$
|
|
81
|
+
const path$b = require$$3__default;
|
|
82
82
|
const fs$e = require$$0__default$1;
|
|
83
|
-
const shelljs$6 = require$$
|
|
83
|
+
const shelljs$6 = require$$4__default;
|
|
84
84
|
const download = require$$6__default;
|
|
85
85
|
const chalk$3 = require$$0__default$2;
|
|
86
|
-
const
|
|
86
|
+
const shelljsOptions = {
|
|
87
87
|
slient: true
|
|
88
88
|
}; // 获取当前目录
|
|
89
89
|
|
|
90
90
|
const cwd = process.cwd();
|
|
91
91
|
|
|
92
92
|
function resolve$d(...args) {
|
|
93
|
-
return path$
|
|
93
|
+
return path$b.resolve(cwd, ...args);
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* 封装logs
|
|
@@ -189,15 +189,20 @@ function downloadRepo(dest, downloadOptions = {
|
|
|
189
189
|
|
|
190
190
|
function downloadRepoForGit$2(url, dest, branch) {
|
|
191
191
|
const cwd = process.cwd();
|
|
192
|
-
return new Promise(resolve => {
|
|
192
|
+
return new Promise((resolve, reject) => {
|
|
193
193
|
// 如果目标目录不存在
|
|
194
194
|
if (fs$e.existsSync(dest)) {
|
|
195
|
-
shelljs$6.rm('-rf', path$
|
|
195
|
+
shelljs$6.rm('-rf', path$b.join(dest));
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
shelljs$6.mkdir('-p', dest);
|
|
199
199
|
shelljs$6.cd(dest);
|
|
200
|
-
shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`,
|
|
200
|
+
const gitCloneRes = shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptions);
|
|
201
|
+
|
|
202
|
+
if (gitCloneRes.code !== 0) {
|
|
203
|
+
reject(gitCloneRes.stderr);
|
|
204
|
+
}
|
|
205
|
+
|
|
201
206
|
shelljs$6.cd(cwd);
|
|
202
207
|
resolve();
|
|
203
208
|
});
|
|
@@ -222,21 +227,12 @@ const cost = start => Date.now() - start;
|
|
|
222
227
|
function createTask$4(task, startText, endText) {
|
|
223
228
|
return async (...args) => {
|
|
224
229
|
const start = Date.now();
|
|
225
|
-
let result;
|
|
226
230
|
const spinner = ora(startText);
|
|
227
231
|
spinner.start();
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
result = e;
|
|
233
|
-
console.log(chalk$3.red(e));
|
|
234
|
-
process.exit(-1);
|
|
235
|
-
} finally {
|
|
236
|
-
endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
|
|
237
|
-
spinner.stop();
|
|
238
|
-
}
|
|
239
|
-
|
|
232
|
+
console.log('\n');
|
|
233
|
+
const result = await task(...args);
|
|
234
|
+
endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
|
|
235
|
+
spinner.stop();
|
|
240
236
|
return result;
|
|
241
237
|
};
|
|
242
238
|
}
|
|
@@ -260,35 +256,35 @@ var widgets = {
|
|
|
260
256
|
camelize
|
|
261
257
|
};
|
|
262
258
|
|
|
263
|
-
const path$
|
|
259
|
+
const path$a = require('path'); // 用户目录
|
|
264
260
|
|
|
265
261
|
|
|
266
262
|
const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
|
|
267
263
|
|
|
268
|
-
const CACHE_DIR$1 = path$
|
|
264
|
+
const CACHE_DIR$1 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
269
265
|
|
|
270
|
-
const TEMPLATE_DIR$1 = path$
|
|
266
|
+
const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
271
267
|
|
|
272
|
-
const MODULE_CODE_DIR$1 = path$
|
|
268
|
+
const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
|
|
273
269
|
|
|
274
|
-
const TEMPLATE_PATH$1 = path$
|
|
270
|
+
const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
275
271
|
|
|
276
272
|
const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
|
|
277
273
|
|
|
278
|
-
const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
|
|
274
|
+
const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
|
|
275
|
+
const TMS_PRIVATE_FILENAME$1 = 'tms.private.config.js'; // 模块代码的默认在modules子目录
|
|
279
276
|
|
|
280
|
-
const DEFAULT_MODULE_DIR
|
|
277
|
+
const DEFAULT_MODULE_DIR = 'modules'; // 模块的配置文件的名称
|
|
281
278
|
|
|
282
|
-
const MODULE_CONFIG_FILENAME$
|
|
279
|
+
const MODULE_CONFIG_FILENAME$3 = 'module.config.json'; // 默认的webpack entry
|
|
283
280
|
|
|
284
281
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
285
|
-
app: path$
|
|
282
|
+
app: path$a.resolve(process.cwd(), 'app')
|
|
286
283
|
}; // 默认从源码拷贝到编译后的配置
|
|
287
284
|
|
|
288
285
|
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
|
|
289
286
|
|
|
290
287
|
const MODE$1 = {
|
|
291
|
-
main: 'tkitmain',
|
|
292
288
|
all: 'all',
|
|
293
289
|
multi: 'multi'
|
|
294
290
|
};
|
|
@@ -307,8 +303,9 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
307
303
|
TEMPLATE_PATH: TEMPLATE_PATH$1,
|
|
308
304
|
TMS_NAME: TMS_NAME$2,
|
|
309
305
|
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
|
|
310
|
-
|
|
311
|
-
|
|
306
|
+
TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME$1,
|
|
307
|
+
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
|
|
308
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$3,
|
|
312
309
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
313
310
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
314
311
|
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
@@ -321,7 +318,7 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
321
318
|
var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
322
319
|
|
|
323
320
|
const fs$d = require$$0__default$1;
|
|
324
|
-
const path$
|
|
321
|
+
const path$9 = require$$3__default;
|
|
325
322
|
/**
|
|
326
323
|
* 判断目录是否为空
|
|
327
324
|
* @param {string} dirname 目录名
|
|
@@ -359,7 +356,7 @@ const copyFile = function (src, dest) {
|
|
|
359
356
|
fs$d.unlinkSync(dest);
|
|
360
357
|
}
|
|
361
358
|
|
|
362
|
-
const dir =
|
|
359
|
+
const dir = path$9.dirname(dest);
|
|
363
360
|
ensureDirExist(dir);
|
|
364
361
|
fs$d.copyFileSync(src, dest);
|
|
365
362
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
@@ -419,7 +416,7 @@ const fileInDir$3 = (dir, file) => {
|
|
|
419
416
|
return false;
|
|
420
417
|
}
|
|
421
418
|
|
|
422
|
-
const relativePath = path$
|
|
419
|
+
const relativePath = path$9.relative(dir, file);
|
|
423
420
|
|
|
424
421
|
if (relativePath.startsWith('..')) {
|
|
425
422
|
return false;
|
|
@@ -490,7 +487,7 @@ var log$2 = {
|
|
|
490
487
|
};
|
|
491
488
|
|
|
492
489
|
const async = require$$0__default$3;
|
|
493
|
-
const ejs = require$$1__default$
|
|
490
|
+
const ejs = require$$1__default$1;
|
|
494
491
|
|
|
495
492
|
const render$1 = (files, metalsmith, next) => {
|
|
496
493
|
const keys = Object.keys(files);
|
|
@@ -510,7 +507,7 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
510
507
|
var render_1 = render$1;
|
|
511
508
|
|
|
512
509
|
const fs$c = require$$0__default$1;
|
|
513
|
-
const inquirer = require$$1__default$
|
|
510
|
+
const inquirer = require$$1__default$2;
|
|
514
511
|
const {
|
|
515
512
|
resolve: resolve$c
|
|
516
513
|
} = widgets;
|
|
@@ -606,9 +603,9 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
606
603
|
|
|
607
604
|
var generator_1 = generator$1;
|
|
608
605
|
|
|
609
|
-
const path$
|
|
606
|
+
const path$8 = require$$3__default;
|
|
610
607
|
const fs$b = require$$0__default$1;
|
|
611
|
-
const shelljs$5 = require$$
|
|
608
|
+
const shelljs$5 = require$$4__default;
|
|
612
609
|
const {
|
|
613
610
|
TEMPLATE_DIR,
|
|
614
611
|
TEMPLATE_PATH,
|
|
@@ -651,7 +648,7 @@ async function createAppDir(targetDir) {
|
|
|
651
648
|
|
|
652
649
|
async function create(appName) {
|
|
653
650
|
const cwd = process.cwd();
|
|
654
|
-
const targetDir = path$
|
|
651
|
+
const targetDir = path$8.resolve(cwd, appName);
|
|
655
652
|
const appType = 'mp';
|
|
656
653
|
await createAppDir(targetDir); // 创建缓存目录
|
|
657
654
|
|
|
@@ -659,7 +656,7 @@ async function create(appName) {
|
|
|
659
656
|
|
|
660
657
|
await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
661
658
|
|
|
662
|
-
generator(path$
|
|
659
|
+
generator(path$8.join(TEMPLATE_PATH, appType), targetDir, {
|
|
663
660
|
appName,
|
|
664
661
|
appType
|
|
665
662
|
}).then(() => {
|
|
@@ -689,39 +686,55 @@ async function create(appName) {
|
|
|
689
686
|
|
|
690
687
|
var create_1 = create;
|
|
691
688
|
|
|
689
|
+
const {
|
|
690
|
+
fail: fail$8
|
|
691
|
+
} = log$2;
|
|
692
|
+
|
|
693
|
+
function handleError$3(error, isDev = false) {
|
|
694
|
+
const errMsg = typeof error === 'object' ? error.message : error;
|
|
695
|
+
|
|
696
|
+
if (isDev) {
|
|
697
|
+
fail$8(errMsg);
|
|
698
|
+
} else {
|
|
699
|
+
fail$8(errMsg);
|
|
700
|
+
process.exit(1);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
var handleError_1 = {
|
|
705
|
+
handleError: handleError$3
|
|
706
|
+
};
|
|
707
|
+
|
|
692
708
|
const fs$a = require$$0__default$1;
|
|
693
709
|
const {
|
|
694
|
-
|
|
695
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
710
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
696
711
|
MODULE_CONFIG_INVALID_KEY
|
|
697
712
|
} = require$$3;
|
|
698
713
|
const {
|
|
699
|
-
fail: fail$
|
|
714
|
+
fail: fail$7
|
|
700
715
|
} = log$2;
|
|
701
716
|
const {
|
|
702
717
|
resolve: resolve$a,
|
|
703
718
|
isObject: isObject$1,
|
|
704
719
|
isArray
|
|
705
720
|
} = widgets;
|
|
721
|
+
const {
|
|
722
|
+
handleError: handleError$2
|
|
723
|
+
} = handleError_1;
|
|
706
724
|
/**
|
|
707
725
|
* 获取每个模块下面的信息,并且收集,后续更新到appJson里面
|
|
708
726
|
* @param { object } file 操作目录下面所有的文件
|
|
709
727
|
* @param { string } appName 小程序的名称
|
|
710
728
|
*/
|
|
711
729
|
|
|
712
|
-
function setModuleConfig$1(file, appName
|
|
730
|
+
function setModuleConfig$1(file, appName) {
|
|
713
731
|
const content = file.contents ? JSON.parse(file.contents.toString()) : JSON.parse(file);
|
|
714
732
|
|
|
715
|
-
if (isObject$1(content)) {
|
|
716
|
-
content.root = content.root.indexOf(moduleDir) > -1 ? content.root : `${moduleDir}/${content.root}`;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
733
|
if (isArray(content)) {
|
|
720
734
|
let i = content.length - 1;
|
|
721
735
|
|
|
722
736
|
while (i >= 0) {
|
|
723
737
|
let current = content[i];
|
|
724
|
-
current.root = current.root.indexOf(moduleDir) > -1 ? current.root : `${moduleDir}/${current.root}`;
|
|
725
738
|
|
|
726
739
|
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
727
740
|
current = { ...current,
|
|
@@ -743,7 +756,7 @@ function setModuleConfig$1(file, appName, moduleDir) {
|
|
|
743
756
|
*/
|
|
744
757
|
|
|
745
758
|
|
|
746
|
-
function getLocalModuleConfig(modules = [], appName,
|
|
759
|
+
function getLocalModuleConfig(modules = [], appName, moduleConfigFilename) {
|
|
747
760
|
const modulesConfig = {};
|
|
748
761
|
modules.forEach(({
|
|
749
762
|
path
|
|
@@ -752,7 +765,7 @@ function getLocalModuleConfig(modules = [], appName, moduleDir, moduleConfigFile
|
|
|
752
765
|
|
|
753
766
|
if (fs$a.existsSync(moduleConfigPath)) {
|
|
754
767
|
const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
755
|
-
modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName
|
|
768
|
+
modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName);
|
|
756
769
|
}
|
|
757
770
|
});
|
|
758
771
|
return modulesConfig;
|
|
@@ -776,7 +789,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
776
789
|
|
|
777
790
|
foundMainPackages.forEach(subpackage => {
|
|
778
791
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
779
|
-
fail$
|
|
792
|
+
fail$7(`主包 ${subpackage} 不能没有 pages`);
|
|
780
793
|
process.exit(-1);
|
|
781
794
|
}
|
|
782
795
|
|
|
@@ -803,7 +816,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
803
816
|
|
|
804
817
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
805
818
|
if (!fs$a.existsSync(sourceAppJsonPath)) {
|
|
806
|
-
fail$
|
|
819
|
+
fail$7(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
807
820
|
process.exit(1);
|
|
808
821
|
}
|
|
809
822
|
|
|
@@ -825,11 +838,25 @@ const getAppJsonContent = sourceAppJsonPath => {
|
|
|
825
838
|
const updateSubpackages = (appJson, modulesConfig) => {
|
|
826
839
|
// eslint-disable-next-line
|
|
827
840
|
for (const name in modulesConfig) {
|
|
828
|
-
const moduleInfo = isObject$1(modulesConfig[name]) ? [modulesConfig[name]] : modulesConfig[name]; //
|
|
841
|
+
const moduleInfo = isObject$1(modulesConfig[name]) ? [modulesConfig[name]] : modulesConfig[name]; // 过滤 pages 为空的情况
|
|
842
|
+
|
|
843
|
+
const validModules = getValidModules$1(moduleInfo); // eslint-disable-next-line
|
|
829
844
|
|
|
830
|
-
appJson.subpackages = appJson.subpackages.concat(
|
|
845
|
+
appJson.subpackages = appJson.subpackages.concat(validModules);
|
|
831
846
|
}
|
|
832
847
|
};
|
|
848
|
+
/**
|
|
849
|
+
* 过滤页面为空的分包
|
|
850
|
+
* @param {Array} moduleCfg 模块配置内容
|
|
851
|
+
* @returns pages不为空的分包
|
|
852
|
+
*/
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
const getValidModules$1 = moduleCfg => {
|
|
856
|
+
// 过滤 pages 为空的情况
|
|
857
|
+
const validModules = moduleCfg.filter(item => item.pages.length > 0);
|
|
858
|
+
return validModules;
|
|
859
|
+
};
|
|
833
860
|
/**
|
|
834
861
|
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
835
862
|
* @param {Object} appJson appjson
|
|
@@ -845,6 +872,12 @@ const processAppJson = appJson => {
|
|
|
845
872
|
const subps = subpackages.map(subp => {
|
|
846
873
|
const invalidKeys = [];
|
|
847
874
|
Object.keys(subp).forEach(key => {
|
|
875
|
+
if (key === 'dependencies') {
|
|
876
|
+
// eslint-disable-next-line
|
|
877
|
+
delete subp.dependencies;
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
|
|
848
881
|
if (key === 'plugins') {
|
|
849
882
|
Object.keys(subp.plugins).forEach(pk => {
|
|
850
883
|
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
@@ -869,7 +902,7 @@ const processAppJson = appJson => {
|
|
|
869
902
|
});
|
|
870
903
|
|
|
871
904
|
if (invalidKeys.length) {
|
|
872
|
-
fail$
|
|
905
|
+
fail$7(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
873
906
|
} // eslint-disable-next-line
|
|
874
907
|
|
|
875
908
|
|
|
@@ -886,7 +919,7 @@ const processAppJson = appJson => {
|
|
|
886
919
|
}).reduce((pre, cur) => pre + cur, '');
|
|
887
920
|
|
|
888
921
|
if (pluginsErrMsg) {
|
|
889
|
-
fail$
|
|
922
|
+
fail$7(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
890
923
|
} // eslint-disable-next-line
|
|
891
924
|
|
|
892
925
|
|
|
@@ -900,23 +933,28 @@ const processAppJson = appJson => {
|
|
|
900
933
|
*/
|
|
901
934
|
|
|
902
935
|
|
|
903
|
-
function buildOutputAppJson$1(tmsConfig, modules) {
|
|
904
|
-
|
|
905
|
-
|
|
936
|
+
function buildOutputAppJson$1(tmsConfig, modules, isDev) {
|
|
937
|
+
try {
|
|
938
|
+
// 获取当前 modules 下的所有子模块的配置内容
|
|
939
|
+
const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME$2); // 获取app.json的配置
|
|
906
940
|
|
|
907
|
-
|
|
941
|
+
const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
|
|
908
942
|
|
|
909
|
-
|
|
943
|
+
updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
|
|
910
944
|
|
|
911
|
-
|
|
945
|
+
processAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
912
946
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
947
|
+
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
948
|
+
fs$a.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
949
|
+
return appJson;
|
|
950
|
+
} catch (e) {
|
|
951
|
+
handleError$2(`生成app.json出现错误: ${e}`, isDev);
|
|
952
|
+
}
|
|
916
953
|
}
|
|
917
954
|
|
|
918
955
|
var buildAppJson = {
|
|
919
956
|
setModuleConfig: setModuleConfig$1,
|
|
957
|
+
getValidModules: getValidModules$1,
|
|
920
958
|
buildOutputAppJson: buildOutputAppJson$1
|
|
921
959
|
};
|
|
922
960
|
|
|
@@ -955,156 +993,55 @@ var global = {
|
|
|
955
993
|
getGlobalInstance: getGlobalInstance$1
|
|
956
994
|
};
|
|
957
995
|
|
|
958
|
-
const MetalSmith = require$$0__default$4;
|
|
959
|
-
const {
|
|
960
|
-
getGlobalInstance
|
|
961
|
-
} = global;
|
|
962
|
-
const {
|
|
963
|
-
downloadRepoForGit,
|
|
964
|
-
resolve: resolve$9
|
|
965
|
-
} = widgets;
|
|
966
|
-
const {
|
|
967
|
-
fail: fail$7
|
|
968
|
-
} = log$2;
|
|
969
|
-
const fs$9 = require$$0__default$1;
|
|
970
|
-
const shelljs$4 = require$$5__default;
|
|
971
|
-
/**
|
|
972
|
-
* 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
|
|
973
|
-
* @param { string } sourceDir 缓存文件夹
|
|
974
|
-
* @param { string } targetDir 目标文件夹
|
|
975
|
-
* @param { arrary } ignore
|
|
976
|
-
* @returns { undefined } no return
|
|
977
|
-
*/
|
|
978
|
-
|
|
979
|
-
function moveFile(sourceDir, targetDir, ignore = []) {
|
|
980
|
-
// 删除不是文件夹的文件
|
|
981
|
-
return new Promise(resolve => {
|
|
982
|
-
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
983
|
-
if (e) {
|
|
984
|
-
fail$7(e); // eslint-disable-line
|
|
985
|
-
|
|
986
|
-
console.log('MetalSmith 详细的错误信息:', e);
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
resolve();
|
|
990
|
-
});
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* 下载目标模块
|
|
995
|
-
* @param { string } sourceDir 缓存文件夹
|
|
996
|
-
* @param { string } targetDir 目标文件夹
|
|
997
|
-
* @returns { array } modules 描述模块的列表
|
|
998
|
-
*/
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
1002
|
-
// 根据小程序的配置文件下载模块, 并且处理信息
|
|
1003
|
-
for (const moduleInfo of modules) {
|
|
1004
|
-
// eslint-disable-line
|
|
1005
|
-
if (moduleInfo.repoInfo) {
|
|
1006
|
-
await downLoadAndMoveModule(sourceDir, targetDir, moduleInfo);
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
/**
|
|
1011
|
-
* 下载模块信息并且将它移动到对应的位置
|
|
1012
|
-
* @param { string } sourceDir 代码缓存文件夹
|
|
1013
|
-
* @param { string } targetDir 代码要放到的目标文件夹
|
|
1014
|
-
* @returns { array } moduleInfo 描述模块的信息
|
|
1015
|
-
*/
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
|
|
1019
|
-
const {
|
|
1020
|
-
repoInfo: {
|
|
1021
|
-
buildGitTag,
|
|
1022
|
-
httpRepoUrl
|
|
1023
|
-
},
|
|
1024
|
-
path
|
|
1025
|
-
} = moduleInfo; // 源码临时存在的源目录
|
|
1026
|
-
|
|
1027
|
-
let sourcePath = resolve$9(sourceDir, path); // 源码要放到目标目录
|
|
1028
|
-
|
|
1029
|
-
const targetPath = resolve$9(targetDir, path); // 设置模块的构建分支
|
|
1030
|
-
|
|
1031
|
-
const cloneBranch = buildGitTag && typeof buildGitTag === 'string' ? buildGitTag : 'master'; // 检查缓存中有没有
|
|
1032
|
-
|
|
1033
|
-
const globalInstance = getGlobalInstance();
|
|
1034
|
-
const moduleInCache = globalInstance.getModuleCache(httpRepoUrl, cloneBranch);
|
|
1035
|
-
|
|
1036
|
-
try {
|
|
1037
|
-
if (!moduleInCache) {
|
|
1038
|
-
await downloadRepoForGit(httpRepoUrl, sourcePath, cloneBranch);
|
|
1039
|
-
globalInstance.setModuleCache(httpRepoUrl, cloneBranch, sourcePath);
|
|
1040
|
-
} else {
|
|
1041
|
-
sourcePath = globalInstance.getModuleCache(httpRepoUrl, cloneBranch).dest;
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
if (fs$9.existsSync(targetPath)) {
|
|
1045
|
-
shelljs$4.rm('-rf', targetPath);
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
|
|
1049
|
-
} catch (e) {
|
|
1050
|
-
fail$7(`downLoadAndMoveModule ${e}`); // eslint-disable-line
|
|
1051
|
-
|
|
1052
|
-
process.exit(-1);
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
var cloneModules_1 = {
|
|
1057
|
-
cloneModules: cloneModules$1
|
|
1058
|
-
};
|
|
1059
|
-
|
|
1060
996
|
var defaultTmsConfig$1 = {
|
|
1061
997
|
// 全局的环境配置项
|
|
1062
998
|
envData: {},
|
|
1063
999
|
// 模块配置信息
|
|
1064
1000
|
modules: [],
|
|
1065
1001
|
cloudDir: 'cloud',
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
dependencies: {},
|
|
1002
|
+
// 第三方依赖代码需要拷贝到本项目的
|
|
1003
|
+
dependencies: {},
|
|
1069
1004
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1005
|
+
/** 编译输出文件夹位置 */
|
|
1006
|
+
outputDir: 'dist',
|
|
1072
1007
|
|
|
1073
|
-
|
|
1074
|
-
|
|
1008
|
+
/** 源码监听路径 */
|
|
1009
|
+
sourceDir: './',
|
|
1075
1010
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
}
|
|
1011
|
+
/** 静态资源目录 */
|
|
1012
|
+
static: []
|
|
1079
1013
|
};
|
|
1080
1014
|
|
|
1081
1015
|
const loadash = require$$0__default$5;
|
|
1082
|
-
const fs$
|
|
1016
|
+
const fs$9 = require$$0__default$1;
|
|
1083
1017
|
const {
|
|
1084
1018
|
TMS_NAME: TMS_NAME$1,
|
|
1085
1019
|
TMS_CONFIG_FILENAME,
|
|
1086
|
-
MODULE_CONFIG_FILENAME
|
|
1020
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
1021
|
+
TMS_PRIVATE_FILENAME
|
|
1087
1022
|
} = require$$3;
|
|
1088
1023
|
const {
|
|
1089
|
-
resolve: resolve$
|
|
1024
|
+
resolve: resolve$9,
|
|
1090
1025
|
isObject
|
|
1091
1026
|
} = widgets;
|
|
1092
1027
|
const {
|
|
1093
|
-
setModuleConfig
|
|
1028
|
+
setModuleConfig,
|
|
1029
|
+
getValidModules
|
|
1094
1030
|
} = buildAppJson;
|
|
1095
1031
|
const defaultTmsConfig = defaultTmsConfig$1;
|
|
1096
1032
|
const {
|
|
1097
1033
|
fail: fail$6
|
|
1098
1034
|
} = log$2;
|
|
1035
|
+
const path$7 = require$$3__default;
|
|
1099
1036
|
/**
|
|
1100
|
-
* 读取tms.config.
|
|
1037
|
+
* 读取tms.config.js
|
|
1101
1038
|
* @param env {string} 环境变量
|
|
1102
1039
|
*/
|
|
1103
1040
|
|
|
1104
1041
|
const readTmsConfig$1 = function (env) {
|
|
1105
|
-
const tmsConfigPath = resolve$
|
|
1042
|
+
const tmsConfigPath = resolve$9(TMS_CONFIG_FILENAME);
|
|
1106
1043
|
|
|
1107
|
-
if (!fs$
|
|
1044
|
+
if (!fs$9.existsSync(tmsConfigPath)) {
|
|
1108
1045
|
fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
1109
1046
|
process.exit(1);
|
|
1110
1047
|
}
|
|
@@ -1115,8 +1052,50 @@ const readTmsConfig$1 = function (env) {
|
|
|
1115
1052
|
env
|
|
1116
1053
|
}); // 合并默认值
|
|
1117
1054
|
|
|
1118
|
-
loadash.mergeWith(tmsConfig, defaultTmsConfig);
|
|
1055
|
+
loadash.mergeWith(tmsConfig, defaultTmsConfig); // modules兼容处理
|
|
1056
|
+
|
|
1057
|
+
tmsConfig.modules = convertModules(tmsConfig.modules);
|
|
1119
1058
|
return tmsConfig;
|
|
1059
|
+
}; // convertModules 处理默认值
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
const convertModules = modules => {
|
|
1063
|
+
const newModules = [];
|
|
1064
|
+
modules.forEach((module, index) => {
|
|
1065
|
+
const newModule = {};
|
|
1066
|
+
|
|
1067
|
+
if (typeof module === 'string') {
|
|
1068
|
+
// 路径字符串
|
|
1069
|
+
Object.assign(newModule, {
|
|
1070
|
+
name: path$7.basename(module),
|
|
1071
|
+
path: module
|
|
1072
|
+
});
|
|
1073
|
+
} else if (typeof module === 'object') {
|
|
1074
|
+
Object.assign(newModule, module);
|
|
1075
|
+
|
|
1076
|
+
if (module.name === undefined) {
|
|
1077
|
+
newModule.name = path$7.basename(module.path);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
newModules.push(newModule);
|
|
1082
|
+
});
|
|
1083
|
+
return newModules;
|
|
1084
|
+
};
|
|
1085
|
+
/**
|
|
1086
|
+
* 读取tms.private.js
|
|
1087
|
+
*/
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
const readTmsPrivateCf$2 = function () {
|
|
1091
|
+
let tmsPrivateCg;
|
|
1092
|
+
const tmsPrivatePath = resolve$9(TMS_PRIVATE_FILENAME);
|
|
1093
|
+
|
|
1094
|
+
if (fs$9.existsSync(tmsPrivatePath)) {
|
|
1095
|
+
tmsPrivateCg = require(tmsPrivatePath);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
return tmsPrivateCg;
|
|
1120
1099
|
};
|
|
1121
1100
|
/**
|
|
1122
1101
|
* 从tms.config.json中检索用户传入的有效modules
|
|
@@ -1149,27 +1128,33 @@ const checkModules$1 = function (tmsConfig, modules) {
|
|
|
1149
1128
|
*/
|
|
1150
1129
|
|
|
1151
1130
|
|
|
1152
|
-
const tmsModulesMergeLocalModuleCfg$3 = (modules, appName
|
|
1131
|
+
const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
1153
1132
|
const newModules = [];
|
|
1154
1133
|
modules.forEach(({
|
|
1155
1134
|
path: relativePath,
|
|
1156
1135
|
name: moduleName
|
|
1157
1136
|
}, moduleIndex) => {
|
|
1158
|
-
const moduleConfigPath = resolve$
|
|
1159
|
-
|
|
1160
|
-
if (fs$
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
...
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1137
|
+
const moduleConfigPath = resolve$9(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
1138
|
+
|
|
1139
|
+
if (fs$9.existsSync(moduleConfigPath)) {
|
|
1140
|
+
try {
|
|
1141
|
+
let moduleConfigContent = fs$9.readFileSync(moduleConfigPath, 'utf-8');
|
|
1142
|
+
moduleConfigContent = setModuleConfig(moduleConfigContent, appName);
|
|
1143
|
+
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
1144
|
+
getValidModules(moduleContentArr).forEach(({
|
|
1145
|
+
name
|
|
1146
|
+
}, moduleContentArrIndex) => {
|
|
1147
|
+
if (name === moduleName) {
|
|
1148
|
+
newModules.push({ ...modules[moduleIndex],
|
|
1149
|
+
...moduleContentArr[moduleContentArrIndex]
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
} catch (e) {
|
|
1154
|
+
fail$6(`${moduleConfigPath}配置错误: ${e}`);
|
|
1155
|
+
newModules.push({ ...modules[moduleIndex]
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1173
1158
|
} else {
|
|
1174
1159
|
newModules.push({ ...modules[moduleIndex]
|
|
1175
1160
|
});
|
|
@@ -1177,16 +1162,186 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName, moduleDir) => {
|
|
|
1177
1162
|
});
|
|
1178
1163
|
return newModules;
|
|
1179
1164
|
};
|
|
1165
|
+
/**
|
|
1166
|
+
* 分包依赖了分包的模块 合并所依赖的modules
|
|
1167
|
+
* @param { object } tmsConfig
|
|
1168
|
+
* @param {array} modules
|
|
1169
|
+
* @param {string} moduleDir
|
|
1170
|
+
* @returns
|
|
1171
|
+
*/
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
|
|
1175
|
+
const moduleNames = [];
|
|
1176
|
+
modules.forEach(({
|
|
1177
|
+
name: moduleName
|
|
1178
|
+
}) => {
|
|
1179
|
+
moduleNames.push(moduleName);
|
|
1180
|
+
});
|
|
1181
|
+
let mergeModules = modules;
|
|
1182
|
+
let isOver = true;
|
|
1183
|
+
modules.forEach(({
|
|
1184
|
+
dependencies: dependencyModules
|
|
1185
|
+
}) => {
|
|
1186
|
+
dependencyModules === null || dependencyModules === void 0 ? void 0 : dependencyModules.forEach(item => {
|
|
1187
|
+
// 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
|
|
1188
|
+
// 否则递归处理,根据name找到相关配置加到modules里
|
|
1189
|
+
if (moduleNames.indexOf(item) === -1) {
|
|
1190
|
+
isOver = false;
|
|
1191
|
+
const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
|
|
1192
|
+
mergeModules = [...mergeModules, ...tmpModules];
|
|
1193
|
+
mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
});
|
|
1197
|
+
return isOver ? mergeModules : subModulesMergeDepModules$2(tmsConfig, mergeModules);
|
|
1198
|
+
};
|
|
1180
1199
|
|
|
1181
1200
|
var tkitUtils = {
|
|
1182
1201
|
readTmsConfig: readTmsConfig$1,
|
|
1202
|
+
readTmsPrivateCf: readTmsPrivateCf$2,
|
|
1183
1203
|
checkModules: checkModules$1,
|
|
1184
|
-
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3
|
|
1204
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
1205
|
+
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
const MetalSmith = require$$0__default$4;
|
|
1209
|
+
const {
|
|
1210
|
+
getGlobalInstance
|
|
1211
|
+
} = global;
|
|
1212
|
+
const {
|
|
1213
|
+
downloadRepoForGit,
|
|
1214
|
+
resolve: resolve$8
|
|
1215
|
+
} = widgets;
|
|
1216
|
+
const {
|
|
1217
|
+
readTmsPrivateCf: readTmsPrivateCf$1
|
|
1218
|
+
} = tkitUtils;
|
|
1219
|
+
const {
|
|
1220
|
+
fail: fail$5
|
|
1221
|
+
} = log$2;
|
|
1222
|
+
const fs$8 = require$$0__default$1;
|
|
1223
|
+
const shelljs$4 = require$$4__default;
|
|
1224
|
+
const {
|
|
1225
|
+
handleError: handleError$1
|
|
1226
|
+
} = handleError_1;
|
|
1227
|
+
/**
|
|
1228
|
+
* 处理用户没有clone git仓库权限问题——拼接账号信息
|
|
1229
|
+
* @param {*} httpRepoUrl
|
|
1230
|
+
* @param {*} moduleName
|
|
1231
|
+
* @returns
|
|
1232
|
+
*/
|
|
1233
|
+
|
|
1234
|
+
function replaceGitUrlAccount(httpRepoUrl, moduleName, privateCf) {
|
|
1235
|
+
var _privateCf$gitAccout;
|
|
1236
|
+
|
|
1237
|
+
let gitUrl = httpRepoUrl;
|
|
1238
|
+
const {
|
|
1239
|
+
username = '',
|
|
1240
|
+
pass = ''
|
|
1241
|
+
} = (privateCf === null || privateCf === void 0 ? void 0 : (_privateCf$gitAccout = privateCf.gitAccout) === null || _privateCf$gitAccout === void 0 ? void 0 : _privateCf$gitAccout[moduleName]) || {};
|
|
1242
|
+
const urlPrefixReg = /http(s)?:\/\//;
|
|
1243
|
+
|
|
1244
|
+
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
1245
|
+
gitUrl = gitUrl.replace(urlPrefixReg, val => `${val}${encodeURIComponent(username)}:${pass}@`);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
return gitUrl;
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
|
|
1252
|
+
* @param { string } sourceDir 缓存文件夹
|
|
1253
|
+
* @param { string } targetDir 目标文件夹
|
|
1254
|
+
* @param { arrary } ignore
|
|
1255
|
+
* @returns { undefined } no return
|
|
1256
|
+
*/
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
function moveFile(sourceDir, targetDir, ignore = []) {
|
|
1260
|
+
// 删除不是文件夹的文件
|
|
1261
|
+
return new Promise((resolve, reject) => {
|
|
1262
|
+
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1263
|
+
if (e) {
|
|
1264
|
+
fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1265
|
+
reject(e);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
resolve();
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* 下载目标模块
|
|
1274
|
+
* @param { string } sourceDir 缓存文件夹
|
|
1275
|
+
* @param { string } targetDir 目标文件夹
|
|
1276
|
+
* @param { boolean } isDev 是否是dev
|
|
1277
|
+
* @returns { array } modules 描述模块的列表
|
|
1278
|
+
*/
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
async function cloneModules$1(sourceDir, targetDir, modules, isDev) {
|
|
1282
|
+
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1283
|
+
const privateCf = readTmsPrivateCf$1(); // 根据小程序的配置文件下载模块, 并且处理信息
|
|
1284
|
+
|
|
1285
|
+
for (const moduleInfo of modules) {
|
|
1286
|
+
if (moduleInfo.repoInfo) {
|
|
1287
|
+
await downLoadAndMoveModule(sourceDir, targetDir, moduleInfo, privateCf, isDev);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* 下载模块信息并且将它移动到对应的位置
|
|
1293
|
+
* @param { string } sourceDir 代码缓存文件夹
|
|
1294
|
+
* @param { string } targetDir 代码要放到的目标文件夹
|
|
1295
|
+
* @param { boolean } isDev 是否是dev
|
|
1296
|
+
* @returns { array } moduleInfo 描述模块的信息
|
|
1297
|
+
*/
|
|
1298
|
+
|
|
1299
|
+
|
|
1300
|
+
async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo, privateCf, isDev) {
|
|
1301
|
+
const {
|
|
1302
|
+
repoInfo: {
|
|
1303
|
+
buildGitTag,
|
|
1304
|
+
httpRepoUrl
|
|
1305
|
+
},
|
|
1306
|
+
path,
|
|
1307
|
+
name
|
|
1308
|
+
} = moduleInfo; // 源码临时存在的源目录
|
|
1309
|
+
|
|
1310
|
+
let sourcePath = resolve$8(sourceDir, name); // 源码要放到目标目录
|
|
1311
|
+
|
|
1312
|
+
const targetPath = resolve$8(targetDir, path); // 设置模块的构建分支
|
|
1313
|
+
|
|
1314
|
+
const cloneBranch = buildGitTag && typeof buildGitTag === 'string' ? buildGitTag : 'master'; // 检查缓存中有没有
|
|
1315
|
+
|
|
1316
|
+
const globalInstance = getGlobalInstance();
|
|
1317
|
+
const moduleInCache = globalInstance.getModuleCache(httpRepoUrl, cloneBranch);
|
|
1318
|
+
|
|
1319
|
+
try {
|
|
1320
|
+
if (!moduleInCache) {
|
|
1321
|
+
// 处理仓库权限问题
|
|
1322
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name, privateCf);
|
|
1323
|
+
await downloadRepoForGit(gitUrl, sourcePath, cloneBranch);
|
|
1324
|
+
globalInstance.setModuleCache(httpRepoUrl, cloneBranch, sourcePath);
|
|
1325
|
+
} else {
|
|
1326
|
+
sourcePath = globalInstance.getModuleCache(httpRepoUrl, cloneBranch).dest;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
if (fs$8.existsSync(targetPath)) {
|
|
1330
|
+
shelljs$4.rm('-rf', `${targetPath}/*`);
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
|
|
1334
|
+
} catch (e) {
|
|
1335
|
+
handleError$1(e, isDev);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
var cloneModules_1 = {
|
|
1340
|
+
cloneModules: cloneModules$1
|
|
1185
1341
|
};
|
|
1186
1342
|
|
|
1187
|
-
/* eslint-disable require-jsdoc */
|
|
1188
1343
|
const ci = require$$0__default$6;
|
|
1189
|
-
const path$6 = require$$
|
|
1344
|
+
const path$6 = require$$3__default;
|
|
1190
1345
|
/**
|
|
1191
1346
|
* 获取小程序ci的Project对象
|
|
1192
1347
|
* @returns {Object} 小程序ci对象
|
|
@@ -1270,66 +1425,78 @@ var mpCiUtils = {
|
|
|
1270
1425
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1271
1426
|
*/
|
|
1272
1427
|
const fs$7 = require$$0__default$1;
|
|
1273
|
-
const
|
|
1274
|
-
const
|
|
1275
|
-
const
|
|
1428
|
+
const fsExtra = require$$1__default$3;
|
|
1429
|
+
const crypto = require$$2__default$1;
|
|
1430
|
+
const path$5 = require$$3__default;
|
|
1431
|
+
const shell = require$$4__default;
|
|
1432
|
+
const glob = require$$5__default;
|
|
1276
1433
|
const LOG = log$2;
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1279
|
-
|
|
1434
|
+
const shellJsOption = {
|
|
1435
|
+
async: false,
|
|
1436
|
+
silent: true
|
|
1437
|
+
};
|
|
1438
|
+
const dirPath = process.cwd(); // 项目根目录
|
|
1439
|
+
|
|
1440
|
+
const install$3 = async (packageJsonPath = '', retry = true, cacheDir) => {
|
|
1441
|
+
const obj = {};
|
|
1442
|
+
const packageContent = fs$7.readFileSync(packageJsonPath);
|
|
1443
|
+
const packageJson = JSON.parse(packageContent);
|
|
1444
|
+
obj.dependencies = packageJson.dependencies || {}; // obj.devDependencies = packageJson.devDependencies || {};
|
|
1445
|
+
// dependencies和devDependencies字段为空,没有需要安装的npm包,直接return
|
|
1446
|
+
// if (Object.keys(obj.dependencies).length === 0 && Object.keys(obj.devDependencies).length === 0) {
|
|
1447
|
+
|
|
1448
|
+
if (Object.keys(obj.dependencies).length === 0) {
|
|
1449
|
+
return;
|
|
1450
|
+
} // 以package.json中dependencies字段stringify后的md5值作为缓存key
|
|
1451
|
+
// 任意包名或者版本号的差异,将导致md5后的差异,从而导致缓存失效,重新下载
|
|
1452
|
+
// 如此来保证npm缓存的准确性
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
const str = JSON.stringify(obj);
|
|
1456
|
+
const key = crypto.createHash('md5').update(str).digest('hex');
|
|
1457
|
+
const keyPath = path$5.join(cacheDir, key);
|
|
1458
|
+
const tarFile = path$5.join(keyPath, 'node_modules.tar.gz'); // npm缓存路径不存在
|
|
1459
|
+
// 或者缓存的包大小小于512byte,认为缓存不合法
|
|
1460
|
+
// 清空缓存目录,重新下载npm包缓存
|
|
1461
|
+
|
|
1462
|
+
const missCache = !fsExtra.pathExistsSync(keyPath) || !fsExtra.existsSync(tarFile) || fsExtra.statSync(tarFile).size < 512;
|
|
1463
|
+
|
|
1464
|
+
if (missCache) {
|
|
1465
|
+
console.log(`未命中缓存,下载${packageJsonPath}依赖`);
|
|
1466
|
+
fsExtra.emptydirSync(keyPath);
|
|
1467
|
+
shell.cp('-f', packageJsonPath, keyPath);
|
|
1468
|
+
shell.cd(keyPath);
|
|
1280
1469
|
|
|
1470
|
+
try {
|
|
1471
|
+
shell.exec('npx yarn --production --registry http://mirrors.tencent.com/npm/', shellJsOption);
|
|
1472
|
+
} catch (err) {
|
|
1473
|
+
console.log('err', err);
|
|
1281
1474
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
}
|
|
1475
|
+
if (retry) {
|
|
1476
|
+
return await install$3(packageJsonPath, false);
|
|
1477
|
+
}
|
|
1286
1478
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1479
|
+
throw err;
|
|
1480
|
+
}
|
|
1289
1481
|
|
|
1290
|
-
|
|
1291
|
-
shell.
|
|
1482
|
+
shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', shellJsOption);
|
|
1483
|
+
shell.exec('rm -rf ./node_modules', shellJsOption);
|
|
1292
1484
|
}
|
|
1293
1485
|
|
|
1294
|
-
|
|
1295
|
-
shell.
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
const getNpmCache = function (targetDir, cacheDir) {
|
|
1303
|
-
const tarNpmFilename = getTarNpmFilename(targetDir);
|
|
1304
|
-
const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
|
|
1305
|
-
|
|
1306
|
-
if (fs$7.existsSync(tarNpmFilePath)) {
|
|
1307
|
-
const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
|
|
1308
|
-
shell.exec(cmd, {
|
|
1309
|
-
async: false,
|
|
1310
|
-
silent: true
|
|
1311
|
-
});
|
|
1312
|
-
} // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
|
|
1313
|
-
|
|
1486
|
+
shell.cp('-Rf', tarFile, `${path$5.dirname(packageJsonPath)}/`);
|
|
1487
|
+
shell.cd(path$5.dirname(packageJsonPath));
|
|
1488
|
+
shell.exec('tar -xzvf ./node_modules.tar.gz -C ./', shellJsOption);
|
|
1489
|
+
shell.exec('rm -rf ./node_modules.tar.gz', shellJsOption);
|
|
1490
|
+
return {
|
|
1491
|
+
missCache,
|
|
1492
|
+
key
|
|
1493
|
+
};
|
|
1314
1494
|
}; // 遍历安装指定目录下所有项目的npm依赖
|
|
1315
1495
|
|
|
1316
1496
|
|
|
1317
1497
|
const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
1318
1498
|
const packageJsonFiles = await findAllPackageJson(modules, contextDir);
|
|
1319
|
-
await Promise.all(packageJsonFiles.map(file =>
|
|
1320
|
-
const dir = path$5.dirname(file);
|
|
1321
|
-
shell.cd(dir);
|
|
1322
|
-
|
|
1323
|
-
if (!fs$7.existsSync(`${dir}/node_modules`)) {
|
|
1324
|
-
getNpmCache(dir, cacheDir);
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
shell.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
|
|
1328
|
-
silent: false
|
|
1329
|
-
});
|
|
1330
|
-
resolve();
|
|
1331
|
-
npmCache(dir, cacheDir);
|
|
1332
|
-
})));
|
|
1499
|
+
await Promise.all(packageJsonFiles.map(file => install$3(file, true, cacheDir)));
|
|
1333
1500
|
};
|
|
1334
1501
|
/**
|
|
1335
1502
|
* 递归查找指定条件的文件
|
|
@@ -1391,7 +1558,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1391
1558
|
const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
1392
1559
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1393
1560
|
|
|
1394
|
-
const cwd = contextDir ||
|
|
1561
|
+
const cwd = contextDir || dirPath;
|
|
1395
1562
|
const result = [path$5.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1396
1563
|
|
|
1397
1564
|
subRoots.forEach(subRoot => {
|
|
@@ -1441,21 +1608,16 @@ const {
|
|
|
1441
1608
|
buildMpNpm
|
|
1442
1609
|
} = mpCiUtils;
|
|
1443
1610
|
const {
|
|
1444
|
-
CACHE_DIR
|
|
1445
|
-
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$2
|
|
1611
|
+
CACHE_DIR
|
|
1446
1612
|
} = require$$3;
|
|
1447
1613
|
const {
|
|
1448
1614
|
cloudNpmInstall,
|
|
1449
1615
|
mpNpmInstallAll
|
|
1450
1616
|
} = npmUtils;
|
|
1451
|
-
const {
|
|
1452
|
-
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
|
|
1453
|
-
} = tkitUtils;
|
|
1454
|
-
|
|
1455
|
-
async function install$2(tmsConfig, modules, isCloud = true) {
|
|
1456
|
-
const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
|
|
1457
1617
|
|
|
1458
|
-
|
|
1618
|
+
async function install$2(tmsConfig, modules, isCloud = false) {
|
|
1619
|
+
// 小程序npm install
|
|
1620
|
+
await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$7(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
|
|
1459
1621
|
|
|
1460
1622
|
await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
|
|
1461
1623
|
appId: tmsConfig.appId,
|
|
@@ -1468,7 +1630,7 @@ async function install$2(tmsConfig, modules, isCloud = true) {
|
|
|
1468
1630
|
|
|
1469
1631
|
var install_1 = install$2;
|
|
1470
1632
|
|
|
1471
|
-
const shelljs$3 = require$$
|
|
1633
|
+
const shelljs$3 = require$$4__default;
|
|
1472
1634
|
const fs$6 = require$$0__default$1;
|
|
1473
1635
|
const io = io$2;
|
|
1474
1636
|
const {
|
|
@@ -1480,17 +1642,17 @@ const {
|
|
|
1480
1642
|
} = buildAppJson;
|
|
1481
1643
|
const {
|
|
1482
1644
|
MODULE_CODE_DIR,
|
|
1483
|
-
DEFAULT_COPY_CONFIG
|
|
1484
|
-
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$1
|
|
1645
|
+
DEFAULT_COPY_CONFIG
|
|
1485
1646
|
} = require$$3;
|
|
1486
1647
|
const {
|
|
1487
1648
|
cloneModules
|
|
1488
1649
|
} = cloneModules_1;
|
|
1489
1650
|
const {
|
|
1490
|
-
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$
|
|
1651
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2,
|
|
1652
|
+
subModulesMergeDepModules: subModulesMergeDepModules$1
|
|
1491
1653
|
} = tkitUtils;
|
|
1492
1654
|
const {
|
|
1493
|
-
fail: fail$
|
|
1655
|
+
fail: fail$4
|
|
1494
1656
|
} = log$2;
|
|
1495
1657
|
const install$1 = install_1;
|
|
1496
1658
|
/**
|
|
@@ -1502,19 +1664,19 @@ const install$1 = install_1;
|
|
|
1502
1664
|
*/
|
|
1503
1665
|
|
|
1504
1666
|
const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
1505
|
-
const outputDir = resolve$6(tmsConfig.
|
|
1667
|
+
const outputDir = resolve$6(tmsConfig.outputDir);
|
|
1506
1668
|
io.ensureDirExist(outputDir);
|
|
1507
1669
|
defaultFiles.forEach(item => {
|
|
1508
1670
|
if (fs$6.existsSync(resolve$6(item))) {
|
|
1509
|
-
shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.
|
|
1671
|
+
shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
|
|
1510
1672
|
}
|
|
1511
1673
|
}); // 拷贝模块的package.json到编译输出目录
|
|
1512
1674
|
|
|
1513
1675
|
targetModules.forEach(item => {
|
|
1514
|
-
const outputModuleDir = resolve$6(`${tmsConfig.
|
|
1676
|
+
const outputModuleDir = resolve$6(`${tmsConfig.outputDir}/${item.root}`);
|
|
1515
1677
|
|
|
1516
1678
|
if (!fs$6.existsSync(resolve$6(item.path))) {
|
|
1517
|
-
fail$
|
|
1679
|
+
fail$4(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1518
1680
|
process.exit(1);
|
|
1519
1681
|
}
|
|
1520
1682
|
|
|
@@ -1524,29 +1686,36 @@ const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
|
1524
1686
|
});
|
|
1525
1687
|
};
|
|
1526
1688
|
|
|
1527
|
-
async function task(tmsConfig, targetModules) {
|
|
1689
|
+
async function task(tmsConfig, targetModules, isDev) {
|
|
1528
1690
|
// 下载和移动代码
|
|
1529
|
-
await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1691
|
+
await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules, isDev); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1692
|
+
|
|
1693
|
+
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
1530
1694
|
|
|
1531
|
-
|
|
1532
|
-
console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
|
|
1695
|
+
newModules = subModulesMergeDepModules$1(tmsConfig, newModules); // 拷贝相关配置文件到输出目录
|
|
1533
1696
|
|
|
1534
1697
|
await createTask$1(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
|
|
1535
1698
|
|
|
1536
1699
|
await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
|
|
1537
1700
|
|
|
1538
|
-
await createTask$1(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
1701
|
+
await createTask$1(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules, isDev);
|
|
1539
1702
|
return newModules;
|
|
1540
1703
|
}
|
|
1541
1704
|
|
|
1542
|
-
async function
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1705
|
+
async function init$5(tmsConfig, targetModules, isDev) {
|
|
1706
|
+
try {
|
|
1707
|
+
const newModules = await task(tmsConfig, targetModules, isDev);
|
|
1708
|
+
return {
|
|
1709
|
+
targetModules: newModules
|
|
1710
|
+
};
|
|
1711
|
+
} catch (error) {
|
|
1712
|
+
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1713
|
+
fail$4(`init流程出现错误${errMsg}`);
|
|
1714
|
+
process.exit(1);
|
|
1715
|
+
}
|
|
1547
1716
|
}
|
|
1548
1717
|
|
|
1549
|
-
var init$5
|
|
1718
|
+
var init_1 = init$5;
|
|
1550
1719
|
|
|
1551
1720
|
var dev$3 = {exports: {}};
|
|
1552
1721
|
|
|
@@ -1570,7 +1739,7 @@ function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
|
1570
1739
|
} // eslint-disable-next-line
|
|
1571
1740
|
|
|
1572
1741
|
|
|
1573
|
-
file.contents =
|
|
1742
|
+
file.contents = Buffer.from(contents);
|
|
1574
1743
|
}
|
|
1575
1744
|
|
|
1576
1745
|
this.push(file);
|
|
@@ -1617,16 +1786,16 @@ var findCssImport = {
|
|
|
1617
1786
|
|
|
1618
1787
|
/* eslint-disable no-param-reassign */
|
|
1619
1788
|
const {
|
|
1620
|
-
fail: fail$
|
|
1789
|
+
fail: fail$3
|
|
1621
1790
|
} = log$2;
|
|
1622
1791
|
|
|
1623
1792
|
function pluginError$3(error, isWatch) {
|
|
1624
1793
|
const errMsg = error.message;
|
|
1625
1794
|
|
|
1626
1795
|
if (isWatch) {
|
|
1627
|
-
fail$
|
|
1796
|
+
fail$3(errMsg);
|
|
1628
1797
|
} else {
|
|
1629
|
-
fail$
|
|
1798
|
+
fail$3(errMsg);
|
|
1630
1799
|
process.exit(1);
|
|
1631
1800
|
}
|
|
1632
1801
|
}
|
|
@@ -1638,7 +1807,7 @@ var pluginError_1 = {
|
|
|
1638
1807
|
/* eslint-disable no-param-reassign */
|
|
1639
1808
|
const through$2 = require$$0__default$7;
|
|
1640
1809
|
const precinct = require$$1__default$4;
|
|
1641
|
-
const path$4 = require$$
|
|
1810
|
+
const path$4 = require$$3__default;
|
|
1642
1811
|
const {
|
|
1643
1812
|
findCssImports
|
|
1644
1813
|
} = findCssImport;
|
|
@@ -1710,14 +1879,14 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
1710
1879
|
// 依赖分析的文件
|
|
1711
1880
|
const anaFileOriginFile = file.history[0];
|
|
1712
1881
|
const anaFileRelativeModule = path$4.relative(resolve$5(module.from), anaFileOriginFile);
|
|
1713
|
-
const anaFileDestFile = resolve$5(tmsConfig.
|
|
1882
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
1714
1883
|
|
|
1715
1884
|
if (file.isBuffer()) {
|
|
1716
1885
|
let contents = String(file.contents);
|
|
1717
1886
|
const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
1718
1887
|
const copyModules = new Map();
|
|
1719
|
-
Object.keys(tmsConfig.
|
|
1720
|
-
const includePath = tmsConfig.
|
|
1888
|
+
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
1889
|
+
const includePath = tmsConfig.dependencies[includeName];
|
|
1721
1890
|
deps.forEach(depItem => {
|
|
1722
1891
|
if (depItem.indexOf(includeName) > -1) {
|
|
1723
1892
|
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
@@ -1739,7 +1908,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
1739
1908
|
const regRes = depItem.match(reg) || [];
|
|
1740
1909
|
|
|
1741
1910
|
if (regRes[2]) {
|
|
1742
|
-
const depDestPath = resolve$5(tmsConfig.
|
|
1911
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
1743
1912
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1744
1913
|
|
|
1745
1914
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -1747,7 +1916,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
1747
1916
|
depOriginFile,
|
|
1748
1917
|
depDestFile,
|
|
1749
1918
|
beforeDepPath: depItem,
|
|
1750
|
-
afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath)
|
|
1919
|
+
afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
1751
1920
|
});
|
|
1752
1921
|
}
|
|
1753
1922
|
}
|
|
@@ -1769,7 +1938,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
1769
1938
|
diffContentCopyFile$2(item.depOriginFile, item.depDestFile);
|
|
1770
1939
|
}); // console.log('mpCommonDep defs', defs);
|
|
1771
1940
|
});
|
|
1772
|
-
file.contents =
|
|
1941
|
+
file.contents = Buffer.from(contents);
|
|
1773
1942
|
}
|
|
1774
1943
|
|
|
1775
1944
|
this.push(file);
|
|
@@ -1785,7 +1954,7 @@ var mpCommonDep_1 = {
|
|
|
1785
1954
|
|
|
1786
1955
|
/* eslint-disable no-param-reassign */
|
|
1787
1956
|
const through$1 = require$$0__default$7;
|
|
1788
|
-
const path$3 = require$$
|
|
1957
|
+
const path$3 = require$$3__default;
|
|
1789
1958
|
const {
|
|
1790
1959
|
ext: ext$1,
|
|
1791
1960
|
fileInDir: fileInDir$1,
|
|
@@ -1807,7 +1976,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
1807
1976
|
// 当前分析的文件的路径
|
|
1808
1977
|
const anaFileOriginFile = file.history[0];
|
|
1809
1978
|
const anaFileRelativeModule = path$3.relative(resolve$4(module.from), anaFileOriginFile);
|
|
1810
|
-
const anaFileDestFile = resolve$4(tmsConfig.
|
|
1979
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
1811
1980
|
|
|
1812
1981
|
if (file.isBuffer()) {
|
|
1813
1982
|
const copyModules = new Map();
|
|
@@ -1817,8 +1986,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
1817
1986
|
contents = JSON.parse(contents);
|
|
1818
1987
|
|
|
1819
1988
|
if (contents.usingComponents) {
|
|
1820
|
-
Object.keys(tmsConfig.
|
|
1821
|
-
const includePath = tmsConfig.
|
|
1989
|
+
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
1990
|
+
const includePath = tmsConfig.dependencies[includeName];
|
|
1822
1991
|
Object.keys(contents.usingComponents).forEach(componentKey => {
|
|
1823
1992
|
const componentPath = contents.usingComponents[componentKey];
|
|
1824
1993
|
|
|
@@ -1842,7 +2011,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
1842
2011
|
const regRes = componentPath.match(reg) || [];
|
|
1843
2012
|
|
|
1844
2013
|
if (regRes[2]) {
|
|
1845
|
-
const depDestPath = resolve$4(tmsConfig.
|
|
2014
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
1846
2015
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1847
2016
|
|
|
1848
2017
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -1851,7 +2020,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
1851
2020
|
depOriginExt: extAlias,
|
|
1852
2021
|
depDestFile,
|
|
1853
2022
|
beforeDepPath: componentPath,
|
|
1854
|
-
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath)
|
|
2023
|
+
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
1855
2024
|
});
|
|
1856
2025
|
}
|
|
1857
2026
|
}
|
|
@@ -1894,7 +2063,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
1894
2063
|
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
1895
2064
|
});
|
|
1896
2065
|
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
1897
|
-
file.contents =
|
|
2066
|
+
file.contents = Buffer.from(contents);
|
|
1898
2067
|
}
|
|
1899
2068
|
|
|
1900
2069
|
this.push(file);
|
|
@@ -1911,7 +2080,7 @@ var mpJsonDep_1 = {
|
|
|
1911
2080
|
const through = require$$0__default$7;
|
|
1912
2081
|
const htmlparser2 = require$$1__default$5;
|
|
1913
2082
|
const fs$3 = require$$0__default$1;
|
|
1914
|
-
const path$2 = require$$
|
|
2083
|
+
const path$2 = require$$3__default;
|
|
1915
2084
|
const {
|
|
1916
2085
|
diffContentCopyFile,
|
|
1917
2086
|
ext,
|
|
@@ -2033,7 +2202,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2033
2202
|
// 依赖分析的文件
|
|
2034
2203
|
const anaFileOriginFile = file.history[0];
|
|
2035
2204
|
const anaFileRelativeModule = path$2.relative(resolve$3(module.from), anaFileOriginFile);
|
|
2036
|
-
const anaFileDestFile = resolve$3(tmsConfig.
|
|
2205
|
+
const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2037
2206
|
|
|
2038
2207
|
if (file.isBuffer()) {
|
|
2039
2208
|
let contents = String(file.contents);
|
|
@@ -2050,9 +2219,9 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2050
2219
|
file: depOriginFile,
|
|
2051
2220
|
extPath
|
|
2052
2221
|
} = extFile(name, depOriginPath);
|
|
2053
|
-
Object.keys(tmsConfig.
|
|
2222
|
+
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2054
2223
|
if (attributes.src.indexOf(includeName) > -1) {
|
|
2055
|
-
const includePath = tmsConfig.
|
|
2224
|
+
const includePath = tmsConfig.dependencies[includeName];
|
|
2056
2225
|
|
|
2057
2226
|
if (!fileInDir(includePath, depOriginFile)) {
|
|
2058
2227
|
pluginError(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
@@ -2064,7 +2233,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2064
2233
|
const regRes = attributes.src.match(reg) || [];
|
|
2065
2234
|
|
|
2066
2235
|
if (regRes[2]) {
|
|
2067
|
-
const depDestPath = resolve$3(tmsConfig.
|
|
2236
|
+
const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2068
2237
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2069
2238
|
|
|
2070
2239
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2072,7 +2241,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2072
2241
|
depOriginFile,
|
|
2073
2242
|
depDestFile,
|
|
2074
2243
|
beforeDepPath: attributes.src,
|
|
2075
|
-
afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile)
|
|
2244
|
+
afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
|
|
2076
2245
|
});
|
|
2077
2246
|
}
|
|
2078
2247
|
}
|
|
@@ -2113,7 +2282,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2113
2282
|
});
|
|
2114
2283
|
}
|
|
2115
2284
|
});
|
|
2116
|
-
file.contents =
|
|
2285
|
+
file.contents = Buffer.from(contents);
|
|
2117
2286
|
}
|
|
2118
2287
|
|
|
2119
2288
|
this.push(file);
|
|
@@ -2130,9 +2299,9 @@ var mpWxmlDep_1 = {
|
|
|
2130
2299
|
/* eslint-disable no-param-reassign */
|
|
2131
2300
|
const postcss$1 = require$$0__default$9;
|
|
2132
2301
|
const fs$2 = require$$0__default$1;
|
|
2133
|
-
const path$1 = require$$
|
|
2302
|
+
const path$1 = require$$3__default;
|
|
2134
2303
|
const {
|
|
2135
|
-
fail: fail$
|
|
2304
|
+
fail: fail$2
|
|
2136
2305
|
} = log$2;
|
|
2137
2306
|
var postcssFontBase64 = postcss$1.plugin('postcss-font-base64', options => {
|
|
2138
2307
|
options = { ...options,
|
|
@@ -2183,13 +2352,13 @@ var postcssFontBase64 = postcss$1.plugin('postcss-font-base64', options => {
|
|
|
2183
2352
|
return readAndEncodeFile(file);
|
|
2184
2353
|
}
|
|
2185
2354
|
|
|
2186
|
-
fail$
|
|
2355
|
+
fail$2(`${file} does not exist.`);
|
|
2187
2356
|
return '';
|
|
2188
2357
|
}
|
|
2189
2358
|
|
|
2190
2359
|
function readAndEncodeFile(file) {
|
|
2191
2360
|
const bitmap = fs$2.readFileSync(file);
|
|
2192
|
-
return
|
|
2361
|
+
return Buffer.from(bitmap).toString('base64');
|
|
2193
2362
|
}
|
|
2194
2363
|
};
|
|
2195
2364
|
});
|
|
@@ -2200,10 +2369,10 @@ const {
|
|
|
2200
2369
|
lastRun
|
|
2201
2370
|
} = require$$0__default$a;
|
|
2202
2371
|
const px2rpx = require$$1__default$6;
|
|
2203
|
-
const postcss = require$$2__default$
|
|
2204
|
-
const watch = require$$3__default$1;
|
|
2205
|
-
const
|
|
2206
|
-
|
|
2372
|
+
const postcss = require$$2__default$2;
|
|
2373
|
+
const watch = require$$3__default$1; // const cache = require('gulp-cache');
|
|
2374
|
+
// const image = require('gulp-image');
|
|
2375
|
+
|
|
2207
2376
|
const replaceEnv = replaceEnv_1;
|
|
2208
2377
|
const {
|
|
2209
2378
|
mpCommonDep
|
|
@@ -2216,7 +2385,7 @@ const {
|
|
|
2216
2385
|
} = mpWxmlDep_1;
|
|
2217
2386
|
const base64 = postcssFontBase64;
|
|
2218
2387
|
const {
|
|
2219
|
-
fail: fail$
|
|
2388
|
+
fail: fail$1
|
|
2220
2389
|
} = log$2;
|
|
2221
2390
|
|
|
2222
2391
|
const since = task => file => lastRun(task) > file.stat.ctime ? lastRun(task) : 0;
|
|
@@ -2247,13 +2416,13 @@ var compile = function (tmsConfig, {
|
|
|
2247
2416
|
switch (globKey) {
|
|
2248
2417
|
case 'js':
|
|
2249
2418
|
srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch)).pipe(dest(destPath)).on('error', err => {
|
|
2250
|
-
fail$
|
|
2419
|
+
fail$1(`js编译报错${err}`);
|
|
2251
2420
|
});
|
|
2252
2421
|
break;
|
|
2253
2422
|
|
|
2254
2423
|
case 'wxss':
|
|
2255
2424
|
srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).pipe(postcss([base64()])).on('error', err => {
|
|
2256
|
-
fail$
|
|
2425
|
+
fail$1(`postcss编译报错${err}`);
|
|
2257
2426
|
}).pipe(px2rpx({
|
|
2258
2427
|
designWidth: 375,
|
|
2259
2428
|
// 设计稿宽度,默认为750
|
|
@@ -2264,7 +2433,7 @@ var compile = function (tmsConfig, {
|
|
|
2264
2433
|
|
|
2265
2434
|
case 'json':
|
|
2266
2435
|
srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
|
|
2267
|
-
fail$
|
|
2436
|
+
fail$1(`json编译报错${err}`);
|
|
2268
2437
|
}).pipe(dest(destPath));
|
|
2269
2438
|
break;
|
|
2270
2439
|
|
|
@@ -2273,9 +2442,11 @@ var compile = function (tmsConfig, {
|
|
|
2273
2442
|
break;
|
|
2274
2443
|
|
|
2275
2444
|
case 'image':
|
|
2276
|
-
srcPipe.pipe(cache(image()))
|
|
2277
|
-
|
|
2278
|
-
})
|
|
2445
|
+
srcPipe // .pipe(cache(image()))
|
|
2446
|
+
// .on('error', (err) => {
|
|
2447
|
+
// fail(`image编译报错${err}`);
|
|
2448
|
+
// })
|
|
2449
|
+
.pipe(dest(destPath));
|
|
2279
2450
|
break;
|
|
2280
2451
|
|
|
2281
2452
|
case 'other':
|
|
@@ -2320,18 +2491,16 @@ var compile = function (tmsConfig, {
|
|
|
2320
2491
|
}
|
|
2321
2492
|
|
|
2322
2493
|
module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
2323
|
-
var _tmsConfig$gulp, _tmsConfig$gulp2;
|
|
2324
|
-
|
|
2325
2494
|
// 监听app.json
|
|
2326
2495
|
if (isWatch) {
|
|
2327
2496
|
watch(resolve('app.json'), {
|
|
2328
2497
|
ignoreInitial: false,
|
|
2329
2498
|
events: ['add', 'change']
|
|
2330
2499
|
}, () => {
|
|
2331
|
-
buildOutputAppJson(tmsConfig, newModules);
|
|
2500
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
2332
2501
|
});
|
|
2333
2502
|
} else {
|
|
2334
|
-
buildOutputAppJson(tmsConfig, newModules);
|
|
2503
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
2335
2504
|
} // 监听根目录的文件
|
|
2336
2505
|
|
|
2337
2506
|
|
|
@@ -2345,7 +2514,7 @@ var compile = function (tmsConfig, {
|
|
|
2345
2514
|
from: '',
|
|
2346
2515
|
to: ''
|
|
2347
2516
|
},
|
|
2348
|
-
destPath: resolve(tmsConfig.
|
|
2517
|
+
destPath: resolve(tmsConfig.outputDir),
|
|
2349
2518
|
srcOption: {
|
|
2350
2519
|
allowEmpty: true
|
|
2351
2520
|
},
|
|
@@ -2365,7 +2534,7 @@ var compile = function (tmsConfig, {
|
|
|
2365
2534
|
watch(`${resolve(module.path)}/**/module.config.json`, {
|
|
2366
2535
|
events: ['change']
|
|
2367
2536
|
}, () => {
|
|
2368
|
-
buildOutputAppJson(tmsConfig, newModules);
|
|
2537
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
2369
2538
|
});
|
|
2370
2539
|
}
|
|
2371
2540
|
|
|
@@ -2381,7 +2550,7 @@ var compile = function (tmsConfig, {
|
|
|
2381
2550
|
glob: { ...glob,
|
|
2382
2551
|
other: [`${resolve(module.path)}/**/*`, ...excludeGlob(glob)]
|
|
2383
2552
|
},
|
|
2384
|
-
destPath: resolve(tmsConfig.
|
|
2553
|
+
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
2385
2554
|
module: {
|
|
2386
2555
|
from: module.path,
|
|
2387
2556
|
to: module.root
|
|
@@ -2391,25 +2560,18 @@ var compile = function (tmsConfig, {
|
|
|
2391
2560
|
},
|
|
2392
2561
|
isWatch
|
|
2393
2562
|
});
|
|
2394
|
-
} //
|
|
2395
|
-
|
|
2563
|
+
} // 静态资源目录-拷贝
|
|
2396
2564
|
|
|
2397
|
-
if (tmsConfig !== null && tmsConfig !== void 0 && (_tmsConfig$gulp = tmsConfig.gulp) !== null && _tmsConfig$gulp !== void 0 && _tmsConfig$gulp.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.static.length) > 0) {
|
|
2398
|
-
for (const item of (_tmsConfig$gulp3 = tmsConfig.gulp) === null || _tmsConfig$gulp3 === void 0 ? void 0 : _tmsConfig$gulp3.static) {
|
|
2399
|
-
var _tmsConfig$gulp3;
|
|
2400
2565
|
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
wxml: `${item.from}/**/*.wxml`,
|
|
2406
|
-
image: `${item.from}/**/*.{png,jpg,jpeg,gif,svg}`
|
|
2407
|
-
};
|
|
2566
|
+
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
2567
|
+
for (const item of tmsConfig.static) {
|
|
2568
|
+
const from = item !== null && item !== void 0 && item.from.startsWith('/') ? item.from : resolve(item.from);
|
|
2569
|
+
const to = item !== null && item !== void 0 && item.to.startsWith('/') ? item.to : resolve(item.to);
|
|
2408
2570
|
compile$1(tmsConfig, {
|
|
2409
|
-
glob: {
|
|
2410
|
-
other: [
|
|
2571
|
+
glob: {
|
|
2572
|
+
other: [from]
|
|
2411
2573
|
},
|
|
2412
|
-
destPath:
|
|
2574
|
+
destPath: to,
|
|
2413
2575
|
module: item,
|
|
2414
2576
|
srcOption: {
|
|
2415
2577
|
allowEmpty: true
|
|
@@ -2426,11 +2588,11 @@ const semver$1 = require$$1__default$7;
|
|
|
2426
2588
|
const {
|
|
2427
2589
|
resolve: resolve$2
|
|
2428
2590
|
} = widgets;
|
|
2429
|
-
const path = require$$
|
|
2591
|
+
const path = require$$3__default;
|
|
2592
|
+
const shelljs$2 = require$$4__default;
|
|
2430
2593
|
const {
|
|
2431
|
-
|
|
2432
|
-
} =
|
|
2433
|
-
const shelljs$2 = require$$5__default;
|
|
2594
|
+
handleError
|
|
2595
|
+
} = handleError_1;
|
|
2434
2596
|
|
|
2435
2597
|
const getLatestVersion = npmName => {
|
|
2436
2598
|
const data = shelljs$2.exec(`npm view ${npmName} version`);
|
|
@@ -2445,7 +2607,7 @@ const getLatestVersion = npmName => {
|
|
|
2445
2607
|
*/
|
|
2446
2608
|
|
|
2447
2609
|
|
|
2448
|
-
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
2610
|
+
const checkDependencies$1 = (modules, cwd, outputDir, isDev) => {
|
|
2449
2611
|
// 步骤1. 收集package.json
|
|
2450
2612
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
2451
2613
|
// 1.1根目录的package.json
|
|
@@ -2468,13 +2630,13 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
|
2468
2630
|
|
|
2469
2631
|
for (const item of packageArr) {
|
|
2470
2632
|
const packageJson = fs$1.readFileSync(item.srcPackageDir, 'utf-8');
|
|
2471
|
-
let dependencies;
|
|
2633
|
+
let dependencies = {};
|
|
2472
2634
|
|
|
2473
2635
|
try {
|
|
2474
|
-
|
|
2636
|
+
const json = JSON.parse(packageJson);
|
|
2637
|
+
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
2475
2638
|
} catch (e) {
|
|
2476
|
-
|
|
2477
|
-
process.exit(1);
|
|
2639
|
+
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项`, isDev);
|
|
2478
2640
|
}
|
|
2479
2641
|
|
|
2480
2642
|
const dependenciesKeys = Object.keys(dependencies);
|
|
@@ -2518,12 +2680,12 @@ const fs = require$$0__default$1;
|
|
|
2518
2680
|
const {
|
|
2519
2681
|
resolve: resolve$1
|
|
2520
2682
|
} = widgets;
|
|
2521
|
-
const init$4 =
|
|
2683
|
+
const init$4 = init_1;
|
|
2522
2684
|
const {
|
|
2523
|
-
|
|
2685
|
+
MODULE_CONFIG_FILENAME
|
|
2524
2686
|
} = require$$3;
|
|
2525
2687
|
const {
|
|
2526
|
-
tmsModulesMergeLocalModuleCfg
|
|
2688
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
2527
2689
|
} = tkitUtils;
|
|
2528
2690
|
const {
|
|
2529
2691
|
checkDependencies
|
|
@@ -2531,8 +2693,9 @@ const {
|
|
|
2531
2693
|
const {
|
|
2532
2694
|
fail
|
|
2533
2695
|
} = log$2;
|
|
2696
|
+
const shelljs$1 = require$$4__default; // const io = require('../../../utils/io');
|
|
2534
2697
|
|
|
2535
|
-
function isInit(tmsConfig, targetModules, contextDir) {
|
|
2698
|
+
function isInit(tmsConfig, targetModules, contextDir, isDev) {
|
|
2536
2699
|
// 判断是否存在dist目录
|
|
2537
2700
|
if (!fs.existsSync(contextDir)) {
|
|
2538
2701
|
return true;
|
|
@@ -2558,10 +2721,10 @@ function isInit(tmsConfig, targetModules, contextDir) {
|
|
|
2558
2721
|
// 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
|
|
2559
2722
|
if (!item.root) {
|
|
2560
2723
|
return true;
|
|
2561
|
-
} //
|
|
2724
|
+
} // 判断dist目录是否有该模块
|
|
2562
2725
|
|
|
2563
2726
|
|
|
2564
|
-
if (!fs.existsSync(`${contextDir}/${item.root}`)) {
|
|
2727
|
+
if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
|
|
2565
2728
|
return true;
|
|
2566
2729
|
} // 判断源码目录是否有该模块
|
|
2567
2730
|
|
|
@@ -2573,52 +2736,67 @@ function isInit(tmsConfig, targetModules, contextDir) {
|
|
|
2573
2736
|
} // 判断package.json的版本是否有新的版本
|
|
2574
2737
|
|
|
2575
2738
|
|
|
2576
|
-
return checkDependencies(targetModules, resolve$1('./'), tmsConfig.
|
|
2739
|
+
return checkDependencies(targetModules, resolve$1('./'), tmsConfig.outputDir, isDev);
|
|
2740
|
+
} // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
2741
|
+
|
|
2742
|
+
|
|
2743
|
+
function delOtherModule(tmsConfig, targetModules) {
|
|
2744
|
+
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
|
|
2745
|
+
const targetModulesName = targetModules.map(item => item.name);
|
|
2746
|
+
modules.forEach(item => {
|
|
2747
|
+
if (item.root && targetModulesName.indexOf(item.name) === -1) {
|
|
2748
|
+
const moduleRootDir = resolve$1(`dist/${item.root}`);
|
|
2749
|
+
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
2750
|
+
silent: true
|
|
2751
|
+
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
2752
|
+
// io.ensureDirExist(moduleRootDir);
|
|
2753
|
+
}
|
|
2754
|
+
});
|
|
2577
2755
|
}
|
|
2578
2756
|
|
|
2579
2757
|
async function dev$2(tmsConfig, targetModules, env) {
|
|
2580
|
-
|
|
2581
|
-
|
|
2758
|
+
let newModules = targetModules;
|
|
2759
|
+
const isDev = true; // 判断是否进行init命令
|
|
2582
2760
|
|
|
2583
|
-
if (isInit(tmsConfig,
|
|
2584
|
-
// init
|
|
2585
|
-
const initData = await init$4(tmsConfig,
|
|
2761
|
+
if (isInit(tmsConfig, targetModules, resolve$1('dist'), isDev)) {
|
|
2762
|
+
// init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
|
|
2763
|
+
const initData = await init$4(tmsConfig, newModules, isDev);
|
|
2586
2764
|
newModules = initData.targetModules;
|
|
2587
2765
|
}
|
|
2588
2766
|
|
|
2589
|
-
console.log('当前dev启动的有效模块', newModules.map(item => item.name));
|
|
2767
|
+
console.log('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
2768
|
+
delOtherModule(tmsConfig, newModules);
|
|
2590
2769
|
gulpDev(tmsConfig, newModules, env);
|
|
2591
2770
|
}
|
|
2592
2771
|
|
|
2593
2772
|
var dev_1 = dev$2;
|
|
2594
2773
|
|
|
2595
|
-
const shelljs$1 = require$$5__default;
|
|
2596
2774
|
const dev$1 = dev$3.exports;
|
|
2597
2775
|
|
|
2598
2776
|
var build$2 = async (tmsConfig, newModules) => {
|
|
2599
|
-
shelljs$1.rm('-rf', tmsConfig.gulp.outputDir);
|
|
2600
2777
|
dev$1(tmsConfig, newModules, false);
|
|
2601
2778
|
};
|
|
2602
2779
|
|
|
2603
|
-
const shelljs = require$$
|
|
2780
|
+
const shelljs = require$$4__default;
|
|
2604
2781
|
const {
|
|
2605
2782
|
resolve
|
|
2606
2783
|
} = widgets;
|
|
2607
|
-
const init$3 =
|
|
2784
|
+
const init$3 = init_1;
|
|
2608
2785
|
const gulpBuild = build$2;
|
|
2609
2786
|
|
|
2610
2787
|
async function build$1(tmsConfig, targetModules, env) {
|
|
2611
2788
|
// 开始构建前,清理输出目录
|
|
2612
|
-
await shelljs.rm('-rf', resolve(tmsConfig.
|
|
2789
|
+
await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
2790
|
+
const isDev = false;
|
|
2613
2791
|
const {
|
|
2614
2792
|
targetModules: newModules
|
|
2615
|
-
} = await init$3(tmsConfig, targetModules);
|
|
2793
|
+
} = await init$3(tmsConfig, targetModules, isDev);
|
|
2616
2794
|
gulpBuild(tmsConfig, newModules, env);
|
|
2617
2795
|
}
|
|
2618
2796
|
|
|
2619
2797
|
var build_1 = build$1;
|
|
2620
2798
|
|
|
2621
|
-
const init$2 =
|
|
2799
|
+
const init$2 = init_1;
|
|
2622
2800
|
const dev = dev_1;
|
|
2623
2801
|
const build = build_1;
|
|
2624
2802
|
const install = install_1;
|
|
@@ -2630,23 +2808,27 @@ const {
|
|
|
2630
2808
|
} = require$$3;
|
|
2631
2809
|
const {
|
|
2632
2810
|
readTmsConfig,
|
|
2811
|
+
readTmsPrivateCf,
|
|
2633
2812
|
checkModules
|
|
2634
2813
|
} = tkitUtils;
|
|
2814
|
+
const {
|
|
2815
|
+
tmsModulesMergeLocalModuleCfg,
|
|
2816
|
+
subModulesMergeDepModules
|
|
2817
|
+
} = tkitUtils;
|
|
2635
2818
|
|
|
2636
|
-
const handleModulesArg = cmd => {
|
|
2637
|
-
//
|
|
2638
|
-
if (cmd.module === MODE.main) {
|
|
2639
|
-
return MODE.main;
|
|
2640
|
-
} // 单模块 或 多模块开发
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
const {
|
|
2644
|
-
argv
|
|
2645
|
-
} = process;
|
|
2646
|
-
const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
|
|
2647
|
-
|
|
2819
|
+
const handleModulesArg = (cmd, tmsPrivateCg) => {
|
|
2820
|
+
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
2648
2821
|
if (cmd.module) {
|
|
2822
|
+
const {
|
|
2823
|
+
argv
|
|
2824
|
+
} = process;
|
|
2825
|
+
const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
|
|
2649
2826
|
return [cmd.module, ...reset];
|
|
2827
|
+
} // 单模块或多模块开发-用户在tms.private.js指定的模块
|
|
2828
|
+
|
|
2829
|
+
|
|
2830
|
+
if (tmsPrivateCg !== null && tmsPrivateCg !== void 0 && tmsPrivateCg.modules && (tmsPrivateCg === null || tmsPrivateCg === void 0 ? void 0 : tmsPrivateCg.modules.length) > 0) {
|
|
2831
|
+
return tmsPrivateCg === null || tmsPrivateCg === void 0 ? void 0 : tmsPrivateCg.modules;
|
|
2650
2832
|
} // 全量模块
|
|
2651
2833
|
|
|
2652
2834
|
|
|
@@ -2654,38 +2836,44 @@ const handleModulesArg = cmd => {
|
|
|
2654
2836
|
};
|
|
2655
2837
|
|
|
2656
2838
|
async function run(commandName, cmd) {
|
|
2657
|
-
|
|
2839
|
+
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
2840
|
+
const tmsPrivateCg = readTmsPrivateCf(); // 处理module参数
|
|
2841
|
+
|
|
2842
|
+
const moduleArg = handleModulesArg(cmd, tmsPrivateCg);
|
|
2658
2843
|
const {
|
|
2659
|
-
env
|
|
2844
|
+
env = tmsPrivateCg === null || tmsPrivateCg === void 0 ? void 0 : tmsPrivateCg.env
|
|
2660
2845
|
} = cmd;
|
|
2661
2846
|
const tmsConfig = await createTask(readTmsConfig, '开始读取脚手架的配置项', '读取脚手架的配置项完成')(env);
|
|
2662
|
-
let modules;
|
|
2847
|
+
let modules;
|
|
2663
2848
|
|
|
2664
|
-
if (moduleArg === MODE.
|
|
2665
|
-
modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages])]);
|
|
2666
|
-
} else if (moduleArg === MODE.all) {
|
|
2849
|
+
if (moduleArg === MODE.all) {
|
|
2667
2850
|
// 全量模块
|
|
2668
2851
|
modules = tmsConfig.modules;
|
|
2669
2852
|
} else {
|
|
2670
2853
|
// 检查用户输入modules的有效性
|
|
2671
2854
|
modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...moduleArg])]);
|
|
2672
|
-
}
|
|
2855
|
+
} // tms.config.js的modules 合并 module.config.json的配置项
|
|
2856
|
+
|
|
2857
|
+
|
|
2858
|
+
let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
2859
|
+
|
|
2860
|
+
newModules = subModulesMergeDepModules(tmsConfig, newModules);
|
|
2673
2861
|
|
|
2674
2862
|
switch (commandName) {
|
|
2675
2863
|
case 'init':
|
|
2676
|
-
init$2(tmsConfig,
|
|
2864
|
+
init$2(tmsConfig, newModules, env);
|
|
2677
2865
|
return;
|
|
2678
2866
|
|
|
2679
2867
|
case 'dev':
|
|
2680
|
-
dev(tmsConfig,
|
|
2868
|
+
dev(tmsConfig, newModules, env);
|
|
2681
2869
|
return;
|
|
2682
2870
|
|
|
2683
2871
|
case 'install':
|
|
2684
|
-
install(tmsConfig,
|
|
2872
|
+
install(tmsConfig, newModules, env);
|
|
2685
2873
|
return;
|
|
2686
2874
|
|
|
2687
2875
|
case 'build':
|
|
2688
|
-
build(tmsConfig,
|
|
2876
|
+
build(tmsConfig, newModules, env);
|
|
2689
2877
|
return;
|
|
2690
2878
|
|
|
2691
2879
|
default:
|
|
@@ -2738,7 +2926,7 @@ var entry = [{
|
|
|
2738
2926
|
|
|
2739
2927
|
var require$$6 = {
|
|
2740
2928
|
name: "@tmsfe/tmskit",
|
|
2741
|
-
version: "0.0.
|
|
2929
|
+
version: "0.0.6",
|
|
2742
2930
|
description: "tmskit",
|
|
2743
2931
|
main: "main.js",
|
|
2744
2932
|
bin: {
|
|
@@ -2779,6 +2967,7 @@ var require$$6 = {
|
|
|
2779
2967
|
"copy-webpack-plugin": "^9.1.0",
|
|
2780
2968
|
"download-git-repo": "^3.0.2",
|
|
2781
2969
|
ejs: "^3.1.5",
|
|
2970
|
+
"fs-extra": "^10.0.1",
|
|
2782
2971
|
"glob-ignore": "^1.0.2",
|
|
2783
2972
|
gulp: "^4.0.2",
|
|
2784
2973
|
"gulp-cache": "^1.1.3",
|