@tmsfe/tmskit 0.0.16 → 0.0.19

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,6 +8,7 @@ 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$$6 = require('glob-ignore');
11
12
  var require$$0$4 = require('async');
12
13
  var require$$1$3 = require('ejs');
13
14
  var require$$1$4 = require('inquirer');
@@ -15,7 +16,6 @@ var require$$0$5 = require('metalsmith');
15
16
  var require$$0$6 = require('lodash');
16
17
  var require$$1$5 = require('crypto');
17
18
  var require$$0$7 = require('miniprogram-ci');
18
- var require$$5 = require('glob-ignore');
19
19
  var require$$1$6 = require('fs-extra');
20
20
  var require$$1$7 = require('semver');
21
21
  var require$$0$8 = require('strip-comments');
@@ -26,8 +26,8 @@ var require$$0$a = require('gulp');
26
26
  var require$$0$b = require('object-assign');
27
27
  var require$$3 = require('fancy-log');
28
28
  var require$$4$1 = require('ansi-colors');
29
- var require$$5$1 = require('chokidar');
30
- var require$$6 = require('readable-stream');
29
+ var require$$5 = require('chokidar');
30
+ var require$$6$1 = require('readable-stream');
31
31
  var require$$7$1 = require('vinyl-file');
32
32
  var require$$8 = require('vinyl');
33
33
  var require$$9 = require('anymatch');
@@ -46,6 +46,7 @@ var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
46
46
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
47
47
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
48
48
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
49
+ var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
49
50
  var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
50
51
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
51
52
  var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
@@ -53,7 +54,6 @@ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
53
54
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
54
55
  var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
55
56
  var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
56
- var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
57
57
  var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
58
58
  var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
59
59
  var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
@@ -64,8 +64,8 @@ var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
64
64
  var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
65
65
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
66
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);
67
+ var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
68
+ var require$$6__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
69
69
  var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7$1);
70
70
  var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
71
71
  var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
