@tmsfe/tmskit 0.0.18 → 0.0.21

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
@@ -8,14 +8,16 @@ var require$$2 = require('ora');
8
8
  var require$$1$2 = require('path');
9
9
  var require$$0$2 = require('fs');
10
10
  var require$$0$3 = require('shelljs');
11
- var require$$0$4 = require('async');
11
+ var require$$6 = require('glob-ignore');
12
+ var require$$0$4 = require('lodash');
13
+ var require$$0$5 = require('async');
12
14
  var require$$1$3 = require('ejs');
13
15
  var require$$1$4 = require('inquirer');
14
- var require$$0$5 = require('metalsmith');
15
- var require$$0$6 = require('lodash');
16
+ var require$$0$6 = require('metalsmith');
17
+ var require$$9$1 = require('request');
18
+ var require$$10 = require('unzipper');
16
19
  var require$$1$5 = require('crypto');
17
20
  var require$$0$7 = require('miniprogram-ci');
18
- var require$$5 = require('glob-ignore');
19
21
  var require$$1$6 = require('fs-extra');
20
22
  var require$$1$7 = require('semver');
21
23
  var require$$0$8 = require('strip-comments');
@@ -25,15 +27,15 @@ var require$$1$9 = require('htmlparser2');
25
27
  var require$$0$a = require('gulp');
26
28
  var require$$0$b = require('object-assign');
27
29
  var require$$3 = require('fancy-log');
28
- var require$$4$1 = require('ansi-colors');
30
+ var require$$4 = require('ansi-colors');
29
31
  var require$$5$1 = require('chokidar');
30
- var require$$6 = require('readable-stream');
31
- var require$$7$1 = require('vinyl-file');
32
+ var require$$6$1 = require('readable-stream');
33
+ var require$$7 = require('vinyl-file');
32
34
  var require$$8 = require('vinyl');
33
- var require$$9 = require('anymatch');
35
+ var require$$9$2 = require('anymatch');
34
36
  var require$$11 = require('glob-parent');
35
37
  var require$$2$1 = require('plugin-error');
36
- var require$$10 = require('path-is-absolute');
38
+ var require$$10$1 = require('path-is-absolute');
37
39
  var require$$12 = require('slash');
38
40
 
39
41
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
@@ -46,14 +48,16 @@ var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
46
48
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
47
49
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
48
50
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
51
+ var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
49
52
  var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
53
+ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
50
54
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
51
55
  var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
52
- var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
53
56
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
57
+ var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9$1);
58
+ var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
54
59
  var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
55
60
  var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
56
- var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
57
61
  var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
58
62
  var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
59
63
  var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
@@ -63,15 +67,15 @@ var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
63
67
  var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
64
68
  var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
65
69
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
66
- var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
67
- var require$$5__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
68
- var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
69
- var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7$1);
70
+ var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
71
+ var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
72
+ var require$$6__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
73
+ var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
70
74
  var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
71
- var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
75
+ var require$$9__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$9$2);
72
76
  var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
73
77
  var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
74
- var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
78
+ var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
75
79
  var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12);
76
80
 
