@tmsfe/tmskit 0.0.52 → 0.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -31,7 +31,7 @@ var require$$4$2 = require('ansi-colors');
31
31
  var require$$5 = require('chokidar');
32
32
  var require$$6 = require('readable-stream');
33
33
  var require$$7 = require('vinyl-file');
34
- var require$$8$1 = require('vinyl');
34
+ var require$$8 = require('vinyl');
35
35
  var require$$9 = require('anymatch');
36
36
  var require$$11 = require('glob-parent');
37
37
  var require$$2$1 = require('plugin-error');
@@ -72,7 +72,7 @@ var require$$4__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$4$2);
72
72
  var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
73
73
  var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
74
74
  var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
75
- var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8$1);
75
+ var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
76
76
  var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
77
77
  var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
78
78
  var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
@@ -80,29 +80,14 @@ var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
80
80
  var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12$1);
81
81
  var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
82
82
 
83
- function getAugmentedNamespace(n) {
84
- if (n.__esModule) return n;
85
- var a = Object.defineProperty({}, '__esModule', {value: true});
86
- Object.keys(n).forEach(function (k) {
87
- var d = Object.getOwnPropertyDescriptor(n, k);
88
- Object.defineProperty(a, k, d.get ? d : {
89
- enumerable: true,
90
- get: function () {
91
- return n[k];
92
- }
93
- });
94
- });
95
- return a;
96
- }
97
-
98
83
  var src$3 = {};
99
84
 
100
85
  const chalk$5 = require$$3__default;
101
86
  const moment$1 = require$$1__default;
87
+
102
88
  /**
103
89
  * 本文件提供无依赖的在终端打印彩色文字的方法。
104
90
  */
105
-
106
91
  const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按,用来还原属性
107
92
 
108
93
  /**
@@ -110,43 +95,33 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
110
95
  * @param {String} message 需要打印的文字信息
111
96
  * @returns {undefined} 无
112
97
  */
113
-
114
98
  const fail$a = (message = '') => {
115
99
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
116
-
117
100
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
118
-
119
101
  console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
120
102
  };
103
+
121
104
  /**
122
105
  * 打印绿底黑字格式的文字
123
106
  * @param {String} message 需要打印的文字信息
124
107
  * @returns {undefined} 无
125
108
  */
126
-
127
-
128
109
  const succeed$2 = (message = '') => {
129
110
  const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
130
-
131
111
  const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
132
-
133
112
  console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
134
113
  };
114
+
135
115
  /**
136
116
  * 打印warn提示
137
117
  * @param {String} message 需要打印的文字信息
138
118
  * @returns {undefined} 无
139
119
  */
140
-
141
-
142
120
  const warn$2 = message => {
143
121
  console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, chalk$5.yellow(message));
144
122
  };
145
-
146
123
  const info$l = (...args) => console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
147
-
148
124
  const infoNoTime$1 = (...args) => console.log(...args);
149
-
150
125
  var log$1 = {
151
126
  fail: fail$a,
152
127
  succeed: succeed$2,
@@ -166,32 +141,32 @@ const {
166
141
  const shelljsOptions = {
167
142
  slient: true,
168
143
  async: false
169
- }; // 获取当前目录
144
+ };
170
145
 
146
+ // 获取当前目录
171
147
  const cwd = process.cwd();
172
-
173
148
  function resolve$l(...args) {
174
149
  return path$h.resolve(cwd, ...args);
175
150
  }
151
+
176
152
  /**
177
153
  * 判断变量是否是一个数组
178
154
  * @param { unknown } obj 变量
179
155
  * @returns { boolean } 是否是一个数组
180
156
  */
181
-
182
157
  function isObject(obj) {
183
158
  return Object.prototype.toString.call(obj) === '[object Object]';
184
159
  }
160
+
185
161
  /**
186
162
  * 判断变量是否是一个对象
187
163
  * @param { unknown } obj 变量
188
164
  * @returns { boolean } 是否是一个对象
189
165
  */
190
-
191
-
192
166
  function isArray(obj) {
193
167
  return Object.prototype.toString.call(obj) === '[object Array]';
194
168
  }
169
+
195
170
  /**
196
171
  * 下载模块代码
197
172
  * @param { string } url 模块地址
@@ -199,8 +174,6 @@ function isArray(obj) {
199
174
  * @param { string } branch 分支名
200
175
  * @returns { undefined } no return
201
176
  */
202
-
203
-
204
177
  function downloadRepoForGit$1(url, dest, branch) {
205
178
  const cwd = process.cwd();
206
179
  return new Promise((resolve, reject) => {
@@ -208,7 +181,6 @@ function downloadRepoForGit$1(url, dest, branch) {
208
181
  if (fs$k.existsSync(dest)) {
209
182
  shelljs$7.rm('-rf', path$h.join(dest));
210
183
  }
211
-
212
184
  shelljs$7.mkdir('-p', dest);
213
185
  shelljs$7.cd(dest);
214
186
  shelljs$7.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
@@ -217,20 +189,18 @@ function downloadRepoForGit$1(url, dest, branch) {
217
189
  if (code !== 0) {
218
190
  reject(stderr);
219
191
  }
220
-
221
192
  shelljs$7.cd(cwd);
222
193
  resolve();
223
194
  });
224
195
  });
225
196
  }
197
+
226
198
  /**
227
199
  * pull模块代码
228
200
  * @param { string } dest 下载代码的路径
229
201
  * @param { string } branch 分支名
230
202
  * @returns { undefined } no return
231
203
  */
232
-
233
-
234
204
  function pullRepoForGit$1(dest, branch) {
235
205
  const cwd = process.cwd();
236
206
  return new Promise((resolve, reject) => {
@@ -242,20 +212,18 @@ function pullRepoForGit$1(dest, branch) {
242
212
  if (code !== 0) {
243
213
  reject(stderr);
244
214
  }
245
-
246
215
  shelljs$7.cd(cwd);
247
216
  resolve();
248
217
  });
249
218
  });
250
219
  }
220
+
251
221
  /**
252
222
  * npm 下载依赖
253
223
  * @param {string} dir 下载npm的目录
254
224
  * @param {object} npm npm的配置 (见下获取npm源入参)
255
225
  * @returns
256
226
  */
257
-
258
-
259
227
  function npmInstall$3(dir, npmConfig) {
260
228
  return new Promise((resolve, reject) => {
261
229
  const registry = getNpmRegistry(npmConfig);
@@ -266,11 +234,12 @@ function npmInstall$3(dir, npmConfig) {
266
234
  if (code !== 0) {
267
235
  reject(stderr);
268
236
  }
269
-
270
237
  resolve();
271
238
  });
272
239
  });
273
- } // 获取npm源
240
+ }
241
+
242
+ // 获取npm源
274
243
  // 入参:{
275
244
  // registry: "https://registry.npmjs.org/",
276
245
  // scope: {
@@ -278,31 +247,26 @@ function npmInstall$3(dir, npmConfig) {
278
247
  // }
279
248
  // }
280
249
  // 出参: --@tencent:registry=http://mirrors.tencent.com/npm/ --registry=https://registry.npmjs.org/
281
-
282
-
283
250
  function getNpmRegistry(npmConfig = {}) {
284
251
  let resRegistry = '';
285
-
286
252
  if (npmConfig.registry) {
287
253
  resRegistry = ` --registry=${npmConfig.registry}`;
288
254
  }
289
-
290
255
  if (isObject(npmConfig.scope)) {
291
256
  Object.keys(npmConfig.scope).forEach(key => {
292
257
  resRegistry += ` --${key}:registry=${npmConfig.scope[key]}`;
293
258
  });
294
259
  }
295
-
296
260
  return resRegistry;
297
261
  }
262
+
298
263
  /**
299
264
  * 计算各项任务耗时
300
265
  * @param {Number} start 任务开始时间
301
266
  * @returns {Undefined} 无需返回值
302
267
  */
303
-
304
-
305
268
  const cost = start => Date.now() - start;
269
+
306
270
  /**
307
271
  * 创建构建子任务
308
272
  * @param {Function} task 子任务执行函数
@@ -310,8 +274,6 @@ const cost = start => Date.now() - start;
310
274
  * @param {String} endText 任务结束后提示语
311
275
  * @returns {Undefined} 无需返回值
312
276
  */
313
-
314
-
315
277
  function createTask$7(task, startText, endText) {
316
278
  return async (...args) => {
317
279
  const start = Date.now();
@@ -324,35 +286,32 @@ function createTask$7(task, startText, endText) {
324
286
  return result;
325
287
  };
326
288
  }
289
+
327
290
  /**
328
291
  * 字符串驼峰化处理
329
292
  * @param {String} str 需要处理的字符串
330
293
  * @returns {String} 经过驼峰处理的字符串
331
294
  */
332
-
333
295
  const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
334
-
335
296
  const mergeMap$1 = function (obj, src) {
336
297
  for (const [k, v] of src) {
337
298
  obj.set(k, v);
338
299
  }
339
-
340
300
  return obj;
341
301
  };
342
-
343
302
  const relativeCwdPath$1 = function (file) {
344
303
  return path$h.relative(process.cwd(), file);
345
304
  };
305
+
346
306
  /**
347
307
  * 从一个对象中,检索出去几个字段
348
308
  * @param {*} obj
349
309
  * @param {*} name
350
310
  * @returns
351
311
  */
352
-
353
-
354
312
  const filterField$8 = (obj, filterNames = []) => {
355
- const newObj = { ...obj
313
+ const newObj = {
314
+ ...obj
356
315
  };
357
316
  filterNames.forEach(name => {
358
317
  if (newObj[name]) {
@@ -360,50 +319,46 @@ const filterField$8 = (obj, filterNames = []) => {
360
319
  }
361
320
  });
362
321
  return newObj;
363
- }; // 检索出文件列表
364
-
322
+ };
365
323
 
324
+ // 检索出文件列表
366
325
  function findFiles(globPath, filter = []) {
367
326
  return new Promise((resolve, reject) => {
368
327
  glob(globPath, filter, (err, files) => {
369
328
  if (err) {
370
329
  reject(err);
371
330
  }
372
-
373
331
  resolve(files);
374
332
  });
375
333
  });
376
- } // 获取绝对路径
377
-
334
+ }
378
335
 
336
+ // 获取绝对路径
379
337
  function getAbsolutePath$6(pathDir, cwd = '') {
380
338
  let newPath = pathDir;
381
339
  newPath = newPath.startsWith('/') ? newPath : resolve$l(cwd, newPath);
382
340
  newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
383
341
  return newPath;
384
- } // 版本比较 => 1(大于), 0(等于), -1(小于)
385
-
342
+ }
386
343
 
344
+ // 版本比较 => 1(大于), 0(等于), -1(小于)
387
345
  function versionCompare(v1, v2) {
388
346
  // 将两个版本号拆成数组
389
347
  const arr1 = v1.split('.');
390
348
  const arr2 = v2.split('.');
391
- const minLength = Math.min(arr1.length, arr2.length); // 依次比较版本号每一位大小
392
-
349
+ const minLength = Math.min(arr1.length, arr2.length);
350
+ // 依次比较版本号每一位大小
393
351
  for (let i = 0; i < minLength; i++) {
394
352
  if (parseInt(arr1[i], 10) !== parseInt(arr2[i], 10)) {
395
353
  return parseInt(arr1[i], 10) > parseInt(arr2[i], 10) ? 1 : -1;
396
354
  }
397
- } // 若前几位分隔相同,则按分隔数比较。
398
-
399
-
355
+ }
356
+ // 若前几位分隔相同,则按分隔数比较。
400
357
  if (arr1.length === arr2.length) {
401
358
  return 0;
402
359
  }
403
-
404
360
  return arr1.length > arr2.length ? 1 : -1;
405
361
  }