@@ -119,7 +119,7 @@ const fail$9 = (message = '') => {
119
119
  */
120
120
 
121
121
 
122
- const succeed$1 = (message = '') => {
122
+ const succeed$2 = (message = '') => {
123
123
  const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
124
124
 
125
125
  const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
@@ -133,27 +133,28 @@ const succeed$1 = (message = '') => {
133
133
  */
134
134
 
135
135
 
136
- const warn$1 = message => {
136
+ const warn$2 = message => {
137
137
  console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
138
138
  };
139
139
 
140
- const info$9 = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
140
+ const info$a = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
141
141
 
142
142
  var log$1 = {
143
143
  fail: fail$9,
144
- succeed: succeed$1,
145
- warn: warn$1,
146
- info: info$9
144
+ succeed: succeed$2,
145
+ warn: warn$2,
146
+ info: info$a
147
147
  };
148
148
 
149
149
  const program$1 = require$$0__default$1;
150
150
  const leven = require$$1__default$1;
151
151
  const ora = require$$2__default;
152
- const path$c = require$$1__default$2;
153
- const fs$d = require$$0__default$2;
152
+ const path$d = require$$1__default$2;
153
+ const fs$g = require$$0__default$2;
154
154
  const shelljs$7 = require$$0__default$3;
155
+ const glob$1 = require$$6__default;
155
156
  const {
156
- info: info$8
157
+ info: info$9
157
158
  } = log$1;
158
159
  const chalk$2 = require$$0__default;
159
160
  const shelljsOptions = {
@@ -163,8 +164,8 @@ const shelljsOptions = {
163
164
 
164
165
  const cwd = process.cwd();
165
166
 
166
- function resolve$e(...args) {
167
- return path$c.resolve(cwd, ...args);
167
+ function resolve$f(...args) {
168
+ return path$d.resolve(cwd, ...args);
168
169
  }
169
170
  /**
170
171
  * 用户输入命令时,进行提示
@@ -184,7 +185,7 @@ const suggestCommands$1 = unknownCommand => {
184
185
  });
185
186
 
186
187
  if (suggestion) {
187
- info$8(` ${chalk$2.red(`Did you mean ${chalk$2.yellow(suggestion)}?`)}`);
188
+ info$9(` ${chalk$2.red(`Did you mean ${chalk$2.yellow(suggestion)}?`)}`);
188
189
  }
189
190
  };
190
191
  /**
@@ -220,8 +221,8 @@ function downloadRepoForGit$2(url, dest, branch) {
220
221
  const cwd = process.cwd();
221
222
  return new Promise((resolve, reject) => {
222
223
  // 如果目标目录不存在
223
- if (fs$d.existsSync(dest)) {
224
- shelljs$7.rm('-rf', path$c.join(dest));
224
+ if (fs$g.existsSync(dest)) {
225
+ shelljs$7.rm('-rf', path$d.join(dest));
225
226
  }
226
227
 
227
228
  shelljs$7.mkdir('-p', dest);
@@ -270,7 +271,7 @@ function pullRepoForGit$1(dest, branch) {
270
271
  */
271
272
 
272
273
 
273
- function npmInstall$1(dir) {
274
+ function npmInstall$2(dir) {
274
275
  return new Promise((resolve, reject) => {
275
276
  shelljs$7.exec('npm install --production --registry http://mirrors.tencent.com/npm/', {
276
277
  cwd: dir,
@@ -305,7 +306,7 @@ function createTask$3(task, startText, endText) {
305
306
  return async (...args) => {
306
307
  const start = Date.now();
307
308
  const spinner = ora();
308
- info$8(startText);
309
+ info$9(startText);
309
310
  spinner.start();
310
311
  const result = await task(...args);
311
312
  endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
@@ -334,11 +335,42 @@ const mergeMap = function (obj, src) {
334
335
  };
335
336
 
336
337
  const relativeCwdPath$1 = function (file) {
337
- return path$c.relative(process.cwd(), file);
338
+ return path$d.relative(process.cwd(), file);
338
339
  };
340
+ /**
341
+ * 从一个对象中,检索出去几个字段
342
+ * @param {*} obj
343
+ * @param {*} name
344
+ * @returns
345
+ */
346
+
347
+
348
+ const filterField$3 = (obj, filterNames = []) => {
349
+ const newObj = { ...obj
350
+ };
351
+ filterNames.forEach(name => {
352
+ if (newObj[name]) {
353
+ delete newObj[name];
354
+ }
355
+ });
356
+ return newObj;
357
+ }; // 检索出文件列表
358
+
359
+
360
+ function findFiles(globPath, filter = []) {
361
+ return new Promise((resolve, reject) => {
362
+ glob$1(globPath, filter, (err, files) => {
363
+ if (err) {
364
+ reject(err);
365
+ }
366
+
367
+ resolve(files);
368
+ });
369
+ });
370
+ }
339
371
 
340
372
  var widgets = {
341
- resolve: resolve$e,
373
+ resolve: resolve$f,
342
374
  isObject: isObject$2,
343
375
  isArray: isArray$1,
344
376
  createTask: createTask$3,
@@ -346,25 +378,29 @@ var widgets = {
346
378
  pullRepoForGit: pullRepoForGit$1,
347
379
  suggestCommands: suggestCommands$1,
348
380
  camelize,
349
- npmInstall: npmInstall$1,
381
+ npmInstall: npmInstall$2,
350
382
  mergeMap,
351
- relativeCwdPath: relativeCwdPath$1
383
+ relativeCwdPath: relativeCwdPath$1,
384
+ filterField: filterField$3,
385
+ findFiles
352
386
  };
353
387
 
354
- const path$b = require('path');
388
+ const path$c = require('path');
355
389
 
356
390
  const os = require('os'); // 用户目录
357
391
 
358
392
 
359
393
  const HOME_DIR = os.homedir(); // 所有文件的缓存目录
360
394
 
361
- const CACHE_DIR$2 = path$b.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
395
+ const CACHE_DIR$3 = path$c.resolve(HOME_DIR, '.tmskit'); // 缓存文件
362
396
 
363
- const TEMPLATE_DIR$1 = path$b.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
397
+ const CACHE_FILE$1 = 'cache_file.json'; // 脚手架模板代码所在目录
364
398
 
365
- const MODULE_CODE_DIR$1 = path$b.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
399
+ const TEMPLATE_DIR$1 = path$c.resolve(CACHE_DIR$3, 'template'); // 第三方模块源码存放的临时缓存目录
366
400
 
367
- const TEMPLATE_PATH$1 = path$b.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
401
+ const MODULE_CODE_DIR$1 = path$c.resolve(CACHE_DIR$3, 'modules_code'); // 脚手架模板代码的具体路径
402
+
403
+ const TEMPLATE_PATH$1 = path$c.resolve(TEMPLATE_DIR$1, 'tools/tmskit-template'); // 脚手架的名称
368
404
 
369
405
  const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
370
406
 
@@ -378,7 +414,7 @@ const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
378
414
  const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
379
415
 
380
416
  const DEFAULT_WEBPACK_ENTRY = {
381
- app: path$b.resolve(process.cwd(), 'app')
417
+ app: path$c.resolve(process.cwd(), 'app')
382
418
  }; // 默认从源码拷贝到编译后的配置
383
419
 
384
420
  const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
@@ -387,12 +423,12 @@ const ENV = {
387
423
  prod: 'production'
388
424
  };
389
425
  const TEMPLATE_TKIT_DIR$2 = '_tmskit';
390
- const MODULE_CONFIG_INVALID_KEY$1 = ['entranceDeclare', 'entryPagePath'];
391
426
 
392
427
  var constant = /*#__PURE__*/Object.freeze({
393
428
  __proto__: null,
394
429
  HOME_DIR: HOME_DIR,
395
- CACHE_DIR: CACHE_DIR$2,
430
+ CACHE_DIR: CACHE_DIR$3,
431
+ CACHE_FILE: CACHE_FILE$1,
396
432
  TEMPLATE_DIR: TEMPLATE_DIR$1,
397
433
  TEMPLATE_PATH: TEMPLATE_PATH$1,
398
434
  TMS_NAME: TMS_NAME$1,
@@ -405,16 +441,15 @@ var constant = /*#__PURE__*/Object.freeze({
405
441
  MODULE_CODE_DIR: MODULE_CODE_DIR$1,
406
442
  ENV: ENV,
407
443
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
408
- MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1,
409
444
  DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
410
445
  });
411
446
 
412
447
  var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
413
448
 
414
- const fs$c = require$$0__default$2;
415
- const path$a = require$$1__default$2;
449
+ const fs$f = require$$0__default$2;
450
+ const path$b = require$$1__default$2;
416
451
  const {
417
- info: info$7
452
+ info: info$8
418
453
  } = log$1;
419
454
  const {
420
455
  relativeCwdPath
@@ -425,12 +460,12 @@ const {
425
460
  * @returns
426
461
  */
427
462
 
428
- const isDirEmpty = dirname => fs$c.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
463
+ const isDirEmpty = dirname => fs$f.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
429
464
 
430
465
 
431
466
  const isFile = pathName => {
432
467
  try {
433
- const stat = fs$c.lstatSync(pathName);
468
+ const stat = fs$f.lstatSync(pathName);
434
469
  return stat.isFile();
435
470
  } catch {
436
471
  return false;
@@ -442,9 +477,9 @@ const isFile = pathName => {
442
477
  */
443
478
 
444
479
 
445
- const ensureDirExist = dirname => {
446
- if (!fs$c.existsSync(dirname)) {
447
- fs$c.mkdirSync(dirname, {
480
+ const ensureDirExist$2 = dirname => {
481
+ if (!fs$f.existsSync(dirname)) {
482
+ fs$f.mkdirSync(dirname, {
448
483
  recursive: true
449
484
  });
450
485
  }
@@ -452,27 +487,27 @@ const ensureDirExist = dirname => {
452
487
 
453
488
 
454
489
  const copyFile = function (src, dest) {
455
- if (fs$c.existsSync(dest)) {
456
- fs$c.unlinkSync(dest);
490
+ if (fs$f.existsSync(dest)) {
491
+ fs$f.unlinkSync(dest);
457
492
  }
458
493
 
459
- const dir = path$a.dirname(dest);
460
- ensureDirExist(dir);
461
- fs$c.copyFileSync(src, dest);
494
+ const dir = path$b.dirname(dest);
495
+ ensureDirExist$2(dir);
496
+ fs$f.copyFileSync(src, dest);
462
497
  }; // 判断文件内容是否一致,不一致再进行拷贝
463
498
 
464
499
 
465
500
  function diffContentCopyFile$3(originFile, destFile) {
466
- if (fs$c.existsSync(destFile)) {
467
- const depDestContent = fs$c.readFileSync(destFile, 'utf8');
468
- const depOriginContent = fs$c.readFileSync(originFile, 'utf8');
501
+ if (fs$f.existsSync(destFile)) {
502
+ const depDestContent = fs$f.readFileSync(destFile, 'utf8');
503
+ const depOriginContent = fs$f.readFileSync(originFile, 'utf8');
469
504
 
470
505
  if (depDestContent !== depOriginContent) {
471
- info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
506
+ info$8(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
472
507
  copyFile(originFile, destFile);
473
508
  }
474
509
  } else {
475
- info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
510
+ info$8(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
476
511
  copyFile(originFile, destFile);
477
512
  }
478
513
  } // 添加后缀
@@ -483,7 +518,7 @@ function ext$3(filePath, extensions) {
483
518
  let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
484
519
 
485
520
  try {
486
- const stat = fs$c.lstatSync(newFilePath);
521
+ const stat = fs$f.lstatSync(newFilePath);
487
522
 
488
523
  if (stat.isDirectory()) {
489
524
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
@@ -494,7 +529,7 @@ function ext$3(filePath, extensions) {
494
529
  for (const ext of extensions) {
495
530
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
496
531
 
497
- if (fs$c.existsSync(file)) {
532
+ if (fs$f.existsSync(file)) {
498
533
  return {
499
534
  ext,
500
535
  extPath: extPath + ext,
@@ -512,11 +547,11 @@ function ext$3(filePath, extensions) {
512
547
 
513
548
 
514
549
  const fileInDir$3 = (dir, file) => {
515
- if (!fs$c.existsSync(dir) || !fs$c.existsSync(file)) {
550
+ if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
516
551
  return false;
517
552
  }
518
553
 
519
- const relativePath = path$a.relative(dir, file);
554
+ const relativePath = path$b.relative(dir, file);
520
555
 
521
556
  if (relativePath.startsWith('..')) {
522
557
  return false;
@@ -529,10 +564,10 @@ function findAllFilesOfDir$1(dir) {
529
564
  const list = [];
530
565
 
531
566
  function listFile(dir) {
532
- const arr = fs$c.readdirSync(dir);
567
+ const arr = fs$f.readdirSync(dir);
533
568
  arr.forEach(item => {
534
- const fullPath = path$a.join(dir, item);
535
- const stats = fs$c.statSync(fullPath);
569
+ const fullPath = path$b.join(dir, item);
570
+ const stats = fs$f.statSync(fullPath);
536
571
 
537
572
  if (stats.isDirectory()) {
538
573
  listFile(fullPath);
@@ -551,7 +586,7 @@ var io$3 = {
551
586
  isDirEmpty,
552
587
  copyFile,
553
588
  diffContentCopyFile: diffContentCopyFile$3,
554
- ensureDirExist,
589
+ ensureDirExist: ensureDirExist$2,
555
590
  ext: ext$3,
556
591
  fileInDir: fileInDir$3,
557
592
  isFile,
@@ -578,10 +613,10 @@ const render$1 = (files, metalsmith, next) => {
578
613
 
579
614
  var render_1 = render$1;
580
615
 
581
- const fs$b = require$$0__default$2;
616
+ const fs$e = require$$0__default$2;
582
617
  const inquirer = require$$1__default$4;
583
618
  const {
584
- resolve: resolve$d
619
+ resolve: resolve$e
585
620
  } = widgets;
586
621
  const {
587
622
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -595,12 +630,12 @@ const {
595
630
  const parseTemplateQuestions = dir => {
596
631
  let prompts = [];
597
632
 
598
- if (!fs$b.existsSync(`${dir}/questions.json`)) {
633
+ if (!fs$e.existsSync(`${dir}/questions.json`)) {
599
634
  return prompts;
600
635
  }
601
636
 
602
637
  try {
603
- const json = JSON.parse(fs$b.readFileSync(`${dir}/questions.json`));
638
+ const json = JSON.parse(fs$e.readFileSync(`${dir}/questions.json`));
604
639
 
605
640
  if (Array.isArray(json) && json.length > 0) {
606
641
  json.forEach((item, index) => {
@@ -633,7 +668,7 @@ const isQuestionType = result => {
633
668
  };
634
669
 
635
670
  const ask$1 = templateDir => (files, metalsmith, next) => {
636
- const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
671
+ const prompts = parseTemplateQuestions(resolve$e(templateDir, TEMPLATE_TKIT_DIR$1));
637
672
  const metadata = metalsmith.metadata();
638
673
  const filteredPrompts = prompts.filter(prompt => {
639
674
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -675,8 +710,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
675
710
 
676
711
  var generator_1 = generator$1;
677
712
 
678
- const path$9 = require$$1__default$2;
679
- const fs$a = require$$0__default$2;
713
+ const path$a = require$$1__default$2;
714
+ const fs$d = require$$0__default$2;
680
715
  const shelljs$6 = require$$0__default$3;
681
716
  const {
682
717
  TEMPLATE_DIR,
@@ -686,13 +721,13 @@ const {
686
721
  const {
687
722
  downloadRepoForGit: downloadRepoForGit$1,
688
723
  createTask: createTask$2,
689
- resolve: resolve$c
724
+ resolve: resolve$d
690
725
  } = widgets;
691
726
  const io$2 = io$3;
692
727
  const {
693
728
  fail: fail$8,
694
- succeed,
695
- info: info$6
729
+ succeed: succeed$1,
730
+ info: info$7
696
731
  } = log$1;
697
732
  const generator = generator_1;
698
733
  /**
@@ -703,7 +738,7 @@ const generator = generator_1;
703
738
 
704
739
  async function createAppDir(targetDir) {
705
740
  // 如果目录非空或者已经存在,提示用户,做选择
706
- if (fs$a.existsSync(targetDir)) {
741
+ if (fs$d.existsSync(targetDir)) {
707
742
  if (!(await io$2.isDirEmpty(targetDir))) {
708
743
  fail$8('该目录名已经存在,换个项目名字吧~');
709
744
  process.exit(1);
@@ -721,7 +756,7 @@ async function createAppDir(targetDir) {
721
756
 
722
757
  async function create(appName) {
723
758
  const cwd = process.cwd();
724
- const targetDir = path$9.resolve(cwd, appName);
759
+ const targetDir = path$a.resolve(cwd, appName);
725
760
  const appType = 'mp';
726
761
  await createAppDir(targetDir); // 创建缓存目录
727
762
 
@@ -729,13 +764,13 @@ async function create(appName) {
729
764
 
730
765
  await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
731
766
 
732
- generator(path$9.join(TEMPLATE_PATH, appType), targetDir, {
767
+ generator(path$a.join(TEMPLATE_PATH, appType), targetDir, {
733
768
  appName,
734
769
  appType
735
770
  }).then(() => {
736
771
  shelljs$6.cd(appName);
737
772
 
738
- const hooks = require(resolve$c(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
773
+ const hooks = require(resolve$d(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
739
774
 
740
775
  if (hooks.afterCreate) {
741
776
  hooks.afterCreate.forEach(item => {
@@ -749,11 +784,11 @@ async function create(appName) {
749
784
  });
750
785
  }
751
786
 
752
- shelljs$6.rm('-rf', resolve$c(appName, TEMPLATE_TKIT_DIR));
753
- succeed('项目创建完成.');
787
+ shelljs$6.rm('-rf', resolve$d(appName, TEMPLATE_TKIT_DIR));
788
+ succeed$1('项目创建完成.');
754
789
  }).catch(err => {
755
790
  fail$8(err.message);
756
- info$6('详细的错误信息:', err);
791
+ info$7('详细的错误信息:', err);
757
792
  });
758
793
  }
759
794
 
@@ -763,7 +798,7 @@ var defaultTmsConfig$1 = {
763
798
  // 全局的环境配置项
764
799
  envData: {},
765
800
  // 模块配置信息
766
- modules: [],
801
+ modules: {},
767
802
  cloudDir: 'cloud',
768
803
  // 第三方依赖代码需要拷贝到本项目的
769
804
  dependencies: {},
@@ -781,15 +816,15 @@ var defaultTmsConfig$1 = {
781
816
  /**
782
817
  * 用来读取处理tms.config.js与module.config.json字段
783
818
  */
784
- const loadash = require$$0__default$6;
785
- const fs$9 = require$$0__default$2;
819
+ const loadash$1 = require$$0__default$6;
820
+ const fs$c = require$$0__default$2;
786
821
  const {
787
822
  TMS_CONFIG_FILENAME,
788
823
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
789
824
  TMS_PRIVATE_FILENAME
790
825
  } = require$$4;
791
826
  const {
792
- resolve: resolve$b,
827
+ resolve: resolve$c,
793
828
  isObject: isObject$1,
794
829
  isArray
795
830
  } = widgets;
@@ -797,16 +832,15 @@ const defaultTmsConfig = defaultTmsConfig$1;
797
832
  const {
798
833
  fail: fail$7
799
834
  } = log$1;
800
- const path$8 = require$$1__default$2;
801
835
  /**
802
836
  * 读取tms.config.js
803
837
  * @param env {string} 环境变量
804
838
  */
805
839
 
806
840
  const readTmsConfig$1 = function (env) {
807
- const tmsConfigPath = resolve$b(TMS_CONFIG_FILENAME);
841
+ const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
808
842
 
809
- if (!fs$9.existsSync(tmsConfigPath)) {
843
+ if (!fs$c.existsSync(tmsConfigPath)) {
810
844
  fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
811
845
  process.exit(1);
812
846
  }
@@ -817,35 +851,7 @@ const readTmsConfig$1 = function (env) {
817
851
  env
818
852
  }); // 合并默认值
819
853
 
820
- loadash.mergeWith(tmsConfig, defaultTmsConfig); // modules兼容处理
821
-
822
- tmsConfig.modules = convertModules(tmsConfig.modules);
823
- return tmsConfig;
824
- }; // convertModules 处理默认值
825
-
826
-
827
- const convertModules = modules => {
828
- const newModules = [];
829
- modules.forEach(module => {
830
- const newModule = {};
831
-
832
- if (typeof module === 'string') {
833
- // 路径字符串
834
- Object.assign(newModule, {
835
- name: path$8.basename(module),
836
- path: module
837
- });
838
- } else if (typeof module === 'object') {
839
- Object.assign(newModule, module);
840
-
841
- if (module.name === undefined) {
842
- newModule.name = path$8.basename(module.path);
843
- }
844
- }
845
-
846
- newModules.push(newModule);
847
- });
848
- return newModules;
854
+ return loadash$1.mergeWith(defaultTmsConfig, tmsConfig);
849
855
  };
850
856
  /**
851
857
  * 读取tms.private.config.js
@@ -854,17 +860,10 @@ const convertModules = modules => {
854
860
 
855
861
  const readTmsPrivateCf$1 = function () {
856
862
  let tmsPrivateCf = {};
857
- const tmsPrivatePath = resolve$b(TMS_PRIVATE_FILENAME);
863
+ const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
858
864
 
859
- if (fs$9.existsSync(tmsPrivatePath)) {
865
+ if (fs$c.existsSync(tmsPrivatePath)) {
860
866
  tmsPrivateCf = require(tmsPrivatePath);
861
- } // 处理modules字段
862
-
863
-
864
- if (tmsPrivateCf.modules instanceof Array) {
865
- Object.assign(tmsPrivateCf.modules, {
866
- include: tmsPrivateCf.modules
867
- });
868
867
  }
869
868
 
870
869
  return tmsPrivateCf;
@@ -880,7 +879,7 @@ const readTmsPrivateCf$1 = function () {
880
879
  const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
881
880
  const targetModules = [];
882
881
  modules.forEach(moduleName => {
883
- const module = tmsConfig.modules.find(module => module.name === moduleName);
882
+ const module = tmsConfig.modules.all.find(module => module.name === moduleName);
884
883
  module && targetModules.push(module);
885
884
  });
886
885
 
@@ -892,18 +891,6 @@ const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
892
891
 
893
892
  return targetModules;
894
893
  };
895
- /**
896
- * 过滤页面为空的分包
897
- * @param {Array} moduleCfg 模块配置内容
898
- * @returns pages不为空的分包
899
- */
900
-
901
-
902
- const getValidModules$1 = moduleCfg => {
903
- // 过滤 pages 为空的情况
904
- const validModules = moduleCfg.filter(item => item.pages.length > 0);
905
- return validModules;
906
- };
907
894
  /**
908
895
  * 适配处理module.config.json的字段
909
896
  * @param { object } fileContent module.config.json的内容
@@ -912,25 +899,31 @@ const getValidModules$1 = moduleCfg => {
912
899
 
913
900
 
914
901
  function adaptMpCgContent(fileContent, appName) {
915
- const content = fileContent.contents ? JSON.parse(fileContent.contents.toString()) : JSON.parse(fileContent);
902
+ const handleContent = function (appName, current) {
903
+ let res = current;
904
+
905
+ if (appName && current.mpConfig && current.mpConfig[appName]) {
906
+ res = { ...current,
907
+ ...current.mpConfig[appName]
908
+ };
909
+ }
910
+
911
+ delete res.mpConfig;
912
+ delete res.isSubpackages;
913
+ return res;
914
+ };
915
+
916
+ let content = JSON.parse(fileContent);
916
917
 
917
918
  if (isArray(content)) {
918
919
  let i = content.length - 1;
919
920
 
920
921
  while (i >= 0) {
921
- let current = content[i];
922
-
923
- if (appName && current.mpConfig && current.mpConfig[appName]) {
924
- current = { ...current,
925
- ...current.mpConfig[appName]
926
- };
927
- }
928
-
929
- delete current.mpConfig;
930
- delete current.isSubpackages;
931
- content[i] = current;
922
+ content[i] = handleContent(appName, content[i]);
932
923
  i--; // eslint-disable-line
933
924
  }
925
+ } else {
926
+ content = handleContent(appName, content);
934
927
  }
935
928
 
936
929
  return content;
@@ -948,10 +941,10 @@ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
948
941
  modules.forEach(({
949
942
  path
950
943
  }) => {
951
- const moduleConfigPath = resolve$b(path, moduleConfigFilename);
944
+ const moduleConfigPath = resolve$c(path, moduleConfigFilename);
952
945
 
953
- if (fs$9.existsSync(moduleConfigPath)) {
954
- const content = fs$9.readFileSync(moduleConfigPath, 'utf-8');
946
+ if (fs$c.existsSync(moduleConfigPath)) {
947
+ const content = fs$c.readFileSync(moduleConfigPath, 'utf-8');
955
948
  modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
956
949
  }
957
950
  });
@@ -972,15 +965,15 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
972
965
  path: relativePath,
973
966
  name: moduleName
974
967
  }, moduleIndex) => {
975
- const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME$1);
968
+ const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$1);
976
969
 
977
- if (fs$9.existsSync(moduleConfigPath)) {
970
+ if (fs$c.existsSync(moduleConfigPath)) {
978
971
  try {
979
972
  let findModule = false;
980
- let moduleConfigContent = fs$9.readFileSync(moduleConfigPath, 'utf-8');
973
+ let moduleConfigContent = fs$c.readFileSync(moduleConfigPath, 'utf-8');
981
974
  moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
982
975
  const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
983
- getValidModules$1(moduleContentArr).forEach(({
976
+ moduleContentArr.forEach(({
984
977
  name
985
978
  }, moduleContentArrIndex) => {
986
979
  if (name === moduleName) {
@@ -992,7 +985,7 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
992
985
  });
993
986
 
994
987
  if (!findModule) {
995
- fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到或pages为空,请检查配置`);
988
+ fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
996
989
  process.exit(1);
997
990
  }
998
991
  } catch (e) {
@@ -1049,7 +1042,6 @@ var tmsMpconfig = {
1049
1042
  readTmsConfig: readTmsConfig$1,
1050
1043
  readTmsPrivateCf: readTmsPrivateCf$1,
1051
1044
  getModuleConfig: getModuleConfig$1,
1052
- getValidModules: getValidModules$1,
1053
1045
  checkModules: checkModules$1,
1054
1046
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
1055
1047
  subModulesMergeDepModules: subModulesMergeDepModules$2
@@ -1087,7 +1079,7 @@ const {
1087
1079
  global: global$5
1088
1080
  } = global_1;
1089
1081
 
1090
- function handleError$4(error) {
1082
+ function handleError$6(error) {
1091
1083
  const errMsg = typeof error === 'object' ? error.message : error;
1092
1084
  const isDev = global$5.getData('isDev');
1093
1085
 
@@ -1100,31 +1092,35 @@ function handleError$4(error) {
1100
1092
  }
1101
1093
 
1102
1094
  var handleError_1 = {
1103
- handleError: handleError$4
1095
+ handleError: handleError$6
1104
1096
  };
1105
1097
 
1106
1098
  /**
1107
1099
  * 生成编译后的app.json
1108
1100
  */
1109
- const fs$8 = require$$0__default$2;
1101
+ /* eslint-disable no-param-reassign */
1102
+
1103
+ const fs$b = require$$0__default$2;
1110
1104
  const {
1111
- MODULE_CONFIG_FILENAME,
1112
- MODULE_CONFIG_INVALID_KEY
1105
+ MODULE_CONFIG_FILENAME
1113
1106
  } = require$$4;
1114
1107
  const {
1115
- getModuleConfig,
1116
- getValidModules
1108
+ getModuleConfig
1117
1109
  } = tmsMpconfig;
1118
1110
  const {
1119
1111
  fail: fail$5
1120
1112
  } = log$1;
1121
1113
  const {
1122
- resolve: resolve$a,
1123
- isObject
1114
+ resolve: resolve$b,
1115
+ isObject,
1116
+ filterField: filterField$2
1124
1117
  } = widgets;
1125
1118
  const {
1126
- handleError: handleError$3
1119
+ handleError: handleError$5
1127
1120
  } = handleError_1;
1121
+ const {
1122
+ global: global$4
1123
+ } = global_1;
1128
1124
  /**
1129
1125
  * 更新appJson里面的主包配置
1130
1126
  * @param { object } appJson appJson信息
@@ -1156,8 +1152,7 @@ function updateMainPackages(appJson, mainPackages = []) {
1156
1152
  }
1157
1153
  }); // 去掉 subpackages 中的主包配置
1158
1154
 
1159
- const foundMainPackageNames = foundMainPackages.map(item => item.name); // eslint-disable-next-line
1160
-
1155
+ const foundMainPackageNames = foundMainPackages.map(item => item.name);
1161
1156
  appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
1162
1157
  return appJson;
1163
1158
  }
@@ -1169,35 +1164,32 @@ function updateMainPackages(appJson, mainPackages = []) {
1169
1164
 
1170
1165
 
1171
1166
  const getAppJsonContent = sourceAppJsonPath => {
1172
- if (!fs$8.existsSync(sourceAppJsonPath)) {
1167
+ if (!fs$b.existsSync(sourceAppJsonPath)) {
1173
1168
  fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1174
1169
  process.exit(1);
1175
1170
  }
1176
1171
 
1177
- const appJson = JSON.parse(fs$8.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1172
+ const appJson = JSON.parse(fs$b.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1178
1173
 
1179
1174
  appJson.subpackages = [];
1180
- appJson.pages = []; // appJson.plugins = {};
1181
-
1182
- delete appJson.entranceDeclare;
1175
+ appJson.pages = [];
1183
1176
  return appJson;
1184
1177
  };
1185
1178
  /**
1186
1179
  * 更新app.json中的subpackages
1187
1180
  * @param {Object} appJson
1188
- * @param {Object} modulesConfig
1181
+ * @param {Object} modulesConfigs
1189
1182
  */
1190
1183
 
1191
1184
 
1192
- const updateSubpackages = (appJson, modulesConfig) => {
1185
+ const updateSubpackages = (appJson, modulesConfigs) => {
1193
1186
  // eslint-disable-next-line
1194
- for (const name in modulesConfig) {
1195
- const moduleInfo = isObject(modulesConfig[name]) ? [modulesConfig[name]] : modulesConfig[name]; // 过滤 pages 为空的情况
1196
-
1197
- const validModules = getValidModules(moduleInfo); // eslint-disable-next-line
1198
-
1199
- appJson.subpackages = appJson.subpackages.concat(validModules);
1187
+ for (const modulePath in modulesConfigs) {
1188
+ const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
1189
+ appJson.subpackages = appJson.subpackages.concat(moduleInfo);
1200
1190
  }
1191
+
1192
+ appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
1201
1193
  };
1202
1194
  /**
1203
1195
  * 处理合并subpackages后的appjson, 整理重复不合法的地方
@@ -1212,44 +1204,33 @@ const fixAppJson = appJson => {
1212
1204
  const pluginsMap = {};
1213
1205
  Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
1214
1206
  const subps = subpackages.map(subp => {
1215
- const invalidKeys = [];
1207
+ const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList'];
1208
+ const objOfFileType = ['preloadRule'];
1216
1209
  Object.keys(subp).forEach(key => {
1217
- if (key === 'dependencies') {
1218
- // eslint-disable-next-line
1219
- delete subp.dependencies;
1220
- return;
1221
- }
1222
-
1223
1210
  if (key === 'plugins') {
1224
1211
  Object.keys(subp.plugins).forEach(pk => {
1225
1212
  pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
1226
1213
  });
1227
- return;
1228
- }
1214
+ } // 分包里数组类型字段,提到appjson最上层
1229
1215
 
1230
- if (MODULE_CONFIG_INVALID_KEY.indexOf(key) > -1) {
1231
- // 如果分包配置中有不支持的key,则错误提醒
1232
- invalidKeys.push(key);
1233
- return;
1234
- }
1235
1216
 
1236
- if (['requiredBackgroundModes', 'embeddedAppIdList'].indexOf(key) > -1) {
1237
- // 提到appjson最上层处理
1238
- const preVal = appJson[key]; // eslint-disable-next-line
1217
+ if (arrOfFileType.indexOf(key) > -1) {
1218
+ const preVal = appJson[key];
1219
+ preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
1220
+ } // 分包里对象类型字段,提到appjson最上层
1221
+
1239
1222
 
1240
- preVal ? appJson[key] = Array.from(new Set(preVal // eslint-disable-next-line
1241
- .slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
1242
- return;
1223
+ if (objOfFileType.indexOf(key) > -1) {
1224
+ const preloadRuleMap = appJson[key] || {};
1225
+ subp[key] && Object.keys(subp[key]).forEach(page => {
1226
+ if (!preloadRuleMap[page]) {
1227
+ preloadRuleMap[page] = subp[key][page];
1228
+ }
1229
+ });
1230
+ appJson[key] = preloadRuleMap;
1243
1231
  }
1244
1232
  });
1245
-
1246
- if (invalidKeys.length) {
1247
- fail$5(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
1248
- } // eslint-disable-next-line
1249
-
1250
-
1251
- invalidKeys.concat(['requiredBackgroundModes', 'embeddedAppIdList']).forEach(k => delete subp[k]);
1252
- return subp;
1233
+ return filterField$2(subp, [...arrOfFileType, ...objOfFileType, 'dependencies']);
1253
1234
  }); // 如果plugins重复,则错误提示
1254
1235
 
1255
1236
  const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
@@ -1261,9 +1242,8 @@ const fixAppJson = appJson => {
1261
1242
  }).reduce((pre, cur) => pre + cur, '');
1262
1243
 
1263
1244
  if (pluginsErrMsg) {
1264
- fail$5(`plugins配置出现错误:${pluginsErrMsg}`);
1265
- } // eslint-disable-next-line
1266
-
1245
+ throw new Error(`plugins配置出现错误:${pluginsErrMsg}`);
1246
+ }
1267
1247
 
1268
1248
  appJson.subpackages = subps;
1269
1249
  };
@@ -1280,26 +1260,31 @@ function buildOutputAppJson$1(tmsConfig, modules) {
1280
1260
  var _tmsConfig$hooks;
1281
1261
 
1282
1262
  // 获取当前 modules 下的所有子模块的配置内容
1283
- const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
1263
+ const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
1284
1264
 
1285
- const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
1265
+ const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
1286
1266
 
1287
- updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
1267
+ updateSubpackages(appJson, modulesConfigs); // 处理appJson中重复||冲突的地方
1288
1268
 
1289
1269
  fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1290
1270
 
1291
1271
  updateMainPackages(appJson, tmsConfig.mainPackages);
1292
- fs$8.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1272
+ fs$b.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1293
1273
 
1294
1274
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
1295
1275
  var _tmsConfig$hooks2;
1296
1276
 
1297
- tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson(appJson);
1277
+ tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
1278
+ tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
1279
+ modules,
1280
+ appJson,
1281
+ isDev: global$4.getData('isDev')
1282
+ });
1298
1283
  }
1299
1284
 
1300
1285
  return appJson;
1301
1286
  } catch (e) {
1302
- handleError$3(`生成app.json出现错误: ${e}`);
1287
+ handleError$5(`生成app.json出现错误: ${e}`);
1303
1288
  }
1304
1289
  }
1305
1290
 
@@ -1311,23 +1296,23 @@ var buildAppJson = {
1311
1296
  * 下载第三方代码
1312
1297
  */
1313
1298
  const MetalSmith = require$$0__default$5;
1314
- const crypto$1 = require$$1__default$5;
1299
+ const crypto$2 = require$$1__default$5;
1315
1300
  const {
1316
1301
  downloadRepoForGit,
1317
1302
  pullRepoForGit,
1318
- resolve: resolve$9
1303
+ resolve: resolve$a
1319
1304
  } = widgets;
1320
1305
  const {
1321
1306
  fail: fail$4,
1322
- info: info$5
1307
+ info: info$6
1323
1308
  } = log$1;
1324
- const fs$7 = require$$0__default$2;
1309
+ const fs$a = require$$0__default$2;
1325
1310
  const shelljs$5 = require$$0__default$3;
1326
1311
  const {
1327
- handleError: handleError$2
1312
+ handleError: handleError$4
1328
1313
  } = handleError_1;
1329
1314
  const {
1330
- global: global$4
1315
+ global: global$3
1331
1316
  } = global_1;
1332
1317
  /**
1333
1318
  * 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
@@ -1337,15 +1322,15 @@ const {
1337
1322
  */
1338
1323
 
1339
1324
  function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1340
- var _tmsPrivateCf$gitAcco, _tmsPrivateCf$gitAcco2;
1325
+ var _tmsConfig$gitAccout, _tmsConfig$gitAccount;
1341
1326
 
1342
1327
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1343
- const tmsPrivateCf = global$4.getData('tmsPrivateCf');
1328
+ const tmsConfig = global$3.getData('tmsConfig');
1344
1329
  let gitUrl = httpRepoUrl;
1345
1330
  const {
1346
1331
  username = '',
1347
1332
  pass = ''
1348
- } = (tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : (_tmsPrivateCf$gitAcco = tmsPrivateCf.gitAccout) === null || _tmsPrivateCf$gitAcco === void 0 ? void 0 : _tmsPrivateCf$gitAcco[moduleName]) || (tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : (_tmsPrivateCf$gitAcco2 = tmsPrivateCf.gitAccount) === null || _tmsPrivateCf$gitAcco2 === void 0 ? void 0 : _tmsPrivateCf$gitAcco2[moduleName]) || {};
1333
+ } = (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]) || {};
1349
1334
  const urlPrefixReg = /http(s)?:\/\//;
1350
1335
 
1351
1336
  if (username && pass && urlPrefixReg.test(gitUrl)) {
@@ -1386,7 +1371,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1386
1371
 
1387
1372
  function md5ByGitUrlBranch(gitUrl, branch) {
1388
1373
  const newBranch = branch && typeof branch === 'string' ? branch : 'master';
1389
- return crypto$1.createHash('md5').update(JSON.stringify({
1374
+ return crypto$2.createHash('md5').update(JSON.stringify({
1390
1375
  gitUrl,
1391
1376
  branch: newBranch
1392
1377
  })).digest('hex');
@@ -1417,7 +1402,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1417
1402
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1418
1403
  return Promise.all(callArr);
1419
1404
  }).catch(e => {
1420
- handleError$2(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1405
+ handleError$4(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1421
1406
  }));
1422
1407
  });
1423
1408
  await Promise.all(arrPromises);
@@ -1462,9 +1447,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1462
1447
 
1463
1448
  const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1464
1449
 
1465
- const sourcePath = resolve$9(sourceDir, md5Key); // 模块源码要放到目标目录
1450
+ const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
1466
1451
 
1467
- const targetPath = resolve$9(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1452
+ const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1468
1453
 
1469
1454
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1470
1455
 
@@ -1474,7 +1459,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1474
1459
  targetPath
1475
1460
  },
1476
1461
  fn: async (sourceModulePath, targetPath) => {
1477
- if (fs$7.existsSync(targetPath)) {
1462
+ if (fs$a.existsSync(targetPath)) {
1478
1463
  shelljs$5.rm('-rf', `${targetPath}/*`);
1479
1464
  }
1480
1465
 
@@ -1489,14 +1474,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1489
1474
  } else {
1490
1475
  let promiseTask;
1491
1476
 
1492
- if (fs$7.existsSync(sourcePath) && fs$7.existsSync(`${sourcePath}/.git`)) {
1477
+ if (fs$a.existsSync(sourcePath) && fs$a.existsSync(`${sourcePath}/.git`)) {
1493
1478
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1494
- info$5(`git pull:${httpRepoUrl}`);
1479
+ info$6(`git pull:${httpRepoUrl}`);
1495
1480
  return pullRepoForGit(sourcePath, branch);
1496
1481
  };
1497
1482
  } else {
1498
1483
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1499
- info$5(`git clone: ${httpRepoUrl}`);
1484
+ info$6(`git clone: ${httpRepoUrl}`);
1500
1485
  return downloadRepoForGit(gitUrl, sourcePath, branch);
1501
1486
  };
1502
1487
  }
@@ -1537,7 +1522,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
1537
1522
  const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
1538
1523
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
1539
1524
 
1540
- if (!fs$7.existsSync(`${sourceDir}/${md5Key}`)) {
1525
+ if (!fs$a.existsSync(`${sourceDir}/${md5Key}`)) {
1541
1526
  return true;
1542
1527
  }
1543
1528
  }
@@ -1551,7 +1536,7 @@ var cloneModules_1 = {
1551
1536
  };
1552
1537
 
1553
1538
  const ci = require$$0__default$7;
1554
- const path$7 = require$$1__default$2;
1539
+ const path$9 = require$$1__default$2;
1555
1540
  /**
1556
1541
  * 获取小程序ci的Project对象
1557
1542
  * @returns {Object} 小程序ci对象
@@ -1565,7 +1550,7 @@ const getMpCi = ({
1565
1550
  }) => {
1566
1551
  var _cfgJsonContent$packO;
1567
1552
 
1568
- const cfgJsonContent = require(path$7.join(projectPath, 'project.config.json'));
1553
+ const cfgJsonContent = require(path$9.join(projectPath, 'project.config.json'));
1569
1554
 
1570
1555
  const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
1571
1556
  value
@@ -1631,21 +1616,71 @@ var mpCi = {
1631
1616
  buildMpNpm: buildMpNpm$1
1632
1617
  };
1633
1618
 
1619
+ const fs$9 = require$$0__default$2;
1620
+ const path$8 = require$$1__default$2;
1621
+ const {
1622
+ CACHE_FILE,
1623
+ CACHE_DIR: CACHE_DIR$2
1624
+ } = require$$4;
1625
+ const {
1626
+ ensureDirExist: ensureDirExist$1
1627
+ } = io$3;
1628
+
1629
+ function getCache$1(projectDir, type) {
1630
+ var _content$projectDir;
1631
+
1632
+ const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
1633
+
1634
+ if (!fs$9.existsSync(filePath)) {
1635
+ return null;
1636
+ }
1637
+
1638
+ const content = require(filePath);
1639
+
1640
+ return content === null || content === void 0 ? void 0 : (_content$projectDir = content[projectDir]) === null || _content$projectDir === void 0 ? void 0 : _content$projectDir[type];
1641
+ }
1642
+
1643
+ function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1644
+ const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
1645
+
1646
+ if (!fs$9.existsSync(filePath)) {
1647
+ const dir = path$8.dirname(filePath);
1648
+ ensureDirExist$1(dir);
1649
+ fs$9.writeFileSync(filePath, '{}');
1650
+ }
1651
+
1652
+ const content = require(filePath);
1653
+
1654
+ if (!content[projectDir]) {
1655
+ content[projectDir] = {};
1656
+ }
1657
+
1658
+ content[projectDir] = {
1659
+ [type]: data
1660
+ };
1661
+ fs$9.writeFileSync(filePath, JSON.stringify(content, null, 2));
1662
+ }
1663
+
1664
+ var cache = {
1665
+ setCache: setCache$1,
1666
+ getCache: getCache$1
1667
+ };
1668
+
1634
1669
  /**
1635
1670
  * 本文件主要负责项目或者分包依赖的npm的安装
1636
1671
  */
1637
- const fs$6 = require$$0__default$2;
1672
+ const fs$8 = require$$0__default$2;
1638
1673
  const fsExtra = require$$1__default$6;
1639
- const crypto = require$$1__default$5;
1640
- const path$6 = require$$1__default$2;
1674
+ const crypto$1 = require$$1__default$5;
1675
+ const path$7 = require$$1__default$2;
1641
1676
  const shell = require$$0__default$3;
1642
- const glob = require$$5__default;
1677
+ const glob = require$$6__default;
1643
1678
  const log = log$1;
1644
1679
  const {
1645
- npmInstall
1680
+ npmInstall: npmInstall$1
1646
1681
  } = widgets;
1647
1682
  const {
1648
- handleError: handleError$1
1683
+ handleError: handleError$3
1649
1684
  } = handleError_1;
1650
1685
  const shellJsOption = {
1651
1686
  async: false,
@@ -1669,22 +1704,22 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1669
1704
  const npmTasksMap = new Map();
1670
1705
 
1671
1706
  for (const packageJsonPath of packageJsonFiles) {
1672
- const packageContent = fs$6.readFileSync(packageJsonPath);
1707
+ const packageContent = fs$8.readFileSync(packageJsonPath);
1673
1708
  const packageJson = JSON.parse(packageContent);
1674
1709
  const md5Obj = {
1675
1710
  dependencies: packageJson.dependencies || {}
1676
1711
  };
1677
1712
 
1678
1713
  if (Object.keys(md5Obj.dependencies).length !== 0) {
1679
- const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
1680
- const cacheNMPath = path$6.join(cacheDir, md5Key);
1681
- const cacheNMTarFile = path$6.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
1714
+ const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
1715
+ const cacheNMPath = path$7.join(cacheDir, md5Key);
1716
+ const cacheNMTarFile = path$7.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
1682
1717
 
1683
1718
  const callback = {
1684
1719
  params: {
1685
1720
  cacheNMPath,
1686
1721
  cacheNMTarFile,
1687
- packageJsonDir: path$6.dirname(packageJsonPath),
1722
+ packageJsonDir: path$7.dirname(packageJsonPath),
1688
1723
  shell
1689
1724
  },
1690
1725
  fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
@@ -1713,7 +1748,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1713
1748
  fsExtra.emptydirSync(cacheNMPath);
1714
1749
  shell.cp('-f', packageJsonPath, cacheNMPath);
1715
1750
  log.info(`npm install: ${packageJsonPath}`);
1716
- return npmInstall(cacheNMPath).then(() => {
1751
+ return npmInstall$1(cacheNMPath).then(() => {
1717
1752
  const newShellJsOption = { ...shellJsOption,
1718
1753
  cwd: cacheNMPath
1719
1754
  };
@@ -1741,7 +1776,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1741
1776
  }; // 遍历安装指定目录下所有项目的npm依赖
1742
1777
 
1743
1778
 
1744
- const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1779
+ const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1745
1780
  const cwd = process.cwd();
1746
1781
  const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
1747
1782
 
@@ -1760,11 +1795,12 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1760
1795
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1761
1796
  return Promise.all(callArr);
1762
1797
  }).catch(e => {
1763
- handleError$1(`npm install ${params.packageJsonPath}出现错误:${e}`);
1798
+ handleError$3(`npm install ${params.packageJsonPath}出现错误:${e}`);
1764
1799
  }));
1765
1800
  });
1766
1801
  await Promise.all(arrPromises);
1767
1802
  shell.cd(cwd);
1803
+ return packageJsonFiles;
1768
1804
  };
1769
1805
  /**
1770
1806
  * 递归查找指定条件的文件
@@ -1785,7 +1821,7 @@ const findFilesByFilter = (startPath, filter) => {
1785
1821
 
1786
1822
  const find = (startPath, filter) => {
1787
1823
  // 目录不存在
1788
- if (!fs$6.existsSync(startPath)) {
1824
+ if (!fs$8.existsSync(startPath)) {
1789
1825
  log.fail(`${startPath}目录不存在`);
1790
1826
  process.exit(-1);
1791
1827
  return;
@@ -1798,10 +1834,10 @@ const findFilesByFilter = (startPath, filter) => {
1798
1834
  return;
1799
1835
  }
1800
1836
 
1801
- const files = fs$6.readdirSync(startPath);
1837
+ const files = fs$8.readdirSync(startPath);
1802
1838
  files.forEach(file => {
1803
- const filename = path$6.join(startPath, file);
1804
- const stat = fs$6.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1839
+ const filename = path$7.join(startPath, file);
1840
+ const stat = fs$8.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1805
1841
 
1806
1842
  if (stat.isDirectory()) {
1807
1843
  find(filename, filter);
@@ -1827,7 +1863,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1827
1863
  const packageJsonName = 'package.json'; // 查找文件名
1828
1864
 
1829
1865
  const cwd = contextDir || dirPath;
1830
- const result = [path$6.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1866
+ const result = [path$7.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1831
1867
 
1832
1868
  subRoots.forEach(subRoot => {
1833
1869
  if (!subRoot.root) {
@@ -1835,7 +1871,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1835
1871
  process.exit(1);
1836
1872
  }
1837
1873
 
1838
- const toppath = path$6.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1874
+ const toppath = path$7.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1839
1875
 
1840
1876
  const list = findFilesByFilter(toppath, packageJsonName);
1841
1877
  result.push(...list);
@@ -1851,7 +1887,7 @@ function cloudNpmInstall(contextDir) {
1851
1887
  }
1852
1888
 
1853
1889
  files.forEach(file => {
1854
- const dir = path$6.dirname(file);
1890
+ const dir = path$7.dirname(file);
1855
1891
  shell.cd(dir);
1856
1892
  shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
1857
1893
  silent: false
@@ -1864,73 +1900,47 @@ function cloudNpmInstall(contextDir) {
1864
1900
 
1865
1901
  var npm = {
1866
1902
  cloudNpmInstall,
1867
- mpNpmInstallAll: mpNpmInstallAll$1,
1903
+ npmInstallAll: npmInstallAll$1,
1868
1904
  findAllPackageJson
1869
1905
  };
1870
1906
 
1871
- const shelljs$4 = require$$0__default$3;
1872
- const fs$5 = require$$0__default$2;
1873
- const io$1 = io$3;
1874
- const {
1875
- createTask: createTask$1,
1876
- resolve: resolve$8
1877
- } = widgets;
1878
- const {
1879
- buildMpNpm
1880
- } = mpCi;
1881
- const {
1882
- CACHE_DIR: CACHE_DIR$1
1883
- } = require$$4;
1884
- const {
1885
- mpNpmInstallAll
1886
- } = npm;
1887
- const {
1888
- global: global$3
1889
- } = global_1;
1890
- const {
1891
- fail: fail$3
1892
- } = log$1;
1893
-
1894
- async function install$2(tmsConfig, modules) {
1895
- // 拷贝模块的package.json到编译输出目录
1896
- modules.forEach(item => {
1897
- const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
1898
-
1899
- if (!fs$5.existsSync(resolve$8(item.path))) {
1900
- fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1901
- process.exit(1);
1902
- }
1903
-
1904
- io$1.ensureDirExist(outputModuleDir);
1905
- const modulePackagePath = resolve$8(item.path, 'package.json');
1906
- if (fs$5.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
1907
- }); // 小程序npm install
1908
-
1909
- await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
1910
- const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
1907
+ const crypto = require$$1__default$5;
1908
+ const fs$7 = require$$0__default$2;
1911
1909
 
1912
- await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
1913
- appId: tmsConfig.appId,
1914
- projectPath: resolve$8('./'),
1915
- privateKey: tmsPrivateCf.privateKey
1910
+ function fileMd5$1(filePath) {
1911
+ return new Promise((resolve, reject) => {
1912
+ const md5sum = crypto.createHash('md5');
1913
+ const stream = fs$7.ReadStream(filePath);
1914
+ stream.on('data', d => {
1915
+ md5sum.update(d);
1916
+ });
1917
+ stream.on('error', err => {
1918
+ reject(err);
1919
+ });
1920
+ stream.on('end', () => {
1921
+ const hash = md5sum.digest('hex');
1922
+ resolve(hash);
1923
+ });
1916
1924
  });
1917
1925
  }
1918
1926
 
1919
- var install_1 = install$2;
1927
+ var md5 = {
1928
+ fileMd5: fileMd5$1
1929
+ };
1920
1930
 
1921
- const fs$4 = require$$0__default$2;
1931
+ const fs$6 = require$$0__default$2;
1922
1932
  const semver$1 = require$$1__default$7;
1923
1933
  const {
1924
- resolve: resolve$7
1934
+ resolve: resolve$9
1925
1935
  } = widgets;
1926
- const path$5 = require$$1__default$2;
1927
- const shelljs$3 = require$$0__default$3;
1936
+ const path$6 = require$$1__default$2;
1937
+ const shelljs$4 = require$$0__default$3;
1928
1938
  const {
1929
- handleError
1939
+ handleError: handleError$2
1930
1940
  } = handleError_1;
1931
1941
 
1932
1942
  const getLatestVersion = npmName => {
1933
- const data = shelljs$3.exec(`npm view ${npmName} version`);
1943
+ const data = shelljs$4.exec(`npm view ${npmName} version`);
1934
1944
  return data.stdout || '0.0.0';
1935
1945
  };
1936
1946
  /**
@@ -1942,50 +1952,50 @@ const getLatestVersion = npmName => {
1942
1952
  */
1943
1953
 
1944
1954
 
1945
- const checkDependencies$1 = (modules, cwd, outputDir) => {
1955
+ const isDependenciesUpdate$1 = (modules, cwd, outputDir) => {
1946
1956
  // 步骤1. 收集package.json
1947
1957
  const packageJsonName = 'package.json'; // 查找文件名
1948
1958
  // 1.1根目录的package.json
1949
1959
 
1950
1960
  const packageArr = [{
1951
- srcPackageDir: path$5.join(cwd, packageJsonName),
1952
- destNpmDir: resolve$7(outputDir, 'node_modules')
1961
+ srcPackageDir: path$6.join(cwd, packageJsonName),
1962
+ destNpmDir: resolve$9(outputDir, 'node_modules')
1953
1963
  }]; // 1.2模块的package.json
1954
1964
 
1955
1965
  modules.forEach(item => {
1956
- const srcPackageDir = path$5.join(cwd, item.path, 'package.json');
1966
+ const srcPackageDir = path$6.join(cwd, item.path, 'package.json');
1957
1967
 
1958
- if (fs$4.existsSync(srcPackageDir)) {
1968
+ if (fs$6.existsSync(srcPackageDir)) {
1959
1969
  packageArr.push({
1960
1970
  srcPackageDir,
1961
- destNpmDir: resolve$7(outputDir, item.root, 'node_modules')
1971
+ destNpmDir: resolve$9(outputDir, item.root, 'node_modules')
1962
1972
  });
1963
1973
  }
1964
1974
  }); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
1965
1975
 
1966
1976
  for (const item of packageArr) {
1967
- const packageJson = fs$4.readFileSync(item.srcPackageDir, 'utf-8');
1977
+ const packageJson = fs$6.readFileSync(item.srcPackageDir, 'utf-8');
1968
1978
  let dependencies = {};
1969
1979
 
1970
1980
  try {
1971
1981
  const json = JSON.parse(packageJson);
1972
1982
  dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
1973
1983
  } catch (e) {
1974
- handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
1984
+ handleError$2(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
1975
1985
  }
1976
1986
 
1977
1987
  const dependenciesKeys = Object.keys(dependencies);
1978
1988
 
1979
1989
  for (const key of dependenciesKeys) {
1980
- const depPath = path$5.join(item.destNpmDir, key);
1990
+ const depPath = path$6.join(item.destNpmDir, key);
1981
1991
 
1982
- if (!fs$4.existsSync(depPath)) {
1992
+ if (!fs$6.existsSync(depPath)) {
1983
1993
  return true;
1984
1994
  }
1985
1995
 
1986
- const depPackagePath = path$5.join(depPath, 'package.json');
1996
+ const depPackagePath = path$6.join(depPath, 'package.json');
1987
1997
 
1988
- if (fs$4.existsSync(depPackagePath)) {
1998
+ if (fs$6.existsSync(depPackagePath)) {
1989
1999
  const packageData = require(depPackagePath);
1990
2000
 
1991
2001
  if (dependencies[key] === 'latest') {
@@ -2006,15 +2016,182 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
2006
2016
  return false;
2007
2017
  };
2008
2018
 
2009
- var checkDependencies_1 = {
2010
- checkDependencies: checkDependencies$1
2019
+ var checkDependencies = {
2020
+ isDependenciesUpdate: isDependenciesUpdate$1
2011
2021
  };
2012
2022
 
2023
+ const shelljs$3 = require$$0__default$3;
2024
+ const fs$5 = require$$0__default$2;
2025
+ const path$5 = require$$1__default$2;
2026
+ const io$1 = io$3;
2027
+ const {
2028
+ createTask: createTask$1,
2029
+ resolve: resolve$8
2030
+ } = widgets;
2031
+ const {
2032
+ buildMpNpm
2033
+ } = mpCi;
2034
+ const {
2035
+ setCache,
2036
+ getCache
2037
+ } = cache;
2038
+ const {
2039
+ CACHE_DIR: CACHE_DIR$1
2040
+ } = require$$4;
2041
+ const {
2042
+ npmInstallAll
2043
+ } = npm;
2044
+ const {
2045
+ fail: fail$3,
2046
+ info: info$5
2047
+ } = log$1;
2048
+ const {
2049
+ fileMd5
2050
+ } = md5;
2051
+ const {
2052
+ isDependenciesUpdate
2053
+ } = checkDependencies;
2054
+
2055
+ async function install$2(tmsConfig, modules, env, useCache = true) {
2056
+ const cwd = process.cwd();
2057
+ const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, modules, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2058
+
2059
+ if (!npmInstallRes.isCache) {
2060
+ // 构建miniprogram_npm, 不使用缓存
2061
+ await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, modules, false);
2062
+ } else {
2063
+ // 构建miniprogram_npm
2064
+ await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, modules, useCache);
2065
+ }
2066
+
2067
+ shelljs$3.cd(cwd);
2068
+ }
2069
+
2070
+ async function npmInstall(tmsConfig, modules, useCache) {
2071
+ // 如果依赖没有更新和使用缓存数据(则命中缓存)
2072
+ if (!isDependenciesUpdate(modules, resolve$8('./'), tmsConfig.outputDir) && useCache) {
2073
+ info$5('node_modules命中缓存');
2074
+ return {
2075
+ isCache: true
2076
+ };
2077
+ } // 拷贝模块的package.json到编译输出目录
2078
+
2079
+
2080
+ modules.forEach(item => {
2081
+ const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
2082
+
2083
+ if (!fs$5.existsSync(resolve$8(item.path))) {
2084
+ fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2085
+ process.exit(1);
2086
+ }
2087
+
2088
+ io$1.ensureDirExist(outputModuleDir);
2089
+ const modulePackagePath = resolve$8(item.path, 'package.json');
2090
+ if (fs$5.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
2091
+ });
2092
+ await npmInstallAll(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
2093
+ return {
2094
+ isCache: false
2095
+ };
2096
+ } // 构建miniprogram_npm
2097
+
2098
+
2099
+ async function mpCiInstall(tmsConfig, modules, useCache) {
2100
+ const packageJsonFiles = [];
2101
+ const rootPackFile = resolve$8(`${tmsConfig.outputDir}/package.json`);
2102
+
2103
+ if (fs$5.existsSync(rootPackFile)) {
2104
+ packageJsonFiles.push(rootPackFile);
2105
+ }
2106
+
2107
+ modules.forEach(item => {
2108
+ const packageJsonFile = resolve$8(`${tmsConfig.outputDir}/${item.root}/package.json`);
2109
+
2110
+ if (fs$5.existsSync(packageJsonFile)) {
2111
+ packageJsonFiles.push(packageJsonFile);
2112
+ }
2113
+ });
2114
+ let isCache = false;
2115
+ const statusMap = {
2116
+ success: 1,
2117
+ doing: 2
2118
+ };
2119
+
2120
+ if (useCache) {
2121
+ let flag = true;
2122
+ await Promise.all(packageJsonFiles.map(async item => {
2123
+ const packageDir = path$5.dirname(item);
2124
+ const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2125
+ const md5Value = await getMNPMd5(packageDir);
2126
+ const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
2127
+ // 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
2128
+
2129
+ if ((preCache === null || preCache === void 0 ? void 0 : preCache.status) !== statusMap.success || (preCache === null || preCache === void 0 ? void 0 : preCache.md5) !== md5Value) {
2130
+ flag = false;
2131
+ }
2132
+ }));
2133
+ isCache = flag;
2134
+ }
2135
+
2136
+ if (isCache) {
2137
+ info$5('miniprogram_npm命中缓存');
2138
+ return;
2139
+ } // 即将构建,在cache中标记开始
2140
+
2141
+
2142
+ await Promise.all(packageJsonFiles.map(async item => {
2143
+ const packageDir = path$5.dirname(item);
2144
+ const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2145
+ setCache(mpDir, 'miniprogram_npm', {
2146
+ md5: '',
2147
+ status: statusMap.doing
2148
+ });
2149
+ }));
2150
+ await buildMpNpm({
2151
+ appId: tmsConfig.appId,
2152
+ projectPath: resolve$8('./'),
2153
+ privateKey: tmsConfig.privateKey
2154
+ }); // 构建成功后,计算md5写入cache
2155
+
2156
+ await Promise.all(packageJsonFiles.map(async item => {
2157
+ const packageDir = path$5.dirname(item);
2158
+ const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2159
+ const md5Value = await getMNPMd5(packageDir);
2160
+ setCache(mpDir, 'miniprogram_npm', {
2161
+ md5: md5Value,
2162
+ status: statusMap.success
2163
+ });
2164
+ }));
2165
+ } // 计算miniprogram_npm压缩文件的md5值
2166
+
2167
+
2168
+ async function getMNPMd5(cwd) {
2169
+ const shellJsOption = {
2170
+ async: false,
2171
+ silent: true
2172
+ };
2173
+ shelljs$3.cd(cwd);
2174
+
2175
+ if (fs$5.existsSync('miniprogram_npm')) {
2176
+ shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2177
+ cwd,
2178
+ ...shellJsOption
2179
+ });
2180
+ const md5Value = await fileMd5('./miniprogram_npm.tar.gz');
2181
+ shelljs$3.rm('-rf', path$5.join(cwd, './miniprogram_npm.tar.gz'));
2182
+ return md5Value;
2183
+ }
2184
+
2185
+ return '';
2186
+ }
2187
+
2188
+ var install_1 = install$2;
2189
+
2013
2190
  const shelljs$2 = require$$0__default$3;
2014
- const fs$3 = require$$0__default$2;
2191
+ const fs$4 = require$$0__default$2;
2015
2192
  const io = io$3;
2016
2193
  const {
2017
- resolve: resolve$6,
2194
+ resolve: resolve$7,
2018
2195
  createTask
2019
2196
  } = widgets;
2020
2197
  const {
@@ -2036,9 +2213,6 @@ const {
2036
2213
  info: info$4
2037
2214
  } = log$1;
2038
2215
  const install$1 = install_1;
2039
- const {
2040
- checkDependencies
2041
- } = checkDependencies_1;
2042
2216
  /**
2043
2217
  * 拷贝相关配置文件到编译输出目录
2044
2218
  * @param { object } tmsConfig
@@ -2048,11 +2222,11 @@ const {
2048
2222
  */
2049
2223
 
2050
2224
  const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2051
- const outputDir = resolve$6(tmsConfig.outputDir);
2225
+ const outputDir = resolve$7(tmsConfig.outputDir);
2052
2226
  io.ensureDirExist(outputDir);
2053
2227
  defaultFiles.forEach(item => {
2054
- if (fs$3.existsSync(resolve$6(item))) {
2055
- shelljs$2.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
2228
+ if (fs$4.existsSync(resolve$7(item))) {
2229
+ shelljs$2.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
2056
2230
  }
2057
2231
  });
2058
2232
  };
@@ -2070,7 +2244,7 @@ function checkConfig(targetModules) {
2070
2244
  } // 判断源码目录是否有该模块
2071
2245
 
2072
2246
 
2073
- if (item.path && !fs$3.existsSync(resolve$6(item.path))) {
2247
+ if (item.path && !fs$4.existsSync(resolve$7(item.path))) {
2074
2248
  throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2075
2249
  }
2076
2250
  }
@@ -2080,7 +2254,7 @@ function checkConfig(targetModules) {
2080
2254
 
2081
2255
  async function task(tmsConfig, targetModules) {
2082
2256
  // 下载和移动代码
2083
- await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
2257
+ await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$7('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
2084
2258
 
2085
2259
  let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
2086
2260
 
@@ -2089,10 +2263,7 @@ async function task(tmsConfig, targetModules) {
2089
2263
 
2090
2264
  await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
2091
2265
 
2092
- if (checkDependencies(newModules, resolve$6('./'), tmsConfig.outputDir)) {
2093
- await install$1(tmsConfig, newModules);
2094
- } // 动态生成编译后的app.json;
2095
-
2266
+ await install$1(tmsConfig, newModules); // 动态生成编译后的app.json;
2096
2267
 
2097
2268
  await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2098
2269
  return newModules;
@@ -2183,9 +2354,9 @@ const {
2183
2354
  diffContentCopyFile: diffContentCopyFile$2
2184
2355
  } = io$3;
2185
2356
  const {
2186
- resolve: resolve$5
2357
+ resolve: resolve$6
2187
2358
  } = widgets;
2188
- const fs$2 = require$$0__default$2;
2359
+ const fs$3 = require$$0__default$2;
2189
2360
  const {
2190
2361
  pluginError: pluginError$2
2191
2362
  } = pluginError_1;
@@ -2198,7 +2369,7 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2198
2369
  let contents = '';
2199
2370
 
2200
2371
  try {
2201
- contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
2372
+ contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
2202
2373
  } catch (e) {
2203
2374
  pluginError$2(e, isWatch);
2204
2375
  }
@@ -2215,12 +2386,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2215
2386
  extPath
2216
2387
  } = ext$2(depOriginPath, extensions);
2217
2388
 
2218
- if (!fs$2.existsSync(depOriginFile)) {
2389
+ if (!fs$3.existsSync(depOriginFile)) {
2219
2390
  pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
2220
2391
  return;
2221
2392
  }
2222
2393
 
2223
- const depDestPath = resolve$5(path$4.dirname(anaFileDestFile), depItem);
2394
+ const depDestPath = resolve$6(path$4.dirname(anaFileDestFile), depItem);
2224
2395
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2225
2396
 
2226
2397
  if (!resDep.has(depDestFile)) {
@@ -2244,8 +2415,8 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2244
2415
  const stream = through$2.obj(function (file, enc, cb) {
2245
2416
  // 依赖分析的文件
2246
2417
  const anaFileOriginFile = file.history[0];
2247
- const anaFileRelativeModule = path$4.relative(resolve$5(module.from), anaFileOriginFile);
2248
- const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2418
+ const anaFileRelativeModule = path$4.relative(resolve$6(module.from), anaFileOriginFile);
2419
+ const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2249
2420
 
2250
2421
  if (file.isBuffer()) {
2251
2422
  let contents = String(file.contents);
@@ -2274,7 +2445,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2274
2445
  const regRes = depItem.match(reg) || [];
2275
2446
 
2276
2447
  if (regRes[2]) {
2277
- const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2448
+ const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2278
2449
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2279
2450
 
2280
2451
  if (!copyModules.has(depDestFile)) {
@@ -2327,9 +2498,9 @@ const {
2327
2498
  diffContentCopyFile: diffContentCopyFile$1
2328
2499
  } = io$3;
2329
2500
  const {
2330
- resolve: resolve$4
2501
+ resolve: resolve$5
2331
2502
  } = widgets;
2332
- const fs$1 = require$$0__default$2;
2503
+ const fs$2 = require$$0__default$2;
2333
2504
  const {
2334
2505
  pluginError: pluginError$1
2335
2506
  } = pluginError_1;
@@ -2341,8 +2512,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2341
2512
  const stream = through$1.obj(function (file, enc, cb) {
2342
2513
  // 当前分析的文件的路径
2343
2514
  const anaFileOriginFile = file.history[0];
2344
- const anaFileRelativeModule = path$3.relative(resolve$4(module.from), anaFileOriginFile);
2345
- const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2515
+ const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
2516
+ const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2346
2517
 
2347
2518
  if (file.isBuffer()) {
2348
2519
  let contents = String(file.contents);
@@ -2377,11 +2548,11 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2377
2548
  } // eslint-disable-next-line
2378
2549
 
2379
2550
 
2380
- const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
2551
+ const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
2381
2552
  const regRes = componentPath.match(reg) || [];
2382
2553
 
2383
2554
  if (regRes[2]) {
2384
- const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2555
+ const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2385
2556
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2386
2557
 
2387
2558
  if (!copyModules.has(depDestFile)) {
@@ -2415,7 +2586,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2415
2586
  const originFile = depOriginFile.replace(depOriginExt, extKey);
2416
2587
  const destFile = depDestFile.replace(depOriginExt, extKey);
2417
2588
 
2418
- if (fs$1.existsSync(originFile)) {
2589
+ if (fs$2.existsSync(originFile)) {
2419
2590
  diffContentCopyFile$1(originFile, destFile);
2420
2591
  const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
2421
2592
 
@@ -2449,7 +2620,7 @@ var mpJsonDep_1 = {
2449
2620
  /* eslint-disable no-param-reassign */
2450
2621
  const through = require$$0__default$9;
2451
2622
  const htmlparser2 = require$$1__default$9;
2452
- const fs = require$$0__default$2;
2623
+ const fs$1 = require$$0__default$2;
2453
2624
  const path$2 = require$$1__default$2;
2454
2625
  const {
2455
2626
  diffContentCopyFile,
@@ -2457,7 +2628,7 @@ const {
2457
2628
  fileInDir
2458
2629
  } = io$3;
2459
2630
  const {
2460
- resolve: resolve$3
2631
+ resolve: resolve$4
2461
2632
  } = widgets;
2462
2633
  const {
2463
2634
  dfsFindCommonDep
@@ -2496,7 +2667,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2496
2667
  let contents = '';
2497
2668
 
2498
2669
  try {
2499
- contents = fs.readFileSync(anaFileOriginFile, 'utf8');
2670
+ contents = fs$1.readFileSync(anaFileOriginFile, 'utf8');
2500
2671
  } catch (e) {
2501
2672
  pluginError(e, isWatch);
2502
2673
  }
@@ -2514,7 +2685,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2514
2685
  extPath
2515
2686
  } = extFile(name, depOriginPath);
2516
2687
 
2517
- if (!fs.existsSync(depOriginFile)) {
2688
+ if (!fs$1.existsSync(depOriginFile)) {
2518
2689
  pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
2519
2690
  return;
2520
2691
  }
@@ -2571,8 +2742,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2571
2742
  const stream = through.obj(function (file, enc, cb) {
2572
2743
  // 依赖分析的文件
2573
2744
  const anaFileOriginFile = file.history[0];
2574
- const anaFileRelativeModule = path$2.relative(resolve$3(module.from), anaFileOriginFile);
2575
- const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2745
+ const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
2746
+ const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2576
2747
 
2577
2748
  if (file.isBuffer()) {
2578
2749
  let contents = String(file.contents);
@@ -2603,7 +2774,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2603
2774
  const regRes = attributes.src.match(reg) || [];
2604
2775
 
2605
2776
  if (regRes[2]) {
2606
- const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2777
+ const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2607
2778
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
2608
2779
 
2609
2780
  if (!copyModules.has(depDestFile)) {
@@ -2630,7 +2801,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2630
2801
  beforeDepPath,
2631
2802
  afterDepPath
2632
2803
  }) => {
2633
- if (fs.existsSync(depOriginFile)) {
2804
+ if (fs$1.existsSync(depOriginFile)) {
2634
2805
  diffContentCopyFile(depOriginFile, depDestFile);
2635
2806
  const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
2636
2807
  contents = contents.replace(reg, `"${afterDepPath}"`);
@@ -2826,10 +2997,10 @@ const path$1 = require$$1__default$2;
2826
2997
  const PluginError = require$$2__default$1;
2827
2998
  const fancyLog = require$$3__default;
2828
2999
  const colors = require$$4__default;
2829
- const chokidar = require$$5__default$1;
3000
+ const chokidar = require$$5__default;
2830
3001
  const {
2831
3002
  Duplex
2832
- } = require$$6__default;
3003
+ } = require$$6__default$1;
2833
3004
  const vinyl = require$$7__default;
2834
3005
  const File = require$$8__default;
2835
3006
  const anymatch = require$$9__default;
@@ -2998,10 +3169,10 @@ const path = require$$1__default$2;
2998
3169
  const shellJs = require$$0__default$3;
2999
3170
  const {
3000
3171
  info: info$3,
3001
- warn
3172
+ warn: warn$1
3002
3173
  } = log$1;
3003
3174
  const {
3004
- resolve: resolve$2
3175
+ resolve: resolve$3
3005
3176
  } = widgets;
3006
3177
  const {
3007
3178
  global: global$2
@@ -3018,7 +3189,7 @@ const logTip = (fileName, tipMap) => {
3018
3189
  // eslint-disable-next-line
3019
3190
  for (const item in tipMap) {
3020
3191
  if (fileName.indexOf(item) > -1) {
3021
- warn(`${fileName}有更新, ${tipMap[item]}`);
3192
+ warn$1(`${fileName}有更新, ${tipMap[item]}`);
3022
3193
  return;
3023
3194
  }
3024
3195
  }
@@ -3027,8 +3198,8 @@ const logTip = (fileName, tipMap) => {
3027
3198
  };
3028
3199
 
3029
3200
  const getTargetFile = (sourceFile, module, outputDir) => {
3030
- const sourceFileRelativeModule = path.relative(resolve$2(module.from), sourceFile);
3031
- const targetFile = resolve$2(outputDir, module.to, sourceFileRelativeModule);
3201
+ const sourceFileRelativeModule = path.relative(resolve$3(module.from), sourceFile);
3202
+ const targetFile = resolve$3(outputDir, module.to, sourceFileRelativeModule);
3032
3203
  return targetFile;
3033
3204
  };
3034
3205
 
@@ -3073,13 +3244,15 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3073
3244
  const path = require$$1__default$2;
3074
3245
  const fs = require$$0__default$2;
3075
3246
  const ora = require$$2__default;
3247
+ const chalk = require$$0__default;
3076
3248
  const {
3077
3249
  parallel,
3078
3250
  series
3079
3251
  } = require$$0__default$a;
3080
3252
  const {
3081
3253
  resolve,
3082
- mergeMap
3254
+ mergeMap,
3255
+ filterField
3083
3256
  } = widgets;
3084
3257
  const {
3085
3258
  buildOutputAppJson
@@ -3123,20 +3296,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3123
3296
  }
3124
3297
 
3125
3298
  module.exports = async (tmsConfig, newModules, isDev = true) => {
3126
- const compileTasksMap = new Map(); // 监听app.json
3127
-
3128
- if (isDev) {
3129
- watch([resolve('app.json')], {
3130
- ignoreInitial: false,
3131
- events: watchEvents
3132
- }, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
3133
- from: resolve(),
3134
- to: resolve(tmsConfig.outputDir)
3135
- });
3136
- } else {
3137
- buildOutputAppJson(tmsConfig, newModules, isDev);
3138
- } // 监听根目录的文件
3139
-
3299
+ const compileTasksMap = new Map(); // 监听根目录的文件
3140
3300
 
3141
3301
  mergeMap(compileTasksMap, compile$1(tmsConfig, {
3142
3302
  glob: {
@@ -3250,6 +3410,15 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3250
3410
  var _tmsConfig$hooks;
3251
3411
 
3252
3412
  if (isDev) {
3413
+ // 监听app.json
3414
+ watch([resolve('app.json')], {
3415
+ ignoreInitial: false,
3416
+ events: watchEvents
3417
+ }, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
3418
+ from: resolve(),
3419
+ to: resolve(tmsConfig.outputDir)
3420
+ }); // 监听其他文件
3421
+
3253
3422
  compileTasksMap.forEach(({
3254
3423
  taskFn,
3255
3424
  module
@@ -3259,6 +3428,8 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3259
3428
  events: watchEvents
3260
3429
  }, taskFn, module);
3261
3430
  });
3431
+ } else {
3432
+ buildOutputAppJson(tmsConfig, newModules, isDev);
3262
3433
  }
3263
3434
 
3264
3435
  eTime = new Date().getTime() - sTime;
@@ -3268,12 +3439,12 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3268
3439
 
3269
3440
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
3270
3441
  isDev,
3271
- tmsConfig,
3442
+ tmsConfig: filterField(tmsConfig, ['gitAccount']),
3272
3443
  modules: newModules
3273
3444
  }));
3274
3445
  }
3275
3446
 
3276
- spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
3447
+ spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
3277
3448
  spinner.stop();
3278
3449
  cb();
3279
3450
  }
@@ -3283,7 +3454,8 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3283
3454
  taskFn
3284
3455
  }) => {
3285
3456
  compileTasks.push(taskFn);
3286
- });
3457
+ }); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
3458
+
3287
3459
  series(start, parallel(...compileTasks), end)();
3288
3460
  };
3289
3461
  })(dev$3);
@@ -3291,7 +3463,8 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3291
3463
  const shelljs$1 = require$$0__default$3;
3292
3464
  const compileDev = dev$3.exports;
3293
3465
  const {
3294
- resolve: resolve$1
3466
+ resolve: resolve$2,
3467
+ filterField: filterField$1
3295
3468
  } = widgets;
3296
3469
  const init$4 = init_1;
3297
3470
  const {
@@ -3308,11 +3481,11 @@ const {
3308
3481
  } = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3309
3482
 
3310
3483
  function delOtherModule(tmsConfig, targetModules) {
3311
- const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
3484
+ const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules.all, tmsConfig.appName);
3312
3485
  const targetModulesName = targetModules.map(item => item.name);
3313
3486
  modules.forEach(item => {
3314
3487
  if (item.root && targetModulesName.indexOf(item.name) === -1) {
3315
- const moduleRootDir = resolve$1(`dist/${item.root}`);
3488
+ const moduleRootDir = resolve$2(`${tmsConfig.outputDir}/${item.root}`);
3316
3489
  shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
3317
3490
  silent: true
3318
3491
  }); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
@@ -3330,7 +3503,7 @@ async function dev$2(tmsConfig, targetModules, env) {
3330
3503
  } = global$1.getData('cmd');
3331
3504
 
3332
3505
  if (noCache) {
3333
- shelljs$1.rm('-rf', resolve$1(tmsConfig.outputDir));
3506
+ shelljs$1.rm('-rf', resolve$2(tmsConfig.outputDir));
3334
3507
  shelljs$1.rm('-rf', CACHE_DIR);
3335
3508
  } // 初始化操作
3336
3509
 
@@ -3344,7 +3517,7 @@ async function dev$2(tmsConfig, targetModules, env) {
3344
3517
 
3345
3518
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
3346
3519
  isDev: true,
3347
- tmsConfig,
3520
+ tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
3348
3521
  modules: newModules
3349
3522
  }));
3350
3523
  }
@@ -3362,26 +3535,107 @@ var build$2 = async (tmsConfig, newModules) => {
3362
3535
 
3363
3536
  const shelljs = require$$0__default$3;
3364
3537
  const {
3365
- resolve
3538
+ resolve: resolve$1,
3539
+ filterField
3366
3540
  } = widgets;
3367
3541
  const init$3 = init_1;
3368
3542
  const compileBuild = build$2;
3369
3543
 
3370
3544
  async function build$1(tmsConfig, targetModules, env) {
3545
+ var _tmsConfig$hooks;
3546
+
3371
3547
  // 开始构建前,清理输出目录
3372
- await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
3548
+ await shelljs.rm('-rf', resolve$1(tmsConfig.outputDir));
3373
3549
  const {
3374
3550
  targetModules: newModules
3375
3551
  } = await init$3(tmsConfig, targetModules);
3552
+
3553
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
3554
+ var _tmsConfig$hooks2;
3555
+
3556
+ await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
3557
+ isDev: false,
3558
+ tmsConfig: filterField(tmsConfig, ['gitAccount']),
3559
+ modules: newModules
3560
+ }));
3561
+ }
3376
3562
  compileBuild(tmsConfig, newModules, env);
3377
3563
  }
3378
3564
 
3379
3565
  var build_1 = build$1;
3380
3566
 
3567
+ const fs = require$$0__default$2;
3568
+ const {
3569
+ resolve
3570
+ } = widgets;
3571
+ const {
3572
+ handleError: handleError$1
3573
+ } = handleError_1;
3574
+ const {
3575
+ ensureDirExist
3576
+ } = io$3;
3577
+ const {
3578
+ warn
3579
+ } = log$1;
3580
+ /**
3581
+ * 根据相关配置创建软链接
3582
+ * @param { object } tmsConfig
3583
+ */
3584
+
3585
+ const symLink$1 = tmsConfig => {
3586
+ try {
3587
+ ensureDirExist(resolve(tmsConfig.cloudDir));
3588
+
3589
+ if (tmsConfig.cloudModules) {
3590
+ tmsConfig.cloudModules.forEach(item => {
3591
+ const sourcePath = resolve(item.path);
3592
+ const targetPath = resolve(tmsConfig.cloudDir, item.name);
3593
+
3594
+ if (!fs.existsSync(sourcePath)) {
3595
+ warn(`云函数${sourcePath}不存在`);
3596
+ return;
3597
+ }
3598
+
3599
+ if (!fs.existsSync(targetPath)) {
3600
+ fs.symlinkSync(sourcePath, targetPath);
3601
+ }
3602
+ });
3603
+ }
3604
+ } catch (e) {
3605
+ handleError$1(`创建软链错误: ${e}`);
3606
+ }
3607
+ };
3608
+
3609
+ var symbolicLink = {
3610
+ symLink: symLink$1
3611
+ };
3612
+
3613
+ const {
3614
+ symLink
3615
+ } = symbolicLink;
3616
+ const {
3617
+ handleError
3618
+ } = handleError_1;
3619
+ const {
3620
+ succeed
3621
+ } = log$1;
3622
+
3623
+ var cloud$1 = async tmsConfig => {
3624
+ try {
3625
+ await symLink(tmsConfig);
3626
+ succeed('云函数创建软链成功');
3627
+ } catch (e) {
3628
+ handleError(`创建软链错误: ${e}`);
3629
+ }
3630
+ };
3631
+
3632
+ /* eslint-disable no-param-reassign */
3633
+ const loadash = require$$0__default$6;
3381
3634
  const init$2 = init_1;
3382
3635
  const dev = dev_1;
3383
3636
  const build = build_1;
3384
3637
  const install = install_1;
3638
+ const cloud = cloud$1;
3385
3639
  const {
3386
3640
  global
3387
3641
  } = global_1;
@@ -3409,40 +3663,60 @@ const handleModuleArg = cmd => {
3409
3663
  */
3410
3664
 
3411
3665
 
3412
- const getSpecificModules = (moduleArg, modulePrivateCfg, moduleAll) => {
3666
+ const getSpecificModules = (moduleArg, modules) => {
3413
3667
  if (moduleArg.length > 0) {
3414
3668
  return moduleArg;
3415
- } // 单模块或多模块开发-用户在tms.private.js指定的模块
3669
+ }
3416
3670
 
3671
+ const {
3672
+ all,
3673
+ include,
3674
+ exclude,
3675
+ blockRemote
3676
+ } = modules; // 单模块或多模块开发-用户在tms.private.js指定的模块
3677
+
3678
+ if ((include === null || include === void 0 ? void 0 : include.length) > 0) {
3679
+ return include;
3680
+ }
3417
3681
 
3418
- if (modulePrivateCfg) {
3419
- var _modulePrivateCfg$inc, _modulePrivateCfg$exc;
3682
+ if ((exclude === null || exclude === void 0 ? void 0 : exclude.length) > 0) {
3683
+ return all.filter(module => !exclude.includes(module.name)).map(item => item.name);
3684
+ }
3420
3685
 
3421
- if (((_modulePrivateCfg$inc = modulePrivateCfg.include) === null || _modulePrivateCfg$inc === void 0 ? void 0 : _modulePrivateCfg$inc.length) > 0) {
3422
- return modulePrivateCfg.include;
3423
- }
3686
+ if (blockRemote === true) {
3687
+ return all.filter(module => module.repoInfo === undefined).map(item => item.name);
3688
+ }
3424
3689
 
3425
- if (((_modulePrivateCfg$exc = modulePrivateCfg.exclude) === null || _modulePrivateCfg$exc === void 0 ? void 0 : _modulePrivateCfg$exc.length) > 0) {
3426
- return moduleAll.filter(module => !modulePrivateCfg.exclude.includes(module.name)).map(item => item.name);
3427
- }
3690
+ return all.map(item => item.name);
3691
+ };
3692
+
3693
+ const mergeConfig = (tmsConfig, tmsPrivateCf) => {
3694
+ const modules = {};
3695
+
3696
+ if (Array.isArray(tmsConfig.modules)) {
3697
+ modules.all = tmsConfig.modules;
3698
+ tmsConfig.modules = modules;
3699
+ } // 合并默认值
3428
3700
 
3429
- if (modulePrivateCfg.blockRemote === true) {
3430
- return moduleAll.filter(module => module.repoInfo === undefined).map(item => item.name);
3431
- }
3432
- }
3433
3701
 
3434
- return moduleAll.map(item => item.name);
3702
+ const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
3703
+ if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
3704
+ return objValue.concat(srcValue);
3705
+ }
3706
+ });
3707
+ return res;
3435
3708
  };
3436
3709
 
3437
3710
  async function run(commandName, cmd) {
3438
- // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
3711
+ // 用户本地的私有项目配置
3439
3712
  const tmsPrivateCf = readTmsPrivateCf();
3440
3713
  const {
3441
3714
  env = tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : tmsPrivateCf.env
3442
3715
  } = cmd;
3443
- const tmsConfig = readTmsConfig(env); // 处理module参数
3716
+ let tmsConfig = readTmsConfig(env);
3717
+ tmsConfig = mergeConfig(tmsConfig, tmsPrivateCf); // 处理module参数
3444
3718
 
3445
- const specificModules = getSpecificModules(handleModuleArg(cmd), tmsPrivateCf.modules, tmsConfig.modules);
3719
+ const specificModules = getSpecificModules(handleModuleArg(cmd), tmsConfig.modules);
3446
3720
  const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])], true); // tms.config.js的modules 合并 module.config.json的配置项
3447
3721
 
3448
3722
  let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
@@ -3452,7 +3726,6 @@ async function run(commandName, cmd) {
3452
3726
  global.setData({
3453
3727
  env,
3454
3728
  cmd,
3455
- tmsPrivateCf,
3456
3729
  tmsConfig
3457
3730
  });
3458
3731
 
@@ -3466,8 +3739,12 @@ async function run(commandName, cmd) {
3466
3739
  dev(tmsConfig, newModules, env);
3467
3740
  return;
3468
3741
 
3742
+ case 'cloud':
3743
+ cloud(tmsConfig, env);
3744
+ return;
3745
+
3469
3746
  case 'install':
3470
- install(tmsConfig, newModules, env);
3747
+ install(tmsConfig, newModules, env, false);
3471
3748
  return;
3472
3749
 
3473
3750
  case 'build':
@@ -3506,6 +3783,13 @@ var entry = [{
3506
3783
  action: cmd => {
3507
3784
  run_1('dev', cmd);
3508
3785
  }
3786
+ }, {
3787
+ command: 'cloud',
3788
+ description: '云函数开发',
3789
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
3790
+ action: cmd => {
3791
+ run_1('cloud', cmd);
3792
+ }
3509
3793
  }, {
3510
3794
  command: 'build',
3511
3795
  description: 'prod 打包编译',
@@ -3530,7 +3814,7 @@ var entry = [{
3530
3814
 
3531
3815
  var require$$7 = {
3532
3816
  name: "@tmsfe/tmskit",
3533
- version: "0.0.16",
3817
+ version: "0.0.19",
3534
3818
  description: "tmskit",
3535
3819
  main: "dist/index.cjs",
3536
3820
  bin: {
@@ -3594,7 +3878,7 @@ var require$$7 = {
3594
3878
  lodash: "^4.17.21",
3595
3879
  metalsmith: "^2.3.0",
3596
3880
  "miniprogram-ci": "1.4.13",
3597
- moment: "^2.29.1",
3881
+ moment: "^2.29.2",
3598
3882
  "object-assign": "^4.0.1",
3599
3883
  ora: "^5.1.0",
3600
3884
  "plugin-error": "^1.0.0",