77
81
  function getAugmentedNamespace(n) {
@@ -91,7 +95,7 @@ function getAugmentedNamespace(n) {
91
95
 
92
96
  var src$2 = {};
93
97
 
94
- const chalk$3 = require$$0__default;
98
+ const chalk$4 = require$$0__default;
95
99
  const moment = require$$1__default;
96
100
  /**
97
101
  * 本文件提供无依赖的在终端打印彩色文字的方法。
@@ -134,28 +138,29 @@ const succeed$2 = (message = '') => {
134
138
 
135
139
 
136
140
  const warn$2 = message => {
137
- console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
141
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$4.yellow(message));
138
142
  };
139
143
 
140
- const info$9 = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
144
+ const info$d = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
141
145
 
142
146
  var log$1 = {
143
147
  fail: fail$9,
144
148
  succeed: succeed$2,
145
149
  warn: warn$2,
146
- info: info$9
150
+ info: info$d
147
151
  };
148
152
 
149
153
  const program$1 = require$$0__default$1;
150
154
  const leven = require$$1__default$1;
151
- const ora = require$$2__default;
152
- const path$b = require$$1__default$2;
153
- const fs$e = require$$0__default$2;
155
+ const ora$1 = require$$2__default;
156
+ const path$e = require$$1__default$2;
157
+ const fs$h = require$$0__default$2;
154
158
  const shelljs$7 = require$$0__default$3;
159
+ const glob$1 = require$$6__default;
155
160
  const {
156
- info: info$8
161
+ info: info$c
157
162
  } = log$1;
158
- const chalk$2 = require$$0__default;
163
+ const chalk$3 = require$$0__default;
159
164
  const shelljsOptions = {
160
165
  slient: true,
161
166
  async: false
@@ -163,8 +168,8 @@ const shelljsOptions = {
163
168
 
164
169
  const cwd = process.cwd();
165
170
 
166
- function resolve$f(...args) {
167
- return path$b.resolve(cwd, ...args);
171
+ function resolve$g(...args) {
172
+ return path$e.resolve(cwd, ...args);
168
173
  }
169
174
  /**
170
175
  * 用户输入命令时,进行提示
@@ -184,7 +189,7 @@ const suggestCommands$1 = unknownCommand => {
184
189
  });
185
190
 
186
191
  if (suggestion) {
187
- info$8(` ${chalk$2.red(`Did you mean ${chalk$2.yellow(suggestion)}?`)}`);
192
+ info$c(` ${chalk$3.red(`Did you mean ${chalk$3.yellow(suggestion)}?`)}`);
188
193
  }
189
194
  };
190
195
  /**
@@ -194,7 +199,7 @@ const suggestCommands$1 = unknownCommand => {
194
199
  */
195
200
 
196
201
 
197
- function isObject$2(obj) {
202
+ function isObject(obj) {
198
203
  return Object.prototype.toString.call(obj) === '[object Object]';
199
204
  }
200
205
  /**
@@ -204,7 +209,7 @@ function isObject$2(obj) {
204
209
  */
205
210
 
206
211
 
207
- function isArray$1(obj) {
212
+ function isArray(obj) {
208
213
  return Object.prototype.toString.call(obj) === '[object Array]';
209
214
  }
210
215
  /**
@@ -216,12 +221,12 @@ function isArray$1(obj) {
216
221
  */
217
222
 
218
223
 
219
- function downloadRepoForGit$2(url, dest, branch) {
224
+ function downloadRepoForGit$1(url, dest, branch) {
220
225
  const cwd = process.cwd();
221
226
  return new Promise((resolve, reject) => {
222
227
  // 如果目标目录不存在
223
- if (fs$e.existsSync(dest)) {
224
- shelljs$7.rm('-rf', path$b.join(dest));
228
+ if (fs$h.existsSync(dest)) {
229
+ shelljs$7.rm('-rf', path$e.join(dest));
225
230
  }
226
231
 
227
232
  shelljs$7.mkdir('-p', dest);
@@ -270,7 +275,7 @@ function pullRepoForGit$1(dest, branch) {
270
275
  */
271
276
 
272
277
 
273
- function npmInstall$1(dir) {
278
+ function npmInstall$2(dir) {
274
279
  return new Promise((resolve, reject) => {
275
280
  shelljs$7.exec('npm install --production --registry http://mirrors.tencent.com/npm/', {
276
281
  cwd: dir,
@@ -301,11 +306,11 @@ const cost = start => Date.now() - start;
301
306
  */
302
307
 
303
308
 
304
- function createTask$3(task, startText, endText) {
309
+ function createTask$2(task, startText, endText) {
305
310
  return async (...args) => {
306
311
  const start = Date.now();
307
- const spinner = ora();
308
- info$8(startText);
312
+ const spinner = ora$1();
313
+ info$c(startText);
309
314
  spinner.start();
310
315
  const result = await task(...args);
311
316
  endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
@@ -321,7 +326,7 @@ function createTask$3(task, startText, endText) {
321
326
 
322
327
  const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
323
328
 
324
- const mergeMap = function (obj, src) {
329
+ const mergeMap$1 = function (obj, src) {
325
330
  for (const [k, v] of src) {
326
331
  if (obj.has(k)) {
327
332
  obj.set(k, obj.get(k) + v);
@@ -334,7 +339,7 @@ const mergeMap = function (obj, src) {
334
339
  };
335
340
 
336
341
  const relativeCwdPath$1 = function (file) {
337
- return path$b.relative(process.cwd(), file);
342
+ return path$e.relative(process.cwd(), file);
338
343
  };
339
344
  /**
340
345
  * 从一个对象中,检索出去几个字段
@@ -344,7 +349,7 @@ const relativeCwdPath$1 = function (file) {
344
349
  */
345
350
 
346
351
 
347
- const filterField$3 = (obj, filterNames = []) => {
352
+ const filterField$4 = (obj, filterNames = []) => {
348
353
  const newObj = { ...obj
349
354
  };
350
355
  filterNames.forEach(name => {
@@ -353,85 +358,474 @@ const filterField$3 = (obj, filterNames = []) => {
353
358
  }
354
359
  });
355
360
  return newObj;
356
- };
361
+ }; // 检索出文件列表
362
+
363
+
364
+ function findFiles(globPath, filter = []) {
365
+ return new Promise((resolve, reject) => {
366
+ glob$1(globPath, filter, (err, files) => {
367
+ if (err) {
368
+ reject(err);
369
+ }
370
+
371
+ resolve(files);
372
+ });
373
+ });
374
+ } // 获取绝对路径
375
+
376
+
377
+ function getAbsolutePath$3(pathDir, cwd = '') {
378
+ let newPath = pathDir;
379
+ newPath = newPath.startsWith('/') ? newPath : resolve$g(cwd, newPath);
380
+ newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
381
+ return newPath;
382
+ }
357
383
 
358
384
  var widgets = {
359
- resolve: resolve$f,
360
- isObject: isObject$2,
361
- isArray: isArray$1,
362
- createTask: createTask$3,
363
- downloadRepoForGit: downloadRepoForGit$2,
385
+ resolve: resolve$g,
386
+ isObject,
387
+ isArray,
388
+ createTask: createTask$2,
389
+ downloadRepoForGit: downloadRepoForGit$1,
364
390
  pullRepoForGit: pullRepoForGit$1,
365
391
  suggestCommands: suggestCommands$1,
366
392
  camelize,
367
- npmInstall: npmInstall$1,
368
- mergeMap,
393
+ npmInstall: npmInstall$2,
394
+ mergeMap: mergeMap$1,
369
395
  relativeCwdPath: relativeCwdPath$1,
370
- filterField: filterField$3
396
+ filterField: filterField$4,
397
+ findFiles,
398
+ getAbsolutePath: getAbsolutePath$3
371
399
  };
372
400
 
373
- const path$a = require('path');
401
+ var tmsMpconfig = {exports: {}};
402
+
403
+ const path$d = require('path');
374
404
 
375
405
  const os = require('os'); // 用户目录
376
406
 
377
407
 
378
408
  const HOME_DIR = os.homedir(); // 所有文件的缓存目录
379
409
 
380
- const CACHE_DIR$2 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
410
+ const CACHE_DIR$3 = path$d.resolve(HOME_DIR, '.tmskit'); // 缓存文件
411
+
412
+ const CACHE_FILE$1 = 'cache_file.json'; // 脚手架模板代码所在目录
381
413
 
382
- const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
414
+ const TEMPLATE_DIR$1 = path$d.resolve(CACHE_DIR$3, 'template'); // 模板的名称
383
415
 
384
- const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
416
+ const TEMPLATE_NAME$1 = 'tmskit-template'; // 第三方模块源码存放的临时缓存目录
385
417
 
386
- const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tmskit-template'); // 脚手架的名称
418
+ const MODULE_CODE_DIR$1 = path$d.resolve(CACHE_DIR$3, 'modules_code'); // 脚手架模板的远程地址
419
+
420
+ const TEMPLATE_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip'; // 脚手架的名称
387
421
 
388
422
  const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
389
423
 
390
- const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
391
- const TMS_PRIVATE_FILENAME$1 = 'tms.private.config.js'; // 模块代码的默认在modules子目录
424
+ const TMS_CONFIG_FILENAME = 'tms.config.js';
425
+ const TMS_PRIVATE_FILENAME = 'tms.private.config.js'; // 模块代码的默认在modules子目录
392
426
 
393
427
  const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目录
394
428
 
395
429
  const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
396
430
 
397
- const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
431
+ const MODULE_CONFIG_FILENAME = 'module.config.json'; // 默认的webpack entry
398
432
 
399
433
  const DEFAULT_WEBPACK_ENTRY = {
400
- app: path$a.resolve(process.cwd(), 'app')
434
+ app: path$d.resolve(process.cwd(), 'app')
401
435
  }; // 默认从源码拷贝到编译后的配置
402
436
 
403
- const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
437
+ const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json'];
404
438
  const ENV = {
405
439
  dev: 'development',
406
440
  prod: 'production'
407
441
  };
408
442
  const TEMPLATE_TKIT_DIR$2 = '_tmskit';
443
+ const CREATE_TEMPLATE_QUESTION$1 = [{
444
+ type: 'list',
445
+ name: 'projectType',
446
+ message: '选择你要创建的模板',
447
+ choices: [{
448
+ name: '小程序项目',
449
+ value: 'mp'
450
+ }, {
451
+ name: '小程序模块',
452
+ value: 'mp-module'
453
+ }]
454
+ }];
409
455
 
410
456
  var constant = /*#__PURE__*/Object.freeze({
411
457
  __proto__: null,
412
458
  HOME_DIR: HOME_DIR,
413
- CACHE_DIR: CACHE_DIR$2,
459
+ CACHE_DIR: CACHE_DIR$3,
460
+ CACHE_FILE: CACHE_FILE$1,
414
461
  TEMPLATE_DIR: TEMPLATE_DIR$1,
415
- TEMPLATE_PATH: TEMPLATE_PATH$1,
462
+ TEMPLATE_NAME: TEMPLATE_NAME$1,
416
463
  TMS_NAME: TMS_NAME$1,
417
- TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
418
- TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME$1,
464
+ TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME,
465
+ TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME,
419
466
  DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
420
- MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
467
+ MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME,
421
468
  DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
422
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
469
+ DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
423
470
  MODULE_CODE_DIR: MODULE_CODE_DIR$1,
424
471
  ENV: ENV,
425
472
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
426
- DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
473
+ DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR,
474
+ CREATE_TEMPLATE_QUESTION: CREATE_TEMPLATE_QUESTION$1,
475
+ TEMPLATE_URL: TEMPLATE_URL$1
427
476
  });
428
477
 
429
- var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
478
+ var require$$5 = /*@__PURE__*/getAugmentedNamespace(constant);
430
479
 
431
- const fs$d = require$$0__default$2;
432
- const path$9 = require$$1__default$2;
480
+ var defaultTmsConfig = {
481
+ // 全局的环境配置项
482
+ envData: {},
483
+ // 模块配置信息
484
+ modules: {},
485
+ cloudDir: 'cloud',
486
+ // 第三方依赖代码需要拷贝到本项目的
487
+ dependencies: {},
488
+
489
+ /** 编译输出文件夹位置 */
490
+ outputDir: 'dist',
491
+
492
+ /** 源码监听路径 */
493
+ sourceDir: './',
494
+
495
+ /** 静态资源目录 */
496
+ static: []
497
+ };
498
+
499
+ /**
500
+ * 用来读取处理tms.config.js与module.config.json字段
501
+ */
502
+
503
+ (function (module) {
504
+ /* eslint-disable no-param-reassign, no-nested-ternary */
505
+ const loadash = require$$0__default$4;
506
+ const fs = require$$0__default$2;
507
+ const path = require$$1__default$2;
508
+ const {
509
+ TMS_CONFIG_FILENAME,
510
+ MODULE_CONFIG_FILENAME,
511
+ TMS_PRIVATE_FILENAME
512
+ } = require$$5;
513
+ const {
514
+ resolve,
515
+ isObject,
516
+ isArray,
517
+ getAbsolutePath
518
+ } = widgets;
519
+ const defaultTmsConfig$1 = defaultTmsConfig;
520
+ const {
521
+ fail
522
+ } = log$1;
523
+ /**
524
+ * 读取tms.config.js
525
+ * @param env {string} 环境变量
526
+ */
527
+
528
+ const readTmsConfig = function () {
529
+ const tmsConfigPath = resolve(TMS_CONFIG_FILENAME);
530
+
531
+ if (!fs.existsSync(tmsConfigPath)) {
532
+ fail('当前执行目录没有tms.config.js的配置项,请进行配置');
533
+ process.exit(1);
534
+ }
535
+
536
+ const tmsConfigFn = require(tmsConfigPath);
537
+
538
+ const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn() : tmsConfigFn; // 合并默认值
539
+
540
+ return loadash.mergeWith(defaultTmsConfig$1, tmsConfig);
541
+ };
542
+ /**
543
+ * 读取tms.private.config.js
544
+ */
545
+
546
+
547
+ const readTmsPrivateCf = function () {
548
+ let tmsPrivateCf = {};
549
+ const tmsPrivatePath = resolve(TMS_PRIVATE_FILENAME);
550
+
551
+ if (fs.existsSync(tmsPrivatePath)) {
552
+ const tmsPrivateFn = require(tmsPrivatePath);
553
+
554
+ tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn() : tmsPrivateFn;
555
+ }
556
+
557
+ return tmsPrivateCf;
558
+ };
559
+ /**
560
+ * 获取tms.config.js, tms.private.config.js的配置项
561
+ * @returns
562
+ */
563
+
564
+
565
+ const getTmsConfig = () => {
566
+ const tmsPrivateCf = readTmsPrivateCf();
567
+ const tmsConfig = readTmsConfig();
568
+ const modules = {};
569
+
570
+ if (Array.isArray(tmsConfig.modules)) {
571
+ modules.all = tmsConfig.modules;
572
+ tmsConfig.modules = modules;
573
+ } // 合并默认值
574
+
575
+
576
+ const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
577
+ if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
578
+ return objValue.concat(srcValue);
579
+ }
580
+ });
581
+ return res;
582
+ };
583
+ /**
584
+ * 根据moduleNames获取modules
585
+ * @param { object } tmsConfig
586
+ * @param { array } moduleNames
587
+ * @param {boolean} errorIsQuit 找不到配置文件是否退出
588
+ * @returns
589
+ */
590
+
591
+
592
+ const getModulesByModuleNames = function (tmsConfig, moduleNames = []) {
593
+ const targetModules = [];
594
+ moduleNames.forEach(moduleName => {
595
+ const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
596
+
597
+ if (!module) {
598
+ throw new Error(`你启动的模块${moduleName}在tms.config.js的modules.all中没有注册`);
599
+ }
600
+
601
+ targetModules.push(module);
602
+ });
603
+ return targetModules;
604
+ };
605
+ /**
606
+ * 适配处理module.config.json的字段
607
+ * @param { object } fileContent module.config.json的内容
608
+ * @param { string } appName 小程序的名称
609
+ */
610
+
611
+
612
+ function adaptMpCgContent(fileContent, appName) {
613
+ const handleContent = function (appName, current) {
614
+ let res = current;
615
+
616
+ if (appName && current.mpConfig && current.mpConfig[appName]) {
617
+ res = { ...current,
618
+ ...current.mpConfig[appName]
619
+ };
620
+ }
621
+
622
+ delete res.mpConfig;
623
+ delete res.isSubpackages;
624
+ return res;
625
+ };
626
+
627
+ let content = fileContent;
628
+
629
+ if (isArray(content)) {
630
+ let i = content.length - 1;
631
+
632
+ while (i >= 0) {
633
+ content[i] = handleContent(appName, content[i]);
634
+ i--; // eslint-disable-line
635
+ }
636
+ } else {
637
+ content = handleContent(appName, content);
638
+ }
639
+
640
+ return content;
641
+ }
642
+
643
+ const adaptDependencies = function (dependencies, subPackages) {
644
+ const newDependencies = dependencies || [];
645
+ subPackages.forEach(item => {
646
+ if (item.dependencies) {
647
+ dependencies = newDependencies.concat(item.dependencies);
648
+ }
649
+ });
650
+ return newDependencies;
651
+ };
652
+
653
+ const adaptSubPackages = function (moduleConfig, appName) {
654
+ const subPackages = isObject(moduleConfig) && moduleConfig.subPackages ? moduleConfig.subPackages : isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
655
+ return adaptMpCgContent(subPackages, appName);
656
+ };
657
+ /**
658
+ * 获取模块module.config.json中的配置信息
659
+ * @param {array} modules 用户要编译的模块列表
660
+ * @param { string } appName 小程序的名称
661
+ */
662
+
663
+
664
+ function getModulesConfig(modules = [], appName) {
665
+ const modulesConfig = [];
666
+ modules.forEach(moduleItem => {
667
+ const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
668
+ let moduleConfig;
669
+
670
+ try {
671
+ moduleConfig = JSON.parse(fs.readFileSync(moduleConfigPath, 'utf-8'));
672
+ } catch (e) {
673
+ throw new Error(`${moduleConfigPath}json解析报错: ${e}`);
674
+ } // 兼容历史逻辑,后续可删除--- start
675
+
676
+
677
+ const subPackages = adaptSubPackages(moduleConfig, appName);
678
+ const dependencies = adaptDependencies(moduleConfig.dependencies, subPackages);
679
+ moduleConfig = { ...(isObject(moduleConfig) ? moduleConfig : {}),
680
+ subPackages,
681
+ dependencies
682
+ }; // 兼容逻辑--- end
683
+
684
+ modulesConfig.push(moduleConfig);
685
+ });
686
+ return modulesConfig;
687
+ }
688
+ /**
689
+ * 获取分包内容 (读取module.config.json的配置项)
690
+ * @param {array} modules
691
+ * @returns
692
+ */
693
+
694
+
695
+ const getSubPackages = modules => {
696
+ const newSubPackages = [];
697
+ modules.forEach(module => {
698
+ (module.subPackages || []).forEach(subPackage => {
699
+ newSubPackages.push({ ...subPackage
700
+ });
701
+ });
702
+ });
703
+ return newSubPackages;
704
+ };
705
+ /**
706
+ * 获取分包的root字段
707
+ * @param {*} modulePath 模块的编译路径
708
+ * @param {*} root 分包的root字段
709
+ * @returns
710
+ */
711
+
712
+
713
+ const getSubPackageRoot = function (modulePath, root) {
714
+ return root.startsWith(modulePath) ? root : `${modulePath}/${root}`;
715
+ }; // 获取分包的源码路径
716
+
717
+
718
+ const getSubPackageSrcPath = function (tmsConfig, module, subPackage) {
719
+ const srcModulePath = getAbsolutePath(module.path);
720
+ const buildModulePath = resolve(tmsConfig.outputDir, module.modulePath);
721
+ const subPackageRoot = getSubPackageRoot(module.modulePath, subPackage.root);
722
+ const buildSubPackagePath = resolve(tmsConfig.outputDir, subPackageRoot);
723
+ const subPackageRelativeModule = path.relative(buildModulePath, buildSubPackagePath);
724
+ const srcSubPackagePath = path.join(srcModulePath, subPackageRelativeModule);
725
+ return srcSubPackagePath;
726
+ };
727
+
728
+ const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
729
+ const newModuleItem = { ...tmsModuleItem,
730
+ ...moduleConfig
731
+ }; // 兼容逻辑
732
+
733
+ if (!newModuleItem.moduleName) newModuleItem.moduleName = newModuleItem.name;
734
+ delete newModuleItem.name; // 参数校验-模块源码路径
735
+
736
+ if (!newModuleItem.path) {
737
+ throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
738
+ } // 参数校验-模块编译路径
739
+
740
+
741
+ if (!newModuleItem.modulePath) {
742
+ throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到modulePath字段`);
743
+ } // 参数校验-分包校验
744
+
745
+
746
+ for (const subPackage of newModuleItem.subPackages) {
747
+ if (!subPackage.root) {
748
+ throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到${subPackage.name}分包的root字段`);
749
+ } // 参数校验-判断分包源码目录是否存在
750
+
751
+
752
+ const subPackageSrcPath = getSubPackageSrcPath(tmsConfig, newModuleItem, subPackage);
753
+
754
+ if (!subPackageSrcPath || !fs.existsSync(subPackageSrcPath)) {
755
+ throw new Error(`没有找到${newModuleItem.moduleName}模块的${subPackage.name}分包源码:${subPackageSrcPath}`);
756
+ }
757
+
758
+ subPackage.path = subPackageSrcPath;
759
+ }
760
+
761
+ return newModuleItem;
762
+ };
763
+ /**
764
+ * 获取所有的模块,合并模块的依赖模块
765
+ * @param { object } tmsConfig
766
+ * @param {array} modules
767
+ * @param {boolean} errorIsQuit 找不到配置文件是否退出
768
+ * @returns
769
+ */
770
+
771
+
772
+ const getModulesByMergeDepModules = (tmsConfig, modules, errorIsQuit = false) => {
773
+ const allModules = new Map();
774
+
775
+ function dfs(tmsConfig, modules) {
776
+ modules.forEach(moduleItem => {
777
+ const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
778
+
779
+ if (!fs.existsSync(moduleConfigPath)) {
780
+ if (!allModules.has(moduleItem.moduleName)) {
781
+ allModules.set(moduleItem.moduleName, moduleItem);
782
+ }
783
+
784
+ if (errorIsQuit) {
785
+ throw new Error(`${moduleItem.moduleName}模块的配置文件module.config.json在${moduleItem.path}目录下没有找到`);
786
+ }
787
+
788
+ return;
789
+ }
790
+
791
+ const [moduleConfig = {}] = getModulesConfig([moduleItem], tmsConfig.appName);
792
+
793
+ if (!allModules.has(moduleItem.moduleName)) {
794
+ allModules.set(moduleItem.moduleName, checkModuleItem(tmsConfig, moduleItem, moduleConfig));
795
+ const dependenciesModules = getModulesByModuleNames(tmsConfig, moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies);
796
+
797
+ if (dependenciesModules.length) {
798
+ dfs(tmsConfig, dependenciesModules);
799
+ }
800
+ }
801
+ });
802
+ }
803
+
804
+ dfs(tmsConfig, modules);
805
+ const modulesArr = [];
806
+
807
+ for (const module of allModules.values()) {
808
+ modulesArr.push(module);
809
+ }
810
+
811
+ return modulesArr;
812
+ };
813
+
814
+ module.exports = {
815
+ readTmsConfig,
816
+ readTmsPrivateCf,
817
+ getModulesConfig,
818
+ getModulesByModuleNames,
819
+ getSubPackages,
820
+ getModulesByMergeDepModules,
821
+ getTmsConfig
822
+ };
823
+ })(tmsMpconfig);
824
+
825
+ const fs$g = require$$0__default$2;
826
+ const path$c = require$$1__default$2;
433
827
  const {
434
- info: info$7
828
+ info: info$b
435
829
  } = log$1;
436
830
  const {
437
831
  relativeCwdPath
@@ -442,12 +836,12 @@ const {
442
836
  * @returns
443
837
  */
444
838
 
445
- const isDirEmpty = dirname => fs$d.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
839
+ const isDirEmpty = dirname => fs$g.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
446
840
 
447
841
 
448
842
  const isFile = pathName => {
449
843
  try {
450
- const stat = fs$d.lstatSync(pathName);
844
+ const stat = fs$g.lstatSync(pathName);
451
845
  return stat.isFile();
452
846
  } catch {
453
847
  return false;
@@ -459,9 +853,9 @@ const isFile = pathName => {
459
853
  */
460
854
 
461
855
 
462
- const ensureDirExist$1 = dirname => {
463
- if (!fs$d.existsSync(dirname)) {
464
- fs$d.mkdirSync(dirname, {
856
+ const ensureDirExist$2 = dirname => {
857
+ if (!fs$g.existsSync(dirname)) {
858
+ fs$g.mkdirSync(dirname, {
465
859
  recursive: true
466
860
  });
467
861
  }
@@ -469,27 +863,27 @@ const ensureDirExist$1 = dirname => {
469
863
 
470
864
 
471
865
  const copyFile = function (src, dest) {
472
- if (fs$d.existsSync(dest)) {
473
- fs$d.unlinkSync(dest);
866
+ if (fs$g.existsSync(dest)) {
867
+ fs$g.unlinkSync(dest);
474
868
  }
475
869
 
476
- const dir = path$9.dirname(dest);
477
- ensureDirExist$1(dir);
478
- fs$d.copyFileSync(src, dest);
870
+ const dir = path$c.dirname(dest);
871
+ ensureDirExist$2(dir);
872
+ fs$g.copyFileSync(src, dest);
479
873
  }; // 判断文件内容是否一致,不一致再进行拷贝
480
874
 
481
875
 
482
876
  function diffContentCopyFile$3(originFile, destFile) {
483
- if (fs$d.existsSync(destFile)) {
484
- const depDestContent = fs$d.readFileSync(destFile, 'utf8');
485
- const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
877
+ if (fs$g.existsSync(destFile)) {
878
+ const depDestContent = fs$g.readFileSync(destFile, 'utf8');
879
+ const depOriginContent = fs$g.readFileSync(originFile, 'utf8');
486
880
 
487
881
  if (depDestContent !== depOriginContent) {
488
- info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
882
+ info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
489
883
  copyFile(originFile, destFile);
490
884
  }
491
885
  } else {
492
- info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
886
+ info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
493
887
  copyFile(originFile, destFile);
494
888
  }
495
889
  } // 添加后缀
@@ -500,7 +894,7 @@ function ext$3(filePath, extensions) {
500
894
  let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
501
895
 
502
896
  try {
503
- const stat = fs$d.lstatSync(newFilePath);
897
+ const stat = fs$g.lstatSync(newFilePath);
504
898
 
505
899
  if (stat.isDirectory()) {
506
900
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
@@ -511,7 +905,7 @@ function ext$3(filePath, extensions) {
511
905
  for (const ext of extensions) {
512
906
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
513
907
 
514
- if (fs$d.existsSync(file)) {
908
+ if (fs$g.existsSync(file)) {
515
909
  return {
516
910
  ext,
517
911
  extPath: extPath + ext,
@@ -529,11 +923,11 @@ function ext$3(filePath, extensions) {
529
923
 
530
924
 
531
925
  const fileInDir$3 = (dir, file) => {
532
- if (!fs$d.existsSync(dir) || !fs$d.existsSync(file)) {
926
+ if (!fs$g.existsSync(dir) || !fs$g.existsSync(file)) {
533
927
  return false;
534
928
  }
535
929
 
536
- const relativePath = path$9.relative(dir, file);
930
+ const relativePath = path$c.relative(dir, file);
537
931
 
538
932
  if (relativePath.startsWith('..')) {
539
933
  return false;
@@ -546,10 +940,10 @@ function findAllFilesOfDir$1(dir) {
546
940
  const list = [];
547
941
 
548
942
  function listFile(dir) {
549
- const arr = fs$d.readdirSync(dir);
943
+ const arr = fs$g.readdirSync(dir);
550
944
  arr.forEach(item => {
551
- const fullPath = path$9.join(dir, item);
552
- const stats = fs$d.statSync(fullPath);
945
+ const fullPath = path$c.join(dir, item);
946
+ const stats = fs$g.statSync(fullPath);
553
947
 
554
948
  if (stats.isDirectory()) {
555
949
  listFile(fullPath);
@@ -568,14 +962,14 @@ var io$3 = {
568
962
  isDirEmpty,
569
963
  copyFile,
570
964
  diffContentCopyFile: diffContentCopyFile$3,
571
- ensureDirExist: ensureDirExist$1,
965
+ ensureDirExist: ensureDirExist$2,
572
966
  ext: ext$3,
573
967
  fileInDir: fileInDir$3,
574
968
  isFile,
575
969
  findAllFilesOfDir: findAllFilesOfDir$1
576
970
  };
577
971
 
578
- const async = require$$0__default$4;
972
+ const async = require$$0__default$5;
579
973
  const ejs = require$$1__default$3;
580
974
 
581
975
  const render$1 = (files, metalsmith, next) => {
@@ -595,14 +989,14 @@ const render$1 = (files, metalsmith, next) => {
595
989
 
596
990
  var render_1 = render$1;
597
991
 
598
- const fs$c = require$$0__default$2;
599
- const inquirer = require$$1__default$4;
992
+ const fs$f = require$$0__default$2;
993
+ const inquirer$1 = require$$1__default$4;
600
994
  const {
601
- resolve: resolve$e
995
+ resolve: resolve$f
602
996
  } = widgets;
603
997
  const {
604
998
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
605
- } = require$$4;
999
+ } = require$$5;
606
1000
  /**
607
1001
  * 获取模板内的问题
608
1002
  * @param {string} dir questions.json所在的目录
@@ -612,12 +1006,12 @@ const {
612
1006
  const parseTemplateQuestions = dir => {
613
1007
  let prompts = [];
614
1008
 
615
- if (!fs$c.existsSync(`${dir}/questions.json`)) {
1009
+ if (!fs$f.existsSync(`${dir}/questions.json`)) {
616
1010
  return prompts;
617
1011
  }
618
1012
 
619
1013
  try {
620
- const json = JSON.parse(fs$c.readFileSync(`${dir}/questions.json`));
1014
+ const json = JSON.parse(fs$f.readFileSync(`${dir}/questions.json`));
621
1015
 
622
1016
  if (Array.isArray(json) && json.length > 0) {
623
1017
  json.forEach((item, index) => {
@@ -650,7 +1044,7 @@ const isQuestionType = result => {
650
1044
  };
651
1045
 
652
1046
  const ask$1 = templateDir => (files, metalsmith, next) => {
653
- const prompts = parseTemplateQuestions(resolve$e(templateDir, TEMPLATE_TKIT_DIR$1));
1047
+ const prompts = parseTemplateQuestions(resolve$f(templateDir, TEMPLATE_TKIT_DIR$1));
654
1048
  const metadata = metalsmith.metadata();
655
1049
  const filteredPrompts = prompts.filter(prompt => {
656
1050
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -659,7 +1053,7 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
659
1053
 
660
1054
  return true;
661
1055
  });
662
- inquirer.prompt(filteredPrompts).then(res => {
1056
+ inquirer$1.prompt(filteredPrompts).then(res => {
663
1057
  for (const prompt of filteredPrompts) {
664
1058
  metadata[prompt.name] = res[prompt.name];
665
1059
  }
@@ -675,12 +1069,12 @@ var ask_1 = ask$1;
675
1069
  const FILES_TO_IGNORE$1 = ['node_modules'];
676
1070
  var ignoreFiles = FILES_TO_IGNORE$1;
677
1071
 
678
- const Metalsmith = require$$0__default$5;
1072
+ const Metalsmith = require$$0__default$6;
679
1073
  const render = render_1;
680
1074
  const ask = ask_1;
681
1075
  const FILES_TO_IGNORE = ignoreFiles;
682
1076
 
683
- const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, reject) => {
1077
+ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolve, reject) => {
684
1078
  Metalsmith(buildDir).metadata(preMetadata).ignore(FILES_TO_IGNORE).clean(false).use(ask(buildDir)).source('./').destination(distDir).use(render).build(err => {
685
1079
  if (err) {
686
1080
  reject(err);
@@ -692,35 +1086,38 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
692
1086
 
693
1087
  var generator_1 = generator$1;
694
1088
 
695
- const path$8 = require$$1__default$2;
696
- const fs$b = require$$0__default$2;
1089
+ const path$b = require$$1__default$2;
1090
+ const fs$e = require$$0__default$2;
697
1091
  const shelljs$6 = require$$0__default$3;
1092
+ const inquirer = require$$1__default$4;
698
1093
  const {
699
1094
  TEMPLATE_DIR,
700
- TEMPLATE_PATH,
701
- TEMPLATE_TKIT_DIR
702
- } = require$$4;
1095
+ TEMPLATE_URL,
1096
+ TEMPLATE_NAME,
1097
+ TEMPLATE_TKIT_DIR,
1098
+ CREATE_TEMPLATE_QUESTION
1099
+ } = require$$5;
703
1100
  const {
704
- downloadRepoForGit: downloadRepoForGit$1,
705
- createTask: createTask$2,
706
- resolve: resolve$d
1101
+ resolve: resolve$e
707
1102
  } = widgets;
708
1103
  const io$2 = io$3;
709
1104
  const {
710
1105
  fail: fail$8,
711
1106
  succeed: succeed$1,
712
- info: info$6
1107
+ info: info$a
713
1108
  } = log$1;
714
1109
  const generator = generator_1;
1110
+ const request = require$$9__default;
1111
+ const unzip = require$$10__default;
715
1112
  /**
716
1113
  * 如果该目录下面存在文件,换个名字
717
1114
  * @param { string } targetDir 当前文件夹
718
1115
  * @returns { undefined }
719
1116
  */
720
1117
 
721
- async function createAppDir(targetDir) {
1118
+ async function createProjectDir(targetDir) {
722
1119
  // 如果目录非空或者已经存在,提示用户,做选择
723
- if (fs$b.existsSync(targetDir)) {
1120
+ if (fs$e.existsSync(targetDir)) {
724
1121
  if (!(await io$2.isDirEmpty(targetDir))) {
725
1122
  fail$8('该目录名已经存在,换个项目名字吧~');
726
1123
  process.exit(1);
@@ -730,305 +1127,93 @@ async function createAppDir(targetDir) {
730
1127
  }
731
1128
  }
732
1129
  /**
733
- * 创建本地小程序运行环境
734
- * @param { string } appType 项目类型
735
- * @param { string } appName 项目名称
1130
+ * 下载和解压远程的小程序模板
1131
+ * @param {string} templateDir
1132
+ * @param {string} templateUrl
1133
+ * @param {string} templateName
1134
+ * @returns
736
1135
  */
737
1136
 
738
1137
 
739
- async function create(appName) {
740
- const cwd = process.cwd();
741
- const targetDir = path$8.resolve(cwd, appName);
742
- const appType = 'mp';
743
- await createAppDir(targetDir); // 创建缓存目录
744
-
745
- io$2.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
746
-
747
- await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
748
-
749
- generator(path$8.join(TEMPLATE_PATH, appType), targetDir, {
750
- appName,
751
- appType
752
- }).then(() => {
753
- shelljs$6.cd(appName);
754
-
755
- const hooks = require(resolve$d(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
1138
+ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1139
+ return new Promise((resolve, reject) => {
1140
+ const localZipPath = `${templateDir}/${templateName}.zip`;
1141
+ const stream = fs$e.createWriteStream(localZipPath);
1142
+ request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
1143
+ if (err) {
1144
+ reject(err);
1145
+ return;
1146
+ }
756
1147
 
757
- if (hooks.afterCreate) {
758
- hooks.afterCreate.forEach(item => {
759
- if (typeof item === 'function') {
760
- item.call(null, shelljs$6, {
761
- appName
762
- });
763
- } else {
764
- shelljs$6.exec(item);
1148
+ fs$e.createReadStream(localZipPath).pipe(unzip.Extract({
1149
+ path: templateDir
1150
+ })).on('close', err => {
1151
+ if (err) {
1152
+ reject(err);
1153
+ return;
765
1154
  }
766
- });
767
- }
768
1155
 
769
- shelljs$6.rm('-rf', resolve$d(appName, TEMPLATE_TKIT_DIR));
770
- succeed$1('项目创建完成.');
771
- }).catch(err => {
772
- fail$8(err.message);
773
- info$6('详细的错误信息:', err);
1156
+ resolve();
1157
+ });
1158
+ });
774
1159
  });
775
1160
  }
776
-
777
- var create_1 = create;
778
-
779
- var defaultTmsConfig$1 = {
780
- // 全局的环境配置项
781
- envData: {},
782
- // 模块配置信息
783
- modules: {},
784
- cloudDir: 'cloud',
785
- // 第三方依赖代码需要拷贝到本项目的
786
- dependencies: {},
787
-
788
- /** 编译输出文件夹位置 */
789
- outputDir: 'dist',
790
-
791
- /** 源码监听路径 */
792
- sourceDir: './',
793
-
794
- /** 静态资源目录 */
795
- static: []
796
- };
797
-
798
- /**
799
- * 用来读取处理tms.config.js与module.config.json字段
800
- */
801
- const loadash$1 = require$$0__default$6;
802
- const fs$a = require$$0__default$2;
803
- const {
804
- TMS_CONFIG_FILENAME,
805
- MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
806
- TMS_PRIVATE_FILENAME
807
- } = require$$4;
808
- const {
809
- resolve: resolve$c,
810
- isObject: isObject$1,
811
- isArray
812
- } = widgets;
813
- const defaultTmsConfig = defaultTmsConfig$1;
814
- const {
815
- fail: fail$7
816
- } = log$1;
817
1161
  /**
818
- * 读取tms.config.js
819
- * @param env {string} 环境变量
820
- */
821
-
822
- const readTmsConfig$1 = function (env) {
823
- const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
824
-
825
- if (!fs$a.existsSync(tmsConfigPath)) {
826
- fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
827
- process.exit(1);
828
- }
829
-
830
- const tmsConfigFn = require(tmsConfigPath);
831
-
832
- const tmsConfig = tmsConfigFn({
833
- env
834
- }); // 合并默认值
835
-
836
- loadash$1.mergeWith(tmsConfig, defaultTmsConfig);
837
- return tmsConfig;
838
- };
839
- /**
840
- * 读取tms.private.config.js
841
- */
842
-
843
-
844
- const readTmsPrivateCf$1 = function () {
845
- let tmsPrivateCf = {};
846
- const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
847
-
848
- if (fs$a.existsSync(tmsPrivatePath)) {
849
- tmsPrivateCf = require(tmsPrivatePath);
850
- }
851
-
852
- return tmsPrivateCf;
853
- };
854
- /**
855
- * 从tms.config.json中检索用户传入的有效modules
856
- * @param { object } tmsConfig
857
- * @param { array } modules
858
- * @returns
859
- */
860
-
861
-
862
- const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
863
- const targetModules = [];
864
- modules.forEach(moduleName => {
865
- const module = tmsConfig.modules.all.find(module => module.name === moduleName);
866
- module && targetModules.push(module);
867
- });
868
-
869
- if (targetModules.length === 0) {
870
- fail$7(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
871
- >name字段与module.config.json的name字段是否一致`);
872
- isQuit && process.exit(1);
873
- }
874
-
875
- return targetModules;
876
- };
877
- /**
878
- * 适配处理module.config.json的字段
879
- * @param { object } fileContent module.config.json的内容
880
- * @param { string } appName 小程序的名称
1162
+ * 创建本地小程序运行环境
1163
+ * @param { string } projectType 项目类型
1164
+ * @param { string } projectName 项目名称
881
1165
  */
882
1166
 
883
1167
 
884
- function adaptMpCgContent(fileContent, appName) {
885
- const handleContent = function (appName, current) {
886
- let res = current;
887
-
888
- if (appName && current.mpConfig && current.mpConfig[appName]) {
889
- res = { ...current,
890
- ...current.mpConfig[appName]
891
- };
892
- }
893
-
894
- delete res.mpConfig;
895
- delete res.isSubpackages;
896
- return res;
897
- };
898
-
899
- let content = JSON.parse(fileContent);
1168
+ async function create(projectName) {
1169
+ const cwd = process.cwd();
1170
+ const targetDir = path$b.resolve(cwd, projectName);
1171
+ const {
1172
+ projectType
1173
+ } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION); // 创建项目目录
900
1174
 
901
- if (isArray(content)) {
902
- let i = content.length - 1;
1175
+ await createProjectDir(targetDir); // 新创建缓存目录
903
1176
 
904
- while (i >= 0) {
905
- content[i] = handleContent(appName, content[i]);
906
- i--; // eslint-disable-line
907
- }
908
- } else {
909
- content = handleContent(appName, content);
1177
+ if (fs$e.existsSync(TEMPLATE_DIR)) {
1178
+ shelljs$6.rm('-rf', TEMPLATE_DIR);
910
1179
  }
911
1180
 
912
- return content;
913
- }
914
- /**
915
- * 递归获取本地所有模块的配置信息
916
- * @param {array} modules 用户要编译的模块列表
917
- * @param { string } appName 小程序的名称
918
- * @param { string } moduleConfigFilename moduleConfig的文件名
919
- */
920
-
921
-
922
- function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
923
- const modulesConfig = {};
924
- modules.forEach(({
925
- path
926
- }) => {
927
- const moduleConfigPath = resolve$c(path, moduleConfigFilename);
1181
+ fs$e.mkdirSync(TEMPLATE_DIR, {
1182
+ recursive: true
1183
+ }); // 下载和解压模板
928
1184
 
929
- if (fs$a.existsSync(moduleConfigPath)) {
930
- const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
931
- modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
932
- }
933
- });
934
- return modulesConfig;
935
- }
936
- /**
937
- * tms.config.js的modules 合并 module.config.json的配置项
938
- * @param {array} modules
939
- * @param {string} appName
940
- * @param {string} moduleDir
941
- * @returns
942
- */
1185
+ await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
943
1186
 
1187
+ generator(path$b.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1188
+ shelljs$6.cd(projectName);
1189
+ const hookFilePath = resolve$e(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
944
1190
 
945
- const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
946
- const newModules = [];
947
- modules.forEach(({
948
- path: relativePath,
949
- name: moduleName
950
- }, moduleIndex) => {
951
- const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$1);
1191
+ if (fs$e.existsSync(hookFilePath)) {
1192
+ const hooks = require(hookFilePath);
952
1193
 
953
- if (fs$a.existsSync(moduleConfigPath)) {
954
- try {
955
- let findModule = false;
956
- let moduleConfigContent = fs$a.readFileSync(moduleConfigPath, 'utf-8');
957
- moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
958
- const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
959
- moduleContentArr.forEach(({
960
- name
961
- }, moduleContentArrIndex) => {
962
- if (name === moduleName) {
963
- findModule = true;
964
- newModules.push({ ...modules[moduleIndex],
965
- ...moduleContentArr[moduleContentArrIndex]
1194
+ if (hooks.afterCreate) {
1195
+ hooks.afterCreate.forEach(item => {
1196
+ if (typeof item === 'function') {
1197
+ item.call(null, shelljs$6, {
1198
+ projectName
966
1199
  });
1200
+ } else {
1201
+ shelljs$6.exec(item);
967
1202
  }
968
1203
  });
969
-
970
- if (!findModule) {
971
- fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
972
- process.exit(1);
973
- }
974
- } catch (e) {
975
- fail$7(`${moduleConfigPath}配置错误: ${e}`);
976
- newModules.push({ ...modules[moduleIndex]
977
- });
978
1204
  }
979
- } else {
980
- newModules.push({ ...modules[moduleIndex]
981
- });
982
- }
983
- });
984
- return newModules;
985
- };
986
- /**
987
- * 分包依赖了分包的模块 合并所依赖的modules
988
- * @param { object } tmsConfig
989
- * @param {array} modules
990
- * @param {string} moduleDir
991
- * @returns
992
- */
993
1205
 
1206
+ shelljs$6.rm('-rf', resolve$e(projectName, TEMPLATE_TKIT_DIR));
1207
+ }
994
1208
 
995
- const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
996
- const moduleNames = [];
997
- modules.forEach(({
998
- name: moduleName
999
- }) => {
1000
- moduleNames.push(moduleName);
1001
- });
1002
- let mergeModules = modules;
1003
- let isOver = true;
1004
- modules.forEach(({
1005
- dependencies: dependencyModules
1006
- }) => {
1007
- dependencyModules === null || dependencyModules === void 0 ? void 0 : dependencyModules.forEach(item => {
1008
- // 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
1009
- // 否则递归处理,根据name找到相关配置加到modules里
1010
- if (moduleNames.indexOf(item) === -1) {
1011
- const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
1012
-
1013
- if (tmpModules.length > 0) {
1014
- isOver = false;
1015
- mergeModules = [...mergeModules, ...tmpModules];
1016
- mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
1017
- }
1018
- }
1019
- });
1209
+ succeed$1('项目创建完成.');
1210
+ }).catch(err => {
1211
+ fail$8(err.message);
1212
+ info$a('详细的错误信息:', err);
1020
1213
  });
1021
- return isOver ? mergeModules : subModulesMergeDepModules$2(tmsConfig, mergeModules);
1022
- };
1214
+ }
1023
1215
 
1024
- var tmsMpconfig = {
1025
- readTmsConfig: readTmsConfig$1,
1026
- readTmsPrivateCf: readTmsPrivateCf$1,
1027
- getModuleConfig: getModuleConfig$1,
1028
- checkModules: checkModules$1,
1029
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
1030
- subModulesMergeDepModules: subModulesMergeDepModules$2
1031
- };
1216
+ var create_1 = create;
1032
1217
 
1033
1218
  const global$6 = {
1034
1219
  data: {},
@@ -1056,26 +1241,32 @@ var global_1 = {
1056
1241
  };
1057
1242
 
1058
1243
  const {
1059
- fail: fail$6
1244
+ fail: fail$7
1060
1245
  } = log$1;
1061
1246
  const {
1062
1247
  global: global$5
1063
1248
  } = global_1;
1064
1249
 
1065
- function handleError$6(error) {
1250
+ function handleError$5(error, isQuit = false) {
1066
1251
  const errMsg = typeof error === 'object' ? error.message : error;
1252
+
1253
+ if (isQuit) {
1254
+ fail$7(errMsg);
1255
+ process.exit(1);
1256
+ }
1257
+
1067
1258
  const isDev = global$5.getData('isDev');
1068
1259
 
1069
1260
  if (isDev) {
1070
- fail$6(errMsg);
1261
+ fail$7(errMsg);
1071
1262
  } else {
1072
- fail$6(errMsg);
1263
+ fail$7(errMsg);
1073
1264
  process.exit(1);
1074
1265
  }
1075
1266
  }
1076
1267
 
1077
1268
  var handleError_1 = {
1078
- handleError: handleError$6
1269
+ handleError: handleError$5
1079
1270
  };
1080
1271
 
1081
1272
  /**
@@ -1083,23 +1274,21 @@ var handleError_1 = {
1083
1274
  */
1084
1275
  /* eslint-disable no-param-reassign */
1085
1276
 
1086
- const fs$9 = require$$0__default$2;
1087
- const {
1088
- MODULE_CONFIG_FILENAME
1089
- } = require$$4;
1277
+ const fs$d = require$$0__default$2;
1090
1278
  const {
1091
- getModuleConfig
1092
- } = tmsMpconfig;
1279
+ getSubPackages: getSubPackages$3,
1280
+ getModulesConfig
1281
+ } = tmsMpconfig.exports;
1093
1282
  const {
1094
- fail: fail$5
1283
+ fail: fail$6,
1284
+ info: info$9
1095
1285
  } = log$1;
1096
1286
  const {
1097
- resolve: resolve$b,
1098
- isObject,
1099
- filterField: filterField$2
1287
+ resolve: resolve$d,
1288
+ filterField: filterField$3
1100
1289
  } = widgets;
1101
1290
  const {
1102
- handleError: handleError$5
1291
+ handleError: handleError$4
1103
1292
  } = handleError_1;
1104
1293
  const {
1105
1294
  global: global$4
@@ -1122,7 +1311,7 @@ function updateMainPackages(appJson, mainPackages = []) {
1122
1311
 
1123
1312
  foundMainPackages.forEach(subpackage => {
1124
1313
  if (!subpackage.pages || !subpackage.pages.length) {
1125
- fail$5(`主包 ${subpackage} 不能没有 pages`);
1314
+ fail$6(`主包 ${subpackage} 不能没有 pages`);
1126
1315
  process.exit(-1);
1127
1316
  }
1128
1317
 
@@ -1147,33 +1336,17 @@ function updateMainPackages(appJson, mainPackages = []) {
1147
1336
 
1148
1337
 
1149
1338
  const getAppJsonContent = sourceAppJsonPath => {
1150
- if (!fs$9.existsSync(sourceAppJsonPath)) {
1151
- fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1339
+ if (!fs$d.existsSync(sourceAppJsonPath)) {
1340
+ fail$6(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1152
1341
  process.exit(1);
1153
1342
  }
1154
1343
 
1155
- const appJson = JSON.parse(fs$9.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1344
+ const appJson = JSON.parse(fs$d.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1156
1345
 
1157
1346
  appJson.subpackages = [];
1158
1347
  appJson.pages = [];
1159
1348
  return appJson;
1160
1349
  };
1161
- /**
1162
- * 更新app.json中的subpackages
1163
- * @param {Object} appJson
1164
- * @param {Object} modulesConfigs
1165
- */
1166
-
1167
-
1168
- const updateSubpackages = (appJson, modulesConfigs) => {
1169
- // eslint-disable-next-line
1170
- for (const modulePath in modulesConfigs) {
1171
- const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
1172
- appJson.subpackages = appJson.subpackages.concat(moduleInfo);
1173
- }
1174
-
1175
- appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
1176
- };
1177
1350
  /**
1178
1351
  * 处理合并subpackages后的appjson, 整理重复不合法的地方
1179
1352
  * @param {Object} appJson appjson
@@ -1213,7 +1386,7 @@ const fixAppJson = appJson => {
1213
1386
  appJson[key] = preloadRuleMap;
1214
1387
  }
1215
1388
  });
1216
- return filterField$2(subp, [...arrOfFileType, ...objOfFileType, 'dependencies']);
1389
+ return filterField$3(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1217
1390
  }); // 如果plugins重复,则错误提示
1218
1391
 
1219
1392
  const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
@@ -1238,27 +1411,30 @@ const fixAppJson = appJson => {
1238
1411
  */
1239
1412
 
1240
1413
 
1241
- function buildOutputAppJson$1(tmsConfig, modules) {
1414
+ function buildOutputAppJson$2(tmsConfig, modules) {
1242
1415
  try {
1243
1416
  var _tmsConfig$hooks;
1244
1417
 
1245
- // 获取当前 modules 下的所有子模块的配置内容
1246
- const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
1418
+ // 获取所有模块,合并模块依赖的模块
1419
+ const modulesConfig = getModulesConfig(modules, tmsConfig.appName, false); // 获取所有的分包
1420
+
1421
+ const subPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
1247
1422
 
1248
- const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
1423
+ const appJson = getAppJsonContent(resolve$d('./app.json')); // 更新app.json中的subpackages
1249
1424
 
1250
- updateSubpackages(appJson, modulesConfigs); // 处理appJson中重复||冲突的地方
1425
+ appJson.subpackages = subPackages;
1426
+ appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name)); // 处理appJson中重复||冲突的地方
1251
1427
 
1252
1428
  fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1253
1429
 
1254
1430
  updateMainPackages(appJson, tmsConfig.mainPackages);
1255
- fs$9.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1431
+ fs$d.writeFileSync(resolve$d(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1256
1432
 
1257
1433
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
1258
1434
  var _tmsConfig$hooks2;
1259
1435
 
1260
1436
  tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
1261
- tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
1437
+ tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
1262
1438
  modules,
1263
1439
  appJson,
1264
1440
  isDev: global$4.getData('isDev')
@@ -1267,32 +1443,33 @@ function buildOutputAppJson$1(tmsConfig, modules) {
1267
1443
 
1268
1444
  return appJson;
1269
1445
  } catch (e) {
1270
- handleError$5(`生成app.json出现错误: ${e}`);
1446
+ handleError$4(`生成app.json出现错误: ${e}`);
1447
+ info$9(e);
1271
1448
  }
1272
1449
  }
1273
1450
 
1274
1451
  var buildAppJson = {
1275
- buildOutputAppJson: buildOutputAppJson$1
1452
+ buildOutputAppJson: buildOutputAppJson$2
1276
1453
  };
1277
1454
 
1278
1455
  /**
1279
1456
  * 下载第三方代码
1280
1457
  */
1281
- const MetalSmith = require$$0__default$5;
1282
- const crypto$1 = require$$1__default$5;
1458
+ const MetalSmith = require$$0__default$6;
1459
+ const crypto$2 = require$$1__default$5;
1283
1460
  const {
1284
1461
  downloadRepoForGit,
1285
1462
  pullRepoForGit,
1286
- resolve: resolve$a
1463
+ resolve: resolve$c
1287
1464
  } = widgets;
1288
1465
  const {
1289
- fail: fail$4,
1290
- info: info$5
1466
+ fail: fail$5,
1467
+ info: info$8
1291
1468
  } = log$1;
1292
- const fs$8 = require$$0__default$2;
1469
+ const fs$c = require$$0__default$2;
1293
1470
  const shelljs$5 = require$$0__default$3;
1294
1471
  const {
1295
- handleError: handleError$4
1472
+ handleError: handleError$3
1296
1473
  } = handleError_1;
1297
1474
  const {
1298
1475
  global: global$3
@@ -1305,7 +1482,7 @@ const {
1305
1482
  */
1306
1483
 
1307
1484
  function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1308
- var _tmsConfig$gitAccout, _tmsConfig$gitAccount;
1485
+ var _tmsConfig$gitAccount;
1309
1486
 
1310
1487
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1311
1488
  const tmsConfig = global$3.getData('tmsConfig');
@@ -1313,7 +1490,7 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1313
1490
  const {
1314
1491
  username = '',
1315
1492
  pass = ''
1316
- } = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccout = tmsConfig.gitAccout) === null || _tmsConfig$gitAccout === void 0 ? void 0 : _tmsConfig$gitAccout[moduleName]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
1493
+ } = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
1317
1494
  const urlPrefixReg = /http(s)?:\/\//;
1318
1495
 
1319
1496
  if (username && pass && urlPrefixReg.test(gitUrl)) {
@@ -1336,7 +1513,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1336
1513
  return new Promise((resolve, reject) => {
1337
1514
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1338
1515
  if (e) {
1339
- fail$4(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1516
+ fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1340
1517
  reject(e);
1341
1518
  }
1342
1519
 
@@ -1354,7 +1531,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1354
1531
 
1355
1532
  function md5ByGitUrlBranch(gitUrl, branch) {
1356
1533
  const newBranch = branch && typeof branch === 'string' ? branch : 'master';
1357
- return crypto$1.createHash('md5').update(JSON.stringify({
1534
+ return crypto$2.createHash('md5').update(JSON.stringify({
1358
1535
  gitUrl,
1359
1536
  branch: newBranch
1360
1537
  })).digest('hex');
@@ -1385,7 +1562,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1385
1562
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1386
1563
  return Promise.all(callArr);
1387
1564
  }).catch(e => {
1388
- handleError$4(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1565
+ handleError$3(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1389
1566
  }));
1390
1567
  });
1391
1568
  await Promise.all(arrPromises);
@@ -1423,16 +1600,16 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1423
1600
  path: gitPath = ''
1424
1601
  },
1425
1602
  path,
1426
- name
1603
+ moduleName
1427
1604
  } = moduleInfo; // 处理仓库权限问题
1428
1605
 
1429
- const gitUrl = replaceGitUrlAccount(httpRepoUrl, name); // 根据gitUrl与branch计算md5
1606
+ const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName); // 根据gitUrl与branch计算md5
1430
1607
 
1431
1608
  const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1432
1609
 
1433
- const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
1610
+ const sourcePath = resolve$c(sourceDir, md5Key); // 模块源码要放到目标目录
1434
1611
 
1435
- const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1612
+ const targetPath = resolve$c(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1436
1613
 
1437
1614
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1438
1615
 
@@ -1442,7 +1619,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1442
1619
  targetPath
1443
1620
  },
1444
1621
  fn: async (sourceModulePath, targetPath) => {
1445
- if (fs$8.existsSync(targetPath)) {
1622
+ if (fs$c.existsSync(targetPath)) {
1446
1623
  shelljs$5.rm('-rf', `${targetPath}/*`);
1447
1624
  }
1448
1625
 
@@ -1457,14 +1634,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1457
1634
  } else {
1458
1635
  let promiseTask;
1459
1636
 
1460
- if (fs$8.existsSync(sourcePath) && fs$8.existsSync(`${sourcePath}/.git`)) {
1637
+ if (fs$c.existsSync(sourcePath) && fs$c.existsSync(`${sourcePath}/.git`)) {
1461
1638
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1462
- info$5(`git pull:${httpRepoUrl}`);
1639
+ info$8(`git pull:${httpRepoUrl}`);
1463
1640
  return pullRepoForGit(sourcePath, branch);
1464
1641
  };
1465
1642
  } else {
1466
1643
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1467
- info$5(`git clone: ${httpRepoUrl}`);
1644
+ info$8(`git clone: ${httpRepoUrl}`);
1468
1645
  return downloadRepoForGit(gitUrl, sourcePath, branch);
1469
1646
  };
1470
1647
  }
@@ -1500,12 +1677,12 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
1500
1677
  buildGitTag,
1501
1678
  httpRepoUrl
1502
1679
  },
1503
- name
1680
+ moduleName
1504
1681
  } = moduleInfo;
1505
- const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
1682
+ const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
1506
1683
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
1507
1684
 
1508
- if (!fs$8.existsSync(`${sourceDir}/${md5Key}`)) {
1685
+ if (!fs$c.existsSync(`${sourceDir}/${md5Key}`)) {
1509
1686
  return true;
1510
1687
  }
1511
1688
  }
@@ -1519,7 +1696,7 @@ var cloneModules_1 = {
1519
1696
  };
1520
1697
 
1521
1698
  const ci = require$$0__default$7;
1522
- const path$7 = require$$1__default$2;
1699
+ const path$a = require$$1__default$2;
1523
1700
  /**
1524
1701
  * 获取小程序ci的Project对象
1525
1702
  * @returns {Object} 小程序ci对象
@@ -1533,7 +1710,7 @@ const getMpCi = ({
1533
1710
  }) => {
1534
1711
  var _cfgJsonContent$packO;
1535
1712
 
1536
- const cfgJsonContent = require(path$7.join(projectPath, 'project.config.json'));
1713
+ const cfgJsonContent = require(path$a.join(projectPath, 'project.config.json'));
1537
1714
 
1538
1715
  const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
1539
1716
  value
@@ -1599,21 +1776,71 @@ var mpCi = {
1599
1776
  buildMpNpm: buildMpNpm$1
1600
1777
  };
1601
1778
 
1779
+ const fs$b = require$$0__default$2;
1780
+ const path$9 = require$$1__default$2;
1781
+ const {
1782
+ CACHE_FILE,
1783
+ CACHE_DIR: CACHE_DIR$2
1784
+ } = require$$5;
1785
+ const {
1786
+ ensureDirExist: ensureDirExist$1
1787
+ } = io$3;
1788
+
1789
+ function getCache$1(projectDir, type) {
1790
+ var _content$projectDir;
1791
+
1792
+ const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
1793
+
1794
+ if (!fs$b.existsSync(filePath)) {
1795
+ return null;
1796
+ }
1797
+
1798
+ const content = require(filePath);
1799
+
1800
+ return content === null || content === void 0 ? void 0 : (_content$projectDir = content[projectDir]) === null || _content$projectDir === void 0 ? void 0 : _content$projectDir[type];
1801
+ }
1802
+
1803
+ function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1804
+ const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
1805
+
1806
+ if (!fs$b.existsSync(filePath)) {
1807
+ const dir = path$9.dirname(filePath);
1808
+ ensureDirExist$1(dir);
1809
+ fs$b.writeFileSync(filePath, '{}');
1810
+ }
1811
+
1812
+ const content = require(filePath);
1813
+
1814
+ if (!content[projectDir]) {
1815
+ content[projectDir] = {};
1816
+ }
1817
+
1818
+ content[projectDir] = {
1819
+ [type]: data
1820
+ };
1821
+ fs$b.writeFileSync(filePath, JSON.stringify(content, null, 2));
1822
+ }
1823
+
1824
+ var cache = {
1825
+ setCache: setCache$1,
1826
+ getCache: getCache$1
1827
+ };
1828
+
1602
1829
  /**
1603
1830
  * 本文件主要负责项目或者分包依赖的npm的安装
1604
1831
  */
1605
- const fs$7 = require$$0__default$2;
1832
+ const fs$a = require$$0__default$2;
1606
1833
  const fsExtra = require$$1__default$6;
1607
- const crypto = require$$1__default$5;
1608
- const path$6 = require$$1__default$2;
1834
+ const crypto$1 = require$$1__default$5;
1835
+ const path$8 = require$$1__default$2;
1609
1836
  const shell = require$$0__default$3;
1610
- const glob = require$$5__default;
1837
+ const glob = require$$6__default;
1611
1838
  const log = log$1;
1612
1839
  const {
1613
- npmInstall
1840
+ npmInstall: npmInstall$1
1614
1841
  } = widgets;
1615
1842
  const {
1616
- handleError: handleError$3
1843
+ handleError: handleError$2
1617
1844
  } = handleError_1;
1618
1845
  const shellJsOption = {
1619
1846
  async: false,
@@ -1637,22 +1864,29 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1637
1864
  const npmTasksMap = new Map();
1638
1865
 
1639
1866
  for (const packageJsonPath of packageJsonFiles) {
1640
- const packageContent = fs$7.readFileSync(packageJsonPath);
1641
- const packageJson = JSON.parse(packageContent);
1867
+ const packageContent = fs$a.readFileSync(packageJsonPath);
1868
+ let packageJson;
1869
+
1870
+ try {
1871
+ packageJson = JSON.parse(packageContent);
1872
+ } catch (e) {
1873
+ throw new Error(`${packageJsonPath}json解析出现错误:${e}`);
1874
+ }
1875
+
1642
1876
  const md5Obj = {
1643
1877
  dependencies: packageJson.dependencies || {}
1644
1878
  };
1645
1879
 
1646
1880
  if (Object.keys(md5Obj.dependencies).length !== 0) {
1647
- const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
1648
- const cacheNMPath = path$6.join(cacheDir, md5Key);
1649
- const cacheNMTarFile = path$6.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
1881
+ const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
1882
+ const cacheNMPath = path$8.join(cacheDir, md5Key);
1883
+ const cacheNMTarFile = path$8.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
1650
1884
 
1651
1885
  const callback = {
1652
1886
  params: {
1653
1887
  cacheNMPath,
1654
1888
  cacheNMTarFile,
1655
- packageJsonDir: path$6.dirname(packageJsonPath),
1889
+ packageJsonDir: path$8.dirname(packageJsonPath),
1656
1890
  shell
1657
1891
  },
1658
1892
  fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
@@ -1681,7 +1915,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1681
1915
  fsExtra.emptydirSync(cacheNMPath);
1682
1916
  shell.cp('-f', packageJsonPath, cacheNMPath);
1683
1917
  log.info(`npm install: ${packageJsonPath}`);
1684
- return npmInstall(cacheNMPath).then(() => {
1918
+ return npmInstall$1(cacheNMPath).then(() => {
1685
1919
  const newShellJsOption = { ...shellJsOption,
1686
1920
  cwd: cacheNMPath
1687
1921
  };
@@ -1709,9 +1943,9 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1709
1943
  }; // 遍历安装指定目录下所有项目的npm依赖
1710
1944
 
1711
1945
 
1712
- const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1946
+ const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
1713
1947
  const cwd = process.cwd();
1714
- const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
1948
+ const packageJsonFiles = await findAllPackageJson(subPackages, contextDir); // 收集npm install的任务
1715
1949
 
1716
1950
  const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir); // 开始执行npm install和回调(移动)的任务
1717
1951
 
@@ -1728,11 +1962,12 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1728
1962
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1729
1963
  return Promise.all(callArr);
1730
1964
  }).catch(e => {
1731
- handleError$3(`npm install ${params.packageJsonPath}出现错误:${e}`);
1965
+ handleError$2(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
1732
1966
  }));
1733
1967
  });
1734
1968
  await Promise.all(arrPromises);
1735
1969
  shell.cd(cwd);
1970
+ return packageJsonFiles;
1736
1971
  };
1737
1972
  /**
1738
1973
  * 递归查找指定条件的文件
@@ -1753,7 +1988,7 @@ const findFilesByFilter = (startPath, filter) => {
1753
1988
 
1754
1989
  const find = (startPath, filter) => {
1755
1990
  // 目录不存在
1756
- if (!fs$7.existsSync(startPath)) {
1991
+ if (!fs$a.existsSync(startPath)) {
1757
1992
  log.fail(`${startPath}目录不存在`);
1758
1993
  process.exit(-1);
1759
1994
  return;
@@ -1766,10 +2001,10 @@ const findFilesByFilter = (startPath, filter) => {
1766
2001
  return;
1767
2002
  }
1768
2003
 
1769
- const files = fs$7.readdirSync(startPath);
2004
+ const files = fs$a.readdirSync(startPath);
1770
2005
  files.forEach(file => {
1771
- const filename = path$6.join(startPath, file);
1772
- const stat = fs$7.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2006
+ const filename = path$8.join(startPath, file);
2007
+ const stat = fs$a.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1773
2008
 
1774
2009
  if (stat.isDirectory()) {
1775
2010
  find(filename, filter);
@@ -1795,15 +2030,10 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1795
2030
  const packageJsonName = 'package.json'; // 查找文件名
1796
2031
 
1797
2032
  const cwd = contextDir || dirPath;
1798
- const result = [path$6.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
2033
+ const result = [path$8.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1799
2034
 
1800
2035
  subRoots.forEach(subRoot => {
1801
- if (!subRoot.root) {
1802
- log.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
1803
- process.exit(1);
1804
- }
1805
-
1806
- const toppath = path$6.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
2036
+ const toppath = path$8.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1807
2037
 
1808
2038
  const list = findFilesByFilter(toppath, packageJsonName);
1809
2039
  result.push(...list);
@@ -1819,7 +2049,7 @@ function cloudNpmInstall(contextDir) {
1819
2049
  }
1820
2050
 
1821
2051
  files.forEach(file => {
1822
- const dir = path$6.dirname(file);
2052
+ const dir = path$8.dirname(file);
1823
2053
  shell.cd(dir);
1824
2054
  shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
1825
2055
  silent: false
@@ -1832,177 +2062,334 @@ function cloudNpmInstall(contextDir) {
1832
2062
 
1833
2063
  var npm = {
1834
2064
  cloudNpmInstall,
1835
- mpNpmInstallAll: mpNpmInstallAll$1,
1836
- findAllPackageJson
2065
+ npmInstallAll: npmInstallAll$1,
2066
+ findAllPackageJson,
2067
+ findFilesByFilter
1837
2068
  };
1838
2069
 
1839
- const shelljs$4 = require$$0__default$3;
1840
- const fs$6 = require$$0__default$2;
1841
- const io$1 = io$3;
1842
- const {
1843
- createTask: createTask$1,
1844
- resolve: resolve$9
1845
- } = widgets;
1846
- const {
1847
- buildMpNpm
1848
- } = mpCi;
1849
- const {
1850
- CACHE_DIR: CACHE_DIR$1
1851
- } = require$$4;
1852
- const {
1853
- mpNpmInstallAll
1854
- } = npm;
1855
- const {
1856
- fail: fail$3
1857
- } = log$1;
1858
-
1859
- async function install$2(tmsConfig, modules) {
1860
- // 拷贝模块的package.json到编译输出目录
1861
- modules.forEach(item => {
1862
- const outputModuleDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
1863
-
1864
- if (!fs$6.existsSync(resolve$9(item.path))) {
1865
- fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1866
- process.exit(1);
1867
- }
1868
-
1869
- io$1.ensureDirExist(outputModuleDir);
1870
- const modulePackagePath = resolve$9(item.path, 'package.json');
1871
- if (fs$6.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
1872
- }); // 小程序npm install
1873
-
1874
- await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`); // 构建miniprogram_npm
2070
+ const crypto = require$$1__default$5;
2071
+ const fs$9 = require$$0__default$2;
1875
2072
 
1876
- await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
1877
- appId: tmsConfig.appId,
1878
- projectPath: resolve$9('./'),
1879
- privateKey: tmsConfig.privateKey
2073
+ function fileMd5$1(filePath) {
2074
+ return new Promise((resolve, reject) => {
2075
+ const md5sum = crypto.createHash('md5');
2076
+ const stream = fs$9.ReadStream(filePath);
2077
+ stream.on('data', d => {
2078
+ md5sum.update(d);
2079
+ });
2080
+ stream.on('error', err => {
2081
+ reject(err);
2082
+ });
2083
+ stream.on('end', () => {
2084
+ const hash = md5sum.digest('hex');
2085
+ resolve(hash);
2086
+ });
1880
2087
  });
1881
2088
  }
1882
2089
 
1883
- var install_1 = install$2;
2090
+ var md5 = {
2091
+ fileMd5: fileMd5$1
2092
+ };
1884
2093
 
1885
- const fs$5 = require$$0__default$2;
2094
+ const fs$8 = require$$0__default$2;
1886
2095
  const semver$1 = require$$1__default$7;
1887
2096
  const {
1888
- resolve: resolve$8
2097
+ resolve: resolve$b,
2098
+ getAbsolutePath: getAbsolutePath$2
1889
2099
  } = widgets;
1890
- const path$5 = require$$1__default$2;
1891
- const shelljs$3 = require$$0__default$3;
2100
+ const path$7 = require$$1__default$2;
2101
+ const shelljs$4 = require$$0__default$3;
1892
2102
  const {
1893
- handleError: handleError$2
2103
+ handleError: handleError$1
1894
2104
  } = handleError_1;
1895
2105
 
1896
2106
  const getLatestVersion = npmName => {
1897
- const data = shelljs$3.exec(`npm view ${npmName} version`);
2107
+ const data = shelljs$4.exec(`npm view ${npmName} version`);
1898
2108
  return data.stdout || '0.0.0';
1899
- };
1900
- /**
1901
- * 检查package.json的依赖大于node_module的版本,则返回true
1902
- * @param {*} modules 模块
1903
- * @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
1904
- * @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
1905
- * @returns
1906
- */
2109
+ }; // 收集package.json
1907
2110
 
1908
2111
 
1909
- const checkDependencies$1 = (modules, cwd, outputDir) => {
1910
- // 步骤1. 收集package.json
2112
+ function collectPackageJson(subPackages, cwd, outputDir) {
1911
2113
  const packageJsonName = 'package.json'; // 查找文件名
1912
2114
  // 1.1根目录的package.json
1913
2115
 
1914
2116
  const packageArr = [{
1915
- srcPackageDir: path$5.join(cwd, packageJsonName),
1916
- destNpmDir: resolve$8(outputDir, 'node_modules')
2117
+ srcPackageDir: path$7.join(cwd, packageJsonName),
2118
+ destNpmDir: resolve$b(outputDir, 'node_modules')
1917
2119
  }]; // 1.2模块的package.json
1918
2120
 
1919
- modules.forEach(item => {
1920
- const srcPackageDir = path$5.join(cwd, item.path, 'package.json');
2121
+ subPackages.forEach(item => {
2122
+ const srcPackageDir = `${getAbsolutePath$2(item.path)}/package.json`;
1921
2123
 
1922
- if (fs$5.existsSync(srcPackageDir)) {
2124
+ if (fs$8.existsSync(srcPackageDir)) {
1923
2125
  packageArr.push({
1924
2126
  srcPackageDir,
1925
- destNpmDir: resolve$8(outputDir, item.root, 'node_modules')
2127
+ destNpmDir: resolve$b(outputDir, item.root, 'node_modules')
1926
2128
  });
1927
2129
  }
1928
- }); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
2130
+ });
2131
+ return packageArr;
2132
+ } // 读取package.json的依赖
1929
2133
 
1930
- for (const item of packageArr) {
1931
- const packageJson = fs$5.readFileSync(item.srcPackageDir, 'utf-8');
1932
- let dependencies = {};
1933
2134
 
1934
- try {
1935
- const json = JSON.parse(packageJson);
1936
- dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
1937
- } catch (e) {
1938
- handleError$2(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
1939
- }
2135
+ function readPackageDependencies(srcPackageDir) {
2136
+ const packageJson = fs$8.readFileSync(srcPackageDir, 'utf-8');
2137
+ let dependencies = {};
2138
+
2139
+ try {
2140
+ const json = packageJson ? JSON.parse(packageJson) : {};
2141
+ dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
2142
+ } catch (e) {
2143
+ handleError$1(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2144
+ }
2145
+
2146
+ return dependencies;
2147
+ }
2148
+ /**
2149
+ * 检查package.json的依赖大于node_module的版本,则返回true
2150
+ * @param {*} subPackages 模块
2151
+ * @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
2152
+ * @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
2153
+ * @returns
2154
+ */
2155
+
2156
+
2157
+ const isDependenciesUpdate$1 = (subPackages, cwd, outputDir) => {
2158
+ // 步骤1. 收集package.json
2159
+ const packageArr = collectPackageJson(subPackages, cwd, outputDir); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
1940
2160
 
2161
+ return checkPackageVersion$1(packageArr);
2162
+ }; // 比较package.json的依赖与node_modules依赖的版本号
2163
+
2164
+
2165
+ const checkPackageVersion$1 = packageArr => {
2166
+ for (const item of packageArr) {
2167
+ const dependencies = readPackageDependencies(item.srcPackageDir);
1941
2168
  const dependenciesKeys = Object.keys(dependencies);
1942
2169
 
1943
2170
  for (const key of dependenciesKeys) {
1944
- const depPath = path$5.join(item.destNpmDir, key);
2171
+ const depPath = path$7.join(item.destNpmDir, key);
1945
2172
 
1946
- if (!fs$5.existsSync(depPath)) {
2173
+ if (!fs$8.existsSync(depPath)) {
1947
2174
  return true;
1948
2175
  }
1949
2176
 
1950
- const depPackagePath = path$5.join(depPath, 'package.json');
2177
+ const depPackagePath = path$7.join(depPath, 'package.json');
2178
+
2179
+ if (fs$8.existsSync(depPackagePath)) {
2180
+ const packageData = require(depPackagePath);
2181
+
2182
+ if (dependencies[key] === 'latest') {
2183
+ dependencies[key] = getLatestVersion(key);
2184
+ }
2185
+
2186
+ if (packageData.version === 'latest') {
2187
+ packageData.version = getLatestVersion(key);
2188
+ }
2189
+
2190
+ if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
2191
+ return true;
2192
+ }
2193
+ }
2194
+ }
2195
+ }
2196
+
2197
+ return false;
2198
+ };
2199
+
2200
+ var checkDependencies = {
2201
+ isDependenciesUpdate: isDependenciesUpdate$1,
2202
+ checkPackageVersion: checkPackageVersion$1
2203
+ };
2204
+
2205
+ const shelljs$3 = require$$0__default$3;
2206
+ const fs$7 = require$$0__default$2;
2207
+ const path$6 = require$$1__default$2;
2208
+ const io$1 = io$3;
2209
+ const {
2210
+ createTask: createTask$1,
2211
+ resolve: resolve$a,
2212
+ getAbsolutePath: getAbsolutePath$1
2213
+ } = widgets;
2214
+ const {
2215
+ buildMpNpm
2216
+ } = mpCi;
2217
+ const {
2218
+ setCache,
2219
+ getCache
2220
+ } = cache;
2221
+ const {
2222
+ CACHE_DIR: CACHE_DIR$1
2223
+ } = require$$5;
2224
+ const {
2225
+ npmInstallAll
2226
+ } = npm;
2227
+ const {
2228
+ info: info$7
2229
+ } = log$1;
2230
+ const {
2231
+ fileMd5
2232
+ } = md5;
2233
+ const {
2234
+ isDependenciesUpdate
2235
+ } = checkDependencies;
2236
+
2237
+ async function install$2(tmsConfig, subPackages, useCache = true) {
2238
+ const cwd = process.cwd();
2239
+ const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2240
+
2241
+ if (!npmInstallRes.isCache) {
2242
+ // 构建miniprogram_npm, 不使用缓存
2243
+ await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
2244
+ } else {
2245
+ // 构建miniprogram_npm
2246
+ await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2247
+ }
2248
+
2249
+ shelljs$3.cd(cwd);
2250
+ }
2251
+
2252
+ async function npmInstall(tmsConfig, subPackages, useCache) {
2253
+ // 如果依赖没有更新和使用缓存数据(则命中缓存)
2254
+ if (!isDependenciesUpdate(subPackages, resolve$a('./'), tmsConfig.outputDir) && useCache) {
2255
+ info$7('node_modules命中缓存');
2256
+ return {
2257
+ isCache: true
2258
+ };
2259
+ } // 拷贝模块的package.json到编译输出目录
2260
+
2261
+
2262
+ subPackages.forEach(item => {
2263
+ const outputModuleDir = resolve$a(`${tmsConfig.outputDir}/${item.root}`);
2264
+ io$1.ensureDirExist(outputModuleDir);
2265
+ const modulePackagePath = `${getAbsolutePath$1(item.path)}/package.json`;
2266
+ if (fs$7.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
2267
+ });
2268
+ await npmInstallAll(subPackages, resolve$a(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
2269
+ return {
2270
+ isCache: false
2271
+ };
2272
+ } // 构建miniprogram_npm
2273
+
2274
+
2275
+ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2276
+ const packageJsonFiles = [];
2277
+ const rootPackFile = resolve$a(`${tmsConfig.outputDir}/package.json`);
2278
+
2279
+ if (fs$7.existsSync(rootPackFile)) {
2280
+ packageJsonFiles.push(rootPackFile);
2281
+ }
2282
+
2283
+ subPackages.forEach(item => {
2284
+ const packageJsonFile = resolve$a(`${tmsConfig.outputDir}/${item.root}/package.json`);
2285
+
2286
+ if (fs$7.existsSync(packageJsonFile)) {
2287
+ packageJsonFiles.push(packageJsonFile);
2288
+ }
2289
+ });
2290
+ let isCache = false;
2291
+ const statusMap = {
2292
+ success: 1,
2293
+ doing: 2
2294
+ };
2295
+
2296
+ if (useCache) {
2297
+ let flag = true;
2298
+ await Promise.all(packageJsonFiles.map(async item => {
2299
+ const packageDir = path$6.dirname(item);
2300
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2301
+ const md5Value = await getMNPMd5(packageDir);
2302
+ const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
2303
+ // 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
2304
+
2305
+ if ((preCache === null || preCache === void 0 ? void 0 : preCache.status) !== statusMap.success || (preCache === null || preCache === void 0 ? void 0 : preCache.md5) !== md5Value) {
2306
+ flag = false;
2307
+ }
2308
+ }));
2309
+ isCache = flag;
2310
+ }
2311
+
2312
+ if (isCache) {
2313
+ info$7('miniprogram_npm命中缓存');
2314
+ return;
2315
+ } // 即将构建,在cache中标记开始
1951
2316
 
1952
- if (fs$5.existsSync(depPackagePath)) {
1953
- const packageData = require(depPackagePath);
1954
2317
 
1955
- if (dependencies[key] === 'latest') {
1956
- dependencies[key] = getLatestVersion(key);
1957
- }
2318
+ await Promise.all(packageJsonFiles.map(async item => {
2319
+ const packageDir = path$6.dirname(item);
2320
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2321
+ setCache(mpDir, 'miniprogram_npm', {
2322
+ md5: '',
2323
+ status: statusMap.doing
2324
+ });
2325
+ }));
2326
+ await buildMpNpm({
2327
+ appId: tmsConfig.appId,
2328
+ projectPath: resolve$a('./'),
2329
+ privateKey: tmsConfig.privateKey
2330
+ }); // 构建成功后,计算md5写入cache
2331
+
2332
+ await Promise.all(packageJsonFiles.map(async item => {
2333
+ const packageDir = path$6.dirname(item);
2334
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2335
+ const md5Value = await getMNPMd5(packageDir);
2336
+ setCache(mpDir, 'miniprogram_npm', {
2337
+ md5: md5Value,
2338
+ status: statusMap.success
2339
+ });
2340
+ }));
2341
+ } // 计算miniprogram_npm压缩文件的md5值
1958
2342
 
1959
- if (packageData.version === 'latest') {
1960
- packageData.version = getLatestVersion(key);
1961
- }
1962
2343
 
1963
- if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
1964
- return true;
1965
- }
1966
- }
1967
- }
2344
+ async function getMNPMd5(cwd) {
2345
+ const shellJsOption = {
2346
+ async: false,
2347
+ silent: true
2348
+ };
2349
+ shelljs$3.cd(cwd);
2350
+
2351
+ if (fs$7.existsSync('miniprogram_npm')) {
2352
+ shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2353
+ cwd,
2354
+ ...shellJsOption
2355
+ });
2356
+ const tarDir = path$6.join(cwd, './miniprogram_npm.tar.gz');
2357
+ const md5Value = await fileMd5(tarDir);
2358
+ shelljs$3.rm('-rf', tarDir);
2359
+ return md5Value;
1968
2360
  }
1969
2361
 
1970
- return false;
1971
- };
2362
+ return '';
2363
+ }
1972
2364
 
1973
- var checkDependencies_1 = {
1974
- checkDependencies: checkDependencies$1
1975
- };
2365
+ var install_1 = install$2;
1976
2366
 
1977
2367
  const shelljs$2 = require$$0__default$3;
1978
- const fs$4 = require$$0__default$2;
2368
+ const fs$6 = require$$0__default$2;
1979
2369
  const io = io$3;
1980
2370
  const {
1981
- resolve: resolve$7,
2371
+ resolve: resolve$9,
1982
2372
  createTask
1983
2373
  } = widgets;
1984
2374
  const {
1985
- buildOutputAppJson
2375
+ buildOutputAppJson: buildOutputAppJson$1
1986
2376
  } = buildAppJson;
1987
2377
  const {
1988
2378
  MODULE_CODE_DIR,
1989
- DEFAULT_COPY_CONFIG
1990
- } = require$$4;
2379
+ DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
2380
+ } = require$$5;
1991
2381
  const {
1992
2382
  cloneModules
1993
2383
  } = cloneModules_1;
1994
2384
  const {
1995
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2,
1996
- subModulesMergeDepModules: subModulesMergeDepModules$1
1997
- } = tmsMpconfig;
2385
+ getModulesByMergeDepModules: getModulesByMergeDepModules$2,
2386
+ getSubPackages: getSubPackages$2
2387
+ } = tmsMpconfig.exports;
1998
2388
  const {
1999
- fail: fail$2,
2000
- info: info$4
2389
+ fail: fail$4,
2390
+ info: info$6
2001
2391
  } = log$1;
2002
2392
  const install$1 = install_1;
2003
- const {
2004
- checkDependencies
2005
- } = checkDependencies_1;
2006
2393
  /**
2007
2394
  * 拷贝相关配置文件到编译输出目录
2008
2395
  * @param { object } tmsConfig
@@ -2012,73 +2399,47 @@ const {
2012
2399
  */
2013
2400
 
2014
2401
  const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2015
- const outputDir = resolve$7(tmsConfig.outputDir);
2402
+ const outputDir = resolve$9(tmsConfig.outputDir);
2016
2403
  io.ensureDirExist(outputDir);
2017
2404
  defaultFiles.forEach(item => {
2018
- if (fs$4.existsSync(resolve$7(item))) {
2019
- shelljs$2.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
2405
+ if (fs$6.existsSync(resolve$9(item))) {
2406
+ shelljs$2.cp('-rf', resolve$9(item), resolve$9(tmsConfig.outputDir, item));
2020
2407
  }
2021
2408
  });
2022
2409
  };
2023
- /**
2024
- * 校验相关配置项
2025
- * @param {*} targetModules
2026
- * @returns
2027
- */
2028
-
2029
-
2030
- function checkConfig(targetModules) {
2031
- for (const item of targetModules) {
2032
- if (!item.root) {
2033
- throw new Error(`检查${item.name} module.config.json的root字段`);
2034
- } // 判断源码目录是否有该模块
2035
-
2036
-
2037
- if (item.path && !fs$4.existsSync(resolve$7(item.path))) {
2038
- throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2039
- }
2040
- }
2041
-
2042
- return true;
2043
- }
2044
2410
 
2045
2411
  async function task(tmsConfig, targetModules) {
2046
2412
  // 下载和移动代码
2047
- await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$7('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
2048
-
2049
- let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
2413
+ await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$9('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2050
2414
 
2051
- newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
2052
- checkConfig(newModules); // 拷贝相关配置文件到输出目录
2415
+ const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
2053
2416
 
2054
- await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
2417
+ const newSubPackages = getSubPackages$2(newModules); // 拷贝相关配置文件到输出目录
2055
2418
 
2056
- if (checkDependencies(newModules, resolve$7('./'), tmsConfig.outputDir)) {
2057
- await install$1(tmsConfig, newModules);
2058
- } // 动态生成编译后的app.json;
2419
+ await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
2059
2420
 
2421
+ await install$1(tmsConfig, newSubPackages, true); // 动态生成编译后的app.json;
2060
2422
 
2061
- await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2062
- return newModules;
2423
+ await createTask(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2424
+ return {
2425
+ modules: newModules,
2426
+ subPackages: newSubPackages
2427
+ };
2063
2428
  }
2064
2429
 
2065
- async function init$5(tmsConfig, targetModules) {
2430
+ async function init$3(tmsConfig, targetModules) {
2066
2431
  try {
2067
- const newModules = await task(tmsConfig, targetModules);
2068
- return {
2069
- targetModules: newModules
2070
- };
2432
+ const taskRes = await task(tmsConfig, targetModules);
2433
+ return taskRes;
2071
2434
  } catch (error) {
2072
2435
  const errMsg = typeof error === 'object' ? error.message : error;
2073
- fail$2(`初始化流程出现错误${errMsg}`);
2074
- info$4('详细的错误信息', error);
2436
+ fail$4(`初始化流程出现错误: ${errMsg}`);
2437
+ info$6('详细的错误信息', error);
2075
2438
  process.exit(1);
2076
2439
  }
2077
2440
  }
2078
2441
 
2079
- var init_1 = init$5;
2080
-
2081
- var dev$3 = {exports: {}};
2442
+ var init_1 = init$3;
2082
2443
 
2083
2444
  /* eslint-disable no-param-reassign */
2084
2445
  const strip = require$$0__default$8; // 匹配规则
@@ -2116,16 +2477,16 @@ var findCssImport = {
2116
2477
 
2117
2478
  /* eslint-disable no-param-reassign */
2118
2479
  const {
2119
- fail: fail$1
2480
+ fail: fail$3
2120
2481
  } = log$1;
2121
2482
 
2122
2483
  function pluginError$3(error, isWatch) {
2123
2484
  const errMsg = error.message;
2124
2485
 
2125
2486
  if (isWatch) {
2126
- fail$1(errMsg);
2487
+ fail$3(errMsg);
2127
2488
  } else {
2128
- fail$1(errMsg);
2489
+ fail$3(errMsg);
2129
2490
  process.exit(1);
2130
2491
  }
2131
2492
  }
@@ -2137,7 +2498,7 @@ var pluginError_1 = {
2137
2498
  /* eslint-disable no-param-reassign */
2138
2499
  const through$2 = require$$0__default$9;
2139
2500
  const precinct = require$$1__default$8;
2140
- const path$4 = require$$1__default$2;
2501
+ const path$5 = require$$1__default$2;
2141
2502
  const {
2142
2503
  findCssImports
2143
2504
  } = findCssImport;
@@ -2147,9 +2508,9 @@ const {
2147
2508
  diffContentCopyFile: diffContentCopyFile$2
2148
2509
  } = io$3;
2149
2510
  const {
2150
- resolve: resolve$6
2511
+ resolve: resolve$8
2151
2512
  } = widgets;
2152
- const fs$3 = require$$0__default$2;
2513
+ const fs$5 = require$$0__default$2;
2153
2514
  const {
2154
2515
  pluginError: pluginError$2
2155
2516
  } = pluginError_1;
@@ -2162,16 +2523,16 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2162
2523
  let contents = '';
2163
2524
 
2164
2525
  try {
2165
- contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
2526
+ contents = fs$5.readFileSync(anaFileOriginFile, 'utf8');
2166
2527
  } catch (e) {
2167
2528
  pluginError$2(e, isWatch);
2168
2529
  }
2169
2530
 
2170
- const deps = cssFilter.indexOf(path$4.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
2531
+ const deps = cssFilter.indexOf(path$5.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
2171
2532
  deps.forEach(depItem => {
2172
2533
  if (depItem.startsWith('.')) {
2173
2534
  // 被依赖文件的存在的绝对路径
2174
- const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2535
+ const depOriginPath = path$5.join(path$5.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2175
2536
 
2176
2537
  const {
2177
2538
  ext: extAlias,
@@ -2179,12 +2540,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2179
2540
  extPath
2180
2541
  } = ext$2(depOriginPath, extensions);
2181
2542
 
2182
- if (!fs$3.existsSync(depOriginFile)) {
2543
+ if (!fs$5.existsSync(depOriginFile)) {
2183
2544
  pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
2184
2545
  return;
2185
2546
  }
2186
2547
 
2187
- const depDestPath = resolve$6(path$4.dirname(anaFileDestFile), depItem);
2548
+ const depDestPath = resolve$8(path$5.dirname(anaFileDestFile), depItem);
2188
2549
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2189
2550
 
2190
2551
  if (!resDep.has(depDestFile)) {
@@ -2208,19 +2569,19 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2208
2569
  const stream = through$2.obj(function (file, enc, cb) {
2209
2570
  // 依赖分析的文件
2210
2571
  const anaFileOriginFile = file.history[0];
2211
- const anaFileRelativeModule = path$4.relative(resolve$6(module.from), anaFileOriginFile);
2212
- const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2572
+ const anaFileRelativeModule = path$5.relative(resolve$8(module.from), anaFileOriginFile);
2573
+ const anaFileDestFile = resolve$8(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2213
2574
 
2214
2575
  if (file.isBuffer()) {
2215
2576
  let contents = String(file.contents);
2216
- const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
2577
+ const deps = cssFilter.indexOf(path$5.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
2217
2578
  const copyModules = new Map();
2218
2579
  Object.keys(tmsConfig.dependencies).forEach(includeName => {
2219
2580
  const includePath = tmsConfig.dependencies[includeName];
2220
2581
  deps.forEach(depItem => {
2221
2582
  if (depItem.indexOf(includeName) > -1) {
2222
2583
  // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
2223
- const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2584
+ const depOriginPath = path$5.join(path$5.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2224
2585
 
2225
2586
  const {
2226
2587
  ext: extAlias,
@@ -2238,7 +2599,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2238
2599
  const regRes = depItem.match(reg) || [];
2239
2600
 
2240
2601
  if (regRes[2]) {
2241
- const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2602
+ const depDestPath = resolve$8(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2242
2603
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2243
2604
 
2244
2605
  if (!copyModules.has(depDestFile)) {
@@ -2246,7 +2607,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2246
2607
  depOriginFile,
2247
2608
  depDestFile,
2248
2609
  beforeDepPath: depItem,
2249
- afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2610
+ afterDepPath: path$5.relative(path$5.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2250
2611
  });
2251
2612
  }
2252
2613
  }
@@ -2284,16 +2645,16 @@ var mpCommonDep_1 = {
2284
2645
 
2285
2646
  /* eslint-disable no-param-reassign */
2286
2647
  const through$1 = require$$0__default$9;
2287
- const path$3 = require$$1__default$2;
2648
+ const path$4 = require$$1__default$2;
2288
2649
  const {
2289
2650
  ext: ext$1,
2290
2651
  fileInDir: fileInDir$1,
2291
2652
  diffContentCopyFile: diffContentCopyFile$1
2292
2653
  } = io$3;
2293
2654
  const {
2294
- resolve: resolve$5
2655
+ resolve: resolve$7
2295
2656
  } = widgets;
2296
- const fs$2 = require$$0__default$2;
2657
+ const fs$4 = require$$0__default$2;
2297
2658
  const {
2298
2659
  pluginError: pluginError$1
2299
2660
  } = pluginError_1;
@@ -2305,8 +2666,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2305
2666
  const stream = through$1.obj(function (file, enc, cb) {
2306
2667
  // 当前分析的文件的路径
2307
2668
  const anaFileOriginFile = file.history[0];
2308
- const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
2309
- const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2669
+ const anaFileRelativeModule = path$4.relative(resolve$7(module.from), anaFileOriginFile);
2670
+ const anaFileDestFile = resolve$7(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2310
2671
 
2311
2672
  if (file.isBuffer()) {
2312
2673
  let contents = String(file.contents);
@@ -2326,7 +2687,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2326
2687
  const componentPath = contents.usingComponents[componentKey];
2327
2688
 
2328
2689
  if (componentPath.indexOf(includeName) > -1) {
2329
- const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
2690
+ const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
2330
2691
 
2331
2692
  const {
2332
2693
  ext: extAlias,
@@ -2345,7 +2706,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2345
2706
  const regRes = componentPath.match(reg) || [];
2346
2707
 
2347
2708
  if (regRes[2]) {
2348
- const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2709
+ const depDestPath = resolve$7(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2349
2710
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2350
2711
 
2351
2712
  if (!copyModules.has(depDestFile)) {
@@ -2354,7 +2715,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2354
2715
  depOriginExt: extAlias,
2355
2716
  depDestFile,
2356
2717
  beforeDepPath: componentPath,
2357
- afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2718
+ afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2358
2719
  });
2359
2720
  }
2360
2721
  }
@@ -2379,7 +2740,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2379
2740
  const originFile = depOriginFile.replace(depOriginExt, extKey);
2380
2741
  const destFile = depDestFile.replace(depOriginExt, extKey);
2381
2742
 
2382
- if (fs$2.existsSync(originFile)) {
2743
+ if (fs$4.existsSync(originFile)) {
2383
2744
  diffContentCopyFile$1(originFile, destFile);
2384
2745
  const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
2385
2746
 
@@ -2413,15 +2774,15 @@ var mpJsonDep_1 = {
2413
2774
  /* eslint-disable no-param-reassign */
2414
2775
  const through = require$$0__default$9;
2415
2776
  const htmlparser2 = require$$1__default$9;
2416
- const fs$1 = require$$0__default$2;
2417
- const path$2 = require$$1__default$2;
2777
+ const fs$3 = require$$0__default$2;
2778
+ const path$3 = require$$1__default$2;
2418
2779
  const {
2419
2780
  diffContentCopyFile,
2420
2781
  ext,
2421
2782
  fileInDir
2422
2783
  } = io$3;
2423
2784
  const {
2424
- resolve: resolve$4
2785
+ resolve: resolve$6
2425
2786
  } = widgets;
2426
2787
  const {
2427
2788
  dfsFindCommonDep
@@ -2460,7 +2821,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2460
2821
  let contents = '';
2461
2822
 
2462
2823
  try {
2463
- contents = fs$1.readFileSync(anaFileOriginFile, 'utf8');
2824
+ contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
2464
2825
  } catch (e) {
2465
2826
  pluginError(e, isWatch);
2466
2827
  }
@@ -2470,7 +2831,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2470
2831
  var _attributes$src;
2471
2832
 
2472
2833
  if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
2473
- const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2834
+ const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2474
2835
 
2475
2836
  const {
2476
2837
  ext,
@@ -2478,12 +2839,12 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2478
2839
  extPath
2479
2840
  } = extFile(name, depOriginPath);
2480
2841
 
2481
- if (!fs$1.existsSync(depOriginFile)) {
2842
+ if (!fs$3.existsSync(depOriginFile)) {
2482
2843
  pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
2483
2844
  return;
2484
2845
  }
2485
2846
 
2486
- const depDestPath = path$2.join(path$2.dirname(anaFileDestFile), attributes.src);
2847
+ const depDestPath = path$3.join(path$3.dirname(anaFileDestFile), attributes.src);
2487
2848
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
2488
2849
 
2489
2850
  if (['import', 'include'].indexOf(name) > -1) {
@@ -2535,8 +2896,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2535
2896
  const stream = through.obj(function (file, enc, cb) {
2536
2897
  // 依赖分析的文件
2537
2898
  const anaFileOriginFile = file.history[0];
2538
- const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
2539
- const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2899
+ const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
2900
+ const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2540
2901
 
2541
2902
  if (file.isBuffer()) {
2542
2903
  let contents = String(file.contents);
@@ -2546,7 +2907,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2546
2907
  const nameFilter = ['import', 'include', 'wxs'];
2547
2908
 
2548
2909
  if (nameFilter.indexOf(name) > -1 && attributes.src) {
2549
- const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2910
+ const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2550
2911
 
2551
2912
  const {
2552
2913
  ext,
@@ -2567,7 +2928,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2567
2928
  const regRes = attributes.src.match(reg) || [];
2568
2929
 
2569
2930
  if (regRes[2]) {
2570
- const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2931
+ const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2571
2932
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
2572
2933
 
2573
2934
  if (!copyModules.has(depDestFile)) {
@@ -2575,7 +2936,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2575
2936
  depOriginFile,
2576
2937
  depDestFile,
2577
2938
  beforeDepPath: attributes.src,
2578
- afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2939
+ afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2579
2940
  });
2580
2941
  }
2581
2942
  }
@@ -2594,7 +2955,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2594
2955
  beforeDepPath,
2595
2956
  afterDepPath
2596
2957
  }) => {
2597
- if (fs$1.existsSync(depOriginFile)) {
2958
+ if (fs$3.existsSync(depOriginFile)) {
2598
2959
  diffContentCopyFile(depOriginFile, depDestFile);
2599
2960
  const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
2600
2961
  contents = contents.replace(reg, `"${afterDepPath}"`);
@@ -2650,10 +3011,10 @@ const {
2650
3011
  // const base64 = require('./plugins/postcss-font-base64');
2651
3012
 
2652
3013
  const {
2653
- fail
3014
+ fail: fail$2
2654
3015
  } = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
2655
3016
 
2656
- var compile = function (tmsConfig, {
3017
+ var compile$1 = function (tmsConfig, {
2657
3018
  glob,
2658
3019
  destPath,
2659
3020
  srcOption,
@@ -2675,11 +3036,11 @@ var compile = function (tmsConfig, {
2675
3036
  });
2676
3037
  return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
2677
3038
  .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
2678
- fail(`mpCommonDep编译报错${err}`);
3039
+ fail$2(`mpCommonDep编译报错${err}`);
2679
3040
  }).pipe(dest(newDestPath, {
2680
3041
  overwrite: true
2681
3042
  })).on('error', err => {
2682
- fail(`js编译报错${err}`);
3043
+ fail$2(`js编译报错${err}`);
2683
3044
  });
2684
3045
  }
2685
3046
  });
@@ -2694,7 +3055,7 @@ var compile = function (tmsConfig, {
2694
3055
  const srcPipe = src$1(newGlobValue, { ...srcOption
2695
3056
  });
2696
3057
  return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
2697
- fail(`mpCommonDep编译报错${err}`);
3058
+ fail$2(`mpCommonDep编译报错${err}`);
2698
3059
  }) // .pipe(postcss([base64()]))
2699
3060
  // .on('error', (err) => {
2700
3061
  // fail(`postcss编译报错${err}`);
@@ -2704,7 +3065,7 @@ var compile = function (tmsConfig, {
2704
3065
  // precision: 2, // 小数最大精度,默认为6
2705
3066
  // }))
2706
3067
  .pipe(dest(newDestPath)).on('error', err => {
2707
- fail(`wxss编译报错${err}`);
3068
+ fail$2(`wxss编译报错${err}`);
2708
3069
  });
2709
3070
  }
2710
3071
  });
@@ -2719,9 +3080,9 @@ var compile = function (tmsConfig, {
2719
3080
  const srcPipe = src$1(newGlobValue, { ...srcOption
2720
3081
  });
2721
3082
  return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
2722
- fail(`mpJsonDep编译报错${err}`);
3083
+ fail$2(`mpJsonDep编译报错${err}`);
2723
3084
  }).pipe(dest(newDestPath)).on('error', err => {
2724
- fail(`json编译报错${err}`);
3085
+ fail$2(`json编译报错${err}`);
2725
3086
  });
2726
3087
  }
2727
3088
  });
@@ -2736,9 +3097,9 @@ var compile = function (tmsConfig, {
2736
3097
  const srcPipe = src$1(newGlobValue, { ...srcOption
2737
3098
  });
2738
3099
  return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
2739
- fail(`mpWxmlDep编译报错${err}`);
3100
+ fail$2(`mpWxmlDep编译报错${err}`);
2740
3101
  }).pipe(dest(newDestPath)).on('error', err => {
2741
- fail(`wxml编译报错${err}`);
3102
+ fail$2(`wxml编译报错${err}`);
2742
3103
  });
2743
3104
  }
2744
3105
  });
@@ -2757,7 +3118,7 @@ var compile = function (tmsConfig, {
2757
3118
  // fail(`image编译报错${err}`);
2758
3119
  // })
2759
3120
  .pipe(dest(newDestPath)).on('error', err => {
2760
- fail(`image编译报错${err}`);
3121
+ fail$2(`image编译报错${err}`);
2761
3122
  });
2762
3123
  }
2763
3124
  });
@@ -2772,7 +3133,7 @@ var compile = function (tmsConfig, {
2772
3133
  const srcPipe = src$1(newGlobValue, { ...srcOption
2773
3134
  });
2774
3135
  return srcPipe.pipe(dest(newDestPath)).on('error', err => {
2775
- fail(`编译报错${err}`);
3136
+ fail$2(`编译报错${err}`);
2776
3137
  });
2777
3138
  }
2778
3139
  });
@@ -2786,18 +3147,18 @@ var compile = function (tmsConfig, {
2786
3147
  // 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
2787
3148
 
2788
3149
  const assign = require$$0__default$b;
2789
- const path$1 = require$$1__default$2;
3150
+ const path$2 = require$$1__default$2;
2790
3151
  const PluginError = require$$2__default$1;
2791
3152
  const fancyLog = require$$3__default;
2792
3153
  const colors = require$$4__default;
2793
- const chokidar = require$$5__default$1;
3154
+ const chokidar = require$$5__default;
2794
3155
  const {
2795
3156
  Duplex
2796
- } = require$$6__default;
3157
+ } = require$$6__default$1;
2797
3158
  const vinyl = require$$7__default;
2798
3159
  const File = require$$8__default;
2799
- const anymatch = require$$9__default;
2800
- const pathIsAbsolute = require$$10__default;
3160
+ const anymatch = require$$9__default$1;
3161
+ const pathIsAbsolute = require$$10__default$1;
2801
3162
  const globParent = require$$11__default;
2802
3163
  const slash = require$$12__default;
2803
3164
 
@@ -2817,7 +3178,7 @@ function normalizeGlobs(globs) {
2817
3178
  return globs;
2818
3179
  }
2819
3180
 
2820
- function watch$1(globs, opts, cb) {
3181
+ function watch$2(globs, opts, cb) {
2821
3182
  globs = normalizeGlobs(globs);
2822
3183
 
2823
3184
  if (typeof opts === 'function') {
@@ -2825,16 +3186,16 @@ function watch$1(globs, opts, cb) {
2825
3186
  opts = {};
2826
3187
  }
2827
3188
 
2828
- opts = assign({}, watch$1._defaultOptions, opts);
3189
+ opts = assign({}, watch$2._defaultOptions, opts);
2829
3190
 
2830
3191
  cb = cb || function () {};
2831
3192
 
2832
3193
  function resolveFilepath(filepath) {
2833
3194
  if (pathIsAbsolute(filepath)) {
2834
- return path$1.normalize(filepath);
3195
+ return path$2.normalize(filepath);
2835
3196
  }
2836
3197
 
2837
- return path$1.resolve(opts.cwd || process.cwd(), filepath);
3198
+ return path$2.resolve(opts.cwd || process.cwd(), filepath);
2838
3199
  }
2839
3200
 
2840
3201
  function resolveGlob(glob) {
@@ -2890,7 +3251,7 @@ function watch$1(globs, opts, cb) {
2890
3251
  let glob;
2891
3252
  let currentFilepath = filepath;
2892
3253
 
2893
- while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$1.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
3254
+ while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$2.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
2894
3255
 
2895
3256
 
2896
3257
  if (!glob) {
@@ -2899,7 +3260,7 @@ function watch$1(globs, opts, cb) {
2899
3260
  }
2900
3261
 
2901
3262
  if (!baseForced) {
2902
- fileOpts.base = path$1.normalize(globParent(glob));
3263
+ fileOpts.base = path$2.normalize(globParent(glob));
2903
3264
  } // Do not stat deleted files
2904
3265
 
2905
3266
 
@@ -2950,54 +3311,76 @@ function watch$1(globs, opts, cb) {
2950
3311
  // Avoid modifying gulp-watch's default options inside a library/reusable package, please.
2951
3312
 
2952
3313
 
2953
- watch$1._defaultOptions = {
3314
+ watch$2._defaultOptions = {
2954
3315
  events: ['add', 'change', 'unlink'],
2955
3316
  ignoreInitial: true,
2956
3317
  readDelay: 10
2957
3318
  };
2958
- var gulpWatch = watch$1;
3319
+ var gulpWatch = watch$2;
2959
3320
 
2960
- const watch = gulpWatch;
2961
- const path = require$$1__default$2;
3321
+ /* eslint-disable no-restricted-syntax */
3322
+ const watch$1 = gulpWatch;
3323
+ const path$1 = require$$1__default$2;
2962
3324
  const shellJs = require$$0__default$3;
2963
3325
  const {
2964
- info: info$3,
2965
- warn: warn$1
3326
+ info: info$5,
3327
+ warn: warn$1,
3328
+ fail: fail$1
2966
3329
  } = log$1;
2967
3330
  const {
2968
- resolve: resolve$3
3331
+ resolve: resolve$5
2969
3332
  } = widgets;
2970
3333
  const {
2971
3334
  global: global$2
2972
3335
  } = global_1;
3336
+ const {
3337
+ checkPackageVersion
3338
+ } = checkDependencies;
2973
3339
  const {
2974
3340
  findAllFilesOfDir
2975
3341
  } = io$3;
2976
3342
  const TIP_MAP = {
2977
- 'package.json': '若依赖有变动,请重新执行tmskit run dev',
2978
- 'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效'
3343
+ 'package.json': {
3344
+ tip: '依赖版本有变动,请重新执行tmskit run dev',
3345
+ check: (sourceFile, targetFile) => {
3346
+ const targetArr = targetFile.split('/');
3347
+ targetArr[targetArr.length - 1] = 'node_modules';
3348
+ const packageArr = [{
3349
+ srcPackageDir: sourceFile,
3350
+ destNpmDir: targetArr.join('/')
3351
+ }];
3352
+ return checkPackageVersion(packageArr);
3353
+ }
3354
+ },
3355
+ 'module.config.json': {
3356
+ tip: '若dependencies字段有变动,请重新执行tmskit run dev才会生效',
3357
+ check: () => true
3358
+ }
2979
3359
  };
2980
3360
 
2981
- const logTip = (fileName, tipMap) => {
2982
- // eslint-disable-next-line
2983
- for (const item in tipMap) {
2984
- if (fileName.indexOf(item) > -1) {
2985
- warn$1(`${fileName}有更新, ${tipMap[item]}`);
2986
- return;
3361
+ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
3362
+ try {
3363
+ for (const item in tipMap) {
3364
+ if (fileName.indexOf(item) > -1 && tipMap[item].check(sourceFile, targetFile)) {
3365
+ warn$1(`${fileName}有更新, ${tipMap[item].tip}`);
3366
+ return;
3367
+ }
2987
3368
  }
2988
- }
2989
3369
 
2990
- info$3(`${fileName}有更新`);
3370
+ info$5(`${fileName}有更新`);
3371
+ } catch (e) {
3372
+ fail$1(`${sourceFile}文件更新提示出现错误: ${e.message}`);
3373
+ }
2991
3374
  };
2992
3375
 
2993
3376
  const getTargetFile = (sourceFile, module, outputDir) => {
2994
- const sourceFileRelativeModule = path.relative(resolve$3(module.from), sourceFile);
2995
- const targetFile = resolve$3(outputDir, module.to, sourceFileRelativeModule);
3377
+ const sourceFileRelativeModule = path$1.relative(resolve$5(module.from), sourceFile);
3378
+ const targetFile = resolve$5(outputDir, module.to, sourceFileRelativeModule);
2996
3379
  return targetFile;
2997
3380
  };
2998
3381
 
2999
3382
  var watch_1 = function (globValue, watchOptions, callback, module) {
3000
- watch(globValue, { // readDelay: 100,
3383
+ watch$1(globValue, { // readDelay: 100,
3001
3384
  ...watchOptions
3002
3385
  }, vinyl => {
3003
3386
  const sourceFile = vinyl.history[0];
@@ -3006,15 +3389,15 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3006
3389
  const tmsConfig = global$2.getData('tmsConfig');
3007
3390
 
3008
3391
  if (vinyl.event === 'addDir') {
3009
- info$3(`更新${sourceFileName}目录`);
3392
+ info$5(`更新${sourceFileName}目录`);
3010
3393
  const files = findAllFilesOfDir(sourceFile);
3011
3394
 
3012
3395
  for (const file of files) {
3013
3396
  const fileDirArr = file.replace(/\\/g, '/').split('/');
3014
3397
  const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
3015
3398
  const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
3016
- logTip(fileName, TIP_MAP);
3017
- callback([file], path.dirname(targetFile));
3399
+ logTip(fileName, sourceFile, targetFile, TIP_MAP);
3400
+ callback([file], path$1.dirname(targetFile));
3018
3401
  }
3019
3402
 
3020
3403
  return;
@@ -3023,262 +3406,266 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3023
3406
  const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
3024
3407
 
3025
3408
  if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
3026
- info$3(`删除${sourceFileName}`);
3409
+ info$5(`删除${sourceFileName}`);
3027
3410
  shellJs.rm('-rf', targetFile);
3028
3411
  return;
3029
3412
  }
3030
3413
 
3031
- logTip(sourceFileName, TIP_MAP);
3032
- return callback([sourceFile], path.dirname(targetFile));
3414
+ logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
3415
+ return callback([sourceFile], path$1.dirname(targetFile));
3033
3416
  });
3034
3417
  };
3035
3418
 
3036
- (function (module) {
3037
- const path = require$$1__default$2;
3038
- const fs = require$$0__default$2;
3039
- const ora = require$$2__default;
3040
- const chalk = require$$0__default;
3041
- const {
3042
- parallel,
3043
- series
3044
- } = require$$0__default$a;
3045
- const {
3046
- resolve,
3047
- mergeMap,
3048
- filterField
3049
- } = widgets;
3050
- const {
3051
- buildOutputAppJson
3052
- } = buildAppJson;
3053
- const {
3054
- DEFAULT_COPY_CONFIG
3055
- } = require$$4;
3056
- const compile$1 = compile;
3057
- const watch = watch_1;
3058
- const {
3059
- info
3060
- } = log$1;
3061
- const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
3062
-
3063
- function excludeGlob(glob) {
3064
- const otherArr = new Set();
3065
- otherArr.add('!**/*.{ttf,otf,woff,eot}');
3066
- Object.keys(glob).forEach(globKey => {
3067
- if (typeof glob[globKey] === 'string') {
3068
- const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
3069
- otherArr.add(data);
3070
- }
3419
+ const path = require$$1__default$2;
3420
+ const fs$2 = require$$0__default$2;
3421
+ const ora = require$$2__default;
3422
+ const chalk$2 = require$$0__default;
3423
+ const {
3424
+ parallel,
3425
+ series
3426
+ } = require$$0__default$a;
3427
+ const {
3428
+ resolve: resolve$4,
3429
+ mergeMap,
3430
+ filterField: filterField$2,
3431
+ getAbsolutePath
3432
+ } = widgets;
3433
+ const {
3434
+ buildOutputAppJson
3435
+ } = buildAppJson;
3436
+ const {
3437
+ DEFAULT_COPY_CONFIG
3438
+ } = require$$5;
3439
+ const compile = compile$1;
3440
+ const watch = watch_1;
3441
+ const {
3442
+ info: info$4
3443
+ } = log$1;
3444
+ const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
3071
3445
 
3072
- if (Array.isArray(glob[globKey])) {
3073
- glob[globKey].forEach(value => {
3074
- if (typeof value === 'string') {
3075
- const data = value.startsWith('!') ? value : `!${value}`;
3076
- otherArr.add(data);
3077
- }
3078
- });
3079
- }
3080
- });
3081
- return Array.from(otherArr);
3082
- }
3446
+ function excludeGlob(glob) {
3447
+ const otherArr = new Set();
3448
+ otherArr.add('!**/*.{ttf,otf,woff,eot}');
3449
+ Object.keys(glob).forEach(globKey => {
3450
+ if (typeof glob[globKey] === 'string') {
3451
+ const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
3452
+ otherArr.add(data);
3453
+ }
3083
3454
 
3084
- function adaptPath(pathDir) {
3085
- let newPath = pathDir;
3086
- newPath = newPath.startsWith('/') ? newPath : resolve(newPath);
3087
- newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
3088
- return newPath;
3089
- }
3455
+ if (Array.isArray(glob[globKey])) {
3456
+ glob[globKey].forEach(value => {
3457
+ if (typeof value === 'string') {
3458
+ const data = value.startsWith('!') ? value : `!${value}`;
3459
+ otherArr.add(data);
3460
+ }
3461
+ });
3462
+ }
3463
+ });
3464
+ return Array.from(otherArr);
3465
+ }
3466
+
3467
+ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3468
+ const compileTasksMap = new Map(); // 监听根目录的文件
3469
+
3470
+ mergeMap(compileTasksMap, compile(tmsConfig, {
3471
+ glob: {
3472
+ json: DEFAULT_COPY_CONFIG.map(item => resolve$4(item))
3473
+ },
3474
+ module: {
3475
+ from: resolve$4(),
3476
+ to: resolve$4(tmsConfig.outputDir)
3477
+ },
3478
+ destPath: resolve$4(tmsConfig.outputDir),
3479
+ srcOption: {
3480
+ allowEmpty: true
3481
+ },
3482
+ isDev
3483
+ })); // 监听模块的文件
3484
+
3485
+ for (let moduleItem of modules) {
3486
+ // 处理默认参数
3487
+ moduleItem = { ...{
3488
+ exclude: []
3489
+ },
3490
+ ...moduleItem
3491
+ };
3492
+ const srcModulePath = getAbsolutePath(moduleItem.path);
3493
+ const buildModulePath = resolve$4(tmsConfig.outputDir, moduleItem.modulePath);
3494
+
3495
+ if (isDev) {
3496
+ // 监听模块配置文件
3497
+ watch([`${srcModulePath}/**/module.config.json`], {
3498
+ events: watchEvents
3499
+ }, () => buildOutputAppJson(tmsConfig, modules, isDev), {
3500
+ from: srcModulePath,
3501
+ to: buildModulePath
3502
+ });
3503
+ }
3090
3504
 
3091
- module.exports = async (tmsConfig, newModules, isDev = true) => {
3092
- const compileTasksMap = new Map(); // 监听根目录的文件
3505
+ const excludes = moduleItem.exclude.map(ePath => {
3506
+ const newPath = getAbsolutePath(ePath, srcModulePath);
3507
+ const ext = path.extname(ePath).slice(1);
3093
3508
 
3094
- mergeMap(compileTasksMap, compile$1(tmsConfig, {
3095
- glob: {
3096
- json: DEFAULT_COPY_CONFIG.map(item => resolve(item)) // wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
3097
- // js: ['app.js', 'app.ts'].map(item => resolve(item)),
3509
+ if (ext) {
3510
+ return `!${resolve$4(srcModulePath, newPath)}`;
3511
+ }
3098
3512
 
3513
+ return `!${resolve$4(srcModulePath, newPath)}/**/*`;
3514
+ });
3515
+ const glob = {
3516
+ js: [`${srcModulePath}/**/*.{js,ts,wxs}`, ...excludes],
3517
+ json: [`${srcModulePath}/**/*.json`, `!${srcModulePath}/**/module.config.json`, ...excludes],
3518
+ wxss: [`${srcModulePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
3519
+ wxml: [`${srcModulePath}/**/*.wxml`, ...excludes],
3520
+ image: [`${srcModulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
3521
+ };
3522
+ mergeMap(compileTasksMap, compile(tmsConfig, {
3523
+ glob: { ...glob,
3524
+ other: [`${srcModulePath}/**/*`, ...excludeGlob(glob)]
3099
3525
  },
3526
+ destPath: buildModulePath,
3100
3527
  module: {
3101
- from: resolve(),
3102
- to: resolve(tmsConfig.outputDir)
3528
+ from: srcModulePath,
3529
+ to: buildModulePath
3103
3530
  },
3104
- destPath: resolve(tmsConfig.outputDir),
3105
3531
  srcOption: {
3106
3532
  allowEmpty: true
3107
3533
  },
3108
3534
  isDev
3109
- })); // 监听模块的文件
3535
+ }));
3536
+ } // 静态资源目录-拷贝
3110
3537
 
3111
- for (let module of newModules) {
3112
- // 处理默认参数
3113
- module = { ...{
3114
- exclude: []
3115
- },
3116
- ...module
3117
- };
3118
- const modulePath = adaptPath(module.path);
3119
3538
 
3120
- if (isDev) {
3121
- // 监听模块配置文件
3122
- watch([`${modulePath}/**/module.config.json`], {
3123
- events: watchEvents
3124
- }, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
3125
- from: modulePath,
3126
- to: modulePath
3127
- });
3539
+ if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
3540
+ for (const item of tmsConfig.static) {
3541
+ item.from = getAbsolutePath(item.from);
3542
+ item.to = getAbsolutePath(item.to);
3543
+ let glob = {};
3544
+ const ext = path.extname(item.from).slice(1);
3545
+
3546
+ if (ext) {
3547
+ glob[ext] = [item.from];
3548
+ } else {
3549
+ glob = {
3550
+ js: [`${item.from}/**/*.{js,ts,wxs}`],
3551
+ json: [`${item.from}/**/*.json`],
3552
+ wxss: [`${item.from}/**/*.{less,wxss,scss,sass,styl}`],
3553
+ wxml: [`${item.from}/**/*.wxml`],
3554
+ image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
3555
+ };
3556
+ glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
3128
3557
  }
3129
3558
 
3130
- const excludes = module.exclude.map(key => `!${resolve(key)}`);
3131
- const glob = {
3132
- js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
3133
- json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
3134
- wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
3135
- wxml: [`${modulePath}/**/*.wxml`, ...excludes],
3136
- image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
3137
- };
3138
- mergeMap(compileTasksMap, compile$1(tmsConfig, {
3139
- glob: { ...glob,
3140
- other: [`${modulePath}/**/*`, ...excludeGlob(glob)]
3141
- },
3142
- destPath: resolve(tmsConfig.outputDir, module.root),
3559
+ const from = fs$2.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
3560
+ mergeMap(compileTasksMap, compile(tmsConfig, {
3561
+ glob,
3562
+ destPath: item.to,
3143
3563
  module: {
3144
- from: module.path,
3145
- to: module.root
3564
+ from,
3565
+ to: item.to
3146
3566
  },
3147
3567
  srcOption: {
3148
3568
  allowEmpty: true
3149
3569
  },
3150
3570
  isDev
3151
3571
  }));
3152
- } // 静态资源目录-拷贝
3153
-
3154
-
3155
- if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
3156
- for (const item of tmsConfig.static) {
3157
- item.from = adaptPath(item.from);
3158
- item.to = adaptPath(item.to);
3159
- let glob = {};
3160
- const ext = path.extname(item.from).slice(1);
3161
-
3162
- if (ext) {
3163
- glob[ext] = [item.from];
3164
- } else {
3165
- glob = {
3166
- js: [`${item.from}/**/*.{js,ts,wxs}`],
3167
- json: [`${item.from}/**/*.json`],
3168
- wxss: [`${item.from}/**/*.{less,wxss}`],
3169
- wxml: [`${item.from}/**/*.wxml`],
3170
- image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
3171
- };
3172
- glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
3173
- }
3174
-
3175
- const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
3176
- mergeMap(compileTasksMap, compile$1(tmsConfig, {
3177
- glob,
3178
- destPath: item.to,
3179
- module: {
3180
- from,
3181
- to: item.to
3182
- },
3183
- srcOption: {
3184
- allowEmpty: true
3185
- },
3186
- isDev
3187
- }));
3188
- }
3189
3572
  }
3573
+ }
3190
3574
 
3191
- let sTime;
3192
- let eTime;
3193
- const spinner = ora();
3575
+ let sTime;
3576
+ let eTime;
3577
+ const spinner = ora();
3194
3578
 
3195
- function start(cb) {
3196
- info('启动编译...');
3197
- spinner.start();
3198
- sTime = new Date().getTime();
3199
- cb();
3200
- }
3579
+ function start(cb) {
3580
+ info$4('启动编译...');
3581
+ spinner.start();
3582
+ sTime = new Date().getTime();
3583
+ cb();
3584
+ }
3201
3585
 
3202
- async function end(cb) {
3203
- var _tmsConfig$hooks;
3586
+ async function end(cb) {
3587
+ var _tmsConfig$hooks;
3204
3588
 
3205
- if (isDev) {
3206
- // 监听app.json
3207
- watch([resolve('app.json')], {
3208
- ignoreInitial: false,
3589
+ if (isDev) {
3590
+ // 监听app.json
3591
+ watch([resolve$4('app.json')], {
3592
+ ignoreInitial: false,
3593
+ events: watchEvents
3594
+ }, () => buildOutputAppJson(tmsConfig, modules, isDev), {
3595
+ from: resolve$4(),
3596
+ to: resolve$4(tmsConfig.outputDir)
3597
+ }); // 监听其他文件
3598
+
3599
+ compileTasksMap.forEach(({
3600
+ taskFn,
3601
+ module
3602
+ }, globValue) => {
3603
+ watch(globValue, {
3604
+ ignoreInitial: true,
3209
3605
  events: watchEvents
3210
- }, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
3211
- from: resolve(),
3212
- to: resolve(tmsConfig.outputDir)
3213
- }); // 监听其他文件
3214
-
3215
- compileTasksMap.forEach(({
3216
- taskFn,
3217
- module
3218
- }, globValue) => {
3219
- watch(globValue, {
3220
- ignoreInitial: true,
3221
- events: watchEvents
3222
- }, taskFn, module);
3223
- });
3224
- } else {
3225
- buildOutputAppJson(tmsConfig, newModules, isDev);
3226
- }
3227
-
3228
- eTime = new Date().getTime() - sTime;
3606
+ }, taskFn, module);
3607
+ });
3608
+ } else {
3609
+ buildOutputAppJson(tmsConfig, modules, isDev);
3610
+ }
3229
3611
 
3230
- if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
3231
- var _tmsConfig$hooks2;
3612
+ eTime = new Date().getTime() - sTime;
3232
3613
 
3233
- await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
3234
- isDev,
3235
- tmsConfig: filterField(tmsConfig, ['gitAccount']),
3236
- modules: newModules
3237
- }));
3238
- }
3614
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
3615
+ var _tmsConfig$hooks2;
3239
3616
 
3240
- spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
3241
- spinner.stop();
3242
- cb();
3617
+ await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
3618
+ isDev,
3619
+ tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
3620
+ modules
3621
+ }));
3243
3622
  }
3244
3623
 
3245
- const compileTasks = [];
3246
- compileTasksMap.forEach(({
3247
- taskFn
3248
- }) => {
3249
- compileTasks.push(taskFn);
3250
- }); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
3624
+ spinner.succeed(chalk$2.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
3625
+ spinner.stop();
3626
+ cb();
3627
+ }
3628
+
3629
+ const compileTasks = [];
3630
+ compileTasksMap.forEach(({
3631
+ taskFn
3632
+ }) => {
3633
+ compileTasks.push(taskFn);
3634
+ }); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
3251
3635
 
3252
- series(start, parallel(...compileTasks), end)();
3253
- };
3254
- })(dev$3);
3636
+ series(start, parallel(...compileTasks), end)();
3637
+ };
3255
3638
 
3256
3639
  const shelljs$1 = require$$0__default$3;
3257
- const compileDev = dev$3.exports;
3640
+ const compileDev = dev$3;
3258
3641
  const {
3259
- resolve: resolve$2,
3642
+ resolve: resolve$3,
3260
3643
  filterField: filterField$1
3261
3644
  } = widgets;
3262
- const init$4 = init_1;
3645
+ const init$2 = init_1;
3263
3646
  const {
3264
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
3265
- } = tmsMpconfig;
3647
+ getModulesByMergeDepModules: getModulesByMergeDepModules$1,
3648
+ getSubPackages: getSubPackages$1
3649
+ } = tmsMpconfig.exports;
3266
3650
  const {
3267
- info: info$2
3651
+ info: info$3
3268
3652
  } = log$1;
3269
3653
  const {
3270
3654
  global: global$1
3271
3655
  } = global_1;
3272
3656
  const {
3273
3657
  CACHE_DIR
3274
- } = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3275
-
3276
- function delOtherModule(tmsConfig, targetModules) {
3277
- const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules.all, tmsConfig.appName);
3278
- const targetModulesName = targetModules.map(item => item.name);
3279
- modules.forEach(item => {
3280
- if (item.root && targetModulesName.indexOf(item.name) === -1) {
3281
- const moduleRootDir = resolve$2(`dist/${item.root}`);
3658
+ } = require$$5; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3659
+
3660
+ function delOtherPackages(tmsConfig, targetSubPackages) {
3661
+ // 获取所有模块,合并模块依赖的模块
3662
+ const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all); // 获取所有的分包
3663
+
3664
+ const allSubPackages = getSubPackages$1(allModules);
3665
+ const targetSubPackagesName = targetSubPackages.map(item => item.name);
3666
+ allSubPackages.forEach(item => {
3667
+ if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
3668
+ const moduleRootDir = resolve$3(`${tmsConfig.outputDir}/${item.root}`);
3282
3669
  shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
3283
3670
  silent: true
3284
3671
  }); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
@@ -3287,23 +3674,24 @@ function delOtherModule(tmsConfig, targetModules) {
3287
3674
  });
3288
3675
  }
3289
3676
 
3290
- async function dev$2(tmsConfig, targetModules, env) {
3677
+ async function dev$2(tmsConfig, targetModules) {
3291
3678
  var _tmsConfig$hooks;
3292
3679
 
3293
- let newModules = targetModules;
3294
3680
  const {
3295
3681
  noCache
3296
3682
  } = global$1.getData('cmd');
3297
3683
 
3298
3684
  if (noCache) {
3299
- shelljs$1.rm('-rf', resolve$2(tmsConfig.outputDir));
3685
+ shelljs$1.rm('-rf', resolve$3(tmsConfig.outputDir));
3300
3686
  shelljs$1.rm('-rf', CACHE_DIR);
3301
3687
  } // 初始化操作
3302
3688
 
3303
3689
 
3304
- const initData = await init$4(tmsConfig, newModules);
3305
- newModules = initData.targetModules;
3306
- info$2('当前dev启动的有效模块', newModules.map(item => item.name).sort());
3690
+ const {
3691
+ subPackages,
3692
+ modules: newModules
3693
+ } = await init$2(tmsConfig, targetModules);
3694
+ info$3('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3307
3695
 
3308
3696
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
3309
3697
  var _tmsConfig$hooks2;
@@ -3314,61 +3702,60 @@ async function dev$2(tmsConfig, targetModules, env) {
3314
3702
  modules: newModules
3315
3703
  }));
3316
3704
  }
3317
- delOtherModule(tmsConfig, newModules);
3318
- compileDev(tmsConfig, newModules, env);
3705
+ delOtherPackages(tmsConfig, subPackages);
3706
+ compileDev(tmsConfig, newModules, true);
3319
3707
  }
3320
3708
 
3321
3709
  var dev_1 = dev$2;
3322
3710
 
3323
- const dev$1 = dev$3.exports;
3711
+ const dev$1 = dev$3;
3324
3712
 
3325
- var build$2 = async (tmsConfig, newModules) => {
3326
- dev$1(tmsConfig, newModules, false);
3713
+ var build$2 = async (tmsConfig, newModules, isDev) => {
3714
+ dev$1(tmsConfig, newModules, isDev);
3327
3715
  };
3328
3716
 
3329
3717
  const shelljs = require$$0__default$3;
3330
3718
  const {
3331
- resolve: resolve$1,
3719
+ resolve: resolve$2,
3332
3720
  filterField
3333
3721
  } = widgets;
3334
- const init$3 = init_1;
3722
+ const init$1 = init_1;
3335
3723
  const compileBuild = build$2;
3336
3724
 
3337
- async function build$1(tmsConfig, targetModules, env) {
3725
+ async function build$1(tmsConfig, targetModules) {
3338
3726
  var _tmsConfig$hooks;
3339
3727
 
3340
3728
  // 开始构建前,清理输出目录
3341
- await shelljs.rm('-rf', resolve$1(tmsConfig.outputDir));
3729
+ await shelljs.rm('-rf', resolve$2(tmsConfig.outputDir));
3342
3730
  const {
3343
- targetModules: newModules
3344
- } = await init$3(tmsConfig, targetModules);
3731
+ modules: newModules
3732
+ } = await init$1(tmsConfig, targetModules);
3733
+ const isDev = false;
3345
3734
 
3346
3735
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
3347
3736
  var _tmsConfig$hooks2;
3348
3737
 
3349
3738
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
3350
- isDev: false,
3739
+ isDev,
3351
3740
  tmsConfig: filterField(tmsConfig, ['gitAccount']),
3352
3741
  modules: newModules
3353
3742
  }));
3354
3743
  }
3355
- compileBuild(tmsConfig, newModules, env);
3744
+ compileBuild(tmsConfig, newModules, isDev);
3356
3745
  }
3357
3746
 
3358
3747
  var build_1 = build$1;
3359
3748
 
3360
- const fs = require$$0__default$2;
3749
+ const fs$1 = require$$0__default$2;
3361
3750
  const {
3362
- resolve
3751
+ resolve: resolve$1
3363
3752
  } = widgets;
3364
- const {
3365
- handleError: handleError$1
3366
- } = handleError_1;
3367
3753
  const {
3368
3754
  ensureDirExist
3369
3755
  } = io$3;
3370
3756
  const {
3371
- warn
3757
+ warn,
3758
+ succeed
3372
3759
  } = log$1;
3373
3760
  /**
3374
3761
  * 根据相关配置创建软链接
@@ -3376,26 +3763,25 @@ const {
3376
3763
  */
3377
3764
 
3378
3765
  const symLink$1 = tmsConfig => {
3379
- try {
3380
- ensureDirExist(resolve(tmsConfig.cloudDir));
3766
+ ensureDirExist(resolve$1(tmsConfig.cloudDir));
3381
3767
 
3382
- if (tmsConfig.cloudModules) {
3383
- tmsConfig.cloudModules.forEach(item => {
3384
- const sourcePath = resolve(item.path);
3385
- const targetPath = resolve(tmsConfig.cloudDir, item.name);
3768
+ if (tmsConfig.cloudModules) {
3769
+ tmsConfig.cloudModules.forEach(item => {
3770
+ const sourcePath = resolve$1(item.path);
3771
+ const targetPath = resolve$1(tmsConfig.cloudDir, item.name);
3386
3772
 
3387
- if (!fs.existsSync(sourcePath)) {
3388
- warn(`云函数${sourcePath}不存在`);
3389
- return;
3390
- }
3773
+ if (!fs$1.existsSync(sourcePath)) {
3774
+ warn(`云函数${sourcePath}不存在`);
3775
+ return;
3776
+ }
3391
3777
 
3392
- if (!fs.existsSync(targetPath)) {
3393
- fs.symlinkSync(sourcePath, targetPath);
3394
- }
3395
- });
3396
- }
3397
- } catch (e) {
3398
- handleError$1(`创建软链错误: ${e}`);
3778
+ if (!fs$1.existsSync(targetPath)) {
3779
+ fs$1.symlinkSync(sourcePath, targetPath);
3780
+ }
3781
+ });
3782
+ succeed('云函数创建软链成功');
3783
+ } else {
3784
+ warn('你没有在tms.config.js的cloudModules注册云函数');
3399
3785
  }
3400
3786
  };
3401
3787
 
@@ -3409,36 +3795,34 @@ const {
3409
3795
  const {
3410
3796
  handleError
3411
3797
  } = handleError_1;
3412
- const {
3413
- succeed
3414
- } = log$1;
3415
3798
 
3416
3799
  var cloud$1 = async tmsConfig => {
3417
3800
  try {
3418
3801
  await symLink(tmsConfig);
3419
- succeed('云函数创建软链成功');
3420
3802
  } catch (e) {
3421
3803
  handleError(`创建软链错误: ${e}`);
3422
3804
  }
3423
3805
  };
3424
3806
 
3425
3807
  /* eslint-disable no-param-reassign */
3426
- const loadash = require$$0__default$6;
3427
- const init$2 = init_1;
3808
+ const init = init_1;
3428
3809
  const dev = dev_1;
3429
3810
  const build = build_1;
3430
3811
  const install = install_1;
3431
3812
  const cloud = cloud$1;
3813
+ const {
3814
+ fail,
3815
+ info: info$2
3816
+ } = log$1;
3432
3817
  const {
3433
3818
  global
3434
3819
  } = global_1;
3435
3820
  const {
3436
- readTmsConfig,
3437
- readTmsPrivateCf,
3438
- checkModules,
3439
- tmsModulesMergeLocalModuleCfg,
3440
- subModulesMergeDepModules
3441
- } = tmsMpconfig;
3821
+ getTmsConfig: getTmsConfig$1,
3822
+ getModulesByMergeDepModules,
3823
+ getSubPackages,
3824
+ getModulesByModuleNames
3825
+ } = tmsMpconfig.exports;
3442
3826
 
3443
3827
  const handleModuleArg = cmd => {
3444
3828
  // 单模块或多模块开发-用户通过脚手架参数指定的模块
@@ -3456,7 +3840,7 @@ const handleModuleArg = cmd => {
3456
3840
  */
3457
3841
 
3458
3842
 
3459
- const getSpecificModules = (moduleArg, modules) => {
3843
+ const getSpecificModuleNames = (moduleArg, modules) => {
3460
3844
  if (moduleArg.length > 0) {
3461
3845
  return moduleArg;
3462
3846
  }
@@ -3473,76 +3857,68 @@ const getSpecificModules = (moduleArg, modules) => {
3473
3857
  }
3474
3858
 
3475
3859
  if ((exclude === null || exclude === void 0 ? void 0 : exclude.length) > 0) {
3476
- return all.filter(module => !exclude.includes(module.name)).map(item => item.name);
3860
+ return all.filter(module => !exclude.includes(module.moduleName)).map(item => item.moduleName);
3477
3861
  }
3478
3862
 
3479
3863
  if (blockRemote === true) {
3480
- return all.filter(module => module.repoInfo === undefined).map(item => item.name);
3864
+ return all.filter(module => module.repoInfo === undefined).map(item => item.moduleName);
3481
3865
  }
3482
3866
 
3483
- return all.map(item => item.name);
3867
+ return all.map(item => item.moduleName);
3484
3868
  };
3485
3869
 
3486
- const mergeConfig = (tmsConfig, tmsPrivateCf) => {
3487
- const modules = {};
3488
-
3489
- if (Array.isArray(tmsConfig.modules)) {
3490
- modules.all = tmsConfig.modules;
3491
- tmsConfig.modules = modules;
3492
- } // 合并默认值
3870
+ async function run(commandName, cmd) {
3871
+ try {
3872
+ // 用户本地的配置
3873
+ const tmsConfig = getTmsConfig$1(); // 缓存数据
3493
3874
 
3875
+ global.setData({
3876
+ cmd,
3877
+ tmsConfig
3878
+ });
3494
3879
 
3495
- const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
3496
- if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
3497
- return objValue.concat(srcValue);
3880
+ if (commandName === 'cloud') {
3881
+ cloud(tmsConfig);
3882
+ return;
3498
3883
  }
3499
- });
3500
- return res;
3501
- };
3502
3884
 
3503
- async function run(commandName, cmd) {
3504
- // 用户本地的私有项目配置
3505
- const tmsPrivateCf = readTmsPrivateCf();
3506
- const {
3507
- env = tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : tmsPrivateCf.env
3508
- } = cmd;
3509
- let tmsConfig = readTmsConfig(env);
3510
- tmsConfig = mergeConfig(tmsConfig, tmsPrivateCf); // 处理module参数
3885
+ otherCommands(tmsConfig, commandName, cmd);
3886
+ } catch (error) {
3887
+ const errMsg = typeof error === 'object' ? error.message : error;
3888
+ fail(`构建出现错误: ${errMsg}`);
3889
+ info$2('详细错误信息', error);
3890
+ process.exit(1);
3891
+ }
3892
+ }
3511
3893
 
3512
- const specificModules = getSpecificModules(handleModuleArg(cmd), tmsConfig.modules);
3513
- const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])], true); // tms.config.js的modules 合并 module.config.json的配置项
3894
+ function otherCommands(tmsConfig, commandName, cmd) {
3895
+ // 处理module参数
3896
+ const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmd), tmsConfig.modules); // moduleNames => ['home', 'car']
3514
3897
 
3515
- let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
3898
+ const moduleNames = [...new Set([...specificModuleNames])];
3899
+ const modules = getModulesByModuleNames(tmsConfig, moduleNames, false); // 获取所有模块,合并模块依赖的模块
3516
3900
 
3517
- newModules = subModulesMergeDepModules(tmsConfig, newModules); // 缓存数据
3901
+ const newModules = getModulesByMergeDepModules(tmsConfig, modules, false); // 获取所有的分包
3518
3902
 
3519
- global.setData({
3520
- env,
3521
- cmd,
3522
- tmsConfig
3523
- });
3903
+ const subPackages = getSubPackages(newModules);
3524
3904
 
3525
3905
  switch (commandName) {
3526
3906
  case 'init':
3527
- init$2(tmsConfig, newModules, env);
3907
+ init(tmsConfig, newModules);
3528
3908
  return;
3529
3909
 
3530
3910
  case 'dev':
3531
3911
  global.setData('isDev', true);
3532
- dev(tmsConfig, newModules, env);
3533
- return;
3534
-
3535
- case 'cloud':
3536
- cloud(tmsConfig, env);
3912
+ dev(tmsConfig, newModules);
3537
3913
  return;
3538
3914
 
3539
3915
  case 'install':
3540
- install(tmsConfig, newModules, env);
3916
+ install(tmsConfig, subPackages, false);
3541
3917
  return;
3542
3918
 
3543
3919
  case 'build':
3544
3920
  global.setData('isDev', false);
3545
- build(tmsConfig, newModules, env);
3921
+ build(tmsConfig, newModules);
3546
3922
  return;
3547
3923
 
3548
3924
  default:
@@ -3553,10 +3929,10 @@ async function run(commandName, cmd) {
3553
3929
  var run_1 = run;
3554
3930
 
3555
3931
  var entry = [{
3556
- command: 'create <app-name>',
3557
- description: '创建新的应用',
3558
- action: (appName, cmd) => {
3559
- create_1(appName, cmd);
3932
+ command: 'create <project-name>',
3933
+ description: '创建项目',
3934
+ action: projectName => {
3935
+ create_1(projectName);
3560
3936
  }
3561
3937
  }, {
3562
3938
  name: 'run',
@@ -3605,9 +3981,9 @@ var entry = [{
3605
3981
  ]
3606
3982
  }];
3607
3983
 
3608
- var require$$7 = {
3984
+ var require$$9 = {
3609
3985
  name: "@tmsfe/tmskit",
3610
- version: "0.0.18",
3986
+ version: "0.0.21",
3611
3987
  description: "tmskit",
3612
3988
  main: "dist/index.cjs",
3613
3989
  bin: {
@@ -3648,21 +4024,16 @@ var require$$7 = {
3648
4024
  dependencies: {
3649
4025
  "ansi-colors": "1.1.0",
3650
4026
  anymatch: "^1.3.0",
3651
- "fancy-log": "1.3.2",
3652
- "glob-parent": "^3.0.1",
3653
- "path-is-absolute": "^1.0.1",
3654
- "readable-stream": "^2.2.2",
3655
- slash: "^1.0.0",
3656
- vinyl: "^2.1.0",
3657
- "vinyl-file": "^2.0.0",
3658
4027
  async: "^3.2.2",
3659
4028
  chalk: "^4.1.0",
3660
4029
  chokidar: "^3.5.3",
3661
4030
  commander: "^8.3.0",
3662
4031
  "copy-webpack-plugin": "^9.1.0",
3663
4032
  ejs: "^3.1.5",
4033
+ "fancy-log": "1.3.2",
3664
4034
  "fs-extra": "^10.0.1",
3665
4035
  "glob-ignore": "^1.0.2",
4036
+ "glob-parent": "^3.0.1",
3666
4037
  gulp: "^4.0.2",
3667
4038
  "gulp-watch": "^5.0.1",
3668
4039
  htmlparser2: "^7.2.0",
@@ -3674,13 +4045,20 @@ var require$$7 = {
3674
4045
  moment: "^2.29.2",
3675
4046
  "object-assign": "^4.0.1",
3676
4047
  ora: "^5.1.0",
4048
+ "path-is-absolute": "^1.0.1",
3677
4049
  "plugin-error": "^1.0.0",
3678
4050
  postcss: "^8.4.6",
3679
4051
  precinct: "^8.3.1",
4052
+ "readable-stream": "^2.2.2",
3680
4053
  "replace-ext": "^2.0.0",
4054
+ request: "^2.88.2",
3681
4055
  shelljs: "^0.8.4",
4056
+ slash: "^1.0.0",
3682
4057
  "strip-comments": "^2.0.1",
3683
4058
  through2: "^4.0.2",
4059
+ unzipper: "^0.10.11",
4060
+ vinyl: "^2.1.0",
4061
+ "vinyl-file": "^2.0.0",
3684
4062
  "vinyl-sourcemaps-apply": "^0.2.0"
3685
4063
  },
3686
4064
  engines: {
@@ -3692,7 +4070,7 @@ var require$$7 = {
3692
4070
  };
3693
4071
 
3694
4072
  const semver = require$$1__default$7;
3695
- const packageJson = require$$7;
4073
+ const packageJson = require$$9;
3696
4074
  const chalk$1 = require$$0__default;
3697
4075
  const {
3698
4076
  info: info$1
@@ -3716,34 +4094,38 @@ const checkNodeVersion = (wanted, id) => {
3716
4094
  };
3717
4095
  /**
3718
4096
  * 检查运行环境
3719
- * @returns {Undefined} 无需返回值
3720
4097
  */
3721
4098
 
3722
4099
 
3723
- function initCliContext() {
4100
+ function check$1() {
3724
4101
  // 执行操作前检查node版本
3725
4102
  // 旧版本node直接提示升级,退出脚本
3726
4103
  checkNodeVersion(requiredVersion, packName);
3727
4104
  }
3728
4105
 
3729
- var init$1 = initCliContext;
4106
+ var check_1 = check$1;
3730
4107
 
3731
4108
  const chalk = require$$0__default;
3732
4109
  const commander = require$$0__default$1;
3733
4110
  const {
3734
- suggestCommands
4111
+ suggestCommands,
4112
+ resolve
3735
4113
  } = widgets;
3736
4114
  const {
3737
4115
  info
3738
4116
  } = log$1;
4117
+ const {
4118
+ getTmsConfig
4119
+ } = tmsMpconfig.exports;
3739
4120
  const {
3740
4121
  TMS_NAME
3741
- } = require$$4;
4122
+ } = require$$5;
3742
4123
  const commands = entry;
3743
- const init = init$1;
3744
- init();
4124
+ const check = check_1;
4125
+ const fs = require$$0__default$2;
4126
+ check();
3745
4127
  const program = new commander.Command(TMS_NAME);
3746
- program.version(`${TMS_NAME} ${require$$7.version}`, '-v, -V, --version');
4128
+ program.version(`${TMS_NAME} ${require$$9.version}`, '-v, -V, --version');
3747
4129
 
3748
4130
  function registerCommand(program, commands) {
3749
4131
  commands.forEach(cmd => {
@@ -3765,7 +4147,20 @@ function registerCommand(program, commands) {
3765
4147
  });
3766
4148
  }
3767
4149
 
3768
- registerCommand(program, commands);
4150
+ function register() {
4151
+ // 注册脚手架内部命令
4152
+ registerCommand(program, commands); // 注册扩展命令
4153
+
4154
+ if (fs.existsSync(resolve('tms.config.js'))) {
4155
+ const tmsConfig = getTmsConfig();
4156
+
4157
+ if (Array.isArray(tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.commands)) {
4158
+ registerCommand(program, tmsConfig.commands);
4159
+ }
4160
+ }
4161
+ }
4162
+
4163
+ register();
3769
4164
  program.on('--help', () => {
3770
4165
  info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
3771
4166
  }); // 捕获未注册的命令