@tmsfe/tmskit 0.0.6 → 0.0.9-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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs.js +1203 -977
  3. package/main.js +1 -3
  4. package/package.json +2 -4
  5. package/src/{gulp → compile}/build.js +0 -0
  6. package/src/{gulp → compile}/compile.js +10 -7
  7. package/src/{gulp → compile}/dev.js +42 -15
  8. package/src/{gulp → compile}/plugins/less.js +0 -0
  9. package/src/{gulp → compile}/plugins/mpCommonDep.js +1 -1
  10. package/src/{gulp → compile}/plugins/mpJsonDep.js +7 -3
  11. package/src/{gulp → compile}/plugins/mpWxmlDep.js +1 -1
  12. package/src/{gulp → compile}/plugins/postcss-font-base64.js +0 -0
  13. package/src/{gulp → compile}/plugins/replaceEnv.js +0 -0
  14. package/src/{gulp → compile}/plugins/utils/pluginError.js +0 -0
  15. package/src/config/constant.js +6 -8
  16. package/src/{utils → core}/buildAppJson.js +14 -69
  17. package/src/{utils → core}/checkDependencies.js +3 -3
  18. package/src/core/cloneModules.js +203 -0
  19. package/src/{utils → core}/handleError.js +4 -2
  20. package/src/core/isInIt.js +69 -0
  21. package/src/{utils/mpCiUtils.js → core/mpCi.js} +0 -0
  22. package/src/core/npm.js +218 -0
  23. package/src/core/symbolicLink.js +24 -0
  24. package/src/{utils/tkitUtils.js → core/tmsMpconfig.js} +85 -9
  25. package/src/entry.js +13 -11
  26. package/src/index.js +7 -6
  27. package/src/init.js +2 -2
  28. package/src/scripts/create/index.js +2 -2
  29. package/src/scripts/run/build/index.js +3 -4
  30. package/src/scripts/run/dev/index.js +11 -53
  31. package/src/scripts/run/index.js +57 -28
  32. package/src/scripts/run/init/index.js +19 -11
  33. package/src/scripts/run/install/index.js +8 -6
  34. package/src/utils/global.js +19 -33
  35. package/src/utils/io.js +3 -2
  36. package/src/utils/log.js +3 -0
  37. package/src/utils/widgets.js +54 -43
  38. package/src/utils/cliUtils.js +0 -35
  39. package/src/utils/cloneModules.js +0 -116
  40. package/src/utils/npmUtils.js +0 -166
package/dist/index.cjs.js CHANGED
@@ -1,62 +1,58 @@
1
1
  'use strict';
2
2
 
3
- var require$$0 = require('commander');
3
+ var require$$0 = require('chalk');
4
+ var require$$0$1 = require('commander');
4
5
  var require$$1 = require('leven');
5
6
  var require$$2 = require('ora');
6
- var require$$3$1 = require('path');
7
- var require$$0$1 = require('fs');
8
- var require$$4 = require('shelljs');
9
- var require$$6$1 = require('download-git-repo');
10
- var require$$0$2 = require('chalk');
11
- var require$$0$3 = require('async');
7
+ var require$$3 = require('path');
8
+ var require$$0$2 = require('fs');
9
+ var require$$0$3 = require('shelljs');
10
+ var require$$0$4 = require('async');
12
11
  var require$$1$1 = require('ejs');
13
12
  var require$$1$2 = require('inquirer');
14
- var require$$0$4 = require('metalsmith');
15
- var require$$0$5 = require('lodash');
16
- var require$$0$6 = require('miniprogram-ci');
13
+ var require$$0$5 = require('metalsmith');
14
+ var require$$0$6 = require('lodash');
15
+ var require$$1$3 = require('crypto');
16
+ var require$$0$7 = require('miniprogram-ci');
17
17
  var require$$5 = require('glob-ignore');
18
- var require$$1$3 = require('fs-extra');
19
- var require$$2$1 = require('crypto');
20
- var require$$0$7 = require('through2');
18
+ var require$$1$4 = require('fs-extra');
19
+ var require$$9 = require('console');
21
20
  var require$$0$8 = require('strip-comments');
22
- var require$$1$4 = require('precinct');
23
- var require$$1$5 = require('htmlparser2');
24
- var require$$0$9 = require('postcss');
21
+ var require$$0$9 = require('through2');
22
+ var require$$1$5 = require('precinct');
23
+ var require$$1$6 = require('htmlparser2');
25
24
  var require$$0$a = require('gulp');
26
- var require$$1$6 = require('gulp-px-to-rpx');
27
- var require$$2$2 = require('gulp-postcss');
28
- var require$$3$2 = require('gulp-watch');
29
- var require$$1$7 = require('semver');
25
+ var require$$1$7 = require('gulp-px-to-rpx');
26
+ var require$$2$1 = require('gulp-watch');
27
+ var require$$1$8 = require('semver');
30
28
 
31
29
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
32
30
 
33
31
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
32
+ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
34
33
  var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
35
34
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
36
- var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
37
- var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
38
- var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
39
- var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
35
+ var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
40
36
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
41
37
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
38
+ var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
42
39
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
43
40
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
44
- var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
45
41
  var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
46
42
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
47
- var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
48
43
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
49
- var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
50
44
  var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
51
- var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
45
+ var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
52
46
  var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
53
- var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
47
+ var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
48
+ var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
54
49
  var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
55
- var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
50
+ var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
56
51
  var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
57
- var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
58
- var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
52
+ var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
59
53
  var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
54
+ var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
55
+ var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
60
56
 