406
-
407
362
  function getGitUser$2() {
408
363
  const res = shelljs$7.exec('git config user.name', {
409
364
  async: false,
@@ -411,7 +366,6 @@ function getGitUser$2() {
411
366
  });
412
367
  return res.stdout;
413
368
  }
414
-
415
369
  var widgets = {
416
370
  resolve: resolve$l,
417
371
  isObject,
@@ -434,45 +388,63 @@ var widgets = {
434
388
  var tmsMpconfig = {exports: {}};
435
389
 
436
390
  const path$g = require$$1__default$1;
437
- const os = require$$1__default$2; // 用户目录
391
+ const os = require$$1__default$2;
438
392
 
439
- const HOME_DIR = os.homedir(); // 所有文件的缓存目录
393
+ // 用户目录
394
+ const HOME_DIR = os.homedir();
440
395
 
441
- const CACHE_DIR = path$g.resolve(HOME_DIR, '.tmskit'); // 版本管理的CDN地址
396
+ // 所有文件的缓存目录
397
+ const CACHE_DIR = path$g.resolve(HOME_DIR, '.tmskit');
442
398
 
443
- const VERSION_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json'; // version缓存文件
399
+ // 版本管理的CDN地址
400
+ const VERSION_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json';
444
401
 
445
- const VERSION_CACHE_FILE = path$g.resolve(CACHE_DIR, 'version_cache_file.json'); // npm缓存文件
402
+ // version缓存文件
403
+ const VERSION_CACHE_FILE = path$g.resolve(CACHE_DIR, 'version_cache_file.json');
446
404
 
447
- const NPM_CACHE_FILE$1 = path$g.resolve(CACHE_DIR, 'npm_cache_file.json'); // 脚手架模板代码所在目录
405
+ // npm缓存文件
406
+ const NPM_CACHE_FILE$1 = path$g.resolve(CACHE_DIR, 'npm_cache_file.json');
448
407
 
449
- const TEMPLATE_DIR$1 = path$g.resolve(CACHE_DIR, 'template'); // 第三方模块源码存放的临时缓存目录
408
+ // 脚手架模板代码所在目录
409
+ const TEMPLATE_DIR$1 = path$g.resolve(CACHE_DIR, 'template');
450
410
 
451
- const MODULE_CODE_DIR$2 = path$g.resolve(CACHE_DIR, 'modules_code'); // 缓存分包node_modules的目录
411
+ // 第三方模块源码存放的临时缓存目录
412
+ const MODULE_CODE_DIR$2 = path$g.resolve(CACHE_DIR, 'modules_code');
452
413
 
453
- const NODE_MODULES_DIR$2 = path$g.resolve(CACHE_DIR, 'node_modules'); // 扩展命令源码的存放处
414
+ // 缓存分包node_modules的目录
415
+ const NODE_MODULES_DIR$2 = path$g.resolve(CACHE_DIR, 'node_modules');
454
416
 
455
- const EXTEND_CMD$1 = path$g.resolve(CACHE_DIR, 'cmd'); // 创建模板的名称
417
+ // 扩展命令源码的存放处
418
+ const EXTEND_CMD$1 = path$g.resolve(CACHE_DIR, 'cmd');
456
419
 
457
- const TEMPLATE_NAME$1 = 'tmskit-template'; // 脚手架模板的远程地址
420
+ // 创建模板的名称
421
+ const TEMPLATE_NAME$1 = 'tmskit-template';
458
422
 
459
- const TEMPLATE_URL$1 = 'http://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip'; // 脚手架的名称
423
+ // 脚手架模板的远程地址
424
+ const TEMPLATE_URL$1 = 'http://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip';
460
425
 
461
- const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
426
+ // 脚手架的名称
427
+ const TMS_NAME$1 = 'tmskit';
462
428
 
429
+ // 脚手架的配置名称
463
430
  const TMS_CONFIG_FILENAME = 'tms.config.js';
464
- const TMS_PRIVATE_FILENAME = 'tms.private.config.js'; // 模块代码的默认在modules子目录
431
+ const TMS_PRIVATE_FILENAME = 'tms.private.config.js';
465
432
 
466
- const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目录
433
+ // 模块代码的默认在modules子目录
434
+ const DEFAULT_MODULE_DIR = 'modules';
467
435
 
468
- const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
436
+ // 模块代码的默认在modules子目录
437
+ const DEFAULT_CLOUD_MODULE_DIR = './cloud';
469
438
 
470
- const MODULE_CONFIG_FILENAME = 'module.config.json'; // 默认的webpack entry
439
+ // 模块的配置文件的名称
440
+ const MODULE_CONFIG_FILENAME = 'module.config.json';
471
441
 
442
+ // 默认的webpack entry
472
443
  const DEFAULT_WEBPACK_ENTRY = {
473
444
  app: path$g.resolve(process.cwd(), 'app')
474
- }; // 默认从源码拷贝到编译后的配置
445
+ };
475
446
 
447
+ // 默认从源码拷贝到编译后的配置
476
448
  const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json', 'project.config.json'];
477
449
  const ENV = {
478
450
  dev: 'development',
@@ -522,6 +494,7 @@ var constant = {
522
494
  VERSION_URL
523
495
  };
524
496
 
497
+ // tmsConfig默认配置项
525
498
  var defaultTmsConfig = {
526
499
  // 全局的环境配置项
527
500
  envData: {},
@@ -530,22 +503,16 @@ var defaultTmsConfig = {
530
503
  cloudDir: 'cloud',
531
504
  // 第三方依赖代码需要拷贝到本项目的
532
505
  dependencies: {},
533
-
534
506
  /** 编译输出文件夹位置 */
535
507
  outputDir: 'dist',
536
-
537
508
  /** 是否在编译前清空输出目录 */
538
509
  cleanOutputDirBeforeCompile: true,
539
-
540
510
  /** 源码监听路径 */
541
511
  sourceDir: './',
542
-
543
512
  /** 静态资源目录 */
544
513
  static: [],
545
-
546
514
  /** 监听扩展文件 */
547
515
  watchExtendFiles: [],
548
-
549
516
  /** 上传是的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E7%BC%96%E8%AF%91%E8%AE%BE%E7%BD%AE */
550
517
  upload: {
551
518
  setting: {
@@ -558,7 +525,6 @@ var defaultTmsConfig = {
558
525
  autoPrefixWXSS: true
559
526
  }
560
527
  },
561
-
562
528
  /** 预览的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88 */
563
529
  preview: {
564
530
  setting: {
@@ -578,7 +544,6 @@ var defaultTmsConfig = {
578
544
 
579
545
  const global$c = {
580
546
  data: {},
581
-
582
547
  setData(...args) {
583
548
  if (args.length === 1) {
584
549
  Object.keys(args[0]).forEach(k => {
@@ -591,11 +556,9 @@ const global$c = {
591
556
  this.data[name] = value;
592
557
  }
593
558
  },
594
-
595
559
  getData(name) {
596
560
  return this.data[name];
597
561
  }
598
-
599
562
  };
600
563
  var global_1 = {
601
564
  global: global$c
@@ -604,7 +567,6 @@ var global_1 = {
604
567
  /**
605
568
  * 用来读取处理tms.config.js与module.config.json字段
606
569
  */
607
-
608
570
  (function (module) {
609
571
  /* eslint-disable no-param-reassign, no-nested-ternary */
610
572
  const loadash = require$$0__default$3;
@@ -630,85 +592,75 @@ var global_1 = {
630
592
  const {
631
593
  fail
632
594
  } = log$1;
595
+
633
596
  /**
634
597
  * 读取tms.config.js
635
598
  * @param {string} configPath tms.config.js的路径
636
599
  */
637
-
638
600
  const readTmsConfig = function (configPath) {
639
601
  const tmsConfigPath = configPath ? `${configPath}/${TMS_CONFIG_FILENAME}` : resolve(TMS_CONFIG_FILENAME);
640
-
641
602
  if (!fs.existsSync(tmsConfigPath)) {
642
603
  fail(`${path.dirname(tmsConfigPath)}没有找到tms.config.js,请进行配置`);
643
604
  process.exit(1);
644
605
  }
645
-
646
606
  const env = global.getData('commandName');
647
-
648
607
  const tmsConfigFn = require(tmsConfigPath);
649
-
650
608
  const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn({
651
609
  env
652
- }) : tmsConfigFn; // 合并默认值
610
+ }) : tmsConfigFn;
653
611
 
612
+ // 合并默认值
654
613
  return loadash.mergeWith({}, defaultTmsConfig$1, tmsConfig);
655
614
  };
615
+
656
616
  /**
657
617
  * 读取tms.private.config.js
658
618
  * @param {string} configPath tms.private.config.js的路径
659
619
  */
660
-
661
-
662
620
  const readTmsPrivateCf = function (configPath) {
663
621
  let tmsPrivateCf = {};
664
622
  const tmsPrivatePath = configPath ? `${configPath}/${TMS_PRIVATE_FILENAME}` : resolve(TMS_PRIVATE_FILENAME);
665
-
666
623
  if (fs.existsSync(tmsPrivatePath)) {
667
624
  const env = global.getData('commandName');
668
-
669
625
  const tmsPrivateFn = require(tmsPrivatePath);
670
-
671
626
  tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn({
672
627
  env
673
628
  }) : tmsPrivateFn;
674
629
  }
675
-
676
630
  return tmsPrivateCf;
677
631
  };
632
+
678
633
  /**
679
634
  * 获取tms.config.js, tms.private.config.js的配置项
680
635
  * @param {string} configPath config.js的路径
681
636
  * @returns
682
637
  */
683
-
684
-
685
638
  const getTmsConfig = configPath => {
686
639
  const tmsPrivateCf = readTmsPrivateCf(configPath);
687
640
  const tmsConfig = readTmsConfig(configPath);
688
641
  const modules = {};
689
-
690
642
  if (Array.isArray(tmsConfig.modules)) {
691
643
  modules.all = tmsConfig.modules;
692
644
  tmsConfig.modules = modules;
693
- } // 使用自定义的合并策略:
645
+ }
646
+ // 使用自定义的合并策略:
694
647
  // 1. 对 templateVars 字段做浅合并(即把 tms.config.js 中的和 tms.private.config.js 中的对象合并,
695
648
  // 如果存在同名字段则以 tms.private.config.js 中的为准)。
696
649
  // 2. 对数组(并且数组元素为对象的情况)执行拼接
697
-
698
-
699
650
  const res = loadash.mergeWith({}, tmsConfig, tmsPrivateCf, (objValue, srcValue, key) => {
700
651
  if (key === 'templateVars') {
701
- return { ...(objValue || {}),
652
+ return {
653
+ ...(objValue || {}),
702
654
  ...(srcValue || {})
703
655
  };
704
656
  }
705
-
706
657
  if (Array.isArray(objValue) && objValue[0] && isObject(objValue[0])) {
707
658
  return objValue.concat(srcValue);
708
659
  }
709
660
  });
710
661
  return res;
711
662
  };
663
+
712
664
  /**
713
665
  * 根据moduleNames获取modules
714
666
  * @param { object } tmsConfig
@@ -716,48 +668,39 @@ var global_1 = {
716
668
  * @param {boolean} errorIsQuit 找不到配置文件是否退出
717
669
  * @returns
718
670
  */
719
-
720
-
721
671
  const getModulesByModuleNames = function (tmsConfig, moduleNames = []) {
722
672
  const targetModules = [];
723
673
  moduleNames.forEach(moduleName => {
724
674
  const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
725
-
726
675
  if (!module) {
727
676
  throw new Error(`你启动的模块${moduleName}在tms.config.js的modules.all中没有注册`);
728
677
  }
729
-
730
678
  targetModules.push(module);
731
679
  });
732
680
  return targetModules;
733
681
  };
682
+
734
683
  /**
735
684
  * 适配处理module.config.json的字段
736
685
  * @param { object } fileContent module.config.json的内容
737
686
  * @param { string } appName 小程序的名称
738
687
  */
739
-
740
-
741
688
  function adaptMpCgContent(fileContent, appName) {
742
689
  const handleContent = function (appName, current) {
743
690
  let res = current;
744
-
745
691
  if (appName && current.mpConfig && current.mpConfig[appName]) {
746
- res = { ...current,
692
+ res = {
693
+ ...current,
747
694
  ...current.mpConfig[appName]
748
695
  };
749
696
  }
750
-
751
697
  delete res.mpConfig;
752
698
  delete res.isSubpackages;
753
699
  return res;
754
700
  };
755
-
756
701
  let content = fileContent;
757
-
758
702
  if (isArray(content)) {
759
703
  let i = content.length - 1;
760
-
761
704
  while (i >= 0) {
762
705
  content[i] = handleContent(appName, content[i]);
763
706
  i--; // eslint-disable-line
@@ -765,23 +708,20 @@ var global_1 = {
765
708
  } else {
766
709
  content = handleContent(appName, content);
767
710
  }
768
-
769
711
  return content;
770
712
  }
771
-
772
713
  const adaptSubPackages = function (moduleConfig, appName) {
773
714
  const {
774
715
  subPackages
775
716
  } = moduleConfig;
776
717
  return adaptMpCgContent(subPackages, appName);
777
718
  };
719
+
778
720
  /**
779
721
  * 获取模块module.config.json中的配置信息
780
722
  * @param {array} modules 用户要编译的模块列表
781
723
  * @param { string } appName 小程序的名称
782
724
  */
783
-
784
-
785
725
  function getModulesConfig(modules = [], tmsConfig) {
786
726
  const {
787
727
  appName
@@ -790,57 +730,56 @@ var global_1 = {
790
730
  modules.forEach(moduleItem => {
791
731
  const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
792
732
  let moduleConfig;
793
-
794
733
  try {
795
734
  // 模板渲染:先将 module.config.json 转为字符串,然后通过 preprocess 渲染
796
735
  const moduleConfigJsonStr = fs.readFileSync(moduleConfigPath, 'utf-8');
797
- const preprocessedStr = pp.preprocess(moduleConfigJsonStr, tmsConfig.templateVars || {}, 'json'); // fs.writeFileSync(resolve(moduleConfigPath), moduleConfigJsonStr, 'utf8');
798
-
736
+ const preprocessedStr = pp.preprocess(moduleConfigJsonStr, tmsConfig.templateVars || {}, 'json');
737
+ // fs.writeFileSync(resolve(moduleConfigPath), moduleConfigJsonStr, 'utf8');
799
738
  moduleConfig = JSON5.parse(preprocessedStr);
800
739
  } catch (e) {
801
740
  throw new Error(`${moduleConfigPath}json解析报错: ${e}`);
802
- } // 兼容历史逻辑,后续可删除--- start
803
-
741
+ }
804
742
 
743
+ // 兼容历史逻辑,后续可删除--- start
805
744
  const subPackages = adaptSubPackages(moduleConfig, appName);
806
- moduleConfig = { ...(isObject(moduleConfig) ? moduleConfig : {}),
745
+ moduleConfig = {
746
+ ...(isObject(moduleConfig) ? moduleConfig : {}),
807
747
  subPackages
808
- }; // 兼容逻辑--- end
809
-
748
+ };
749
+ // 兼容逻辑--- end
810
750
  modulesConfig.push(moduleConfig);
811
751
  });
812
752
  return modulesConfig;
813
753
  }
754
+
814
755
  /**
815
756
  * 获取分包内容 (读取module.config.json的配置项)
816
757
  * @param {array} modules
817
758
  * @returns
818
759
  */
819
-
820
-
821
760
  const getSubPackages = modules => {
822
761
  const newSubPackages = [];
823
762
  modules.forEach(module => {
824
763
  (module.subPackages || []).forEach(subPackage => {
825
- newSubPackages.push({ ...subPackage
764
+ newSubPackages.push({
765
+ ...subPackage
826
766
  });
827
767
  });
828
768
  });
829
769
  return newSubPackages;
830
770
  };
771
+
831
772
  /**
832
773
  * 获取分包的root字段
833
774
  * @param {*} modulePath 模块的编译路径
834
775
  * @param {*} root 分包的root字段
835
776
  * @returns
836
777
  */
837
-
838
-
839
778
  const getSubPackageRoot = function (modulePath, root) {
840
779
  return root.startsWith(modulePath) ? root : `${modulePath}/${root}`;
841
- }; // 获取分包的源码路径
842
-
780
+ };
843
781
 
782
+ // 获取分包的源码路径
844
783
  const getSubPackageSrcPath = function (tmsConfig, module, subPackage) {
845
784
  const srcModulePath = getAbsolutePath(module.path);
846
785
  const buildModulePath = resolve(tmsConfig.outputDir, module.modulePath);
@@ -850,39 +789,37 @@ var global_1 = {
850
789
  const srcSubPackagePath = path.join(srcModulePath, subPackageRelativeModule);
851
790
  return srcSubPackagePath;
852
791
  };
853
-
854
792
  const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
855
- const newModuleItem = { ...tmsModuleItem,
793
+ const newModuleItem = {
794
+ ...tmsModuleItem,
856
795
  ...moduleConfig
857
- }; // 参数校验-模块源码路径
796
+ };
858
797
 
798
+ // 参数校验-模块源码路径
859
799
  if (!newModuleItem.path) {
860
800
  throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
861
- } // 参数校验-模块编译路径
862
-
801
+ }
863
802
 
803
+ // 参数校验-模块编译路径
864
804
  if (!newModuleItem.modulePath) {
865
805
  throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到modulePath字段`);
866
- } // 参数校验-分包校验
867
-
868
-
806
+ }
807
+ // 参数校验-分包校验
869
808
  for (const subPackage of newModuleItem.subPackages) {
870
809
  if (!subPackage.root) {
871
810
  throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到${subPackage.name}分包的root字段`);
872
- } // 参数校验-判断分包源码目录是否存在
873
-
811
+ }
874
812
 
813
+ // 参数校验-判断分包源码目录是否存在
875
814
  const subPackageSrcPath = getSubPackageSrcPath(tmsConfig, newModuleItem, subPackage);
876
-
877
815
  if (!subPackageSrcPath || !fs.existsSync(subPackageSrcPath)) {
878
816
  throw new Error(`没有找到${newModuleItem.moduleName}模块的${subPackage.name}分包源码:${subPackageSrcPath}`);
879
817
  }
880
-
881
818
  subPackage.path = subPackageSrcPath;
882
819
  }
883
-
884
820
  return newModuleItem;
885
821
  };
822
+
886
823
  /**
887
824
  * 获取所有的模块,合并模块的依赖模块
888
825
  * @param { object } tmsConfig
@@ -890,54 +827,40 @@ var global_1 = {
890
827
  * @param {boolean} errorIsQuit 找不到配置文件是否退出
891
828
  * @returns
892
829
  */
893
-
894
-
895
830
  const getModulesByMergeDepModules = (tmsConfig, modules, errorIsQuit = false) => {
896
831
  const allModules = new Map();
897
-
898
832
  function dfs(tmsConfig, modules) {
899
833
  modules.forEach(moduleItem => {
900
834
  if (!moduleItem.path) {
901
835
  throw new Error(`${moduleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
902
836
  }
903
-
904
837
  const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
905
-
906
838
  if (!fs.existsSync(moduleConfigPath)) {
907
839
  if (!allModules.has(moduleItem.moduleName)) {
908
840
  allModules.set(moduleItem.moduleName, moduleItem);
909
841
  }
910
-
911
842
  if (errorIsQuit) {
912
843
  throw new Error(`${moduleItem.moduleName}模块的配置文件module.config.json在${moduleItem.path}目录下没有找到 ${moduleConfigPath}`);
913
844
  }
914
-
915
845
  return;
916
846
  }
917
-
918
847
  const [moduleConfig = {}] = getModulesConfig([moduleItem], tmsConfig);
919
-
920
848
  if (!allModules.has(moduleItem.moduleName)) {
921
849
  allModules.set(moduleItem.moduleName, checkModuleItem(tmsConfig, moduleItem, moduleConfig));
922
850
  const dependenciesModules = getModulesByModuleNames(tmsConfig, moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies);
923
-
924
851
  if (dependenciesModules.length) {
925
852
  dfs(tmsConfig, dependenciesModules);
926
853
  }
927
854
  }
928
855
  });
929
856
  }
930
-
931
857
  dfs(tmsConfig, modules);
932
858
  const modulesArr = [];
933
-
934
859
  for (const module of allModules.values()) {
935
860
  modulesArr.push(module);
936
861
  }
937
-
938
862
  return modulesArr;
939
863
  };
940
-
941
864
  module.exports = {
942
865
  readTmsConfig,
943
866
  readTmsPrivateCf,
@@ -962,10 +885,9 @@ const {
962
885
  * @param {string} dirname 目录名
963
886
  * @returns
964
887
  */
888
+ const isDirEmpty = dirname => fs$j.promises.readdir(dirname).then(files => files.length === 0);
965
889
 
966
- const isDirEmpty = dirname => fs$j.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
967
-
968
-
890
+ // 判断是否是文件
969
891
  const isFile = pathName => {
970
892
  try {
971
893
  const stat = fs$j.lstatSync(pathName);
@@ -974,37 +896,34 @@ const isFile = pathName => {
974
896
  return false;
975
897
  }
976
898
  };
899
+
977
900
  /**
978
901
  * 确保目录存在,不存在就创建一个
979
902
  * @param {*} dirname 目录名
980
903
  */
981
-
982
-
983
904
  const ensureDirExist$6 = dirname => {
984
905
  if (!fs$j.existsSync(dirname)) {
985
906
  fs$j.mkdirSync(dirname, {
986
907
  recursive: true
987
908
  });
988
909
  }
989
- }; // 复制文件
990
-
910
+ };
991
911
 
912
+ // 复制文件
992
913
  const copyFile = function (src, dest) {
993
914
  if (fs$j.existsSync(dest)) {
994
915
  fs$j.unlinkSync(dest);
995
916
  }
996
-
997
917
  const dir = path$f.dirname(dest);
998
918
  ensureDirExist$6(dir);
999
919
  fs$j.copyFileSync(src, dest);
1000
- }; // 判断文件内容是否一致,不一致再进行拷贝
1001
-
920
+ };
1002
921
 
922
+ // 判断文件内容是否一致,不一致再进行拷贝
1003
923
  function diffContentCopyFile(originFile, destFile) {
1004
924
  if (fs$j.existsSync(destFile)) {
1005
925
  const depDestContent = fs$j.readFileSync(destFile, 'utf8');
1006
926
  const depOriginContent = fs$j.readFileSync(originFile, 'utf8');
1007
-
1008
927
  if (depDestContent !== depOriginContent) {
1009
928
  info$j(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
1010
929
  copyFile(originFile, destFile);
@@ -1013,25 +932,22 @@ function diffContentCopyFile(originFile, destFile) {
1013
932
  info$j(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
1014
933
  copyFile(originFile, destFile);
1015
934
  }
1016
- } // 添加后缀
1017
-
935
+ }
1018
936
 
937
+ // 添加后缀
1019
938
  function ext(filePath, extensions) {
1020
939
  let newFilePath = filePath;
1021
- let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
1022
-
940
+ let extPath = '';
941
+ // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
1023
942
  try {
1024
943
  const stat = fs$j.lstatSync(newFilePath);
1025
-
1026
944
  if (stat.isDirectory()) {
1027
945
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
1028
946
  newFilePath += extPath;
1029
947
  }
1030
948
  } catch (e) {}
1031
-
1032
949
  for (const ext of extensions) {
1033
950
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
1034
-
1035
951
  if (fs$j.existsSync(file)) {
1036
952
  return {
1037
953
  ext,
@@ -1040,38 +956,31 @@ function ext(filePath, extensions) {
1040
956
  };
1041
957
  }
1042
958
  }
1043
-
1044
959
  return {
1045
960
  ext: '',
1046
961
  extPath,
1047
962
  file: filePath
1048
963
  };
1049
- } // 判断文件是否在某个目录
1050
-
964
+ }
1051
965
 
966
+ // 判断文件是否在某个目录
1052
967
  const fileInDir = (dir, file) => {
1053
968
  if (!fs$j.existsSync(dir) || !fs$j.existsSync(file)) {
1054
969
  return false;
1055
970
  }
1056
-
1057
971
  const relativePath = path$f.relative(dir, file);
1058
-
1059
972
  if (relativePath.startsWith('..')) {
1060
973
  return false;
1061
974
  }
1062
-
1063
975
  return true;
1064
976
  };
1065
-
1066
977
  function findAllFilesOfDir(dir) {
1067
978
  const list = [];
1068
-
1069
979
  function listFile(dir) {
1070
980
  const arr = fs$j.readdirSync(dir);
1071
981
  arr.forEach(item => {
1072
982
  const fullPath = path$f.join(dir, item);
1073
983
  const stats = fs$j.statSync(fullPath);
1074
-
1075
984
  if (stats.isDirectory()) {
1076
985
  listFile(fullPath);
1077
986
  } else {
@@ -1080,11 +989,9 @@ function findAllFilesOfDir(dir) {
1080
989
  });
1081
990
  return list;
1082
991
  }
1083
-
1084
992
  listFile(dir);
1085
993
  return list;
1086
994
  }
1087
-
1088
995
  var io$3 = {
1089
996
  isDirEmpty,
1090
997
  copyFile,
@@ -1098,22 +1005,18 @@ var io$3 = {
1098
1005
 
1099
1006
  const async = require$$0__default$4;
1100
1007
  const ejs = require$$1__default$4;
1101
-
1102
1008
  const render$1 = (files, metalsmith, next) => {
1103
1009
  const keys = Object.keys(files);
1104
1010
  const metadata = metalsmith.metadata();
1105
-
1106
1011
  const run = (file, next) => {
1107
1012
  const str = files[file].contents.toString();
1108
- const newStr = ejs.render(str, metadata); // eslint-disable-next-line
1109
-
1013
+ const newStr = ejs.render(str, metadata);
1014
+ // eslint-disable-next-line
1110
1015
  files[file].contents = Buffer.from(newStr);
1111
1016
  next();
1112
1017
  };
1113
-
1114
1018
  async.each(keys, run, next);
1115
1019
  };
1116
-
1117
1020
  var render_1 = render$1;
1118
1021
 
1119
1022
  const fs$i = require$$0__default$1;
@@ -1129,17 +1032,13 @@ const {
1129
1032
  * @param {string} dir questions.json所在的目录
1130
1033
  * @returns {Array} inquirer 问题数组
1131
1034
  */
1132
-
1133
1035
  const parseTemplateQuestions = dir => {
1134
1036
  let prompts = [];
1135
-
1136
1037
  if (!fs$i.existsSync(`${dir}/questions.json`)) {
1137
1038
  return prompts;
1138
1039
  }
1139
-
1140
1040
  try {
1141
1041
  const json = JSON.parse(fs$i.readFileSync(`${dir}/questions.json`));
1142
-
1143
1042
  if (Array.isArray(json) && json.length > 0) {
1144
1043
  json.forEach((item, index) => {
1145
1044
  if (!isQuestionType(item)) {
@@ -1149,27 +1048,21 @@ const parseTemplateQuestions = dir => {
1149
1048
  } else {
1150
1049
  throw new Error('问题文件只能是数组');
1151
1050
  }
1152
-
1153
1051
  prompts = json;
1154
1052
  } catch (err) {
1155
1053
  throw new Error(`模板异常,${err.message}`);
1156
1054
  }
1157
-
1158
1055
  return prompts;
1159
1056
  };
1160
-
1161
1057
  const isQuestionType = result => {
1162
1058
  if (!('message' in result)) {
1163
1059
  return false;
1164
1060
  }
1165
-
1166
1061
  if (!('name' in result)) {
1167
1062
  return false;
1168
1063
  }
1169
-
1170
1064
  return true;
1171
1065
  };
1172
-
1173
1066
  const ask$1 = templateDir => (files, metalsmith, next) => {
1174
1067
  const prompts = parseTemplateQuestions(resolve$k(templateDir, TEMPLATE_TKIT_DIR$1));
1175
1068
  const metadata = metalsmith.metadata();
@@ -1177,22 +1070,20 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
1177
1070
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
1178
1071
  return false;
1179
1072
  }
1180
-
1181
1073
  return true;
1182
1074
  });
1183
1075
  inquirer$1.prompt(filteredPrompts).then(res => {
1184
1076
  for (const prompt of filteredPrompts) {
1185
1077
  metadata[prompt.name] = res[prompt.name];
1186
1078
  }
1187
-
1188
1079
  next();
1189
1080
  }).catch(err => {
1190
1081
  next(err);
1191
1082
  });
1192
1083
  };
1193
-
1194
1084
  var ask_1 = ask$1;
1195
1085
 
1086
+ // 在metal smith遍历时需要忽略的文件,这些文件会引起metalsmith的parse error
1196
1087
  const FILES_TO_IGNORE$1 = ['node_modules'];
1197
1088
  var ignoreFiles = FILES_TO_IGNORE$1;
1198
1089
 
@@ -1200,7 +1091,6 @@ const Metalsmith = require$$0__default$5;
1200
1091
  const render = render_1;
1201
1092
  const ask = ask_1;
1202
1093
  const FILES_TO_IGNORE = ignoreFiles;
1203
-
1204
1094
  const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolve, reject) => {
1205
1095
  Metalsmith(buildDir).metadata(preMetadata).ignore(FILES_TO_IGNORE).clean(false).use(ask(buildDir)).source('./').destination(distDir).use(render).build(err => {
1206
1096
  if (err) {
@@ -1210,7 +1100,6 @@ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolv
1210
1100
  }
1211
1101
  });
1212
1102
  });
1213
-
1214
1103
  var generator_1 = generator$1;
1215
1104
 
1216
1105
  const request$1 = require$$0__default$6;
@@ -1218,7 +1107,6 @@ const {
1218
1107
  getGitUser: getGitUser$1
1219
1108
  } = widgets;
1220
1109
  const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
1221
-
1222
1110
  const report$b = (name, attrs = {}) => {
1223
1111
  try {
1224
1112
  const param = [];
@@ -1226,23 +1114,21 @@ const report$b = (name, attrs = {}) => {
1226
1114
  param[28] = 'tmskit';
1227
1115
  param[29] = getGitUser$1();
1228
1116
  param[30] = JSON.stringify(attrs);
1229
-
1230
1117
  for (let i = 0; i < 40; i++) {
1231
1118
  if (!param[i]) param[i] = null;
1232
1119
  }
1233
-
1234
1120
  ;
1235
1121
  request$1.post({
1236
1122
  url: apiUrl,
1237
1123
  json: {
1238
1124
  param
1239
1125
  }
1240
- }, () => {}); // (error, response, body) => {
1126
+ }, () => {});
1127
+ // (error, response, body) => {
1241
1128
  // console.log('body:', body);
1242
1129
  // }
1243
1130
  } catch (e) {}
1244
1131
  };
1245
-
1246
1132
  var report_1 = report$b;
1247
1133
 
1248
1134
  const path$e = require$$1__default$1;
@@ -1269,12 +1155,12 @@ const generator = generator_1;
1269
1155
  const request = require$$0__default$6;
1270
1156
  const unzip = require$$10__default;
1271
1157
  const report$a = report_1;
1158
+
1272
1159
  /**
1273
1160
  * 如果该目录下面存在文件,换个名字
1274
1161
  * @param { string } targetDir 当前文件夹
1275
1162
  * @returns { undefined }
1276
1163
  */
1277
-
1278
1164
  async function createProjectDir(targetDir) {
1279
1165
  // 如果目录非空或者已经存在,提示用户,做选择
1280
1166
  if (fs$h.existsSync(targetDir)) {
@@ -1286,6 +1172,7 @@ async function createProjectDir(targetDir) {
1286
1172
  shelljs$6.mkdir('-p', targetDir);
1287
1173
  }
1288
1174
  }
1175
+
1289
1176
  /**
1290
1177
  * 下载和解压远程的小程序模板
1291
1178
  * @param {string} templateDir
@@ -1293,8 +1180,6 @@ async function createProjectDir(targetDir) {
1293
1180
  * @param {string} templateName
1294
1181
  * @returns
1295
1182
  */
1296
-
1297
-
1298
1183
  function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1299
1184
  return new Promise((resolve, reject) => {
1300
1185
  const localZipPath = `${templateDir}/${templateName}.zip`;
@@ -1304,7 +1189,6 @@ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1304
1189
  reject(err);
1305
1190
  return;
1306
1191
  }
1307
-
1308
1192
  fs$h.createReadStream(localZipPath).pipe(unzip.Extract({
1309
1193
  path: templateDir
1310
1194
  })).on('close', err => {
@@ -1312,19 +1196,17 @@ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1312
1196
  reject(err);
1313
1197
  return;
1314
1198
  }
1315
-
1316
1199
  resolve();
1317
1200
  });
1318
1201
  });
1319
1202
  });
1320
1203
  }
1204
+
1321
1205
  /**
1322
1206
  * 创建本地小程序运行环境
1323
1207
  * @param { string } projectType 项目类型
1324
1208
  * @param { string } projectName 项目名称
1325
1209
  */
1326
-
1327
-
1328
1210
  async function create(projectName) {
1329
1211
  const cwd = process.cwd();
1330
1212
  const targetDir = path$e.resolve(cwd, projectName);
@@ -1333,27 +1215,28 @@ async function create(projectName) {
1333
1215
  } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
1334
1216
  report$a('create-start', {
1335
1217
  projectType
1336
- }); // 创建项目目录
1218
+ });
1337
1219
 
1338
- await createProjectDir(targetDir); // 新创建缓存目录
1220
+ // 创建项目目录
1221
+ await createProjectDir(targetDir);
1339
1222
 
1223
+ // 新创建缓存目录
1340
1224
  if (fs$h.existsSync(TEMPLATE_DIR)) {
1341
1225
  shelljs$6.rm('-rf', TEMPLATE_DIR);
1342
1226
  }
1343
-
1344
1227
  fs$h.mkdirSync(TEMPLATE_DIR, {
1345
1228
  recursive: true
1346
- }); // 下载和解压模板
1229
+ });
1347
1230
 
1348
- await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
1231
+ // 下载和解压模板
1232
+ await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME);
1349
1233
 
1234
+ // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
1350
1235
  generator(path$e.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1351
1236
  shelljs$6.cd(projectName);
1352
1237
  const hookFilePath = resolve$j(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1353
-
1354
1238
  if (fs$h.existsSync(hookFilePath)) {
1355
1239
  const hooks = require(hookFilePath);
1356
-
1357
1240
  if (hooks.afterCreate) {
1358
1241
  hooks.afterCreate.forEach(item => {
1359
1242
  if (typeof item === 'function') {
@@ -1365,10 +1248,8 @@ async function create(projectName) {
1365
1248
  }
1366
1249
  });
1367
1250
  }
1368
-
1369
1251
  shelljs$6.rm('-rf', resolve$j(projectName, TEMPLATE_TKIT_DIR));
1370
1252
  }
1371
-
1372
1253
  report$a('create-success', {
1373
1254
  projectType
1374
1255
  });
@@ -1378,7 +1259,6 @@ async function create(projectName) {
1378
1259
  info$i('详细的错误信息:', err);
1379
1260
  });
1380
1261
  }
1381
-
1382
1262
  var create_1 = create;
1383
1263
 
1384
1264
  const fs$g = require$$0__default$1;
@@ -1397,23 +1277,21 @@ const {
1397
1277
  info: info$h,
1398
1278
  fail: fail$8
1399
1279
  } = log$1;
1280
+
1400
1281
  /**
1401
1282
  * 下载扩展命令的npm包
1402
1283
  * @param {string} npmName npm包名
1403
1284
  * @param {object} cmd {registry: 'http://mirrors.tencent.com/npm/'} 用户输入执行install-cmd的参数
1404
1285
  */
1405
-
1406
1286
  async function installCmd(npmName, cmd) {
1407
1287
  try {
1408
1288
  const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1409
-
1410
1289
  if (!fs$g.existsSync(cmdPackageJson)) {
1411
1290
  ensureDirExist$5(EXTEND_CMD);
1412
1291
  fs$g.writeFileSync(cmdPackageJson, JSON.stringify({
1413
1292
  dependencies: {}
1414
1293
  }, null, 2));
1415
1294
  }
1416
-
1417
1295
  shellJs$3.cd(EXTEND_CMD);
1418
1296
  await createTask$6(npmName => new Promise((resolve, reject) => {
1419
1297
  const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
@@ -1424,7 +1302,6 @@ async function installCmd(npmName, cmd) {
1424
1302
  if (code !== 0) {
1425
1303
  reject(stderr);
1426
1304
  }
1427
-
1428
1305
  resolve();
1429
1306
  });
1430
1307
  }), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
@@ -1434,16 +1311,14 @@ async function installCmd(npmName, cmd) {
1434
1311
  process.exit(1);
1435
1312
  }
1436
1313
  }
1314
+
1437
1315
  /**
1438
1316
  * 加载扩展命令的npm包
1439
1317
  * @returns
1440
1318
  */
1441
-
1442
-
1443
1319
  function loadExtendCmd$1() {
1444
1320
  const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1445
1321
  const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
1446
-
1447
1322
  if (fs$g.existsSync(cmdPackageJson)) {
1448
1323
  const content = fs$g.readFileSync(cmdPackageJson, 'utf8');
1449
1324
  const json = JSON.parse(content);
@@ -1453,17 +1328,14 @@ function loadExtendCmd$1() {
1453
1328
  // 检索cmd的npm包
1454
1329
  if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
1455
1330
  const cmdConfig = path$d.join(cmdNpmDir, name, 'tms.config.js');
1456
-
1457
1331
  if (fs$g.existsSync(cmdConfig)) {
1458
1332
  cmdConfigs.push(cmdConfig);
1459
1333
  }
1460
1334
  });
1461
1335
  return cmdConfigs;
1462
1336
  }
1463
-
1464
1337
  return [];
1465
1338
  }
1466
-
1467
1339
  var extendCmd = {
1468
1340
  installCmd,
1469
1341
  loadExtendCmd: loadExtendCmd$1
@@ -1475,17 +1347,13 @@ const {
1475
1347
  const {
1476
1348
  global: global$b
1477
1349
  } = global_1;
1478
-
1479
1350
  function handleError$9(error, isQuit = false) {
1480
1351
  const errMsg = typeof error === 'object' ? error.message : error;
1481
-
1482
1352
  if (isQuit) {
1483
1353
  fail$7(errMsg);
1484
1354
  process.exit(1);
1485
1355
  }
1486
-
1487
1356
  const isDev = global$b.getData('isDev');
1488
-
1489
1357
  if (isDev) {
1490
1358
  fail$7(errMsg);
1491
1359
  } else {
@@ -1493,42 +1361,35 @@ function handleError$9(error, isQuit = false) {
1493
1361
  process.exit(1);
1494
1362
  }
1495
1363
  }
1496
-
1497
1364
  var handleError_1 = {
1498
1365
  handleError: handleError$9
1499
1366
  };
1500
1367
 
1501
1368
  const {
1502
1369
  resolve: resolve$i
1503
- } = require('../utils/widgets');
1504
-
1370
+ } = widgets;
1505
1371
  const {
1506
1372
  info: info$g
1507
- } = require('../utils/log');
1373
+ } = log$1;
1374
+ const fs$f = require$$0__default$1;
1508
1375
 
1509
- const fs$f = require('fs');
1510
1376
  /* eslint-disable no-param-reassign */
1511
-
1512
1377
  /**
1513
1378
  * 检查是否包含 meta-services 分包
1514
1379
  * @param {Object} appJson app.json配置对象
1515
1380
  * @returns {boolean}
1516
1381
  */
1517
-
1518
-
1519
1382
  function hasMetaServicesSubpackage(appJson) {
1520
1383
  return appJson.subpackages.some(s => s.root === 'modules/meta-services' || s.name === 'meta-services');
1521
1384
  }
1385
+
1522
1386
  /**
1523
1387
  * 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除 agent 配置
1524
1388
  * @param {Object} appJson app.json配置对象
1525
1389
  */
1526
-
1527
-
1528
1390
  function handleAgentConfig$1(appJson) {
1529
1391
  const hasMetaServices = hasMetaServicesSubpackage(appJson);
1530
1392
  console.log('🔍', hasMetaServices ? '包含' : '不包含', 'meta-services 分包');
1531
-
1532
1393
  if (hasMetaServices) {
1533
1394
  if (!appJson.agent) {
1534
1395
  try {
@@ -1544,23 +1405,20 @@ function handleAgentConfig$1(appJson) {
1544
1405
  info$g('已移除 agent 配置');
1545
1406
  }
1546
1407
  }
1408
+
1547
1409
  /**
1548
1410
  * 处理 project.config.json 中的 packOptions.include 配置
1549
1411
  * @param {Object} appJson app.json配置对象
1550
1412
  * @param {string} outputDir 输出目录
1551
1413
  */
1552
-
1553
1414
  function handleProjectConfigInclude$1(appJson, outputDir) {
1554
1415
  const projectConfigPath = resolve$i(outputDir, 'project.config.json');
1555
1416
  if (!fs$f.existsSync(projectConfigPath)) return;
1556
-
1557
1417
  const projectConfig = require(projectConfigPath);
1558
-
1559
1418
  const hasMetaServices = hasMetaServicesSubpackage(appJson);
1560
1419
  if (!projectConfig.packOptions) projectConfig.packOptions = {};
1561
1420
  if (!projectConfig.packOptions.include) projectConfig.packOptions.include = [];
1562
1421
  const existingIndex = projectConfig.packOptions.include.findIndex(item => item.type === 'folder' && item.value === 'modules/meta-services');
1563
-
1564
1422
  if (hasMetaServices && existingIndex === -1) {
1565
1423
  projectConfig.packOptions.include.push({
1566
1424
  type: 'folder',
@@ -1571,23 +1429,18 @@ function handleProjectConfigInclude$1(appJson, outputDir) {
1571
1429
  projectConfig.packOptions.include.splice(existingIndex, 1);
1572
1430
  info$g('已从 project.config.json 移除 meta-services');
1573
1431
  }
1574
-
1575
1432
  fs$f.writeFileSync(projectConfigPath, JSON.stringify(projectConfig, null, 2));
1576
1433
  }
1577
-
1578
- var handleAgentConfig$2 = /*#__PURE__*/Object.freeze({
1579
- __proto__: null,
1580
- handleAgentConfig: handleAgentConfig$1,
1581
- handleProjectConfigInclude: handleProjectConfigInclude$1
1582
- });
1583
-
1584
- var require$$8 = /*@__PURE__*/getAugmentedNamespace(handleAgentConfig$2);
1434
+ var handleAgentConfig_1 = {
1435
+ handleAgentConfig: handleAgentConfig$1,
1436
+ handleProjectConfigInclude: handleProjectConfigInclude$1
1437
+ };
1585
1438
 
1586
1439
  /**
1587
1440
  * 生成编译后的app.json
1588
1441
  */
1589
- /* eslint-disable no-param-reassign */
1590
1442
 
1443
+ /* eslint-disable no-param-reassign */
1591
1444
  const fs$e = require$$0__default$1;
1592
1445
  const pp$1 = require$$1__default$3;
1593
1446
  const {
@@ -1612,42 +1465,38 @@ const report$9 = report_1;
1612
1465
  const {
1613
1466
  handleAgentConfig,
1614
1467
  handleProjectConfigInclude
1615
- } = require$$8;
1468
+ } = handleAgentConfig_1;
1469
+
1616
1470
  /**
1617
1471
  * 更新appJson里面的主包配置
1618
1472
  * @param { object } appJson appJson信息
1619
1473
  * @param { array } mainPackages 小程序主包信息
1620
1474
  * @returns { object } appJson小程序主页配置信息
1621
1475
  */
1622
-
1623
1476
  function updateMainPackages(appJson, mainPackages = []) {
1624
1477
  let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
1625
-
1626
1478
  if (foundMainPackages.length === 0 && appJson.pages.length === 0) {
1627
1479
  // 没找到主包
1628
1480
  foundMainPackages = [appJson.subpackages[0]];
1629
- } // 拼装 app.pages
1630
-
1631
-
1481
+ }
1482
+ // 拼装 app.pages
1632
1483
  foundMainPackages.forEach(subpackage => {
1633
1484
  if (!subpackage.allowNoPages && (!subpackage.pages || !subpackage.pages.length)) {
1634
1485
  fail$6(`主包 ${subpackage} 不能没有 pages`, foundMainPackages, subpackage);
1635
1486
  process.exit(-1);
1636
1487
  }
1637
-
1638
1488
  subpackage.pages.forEach(page => {
1639
1489
  const pagePath = `${subpackage.root}/${page}`;
1640
-
1641
1490
  if (!appJson.pages.includes(pagePath)) {
1642
1491
  appJson.pages.push(pagePath);
1643
1492
  }
1644
1493
  });
1645
-
1646
1494
  if (subpackage.plugins) {
1647
1495
  Object.assign(appJson.plugins, subpackage.plugins);
1648
1496
  }
1649
- }); // 去掉 subpackages 中的主包配置
1497
+ });
1650
1498
 
1499
+ // 去掉 subpackages 中的主包配置
1651
1500
  const foundMainPackageNames = foundMainPackages.map(item => item.name);
1652
1501
  appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
1653
1502
  return appJson;
@@ -1657,41 +1506,39 @@ function updateMainPackages(appJson, mainPackages = []) {
1657
1506
  * @param {string} sourceAppJsonPath app.json存在的源码路径
1658
1507
  * @returns
1659
1508
  */
1660
-
1661
-
1662
1509
  const getAppJsonContent = sourceAppJsonPath => {
1663
1510
  if (!fs$e.existsSync(sourceAppJsonPath)) {
1664
1511
  fail$6(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1665
1512
  process.exit(1);
1666
1513
  }
1667
-
1668
- const appJson = JSON.parse(fs$e.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1669
-
1514
+ const appJson = JSON.parse(fs$e.readFileSync(sourceAppJsonPath), 'utf-8');
1515
+ // 加入默认值
1670
1516
  appJson.subpackages = appJson.subpackages || [];
1671
1517
  appJson.pages = appJson.pages || [];
1672
1518
  return appJson;
1673
1519
  };
1520
+
1674
1521
  /**
1675
1522
  * 处理合并subpackages后的appjson, 整理重复不合法的地方
1676
1523
  * @param {Object} appJson appjson
1677
1524
  */
1678
-
1679
-
1680
1525
  const fixAppJson = appJson => {
1681
1526
  const {
1682
1527
  subpackages
1683
- } = appJson; // 创建插件映射,用于检测插件配置冲突
1684
-
1685
- const pluginsMap = {}; // 记录app.json顶层的插件配置
1686
-
1687
- Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']); // 处理每个分包的配置
1528
+ } = appJson;
1529
+ // 创建插件映射,用于检测插件配置冲突
1530
+ const pluginsMap = {};
1531
+ // 记录app.json顶层的插件配置
1532
+ Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
1688
1533
 
1534
+ // 处理每个分包的配置
1689
1535
  const subps = subpackages.map(subp => {
1690
1536
  // 需要从分包提取到app.json顶层的数组类型字段
1691
- const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList']; // 需要从分包提取到app.json顶层的对象类型字段
1692
-
1693
- const objOfFileType = ['preloadRule']; // 遍历分包中的每个配置项
1537
+ const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList'];
1538
+ // 需要从分包提取到app.json顶层的对象类型字段
1539
+ const objOfFileType = ['preloadRule'];
1694
1540
 
1541
+ // 遍历分包中的每个配置项
1695
1542
  Object.keys(subp).forEach(key => {
1696
1543
  // 处理插件配置,检查是否有重复配置的插件
1697
1544
  if (key === 'plugins') {
@@ -1699,15 +1546,15 @@ const fixAppJson = appJson => {
1699
1546
  // 记录每个插件被哪些地方配置
1700
1547
  pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
1701
1548
  });
1702
- } // 处理数组类型字段(如requiredBackgroundModes),合并到app.json顶层并去重
1703
-
1549
+ }
1704
1550
 
1551
+ // 处理数组类型字段(如requiredBackgroundModes),合并到app.json顶层并去重
1705
1552
  if (arrOfFileType.indexOf(key) > -1) {
1706
1553
  const preVal = appJson[key];
1707
1554
  preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
1708
- } // 处理对象类型字段(如preloadRule),合并到app.json顶层,已存在的键值不覆盖
1709
-
1555
+ }
1710
1556
 
1557
+ // 处理对象类型字段(如preloadRule),合并到app.json顶层,已存在的键值不覆盖
1711
1558
  if (objOfFileType.indexOf(key) > -1) {
1712
1559
  const preloadRuleMap = appJson[key] || {};
1713
1560
  subp[key] && Object.keys(subp[key]).forEach(page => {
@@ -1717,45 +1564,46 @@ const fixAppJson = appJson => {
1717
1564
  });
1718
1565
  appJson[key] = preloadRuleMap;
1719
1566
  }
1720
- }); // 从分包配置中移除已提取到顶层的字段以及一些构建相关的内部字段
1567
+ });
1721
1568
 
1569
+ // 从分包配置中移除已提取到顶层的字段以及一些构建相关的内部字段
1722
1570
  return filterField$7(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1723
- }); // 检查插件配置冲突,如果同一个插件在多处配置则报错
1571
+ });
1724
1572
 
1573
+ // 检查插件配置冲突,如果同一个插件在多处配置则报错
1725
1574
  const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
1726
1575
  if (pluginsMap[pk].length > 1) {
1727
1576
  return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
1728
1577
  }
1729
-
1730
1578
  return '';
1731
1579
  }).reduce((pre, cur) => pre + cur, '');
1732
-
1733
1580
  if (pluginsErrMsg) {
1734
1581
  throw new Error(`plugins配置出现错误:${pluginsErrMsg}`);
1735
- } // 用处理后的分包配置更新app.json的subpackages字段
1736
-
1582
+ }
1737
1583
 
1584
+ // 用处理后的分包配置更新app.json的subpackages字段
1738
1585
  appJson.subpackages = subps;
1739
1586
  };
1587
+
1740
1588
  /**
1741
1589
  * 合并分包配置,保留已有分包,添加新分包
1742
1590
  * @param {Array} existingPackages 现有的分包配置
1743
1591
  * @param {Array} newPackages 新的分包配置
1744
1592
  * @returns {Array} 合并后的分包配置
1745
1593
  */
1746
-
1747
-
1748
1594
  function mergeSubPackages(existingPackages, newPackages) {
1749
1595
  // 创建结果数组和root到索引的映射
1750
1596
  const resultPackages = [...existingPackages];
1751
- const rootMap = {}; // 建立现有分包的root映射
1597
+ const rootMap = {};
1752
1598
 
1599
+ // 建立现有分包的root映射
1753
1600
  existingPackages.forEach((pkg, index) => {
1754
1601
  if (pkg.root) {
1755
1602
  rootMap[pkg.root] = index;
1756
1603
  }
1757
- }); // 合并新分包
1604
+ });
1758
1605
 
1606
+ // 合并新分包
1759
1607
  newPackages.forEach(newPkg => {
1760
1608
  if (!newPkg.root) return; // 忽略没有root的分包
1761
1609
 
@@ -1769,45 +1617,44 @@ function mergeSubPackages(existingPackages, newPackages) {
1769
1617
  });
1770
1618
  return resultPackages;
1771
1619
  }
1620
+
1772
1621
  /**
1773
1622
  * 动态生成编译后的app.json
1774
1623
  * @param {object} tmsConfig
1775
1624
  * @param {array} modules 用户要编译的模块列表
1776
1625
  * @returns
1777
1626
  */
1778
-
1779
-
1780
1627
  async function buildOutputAppJson$3(tmsConfig, modules) {
1781
1628
  try {
1782
1629
  var _tmsConfig$hooks;
1783
-
1784
1630
  // 获取所有模块,合并模块依赖的模块
1785
- const modulesConfig = getModulesConfig(modules, tmsConfig, false); // 获取所有的分包
1786
-
1787
- const newSubPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
1788
-
1789
- let appJson = getAppJsonContent(resolve$h('./app.json')); // 保留已有分包配置,合并新的分包配置
1631
+ const modulesConfig = getModulesConfig(modules, tmsConfig, false);
1632
+ // 获取所有的分包
1633
+ const newSubPackages = getSubPackages$3(modulesConfig);
1634
+ // 获取app.json的配置
1635
+ let appJson = getAppJsonContent(resolve$h('./app.json'));
1790
1636
 
1637
+ // 保留已有分包配置,合并新的分包配置
1791
1638
  const existingSubpackages = appJson.subpackages || [];
1792
1639
  appJson.subpackages = mergeSubPackages(existingSubpackages, newSubPackages);
1793
- appJson.subpackages.sort((item1, item2) => item1.root.localeCompare(item2.root)); // 处理appJson中重复||冲突的地方
1794
-
1795
- fixAppJson(appJson); // 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除
1796
-
1797
- handleAgentConfig(appJson); // 处理 project.config.json 中的 packOptions.include 配置
1798
-
1799
- handleProjectConfigInclude(appJson, tmsConfig.outputDir); // 更新主包,需在subpackages处理完成后执行, pages/
1800
-
1801
- updateMainPackages(appJson, tmsConfig.mainPackages); // 模板渲染:先将 app.json 转为字符串,然后通过 preprocess 渲染
1802
-
1640
+ appJson.subpackages.sort((item1, item2) => item1.root.localeCompare(item2.root));
1641
+
1642
+ // 处理appJson中重复||冲突的地方
1643
+ fixAppJson(appJson);
1644
+ // 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除
1645
+ handleAgentConfig(appJson);
1646
+ // 处理 project.config.json 中的 packOptions.include 配置
1647
+ handleProjectConfigInclude(appJson, tmsConfig.outputDir);
1648
+ // 更新主包,需在subpackages处理完成后执行, pages/
1649
+ updateMainPackages(appJson, tmsConfig.mainPackages);
1650
+
1651
+ // 模板渲染:先将 app.json 转为字符串,然后通过 preprocess 渲染
1803
1652
  const appJsonStr = JSON.stringify(appJson, null, 2);
1804
1653
  const preprocessedStr = pp$1.preprocess(appJsonStr, tmsConfig.templateVars || {}, 'json');
1805
1654
  fs$e.writeFileSync(resolve$h(`${tmsConfig.outputDir}/app.json`), preprocessedStr, 'utf8');
1806
1655
  appJson = JSON.parse(preprocessedStr);
1807
-
1808
1656
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
1809
1657
  var _tmsConfig$hooks2;
1810
-
1811
1658
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
1812
1659
  tmsConfig: filterField$7(tmsConfig, ['gitAccount']),
1813
1660
  cmdOptions: global$a.getData('cmdOptions'),
@@ -1817,14 +1664,12 @@ async function buildOutputAppJson$3(tmsConfig, modules) {
1817
1664
  }));
1818
1665
  report$9('hooks:updateAppJson');
1819
1666
  }
1820
-
1821
1667
  return appJson;
1822
1668
  } catch (e) {
1823
1669
  handleError$8(`生成app.json出现错误: ${e}`);
1824
1670
  info$f(e);
1825
1671
  }
1826
1672
  }
1827
-
1828
1673
  var buildAppJson = {
1829
1674
  buildOutputAppJson: buildOutputAppJson$3
1830
1675
  };
@@ -1851,16 +1696,15 @@ const {
1851
1696
  const {
1852
1697
  global: global$9
1853
1698
  } = global_1;
1699
+
1854
1700
  /**
1855
1701
  * 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
1856
1702
  * @param {*} httpRepoUrl
1857
1703
  * @param {*} moduleName
1858
1704
  * @returns
1859
1705
  */
1860
-
1861
1706
  function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1862
1707
  var _tmsConfig$gitAccount, _tmsConfig$gitAccount2, _tmsConfig$gitAccount3;
1863
-
1864
1708
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1865
1709
  const tmsConfig = global$9.getData('tmsConfig');
1866
1710
  let gitUrl = httpRepoUrl;
@@ -1871,13 +1715,12 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1871
1715
  pass = ''
1872
1716
  } = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount2 = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount2 === void 0 ? void 0 : _tmsConfig$gitAccount2[httpRepoUrl]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount3 = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount3 === void 0 ? void 0 : _tmsConfig$gitAccount3[group]) || {};
1873
1717
  const urlPrefixReg = /http(s)?:\/\//;
1874
-
1875
1718
  if (username && pass && urlPrefixReg.test(gitUrl)) {
1876
1719
  gitUrl = gitUrl.replace(urlPrefixReg, val => `${val}${encodeURIComponent(username)}:${encodeURIComponent(pass)}@`);
1877
1720
  }
1878
-
1879
1721
  return gitUrl;
1880
1722
  }
1723
+
1881
1724
  /**
1882
1725
  * 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
1883
1726
  * @param { string } sourceDir 缓存文件夹
@@ -1885,33 +1728,28 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1885
1728
  * @param { arrary } ignore
1886
1729
  * @returns { undefined } no return
1887
1730
  */
1888
-
1889
-
1890
1731
  function moveFile(sourceDir, targetDir, ignore = []) {
1891
1732
  if (fs$d.existsSync(targetDir)) {
1892
1733
  shelljs$5.rm('-rf', targetDir);
1893
- } // 删除不是文件夹的文件
1894
-
1895
-
1734
+ }
1735
+ // 删除不是文件夹的文件
1896
1736
  return new Promise((resolve, reject) => {
1897
1737
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1898
1738
  if (e) {
1899
1739
  fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1900
1740
  reject(e);
1901
1741
  }
1902
-
1903
1742
  resolve();
1904
1743
  });
1905
1744
  });
1906
1745
  }
1746
+
1907
1747
  /**
1908
1748
  * 根据gitUrl 和 branch取md5值
1909
1749
  * @param {*} gitUrl
1910
1750
  * @param {*} branch
1911
1751
  * @returns
1912
1752
  */
1913
-
1914
-
1915
1753
  function md5ByGitUrlBranch(gitUrl, branch) {
1916
1754
  const newBranch = branch && typeof branch === 'string' ? branch : 'master';
1917
1755
  return crypto$2.createHash('md5').update(JSON.stringify({
@@ -1919,19 +1757,19 @@ function md5ByGitUrlBranch(gitUrl, branch) {
1919
1757
  branch: newBranch
1920
1758
  })).digest('hex');
1921
1759
  }
1760
+
1922
1761
  /**
1923
1762
  * 下载目标模块
1924
1763
  * @param { string } sourceDir 缓存文件夹
1925
1764
  * @param { string } targetDir 目标文件夹
1926
1765
  * @returns { array } modules 描述模块的列表
1927
1766
  */
1928
-
1929
-
1930
1767
  async function cloneModules$1(sourceDir, targetDir, modules) {
1931
- const cwd = process.cwd(); // 收集下载模块代码的任务
1932
-
1933
- const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules); // 开始执行下载和移动代码的任务
1768
+ const cwd = process.cwd();
1769
+ // 收集下载模块代码的任务
1770
+ const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules);
1934
1771
 
1772
+ // 开始执行下载和移动代码的任务
1935
1773
  const arrPromises = [];
1936
1774
  downloadTasksMap.forEach(({
1937
1775
  promiseTask,
@@ -1951,14 +1789,13 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1951
1789
  await Promise.all(arrPromises);
1952
1790
  shelljs$5.cd(cwd);
1953
1791
  }
1792
+
1954
1793
  /**
1955
1794
  * 收集下载模块代码的任务
1956
1795
  * @param { string } sourceDir 代码缓存文件夹
1957
1796
  * @param { string } targetDir 代码要放到的目标文件夹
1958
1797
  * @returns { array } modules 描述模块的列表
1959
1798
  */
1960
-
1961
-
1962
1799
  function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1963
1800
  // 下载代码任务 Map (key解释 缓存代码路径/md5(gitUrl,branch)
1964
1801
  // {
@@ -1973,7 +1810,6 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1973
1810
  // }
1974
1811
  // }
1975
1812
  const downloadTasksMap = new Map();
1976
-
1977
1813
  for (const moduleInfo of modules) {
1978
1814
  if (moduleInfo.repoInfo) {
1979
1815
  const {
@@ -1984,18 +1820,20 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1984
1820
  },
1985
1821
  path,
1986
1822
  moduleName
1987
- } = moduleInfo; // 处理仓库权限问题
1988
-
1989
- const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName); // 根据gitUrl与branch计算md5
1990
-
1991
- const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1992
-
1993
- const sourcePath = resolve$g(sourceDir, md5Key); // 模块源码要放到目标目录
1994
-
1995
- const targetPath = resolve$g(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1996
-
1997
- const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1998
-
1823
+ } = moduleInfo;
1824
+
1825
+ // 处理仓库权限问题
1826
+ const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
1827
+ // 根据gitUrlbranch计算md5
1828
+ const md5Key = md5ByGitUrlBranch(gitUrl, branch);
1829
+ // git源码临时存在的源目录
1830
+ const sourcePath = resolve$g(sourceDir, md5Key);
1831
+ // 模块源码要放到目标目录
1832
+ const targetPath = resolve$g(targetDir, path);
1833
+ // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1834
+ const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath;
1835
+
1836
+ // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1999
1837
  const callback = {
2000
1838
  params: {
2001
1839
  sourceModulePath,
@@ -2005,18 +1843,15 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
2005
1843
  if (fs$d.existsSync(targetPath)) {
2006
1844
  shelljs$5.rm('-rf', `${targetPath}/*`);
2007
1845
  }
2008
-
2009
1846
  await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
2010
1847
  }
2011
1848
  };
2012
-
2013
1849
  if (downloadTasksMap.has(sourcePath)) {
2014
1850
  const task = downloadTasksMap.get(sourcePath);
2015
1851
  task.callbacks.push(callback);
2016
1852
  downloadTasksMap.set(sourcePath, task);
2017
1853
  } else {
2018
1854
  let promiseTask;
2019
-
2020
1855
  if (fs$d.existsSync(sourcePath) && fs$d.existsSync(`${sourcePath}/.git`)) {
2021
1856
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
2022
1857
  info$e(`git pull:${httpRepoUrl} --branch: ${branch}`);
@@ -2031,7 +1866,6 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
2031
1866
  return downloadRepoForGit(gitUrl, sourcePath, branch);
2032
1867
  };
2033
1868
  }
2034
-
2035
1869
  downloadTasksMap.set(sourcePath, {
2036
1870
  promiseTask,
2037
1871
  params: {
@@ -2045,17 +1879,15 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
2045
1879
  }
2046
1880
  }
2047
1881
  }
2048
-
2049
1882
  return downloadTasksMap;
2050
1883
  }
1884
+
2051
1885
  /**
2052
1886
  * 检查远程模块的gitUrl与 branch是否有更新
2053
1887
  * @param {string} sourceDir 模块源码在缓存区的目录
2054
1888
  * @param {object} moduleInfo 模块的配置信息
2055
1889
  * @returns
2056
1890
  */
2057
-
2058
-
2059
1891
  function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
2060
1892
  if (moduleInfo.repoInfo) {
2061
1893
  const {
@@ -2067,15 +1899,12 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
2067
1899
  } = moduleInfo;
2068
1900
  const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
2069
1901
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
2070
-
2071
1902
  if (!fs$d.existsSync(`${sourceDir}/${md5Key}`)) {
2072
1903
  return true;
2073
1904
  }
2074
1905
  }
2075
-
2076
1906
  return false;
2077
1907
  }
2078
-
2079
1908
  var cloneModules_1 = {
2080
1909
  cloneModules: cloneModules$1,
2081
1910
  checkRemoteModGitUrlBranch
@@ -2083,11 +1912,11 @@ var cloneModules_1 = {
2083
1912
 
2084
1913
  const ci = require$$0__default$7;
2085
1914
  const path$c = require$$1__default$1;
1915
+
2086
1916
  /**
2087
1917
  * 获取小程序ci的Project对象
2088
1918
  * @returns {Object} 小程序ci对象
2089
1919
  */
2090
-
2091
1920
  const getMpCi = ({
2092
1921
  appId,
2093
1922
  projectPath,
@@ -2095,9 +1924,7 @@ const getMpCi = ({
2095
1924
  privateKey = 'TODO'
2096
1925
  }) => {
2097
1926
  var _projectCg$packOption, _projectCg$packOption2;
2098
-
2099
1927
  const projectCg = require(path$c.join(projectPath, 'project.config.json'));
2100
-
2101
1928
  const ignores = (projectCg === null || projectCg === void 0 ? void 0 : (_projectCg$packOption = projectCg.packOptions) === null || _projectCg$packOption === void 0 ? void 0 : (_projectCg$packOption2 = _projectCg$packOption.ignore) === null || _projectCg$packOption2 === void 0 ? void 0 : _projectCg$packOption2.map(({
2102
1929
  value
2103
1930
  }) => value)) || [];
@@ -2109,22 +1936,21 @@ const getMpCi = ({
2109
1936
  ignores: ['node_modules/**/*', 'cloud/**/*', ...ignores]
2110
1937
  });
2111
1938
  };
1939
+
2112
1940
  /**
2113
1941
  * 格式化构建npm结果信息
2114
1942
  * @param {Array<String>} warning 构建时的告警信息
2115
1943
  * @returns {String} npm构建错误信息
2116
1944
  */
2117
-
2118
-
2119
1945
  const formatPackNpmWarning = warning => {
2120
1946
  if (!warning) {
2121
1947
  return '';
2122
1948
  }
2123
-
2124
1949
  const result = warning.map((it, index) => `${index + 1}. ${it.msg}
2125
1950
  \t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
2126
1951
  return result;
2127
1952
  };
1953
+
2128
1954
  /**
2129
1955
  * 构建miniprogram_npm https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E6%9E%84%E5%BB%BAnpm
2130
1956
  * * @param {object} {
@@ -2133,8 +1959,6 @@ const formatPackNpmWarning = warning => {
2133
1959
  * privateKey,
2134
1960
  * }
2135
1961
  */
2136
-
2137
-
2138
1962
  const buildMpNpm$1 = async ({
2139
1963
  appId,
2140
1964
  projectPath,
@@ -2149,13 +1973,12 @@ const buildMpNpm$1 = async ({
2149
1973
  ignores: ['cloud/**/*']
2150
1974
  });
2151
1975
  const packNpmMsg = formatPackNpmWarning(packNpmWarning);
2152
-
2153
1976
  if (packNpmMsg) {
2154
1977
  return Promise.reject(packNpmMsg);
2155
1978
  }
2156
-
2157
1979
  return Promise.resolve();
2158
1980
  };
1981
+
2159
1982
  /**
2160
1983
  * 预览小程序码 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88
2161
1984
  * @param {object} {
@@ -2166,8 +1989,6 @@ const buildMpNpm$1 = async ({
2166
1989
  * robot
2167
1990
  * }
2168
1991
  */
2169
-
2170
-
2171
1992
  const previewMp = async (params = {}) => {
2172
1993
  const {
2173
1994
  appId,
@@ -2186,6 +2007,7 @@ const previewMp = async (params = {}) => {
2186
2007
  onProgressUpdate: () => {}
2187
2008
  });
2188
2009
  };
2010
+
2189
2011
  /**
2190
2012
  * 上传小程序 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E4%B8%8A%E4%BC%A0
2191
2013
  * @param {object} {
@@ -2196,8 +2018,6 @@ const previewMp = async (params = {}) => {
2196
2018
  * desc
2197
2019
  * }
2198
2020
  */
2199
-
2200
-
2201
2021
  const uploadMp = async (params = {}) => {
2202
2022
  const {
2203
2023
  appId,
@@ -2216,7 +2036,6 @@ const uploadMp = async (params = {}) => {
2216
2036
  onProgressUpdate: () => {}
2217
2037
  });
2218
2038
  };
2219
-
2220
2039
  const getDevSourceMap = async (params = {}) => {
2221
2040
  const {
2222
2041
  appId,
@@ -2236,7 +2055,6 @@ const getDevSourceMap = async (params = {}) => {
2236
2055
  sourceMapSavePath
2237
2056
  });
2238
2057
  };
2239
-
2240
2058
  var mpCi$3 = {
2241
2059
  buildMpNpm: buildMpNpm$1,
2242
2060
  previewMp,
@@ -2252,42 +2070,31 @@ const {
2252
2070
  const {
2253
2071
  ensureDirExist: ensureDirExist$4
2254
2072
  } = io$3;
2255
-
2256
2073
  function getCache$1(projectDir, type) {
2257
2074
  var _content$projectDir;
2258
-
2259
2075
  const filePath = NPM_CACHE_FILE;
2260
-
2261
2076
  if (!fs$c.existsSync(filePath)) {
2262
2077
  return null;
2263
2078
  }
2264
-
2265
2079
  const content = require(filePath);
2266
-
2267
2080
  return content === null || content === void 0 ? void 0 : (_content$projectDir = content[projectDir]) === null || _content$projectDir === void 0 ? void 0 : _content$projectDir[type];
2268
2081
  }
2269
-
2270
2082
  function setCache$1(projectDir, type = 'miniprogram_npm', data) {
2271
2083
  const filePath = NPM_CACHE_FILE;
2272
-
2273
2084
  if (!fs$c.existsSync(filePath)) {
2274
2085
  const dir = path$b.dirname(filePath);
2275
2086
  ensureDirExist$4(dir);
2276
2087
  fs$c.writeFileSync(filePath, '{}');
2277
2088
  }
2278
-
2279
2089
  const content = require(filePath);
2280
-
2281
2090
  if (!content[projectDir]) {
2282
2091
  content[projectDir] = {};
2283
2092
  }
2284
-
2285
2093
  content[projectDir] = {
2286
2094
  [type]: data
2287
2095
  };
2288
2096
  fs$c.writeFileSync(filePath, JSON.stringify(content, null, 2));
2289
2097
  }
2290
-
2291
2098
  var cache = {
2292
2099
  setCache: setCache$1,
2293
2100
  getCache: getCache$1
@@ -2331,26 +2138,23 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2331
2138
  // }
2332
2139
  // }
2333
2140
  const npmTasksMap = new Map();
2334
-
2335
2141
  for (const packageJsonPath of packageJsonFiles) {
2336
2142
  const packageContent = fs$b.readFileSync(packageJsonPath);
2337
2143
  let packageJson;
2338
-
2339
2144
  try {
2340
2145
  packageJson = JSON.parse(packageContent);
2341
2146
  } catch (e) {
2342
2147
  throw new Error(`${packageJsonPath}json解析出现错误:${e}`);
2343
2148
  }
2344
-
2345
2149
  const md5Obj = {
2346
2150
  dependencies: packageJson.dependencies || {}
2347
2151
  };
2348
-
2349
2152
  if (Object.keys(md5Obj.dependencies).length !== 0) {
2350
2153
  const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
2351
2154
  const cacheNMPath = path$a.join(cacheDir, md5Key);
2352
- const cacheNMTarFile = path$a.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
2155
+ const cacheNMTarFile = path$a.join(cacheNMPath, 'node_modules.tar.gz');
2353
2156
 
2157
+ // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
2354
2158
  const callback = {
2355
2159
  params: {
2356
2160
  cacheNMPath,
@@ -2361,7 +2165,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2361
2165
  fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
2362
2166
  shell.cd(cacheNMPath);
2363
2167
  shell.cp('-Rf', cacheNMTarFile, `${packageJsonDir}/`);
2364
- const newShellJsOption = { ...shellJsOption,
2168
+ const newShellJsOption = {
2169
+ ...shellJsOption,
2365
2170
  cwd: packageJsonDir
2366
2171
  };
2367
2172
  shell.cd(packageJsonDir);
@@ -2369,16 +2174,13 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2369
2174
  shell.rm('-rf', './node_modules.tar.gz');
2370
2175
  }
2371
2176
  };
2372
-
2373
2177
  if (npmTasksMap.has(cacheNMPath)) {
2374
2178
  const task = npmTasksMap.get(cacheNMPath);
2375
2179
  task.callbacks.push(callback);
2376
2180
  npmTasksMap.set(cacheNMPath, task);
2377
2181
  } else {
2378
2182
  const missCache = !fsExtra.pathExistsSync(cacheNMPath) || !fsExtra.existsSync(cacheNMTarFile) || fsExtra.statSync(cacheNMTarFile).size < 512;
2379
-
2380
2183
  let promiseTask = () => Promise.resolve();
2381
-
2382
2184
  if (missCache) {
2383
2185
  promiseTask = (packageJsonPath, cacheNMPath, shell) => {
2384
2186
  fsExtra.emptydirSync(cacheNMPath);
@@ -2386,7 +2188,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2386
2188
  log.info(`npm install: ${packageJsonPath}`);
2387
2189
  const tmsConfig = global$8.getData('tmsConfig');
2388
2190
  return npmInstall$2(cacheNMPath, tmsConfig.npm).then(() => {
2389
- const newShellJsOption = { ...shellJsOption,
2191
+ const newShellJsOption = {
2192
+ ...shellJsOption,
2390
2193
  cwd: cacheNMPath
2391
2194
  };
2392
2195
  shell.cd(cacheNMPath);
@@ -2395,7 +2198,6 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2395
2198
  });
2396
2199
  };
2397
2200
  }
2398
-
2399
2201
  npmTasksMap.set(cacheNMPath, {
2400
2202
  promiseTask,
2401
2203
  params: {
@@ -2408,17 +2210,18 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2408
2210
  }
2409
2211
  }
2410
2212
  }
2411
-
2412
2213
  return npmTasksMap;
2413
- }; // 遍历安装指定目录下所有项目的npm依赖
2414
-
2214
+ };
2415
2215
 
2216
+ // 遍历安装指定目录下所有项目的npm依赖
2416
2217
  const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
2417
2218
  const cwd = process.cwd();
2418
- const packageJsonFiles = await findAllPackageJson(subPackages, contextDir); // 收集npm install的任务
2219
+ const packageJsonFiles = await findAllPackageJson(subPackages, contextDir);
2419
2220
 
2420
- const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir); // 开始执行npm install和回调(移动)的任务
2221
+ // 收集npm install的任务
2222
+ const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir);
2421
2223
 
2224
+ // 开始执行npm install和回调(移动)的任务
2422
2225
  const arrPromises = [];
2423
2226
  npmTasksMap.forEach(({
2424
2227
  promiseTask,
@@ -2439,14 +2242,13 @@ const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
2439
2242
  shell.cd(cwd);
2440
2243
  return packageJsonFiles;
2441
2244
  };
2245
+
2442
2246
  /**
2443
2247
  * 递归查找指定条件的文件
2444
2248
  * @param {String} startPath 开始查找的根路径
2445
2249
  * @param {String} filter 匹配的字符串
2446
2250
  * @returns {Array<String>} 查找到的文件路径列表
2447
2251
  */
2448
-
2449
-
2450
2252
  const findFilesByFilter = (startPath, filter) => {
2451
2253
  const result = [];
2452
2254
  /**
@@ -2455,27 +2257,24 @@ const findFilesByFilter = (startPath, filter) => {
2455
2257
  * @param {String} filter 筛选器
2456
2258
  * @returns {Undefined} 无需返回值
2457
2259
  */
2458
-
2459
2260
  const find = (startPath, filter) => {
2460
2261
  // 目录不存在
2461
2262
  if (!fs$b.existsSync(startPath)) {
2462
2263
  log.fail(`${startPath}目录不存在`);
2463
2264
  process.exit(-1);
2464
2265
  return;
2465
- } // 当前目录下的所有文件 / 文件夹
2466
-
2266
+ }
2467
2267
 
2268
+ // 当前目录下的所有文件 / 文件夹
2468
2269
  const exceptDir = ['node_modules', 'miniprogram_npm'];
2469
-
2470
2270
  if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
2471
2271
  return;
2472
2272
  }
2473
-
2474
2273
  const files = fs$b.readdirSync(startPath);
2475
2274
  files.forEach(file => {
2476
2275
  const filename = path$a.join(startPath, file);
2477
- const stat = fs$b.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2478
-
2276
+ const stat = fs$b.lstatSync(filename);
2277
+ // 当前文件是文件夹类型,继续递归
2479
2278
  if (stat.isDirectory()) {
2480
2279
  find(filename, filter);
2481
2280
  } else if (filename.indexOf(filter) >= 0) {
@@ -2484,33 +2283,28 @@ const findFilesByFilter = (startPath, filter) => {
2484
2283
  }
2485
2284
  });
2486
2285
  };
2487
-
2488
2286
  find(startPath, filter);
2489
2287
  return result;
2490
2288
  };
2289
+
2491
2290
  /**
2492
2291
  * 找到项目中所有的package.json文件
2493
2292
  * @param {Array<String>} subRoots 需要安装npm依赖的路径
2494
2293
  * @param {String} contextDir 命令运行的目录
2495
2294
  * @returns {Array<String>} 找到的所有package.json文件的路径
2496
2295
  */
2497
-
2498
-
2499
2296
  const findAllPackageJson = (subRoots = [], contextDir) => {
2500
2297
  const packageJsonName = 'package.json'; // 查找文件名
2501
-
2502
2298
  const cwd = contextDir || dirPath;
2503
2299
  const result = [path$a.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
2504
2300
 
2505
2301
  subRoots.forEach(subRoot => {
2506
2302
  const toppath = path$a.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
2507
-
2508
2303
  const list = findFilesByFilter(toppath, packageJsonName);
2509
2304
  result.push(...list);
2510
2305
  });
2511
2306
  return result;
2512
2307
  };
2513
-
2514
2308
  var npm = {
2515
2309
  npmInstallAll: npmInstallAll$1,
2516
2310
  findAllPackageJson,
@@ -2519,7 +2313,6 @@ var npm = {
2519
2313
 
2520
2314
  const crypto = require$$1__default$6;
2521
2315
  const fs$a = require$$0__default$1;
2522
-
2523
2316
  function fileMd5$1(filePath) {
2524
2317
  return new Promise((resolve, reject) => {
2525
2318
  const md5sum = crypto.createHash('md5');
@@ -2536,7 +2329,6 @@ function fileMd5$1(filePath) {
2536
2329
  });
2537
2330
  });
2538
2331
  }
2539
-
2540
2332
  var md5 = {
2541
2333
  fileMd5: fileMd5$1
2542
2334
  };
@@ -2552,30 +2344,25 @@ const shelljs$4 = require$$0__default$2;
2552
2344
  const {
2553
2345
  handleError: handleError$5
2554
2346
  } = handleError_1;
2555
-
2556
2347
  const getLatestVersion = npmName => {
2557
2348
  const data = shelljs$4.exec(`npm view ${npmName} version`);
2558
-
2559
2349
  if (data.code === 0) {
2560
2350
  return data.stdout;
2561
2351
  }
2562
-
2563
2352
  return '0.0.0';
2564
- }; // 收集package.json
2565
-
2353
+ };
2566
2354
 
2355
+ // 收集package.json
2567
2356
  function collectPackageJson(subPackages, cwd, outputDir) {
2568
2357
  const packageJsonName = 'package.json'; // 查找文件名
2569
2358
  // 1.1根目录的package.json
2570
-
2571
2359
  const packageArr = [{
2572
2360
  srcPackageDir: path$9.join(cwd, packageJsonName),
2573
2361
  destNpmDir: resolve$f(outputDir, 'node_modules')
2574
- }]; // 1.2模块的package.json
2575
-
2362
+ }];
2363
+ // 1.2模块的package.json
2576
2364
  subPackages.forEach(item => {
2577
2365
  const srcPackageDir = `${getAbsolutePath$5(item.path)}/package.json`;
2578
-
2579
2366
  if (fs$9.existsSync(srcPackageDir)) {
2580
2367
  packageArr.push({
2581
2368
  srcPackageDir,
@@ -2584,22 +2371,21 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2584
2371
  }
2585
2372
  });
2586
2373
  return packageArr;
2587
- } // 读取package.json的依赖
2588
-
2374
+ }
2589
2375
 
2376
+ // 读取package.json的依赖
2590
2377
  function readPackageDependencies(srcPackageDir) {
2591
2378
  const packageJson = fs$9.readFileSync(srcPackageDir, 'utf-8');
2592
2379
  let dependencies = {};
2593
-
2594
2380
  try {
2595
2381
  const json = packageJson ? JSON.parse(packageJson) : {};
2596
2382
  dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
2597
2383
  } catch (e) {
2598
2384
  handleError$5(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2599
2385
  }
2600
-
2601
2386
  return dependencies;
2602
2387
  }
2388
+
2603
2389
  /**
2604
2390
  * 检查package.json的依赖大于node_module的版本,则返回true
2605
2391
  * @param {*} subPackages 模块
@@ -2607,51 +2393,40 @@ function readPackageDependencies(srcPackageDir) {
2607
2393
  * @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
2608
2394
  * @returns
2609
2395
  */
2610
-
2611
-
2612
2396
  const isDependenciesUpdate$1 = (subPackages, cwd, outputDir) => {
2613
2397
  // 步骤1. 收集package.json
2614
- const packageArr = collectPackageJson(subPackages, cwd, outputDir); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
2615
-
2398
+ const packageArr = collectPackageJson(subPackages, cwd, outputDir);
2399
+ // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
2616
2400
  return checkPackageVersion$1(packageArr);
2617
- }; // 比较package.json的依赖与node_modules依赖的版本号
2618
-
2401
+ };
2619
2402
 
2403
+ // 比较package.json的依赖与node_modules依赖的版本号
2620
2404
  const checkPackageVersion$1 = packageArr => {
2621
2405
  for (const item of packageArr) {
2622
2406
  const dependencies = readPackageDependencies(item.srcPackageDir);
2623
2407
  const dependenciesKeys = Object.keys(dependencies);
2624
-
2625
2408
  for (const key of dependenciesKeys) {
2626
2409
  const depPath = path$9.join(item.destNpmDir, key);
2627
-
2628
2410
  if (!fs$9.existsSync(depPath)) {
2629
2411
  return true;
2630
2412
  }
2631
-
2632
2413
  const depPackagePath = path$9.join(depPath, 'package.json');
2633
-
2634
2414
  if (fs$9.existsSync(depPackagePath)) {
2635
2415
  const packageData = require(depPackagePath);
2636
-
2637
2416
  if (dependencies[key] === 'latest') {
2638
2417
  dependencies[key] = getLatestVersion(key);
2639
2418
  }
2640
-
2641
2419
  if (packageData.version === 'latest') {
2642
2420
  packageData.version = getLatestVersion(key);
2643
2421
  }
2644
-
2645
2422
  if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
2646
2423
  return true;
2647
2424
  }
2648
2425
  }
2649
2426
  }
2650
2427
  }
2651
-
2652
2428
  return false;
2653
2429
  };
2654
-
2655
2430
  var checkDependencies = {
2656
2431
  isDependenciesUpdate: isDependenciesUpdate$1,
2657
2432
  checkPackageVersion: checkPackageVersion$1
@@ -2692,15 +2467,12 @@ const {
2692
2467
  const {
2693
2468
  isDependenciesUpdate
2694
2469
  } = checkDependencies;
2695
-
2696
2470
  async function install$3(tmsConfig, subPackages, useCache = true) {
2697
2471
  var _tmsConfig$hooks;
2698
-
2699
- const cwd = process.cwd(); // 加npm install之前的钩子
2700
-
2472
+ const cwd = process.cwd();
2473
+ // 加npm install之前的钩子
2701
2474
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeNpmInstall) === 'function') {
2702
2475
  var _tmsConfig$hooks2;
2703
-
2704
2476
  info$d('—————— 执行beforeNpmInstall ————');
2705
2477
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeNpmInstall({
2706
2478
  tmsConfig: filterField$6(tmsConfig, ['gitAccount']),
@@ -2708,8 +2480,9 @@ async function install$3(tmsConfig, subPackages, useCache = true) {
2708
2480
  }));
2709
2481
  info$d('—————— 执行beforeNpmInstall 完成 ————');
2710
2482
  }
2711
- const npmInstallRes = await createTask$5(npmInstall$1, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2483
+ const npmInstallRes = await createTask$5(npmInstall$1, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache);
2712
2484
 
2485
+ // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2713
2486
  if (!npmInstallRes.isCache) {
2714
2487
  // 构建miniprogram_npm, 不使用缓存
2715
2488
  await createTask$5(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
@@ -2717,10 +2490,8 @@ async function install$3(tmsConfig, subPackages, useCache = true) {
2717
2490
  // 构建miniprogram_npm
2718
2491
  await createTask$5(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2719
2492
  }
2720
-
2721
2493
  shelljs$3.cd(cwd);
2722
2494
  }
2723
-
2724
2495
  async function npmInstall$1(tmsConfig, subPackages, useCache) {
2725
2496
  // 如果依赖没有更新和使用缓存数据(则命中缓存)
2726
2497
  if (!isDependenciesUpdate(subPackages, resolve$e('./'), tmsConfig.outputDir) && useCache) {
@@ -2728,9 +2499,8 @@ async function npmInstall$1(tmsConfig, subPackages, useCache) {
2728
2499
  return {
2729
2500
  isCache: true
2730
2501
  };
2731
- } // 拷贝模块的package.json到编译输出目录
2732
-
2733
-
2502
+ }
2503
+ // 拷贝模块的package.json到编译输出目录
2734
2504
  subPackages.forEach(item => {
2735
2505
  const outputModuleDir = resolve$e(`${tmsConfig.outputDir}/${item.root}`);
2736
2506
  io$1.ensureDirExist(outputModuleDir);
@@ -2741,20 +2511,17 @@ async function npmInstall$1(tmsConfig, subPackages, useCache) {
2741
2511
  return {
2742
2512
  isCache: false
2743
2513
  };
2744
- } // 构建miniprogram_npm
2745
-
2514
+ }
2746
2515
 
2516
+ // 构建miniprogram_npm
2747
2517
  async function mpCiInstall(tmsConfig, subPackages, useCache) {
2748
2518
  const packageJsonFiles = [];
2749
2519
  const rootPackFile = resolve$e(`${tmsConfig.outputDir}/package.json`);
2750
-
2751
2520
  if (fs$8.existsSync(rootPackFile)) {
2752
2521
  packageJsonFiles.push(rootPackFile);
2753
2522
  }
2754
-
2755
2523
  subPackages.forEach(item => {
2756
2524
  const packageJsonFile = resolve$e(`${tmsConfig.outputDir}/${item.root}/package.json`);
2757
-
2758
2525
  if (fs$8.existsSync(packageJsonFile)) {
2759
2526
  packageJsonFiles.push(packageJsonFile);
2760
2527
  }
@@ -2764,29 +2531,27 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2764
2531
  success: 1,
2765
2532
  doing: 2
2766
2533
  };
2767
-
2768
2534
  if (useCache) {
2769
2535
  let flag = true;
2770
2536
  await Promise.all(packageJsonFiles.map(async item => {
2771
2537
  const packageDir = path$8.dirname(item);
2772
2538
  const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
2773
2539
  const md5Value = await getMNPMd5(packageDir);
2774
- const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
2540
+ const preCache = getCache(mpDir, 'miniprogram_npm');
2541
+ // console.log('miniprogram_npm', preCache, md5Value);
2775
2542
  // 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
2776
-
2777
2543
  if ((preCache === null || preCache === void 0 ? void 0 : preCache.status) !== statusMap.success || (preCache === null || preCache === void 0 ? void 0 : preCache.md5) !== md5Value) {
2778
2544
  flag = false;
2779
2545
  }
2780
2546
  }));
2781
2547
  isCache = flag;
2782
2548
  }
2783
-
2784
2549
  if (isCache) {
2785
2550
  info$d('miniprogram_npm命中缓存');
2786
2551
  return;
2787
- } // 即将构建,在cache中标记开始
2788
-
2552
+ }
2789
2553
 
2554
+ // 即将构建,在cache中标记开始
2790
2555
  await Promise.all(packageJsonFiles.map(async item => {
2791
2556
  const packageDir = path$8.dirname(item);
2792
2557
  const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
@@ -2799,8 +2564,9 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2799
2564
  appId: tmsConfig.appId,
2800
2565
  projectPath: resolve$e('./'),
2801
2566
  privateKey: tmsConfig.privateKey
2802
- }); // 构建成功后,计算md5写入cache
2567
+ });
2803
2568
 
2569
+ // 构建成功后,计算md5写入cache
2804
2570
  await Promise.all(packageJsonFiles.map(async item => {
2805
2571
  const packageDir = path$8.dirname(item);
2806
2572
  const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
@@ -2810,16 +2576,15 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2810
2576
  status: statusMap.success
2811
2577
  });
2812
2578
  }));
2813
- } // 计算miniprogram_npm压缩文件的md5值
2814
-
2579
+ }
2815
2580
 
2581
+ // 计算miniprogram_npm压缩文件的md5值
2816
2582
  async function getMNPMd5(cwd) {
2817
2583
  const shellJsOption = {
2818
2584
  async: false,
2819
2585
  silent: true
2820
2586
  };
2821
2587
  shelljs$3.cd(cwd);
2822
-
2823
2588
  if (fs$8.existsSync('miniprogram_npm')) {
2824
2589
  shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2825
2590
  cwd,
@@ -2830,10 +2595,8 @@ async function getMNPMd5(cwd) {
2830
2595
  shelljs$3.rm('-rf', tarDir);
2831
2596
  return md5Value;
2832
2597
  }
2833
-
2834
2598
  return '';
2835
2599
  }
2836
-
2837
2600
  var install_1 = install$3;
2838
2601
 
2839
2602
  const shelljs$2 = require$$0__default$2;
@@ -2862,6 +2625,7 @@ const {
2862
2625
  info: info$c
2863
2626
  } = log$1;
2864
2627
  const install$2 = install_1;
2628
+
2865
2629
  /**
2866
2630
  * 拷贝相关配置文件到编译输出目录
2867
2631
  * @param { object } tmsConfig
@@ -2869,7 +2633,6 @@ const install$2 = install_1;
2869
2633
  * @param { array } defaultFiles 默认需要拷贝的配置项
2870
2634
  * @returns
2871
2635
  */
2872
-
2873
2636
  const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2874
2637
  const outputDir = resolve$d(tmsConfig.outputDir);
2875
2638
  io.ensureDirExist(outputDir);
@@ -2879,26 +2642,28 @@ const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2879
2642
  }
2880
2643
  });
2881
2644
  };
2882
-
2883
2645
  async function task(tmsConfig, targetModules) {
2884
2646
  // 下载和移动代码
2885
- await createTask$4(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$d('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2647
+ await createTask$4(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$d('./'), targetModules);
2886
2648
 
2887
- const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
2888
-
2889
- const newSubPackages = getSubPackages$2(newModules); // 拷贝相关配置文件到输出目录
2649
+ // 获取所有模块,合并模块依赖的模块
2650
+ const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true);
2651
+ // 获取所有的分包
2652
+ const newSubPackages = getSubPackages$2(newModules);
2890
2653
 
2891
- await createTask$4(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
2654
+ // 拷贝相关配置文件到输出目录
2655
+ await createTask$4(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1);
2892
2656
 
2893
- await install$2(tmsConfig, newSubPackages, true); // 动态生成编译后的app.json;
2657
+ // install
2658
+ await install$2(tmsConfig, newSubPackages, true);
2894
2659
 
2660
+ // 动态生成编译后的app.json;
2895
2661
  await createTask$4(buildOutputAppJson$2, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2896
2662
  return {
2897
2663
  modules: newModules,
2898
2664
  subPackages: newSubPackages
2899
2665
  };
2900
2666
  }
2901
-
2902
2667
  async function init$3(tmsConfig, targetModules) {
2903
2668
  try {
2904
2669
  const taskRes = await task(tmsConfig, targetModules);
@@ -2910,11 +2675,9 @@ async function init$3(tmsConfig, targetModules) {
2910
2675
  process.exit(1);
2911
2676
  }
2912
2677
  }
2913
-
2914
2678
  var init_1 = init$3;
2915
2679
 
2916
2680
  /* eslint-disable no-param-reassign */
2917
-
2918
2681
  function mpProjectJson$1() {
2919
2682
  return function ({
2920
2683
  vinyl,
@@ -2925,11 +2688,9 @@ function mpProjectJson$1() {
2925
2688
  contents = contents.replace(/"miniprogramRoot"[^,]+,/g, '');
2926
2689
  vinyl.contents = Buffer.from(contents);
2927
2690
  }
2928
-
2929
2691
  next();
2930
2692
  };
2931
2693
  }
2932
-
2933
2694
  var mpProjectJson_1 = mpProjectJson$1;
2934
2695
 
2935
2696
  /* eslint-disable @typescript-eslint/no-require-imports */
@@ -2938,15 +2699,15 @@ const pp = require$$1__default$3;
2938
2699
  const path$7 = require$$1__default$1;
2939
2700
  const chalk$4 = require$$3__default;
2940
2701
  /* eslint-enable @typescript-eslint/no-require-imports */
2941
- // 允许渲染的文件类型列表
2942
2702
 
2703
+ // 允许渲染的文件类型列表
2943
2704
  const TEMPLATE_FILE_EXTENSIONS = ['.json', '.js', '.ts', '.wxml', '.wxss', '.wxs', '.css', '.less', '.scss'];
2705
+
2944
2706
  /**
2945
2707
  * 获取预处理器类型
2946
2708
  * @param {string} extName 文件扩展名
2947
2709
  * @returns {string} 预处理器类型
2948
2710
  */
2949
-
2950
2711
  const getPreprocessType = extName => {
2951
2712
  const type = extName.replace('.', '');
2952
2713
  if (type === 'wxml') return 'html';
@@ -2954,6 +2715,7 @@ const getPreprocessType = extName => {
2954
2715
  if (type === 'wxss') return 'css';
2955
2716
  return type;
2956
2717
  };
2718
+
2957
2719
  /**
2958
2720
  * 获取错误上下文信息
2959
2721
  * @param {string} content 文件内容
@@ -2961,80 +2723,67 @@ const getPreprocessType = extName => {
2961
2723
  * @param {number} contextLines 上下文行数
2962
2724
  * @returns {string} 格式化的错误上下文
2963
2725
  */
2964
-
2965
-
2966
2726
  const getErrorContext = (content, errorLine, contextLines = 2) => {
2967
2727
  const lines = content.split('\n');
2968
2728
  const start = Math.max(1, errorLine - contextLines);
2969
2729
  const end = Math.min(lines.length, errorLine + contextLines);
2970
2730
  let context = '';
2971
-
2972
2731
  for (let i = start; i <= end; i++) {
2973
2732
  const marker = i === errorLine ? ' >> ' : ' ';
2974
2733
  context += `${marker}${i}| ${lines[i - 1]}\n`;
2975
2734
  }
2976
-
2977
2735
  return context;
2978
2736
  };
2737
+
2979
2738
  /**
2980
2739
  * 打印错误信息
2981
2740
  * @param {string} filePath 文件路径
2982
2741
  * @param {string} context 错误上下文
2983
2742
  * @param {Error} error 错误对象
2984
2743
  */
2985
-
2986
-
2987
2744
  const printError = (filePath, context, error) => {
2988
2745
  console.error(`${chalk$4.yellow('渲染模板出错,请检查处理:')}\n${chalk$4.yellow('文件:')}\n${chalk$4.yellow(filePath)}\n${chalk$4.yellow('错误位置:')}\n${chalk$4.gray(context)}\n${chalk$4.red('错误信息:')}\n${chalk$4.red(error.message)}\n${chalk$4.gray('--------------------------------')}`);
2989
2746
  };
2747
+
2990
2748
  /**
2991
2749
  * 模板渲染插件
2992
2750
  * @param {Object} tmsConfig 配置对象
2993
2751
  * @returns {Object} through2 转换流
2994
2752
  */
2995
-
2996
-
2997
2753
  var tmsTemplateRender = function tmsTemplateRender(tmsConfig) {
2998
2754
  return through$1.obj((file, encoding, callback) => {
2999
2755
  if (!file.isBuffer()) {
3000
2756
  return callback(null, file);
3001
2757
  }
3002
-
3003
2758
  const extName = path$7.extname(file.path).toLowerCase();
3004
-
3005
2759
  if (!TEMPLATE_FILE_EXTENSIONS.includes(extName)) {
3006
2760
  return callback(null, file);
3007
2761
  }
3008
-
3009
2762
  const content = file.contents.toString(encoding);
3010
-
3011
2763
  try {
3012
2764
  const vars = tmsConfig.templateVars || {};
3013
- const ppType = getPreprocessType(extName); // 手动检查 @echo 引用的变量是否存在
3014
-
2765
+ const ppType = getPreprocessType(extName);
2766
+ // 手动检查 @echo 引用的变量是否存在
3015
2767
  const echoPattern = /\/\* @echo (\w+) \*\//g;
3016
2768
  let match;
3017
-
3018
2769
  while ((match = echoPattern.exec(content)) !== null) {
3019
- const variableName = match[1]; // eslint-disable-next-line no-prototype-builtins
3020
-
2770
+ const variableName = match[1];
2771
+ // eslint-disable-next-line no-prototype-builtins
3021
2772
  if (!vars.hasOwnProperty(variableName)) {
3022
2773
  const error = new Error(`变量 ${variableName} 未定义`);
3023
2774
  error.line = content.substring(0, match.index).split('\n').length;
3024
2775
  throw error;
3025
2776
  }
3026
2777
  }
3027
-
3028
- const rendered = pp.preprocess(content, vars, ppType); // eslint-disable-next-line no-param-reassign
3029
-
2778
+ const rendered = pp.preprocess(content, vars, ppType);
2779
+ // eslint-disable-next-line no-param-reassign
3030
2780
  file.contents = Buffer.from(rendered);
3031
2781
  } catch (err) {
3032
2782
  const context = getErrorContext(content, err.line || 1);
3033
- printError(file.path, context, err); // 直接抛出异常,中断编译流程
3034
-
2783
+ printError(file.path, context, err);
2784
+ // 直接抛出异常,中断编译流程
3035
2785
  throw new Error(`模板渲染失败: ${file.path}\n${err.message}`);
3036
2786
  }
3037
-
3038
2787
  callback(null, file);
3039
2788
  });
3040
2789
  };
@@ -3054,13 +2803,11 @@ const through = require$$0__default$8;
3054
2803
  const {
3055
2804
  fail: fail$3
3056
2805
  } = log$1;
3057
-
3058
2806
  const getTargetFile$2 = (sourceFile, module, outputDir) => {
3059
2807
  const sourceFileRelativeModule = path$6.relative(resolve$c(module.from), sourceFile);
3060
2808
  const targetFile = resolve$c(outputDir, module.to, sourceFileRelativeModule);
3061
2809
  return targetFile;
3062
2810
  };
3063
-
3064
2811
  const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
3065
2812
  const {
3066
2813
  plugins = []
@@ -3082,7 +2829,6 @@ const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
3082
2829
  this.push(vinyl);
3083
2830
  }))), srcPipe);
3084
2831
  };
3085
-
3086
2832
  var compile$1 = function (tmsConfig, {
3087
2833
  glob,
3088
2834
  destPath,
@@ -3096,12 +2842,15 @@ var compile$1 = function (tmsConfig, {
3096
2842
  taskFn: (sourceFile, targetPath) => {
3097
2843
  const newGlobValue = Array.isArray(sourceFile) ? sourceFile : glob;
3098
2844
  const newDestPath = targetPath ? targetPath : destPath;
3099
- let srcPipe = src$2(newGlobValue, { ...srcOption
3100
- }); // 在文件读取后,插件处理之前先加入模板渲染插件
2845
+ let srcPipe = src$2(newGlobValue, {
2846
+ ...srcOption
2847
+ });
3101
2848
 
2849
+ // 在文件读取后,插件处理之前先加入模板渲染插件
3102
2850
  const templateRender = tmsTemplateRender;
3103
- srcPipe = srcPipe.pipe(templateRender(tmsConfig)); // 后续步骤继续执行其他插件
2851
+ srcPipe = srcPipe.pipe(templateRender(tmsConfig));
3104
2852
 
2853
+ // 后续步骤继续执行其他插件
3105
2854
  const pluginParams = {
3106
2855
  module,
3107
2856
  isDev
@@ -3117,7 +2866,6 @@ var compile$1 = function (tmsConfig, {
3117
2866
 
3118
2867
  /* eslint-disable */
3119
2868
  // 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
3120
-
3121
2869
  const assign = require$$0__default$a;
3122
2870
  const path$5 = require$$1__default$1;
3123
2871
  const PluginError = require$$2__default$1;
@@ -3133,69 +2881,52 @@ const anymatch = require$$9__default;
3133
2881
  const pathIsAbsolute = require$$10__default$1;
3134
2882
  const globParent = require$$11__default;
3135
2883
  const slash = require$$12__default;
3136
-
3137
2884
  function normalizeGlobs(globs) {
3138
2885
  if (!globs) {
3139
2886
  throw new PluginError('gulp-watch', 'glob argument required');
3140
2887
  }
3141
-
3142
2888
  if (typeof globs === 'string') {
3143
2889
  globs = [globs];
3144
2890
  }
3145
-
3146
2891
  if (!Array.isArray(globs)) {
3147
2892
  throw new PluginError('gulp-watch', `glob should be String or Array, not ${typeof globs}`);
3148
2893
  }
3149
-
3150
2894
  return globs;
3151
2895
  }
3152
-
3153
2896
  function watch$3(globs, opts, cb) {
3154
2897
  globs = normalizeGlobs(globs);
3155
-
3156
2898
  if (typeof opts === 'function') {
3157
2899
  cb = opts;
3158
2900
  opts = {};
3159
2901
  }
3160
-
3161
2902
  opts = assign({}, watch$3._defaultOptions, opts);
3162
-
3163
2903
  cb = cb || function () {};
3164
-
3165
2904
  function resolveFilepath(filepath) {
3166
2905
  if (pathIsAbsolute(filepath)) {
3167
2906
  return path$5.normalize(filepath);
3168
2907
  }
3169
-
3170
2908
  return path$5.resolve(opts.cwd || process.cwd(), filepath);
3171
2909
  }
3172
-
3173
2910
  function resolveGlob(glob) {
3174
2911
  let mod = '';
3175
-
3176
2912
  if (glob[0] === '!') {
3177
2913
  mod = glob[0];
3178
2914
  glob = glob.slice(1);
3179
2915
  }
3180
-
3181
2916
  return mod + slash(resolveFilepath(glob));
3182
2917
  }
3183
-
3184
2918
  globs = globs.map(resolveGlob);
3185
2919
  const baseForced = Boolean(opts.base);
3186
2920
  const outputStream = new Duplex({
3187
2921
  objectMode: true,
3188
2922
  allowHalfOpen: true
3189
2923
  });
3190
-
3191
2924
  outputStream._write = function _write(file, enc, done) {
3192
2925
  cb(file);
3193
2926
  this.push(file);
3194
2927
  done();
3195
2928
  };
3196
-
3197
2929
  outputStream._read = function _read() {};
3198
-
3199
2930
  const watcher = chokidar.watch(globs, opts);
3200
2931
  opts.events.forEach(ev => {
3201
2932
  watcher.on(ev, processEvent.bind(undefined, ev));
@@ -3203,86 +2934,72 @@ function watch$3(globs, opts, cb) {
3203
2934
  ['add', 'change', 'unlink', 'addDir', 'unlinkDir', 'error', 'ready', 'raw'].forEach(ev => {
3204
2935
  watcher.on(ev, outputStream.emit.bind(outputStream, ev));
3205
2936
  });
3206
-
3207
2937
  outputStream.add = function add(newGlobs) {
3208
2938
  newGlobs = normalizeGlobs(newGlobs).map(resolveGlob);
3209
2939
  watcher.add(newGlobs);
3210
2940
  globs.push.apply(globs, newGlobs);
3211
2941
  };
3212
-
3213
2942
  outputStream.unwatch = watcher.unwatch.bind(watcher);
3214
-
3215
2943
  outputStream.close = function () {
3216
2944
  watcher.close();
3217
2945
  this.emit('end');
3218
2946
  };
3219
-
3220
2947
  function processEvent(event, filepath) {
3221
2948
  filepath = resolveFilepath(filepath);
3222
2949
  const fileOpts = assign({}, opts);
3223
2950
  let glob;
3224
2951
  let currentFilepath = filepath;
3225
-
3226
2952
  while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$5.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
3227
2953
 
3228
-
3229
2954
  if (!glob) {
3230
2955
  console.error('[gulp-watch]没有匹配到glob');
3231
2956
  return;
3232
2957
  }
3233
-
3234
2958
  if (!baseForced) {
3235
2959
  fileOpts.base = path$5.normalize(globParent(glob));
3236
- } // Do not stat deleted files
3237
-
2960
+ }
3238
2961
 
2962
+ // Do not stat deleted files
3239
2963
  if (event === 'unlink' || event === 'unlinkDir' || event === 'addDir') {
3240
2964
  fileOpts.path = filepath;
3241
2965
  write(event, null, new File(fileOpts));
3242
2966
  return;
3243
- } // Workaround for early read
3244
-
2967
+ }
3245
2968
 
2969
+ // Workaround for early read
3246
2970
  setTimeout(() => {
3247
2971
  vinyl.read(filepath, fileOpts).then(file => {
3248
2972
  write(event, null, file);
3249
2973
  });
3250
2974
  }, opts.readDelay);
3251
2975
  }
3252
-
3253
2976
  function write(event, err, file) {
3254
2977
  if (err) {
3255
2978
  outputStream.emit('error', err);
3256
2979
  return;
3257
2980
  }
3258
-
3259
2981
  if (opts.verbose) {
3260
2982
  log(event, file);
3261
2983
  }
3262
-
3263
2984
  file.event = event;
3264
2985
  outputStream.push(file);
3265
2986
  cb(file);
3266
2987
  }
3267
-
3268
2988
  function log(event, file) {
3269
2989
  event = event[event.length - 1] === 'e' ? `${event}d` : `${event}ed`;
3270
2990
  const msg = [colors.magenta(file.relative), 'was', event];
3271
-
3272
2991
  if (opts.name) {
3273
2992
  msg.unshift(`${colors.cyan(opts.name)} saw`);
3274
2993
  }
3275
-
3276
2994
  fancyLog.info.apply(null, msg);
3277
2995
  }
3278
-
3279
2996
  return outputStream;
3280
- } // This is not part of the public API as that would lead to global state (singleton) pollution,
2997
+ }
2998
+
2999
+ // This is not part of the public API as that would lead to global state (singleton) pollution,
3281
3000
  // and allow unexpected interference between unrelated modules that make use of gulp-watch.
3282
3001
  // This can be useful for unit tests and root application configuration, though.
3283
3002
  // Avoid modifying gulp-watch's default options inside a library/reusable package, please.
3284
-
3285
-
3286
3003
  watch$3._defaultOptions = {
3287
3004
  events: ['add', 'change', 'unlink'],
3288
3005
  ignoreInitial: true,
@@ -3331,7 +3048,6 @@ const TIP_MAP = {
3331
3048
  check: () => true
3332
3049
  }
3333
3050
  };
3334
-
3335
3051
  const logTip = (fileName, sourceFile, targetFile, tipMap) => {
3336
3052
  try {
3337
3053
  for (const item in tipMap) {
@@ -3340,20 +3056,18 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
3340
3056
  return;
3341
3057
  }
3342
3058
  }
3343
-
3344
3059
  info$b(`${fileName}有更新`);
3345
3060
  } catch (e) {
3346
3061
  fail$2(`${sourceFile}文件更新提示出现错误: ${e.message}`);
3347
3062
  }
3348
3063
  };
3349
-
3350
3064
  const getTargetFile$1 = (sourceFile, module, outputDir) => {
3351
3065
  const sourceFileRelativeModule = path$4.relative(resolve$b(module.from), sourceFile);
3352
3066
  return resolve$b(outputDir, module.to, sourceFileRelativeModule);
3353
3067
  };
3354
-
3355
3068
  var watch_1 = function (globValue, watchOptions, callback, module) {
3356
- watch$2(globValue, { // readDelay: 100,
3069
+ watch$2(globValue, {
3070
+ // readDelay: 100,
3357
3071
  ...watchOptions
3358
3072
  }, async vinyl => {
3359
3073
  const sourceFile = vinyl.history[0];
@@ -3361,19 +3075,16 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3361
3075
  const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
3362
3076
  const tmsConfig = global$6.getData('tmsConfig');
3363
3077
  let targetFile = getTargetFile$1(sourceFile, module, tmsConfig.outputDir);
3364
-
3365
3078
  if (module.custom) {
3366
3079
  const filePath = sourceFile.replace(/\\/g, '/').replace(module.from, '');
3367
3080
  targetFile = path$4.join(module.to, filePath);
3368
3081
  }
3369
-
3370
3082
  if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
3371
3083
  info$b(`删除${sourceFileName}`);
3372
3084
  shellJs$2.rm('-rf', targetFile);
3373
3085
  updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
3374
3086
  return;
3375
3087
  }
3376
-
3377
3088
  await runCallback({
3378
3089
  tmsConfig,
3379
3090
  sourceFile,
@@ -3383,9 +3094,9 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3383
3094
  });
3384
3095
  logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
3385
3096
  });
3386
- }; // 开始执行watch 文件的 callback函数
3387
-
3097
+ };
3388
3098
 
3099
+ // 开始执行watch 文件的 callback函数
3389
3100
  async function runCallback({
3390
3101
  tmsConfig,
3391
3102
  sourceFile,
@@ -3405,12 +3116,11 @@ async function runCallback({
3405
3116
  await callback([sourceFile], path$4.dirname(targetFile));
3406
3117
  await updateFileHook(tmsConfig, sourceFile, targetFile, type);
3407
3118
  }
3408
- } // 执行源码文件更新的钩子
3409
-
3119
+ }
3410
3120
 
3121
+ // 执行源码文件更新的钩子
3411
3122
  async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
3412
3123
  var _tmsConfig$hooks;
3413
-
3414
3124
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateFile) === 'function') {
3415
3125
  await tmsConfig.hooks.updateFile({
3416
3126
  tmsConfig: filterField$5(tmsConfig, ['gitAccount']),
@@ -3453,10 +3163,10 @@ const {
3453
3163
  global: global$5
3454
3164
  } = global_1;
3455
3165
  const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
3456
-
3457
3166
  var dev$4 = async (tmsConfig, modules, isDev = true) => {
3458
- const compileTasksMap = new Map(); // 监听根目录的文件
3167
+ const compileTasksMap = new Map();
3459
3168
 
3169
+ // 监听根目录的文件
3460
3170
  mergeMap(compileTasksMap, compile(tmsConfig, {
3461
3171
  glob: DEFAULT_COPY_CONFIG.map(item => resolve$a(item)),
3462
3172
  module: {
@@ -3468,8 +3178,9 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3468
3178
  allowEmpty: true
3469
3179
  },
3470
3180
  isDev
3471
- })); // 监听extendFiles
3181
+ }));
3472
3182
 
3183
+ // 监听extendFiles
3473
3184
  if (tmsConfig.watchExtendFiles.length) {
3474
3185
  tmsConfig.watchExtendFiles.forEach(item => {
3475
3186
  mergeMap(compileTasksMap, compile(tmsConfig, {
@@ -3486,19 +3197,19 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3486
3197
  isDev
3487
3198
  }));
3488
3199
  });
3489
- } // 监听模块的文件
3490
-
3200
+ }
3491
3201
 
3202
+ // 监听模块的文件
3492
3203
  for (let moduleItem of modules) {
3493
3204
  // 处理默认参数
3494
- moduleItem = { ...{
3205
+ moduleItem = {
3206
+ ...{
3495
3207
  exclude: []
3496
3208
  },
3497
3209
  ...moduleItem
3498
3210
  };
3499
3211
  const srcModulePath = getAbsolutePath$3(moduleItem.path);
3500
3212
  const buildModulePath = resolve$a(tmsConfig.outputDir, moduleItem.modulePath);
3501
-
3502
3213
  if (isDev) {
3503
3214
  // 监听模块配置文件
3504
3215
  watch$1([`${srcModulePath}/**/module.config.json`], {
@@ -3508,15 +3219,12 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3508
3219
  to: buildModulePath
3509
3220
  });
3510
3221
  }
3511
-
3512
3222
  const excludes = moduleItem.exclude.map(ePath => {
3513
3223
  const newPath = getAbsolutePath$3(ePath, srcModulePath);
3514
3224
  const ext = path$3.extname(ePath).slice(1);
3515
-
3516
3225
  if (ext) {
3517
3226
  return `!${resolve$a(srcModulePath, newPath)}`;
3518
3227
  }
3519
-
3520
3228
  return `!${resolve$a(srcModulePath, newPath)}/**/*`;
3521
3229
  });
3522
3230
  const moduleConfigPath = `${srcModulePath}/**/module.config.json`;
@@ -3533,22 +3241,20 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3533
3241
  },
3534
3242
  isDev
3535
3243
  }));
3536
- } // static静态资源目录
3537
-
3244
+ }
3538
3245
 
3246
+ // static静态资源目录
3539
3247
  if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
3540
3248
  for (const item of tmsConfig.static) {
3541
3249
  item.from = getAbsolutePath$3(item.from);
3542
3250
  item.to = getAbsolutePath$3(item.to);
3543
3251
  let glob = {};
3544
3252
  const ext = path$3.extname(item.from).slice(1);
3545
-
3546
3253
  if (ext) {
3547
3254
  glob = [item.from];
3548
3255
  } else {
3549
3256
  glob = [`${item.from}/**/*`];
3550
3257
  }
3551
-
3552
3258
  const from = fs$6.lstatSync(item.from).isFile() ? path$3.dirname(item.from) : item.from;
3553
3259
  mergeMap(compileTasksMap, compile(tmsConfig, {
3554
3260
  glob,
@@ -3564,21 +3270,17 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3564
3270
  }));
3565
3271
  }
3566
3272
  }
3567
-
3568
3273
  let sTime;
3569
3274
  let eTime;
3570
3275
  const spinner = ora$1();
3571
-
3572
3276
  function start(cb) {
3573
3277
  info$a('启动编译...');
3574
3278
  spinner.start();
3575
3279
  sTime = new Date().getTime();
3576
3280
  cb();
3577
3281
  }
3578
-
3579
3282
  async function end(cb) {
3580
3283
  var _tmsConfig$hooks;
3581
-
3582
3284
  if (isDev) {
3583
3285
  // 监听app.json
3584
3286
  watch$1([resolve$a('app.json')], {
@@ -3587,8 +3289,8 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3587
3289
  }, async () => await buildOutputAppJson$1(tmsConfig, modules, isDev), {
3588
3290
  from: resolve$a(),
3589
3291
  to: resolve$a(tmsConfig.outputDir)
3590
- }); // 监听其他文件
3591
-
3292
+ });
3293
+ // 监听其他文件
3592
3294
  compileTasksMap.forEach(({
3593
3295
  taskFn,
3594
3296
  module
@@ -3601,12 +3303,9 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3601
3303
  } else {
3602
3304
  await buildOutputAppJson$1(tmsConfig, modules, isDev);
3603
3305
  }
3604
-
3605
3306
  eTime = new Date().getTime() - sTime;
3606
-
3607
3307
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterFirstCompile) === 'function') {
3608
3308
  var _tmsConfig$hooks2;
3609
-
3610
3309
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterFirstCompile({
3611
3310
  isDev,
3612
3311
  tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
@@ -3615,19 +3314,17 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3615
3314
  }));
3616
3315
  report$7('hooks:afterCompile');
3617
3316
  }
3618
-
3619
3317
  spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
3620
3318
  spinner.stop();
3621
3319
  cb();
3622
3320
  }
3623
-
3624
3321
  const compileTasks = [];
3625
3322
  compileTasksMap.forEach(({
3626
3323
  taskFn
3627
3324
  }) => {
3628
3325
  compileTasks.push(taskFn);
3629
- }); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
3630
-
3326
+ });
3327
+ // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
3631
3328
  series$1(start, parallel$1(...compileTasks), end)();
3632
3329
  };
3633
3330
 
@@ -3655,13 +3352,14 @@ const {
3655
3352
  MODULE_CODE_DIR,
3656
3353
  NODE_MODULES_DIR
3657
3354
  } = constant;
3658
- const report$6 = report_1; // const { recommendVersion } = require('../../../core/recommendVersion');
3659
- // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3355
+ const report$6 = report_1;
3356
+ // const { recommendVersion } = require('../../../core/recommendVersion');
3660
3357
 
3358
+ // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3661
3359
  function delOtherPackages(tmsConfig, targetSubPackages) {
3662
3360
  // 获取所有模块,合并模块依赖的模块
3663
- const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all); // 获取所有的分包
3664
-
3361
+ const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all);
3362
+ // 获取所有的分包
3665
3363
  const allSubPackages = getSubPackages$1(allModules);
3666
3364
  const targetSubPackagesName = targetSubPackages.map(item => item.name);
3667
3365
  allSubPackages.forEach(item => {
@@ -3669,42 +3367,38 @@ function delOtherPackages(tmsConfig, targetSubPackages) {
3669
3367
  const moduleRootDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
3670
3368
  shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
3671
3369
  silent: true
3672
- }); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
3370
+ });
3371
+ // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
3673
3372
  // io.ensureDirExist(moduleRootDir);
3674
3373
  }
3675
3374
  });
3676
3375
  }
3677
-
3678
3376
  async function dev$3(tmsConfig, targetModules) {
3679
3377
  var _tmsConfig$hooks;
3680
-
3681
3378
  const {
3682
3379
  noCache
3683
3380
  } = global$4.getData('cmdOptions');
3684
-
3685
3381
  if (noCache) {
3686
3382
  if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
3687
3383
  shelljs$1.rm('-rf', resolve$9(tmsConfig.outputDir));
3688
3384
  }
3689
-
3690
3385
  shelljs$1.rm('-rf', MODULE_CODE_DIR);
3691
3386
  shelljs$1.rm('-rf', NODE_MODULES_DIR);
3692
- } // 推荐tmskit的版本
3387
+ }
3388
+ // 推荐tmskit的版本
3693
3389
  // await recommendVersion();
3694
- // 初始化操作
3695
-
3696
3390
 
3391
+ // 初始化操作
3697
3392
  const {
3698
3393
  subPackages,
3699
3394
  modules: newModules
3700
- } = await init$2(tmsConfig, targetModules); // 在启动开发环境前主动执行生成 app.json
3395
+ } = await init$2(tmsConfig, targetModules);
3701
3396
 
3397
+ // 在启动开发环境前主动执行生成 app.json
3702
3398
  await buildOutputAppJson(tmsConfig, newModules);
3703
3399
  info$9('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3704
-
3705
3400
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
3706
3401
  var _tmsConfig$hooks2;
3707
-
3708
3402
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
3709
3403
  isDev: true,
3710
3404
  tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
@@ -3716,11 +3410,9 @@ async function dev$3(tmsConfig, targetModules) {
3716
3410
  delOtherPackages(tmsConfig, subPackages);
3717
3411
  compileDev(tmsConfig, newModules, true);
3718
3412
  }
3719
-
3720
3413
  var dev_1 = dev$3;
3721
3414
 
3722
3415
  const dev$2 = dev$4;
3723
-
3724
3416
  var build$2 = async (tmsConfig, newModules, isDev) => {
3725
3417
  dev$2(tmsConfig, newModules, isDev);
3726
3418
  };
@@ -3739,24 +3431,19 @@ const report$5 = report_1;
3739
3431
  const {
3740
3432
  global: global$3
3741
3433
  } = global_1;
3742
-
3743
3434
  async function build$1(tmsConfig, targetModules) {
3744
3435
  var _tmsConfig$hooks;
3745
-
3746
3436
  // 开始构建前,清理输出目录
3747
3437
  if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
3748
3438
  await shelljs.rm('-rf', resolve$8(tmsConfig.outputDir));
3749
3439
  }
3750
-
3751
3440
  const {
3752
3441
  modules: newModules
3753
3442
  } = await init$1(tmsConfig, targetModules);
3754
3443
  info$8('当前build有效模块', newModules.map(item => item.moduleName).sort());
3755
3444
  const isDev = false;
3756
-
3757
3445
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
3758
3446
  var _tmsConfig$hooks2;
3759
-
3760
3447
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
3761
3448
  isDev,
3762
3449
  tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
@@ -3767,7 +3454,6 @@ async function build$1(tmsConfig, targetModules) {
3767
3454
  }
3768
3455
  compileBuild(tmsConfig, newModules, isDev);
3769
3456
  }
3770
-
3771
3457
  var build_1 = build$1;
3772
3458
 
3773
3459
  const moment = require$$1__default;
@@ -3780,39 +3466,32 @@ const {
3780
3466
  const {
3781
3467
  ensureDirExist: ensureDirExist$3
3782
3468
  } = io$3;
3783
-
3784
3469
  function getAllSize$2(data = {}) {
3785
3470
  let allSize;
3786
-
3787
3471
  for (const item of data === null || data === void 0 ? void 0 : data.subPackageInfo) {
3788
3472
  if (item.name === '__FULL__') {
3789
3473
  allSize = item.size;
3790
3474
  break;
3791
3475
  }
3792
3476
  }
3793
-
3794
3477
  return allSize;
3795
3478
  }
3796
-
3797
3479
  const getDesc$3 = (desc = '') => {
3798
3480
  const user = getGitUser();
3799
3481
  const date = moment().format('YYYY-MM-DD HH:mm:ss');
3800
3482
  return `构建描述:${desc}; 构建人: ${user}; 构建时间:${date}`;
3801
3483
  };
3802
-
3803
3484
  const outputInfo$2 = (infoOutput, data) => {
3804
3485
  const outPath = getAbsolutePath$2(infoOutput);
3805
3486
  const dir = path$2.dirname(outPath);
3806
3487
  ensureDirExist$3(dir);
3807
3488
  fs$5.writeFileSync(outPath, JSON.stringify(data, null, 2));
3808
3489
  };
3809
-
3810
3490
  const getDetaultVersion = () => {
3811
3491
  const version = moment().format('gggg,mm').split(',');
3812
3492
  version.push('0');
3813
3493
  return version.join('.');
3814
3494
  };
3815
-
3816
3495
  var utils = {
3817
3496
  getAllSize: getAllSize$2,
3818
3497
  getDesc: getDesc$3,
@@ -3843,12 +3522,13 @@ const {
3843
3522
  getDesc: getDesc$2
3844
3523
  } = utils;
3845
3524
  const report$4 = report_1;
3846
-
3847
3525
  const handleParams$2 = (tmsConfig, cmdOptions) => {
3848
- const params = { ...(tmsConfig.preview ? tmsConfig.preview : {}),
3526
+ const params = {
3527
+ ...(tmsConfig.preview ? tmsConfig.preview : {}),
3849
3528
  ...cmdOptions
3850
3529
  };
3851
- return { ...params,
3530
+ return {
3531
+ ...params,
3852
3532
  appId: params.appId || tmsConfig.appId,
3853
3533
  projectPath: resolve$7(tmsConfig.outputDir),
3854
3534
  privateKey: params.privateKey || tmsConfig.privateKey,
@@ -3857,22 +3537,18 @@ const handleParams$2 = (tmsConfig, cmdOptions) => {
3857
3537
  qrcodeOutputDest: getAbsolutePath$1(params.qrcodeOutputDest || '')
3858
3538
  };
3859
3539
  };
3540
+
3860
3541
  /**
3861
3542
  * 预览
3862
3543
  * @params {object} tmsConfig
3863
3544
  * @param {object} cmdOptions {qrcodeFormat: 'base64', qrcodeOutputDest: './a.txt', robot: 2, infoOutput: './a.txt' }
3864
3545
  */
3865
-
3866
-
3867
3546
  async function preview$1(tmsConfig, cmdOptions) {
3868
3547
  try {
3869
3548
  var _tmsConfig$hooks;
3870
-
3871
3549
  const params = handleParams$2(tmsConfig, cmdOptions);
3872
-
3873
3550
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforePreview) === 'function') {
3874
3551
  var _tmsConfig$hooks2;
3875
-
3876
3552
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforePreview({
3877
3553
  tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
3878
3554
  cmdOptions: global$2.getData('cmdOptions'),
@@ -3880,33 +3556,28 @@ async function preview$1(tmsConfig, cmdOptions) {
3880
3556
  }));
3881
3557
  report$4('hooks:beforePreview');
3882
3558
  }
3883
-
3884
3559
  ;
3885
- const previewRes = await createTask$3(mpCi$2.previewMp, '正在构建预览码', '构建预览码完成')({ ...params
3560
+ const previewRes = await createTask$3(mpCi$2.previewMp, '正在构建预览码', '构建预览码完成')({
3561
+ ...params
3886
3562
  });
3887
3563
  const allSize = getAllSize$1(previewRes);
3888
-
3889
3564
  if (params.infoOutput) {
3890
3565
  let qrcodeBase64 = '';
3891
-
3892
3566
  if (params.qrcodeFormat === 'base64' && fs$4.existsSync(params.qrcodeOutputDest)) {
3893
3567
  qrcodeBase64 = fs$4.readFileSync(params.qrcodeOutputDest, 'utf8');
3894
3568
  }
3895
-
3896
3569
  outputInfo$1(params.infoOutput, {
3897
3570
  sourceCode: params.projectPath,
3898
3571
  qrcodeBase64,
3899
3572
  ...previewRes
3900
3573
  });
3901
3574
  }
3902
-
3903
3575
  info$7('预览包大小:', `${allSize}k`);
3904
3576
  } catch (e) {
3905
3577
  console.log('详细错误:', e);
3906
3578
  handleError$4(`预览错误: ${e.message}`, true);
3907
3579
  }
3908
3580
  }
3909
-
3910
3581
  var preview_1 = preview$1;
3911
3582
 
3912
3583
  const mpCi$1 = mpCi$3;
@@ -3930,17 +3601,16 @@ const {
3930
3601
  getDesc: getDesc$1
3931
3602
  } = utils;
3932
3603
  const report$3 = report_1;
3933
-
3934
3604
  const handleParams$1 = (tmsConfig, cmdOptions) => {
3935
- const params = { ...(tmsConfig.upload ? tmsConfig.upload : {}),
3605
+ const params = {
3606
+ ...(tmsConfig.upload ? tmsConfig.upload : {}),
3936
3607
  ...cmdOptions
3937
3608
  };
3938
-
3939
3609
  if (!params.version) {
3940
3610
  throw new Error('请指定传入版本号 eg: tmskit run upload --version 2022.28.5');
3941
3611
  }
3942
-
3943
- return { ...params,
3612
+ return {
3613
+ ...params,
3944
3614
  appId: params.appId || tmsConfig.appId,
3945
3615
  projectPath: resolve$6(tmsConfig.outputDir),
3946
3616
  privateKey: params.privateKey || tmsConfig.privateKey,
@@ -3948,22 +3618,18 @@ const handleParams$1 = (tmsConfig, cmdOptions) => {
3948
3618
  desc: params.desc || getDesc$1(params.desc)
3949
3619
  };
3950
3620
  };
3621
+
3951
3622
  /**
3952
3623
  * 上传
3953
3624
  * @param {object} tmsConfig
3954
3625
  * @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
3955
3626
  */
3956
-
3957
-
3958
3627
  async function upload$1(tmsConfig, cmdOptions) {
3959
3628
  try {
3960
3629
  var _tmsConfig$hooks;
3961
-
3962
3630
  const params = handleParams$1(tmsConfig, cmdOptions);
3963
-
3964
3631
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeUpload) === 'function') {
3965
3632
  var _tmsConfig$hooks2;
3966
-
3967
3633
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeUpload({
3968
3634
  tmsConfig: filterField(tmsConfig, ['gitAccount']),
3969
3635
  cmdOptions: global$1.getData('cmdOptions'),
@@ -3971,26 +3637,23 @@ async function upload$1(tmsConfig, cmdOptions) {
3971
3637
  }));
3972
3638
  report$3('hooks:beforeUpload');
3973
3639
  }
3974
-
3975
3640
  ;
3976
- const uploadRes = await createTask$2(mpCi$1.uploadMp, '正在上传小程序代码', '上传小程序代码完成')({ ...params
3641
+ const uploadRes = await createTask$2(mpCi$1.uploadMp, '正在上传小程序代码', '上传小程序代码完成')({
3642
+ ...params
3977
3643
  });
3978
3644
  const allSize = getAllSize(uploadRes);
3979
-
3980
3645
  if (params.infoOutput) {
3981
3646
  outputInfo(params.infoOutput, {
3982
3647
  sourceCode: params.projectPath,
3983
3648
  ...uploadRes
3984
3649
  });
3985
3650
  }
3986
-
3987
3651
  info$6(`上传包大小: ${allSize}k; 上传包版本: ${params.version}`);
3988
3652
  } catch (e) {
3989
3653
  console.log('详细错误:', e);
3990
3654
  handleError$3(`上传错误: ${e.message}`, true);
3991
3655
  }
3992
3656
  }
3993
-
3994
3657
  var upload_1 = upload$1;
3995
3658
 
3996
3659
  const mpCi = mpCi$3;
@@ -4008,9 +3671,9 @@ const {
4008
3671
  getDesc
4009
3672
  } = utils;
4010
3673
  const report$2 = report_1;
4011
-
4012
3674
  const handleParams = (tmsConfig, cmdOptions) => {
4013
- const params = { ...(tmsConfig.upload ? tmsConfig.upload : {}),
3675
+ const params = {
3676
+ ...(tmsConfig.upload ? tmsConfig.upload : {}),
4014
3677
  ...cmdOptions
4015
3678
  };
4016
3679
  return {
@@ -4023,18 +3686,18 @@ const handleParams = (tmsConfig, cmdOptions) => {
4023
3686
  desc: params.desc || getDesc(params.desc)
4024
3687
  };
4025
3688
  };
3689
+
4026
3690
  /**
4027
3691
  * 获取sourcemap
4028
3692
  * @param {object} tmsConfig
4029
3693
  * @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
4030
3694
  */
4031
-
4032
-
4033
3695
  async function sourcemap$1(tmsConfig, cmdOptions) {
4034
3696
  try {
4035
3697
  const params = handleParams(tmsConfig, cmdOptions);
4036
3698
  report$2('sourcemap');
4037
- await createTask$1(mpCi.getDevSourceMap, '正在获取小程序代码sourcemap', '获取小程序代码sourcemap完成')({ ...params
3699
+ await createTask$1(mpCi.getDevSourceMap, '正在获取小程序代码sourcemap', '获取小程序代码sourcemap完成')({
3700
+ ...params
4038
3701
  });
4039
3702
  info$5(`sourcemap文件已保存到${params.sourceMapSavePath}`);
4040
3703
  } catch (e) {
@@ -4042,28 +3705,27 @@ async function sourcemap$1(tmsConfig, cmdOptions) {
4042
3705
  handleError$2(`获取sourcemap错误: ${e.message}`, true);
4043
3706
  }
4044
3707
  }
4045
-
4046
3708
  var sourcemap_1 = sourcemap$1;
4047
3709
 
4048
3710
  const {
4049
3711
  resolve: resolve$4,
4050
3712
  getAbsolutePath
4051
- } = widgets; // 处理tms.config.cloudModules的兼容数据
3713
+ } = widgets;
4052
3714
 
3715
+ // 处理tms.config.cloudModules的兼容数据
4053
3716
  function getTmsCloudModules(tmsConfig) {
4054
3717
  const {
4055
3718
  cloudModules
4056
3719
  } = tmsConfig;
4057
-
4058
3720
  if (Array.isArray(tmsConfig.cloudModules)) {
4059
3721
  return {
4060
3722
  all: [...tmsConfig.cloudModules],
4061
3723
  include: []
4062
3724
  };
4063
3725
  }
4064
-
4065
3726
  return cloudModules;
4066
3727
  }
3728
+
4067
3729
  /**
4068
3730
  * 获取需要监听的云函数
4069
3731
  * @param {*} tmsConfig {}
@@ -4071,21 +3733,17 @@ function getTmsCloudModules(tmsConfig) {
4071
3733
  * @returns
4072
3734
  * [{ name: '', sourcePath: '', targetPath: ''}]
4073
3735
  */
4074
-
4075
-
4076
3736
  function getCloudsOfListen$2(tmsConfig, cmdOptions) {
4077
3737
  var _cmdOptions$cloud;
4078
-
4079
3738
  // 获取tmsconfig配置的云函数的配置项
4080
3739
  const cloudModules = getTmsCloudModules(tmsConfig);
4081
- let includeClouds = (cmdOptions === null || cmdOptions === void 0 ? void 0 : (_cmdOptions$cloud = cmdOptions.cloud) === null || _cmdOptions$cloud === void 0 ? void 0 : _cmdOptions$cloud.split(',')) || cloudModules.include || []; // 如果没有配置include, 默认使用所有的数据云函数列表
3740
+ let includeClouds = (cmdOptions === null || cmdOptions === void 0 ? void 0 : (_cmdOptions$cloud = cmdOptions.cloud) === null || _cmdOptions$cloud === void 0 ? void 0 : _cmdOptions$cloud.split(',')) || cloudModules.include || [];
4082
3741
 
3742
+ // 如果没有配置include, 默认使用所有的数据云函数列表
4083
3743
  if (includeClouds.length === 0) {
4084
3744
  includeClouds = cloudModules.all.map(item => item.name);
4085
3745
  }
4086
-
4087
3746
  const result = [];
4088
-
4089
3747
  for (const item of cloudModules.all) {
4090
3748
  if (includeClouds.includes(item.name)) {
4091
3749
  result.push({
@@ -4095,45 +3753,38 @@ function getCloudsOfListen$2(tmsConfig, cmdOptions) {
4095
3753
  });
4096
3754
  }
4097
3755
  }
4098
-
4099
3756
  return result;
4100
3757
  }
4101
-
4102
3758
  var getClouds = getCloudsOfListen$2;
4103
3759
 
4104
3760
  const fs$3 = require$$0__default$1;
3761
+
4105
3762
  /**
4106
3763
  * 检查云函数的配置项
4107
3764
  * @param {*} tmsConfig
4108
3765
  */
4109
-
4110
3766
  function checkCloudConfig$2(tmsConfig) {
4111
3767
  if (!tmsConfig.cloudModules) {
4112
3768
  return '你没有在tms.config.js的cloudModules注册云函数';
4113
3769
  }
4114
-
4115
3770
  if (!tmsConfig.cloudDir) {
4116
3771
  return '你没有在tms.config.js配置云函数编译目录cloudDir';
4117
3772
  }
4118
-
4119
3773
  return;
4120
3774
  }
3775
+
4121
3776
  /**
4122
3777
  * 检查云函数源码目录是否存在
4123
3778
  * @param {Array} clouds [{name: '', sourcePath: '', targetPath: ''}]
4124
3779
  */
4125
-
4126
-
4127
3780
  function checkSrcPathIsExist$1(clouds) {
4128
3781
  for (const item of clouds) {
4129
3782
  if (!fs$3.existsSync(item.sourcePath)) {
4130
3783
  return `${item.name}云函数的${item.sourcePath}目录不存在, 请检查tms.config.js>cloudModules>all云函数的配置目录`;
4131
3784
  }
4132
3785
  }
4133
-
4134
3786
  return;
4135
3787
  }
4136
-
4137
3788
  var check$2 = {
4138
3789
  checkCloudConfig: checkCloudConfig$2,
4139
3790
  checkSrcPathIsExist: checkSrcPathIsExist$1
@@ -4160,23 +3811,21 @@ const {
4160
3811
  const {
4161
3812
  checkCloudConfig: checkCloudConfig$1
4162
3813
  } = check$2;
4163
-
4164
3814
  var link = async (tmsConfig, cmdOptions) => {
4165
3815
  try {
4166
3816
  ensureDirExist$2(resolve$3(tmsConfig.cloudDir));
4167
- checkCloudConfig$1(tmsConfig); // 获取需要监听的云函数列表
4168
-
4169
- const clouds = getCloudsOfListen$1(tmsConfig, cmdOptions); // 打印启动云函数列表
3817
+ checkCloudConfig$1(tmsConfig);
4170
3818
 
3819
+ // 获取需要监听的云函数列表
3820
+ const clouds = getCloudsOfListen$1(tmsConfig, cmdOptions);
3821
+ // 打印启动云函数列表
4171
3822
  info$4('当前启动云函数列表:', clouds.map(item => item.name).sort());
4172
3823
  clouds.forEach(item => {
4173
3824
  if (!fs$2.existsSync(item.sourcePath)) {
4174
3825
  warn(`云函数${item.sourcePath}不存在`);
4175
3826
  return;
4176
3827
  }
4177
-
4178
3828
  const stat = fs$2.lstatSync(item.targetPath);
4179
-
4180
3829
  if (!stat.isSymbolicLink()) {
4181
3830
  fs$2.symlinkSync(item.sourcePath, item.targetPath);
4182
3831
  }
@@ -4200,18 +3849,16 @@ const {
4200
3849
  const {
4201
3850
  info: info$3
4202
3851
  } = log$1;
3852
+
4203
3853
  /**
4204
3854
  * npm install
4205
3855
  * @param {array} clouds [{name: '', sourcePath: '', targetPath: ''}]
4206
3856
  */
4207
-
4208
3857
  const runInstall$1 = async (clouds, tmsConfig) => {
4209
3858
  const promises = [];
4210
-
4211
3859
  for (const item of clouds) {
4212
3860
  ensureDirExist$1(item.targetPath);
4213
3861
  const packageFilePath = resolve$2(item.sourcePath, 'package.json');
4214
-
4215
3862
  if (fs$1.existsSync(packageFilePath)) {
4216
3863
  shellJs$1.cp('-Rf', resolve$2(packageFilePath), item.targetPath);
4217
3864
  promises.push(() => {
@@ -4222,7 +3869,6 @@ const runInstall$1 = async (clouds, tmsConfig) => {
4222
3869
  }
4223
3870
  await Promise.all(promises.map(item => item()));
4224
3871
  };
4225
-
4226
3872
  var install$1 = {
4227
3873
  runInstall: runInstall$1
4228
3874
  };
@@ -4260,13 +3906,13 @@ const {
4260
3906
  const {
4261
3907
  runInstall
4262
3908
  } = install$1;
3909
+
4263
3910
  /**
4264
3911
  * 获取云函数的编译任务
4265
3912
  * @param {array} clouds [{name: '', sourcePath: '', targetPath: ''}]
4266
3913
  * @param {object} srcOption gulp.src的参数
4267
3914
  * @returns Map {'${sourcePath}': {taskFn: () => {}, targetPath: 'xxx'}}
4268
3915
  */
4269
-
4270
3916
  const getCompileTasks = (clouds, srcOption) => {
4271
3917
  const compileTasksMap = new Map();
4272
3918
  clouds.forEach(item => {
@@ -4284,18 +3930,16 @@ const getCompileTasks = (clouds, srcOption) => {
4284
3930
  });
4285
3931
  return compileTasksMap;
4286
3932
  };
4287
-
4288
3933
  const getTargetFile = (sourceFile, sourcePath, targetPath) => {
4289
3934
  const sourceFileRelativeModule = path$1.relative(sourcePath, sourceFile);
4290
3935
  const targetFile = resolve$1(targetPath, sourceFileRelativeModule);
4291
3936
  return targetFile;
4292
3937
  };
3938
+
4293
3939
  /**
4294
3940
  * 开始启动编译
4295
3941
  * @param {Map} compileTasksMap {'${sourcePath}': {taskFn: () => {}, targetPath: 'xxx'}}
4296
3942
  */
4297
-
4298
-
4299
3943
  const runCompile = (compileTasksMap, callback) => {
4300
3944
  async function end(next) {
4301
3945
  // 监听其他文件
@@ -4311,16 +3955,16 @@ const runCompile = (compileTasksMap, callback) => {
4311
3955
  callback && callback();
4312
3956
  next();
4313
3957
  }
4314
-
4315
3958
  const compileTasksArr = [];
4316
3959
  compileTasksMap.forEach(({
4317
3960
  taskFn
4318
3961
  }) => {
4319
3962
  compileTasksArr.push(taskFn);
4320
- }); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
4321
-
3963
+ });
3964
+ // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
4322
3965
  series(parallel(...compileTasksArr), end)();
4323
3966
  };
3967
+
4324
3968
  /**
4325
3969
  * 监听文件变动
4326
3970
  * @param {*} sourcePath 云函数的源码目录
@@ -4328,55 +3972,53 @@ const runCompile = (compileTasksMap, callback) => {
4328
3972
  * @param {*} callback 监听到变动的回调
4329
3973
  * @param {*} targetPath 云函数的编译目录
4330
3974
  */
4331
-
4332
-
4333
3975
  const runWatch = (sourcePath, watchOptions, callback, targetPath) => {
4334
- watch(sourcePath, { ...watchOptions
3976
+ watch(sourcePath, {
3977
+ ...watchOptions
4335
3978
  }, vinyl => {
4336
3979
  const sourceFile = vinyl.history[0];
4337
3980
  const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
4338
3981
  const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
4339
3982
  const targetFile = getTargetFile(sourceFile, sourcePath, targetPath);
4340
-
4341
3983
  if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
4342
3984
  info$2(`删除${sourceFileName}`);
4343
3985
  shellJs.rm('-rf', targetFile);
4344
3986
  return;
4345
3987
  }
4346
-
4347
3988
  info$2(`${sourceFileName}有更新`);
4348
3989
  return callback([sourceFile], path$1.dirname(targetFile));
4349
3990
  });
4350
3991
  };
4351
-
4352
3992
  var dev$1 = async (tmsConfig, cmdOptions) => {
4353
3993
  try {
4354
3994
  const sTime = new Date().getTime();
4355
3995
  const spinner = ora();
4356
- spinner.start(); // 检查云函数的配置项
3996
+ spinner.start();
4357
3997
 
3998
+ // 检查云函数的配置项
4358
3999
  const configErrMsg = checkCloudConfig(tmsConfig);
4359
-
4360
4000
  if (configErrMsg) {
4361
4001
  throw new Error(configErrMsg);
4362
- } // 确保云函数的编译目录存在
4363
-
4364
-
4365
- ensureDirExist(resolve$1(tmsConfig.cloudDir)); // 获取需要监听的云函数列表
4002
+ }
4366
4003
 
4367
- const clouds = getCloudsOfListen(tmsConfig, cmdOptions); // 检查云函数源码目录是否存在
4004
+ // 确保云函数的编译目录存在
4005
+ ensureDirExist(resolve$1(tmsConfig.cloudDir));
4368
4006
 
4007
+ // 获取需要监听的云函数列表
4008
+ const clouds = getCloudsOfListen(tmsConfig, cmdOptions);
4009
+ // 检查云函数源码目录是否存在
4369
4010
  const srcNotExistErrMsg = checkSrcPathIsExist(clouds);
4370
-
4371
4011
  if (srcNotExistErrMsg) {
4372
4012
  throw new Error(srcNotExistErrMsg);
4373
- } // 打印启动云函数列表
4374
-
4013
+ }
4375
4014
 
4376
- info$2('当前启动云函数列表:', clouds.map(item => item.name).sort()); // npm install
4015
+ // 打印启动云函数列表
4016
+ info$2('当前启动云函数列表:', clouds.map(item => item.name).sort());
4377
4017
 
4378
- await createTask(runInstall, '开始npm install', 'npm install完成')(clouds, tmsConfig); // 获取云函数列表的编译任务
4018
+ // npm install
4019
+ await createTask(runInstall, '开始npm install', 'npm install完成')(clouds, tmsConfig);
4379
4020
 
4021
+ // 获取云函数列表的编译任务
4380
4022
  const compileTasksMap = getCompileTasks(clouds, {
4381
4023
  allowEmpty: true
4382
4024
  });
@@ -4415,13 +4057,11 @@ const {
4415
4057
  getSubPackages,
4416
4058
  getModulesByModuleNames
4417
4059
  } = tmsMpconfig.exports;
4418
-
4419
4060
  const handleModuleArg = cmdOptions => {
4420
4061
  // 单模块或多模块开发-用户通过脚手架参数指定的模块
4421
4062
  if (typeof cmdOptions.module === 'string') {
4422
4063
  return cmdOptions.module.split(',');
4423
4064
  }
4424
-
4425
4065
  return [];
4426
4066
  };
4427
4067
  /**
@@ -4430,47 +4070,38 @@ const handleModuleArg = cmdOptions => {
4430
4070
  * @param {Object} modulePrivateCfg 私有配置里的模块
4431
4071
  * @param {Array} moduleAll 当前小程序全部模块
4432
4072
  */
4433
-
4434
-
4435
4073
  const getSpecificModuleNames = (moduleArg, modules) => {
4436
4074
  if (moduleArg.length > 0) {
4437
4075
  return moduleArg;
4438
4076
  }
4439
-
4440
4077
  const {
4441
4078
  all,
4442
4079
  include,
4443
4080
  exclude,
4444
4081
  blockRemote
4445
- } = modules; // 单模块或多模块开发-用户在tms.private.js指定的模块
4446
-
4082
+ } = modules;
4083
+ // 单模块或多模块开发-用户在tms.private.js指定的模块
4447
4084
  if ((include === null || include === void 0 ? void 0 : include.length) > 0) {
4448
4085
  return include;
4449
4086
  }
4450
-
4451
4087
  if ((exclude === null || exclude === void 0 ? void 0 : exclude.length) > 0) {
4452
4088
  return all.filter(module => !exclude.includes(module.moduleName)).map(item => item.moduleName);
4453
4089
  }
4454
-
4455
4090
  if (blockRemote === true) {
4456
4091
  return all.filter(module => module.repoInfo === undefined).map(item => item.moduleName);
4457
4092
  }
4458
-
4459
4093
  return all.map(item => item.moduleName);
4460
4094
  };
4461
-
4462
4095
  async function run(commandName, cmdOptions) {
4463
- global.setData('commandName', commandName); // 用户本地的配置
4464
-
4096
+ global.setData('commandName', commandName);
4097
+ // 用户本地的配置
4465
4098
  const tmsConfig = getTmsConfig$1();
4466
-
4467
4099
  try {
4468
4100
  // 缓存数据
4469
4101
  global.setData({
4470
4102
  cmdOptions,
4471
4103
  tmsConfig
4472
4104
  });
4473
-
4474
4105
  if (commandName === 'cloud-link') {
4475
4106
  cloudLink(tmsConfig, cmdOptions);
4476
4107
  report$1('run:cloud-link', {
@@ -4478,7 +4109,6 @@ async function run(commandName, cmdOptions) {
4478
4109
  });
4479
4110
  return;
4480
4111
  }
4481
-
4482
4112
  if (commandName === 'cloud-dev') {
4483
4113
  cloudDev(tmsConfig, cmdOptions);
4484
4114
  report$1('run:cloud-dev', {
@@ -4486,7 +4116,6 @@ async function run(commandName, cmdOptions) {
4486
4116
  });
4487
4117
  return;
4488
4118
  }
4489
-
4490
4119
  otherCommands(tmsConfig, commandName, cmdOptions);
4491
4120
  } catch (error) {
4492
4121
  const errMsg = typeof error === 'object' ? error.message : error;
@@ -4499,18 +4128,18 @@ async function run(commandName, cmdOptions) {
4499
4128
  process.exit(1);
4500
4129
  }
4501
4130
  }
4502
-
4503
4131
  function otherCommands(tmsConfig, commandName, cmdOptions) {
4504
4132
  // 处理module参数
4505
- const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmdOptions), tmsConfig.modules); // moduleNames => ['home', 'car']
4133
+ const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmdOptions), tmsConfig.modules);
4506
4134
 
4135
+ // moduleNames => ['home', 'car']
4507
4136
  const moduleNames = [...new Set([...specificModuleNames])];
4508
- const modules = getModulesByModuleNames(tmsConfig, moduleNames, false); // 获取所有模块,合并模块依赖的模块
4509
-
4510
- const newModules = getModulesByMergeDepModules(tmsConfig, modules, false); // 获取所有的分包
4137
+ const modules = getModulesByModuleNames(tmsConfig, moduleNames, false);
4511
4138
 
4139
+ // 获取所有模块,合并模块依赖的模块
4140
+ const newModules = getModulesByMergeDepModules(tmsConfig, modules, false);
4141
+ // 获取所有的分包
4512
4142
  const subPackages = getSubPackages(newModules);
4513
-
4514
4143
  switch (commandName) {
4515
4144
  case 'init':
4516
4145
  init(tmsConfig, newModules);
@@ -4518,7 +4147,6 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
4518
4147
  appName: tmsConfig.appName
4519
4148
  });
4520
4149
  return;
4521
-
4522
4150
  case 'dev':
4523
4151
  global.setData('isDev', true);
4524
4152
  dev(tmsConfig, newModules);
@@ -4526,14 +4154,12 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
4526
4154
  appName: tmsConfig.appName
4527
4155
  });
4528
4156
  return;
4529
-
4530
4157
  case 'install':
4531
4158
  install(tmsConfig, subPackages, false);
4532
4159
  report$1('run:install', {
4533
4160
  appName: tmsConfig.appName
4534
4161
  });
4535
4162
  return;
4536
-
4537
4163
  case 'build':
4538
4164
  global.setData('isDev', false);
4539
4165
  build(tmsConfig, newModules);
@@ -4541,33 +4167,28 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
4541
4167
  appName: tmsConfig.appName
4542
4168
  });
4543
4169
  return;
4544
-
4545
4170
  case 'preview':
4546
4171
  preview(tmsConfig, cmdOptions);
4547
4172
  report$1('run:preview', {
4548
4173
  appName: tmsConfig.appName
4549
4174
  });
4550
4175
  return;
4551
-
4552
4176
  case 'upload':
4553
4177
  upload(tmsConfig, cmdOptions);
4554
4178
  report$1('run:upload', {
4555
4179
  appName: tmsConfig.appName
4556
4180
  });
4557
4181
  return;
4558
-
4559
4182
  case 'sourcemap':
4560
4183
  sourcemap(tmsConfig);
4561
4184
  report$1('run:sourcemap', {
4562
4185
  appName: tmsConfig.appName
4563
4186
  });
4564
4187
  return;
4565
-
4566
4188
  default:
4567
4189
  return;
4568
4190
  }
4569
4191
  }
4570
-
4571
4192
  var run_1 = run;
4572
4193
 
4573
4194
  var entry = [{
@@ -4637,7 +4258,8 @@ var entry = [{
4637
4258
  action: cmdOptions => {
4638
4259
  run_1('cloud-dev', cmdOptions);
4639
4260
  }
4640
- } // {
4261
+ }
4262
+ // {
4641
4263
  // command: 'cloud-link',
4642
4264
  // description: '云函数开发',
4643
4265
  // options: [
@@ -4652,7 +4274,7 @@ var entry = [{
4652
4274
 
4653
4275
  var require$$12 = {
4654
4276
  name: "@tmsfe/tmskit",
4655
- version: "0.0.52",
4277
+ version: "0.0.53",
4656
4278
  description: "tmskit",
4657
4279
  main: "dist/index.cjs",
4658
4280
  bin: {
@@ -4747,13 +4369,13 @@ const {
4747
4369
  } = log$1;
4748
4370
  const requiredVersion = packageJson.engines.node;
4749
4371
  const packName = packageJson.name;
4372
+
4750
4373
  /**
4751
4374
  * 检查node版本
4752
4375
  * @param {String} wanted 希望的node版本
4753
4376
  * @param {String} id 某node特性
4754
4377
  * @returns {Undefined} 无需返回值
4755
4378
  */
4756
-
4757
4379
  const checkNodeVersion = (wanted, id) => {
4758
4380
  if (!semver.satisfies(process.version, wanted, {
4759
4381
  includePrerelease: true
@@ -4762,17 +4384,15 @@ const checkNodeVersion = (wanted, id) => {
4762
4384
  process.exit(1);
4763
4385
  }
4764
4386
  };
4387
+
4765
4388
  /**
4766
4389
  * 检查运行环境
4767
4390
  */
4768
-
4769
-
4770
4391
  function check$1() {
4771
4392
  // 执行操作前检查node版本
4772
4393
  // 旧版本node直接提示升级,退出脚本
4773
4394
  checkNodeVersion(requiredVersion, packName);
4774
4395
  }
4775
-
4776
4396
  var check_1 = check$1;
4777
4397
 
4778
4398
  /* eslint-disable no-param-reassign */
@@ -4800,8 +4420,9 @@ const {
4800
4420
  const report = report_1;
4801
4421
  check();
4802
4422
  const program = new commander.Command(TMS_NAME);
4803
- program.version(`${TMS_NAME} ${require$$12.version}`, '-v, -V, --version'); // 注册命令底层实现
4423
+ program.version(`${TMS_NAME} ${require$$12.version}`, '-v, -V, --version');
4804
4424
 
4425
+ // 注册命令底层实现
4805
4426
  function registerCommand(program, commands) {
4806
4427
  commands.forEach(cmd => {
4807
4428
  if (cmd.type === 'parent') {
@@ -4812,56 +4433,53 @@ function registerCommand(program, commands) {
4812
4433
  program.addCommand(childProgram);
4813
4434
  } else {
4814
4435
  var _cmd$options;
4815
-
4816
4436
  const command = program.command(cmd.command);
4817
4437
  cmd.usage && command.usage(cmd.usage);
4818
4438
  cmd.description && command.description(cmd.description);
4819
- (_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt)); // 上报
4820
-
4439
+ (_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
4440
+ // 上报
4821
4441
  command.hook('preAction', thisCommand => {
4822
4442
  report(`${thisCommand._name}-pre`);
4823
- }); // 上报
4824
-
4443
+ });
4444
+ // 上报
4825
4445
  command.hook('postAction', thisCommand => {
4826
4446
  report(`${thisCommand._name}-post`);
4827
4447
  });
4828
4448
  command.action(cmd.action);
4829
4449
  }
4830
4450
  });
4831
- } // 注册扩展命令
4832
-
4451
+ }
4833
4452
 
4453
+ // 注册扩展命令
4834
4454
  function registerExtendCommand(program, configPath) {
4835
4455
  const tmsConfig = getTmsConfig(configPath);
4836
-
4837
4456
  if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.commands) {
4838
4457
  const commands = typeof tmsConfig.commands === 'function' ? tmsConfig.commands() : tmsConfig.commands;
4839
-
4840
4458
  if (Array.isArray(commands)) {
4841
4459
  registerCommand(program, commands);
4842
4460
  }
4843
4461
  }
4844
- } // 注册所有的命令
4845
-
4846
-
4462
+ }
4463
+ // 注册所有的命令
4847
4464
  function registerAllCmds(program, commands) {
4848
4465
  // 注册脚手架内部命令
4849
- registerCommand(program, commands); // 注册npm包扩展命令
4466
+ registerCommand(program, commands);
4850
4467
 
4468
+ // 注册npm包扩展命令
4851
4469
  const cmdConfigs = loadExtendCmd();
4852
4470
  cmdConfigs.forEach(cmdConfig => {
4853
4471
  registerExtendCommand(program, path.dirname(cmdConfig));
4854
- }); // 注册当前目录扩展命令
4472
+ });
4855
4473
 
4474
+ // 注册当前目录扩展命令
4856
4475
  const tmsConfigPath = resolve('./tms.config.js');
4857
-
4858
4476
  if (fs.existsSync(tmsConfigPath)) {
4859
4477
  registerExtendCommand(program, path.dirname(tmsConfigPath));
4860
4478
  }
4861
4479
  }
4480
+ registerAllCmds(program, commands);
4862
4481
 
4863
- registerAllCmds(program, commands); // 捕获未注册的命令
4864
-
4482
+ // 捕获未注册的命令
4865
4483
  program.arguments('<command>').option('-c, --config <value>', '配置', value => {
4866
4484
  // 注册指定配置的扩展命令
4867
4485
  registerExtendCommand(program, path.dirname(resolve(value)));
@@ -4876,12 +4494,10 @@ program.arguments('<command>').option('-c, --config <value>', '配置', value =>
4876
4494
  program.on('--help', () => {
4877
4495
  infoNoTime(`Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
4878
4496
  });
4879
-
4880
4497
  if (!process.argv.slice(2).length) {
4881
4498
  program.outputHelp();
4882
4499
  process.exit(-1);
4883
4500
  }
4884
-
4885
4501
  program.parse(process.argv);
4886
4502
  var src = src$3;
4887
4503