61
57
  function getAugmentedNamespace(n) {
62
58
  if (n.__esModule) return n;
@@ -75,36 +71,86 @@ function getAugmentedNamespace(n) {
75
71
 
76
72
  var src$2 = {};
77
73
 
78
- const program$1 = require$$0__default;
74
+ const chalk$3 = require$$0__default;
75
+ /**
76
+ * 本文件提供无依赖的在终端打印彩色文字的方法。
77
+ */
78
+
79
+ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按,用来还原属性
80
+
81
+ /**
82
+ * 打印红底黑字格式的文字
83
+ * @param {String} message 需要打印的文字信息
84
+ * @returns {undefined} 无
85
+ */
86
+
87
+ const fail$9 = (message = '') => {
88
+ const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
89
+
90
+ const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
91
+
92
+ console.log(`${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
93
+ };
94
+ /**
95
+ * 打印绿底黑字格式的文字
96
+ * @param {String} message 需要打印的文字信息
97
+ * @returns {undefined} 无
98
+ */
99
+
100
+
101
+ const succeed$1 = (message = '') => {
102
+ const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
103
+
104
+ const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
105
+
106
+ console.log(`${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
107
+ };
108
+ /**
109
+ * 打印warn提示
110
+ * @param {String} message 需要打印的文字信息
111
+ * @returns {undefined} 无
112
+ */
113
+
114
+
115
+ const warn = message => {
116
+ console.log(chalk$3.yellow(message));
117
+ };
118
+
119
+ const info$9 = (...args) => console.log(...args);
120
+
121
+ var log$1 = {
122
+ fail: fail$9,
123
+ succeed: succeed$1,
124
+ warn,
125
+ info: info$9
126
+ };
127
+
128
+ const program$1 = require$$0__default$1;
79
129
  const leven = require$$1__default;
80
130
  const ora = require$$2__default;
81
- const path$b = require$$3__default;
82
- const fs$e = require$$0__default$1;
83
- const shelljs$6 = require$$4__default;
84
- const download = require$$6__default;
85
- const chalk$3 = require$$0__default$2;
131
+ const path$a = require$$3__default;
132
+ const fs$e = require$$0__default$2;
133
+ const shelljs$6 = require$$0__default$3;
134
+ const {
135
+ info: info$8
136
+ } = log$1;
137
+ const chalk$2 = require$$0__default;
86
138
  const shelljsOptions = {
87
- slient: true
139
+ slient: true,
140
+ async: false
88
141
  }; // 获取当前目录
89
142
 
90
143
  const cwd = process.cwd();
91
144
 
92
- function resolve$d(...args) {
93
- return path$b.resolve(cwd, ...args);
145
+ function resolve$f(...args) {
146
+ return path$a.resolve(cwd, ...args);
94
147
  }
95
- /**
96
- * 封装logs
97
- * @returns {Undefined} 无需返回值
98
- */
99
-
100
- const log$3 = (...args) => console.log(...args);
101
148
  /**
102
149
  * 用户输入命令时,进行提示
103
150
  * @param {String} unknownCommand 非预期的命令
104
151
  * @returns {Undefined} 无需返回值
105
152
  */
106
153
 
107
-
108
154
  const suggestCommands$1 = unknownCommand => {
109
155
  const availableCommands = program$1.commands.map(cmd => cmd._name);
110
156
  let suggestion;
@@ -117,7 +163,7 @@ const suggestCommands$1 = unknownCommand => {
117
163
  });
118
164
 
119
165
  if (suggestion) {
120
- log$3(` ${chalk$3.red(`Did you mean ${chalk$3.yellow(suggestion)}?`)}`);
166
+ info$8(` ${chalk$2.red(`Did you mean ${chalk$2.yellow(suggestion)}?`)}`);
121
167
  }
122
168
  };
123
169
  /**
@@ -141,70 +187,80 @@ function isArray$1(obj) {
141
187
  return Object.prototype.toString.call(obj) === '[object Array]';
142
188
  }
143
189
  /**
144
- * 下载模块到目标目录
190
+ * 下载模块代码
191
+ * @param { string } url 模块地址
145
192
  * @param { string } dest 目标地址
146
- * @param { object } downloadOptions 模块下载配置 { repoUrl-仓库地址, gitUrl-git地址, branch-分支或者tag }
193
+ * @param { string } branch 分支名
147
194
  * @returns { undefined } no return
148
195
  */
149
196
 
150
197
 
151
- function downloadRepo(dest, downloadOptions = {
152
- repoUrl: '',
153
- gitUrl: '',
154
- branch: ''
155
- }) {
156
- const {
157
- repoUrl,
158
- gitUrl,
159
- branch
160
- } = downloadOptions;
161
-
162
- if (fs$e.existsSync(dest)) {
163
- shelljs$6.rm('-rf', dest);
164
- }
165
-
166
- shelljs$6.mkdir('-p', dest);
167
- return new Promise(resolve => {
168
- download(`${repoUrl}#${branch}`, dest, {
169
- clone: true
170
- }, async e => {
171
- if (e) {
172
- console.log(e); // eslint-disable-line
198
+ function downloadRepoForGit$2(url, dest, branch) {
199
+ const cwd = process.cwd();
200
+ return new Promise((resolve, reject) => {
201
+ // 如果目标目录不存在
202
+ if (fs$e.existsSync(dest)) {
203
+ shelljs$6.rm('-rf', path$a.join(dest));
204
+ }
173
205
 
174
- await downloadRepoForGit$2(gitUrl, dest, branch);
206
+ shelljs$6.mkdir('-p', dest);
207
+ shelljs$6.cd(dest);
208
+ shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
209
+ silent: true
210
+ }, (code, stdout, stderr) => {
211
+ if (code !== 0) {
212
+ reject(stderr);
175
213
  }
176
214
 
215
+ shelljs$6.cd(cwd);
177
216
  resolve();
178
217
  });
179
218
  });
180
219
  }
181
220
  /**
182
- * 下载模块到目标目录备用方案
183
- * @param { string } url 模块地址
184
- * @param { string } dest 目标地址
221
+ * pull模块代码
222
+ * @param { string } dest 下载代码的路径
185
223
  * @param { string } branch 分支名
186
224
  * @returns { undefined } no return
187
225
  */
188
226
 
189
227
 
190
- function downloadRepoForGit$2(url, dest, branch) {
228
+ function pullRepoForGit$1(dest, branch) {
191
229
  const cwd = process.cwd();
192
230
  return new Promise((resolve, reject) => {
193
- // 如果目标目录不存在
194
- if (fs$e.existsSync(dest)) {
195
- shelljs$6.rm('-rf', path$b.join(dest));
196
- }
197
-
198
- shelljs$6.mkdir('-p', dest);
199
231
  shelljs$6.cd(dest);
200
- const gitCloneRes = shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptions);
232
+ shelljs$6.exec('git config pull.rebase false', shelljsOptions);
233
+ shelljs$6.exec(`git pull origin ${branch}`, {
234
+ silent: true
235
+ }, (code, stdout, stderr) => {
236
+ if (code !== 0) {
237
+ reject(stderr);
238
+ }
201
239
 
202
- if (gitCloneRes.code !== 0) {
203
- reject(gitCloneRes.stderr);
204
- }
240
+ shelljs$6.cd(cwd);
241
+ resolve();
242
+ });
243
+ });
244
+ }
245
+ /**
246
+ * npm 下载依赖
247
+ * @param {*} dir
248
+ * @returns
249
+ */
250
+
251
+
252
+ function npmInstall$1(dir) {
253
+ return new Promise((resolve, reject) => {
254
+ shelljs$6.exec('npx yarn --production --registry http://mirrors.tencent.com/npm/', {
255
+ cwd: dir,
256
+ silent: true
257
+ }, (code, stdout, stderr) => {
258
+ if (code !== 0) {
259
+ reject(stderr);
260
+ }
205
261
 
206
- shelljs$6.cd(cwd);
207
- resolve();
262
+ resolve();
263
+ });
208
264
  });
209
265
  }
210
266
  /**
@@ -224,12 +280,12 @@ const cost = start => Date.now() - start;
224
280
  */
225
281
 
226
282
 
227
- function createTask$4(task, startText, endText) {
283
+ function createTask$3(task, startText, endText) {
228
284
  return async (...args) => {
229
285
  const start = Date.now();
230
286
  const spinner = ora(startText);
231
287
  spinner.start();
232
- console.log('\n');
288
+ info$8('\n');
233
289
  const result = await task(...args);
234
290
  endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
235
291
  spinner.stop();
@@ -245,49 +301,48 @@ function createTask$4(task, startText, endText) {
245
301
  const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
246
302
 
247
303
  var widgets = {
248
- resolve: resolve$d,
249
- log: log$3,
304
+ resolve: resolve$f,
250
305
  isObject: isObject$2,
251
306
  isArray: isArray$1,
252
- createTask: createTask$4,
253
- downloadRepo,
307
+ createTask: createTask$3,
254
308
  downloadRepoForGit: downloadRepoForGit$2,
309
+ pullRepoForGit: pullRepoForGit$1,
255
310
  suggestCommands: suggestCommands$1,
256
- camelize
311
+ camelize,
312
+ npmInstall: npmInstall$1
257
313
  };
258
314
 
259
- const path$a = require('path'); // 用户目录
315
+ const path$9 = require('path');
260
316
 
317
+ const os = require('os'); // 用户目录
261
318
 
262
- const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
263
319
 
264
- const CACHE_DIR$1 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
320
+ const HOME_DIR = os.homedir(); // 所有文件的缓存目录
265
321
 
266
- const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
322
+ const CACHE_DIR$1 = path$9.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
267
323
 
268
- const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
324
+ const TEMPLATE_DIR$1 = path$9.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
269
325
 
270
- const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
326
+ const MODULE_CODE_DIR$2 = path$9.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
327
+
328
+ const TEMPLATE_PATH$1 = path$9.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
271
329
 
272
330
  const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
273
331
 
274
332
  const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
275
333
  const TMS_PRIVATE_FILENAME$1 = 'tms.private.config.js'; // 模块代码的默认在modules子目录
276
334
 
277
- const DEFAULT_MODULE_DIR = 'modules'; // 模块的配置文件的名称
335
+ const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目录
336
+
337
+ const DEFAULT_CLOUD_MODULE_DIR$1 = './cloud'; // 模块的配置文件的名称
278
338
 
279
339
  const MODULE_CONFIG_FILENAME$3 = 'module.config.json'; // 默认的webpack entry
280
340
 
281
341
  const DEFAULT_WEBPACK_ENTRY = {
282
- app: path$a.resolve(process.cwd(), 'app')
342
+ app: path$9.resolve(process.cwd(), 'app')
283
343
  }; // 默认从源码拷贝到编译后的配置
284
344
 
285
- const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
286
-
287
- const MODE$1 = {
288
- all: 'all',
289
- multi: 'multi'
290
- };
345
+ const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
291
346
  const ENV = {
292
347
  dev: 'development',
293
348
  prod: 'production'
@@ -308,17 +363,20 @@ var constant = /*#__PURE__*/Object.freeze({
308
363
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$3,
309
364
  DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
310
365
  DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
311
- MODULE_CODE_DIR: MODULE_CODE_DIR$1,
312
- MODE: MODE$1,
366
+ MODULE_CODE_DIR: MODULE_CODE_DIR$2,
313
367
  ENV: ENV,
314
368
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
315
- MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1
369
+ MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1,
370
+ DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR$1
316
371
  });
317
372
 
318
- var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
373
+ var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
319
374
 
320
- const fs$d = require$$0__default$1;
321
- const path$9 = require$$3__default;
375
+ const fs$d = require$$0__default$2;
376
+ const path$8 = require$$3__default;
377
+ const {
378
+ info: info$7
379
+ } = log$1;
322
380
  /**
323
381
  * 判断目录是否为空
324
382
  * @param {string} dirname 目录名
@@ -356,7 +414,7 @@ const copyFile = function (src, dest) {
356
414
  fs$d.unlinkSync(dest);
357
415
  }
358
416
 
359
- const dir = path$9.dirname(dest);
417
+ const dir = path$8.dirname(dest);
360
418
  ensureDirExist(dir);
361
419
  fs$d.copyFileSync(src, dest);
362
420
  }; // 判断文件内容是否一致,不一致再进行拷贝
@@ -368,11 +426,11 @@ function diffContentCopyFile$3(originFile, destFile) {
368
426
  const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
369
427
 
370
428
  if (depDestContent !== depOriginContent) {
371
- console.log(`拷贝${originFile}内容到${destFile}`);
429
+ info$7(`拷贝${originFile}内容到${destFile}`);
372
430
  copyFile(originFile, destFile);
373
431
  }
374
432
  } else {
375
- console.log(`拷贝${originFile}内容到${destFile}`);
433
+ info$7(`拷贝${originFile}内容到${destFile}`);
376
434
  copyFile(originFile, destFile);
377
435
  }
378
436
  } // 添加后缀
@@ -416,7 +474,7 @@ const fileInDir$3 = (dir, file) => {
416
474
  return false;
417
475
  }
418
476
 
419
- const relativePath = path$9.relative(dir, file);
477
+ const relativePath = path$8.relative(dir, file);
420
478
 
421
479
  if (relativePath.startsWith('..')) {
422
480
  return false;
@@ -435,58 +493,7 @@ var io$2 = {
435
493
  isFile
436
494
  };
437
495
 
438
- const chalk$2 = require$$0__default$2;
439
- /**
440
- * 本文件提供无依赖的在终端打印彩色文字的方法。
441
- */
442
-
443
- const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按,用来还原属性
444
-
445
- /**
446
- * 打印红底黑字格式的文字
447
- * @param {String} message 需要打印的文字信息
448
- * @returns {undefined} 无
449
- */
450
-
451
- const fail$a = (message = '') => {
452
- const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
453
-
454
- const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
455
-
456
- console.log(`${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
457
- };
458
- /**
459
- * 打印绿底黑字格式的文字
460
- * @param {String} message 需要打印的文字信息
461
- * @returns {undefined} 无
462
- */
463
-
464
-
465
- const succeed$1 = (message = '') => {
466
- const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
467
-
468
- const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
469
-
470
- console.log(`${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
471
- };
472
- /**
473
- * 打印warn提示
474
- * @param {String} message 需要打印的文字信息
475
- * @returns {undefined} 无
476
- */
477
-
478
-
479
- const warn = message => {
480
- console.log(chalk$2.yellow(message));
481
- };
482
-
483
- var log$2 = {
484
- fail: fail$a,
485
- succeed: succeed$1,
486
- warn
487
- };
488
-
489
- const async = require$$0__default$3;
496
+ const async = require$$0__default$4;
490
497
  const ejs = require$$1__default$1;
491
498
 
492
499
  const render$1 = (files, metalsmith, next) => {
@@ -506,14 +513,14 @@ const render$1 = (files, metalsmith, next) => {
506
513
 
507
514
  var render_1 = render$1;
508
515
 
509
- const fs$c = require$$0__default$1;
516
+ const fs$c = require$$0__default$2;
510
517
  const inquirer = require$$1__default$2;
511
518
  const {
512
- resolve: resolve$c
519
+ resolve: resolve$e
513
520
  } = widgets;
514
521
  const {
515
522
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
516
- } = require$$3;
523
+ } = require$$4;
517
524
  /**
518
525
  * 获取模板内的问题
519
526
  * @param {string} dir questions.json所在的目录
@@ -561,7 +568,7 @@ const isQuestionType = result => {
561
568
  };
562
569
 
563
570
  const ask$1 = templateDir => (files, metalsmith, next) => {
564
- const prompts = parseTemplateQuestions(resolve$c(templateDir, TEMPLATE_TKIT_DIR$1));
571
+ const prompts = parseTemplateQuestions(resolve$e(templateDir, TEMPLATE_TKIT_DIR$1));
565
572
  const metadata = metalsmith.metadata();
566
573
  const filteredPrompts = prompts.filter(prompt => {
567
574
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -586,7 +593,7 @@ var ask_1 = ask$1;
586
593
  const FILES_TO_IGNORE$1 = ['node_modules'];
587
594
  var ignoreFiles = FILES_TO_IGNORE$1;
588
595
 
589
- const Metalsmith = require$$0__default$4;
596
+ const Metalsmith = require$$0__default$5;
590
597
  const render = render_1;
591
598
  const ask = ask_1;
592
599
  const FILES_TO_IGNORE = ignoreFiles;
@@ -603,24 +610,25 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
603
610
 
604
611
  var generator_1 = generator$1;
605
612
 
606
- const path$8 = require$$3__default;
607
- const fs$b = require$$0__default$1;
608
- const shelljs$5 = require$$4__default;
613
+ const path$7 = require$$3__default;
614
+ const fs$b = require$$0__default$2;
615
+ const shelljs$5 = require$$0__default$3;
609
616
  const {
610
617
  TEMPLATE_DIR,
611
618
  TEMPLATE_PATH,
612
619
  TEMPLATE_TKIT_DIR
613
- } = require$$3;
620
+ } = require$$4;
614
621
  const {
615
622
  downloadRepoForGit: downloadRepoForGit$1,
616
- createTask: createTask$3,
617
- resolve: resolve$b
623
+ createTask: createTask$2,
624
+ resolve: resolve$d
618
625
  } = widgets;
619
626
  const io$1 = io$2;
620
627
  const {
621
- fail: fail$9,
622
- succeed
623
- } = log$2;
628
+ fail: fail$8,
629
+ succeed,
630
+ info: info$6
631
+ } = log$1;
624
632
  const generator = generator_1;
625
633
  /**
626
634
  * 如果该目录下面存在文件,换个名字
@@ -632,7 +640,7 @@ async function createAppDir(targetDir) {
632
640
  // 如果目录非空或者已经存在,提示用户,做选择
633
641
  if (fs$b.existsSync(targetDir)) {
634
642
  if (!(await io$1.isDirEmpty(targetDir))) {
635
- fail$9('该目录名已经存在,换个项目名字吧~');
643
+ fail$8('该目录名已经存在,换个项目名字吧~');
636
644
  process.exit(1);
637
645
  }
638
646
  } else {
@@ -648,21 +656,21 @@ async function createAppDir(targetDir) {
648
656
 
649
657
  async function create(appName) {
650
658
  const cwd = process.cwd();
651
- const targetDir = path$8.resolve(cwd, appName);
659
+ const targetDir = path$7.resolve(cwd, appName);
652
660
  const appType = 'mp';
653
661
  await createAppDir(targetDir); // 创建缓存目录
654
662
 
655
663
  io$1.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
656
664
 
657
- await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
665
+ await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
658
666
 
659
- generator(path$8.join(TEMPLATE_PATH, appType), targetDir, {
667
+ generator(path$7.join(TEMPLATE_PATH, appType), targetDir, {
660
668
  appName,
661
669
  appType
662
670
  }).then(() => {
663
671
  shelljs$5.cd(appName);
664
672
 
665
- const hooks = require(resolve$b(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
673
+ const hooks = require(resolve$d(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
666
674
 
667
675
  if (hooks.afterCreate) {
668
676
  hooks.afterCreate.forEach(item => {
@@ -676,108 +684,386 @@ async function create(appName) {
676
684
  });
677
685
  }
678
686
 
679
- shelljs$5.rm('-rf', resolve$b(appName, TEMPLATE_TKIT_DIR));
687
+ shelljs$5.rm('-rf', resolve$d(appName, TEMPLATE_TKIT_DIR));
680
688
  succeed('项目创建完成.');
681
689
  }).catch(err => {
682
- fail$9(err.message);
683
- console.log('详细的错误信息:', err);
690
+ fail$8(err.message);
691
+ info$6('详细的错误信息:', err);
684
692
  });
685
693
  }
686
694
 
687
695
  var create_1 = create;
688
696
 
689
- const {
690
- fail: fail$8
691
- } = log$2;
697
+ var defaultTmsConfig$1 = {
698
+ // 全局的环境配置项
699
+ envData: {},
700
+ // 模块配置信息
701
+ modules: [],
702
+ cloudDir: 'cloud',
703
+ // 第三方依赖代码需要拷贝到本项目的
704
+ dependencies: {},
692
705
 
693
- function handleError$3(error, isDev = false) {
694
- const errMsg = typeof error === 'object' ? error.message : error;
706
+ /** 编译输出文件夹位置 */
707
+ outputDir: 'dist',
695
708
 
696
- if (isDev) {
697
- fail$8(errMsg);
698
- } else {
699
- fail$8(errMsg);
700
- process.exit(1);
701
- }
702
- }
709
+ /** 源码监听路径 */
710
+ sourceDir: './',
703
711
 
704
- var handleError_1 = {
705
- handleError: handleError$3
712
+ /** 静态资源目录 */
713
+ static: []
706
714
  };
707
715
 
708
- const fs$a = require$$0__default$1;
716
+ /**
717
+ * 用来读取处理tms.config.js与module.config.json字段
718
+ */
719
+ const loadash = require$$0__default$6;
720
+ const fs$a = require$$0__default$2;
709
721
  const {
722
+ TMS_NAME: TMS_NAME$1,
723
+ TMS_CONFIG_FILENAME,
710
724
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
711
- MODULE_CONFIG_INVALID_KEY
712
- } = require$$3;
713
- const {
714
- fail: fail$7
715
- } = log$2;
725
+ TMS_PRIVATE_FILENAME
726
+ } = require$$4;
716
727
  const {
717
- resolve: resolve$a,
728
+ resolve: resolve$c,
718
729
  isObject: isObject$1,
719
730
  isArray
720
731
  } = widgets;
732
+ const defaultTmsConfig = defaultTmsConfig$1;
721
733
  const {
722
- handleError: handleError$2
723
- } = handleError_1;
734
+ fail: fail$7
735
+ } = log$1;
736
+ const path$6 = require$$3__default;
724
737
  /**
725
- * 获取每个模块下面的信息,并且收集,后续更新到appJson里面
726
- * @param { object } file 操作目录下面所有的文件
727
- * @param { string } appName 小程序的名称
738
+ * 读取tms.config.js
739
+ * @param env {string} 环境变量
728
740
  */
729
741
 
730
- function setModuleConfig$1(file, appName) {
731
- const content = file.contents ? JSON.parse(file.contents.toString()) : JSON.parse(file);
742
+ const readTmsConfig$1 = function (env) {
743
+ const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
732
744
 
733
- if (isArray(content)) {
734
- let i = content.length - 1;
745
+ if (!fs$a.existsSync(tmsConfigPath)) {
746
+ fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
747
+ process.exit(1);
748
+ }
735
749
 
736
- while (i >= 0) {
737
- let current = content[i];
750
+ const tmsConfigFn = require(tmsConfigPath);
738
751
 
739
- if (appName && current.mpConfig && current.mpConfig[appName]) {
740
- current = { ...current,
741
- ...current.mpConfig[appName]
742
- };
743
- }
752
+ const tmsConfig = tmsConfigFn({
753
+ env
754
+ }); // 合并默认值
744
755
 
745
- delete current.mpConfig;
746
- delete current.isSubpackages;
747
- content[i] = current;
748
- i--; // eslint-disable-line
756
+ loadash.mergeWith(tmsConfig, defaultTmsConfig); // modules兼容处理
757
+
758
+ tmsConfig.modules = convertModules(tmsConfig.modules);
759
+ return tmsConfig;
760
+ }; // convertModules 处理默认值
761
+
762
+
763
+ const convertModules = modules => {
764
+ const newModules = [];
765
+ modules.forEach(module => {
766
+ const newModule = {};
767
+
768
+ if (typeof module === 'string') {
769
+ // 路径字符串
770
+ Object.assign(newModule, {
771
+ name: path$6.basename(module),
772
+ path: module
773
+ });
774
+ } else if (typeof module === 'object') {
775
+ Object.assign(newModule, module);
776
+
777
+ if (module.name === undefined) {
778
+ newModule.name = path$6.basename(module.path);
779
+ }
749
780
  }
750
- }
751
781
 
752
- return content;
753
- }
782
+ newModules.push(newModule);
783
+ });
784
+ return newModules;
785
+ };
754
786
  /**
755
- * 递归获取本地所有模块的配置信息
787
+ * 读取tms.private.config.js
756
788
  */
757
789
 
758
790
 
759
- function getLocalModuleConfig(modules = [], appName, moduleConfigFilename) {
760
- const modulesConfig = {};
761
- modules.forEach(({
762
- path
763
- }) => {
764
- const moduleConfigPath = resolve$a(path, moduleConfigFilename);
791
+ const readTmsPrivateCf$1 = function () {
792
+ let tmsPrivateCf = {};
793
+ const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
794
+
795
+ if (fs$a.existsSync(tmsPrivatePath)) {
796
+ tmsPrivateCf = require(tmsPrivatePath);
797
+ } // 处理modules字段
798
+
799
+
800
+ if (tmsPrivateCf.modules instanceof Array) {
801
+ Object.assign(tmsPrivateCf.modules, {
802
+ include: tmsPrivateCf.modules
803
+ });
804
+ }
805
+
806
+ return tmsPrivateCf;
807
+ };
808
+ /**
809
+ * 从tms.config.json中检索用户传入的有效modules
810
+ * @param { object } tmsConfig
811
+ * @param { array } modules
812
+ * @returns
813
+ */
814
+
815
+
816
+ const checkModules$1 = function (tmsConfig, modules) {
817
+ const targetModules = [];
818
+ modules.forEach(moduleName => {
819
+ const module = tmsConfig.modules.find(module => module.name === moduleName);
820
+ module && targetModules.push(module);
821
+ });
822
+
823
+ if (targetModules.length === 0) {
824
+ fail$7(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
825
+ process.exit(1);
826
+ }
827
+
828
+ return targetModules;
829
+ };
830
+ /**
831
+ * 过滤页面为空的分包
832
+ * @param {Array} moduleCfg 模块配置内容
833
+ * @returns pages不为空的分包
834
+ */
835
+
836
+
837
+ const getValidModules$1 = moduleCfg => {
838
+ // 过滤 pages 为空的情况
839
+ const validModules = moduleCfg.filter(item => item.pages.length > 0);
840
+ return validModules;
841
+ };
842
+ /**
843
+ * 适配处理module.config.json的字段
844
+ * @param { object } fileContent module.config.json的内容
845
+ * @param { string } appName 小程序的名称
846
+ */
847
+
848
+
849
+ function adaptMpCgContent(fileContent, appName) {
850
+ const content = fileContent.contents ? JSON.parse(fileContent.contents.toString()) : JSON.parse(fileContent);
851
+
852
+ if (isArray(content)) {
853
+ let i = content.length - 1;
854
+
855
+ while (i >= 0) {
856
+ let current = content[i];
857
+
858
+ if (appName && current.mpConfig && current.mpConfig[appName]) {
859
+ current = { ...current,
860
+ ...current.mpConfig[appName]
861
+ };
862
+ }
863
+
864
+ delete current.mpConfig;
865
+ delete current.isSubpackages;
866
+ content[i] = current;
867
+ i--; // eslint-disable-line
868
+ }
869
+ }
870
+
871
+ return content;
872
+ }
873
+ /**
874
+ * 递归获取本地所有模块的配置信息
875
+ * @param {array} modules 用户要编译的模块列表
876
+ * @param { string } appName 小程序的名称
877
+ * @param { string } moduleConfigFilename moduleConfig的文件名
878
+ */
879
+
880
+
881
+ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
882
+ const modulesConfig = {};
883
+ modules.forEach(({
884
+ path
885
+ }) => {
886
+ const moduleConfigPath = resolve$c(path, moduleConfigFilename);
765
887
 
766
888
  if (fs$a.existsSync(moduleConfigPath)) {
767
889
  const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
768
- modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName);
890
+ modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
769
891
  }
770
892
  });
771
893
  return modulesConfig;
772
894
  }
773
895
  /**
774
- * 更新appJson里面的首页配置
896
+ * tms.config.js的modules 合并 module.config.json的配置项
897
+ * @param {array} modules
898
+ * @param {string} appName
899
+ * @param {string} moduleDir
900
+ * @returns
901
+ */
902
+
903
+
904
+ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
905
+ const newModules = [];
906
+ modules.forEach(({
907
+ path: relativePath,
908
+ name: moduleName
909
+ }, moduleIndex) => {
910
+ const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$2);
911
+
912
+ if (fs$a.existsSync(moduleConfigPath)) {
913
+ try {
914
+ let findModule = false;
915
+ let moduleConfigContent = fs$a.readFileSync(moduleConfigPath, 'utf-8');
916
+ moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
917
+ const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
918
+ getValidModules$1(moduleContentArr).forEach(({
919
+ name
920
+ }, moduleContentArrIndex) => {
921
+ if (name === moduleName) {
922
+ findModule = true;
923
+ newModules.push({ ...modules[moduleIndex],
924
+ ...moduleContentArr[moduleContentArrIndex]
925
+ });
926
+ }
927
+ });
928
+
929
+ if (!findModule) {
930
+ fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
931
+ process.exit(1);
932
+ }
933
+ } catch (e) {
934
+ fail$7(`${moduleConfigPath}配置错误: ${e}`);
935
+ newModules.push({ ...modules[moduleIndex]
936
+ });
937
+ }
938
+ } else {
939
+ newModules.push({ ...modules[moduleIndex]
940
+ });
941
+ }
942
+ });
943
+ return newModules;
944
+ };
945
+ /**
946
+ * 分包依赖了分包的模块 合并所依赖的modules
947
+ * @param { object } tmsConfig
948
+ * @param {array} modules
949
+ * @param {string} moduleDir
950
+ * @returns
951
+ */
952
+
953
+
954
+ const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
955
+ const moduleNames = [];
956
+ modules.forEach(({
957
+ name: moduleName
958
+ }) => {
959
+ moduleNames.push(moduleName);
960
+ });
961
+ let mergeModules = modules;
962
+ let isOver = true;
963
+ modules.forEach(({
964
+ dependencies: dependencyModules
965
+ }) => {
966
+ dependencyModules === null || dependencyModules === void 0 ? void 0 : dependencyModules.forEach(item => {
967
+ // 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
968
+ // 否则递归处理,根据name找到相关配置加到modules里
969
+ if (moduleNames.indexOf(item) === -1) {
970
+ isOver = false;
971
+ const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
972
+ mergeModules = [...mergeModules, ...tmpModules];
973
+ mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
974
+ }
975
+ });
976
+ });
977
+ return isOver ? mergeModules : subModulesMergeDepModules$2(tmsConfig, mergeModules);
978
+ };
979
+
980
+ var tmsMpconfig = {
981
+ readTmsConfig: readTmsConfig$1,
982
+ readTmsPrivateCf: readTmsPrivateCf$1,
983
+ getModuleConfig: getModuleConfig$1,
984
+ getValidModules: getValidModules$1,
985
+ checkModules: checkModules$1,
986
+ tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
987
+ subModulesMergeDepModules: subModulesMergeDepModules$2
988
+ };
989
+
990
+ const global$5 = {
991
+ data: {},
992
+
993
+ setData(...args) {
994
+ if (args.length === 1) {
995
+ Object.keys(args[0]).forEach(k => {
996
+ if (args[0][k]) {
997
+ this.data[k] = args[0][k];
998
+ }
999
+ });
1000
+ } else {
1001
+ const [name, value] = args;
1002
+ this.data[name] = value;
1003
+ }
1004
+ },
1005
+
1006
+ getData(name) {
1007
+ return this.data[name];
1008
+ }
1009
+
1010
+ };
1011
+ var global_1 = {
1012
+ global: global$5
1013
+ };
1014
+
1015
+ const {
1016
+ fail: fail$6
1017
+ } = log$1;
1018
+ const {
1019
+ global: global$4
1020
+ } = global_1;
1021
+
1022
+ function handleError$5(error) {
1023
+ const errMsg = typeof error === 'object' ? error.message : error;
1024
+ const isDev = global$4.getData('isDev');
1025
+
1026
+ if (isDev) {
1027
+ fail$6(errMsg);
1028
+ } else {
1029
+ fail$6(errMsg);
1030
+ process.exit(1);
1031
+ }
1032
+ }
1033
+
1034
+ var handleError_1 = {
1035
+ handleError: handleError$5
1036
+ };
1037
+
1038
+ /**
1039
+ * 生成编译后的app.json
1040
+ */
1041
+ const fs$9 = require$$0__default$2;
1042
+ const {
1043
+ MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
1044
+ MODULE_CONFIG_INVALID_KEY
1045
+ } = require$$4;
1046
+ const {
1047
+ getModuleConfig,
1048
+ getValidModules
1049
+ } = tmsMpconfig;
1050
+ const {
1051
+ fail: fail$5
1052
+ } = log$1;
1053
+ const {
1054
+ resolve: resolve$b,
1055
+ isObject
1056
+ } = widgets;
1057
+ const {
1058
+ handleError: handleError$4
1059
+ } = handleError_1;
1060
+ /**
1061
+ * 更新appJson里面的主包配置
775
1062
  * @param { object } appJson appJson信息
776
1063
  * @param { array } mainPackages 小程序主包信息
777
1064
  * @returns { object } appJson小程序主页配置信息
778
1065
  */
779
1066
 
780
-
781
1067
  function updateMainPackages(appJson, mainPackages = []) {
782
1068
  let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
783
1069
 
@@ -789,7 +1075,7 @@ function updateMainPackages(appJson, mainPackages = []) {
789
1075
 
790
1076
  foundMainPackages.forEach(subpackage => {
791
1077
  if (!subpackage.pages || !subpackage.pages.length) {
792
- fail$7(`主包 ${subpackage} 不能没有 pages`);
1078
+ fail$5(`主包 ${subpackage} 不能没有 pages`);
793
1079
  process.exit(-1);
794
1080
  }
795
1081
 
@@ -809,18 +1095,18 @@ function updateMainPackages(appJson, mainPackages = []) {
809
1095
  }
810
1096
  /**
811
1097
  * 获取app.json内容
812
- * @param {string} sourceAppJsonPath
1098
+ * @param {string} sourceAppJsonPath app.json存在的源码路径
813
1099
  * @returns
814
1100
  */
815
1101
 
816
1102
 
817
1103
  const getAppJsonContent = sourceAppJsonPath => {
818
- if (!fs$a.existsSync(sourceAppJsonPath)) {
819
- fail$7(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1104
+ if (!fs$9.existsSync(sourceAppJsonPath)) {
1105
+ fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
820
1106
  process.exit(1);
821
1107
  }
822
1108
 
823
- const appJson = JSON.parse(fs$a.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1109
+ const appJson = JSON.parse(fs$9.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
824
1110
 
825
1111
  appJson.subpackages = [];
826
1112
  appJson.pages = []; // appJson.plugins = {};
@@ -838,32 +1124,20 @@ const getAppJsonContent = sourceAppJsonPath => {
838
1124
  const updateSubpackages = (appJson, modulesConfig) => {
839
1125
  // eslint-disable-next-line
840
1126
  for (const name in modulesConfig) {
841
- const moduleInfo = isObject$1(modulesConfig[name]) ? [modulesConfig[name]] : modulesConfig[name]; // 过滤 pages 为空的情况
1127
+ const moduleInfo = isObject(modulesConfig[name]) ? [modulesConfig[name]] : modulesConfig[name]; // 过滤 pages 为空的情况
842
1128
 
843
- const validModules = getValidModules$1(moduleInfo); // eslint-disable-next-line
1129
+ const validModules = getValidModules(moduleInfo); // eslint-disable-next-line
844
1130
 
845
1131
  appJson.subpackages = appJson.subpackages.concat(validModules);
846
1132
  }
847
1133
  };
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
- };
860
1134
  /**
861
1135
  * 处理合并subpackages后的appjson, 整理重复不合法的地方
862
1136
  * @param {Object} appJson appjson
863
1137
  */
864
1138
 
865
1139
 
866
- const processAppJson = appJson => {
1140
+ const fixAppJson = appJson => {
867
1141
  const {
868
1142
  subpackages
869
1143
  } = appJson;
@@ -902,7 +1176,7 @@ const processAppJson = appJson => {
902
1176
  });
903
1177
 
904
1178
  if (invalidKeys.length) {
905
- fail$7(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
1179
+ fail$5(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
906
1180
  } // eslint-disable-next-line
907
1181
 
908
1182
 
@@ -919,7 +1193,7 @@ const processAppJson = appJson => {
919
1193
  }).reduce((pre, cur) => pre + cur, '');
920
1194
 
921
1195
  if (pluginsErrMsg) {
922
- fail$7(`plugins配置出现错误:${pluginsErrMsg}`);
1196
+ fail$5(`plugins配置出现错误:${pluginsErrMsg}`);
923
1197
  } // eslint-disable-next-line
924
1198
 
925
1199
 
@@ -928,317 +1202,104 @@ const processAppJson = appJson => {
928
1202
  /**
929
1203
  * 动态生成编译后的app.json
930
1204
  * @param {object} tmsConfig
931
- * @param {array} modules
1205
+ * @param {array} modules 用户要编译的模块列表
932
1206
  * @returns
933
1207
  */
934
1208
 
935
1209
 
936
- function buildOutputAppJson$1(tmsConfig, modules, isDev) {
1210
+ function buildOutputAppJson$1(tmsConfig, modules) {
937
1211
  try {
938
1212
  // 获取当前 modules 下的所有子模块的配置内容
939
- const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME$2); // 获取app.json的配置
1213
+ const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
940
1214
 
941
- const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
1215
+ const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
942
1216
 
943
1217
  updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
944
1218
 
945
- processAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1219
+ fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
946
1220
 
947
1221
  updateMainPackages(appJson, tmsConfig.mainPackages);
948
- fs$a.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1222
+ fs$9.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
949
1223
  return appJson;
950
1224
  } catch (e) {
951
- handleError$2(`生成app.json出现错误: ${e}`, isDev);
1225
+ handleError$4(`生成app.json出现错误: ${e}`);
952
1226
  }
953
1227
  }
954
1228
 
955
1229
  var buildAppJson = {
956
- setModuleConfig: setModuleConfig$1,
957
- getValidModules: getValidModules$1,
958
1230
  buildOutputAppJson: buildOutputAppJson$1
959
1231
  };
960
1232
 
961
- class Globale {
962
- constructor() {
963
- this.moduleCache = {};
964
- }
965
-
966
- setModuleCache(url, branch, dest) {
967
- const instance = getGlobalInstance$1();
968
- const key = `${branch}:${url}`;
969
- instance.moduleCache[key] = {
970
- dest
971
- };
972
- return instance.moduleCache[key];
973
- }
974
-
975
- getModuleCache(url, branch) {
976
- const instance = getGlobalInstance$1();
977
- return instance.moduleCache[`${branch}:${url}`];
978
- }
979
-
980
- }
981
-
982
- let instance;
983
-
984
- function getGlobalInstance$1() {
985
- if (instance) {
986
- return instance;
987
- }
988
-
989
- return instance = new Globale();
990
- }
991
-
992
- var global = {
993
- getGlobalInstance: getGlobalInstance$1
994
- };
995
-
996
- var defaultTmsConfig$1 = {
997
- // 全局的环境配置项
998
- envData: {},
999
- // 模块配置信息
1000
- modules: [],
1001
- cloudDir: 'cloud',
1002
- // 第三方依赖代码需要拷贝到本项目的
1003
- dependencies: {},
1004
-
1005
- /** 编译输出文件夹位置 */
1006
- outputDir: 'dist',
1007
-
1008
- /** 源码监听路径 */
1009
- sourceDir: './',
1010
-
1011
- /** 静态资源目录 */
1012
- static: []
1013
- };
1014
-
1015
- const loadash = require$$0__default$5;
1016
- const fs$9 = require$$0__default$1;
1017
- const {
1018
- TMS_NAME: TMS_NAME$1,
1019
- TMS_CONFIG_FILENAME,
1020
- MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
1021
- TMS_PRIVATE_FILENAME
1022
- } = require$$3;
1233
+ const fs$8 = require$$0__default$2;
1023
1234
  const {
1024
- resolve: resolve$9,
1025
- isObject
1235
+ resolve: resolve$a
1026
1236
  } = widgets;
1027
1237
  const {
1028
- setModuleConfig,
1029
- getValidModules
1030
- } = buildAppJson;
1031
- const defaultTmsConfig = defaultTmsConfig$1;
1238
+ handleError: handleError$3
1239
+ } = handleError_1;
1032
1240
  const {
1033
- fail: fail$6
1034
- } = log$2;
1035
- const path$7 = require$$3__default;
1241
+ DEFAULT_CLOUD_MODULE_DIR
1242
+ } = require$$4;
1036
1243
  /**
1037
- * 读取tms.config.js
1038
- * @param env {string} 环境变量
1244
+ * 根据相关配置创建软链接
1245
+ * @param { object } tmsConfig
1039
1246
  */
1040
1247
 
1041
- const readTmsConfig$1 = function (env) {
1042
- const tmsConfigPath = resolve$9(TMS_CONFIG_FILENAME);
1043
-
1044
- if (!fs$9.existsSync(tmsConfigPath)) {
1045
- fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
1046
- process.exit(1);
1047
- }
1048
-
1049
- const tmsConfigFn = require(tmsConfigPath);
1050
-
1051
- const tmsConfig = tmsConfigFn({
1052
- env
1053
- }); // 合并默认值
1054
-
1055
- loadash.mergeWith(tmsConfig, defaultTmsConfig); // modules兼容处理
1056
-
1057
- tmsConfig.modules = convertModules(tmsConfig.modules);
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
1248
+ const symLink$1 = tmsConfig => {
1249
+ try {
1250
+ if (tmsConfig.cloudModules) {
1251
+ tmsConfig.cloudModules.forEach(item => {
1252
+ fs$8.symlinkSync(resolve$a(item.path), resolve$a(DEFAULT_CLOUD_MODULE_DIR, item.name));
1072
1253
  });
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
1254
  }
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);
1255
+ } catch (e) {
1256
+ handleError$3(`创建软链错误: ${e}`);
1096
1257
  }
1097
-
1098
- return tmsPrivateCg;
1099
1258
  };
1100
- /**
1101
- * 从tms.config.json中检索用户传入的有效modules
1102
- * @param { object } tmsConfig
1103
- * @param { array } modules
1104
- * @returns
1105
- */
1106
-
1107
-
1108
- const checkModules$1 = function (tmsConfig, modules) {
1109
- const targetModules = [];
1110
- modules.forEach(moduleName => {
1111
- const module = tmsConfig.modules.find(module => module.name === moduleName);
1112
- module && targetModules.push(module);
1113
- });
1114
1259
 
1115
- if (targetModules.length === 0) {
1116
- fail$6(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
1117
- process.exit(1);
1118
- }
1119
-
1120
- return targetModules;
1260
+ var symbolicLink = {
1261
+ symLink: symLink$1
1121
1262
  };
1122
- /**
1123
- * tms.config.js的modules 合并 module.config.json的配置项
1124
- * @param {array} modules
1125
- * @param {string} appName
1126
- * @param {string} moduleDir
1127
- * @returns
1128
- */
1129
1263
 
1130
-
1131
- const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
1132
- const newModules = [];
1133
- modules.forEach(({
1134
- path: relativePath,
1135
- name: moduleName
1136
- }, moduleIndex) => {
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
- }
1158
- } else {
1159
- newModules.push({ ...modules[moduleIndex]
1160
- });
1161
- }
1162
- });
1163
- return newModules;
1164
- };
1165
1264
  /**
1166
- * 分包依赖了分包的模块 合并所依赖的modules
1167
- * @param { object } tmsConfig
1168
- * @param {array} modules
1169
- * @param {string} moduleDir
1170
- * @returns
1265
+ * 下载第三方代码
1171
1266
  */
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
- };
1199
-
1200
- var tkitUtils = {
1201
- readTmsConfig: readTmsConfig$1,
1202
- readTmsPrivateCf: readTmsPrivateCf$2,
1203
- checkModules: checkModules$1,
1204
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
1205
- subModulesMergeDepModules: subModulesMergeDepModules$2
1206
- };
1207
-
1208
- const MetalSmith = require$$0__default$4;
1209
- const {
1210
- getGlobalInstance
1211
- } = global;
1267
+ const MetalSmith = require$$0__default$5;
1268
+ const crypto$1 = require$$1__default$3;
1212
1269
  const {
1213
1270
  downloadRepoForGit,
1214
- resolve: resolve$8
1271
+ pullRepoForGit,
1272
+ resolve: resolve$9
1215
1273
  } = widgets;
1216
1274
  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;
1275
+ fail: fail$4,
1276
+ info: info$5
1277
+ } = log$1;
1278
+ const fs$7 = require$$0__default$2;
1279
+ const shelljs$4 = require$$0__default$3;
1224
1280
  const {
1225
- handleError: handleError$1
1281
+ handleError: handleError$2
1226
1282
  } = handleError_1;
1283
+ const {
1284
+ global: global$3
1285
+ } = global_1;
1227
1286
  /**
1228
- * 处理用户没有clone git仓库权限问题——拼接账号信息
1287
+ * 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
1229
1288
  * @param {*} httpRepoUrl
1230
1289
  * @param {*} moduleName
1231
1290
  * @returns
1232
1291
  */
1233
1292
 
1234
- function replaceGitUrlAccount(httpRepoUrl, moduleName, privateCf) {
1235
- var _privateCf$gitAccout;
1293
+ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1294
+ var _tmsPrivateCf$gitAcco;
1236
1295
 
1296
+ // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1297
+ const tmsPrivateCf = global$3.getData('tmsPrivateCf');
1237
1298
  let gitUrl = httpRepoUrl;
1238
1299
  const {
1239
1300
  username = '',
1240
1301
  pass = ''
1241
- } = (privateCf === null || privateCf === void 0 ? void 0 : (_privateCf$gitAccout = privateCf.gitAccout) === null || _privateCf$gitAccout === void 0 ? void 0 : _privateCf$gitAccout[moduleName]) || {};
1302
+ } = (tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : (_tmsPrivateCf$gitAcco = tmsPrivateCf.gitAccout) === null || _tmsPrivateCf$gitAcco === void 0 ? void 0 : _tmsPrivateCf$gitAcco[moduleName]) || {};
1242
1303
  const urlPrefixReg = /http(s)?:\/\//;
1243
1304
 
1244
1305
  if (username && pass && urlPrefixReg.test(gitUrl)) {
@@ -1261,7 +1322,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1261
1322
  return new Promise((resolve, reject) => {
1262
1323
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1263
1324
  if (e) {
1264
- fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1325
+ fail$4(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1265
1326
  reject(e);
1266
1327
  }
1267
1328
 
@@ -1269,79 +1330,180 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1269
1330
  });
1270
1331
  });
1271
1332
  }
1333
+ /**
1334
+ * 根据gitUrl 和 branch取md5值
1335
+ * @param {*} gitUrl
1336
+ * @param {*} branch
1337
+ * @returns
1338
+ */
1339
+
1340
+
1341
+ function md5ByGitUrlBranch(gitUrl, branch) {
1342
+ const newBranch = branch && typeof branch === 'string' ? branch : 'master';
1343
+ return crypto$1.createHash('md5').update(JSON.stringify({
1344
+ gitUrl,
1345
+ branch: newBranch
1346
+ })).digest('hex');
1347
+ }
1272
1348
  /**
1273
1349
  * 下载目标模块
1274
1350
  * @param { string } sourceDir 缓存文件夹
1275
1351
  * @param { string } targetDir 目标文件夹
1276
- * @param { boolean } isDev 是否是dev
1277
1352
  * @returns { array } modules 描述模块的列表
1278
1353
  */
1279
1354
 
1280
1355
 
1281
- async function cloneModules$1(sourceDir, targetDir, modules, isDev) {
1282
- // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1283
- const privateCf = readTmsPrivateCf$1(); // 根据小程序的配置文件下载模块, 并且处理信息
1356
+ async function cloneModules$1(sourceDir, targetDir, modules) {
1357
+ // 收集下载模块代码的任务
1358
+ const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules); // 开始执行下载和移动代码的任务
1284
1359
 
1285
- for (const moduleInfo of modules) {
1286
- if (moduleInfo.repoInfo) {
1287
- await downLoadAndMoveModule(sourceDir, targetDir, moduleInfo, privateCf, isDev);
1288
- }
1289
- }
1360
+ const arrPromises = [];
1361
+ downloadTasksMap.forEach(({
1362
+ promiseTask,
1363
+ params,
1364
+ callbacks
1365
+ }) => {
1366
+ arrPromises.push(promiseTask(...Object.keys(params).map(key => params[key])).then(async () => {
1367
+ const callArr = callbacks.map(async ({
1368
+ params: cParams,
1369
+ fn
1370
+ }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1371
+ return Promise.all(callArr);
1372
+ }).catch(e => {
1373
+ handleError$2(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1374
+ }));
1375
+ });
1376
+ await Promise.all(arrPromises);
1290
1377
  }
1291
1378
  /**
1292
- * 下载模块信息并且将它移动到对应的位置
1379
+ * 收集下载模块代码的任务
1293
1380
  * @param { string } sourceDir 代码缓存文件夹
1294
1381
  * @param { string } targetDir 代码要放到的目标文件夹
1295
- * @param { boolean } isDev 是否是dev
1296
- * @returns { array } moduleInfo 描述模块的信息
1382
+ * @returns { array } modules 描述模块的列表
1297
1383
  */
1298
1384
 
1299
1385
 
1300
- async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo, privateCf, isDev) {
1301
- const {
1302
- repoInfo: {
1303
- buildGitTag,
1304
- httpRepoUrl
1305
- },
1306
- path,
1307
- name
1308
- } = moduleInfo; // 源码临时存在的源目录
1386
+ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1387
+ // 下载代码任务 Map (key解释 缓存代码路径/md5(gitUrl,branch)
1388
+ // {
1389
+ // '/Users/odile/.tmskit/modules_code/026cb72509c2369dbd75779181f820bc': {
1390
+ // promiseTask, 下载代码的任务
1391
+ // params: { 下载代码时的参数
1392
+ // gitUrl,
1393
+ // sourcePath,
1394
+ // branch,
1395
+ // },
1396
+ // callbacks: [callback],// 下载完代码后的回调
1397
+ // }
1398
+ // }
1399
+ const downloadTasksMap = new Map();
1309
1400
 
1310
- let sourcePath = resolve$8(sourceDir, name); // 源码要放到目标目录
1401
+ for (const moduleInfo of modules) {
1402
+ if (moduleInfo.repoInfo) {
1403
+ const {
1404
+ repoInfo: {
1405
+ buildGitTag: branch,
1406
+ httpRepoUrl,
1407
+ path: gitPath = ''
1408
+ },
1409
+ path,
1410
+ name
1411
+ } = moduleInfo; // 处理仓库权限问题
1311
1412
 
1312
- const targetPath = resolve$8(targetDir, path); // 设置模块的构建分支
1413
+ const gitUrl = replaceGitUrlAccount(httpRepoUrl, name); // 根据gitUrl与branch计算md5
1313
1414
 
1314
- const cloneBranch = buildGitTag && typeof buildGitTag === 'string' ? buildGitTag : 'master'; // 检查缓存中有没有
1415
+ const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1315
1416
 
1316
- const globalInstance = getGlobalInstance();
1317
- const moduleInCache = globalInstance.getModuleCache(httpRepoUrl, cloneBranch);
1417
+ const sourcePath = resolve$9(sourceDir, md5Key); // 模块源码要放到目标目录
1318
1418
 
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
- }
1419
+ const targetPath = resolve$9(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1420
+
1421
+ const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1422
+
1423
+ const callback = {
1424
+ params: {
1425
+ sourceModulePath,
1426
+ targetPath
1427
+ },
1428
+ fn: async (sourceModulePath, targetPath) => {
1429
+ if (fs$7.existsSync(targetPath)) {
1430
+ shelljs$4.rm('-rf', `${targetPath}/*`);
1431
+ }
1432
+
1433
+ await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
1434
+ }
1435
+ };
1436
+
1437
+ if (downloadTasksMap.has(sourcePath)) {
1438
+ const task = downloadTasksMap.get(sourcePath);
1439
+ task.callbacks.push(callback);
1440
+ downloadTasksMap.set(sourcePath, task);
1441
+ } else {
1442
+ let promiseTask;
1443
+
1444
+ if (fs$7.existsSync(sourcePath) && fs$7.existsSync(`${sourcePath}/.git`)) {
1445
+ promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1446
+ info$5(`git pull仓库:${httpRepoUrl}`);
1447
+ return pullRepoForGit(sourcePath, branch);
1448
+ };
1449
+ } else {
1450
+ promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1451
+ info$5(`git clone仓库: ${httpRepoUrl}`);
1452
+ return downloadRepoForGit(gitUrl, sourcePath, branch);
1453
+ };
1454
+ }
1328
1455
 
1329
- if (fs$8.existsSync(targetPath)) {
1330
- shelljs$4.rm('-rf', `${targetPath}/*`);
1456
+ downloadTasksMap.set(sourcePath, {
1457
+ promiseTask,
1458
+ params: {
1459
+ gitUrl,
1460
+ sourcePath,
1461
+ branch,
1462
+ httpRepoUrl
1463
+ },
1464
+ callbacks: [callback]
1465
+ });
1466
+ }
1331
1467
  }
1468
+ }
1332
1469
 
1333
- await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
1334
- } catch (e) {
1335
- handleError$1(e, isDev);
1470
+ return downloadTasksMap;
1471
+ }
1472
+ /**
1473
+ * 检查远程模块的gitUrl与 branch是否有更新
1474
+ * @param {string} sourceDir 模块源码在缓存区的目录
1475
+ * @param {object} moduleInfo 模块的配置信息
1476
+ * @returns
1477
+ */
1478
+
1479
+
1480
+ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
1481
+ if (moduleInfo.repoInfo) {
1482
+ const {
1483
+ repoInfo: {
1484
+ buildGitTag,
1485
+ httpRepoUrl
1486
+ },
1487
+ name
1488
+ } = moduleInfo;
1489
+ const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
1490
+ const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
1491
+
1492
+ if (!fs$7.existsSync(`${sourceDir}/${md5Key}`)) {
1493
+ return true;
1494
+ }
1336
1495
  }
1496
+
1497
+ return false;
1337
1498
  }
1338
1499
 
1339
1500
  var cloneModules_1 = {
1340
- cloneModules: cloneModules$1
1501
+ cloneModules: cloneModules$1,
1502
+ checkRemoteModGitUrlBranch: checkRemoteModGitUrlBranch$1
1341
1503
  };
1342
1504
 
1343
- const ci = require$$0__default$6;
1344
- const path$6 = require$$3__default;
1505
+ const ci = require$$0__default$7;
1506
+ const path$5 = require$$3__default;
1345
1507
  /**
1346
1508
  * 获取小程序ci的Project对象
1347
1509
  * @returns {Object} 小程序ci对象
@@ -1355,7 +1517,7 @@ const getMpCi = ({
1355
1517
  }) => {
1356
1518
  var _cfgJsonContent$packO;
1357
1519
 
1358
- const cfgJsonContent = require(path$6.join(projectPath, 'project.config.json'));
1520
+ const cfgJsonContent = require(path$5.join(projectPath, 'project.config.json'));
1359
1521
 
1360
1522
  const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
1361
1523
  value
@@ -1417,108 +1579,165 @@ const buildMpNpm$1 = async ({
1417
1579
  return Promise.resolve();
1418
1580
  };
1419
1581
 
1420
- var mpCiUtils = {
1582
+ var mpCi = {
1421
1583
  buildMpNpm: buildMpNpm$1
1422
1584
  };
1423
1585
 
1424
1586
  /**
1425
1587
  * 本文件主要负责项目或者分包依赖的npm的安装
1426
1588
  */
1427
- const fs$7 = require$$0__default$1;
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;
1589
+ const fs$6 = require$$0__default$2;
1590
+ const fsExtra = require$$1__default$4;
1591
+ const crypto = require$$1__default$3;
1592
+ const path$4 = require$$3__default;
1593
+ const shell = require$$0__default$3;
1432
1594
  const glob = require$$5__default;
1433
- const LOG = log$2;
1595
+ const log = log$1;
1596
+ const {
1597
+ npmInstall
1598
+ } = widgets;
1599
+ const {
1600
+ handleError: handleError$1
1601
+ } = handleError_1;
1602
+ const {
1603
+ info: info$4
1604
+ } = require$$9__default;
1434
1605
  const shellJsOption = {
1435
1606
  async: false,
1436
1607
  silent: true
1437
1608
  };
1438
1609
  const dirPath = process.cwd(); // 项目根目录
1439
1610
 
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;
1611
+ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1612
+ // 下载代码任务 Map (key解释 缓存代码路径/md5(package.json.dependencies)
1613
+ // {
1614
+ // '/Users/odile/.tmskit/node_modules/026cb72509c2369dbd75779181f820bc': {
1615
+ // promiseTask, 下载的任务
1616
+ // params: { 下载代码时的参数
1617
+ // gitUrl,
1618
+ // sourcePath,
1619
+ // branch,
1620
+ // },
1621
+ // callbacks: [callback],// 下载完代码后的回调
1622
+ // }
1623
+ // }
1624
+ const npmTasksMap = new Map();
1625
+
1626
+ for (const packageJsonPath of packageJsonFiles) {
1627
+ const packageContent = fs$6.readFileSync(packageJsonPath);
1628
+ const packageJson = JSON.parse(packageContent);
1629
+ const md5Obj = {
1630
+ dependencies: packageJson.dependencies || {}
1631
+ };
1463
1632
 
1464
- if (missCache) {
1465
- console.log(`未命中缓存,下载${packageJsonPath}依赖`);
1466
- fsExtra.emptydirSync(keyPath);
1467
- shell.cp('-f', packageJsonPath, keyPath);
1468
- shell.cd(keyPath);
1633
+ if (Object.keys(md5Obj.dependencies).length !== 0) {
1634
+ const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
1635
+ const cacheNMPath = path$4.join(cacheDir, md5Key);
1636
+ const cacheNMTarFile = path$4.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
1637
+
1638
+ const callback = {
1639
+ params: {
1640
+ cacheNMPath,
1641
+ cacheNMTarFile,
1642
+ packageJsonDir: path$4.dirname(packageJsonPath),
1643
+ shell
1644
+ },
1645
+ fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
1646
+ shell.cd(cacheNMPath);
1647
+ shell.cp('-Rf', cacheNMTarFile, `${packageJsonDir}/`);
1648
+ const newShellJsOption = { ...shellJsOption,
1649
+ cwd: packageJsonDir
1650
+ };
1651
+ shell.exec('tar -xzvf ./node_modules.tar.gz -C ./', newShellJsOption);
1652
+ shell.exec('rm -rf ./node_modules.tar.gz', newShellJsOption);
1653
+ }
1654
+ };
1469
1655
 
1470
- try {
1471
- shell.exec('npx yarn --production --registry http://mirrors.tencent.com/npm/', shellJsOption);
1472
- } catch (err) {
1473
- console.log('err', err);
1656
+ if (npmTasksMap.has(cacheNMPath)) {
1657
+ const task = npmTasksMap.get(cacheNMPath);
1658
+ task.callbacks.push(callback);
1659
+ npmTasksMap.set(cacheNMPath, task);
1660
+ } else {
1661
+ const missCache = !fsExtra.pathExistsSync(cacheNMPath) || !fsExtra.existsSync(cacheNMTarFile) || fsExtra.statSync(cacheNMTarFile).size < 512;
1662
+
1663
+ let promiseTask = () => Promise.resolve();
1664
+
1665
+ if (missCache) {
1666
+ promiseTask = (packageJsonPath, cacheNMPath, shell) => {
1667
+ fsExtra.emptydirSync(cacheNMPath);
1668
+ shell.cp('-f', packageJsonPath, cacheNMPath);
1669
+ info$4(`npm install: ${packageJsonPath}`);
1670
+ return npmInstall(cacheNMPath).then(() => {
1671
+ const newShellJsOption = { ...shellJsOption,
1672
+ cwd: cacheNMPath
1673
+ };
1674
+ shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
1675
+ shell.exec('rm -rf ./node_modules', newShellJsOption);
1676
+ });
1677
+ };
1678
+ }
1474
1679
 
1475
- if (retry) {
1476
- return await install$3(packageJsonPath, false);
1680
+ npmTasksMap.set(cacheNMPath, {
1681
+ promiseTask,
1682
+ params: {
1683
+ packageJsonPath,
1684
+ cacheNMPath,
1685
+ shell
1686
+ },
1687
+ callbacks: [callback]
1688
+ });
1477
1689
  }
1478
-
1479
- throw err;
1480
1690
  }
1481
-
1482
- shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', shellJsOption);
1483
- shell.exec('rm -rf ./node_modules', shellJsOption);
1484
1691
  }
1485
1692
 
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
- };
1693
+ return npmTasksMap;
1494
1694
  }; // 遍历安装指定目录下所有项目的npm依赖
1495
1695
 
1496
1696
 
1497
1697
  const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1498
- const packageJsonFiles = await findAllPackageJson(modules, contextDir);
1499
- await Promise.all(packageJsonFiles.map(file => install$3(file, true, cacheDir)));
1698
+ const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
1699
+
1700
+ const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir); // 开始执行npm install和回调(移动)的任务
1701
+
1702
+ const arrPromises = [];
1703
+ npmTasksMap.forEach(({
1704
+ promiseTask,
1705
+ params,
1706
+ callbacks
1707
+ }) => {
1708
+ arrPromises.push(promiseTask(...Object.keys(params).map(key => params[key])).then(async () => {
1709
+ const callArr = callbacks.map(async ({
1710
+ params: cParams,
1711
+ fn
1712
+ }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1713
+ return Promise.all(callArr);
1714
+ }).catch(e => {
1715
+ handleError$1(`npm install ${params.packageJsonPath}出现错误:${e}`);
1716
+ }));
1717
+ });
1718
+ await Promise.all(arrPromises);
1500
1719
  };
1501
1720
  /**
1502
- * 递归查找指定条件的文件
1503
- * @param {String} startPath 开始查找的根路径
1504
- * @param {String} filter 匹配的字符串
1505
- * @returns {Array<String>} 查找到的文件路径列表
1506
- */
1721
+ * 递归查找指定条件的文件
1722
+ * @param {String} startPath 开始查找的根路径
1723
+ * @param {String} filter 匹配的字符串
1724
+ * @returns {Array<String>} 查找到的文件路径列表
1725
+ */
1507
1726
 
1508
1727
 
1509
1728
  const findFilesByFilter = (startPath, filter) => {
1510
1729
  const result = [];
1511
1730
  /**
1512
- * 根据指定的筛选器查找文件
1513
- * @param {String} startPath 开始查找的文件夹路径
1514
- * @param {String} filter 筛选器
1515
- * @returns {Undefined} 无需返回值
1516
- */
1731
+ * 根据指定的筛选器查找文件
1732
+ * @param {String} startPath 开始查找的文件夹路径
1733
+ * @param {String} filter 筛选器
1734
+ * @returns {Undefined} 无需返回值
1735
+ */
1517
1736
 
1518
1737
  const find = (startPath, filter) => {
1519
1738
  // 目录不存在
1520
- if (!fs$7.existsSync(startPath)) {
1521
- LOG.fail(`${startPath}目录不存在`);
1739
+ if (!fs$6.existsSync(startPath)) {
1740
+ log.fail(`${startPath}目录不存在`);
1522
1741
  process.exit(-1);
1523
1742
  return;
1524
1743
  } // 当前目录下的所有文件 / 文件夹
@@ -1530,10 +1749,10 @@ const findFilesByFilter = (startPath, filter) => {
1530
1749
  return;
1531
1750
  }
1532
1751
 
1533
- const files = fs$7.readdirSync(startPath);
1752
+ const files = fs$6.readdirSync(startPath);
1534
1753
  files.forEach(file => {
1535
- const filename = path$5.join(startPath, file);
1536
- const stat = fs$7.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1754
+ const filename = path$4.join(startPath, file);
1755
+ const stat = fs$6.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1537
1756
 
1538
1757
  if (stat.isDirectory()) {
1539
1758
  find(filename, filter);
@@ -1548,26 +1767,26 @@ const findFilesByFilter = (startPath, filter) => {
1548
1767
  return result;
1549
1768
  };
1550
1769
  /**
1551
- * 找到项目中所有的package.json文件
1552
- * @param {Array<String>} subRoots 需要安装npm依赖的路径
1553
- * @param {String} contextDir 命令运行的目录
1554
- * @returns {Array<String>} 找到的所有package.json文件的路径
1555
- */
1770
+ * 找到项目中所有的package.json文件
1771
+ * @param {Array<String>} subRoots 需要安装npm依赖的路径
1772
+ * @param {String} contextDir 命令运行的目录
1773
+ * @returns {Array<String>} 找到的所有package.json文件的路径
1774
+ */
1556
1775
 
1557
1776
 
1558
1777
  const findAllPackageJson = (subRoots = [], contextDir) => {
1559
1778
  const packageJsonName = 'package.json'; // 查找文件名
1560
1779
 
1561
1780
  const cwd = contextDir || dirPath;
1562
- const result = [path$5.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1781
+ const result = [path$4.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1563
1782
 
1564
1783
  subRoots.forEach(subRoot => {
1565
1784
  if (!subRoot.root) {
1566
- LOG.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
1785
+ log.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
1567
1786
  process.exit(1);
1568
1787
  }
1569
1788
 
1570
- const toppath = path$5.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1789
+ const toppath = path$4.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1571
1790
 
1572
1791
  const list = findFilesByFilter(toppath, packageJsonName);
1573
1792
  result.push(...list);
@@ -1583,7 +1802,7 @@ function cloudNpmInstall$1(contextDir) {
1583
1802
  }
1584
1803
 
1585
1804
  files.forEach(file => {
1586
- const dir = path$5.dirname(file);
1805
+ const dir = path$4.dirname(file);
1587
1806
  shell.cd(dir);
1588
1807
  shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
1589
1808
  silent: false
@@ -1594,66 +1813,74 @@ function cloudNpmInstall$1(contextDir) {
1594
1813
  });
1595
1814
  }
1596
1815
 
1597
- var npmUtils = {
1816
+ var npm = {
1598
1817
  cloudNpmInstall: cloudNpmInstall$1,
1599
1818
  mpNpmInstallAll: mpNpmInstallAll$1,
1600
1819
  findAllPackageJson
1601
1820
  };
1602
1821
 
1603
1822
  const {
1604
- createTask: createTask$2,
1605
- resolve: resolve$7
1823
+ createTask: createTask$1,
1824
+ resolve: resolve$8
1606
1825
  } = widgets;
1607
1826
  const {
1608
1827
  buildMpNpm
1609
- } = mpCiUtils;
1828
+ } = mpCi;
1610
1829
  const {
1611
1830
  CACHE_DIR
1612
- } = require$$3;
1831
+ } = require$$4;
1613
1832
  const {
1614
1833
  cloudNpmInstall,
1615
1834
  mpNpmInstallAll
1616
- } = npmUtils;
1835
+ } = npm;
1836
+ const {
1837
+ global: global$2
1838
+ } = global_1;
1617
1839
 
1618
1840
  async function install$2(tmsConfig, modules, isCloud = false) {
1619
1841
  // 小程序npm install
1620
- await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$7(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1842
+ await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
1843
+ const tmsPrivateCf = global$2.getData('tmsPrivateCf'); // 构建miniprogram_npm
1621
1844
 
1622
- await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1845
+ await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
1623
1846
  appId: tmsConfig.appId,
1624
- projectPath: resolve$7('./'),
1625
- privateKey: tmsConfig.privateKey
1847
+ projectPath: resolve$8('./'),
1848
+ privateKey: tmsPrivateCf.privateKey
1626
1849
  }); // 安装云函数的
1627
1850
 
1628
- isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$7(tmsConfig.cloudDir));
1851
+ isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$8(tmsConfig.cloudDir));
1629
1852
  }
1630
1853
 
1631
1854
  var install_1 = install$2;
1632
1855
 
1633
- const shelljs$3 = require$$4__default;
1634
- const fs$6 = require$$0__default$1;
1856
+ const shelljs$3 = require$$0__default$3;
1857
+ const fs$5 = require$$0__default$2;
1635
1858
  const io = io$2;
1636
1859
  const {
1637
- resolve: resolve$6,
1638
- createTask: createTask$1
1860
+ resolve: resolve$7,
1861
+ createTask
1639
1862
  } = widgets;
1640
1863
  const {
1641
1864
  buildOutputAppJson
1642
1865
  } = buildAppJson;
1643
1866
  const {
1644
- MODULE_CODE_DIR,
1867
+ symLink
1868
+ } = symbolicLink;
1869
+ const {
1870
+ MODULE_CODE_DIR: MODULE_CODE_DIR$1,
1645
1871
  DEFAULT_COPY_CONFIG
1646
- } = require$$3;
1872
+ } = require$$4;
1647
1873
  const {
1648
1874
  cloneModules
1649
1875
  } = cloneModules_1;
1650
1876
  const {
1651
1877
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2,
1652
1878
  subModulesMergeDepModules: subModulesMergeDepModules$1
1653
- } = tkitUtils;
1879
+ } = tmsMpconfig;
1654
1880
  const {
1655
- fail: fail$4
1656
- } = log$2;
1881
+ fail: fail$3,
1882
+ info: info$3
1883
+ } = log$1;
1657
1884
  const install$1 = install_1;
1658
1885
  /**
1659
1886
  * 拷贝相关配置文件到编译输出目录
@@ -1664,53 +1891,55 @@ const install$1 = install_1;
1664
1891
  */
1665
1892
 
1666
1893
  const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1667
- const outputDir = resolve$6(tmsConfig.outputDir);
1894
+ const outputDir = resolve$7(tmsConfig.outputDir);
1668
1895
  io.ensureDirExist(outputDir);
1669
1896
  defaultFiles.forEach(item => {
1670
- if (fs$6.existsSync(resolve$6(item))) {
1671
- shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
1897
+ if (fs$5.existsSync(resolve$7(item))) {
1898
+ shelljs$3.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
1672
1899
  }
1673
1900
  }); // 拷贝模块的package.json到编译输出目录
1674
1901
 
1675
1902
  targetModules.forEach(item => {
1676
- const outputModuleDir = resolve$6(`${tmsConfig.outputDir}/${item.root}`);
1903
+ const outputModuleDir = resolve$7(`${tmsConfig.outputDir}/${item.root}`);
1677
1904
 
1678
- if (!fs$6.existsSync(resolve$6(item.path))) {
1679
- fail$4(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1905
+ if (!fs$5.existsSync(resolve$7(item.path))) {
1906
+ fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1680
1907
  process.exit(1);
1681
1908
  }
1682
1909
 
1683
1910
  io.ensureDirExist(outputModuleDir);
1684
- const modulePackagePath = resolve$6(item.path, 'package.json');
1685
- if (fs$6.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
1911
+ const modulePackagePath = resolve$7(item.path, 'package.json');
1912
+ if (fs$5.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
1686
1913
  });
1687
1914
  };
1688
1915
 
1689
- async function task(tmsConfig, targetModules, isDev) {
1916
+ async function task(tmsConfig, targetModules) {
1690
1917
  // 下载和移动代码
1691
- await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules, isDev); // tms.config.js的modules 合并 module.config.json的配置项
1918
+ await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$7('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1692
1919
 
1693
1920
  let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
1694
1921
 
1695
1922
  newModules = subModulesMergeDepModules$1(tmsConfig, newModules); // 拷贝相关配置文件到输出目录
1696
1923
 
1697
- await createTask$1(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
1924
+ await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
1698
1925
 
1699
1926
  await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
1700
1927
 
1701
- await createTask$1(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules, isDev);
1928
+ await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
1929
+ await createTask(symLink, '开始创建软链接', '创建软链接完成')(tmsConfig);
1702
1930
  return newModules;
1703
1931
  }
1704
1932
 
1705
- async function init$5(tmsConfig, targetModules, isDev) {
1933
+ async function init$5(tmsConfig, targetModules) {
1706
1934
  try {
1707
- const newModules = await task(tmsConfig, targetModules, isDev);
1935
+ const newModules = await task(tmsConfig, targetModules);
1708
1936
  return {
1709
1937
  targetModules: newModules
1710
1938
  };
1711
1939
  } catch (error) {
1712
1940
  const errMsg = typeof error === 'object' ? error.message : error;
1713
- fail$4(`init流程出现错误${errMsg}`);
1941
+ fail$3(`init流程出现错误${errMsg}`);
1942
+ info$3('详细的错误信息', error);
1714
1943
  process.exit(1);
1715
1944
  }
1716
1945
  }
@@ -1719,37 +1948,6 @@ var init_1 = init$5;
1719
1948
 
1720
1949
  var dev$3 = {exports: {}};
1721
1950
 
1722
- const through$3 = require$$0__default$7;
1723
-
1724
- function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
1725
- const stream = through$3.obj(function (file, enc, cb) {
1726
- if (file.isBuffer()) {
1727
- let contents = String(file.contents);
1728
- let resReg; // eslint-disable-next-line
1729
-
1730
- while ((resReg = reg.exec(contents)) !== null) {
1731
- const [reg1, reg2, reg3] = resReg;
1732
-
1733
- if (reg1 && reg2 && reg3) {
1734
- const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
1735
- contents = contents.replace(reg1, value);
1736
- } else if (reg1 && !reg2 && !reg3) {
1737
- contents = contents.replace(reg1, JSON.stringify(envData));
1738
- }
1739
- } // eslint-disable-next-line
1740
-
1741
-
1742
- file.contents = Buffer.from(contents);
1743
- }
1744
-
1745
- this.push(file);
1746
- cb();
1747
- });
1748
- return stream;
1749
- }
1750
-
1751
- var replaceEnv_1 = replaceEnv$1;
1752
-
1753
1951
  /* eslint-disable no-param-reassign */
1754
1952
  const strip = require$$0__default$8; // 匹配规则
1755
1953
 
@@ -1786,16 +1984,16 @@ var findCssImport = {
1786
1984
 
1787
1985
  /* eslint-disable no-param-reassign */
1788
1986
  const {
1789
- fail: fail$3
1790
- } = log$2;
1987
+ fail: fail$2
1988
+ } = log$1;
1791
1989
 
1792
1990
  function pluginError$3(error, isWatch) {
1793
1991
  const errMsg = error.message;
1794
1992
 
1795
1993
  if (isWatch) {
1796
- fail$3(errMsg);
1994
+ fail$2(errMsg);
1797
1995
  } else {
1798
- fail$3(errMsg);
1996
+ fail$2(errMsg);
1799
1997
  process.exit(1);
1800
1998
  }
1801
1999
  }
@@ -1805,9 +2003,9 @@ var pluginError_1 = {
1805
2003
  };
1806
2004
 
1807
2005
  /* eslint-disable no-param-reassign */
1808
- const through$2 = require$$0__default$7;
1809
- const precinct = require$$1__default$4;
1810
- const path$4 = require$$3__default;
2006
+ const through$2 = require$$0__default$9;
2007
+ const precinct = require$$1__default$5;
2008
+ const path$3 = require$$3__default;
1811
2009
  const {
1812
2010
  findCssImports
1813
2011
  } = findCssImport;
@@ -1817,9 +2015,9 @@ const {
1817
2015
  diffContentCopyFile: diffContentCopyFile$2
1818
2016
  } = io$2;
1819
2017
  const {
1820
- resolve: resolve$5
2018
+ resolve: resolve$6
1821
2019
  } = widgets;
1822
- const fs$5 = require$$0__default$1;
2020
+ const fs$4 = require$$0__default$2;
1823
2021
  const {
1824
2022
  pluginError: pluginError$2
1825
2023
  } = pluginError_1;
@@ -1832,16 +2030,16 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
1832
2030
  let contents = '';
1833
2031
 
1834
2032
  try {
1835
- contents = fs$5.readFileSync(anaFileOriginFile, 'utf8');
2033
+ contents = fs$4.readFileSync(anaFileOriginFile, 'utf8');
1836
2034
  } catch (e) {
1837
2035
  pluginError$2(e, isWatch);
1838
2036
  }
1839
2037
 
1840
- const deps = cssFilter.indexOf(path$4.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
2038
+ const deps = cssFilter.indexOf(path$3.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
1841
2039
  deps.forEach(depItem => {
1842
2040
  if (depItem.startsWith('.')) {
1843
2041
  // 被依赖文件的存在的绝对路径
1844
- const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2042
+ const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1845
2043
 
1846
2044
  const {
1847
2045
  ext: extAlias,
@@ -1849,12 +2047,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
1849
2047
  extPath
1850
2048
  } = ext$2(depOriginPath, extensions);
1851
2049
 
1852
- if (!fs$5.existsSync(depOriginFile)) {
2050
+ if (!fs$4.existsSync(depOriginFile)) {
1853
2051
  pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
1854
2052
  return;
1855
2053
  }
1856
2054
 
1857
- const depDestPath = resolve$5(path$4.dirname(anaFileDestFile), depItem);
2055
+ const depDestPath = resolve$6(path$3.dirname(anaFileDestFile), depItem);
1858
2056
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
1859
2057
 
1860
2058
  if (!resDep.has(depDestFile)) {
@@ -1878,19 +2076,19 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
1878
2076
  const stream = through$2.obj(function (file, enc, cb) {
1879
2077
  // 依赖分析的文件
1880
2078
  const anaFileOriginFile = file.history[0];
1881
- const anaFileRelativeModule = path$4.relative(resolve$5(module.from), anaFileOriginFile);
1882
- const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2079
+ const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
2080
+ const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
1883
2081
 
1884
2082
  if (file.isBuffer()) {
1885
2083
  let contents = String(file.contents);
1886
- const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
2084
+ const deps = cssFilter.indexOf(path$3.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
1887
2085
  const copyModules = new Map();
1888
2086
  Object.keys(tmsConfig.dependencies).forEach(includeName => {
1889
2087
  const includePath = tmsConfig.dependencies[includeName];
1890
2088
  deps.forEach(depItem => {
1891
2089
  if (depItem.indexOf(includeName) > -1) {
1892
2090
  // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
1893
- const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2091
+ const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1894
2092
 
1895
2093
  const {
1896
2094
  ext: extAlias,
@@ -1904,11 +2102,11 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
1904
2102
  } // eslint-disable-next-line
1905
2103
 
1906
2104
 
1907
- const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
2105
+ const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
1908
2106
  const regRes = depItem.match(reg) || [];
1909
2107
 
1910
2108
  if (regRes[2]) {
1911
- const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2109
+ const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
1912
2110
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
1913
2111
 
1914
2112
  if (!copyModules.has(depDestFile)) {
@@ -1916,7 +2114,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
1916
2114
  depOriginFile,
1917
2115
  depDestFile,
1918
2116
  beforeDepPath: depItem,
1919
- afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2117
+ afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
1920
2118
  });
1921
2119
  }
1922
2120
  }
@@ -1953,17 +2151,17 @@ var mpCommonDep_1 = {
1953
2151
  };
1954
2152
 
1955
2153
  /* eslint-disable no-param-reassign */
1956
- const through$1 = require$$0__default$7;
1957
- const path$3 = require$$3__default;
2154
+ const through$1 = require$$0__default$9;
2155
+ const path$2 = require$$3__default;
1958
2156
  const {
1959
2157
  ext: ext$1,
1960
2158
  fileInDir: fileInDir$1,
1961
2159
  diffContentCopyFile: diffContentCopyFile$1
1962
2160
  } = io$2;
1963
2161
  const {
1964
- resolve: resolve$4
2162
+ resolve: resolve$5
1965
2163
  } = widgets;
1966
- const fs$4 = require$$0__default$1;
2164
+ const fs$3 = require$$0__default$2;
1967
2165
  const {
1968
2166
  pluginError: pluginError$1
1969
2167
  } = pluginError_1;
@@ -1975,15 +2173,19 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
1975
2173
  const stream = through$1.obj(function (file, enc, cb) {
1976
2174
  // 当前分析的文件的路径
1977
2175
  const anaFileOriginFile = file.history[0];
1978
- const anaFileRelativeModule = path$3.relative(resolve$4(module.from), anaFileOriginFile);
1979
- const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2176
+ const anaFileRelativeModule = path$2.relative(resolve$5(module.from), anaFileOriginFile);
2177
+ const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
1980
2178
 
1981
2179
  if (file.isBuffer()) {
1982
- const copyModules = new Map();
1983
2180
  let contents = String(file.contents);
2181
+ const copyModules = new Map();
1984
2182
 
1985
2183
  try {
1986
- contents = JSON.parse(contents);
2184
+ try {
2185
+ contents = contents ? JSON.parse(contents) : {};
2186
+ } catch (e) {
2187
+ throw new Error(`解析${file.path}出现错误,请检查配置信息: ${e}`);
2188
+ }
1987
2189
 
1988
2190
  if (contents.usingComponents) {
1989
2191
  Object.keys(tmsConfig.dependencies).forEach(includeName => {
@@ -1992,7 +2194,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
1992
2194
  const componentPath = contents.usingComponents[componentKey];
1993
2195
 
1994
2196
  if (componentPath.indexOf(includeName) > -1) {
1995
- const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
2197
+ const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
1996
2198
 
1997
2199
  const {
1998
2200
  ext: extAlias,
@@ -2007,11 +2209,11 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2007
2209
  } // eslint-disable-next-line
2008
2210
 
2009
2211
 
2010
- const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
2212
+ const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
2011
2213
  const regRes = componentPath.match(reg) || [];
2012
2214
 
2013
2215
  if (regRes[2]) {
2014
- const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2216
+ const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2015
2217
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2016
2218
 
2017
2219
  if (!copyModules.has(depDestFile)) {
@@ -2020,7 +2222,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2020
2222
  depOriginExt: extAlias,
2021
2223
  depDestFile,
2022
2224
  beforeDepPath: componentPath,
2023
- afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2225
+ afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2024
2226
  });
2025
2227
  }
2026
2228
  }
@@ -2045,7 +2247,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2045
2247
  const originFile = depOriginFile.replace(depOriginExt, extKey);
2046
2248
  const destFile = depDestFile.replace(depOriginExt, extKey);
2047
2249
 
2048
- if (fs$4.existsSync(originFile)) {
2250
+ if (fs$3.existsSync(originFile)) {
2049
2251
  diffContentCopyFile$1(originFile, destFile);
2050
2252
  const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
2051
2253
 
@@ -2077,17 +2279,17 @@ var mpJsonDep_1 = {
2077
2279
  };
2078
2280
 
2079
2281
  /* eslint-disable no-param-reassign */
2080
- const through = require$$0__default$7;
2081
- const htmlparser2 = require$$1__default$5;
2082
- const fs$3 = require$$0__default$1;
2083
- const path$2 = require$$3__default;
2282
+ const through = require$$0__default$9;
2283
+ const htmlparser2 = require$$1__default$6;
2284
+ const fs$2 = require$$0__default$2;
2285
+ const path$1 = require$$3__default;
2084
2286
  const {
2085
2287
  diffContentCopyFile,
2086
2288
  ext,
2087
2289
  fileInDir
2088
2290
  } = io$2;
2089
2291
  const {
2090
- resolve: resolve$3
2292
+ resolve: resolve$4
2091
2293
  } = widgets;
2092
2294
  const {
2093
2295
  dfsFindCommonDep
@@ -2126,7 +2328,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2126
2328
  let contents = '';
2127
2329
 
2128
2330
  try {
2129
- contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
2331
+ contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
2130
2332
  } catch (e) {
2131
2333
  pluginError(e, isWatch);
2132
2334
  }
@@ -2136,7 +2338,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2136
2338
  var _attributes$src;
2137
2339
 
2138
2340
  if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
2139
- const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2341
+ const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2140
2342
 
2141
2343
  const {
2142
2344
  ext,
@@ -2144,12 +2346,12 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2144
2346
  extPath
2145
2347
  } = extFile(name, depOriginPath);
2146
2348
 
2147
- if (!fs$3.existsSync(depOriginFile)) {
2349
+ if (!fs$2.existsSync(depOriginFile)) {
2148
2350
  pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
2149
2351
  return;
2150
2352
  }
2151
2353
 
2152
- const depDestPath = path$2.join(path$2.dirname(anaFileDestFile), attributes.src);
2354
+ const depDestPath = path$1.join(path$1.dirname(anaFileDestFile), attributes.src);
2153
2355
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
2154
2356
 
2155
2357
  if (['import', 'include'].indexOf(name) > -1) {
@@ -2201,8 +2403,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2201
2403
  const stream = through.obj(function (file, enc, cb) {
2202
2404
  // 依赖分析的文件
2203
2405
  const anaFileOriginFile = file.history[0];
2204
- const anaFileRelativeModule = path$2.relative(resolve$3(module.from), anaFileOriginFile);
2205
- const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2406
+ const anaFileRelativeModule = path$1.relative(resolve$4(module.from), anaFileOriginFile);
2407
+ const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2206
2408
 
2207
2409
  if (file.isBuffer()) {
2208
2410
  let contents = String(file.contents);
@@ -2212,7 +2414,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2212
2414
  const nameFilter = ['import', 'include', 'wxs'];
2213
2415
 
2214
2416
  if (nameFilter.indexOf(name) > -1 && attributes.src) {
2215
- const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2417
+ const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2216
2418
 
2217
2419
  const {
2218
2420
  ext,
@@ -2229,11 +2431,11 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2229
2431
  } // eslint-disable-next-line
2230
2432
 
2231
2433
 
2232
- const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
2434
+ const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
2233
2435
  const regRes = attributes.src.match(reg) || [];
2234
2436
 
2235
2437
  if (regRes[2]) {
2236
- const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2438
+ const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2237
2439
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
2238
2440
 
2239
2441
  if (!copyModules.has(depDestFile)) {
@@ -2241,7 +2443,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2241
2443
  depOriginFile,
2242
2444
  depDestFile,
2243
2445
  beforeDepPath: attributes.src,
2244
- afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2446
+ afterDepPath: path$1.relative(path$1.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2245
2447
  });
2246
2448
  }
2247
2449
  }
@@ -2260,7 +2462,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2260
2462
  beforeDepPath,
2261
2463
  afterDepPath
2262
2464
  }) => {
2263
- if (fs$3.existsSync(depOriginFile)) {
2465
+ if (fs$2.existsSync(depOriginFile)) {
2264
2466
  diffContentCopyFile(depOriginFile, depDestFile);
2265
2467
  const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
2266
2468
  contents = contents.replace(reg, `"${afterDepPath}"`);
@@ -2296,84 +2498,16 @@ var mpWxmlDep_1 = {
2296
2498
  dfsFindWxmlDep
2297
2499
  };
2298
2500
 
2299
- /* eslint-disable no-param-reassign */
2300
- const postcss$1 = require$$0__default$9;
2301
- const fs$2 = require$$0__default$1;
2302
- const path$1 = require$$3__default;
2303
- const {
2304
- fail: fail$2
2305
- } = log$2;
2306
- var postcssFontBase64 = postcss$1.plugin('postcss-font-base64', options => {
2307
- options = { ...options,
2308
- ...{
2309
- match: {
2310
- Scrabble: ['fakefont']
2311
- },
2312
- format: ['eot', 'woff', 'woff2', 'ttf']
2313
- }
2314
- };
2315
- return function (css, result) {
2316
- css.walkAtRules('font-face', fontFace => {
2317
- const fileTypeRegex = getRegexStringForFileTypes(options.format);
2318
- fontFace.replaceValues(new RegExp(`url\\(["']?.+\\.${fileTypeRegex}["']?\\)`), attr => {
2319
- const fontRePath = attr.replace(/(url|'|"|\(|\)|\?#iefix)/g, '');
2320
- const fontAbPath = path$1.join(path$1.dirname(result.opts.from), fontRePath);
2321
- const res64 = base64Encode(fontAbPath);
2322
- const newUrlStr = 'url(data:'.concat(getMimeType(attr)).concat(';charset=utf-8;base64,').concat(res64).concat(')');
2323
- return res64 ? newUrlStr : attr;
2324
- });
2325
- });
2326
-
2327
- function getRegexStringForFileTypes(fileTypes) {
2328
- const regex = fileTypes.map(fileType => fileType === 'eot' ? fileType.concat('(\\?#iefix)?') : fileType).join('|');
2329
- return regex ? `(${regex})` : '';
2330
- } // helper functions
2331
-
2332
-
2333
- function getMimeType(attribute) {
2334
- const formats = {
2335
- '.woff': 'application/font-woff',
2336
- '.woff2': 'font/woff2',
2337
- '.ttf': 'application/font-sfnt',
2338
- '.eot': 'application/vnd.ms-fontobject',
2339
- '.otf': 'application/font-sfnt'
2340
- };
2341
- let match = '';
2342
- const extension = attribute.match(/\.[a-z]{3,4}/)[0];
2343
-
2344
- if (extension in formats) {
2345
- match = formats[extension];
2346
- }
2347
- return match;
2348
- }
2349
-
2350
- function base64Encode(file) {
2351
- if (fs$2.existsSync(file)) {
2352
- return readAndEncodeFile(file);
2353
- }
2354
-
2355
- fail$2(`${file} does not exist.`);
2356
- return '';
2357
- }
2358
-
2359
- function readAndEncodeFile(file) {
2360
- const bitmap = fs$2.readFileSync(file);
2361
- return Buffer.from(bitmap).toString('base64');
2362
- }
2363
- };
2364
- });
2365
-
2366
2501
  const {
2367
2502
  src: src$1,
2368
2503
  dest,
2369
2504
  lastRun
2370
2505
  } = require$$0__default$a;
2371
- const px2rpx = require$$1__default$6;
2372
- const postcss = require$$2__default$2;
2373
- const watch = require$$3__default$1; // const cache = require('gulp-cache');
2506
+ const px2rpx = require$$1__default$7;
2507
+ const watch = require$$2__default$1; // const cache = require('gulp-cache');
2374
2508
  // const image = require('gulp-image');
2509
+ // const replaceEnv = require('./plugins/replaceEnv');
2375
2510
 
2376
- const replaceEnv = replaceEnv_1;
2377
2511
  const {
2378
2512
  mpCommonDep
2379
2513
  } = mpCommonDep_1;
@@ -2382,11 +2516,12 @@ const {
2382
2516
  } = mpJsonDep_1;
2383
2517
  const {
2384
2518
  mpWxmlDep
2385
- } = mpWxmlDep_1;
2386
- const base64 = postcssFontBase64;
2519
+ } = mpWxmlDep_1; // const postcss = require('gulp-postcss');
2520
+ // const base64 = require('./plugins/postcss-font-base64');
2521
+
2387
2522
  const {
2388
2523
  fail: fail$1
2389
- } = log$2;
2524
+ } = log$1;
2390
2525
 
2391
2526
  const since = task => file => lastRun(task) > file.stat.ctime ? lastRun(task) : 0;
2392
2527
 
@@ -2415,15 +2550,20 @@ var compile = function (tmsConfig, {
2415
2550
 
2416
2551
  switch (globKey) {
2417
2552
  case 'js':
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 => {
2553
+ srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
2554
+ .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch)).pipe(dest(destPath)).on('error', err => {
2419
2555
  fail$1(`js编译报错${err}`);
2420
2556
  });
2421
2557
  break;
2422
2558
 
2423
2559
  case 'wxss':
2424
- srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).pipe(postcss([base64()])).on('error', err => {
2425
- fail$1(`postcss编译报错${err}`);
2426
- }).pipe(px2rpx({
2560
+ srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).on('error', err => {
2561
+ fail$1(`mpCommonDep编译报错${err}`);
2562
+ }) // .pipe(postcss([base64()]))
2563
+ // .on('error', (err) => {
2564
+ // fail(`postcss编译报错${err}`);
2565
+ // })
2566
+ .pipe(px2rpx({
2427
2567
  designWidth: 375,
2428
2568
  // 设计稿宽度,默认为750
2429
2569
  precision: 2 // 小数最大精度,默认为6
@@ -2433,7 +2573,7 @@ var compile = function (tmsConfig, {
2433
2573
 
2434
2574
  case 'json':
2435
2575
  srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
2436
- fail$1(`json编译报错${err}`);
2576
+ fail$1(`mpJsonDep编译报错${err}`);
2437
2577
  }).pipe(dest(destPath));
2438
2578
  break;
2439
2579
 
@@ -2457,7 +2597,9 @@ var compile = function (tmsConfig, {
2457
2597
  };
2458
2598
 
2459
2599
  (function (module) {
2460
- const watch = require$$3__default$1;
2600
+ const path = require$$3__default;
2601
+ const fs = require$$0__default$2;
2602
+ const watch = require$$2__default$1;
2461
2603
  const {
2462
2604
  resolve
2463
2605
  } = widgets;
@@ -2466,7 +2608,7 @@ var compile = function (tmsConfig, {
2466
2608
  } = buildAppJson;
2467
2609
  const {
2468
2610
  DEFAULT_COPY_CONFIG
2469
- } = require$$3;
2611
+ } = require$$4;
2470
2612
  const compile$1 = compile;
2471
2613
 
2472
2614
  function excludeGlob(glob) {
@@ -2490,6 +2632,13 @@ var compile = function (tmsConfig, {
2490
2632
  return Array.from(otherArr);
2491
2633
  }
2492
2634
 
2635
+ function adaptPath(pathDir) {
2636
+ let newPath = pathDir;
2637
+ newPath = newPath.startsWith('/') ? newPath : resolve(newPath);
2638
+ newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
2639
+ return newPath;
2640
+ }
2641
+
2493
2642
  module.exports = async (tmsConfig, newModules, isWatch = true) => {
2494
2643
  // 监听app.json
2495
2644
  if (isWatch) {
@@ -2506,9 +2655,9 @@ var compile = function (tmsConfig, {
2506
2655
 
2507
2656
  compile$1(tmsConfig, {
2508
2657
  glob: {
2509
- json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
2510
- wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
2511
- js: ['app.js', 'app.ts'].map(item => resolve(item))
2658
+ json: DEFAULT_COPY_CONFIG.map(item => resolve(item)) // wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
2659
+ // js: ['app.js', 'app.ts'].map(item => resolve(item)),
2660
+
2512
2661
  },
2513
2662
  module: {
2514
2663
  from: '',
@@ -2539,16 +2688,17 @@ var compile = function (tmsConfig, {
2539
2688
  }
2540
2689
 
2541
2690
  const excludes = module.exclude.map(key => `!${resolve(key)}`);
2691
+ const modulePath = adaptPath(module.path);
2542
2692
  const glob = {
2543
- js: [`${resolve(module.path)}/**/*.{js,ts,wxs}`, ...excludes],
2544
- json: [`${resolve(module.path)}/**/*.json`, ...excludes],
2545
- wxss: [`${resolve(module.path)}/**/*.{less,wxss}`, ...excludes],
2546
- wxml: [`${resolve(module.path)}/**/*.wxml`, ...excludes],
2547
- image: [`${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
2693
+ js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
2694
+ json: [`${modulePath}/**/*.json`, ...excludes],
2695
+ wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
2696
+ wxml: [`${modulePath}/**/*.wxml`, ...excludes],
2697
+ image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
2548
2698
  };
2549
2699
  compile$1(tmsConfig, {
2550
2700
  glob: { ...glob,
2551
- other: [`${resolve(module.path)}/**/*`, ...excludeGlob(glob)]
2701
+ other: [`${modulePath}/**/*`, ...excludeGlob(glob)]
2552
2702
  },
2553
2703
  destPath: resolve(tmsConfig.outputDir, module.root),
2554
2704
  module: {
@@ -2565,14 +2715,32 @@ var compile = function (tmsConfig, {
2565
2715
 
2566
2716
  if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
2567
2717
  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);
2718
+ item.from = adaptPath(item.from);
2719
+ item.to = adaptPath(item.to);
2720
+ let glob = {};
2721
+ const ext = path.extname(item.from).slice(1);
2722
+
2723
+ if (ext) {
2724
+ glob[ext] = [item.from];
2725
+ } else {
2726
+ glob = {
2727
+ js: [`${item.from}/**/*.{js,ts,wxs}`],
2728
+ json: [`${item.from}/**/*.json`],
2729
+ wxss: [`${item.from}/**/*.{less,wxss}`],
2730
+ wxml: [`${item.from}/**/*.wxml`],
2731
+ image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
2732
+ };
2733
+ glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
2734
+ }
2735
+
2736
+ const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
2570
2737
  compile$1(tmsConfig, {
2571
- glob: {
2572
- other: [from]
2738
+ glob,
2739
+ destPath: item.to,
2740
+ module: {
2741
+ from,
2742
+ to: item.to
2573
2743
  },
2574
- destPath: to,
2575
- module: item,
2576
2744
  srcOption: {
2577
2745
  allowEmpty: true
2578
2746
  },
@@ -2583,13 +2751,13 @@ var compile = function (tmsConfig, {
2583
2751
  };
2584
2752
  })(dev$3);
2585
2753
 
2586
- const fs$1 = require$$0__default$1;
2587
- const semver$1 = require$$1__default$7;
2754
+ const fs$1 = require$$0__default$2;
2755
+ const semver$1 = require$$1__default$8;
2588
2756
  const {
2589
- resolve: resolve$2
2757
+ resolve: resolve$3
2590
2758
  } = widgets;
2591
2759
  const path = require$$3__default;
2592
- const shelljs$2 = require$$4__default;
2760
+ const shelljs$2 = require$$0__default$3;
2593
2761
  const {
2594
2762
  handleError
2595
2763
  } = handleError_1;
@@ -2607,14 +2775,14 @@ const getLatestVersion = npmName => {
2607
2775
  */
2608
2776
 
2609
2777
 
2610
- const checkDependencies$1 = (modules, cwd, outputDir, isDev) => {
2778
+ const checkDependencies$1 = (modules, cwd, outputDir) => {
2611
2779
  // 步骤1. 收集package.json
2612
2780
  const packageJsonName = 'package.json'; // 查找文件名
2613
2781
  // 1.1根目录的package.json
2614
2782
 
2615
2783
  const packageArr = [{
2616
2784
  srcPackageDir: path.join(cwd, packageJsonName),
2617
- destNpmDir: resolve$2(outputDir, 'node_modules')
2785
+ destNpmDir: resolve$3(outputDir, 'node_modules')
2618
2786
  }]; // 1.2模块的package.json
2619
2787
 
2620
2788
  modules.forEach(item => {
@@ -2623,7 +2791,7 @@ const checkDependencies$1 = (modules, cwd, outputDir, isDev) => {
2623
2791
  if (fs$1.existsSync(srcPackageDir)) {
2624
2792
  packageArr.push({
2625
2793
  srcPackageDir,
2626
- destNpmDir: resolve$2(outputDir, item.root, 'node_modules')
2794
+ destNpmDir: resolve$3(outputDir, item.root, 'node_modules')
2627
2795
  });
2628
2796
  }
2629
2797
  }); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
@@ -2636,7 +2804,7 @@ const checkDependencies$1 = (modules, cwd, outputDir, isDev) => {
2636
2804
  const json = JSON.parse(packageJson);
2637
2805
  dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
2638
2806
  } catch (e) {
2639
- handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项`, isDev);
2807
+ handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2640
2808
  }
2641
2809
 
2642
2810
  const dependenciesKeys = Object.keys(dependencies);
@@ -2675,27 +2843,53 @@ var checkDependencies_1 = {
2675
2843
  checkDependencies: checkDependencies$1
2676
2844
  };
2677
2845
 
2678
- const gulpDev = dev$3.exports;
2679
- const fs = require$$0__default$1;
2846
+ const fs = require$$0__default$2;
2680
2847
  const {
2681
- resolve: resolve$1
2848
+ resolve: resolve$2
2682
2849
  } = widgets;
2683
- const init$4 = init_1;
2684
2850
  const {
2685
- MODULE_CONFIG_FILENAME
2686
- } = require$$3;
2851
+ MODULE_CONFIG_FILENAME,
2852
+ MODULE_CODE_DIR
2853
+ } = require$$4;
2687
2854
  const {
2688
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
2689
- } = tkitUtils;
2855
+ checkRemoteModGitUrlBranch
2856
+ } = cloneModules_1;
2690
2857
  const {
2691
2858
  checkDependencies
2692
2859
  } = checkDependencies_1;
2693
2860
  const {
2694
2861
  fail
2695
- } = log$2;
2696
- const shelljs$1 = require$$4__default; // const io = require('../../../utils/io');
2862
+ } = log$1;
2863
+
2864
+ function checkModule(targetModules, contextDir) {
2865
+ // 判断\源码\dist\是否存在用户指定的模块
2866
+ for (const item of targetModules) {
2867
+ // 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
2868
+ if (!item.root) {
2869
+ return true;
2870
+ } // 判断dist目录是否有该模块
2871
+
2872
+
2873
+ if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
2874
+ return true;
2875
+ } // 判断第三方远程模块git地址与branch是否有更新
2876
+
2877
+
2878
+ if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
2879
+ return true;
2880
+ } // 判断源码目录是否有该模块
2881
+
2882
+
2883
+ if (item.path && !fs.existsSync(resolve$2(item.path))) {
2884
+ fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2885
+ process.exit(1);
2886
+ }
2887
+ }
2888
+
2889
+ return false;
2890
+ }
2697
2891
 
2698
- function isInit(tmsConfig, targetModules, contextDir, isDev) {
2892
+ function isInit$1(tmsConfig, targetModules, contextDir) {
2699
2893
  // 判断是否存在dist目录
2700
2894
  if (!fs.existsSync(contextDir)) {
2701
2895
  return true;
@@ -2714,31 +2908,43 @@ function isInit(tmsConfig, targetModules, contextDir, isDev) {
2714
2908
 
2715
2909
  if (!fs.existsSync(`${contextDir}/app.json`)) {
2716
2910
  return true;
2717
- } // 判断\源码\dist\是否存在用户指定的模块
2718
-
2719
-
2720
- for (const item of targetModules) {
2721
- // 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
2722
- if (!item.root) {
2723
- return true;
2724
- } // 判断dist目录是否有该模块
2911
+ } // 判断模块信息
2725
2912
 
2726
2913
 
2727
- if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
2728
- return true;
2729
- } // 判断源码目录是否有该模块
2914
+ if (checkModule(targetModules, contextDir)) {
2915
+ return true;
2916
+ } // 判断package.json的版本是否有新的版本
2730
2917
 
2731
2918
 
2732
- if (item.path && !fs.existsSync(resolve$1(item.path))) {
2733
- fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2734
- process.exit(1);
2735
- }
2736
- } // 判断package.json的版本是否有新的版本
2919
+ if (checkDependencies(targetModules, resolve$2('./'), tmsConfig.outputDir)) {
2920
+ return true;
2921
+ }
2737
2922
 
2923
+ return false;
2924
+ }
2738
2925
 
2739
- return checkDependencies(targetModules, resolve$1('./'), tmsConfig.outputDir, isDev);
2740
- } // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
2926
+ var isInIt = {
2927
+ isInit: isInit$1
2928
+ };
2741
2929
 
2930
+ const shelljs$1 = require$$0__default$3;
2931
+ const compileDev = dev$3.exports;
2932
+ const {
2933
+ resolve: resolve$1
2934
+ } = widgets;
2935
+ const init$4 = init_1;
2936
+ const {
2937
+ isInit
2938
+ } = isInIt;
2939
+ const {
2940
+ tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
2941
+ } = tmsMpconfig;
2942
+ const {
2943
+ info: info$2
2944
+ } = log$1;
2945
+ const {
2946
+ global: global$1
2947
+ } = global_1; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
2742
2948
 
2743
2949
  function delOtherModule(tmsConfig, targetModules) {
2744
2950
  const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
@@ -2756,17 +2962,17 @@ function delOtherModule(tmsConfig, targetModules) {
2756
2962
 
2757
2963
  async function dev$2(tmsConfig, targetModules, env) {
2758
2964
  let newModules = targetModules;
2759
- const isDev = true; // 判断是否进行init命令
2965
+ const isLatest = global$1.getData('cmd').latest; // 判断是否进行init命令
2760
2966
 
2761
- if (isInit(tmsConfig, targetModules, resolve$1('dist'), isDev)) {
2967
+ if (isLatest || isInit(tmsConfig, targetModules, resolve$1('dist'))) {
2762
2968
  // init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
2763
- const initData = await init$4(tmsConfig, newModules, isDev);
2969
+ const initData = await init$4(tmsConfig, newModules);
2764
2970
  newModules = initData.targetModules;
2765
2971
  }
2766
2972
 
2767
- console.log('当前dev启动的有效模块', newModules.map(item => item.name).sort());
2973
+ info$2('当前dev启动的有效模块', newModules.map(item => item.name).sort());
2768
2974
  delOtherModule(tmsConfig, newModules);
2769
- gulpDev(tmsConfig, newModules, env);
2975
+ compileDev(tmsConfig, newModules, env);
2770
2976
  }
2771
2977
 
2772
2978
  var dev_1 = dev$2;
@@ -2777,21 +2983,20 @@ var build$2 = async (tmsConfig, newModules) => {
2777
2983
  dev$1(tmsConfig, newModules, false);
2778
2984
  };
2779
2985
 
2780
- const shelljs = require$$4__default;
2986
+ const shelljs = require$$0__default$3;
2781
2987
  const {
2782
2988
  resolve
2783
2989
  } = widgets;
2784
2990
  const init$3 = init_1;
2785
- const gulpBuild = build$2;
2991
+ const compileBuild = build$2;
2786
2992
 
2787
2993
  async function build$1(tmsConfig, targetModules, env) {
2788
2994
  // 开始构建前,清理输出目录
2789
2995
  await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
2790
- const isDev = false;
2791
2996
  const {
2792
2997
  targetModules: newModules
2793
- } = await init$3(tmsConfig, targetModules, isDev);
2794
- gulpBuild(tmsConfig, newModules, env);
2998
+ } = await init$3(tmsConfig, targetModules);
2999
+ compileBuild(tmsConfig, newModules, env);
2795
3000
  }
2796
3001
 
2797
3002
  var build_1 = build$1;
@@ -2801,63 +3006,77 @@ const dev = dev_1;
2801
3006
  const build = build_1;
2802
3007
  const install = install_1;
2803
3008
  const {
2804
- createTask
2805
- } = widgets;
2806
- const {
2807
- MODE
2808
- } = require$$3;
3009
+ global
3010
+ } = global_1;
2809
3011
  const {
2810
3012
  readTmsConfig,
2811
3013
  readTmsPrivateCf,
2812
- checkModules
2813
- } = tkitUtils;
2814
- const {
3014
+ checkModules,
2815
3015
  tmsModulesMergeLocalModuleCfg,
2816
3016
  subModulesMergeDepModules
2817
- } = tkitUtils;
3017
+ } = tmsMpconfig;
2818
3018
 
2819
- const handleModulesArg = (cmd, tmsPrivateCg) => {
3019
+ const handleModuleArg = cmd => {
2820
3020
  // 单模块或多模块开发-用户通过脚手架参数指定的模块
2821
- if (cmd.module) {
2822
- const {
2823
- argv
2824
- } = process;
2825
- const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
2826
- return [cmd.module, ...reset];
3021
+ if (typeof cmd.module === 'string') {
3022
+ return cmd.module.split(',');
3023
+ }
3024
+
3025
+ return [];
3026
+ };
3027
+ /**
3028
+ * 获取用户指定要跑的模块
3029
+ * @param {Array} moduleArg 参数指定的模块
3030
+ * @param {Object} modulePrivateCfg 私有配置里的模块
3031
+ * @param {Array} moduleAll 当前小程序全部模块
3032
+ */
3033
+
3034
+
3035
+ const getSpecificModules = (moduleArg, modulePrivateCfg, moduleAll) => {
3036
+ if (moduleArg.length > 0) {
3037
+ return moduleArg;
2827
3038
  } // 单模块或多模块开发-用户在tms.private.js指定的模块
2828
3039
 
2829
3040
 
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;
2832
- } // 全量模块
3041
+ if (modulePrivateCfg) {
3042
+ var _modulePrivateCfg$inc, _modulePrivateCfg$exc;
3043
+
3044
+ if (((_modulePrivateCfg$inc = modulePrivateCfg.include) === null || _modulePrivateCfg$inc === void 0 ? void 0 : _modulePrivateCfg$inc.length) > 0) {
3045
+ return modulePrivateCfg.include;
3046
+ }
3047
+
3048
+ if (((_modulePrivateCfg$exc = modulePrivateCfg.exclude) === null || _modulePrivateCfg$exc === void 0 ? void 0 : _modulePrivateCfg$exc.length) > 0) {
3049
+ return moduleAll.filter(module => !modulePrivateCfg.exclude.includes(module.name)).map(item => item.name);
3050
+ }
2833
3051
 
3052
+ if (modulePrivateCfg.blockRemote === true) {
3053
+ return moduleAll.filter(module => module.repoInfo === undefined).map(item => item.name);
3054
+ }
3055
+ }
2834
3056
 
2835
- return MODE.all;
3057
+ return moduleAll.map(item => item.name);
2836
3058
  };
2837
3059
 
2838
3060
  async function run(commandName, cmd) {
2839
3061
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
2840
- const tmsPrivateCg = readTmsPrivateCf(); // 处理module参数
2841
-
2842
- const moduleArg = handleModulesArg(cmd, tmsPrivateCg);
3062
+ const tmsPrivateCf = readTmsPrivateCf();
2843
3063
  const {
2844
- env = tmsPrivateCg === null || tmsPrivateCg === void 0 ? void 0 : tmsPrivateCg.env
3064
+ env = tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : tmsPrivateCf.env
2845
3065
  } = cmd;
2846
- const tmsConfig = await createTask(readTmsConfig, '开始读取脚手架的配置项', '读取脚手架的配置项完成')(env);
2847
- let modules;
2848
-
2849
- if (moduleArg === MODE.all) {
2850
- // 全量模块
2851
- modules = tmsConfig.modules;
2852
- } else {
2853
- // 检查用户输入modules的有效性
2854
- modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...moduleArg])]);
2855
- } // tms.config.js的modules 合并 module.config.json的配置项
3066
+ const tmsConfig = readTmsConfig(env); // 处理module参数
2856
3067
 
3068
+ const specificModules = getSpecificModules(handleModuleArg(cmd), tmsPrivateCf.modules, tmsConfig.modules);
3069
+ const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])]); // tms.config.js的modules 合并 module.config.json的配置项
2857
3070
 
2858
3071
  let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
2859
3072
 
2860
- newModules = subModulesMergeDepModules(tmsConfig, newModules);
3073
+ newModules = subModulesMergeDepModules(tmsConfig, newModules); // 缓存数据
3074
+
3075
+ global.setData({
3076
+ env,
3077
+ cmd,
3078
+ tmsPrivateCf
3079
+ });
2861
3080
 
2862
3081
  switch (commandName) {
2863
3082
  case 'init':
@@ -2865,6 +3084,7 @@ async function run(commandName, cmd) {
2865
3084
  return;
2866
3085
 
2867
3086
  case 'dev':
3087
+ global.setData('isDev', true);
2868
3088
  dev(tmsConfig, newModules, env);
2869
3089
  return;
2870
3090
 
@@ -2873,6 +3093,7 @@ async function run(commandName, cmd) {
2873
3093
  return;
2874
3094
 
2875
3095
  case 'build':
3096
+ global.setData('isDev', false);
2876
3097
  build(tmsConfig, newModules, env);
2877
3098
  return;
2878
3099
 
@@ -2903,7 +3124,7 @@ var entry = [{
2903
3124
  }, {
2904
3125
  command: 'dev',
2905
3126
  description: 'dev 打包编译',
2906
- options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
3127
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-latest, --latest', '下载最新第三方模块代码、安装最新依赖']],
2907
3128
  action: cmd => {
2908
3129
  run_1('dev', cmd);
2909
3130
  }
@@ -2914,21 +3135,26 @@ var entry = [{
2914
3135
  action: cmd => {
2915
3136
  run_1('build', cmd);
2916
3137
  }
2917
- }, {
2918
- command: 'init',
2919
- description: '根据模块配置初始化项目(eg: 动态拷贝模块、下载依赖、生成app.json等)',
2920
- options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
2921
- action: cmd => {
2922
- run_1('init', cmd);
2923
- }
2924
- }]
3138
+ } // 对外暂不暴露该命令
3139
+ // {
3140
+ // command: 'init',
3141
+ // description: '模块配置初始化项目(eg: 下载第三方模块代码、安装依赖、生成app.json等)',
3142
+ // options: [
3143
+ // ['-m, --module [moduleName]', '模块名称'],
3144
+ // ['-e, --env [env]', '环境变量'],
3145
+ // ],
3146
+ // action: (cmd) => {
3147
+ // require('./scripts/run/index')('init', cmd);
3148
+ // },
3149
+ // },
3150
+ ]
2925
3151
  }];
2926
3152
 
2927
- var require$$6 = {
3153
+ var require$$7 = {
2928
3154
  name: "@tmsfe/tmskit",
2929
- version: "0.0.6",
3155
+ version: "0.0.9-beta.0",
2930
3156
  description: "tmskit",
2931
- main: "main.js",
3157
+ main: "dist/index.cjs",
2932
3158
  bin: {
2933
3159
  tmskit: "main.js"
2934
3160
  },
@@ -2965,13 +3191,11 @@ var require$$6 = {
2965
3191
  chalk: "^4.1.0",
2966
3192
  commander: "^8.3.0",
2967
3193
  "copy-webpack-plugin": "^9.1.0",
2968
- "download-git-repo": "^3.0.2",
2969
3194
  ejs: "^3.1.5",
2970
3195
  "fs-extra": "^10.0.1",
2971
3196
  "glob-ignore": "^1.0.2",
2972
3197
  gulp: "^4.0.2",
2973
3198
  "gulp-cache": "^1.1.3",
2974
- "gulp-image": "^5.1.0",
2975
3199
  "gulp-postcss": "^9.0.1",
2976
3200
  "gulp-px-to-rpx": "^1.0.7",
2977
3201
  "gulp-watch": "^5.0.1",
@@ -3000,12 +3224,12 @@ var require$$6 = {
3000
3224
  }
3001
3225
  };
3002
3226
 
3003
- const semver = require$$1__default$7;
3004
- const packageJson = require$$6;
3005
- const chalk$1 = require$$0__default$2;
3227
+ const semver = require$$1__default$8;
3228
+ const packageJson = require$$7;
3229
+ const chalk$1 = require$$0__default;
3006
3230
  const {
3007
- log: log$1
3008
- } = widgets;
3231
+ info: info$1
3232
+ } = log$1;
3009
3233
  const requiredVersion = packageJson.engines.node;
3010
3234
  const packName = packageJson.name;
3011
3235
  /**
@@ -3019,7 +3243,7 @@ const checkNodeVersion = (wanted, id) => {
3019
3243
  if (!semver.satisfies(process.version, wanted, {
3020
3244
  includePrerelease: true
3021
3245
  })) {
3022
- log$1(chalk$1.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id} 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
3246
+ info$1(chalk$1.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id} 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
3023
3247
  process.exit(1);
3024
3248
  }
3025
3249
  };
@@ -3037,20 +3261,22 @@ function initCliContext() {
3037
3261
 
3038
3262
  var init$1 = initCliContext;
3039
3263
 
3040
- const chalk = require$$0__default$2;
3041
- const commander = require$$0__default;
3264
+ const chalk = require$$0__default;
3265
+ const commander = require$$0__default$1;
3042
3266
  const {
3043
- log,
3044
3267
  suggestCommands
3045
3268
  } = widgets;
3269
+ const {
3270
+ info
3271
+ } = log$1;
3046
3272
  const {
3047
3273
  TMS_NAME
3048
- } = require$$3;
3274
+ } = require$$4;
3049
3275
  const commands = entry;
3050
3276
  const init = init$1;
3051
3277
  init();
3052
3278
  const program = new commander.Command(TMS_NAME);
3053
- program.version(`${TMS_NAME} ${require$$6.version}`, '-v, -V, --version');
3279
+ program.version(`${TMS_NAME} ${require$$7.version}`, '-v, -V, --version');
3054
3280
 
3055
3281
  function registerCommand(program, commands) {
3056
3282
  commands.forEach(cmd => {
@@ -3074,15 +3300,15 @@ function registerCommand(program, commands) {
3074
3300
 
3075
3301
  registerCommand(program, commands);
3076
3302
  program.on('--help', () => {
3077
- log();
3078
- log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
3079
- log();
3303
+ info();
3304
+ info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
3305
+ info();
3080
3306
  }); // 捕获未注册的命令
3081
3307
 
3082
3308
  program.arguments('<command>').action(cmd => {
3083
3309
  program.outputHelp();
3084
- log(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
3085
- log();
3310
+ info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
3311
+ info();
3086
3312
  suggestCommands(cmd);
3087
3313
  process.exitCode = 1;
3088
3314
  });