@tmsfe/tmskit 0.0.10 → 0.0.13

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
@@ -1,58 +1,56 @@
1
1
  'use strict';
2
2
 
3
3
  var require$$0 = require('chalk');
4
+ var require$$1 = require('moment');
4
5
  var require$$0$1 = require('commander');
5
- var require$$1 = require('leven');
6
+ var require$$1$1 = require('leven');
6
7
  var require$$2 = require('ora');
7
- var require$$3 = require('path');
8
+ var require$$1$2 = require('path');
8
9
  var require$$0$2 = require('fs');
9
10
  var require$$0$3 = require('shelljs');
10
11
  var require$$0$4 = require('async');
11
- var require$$1$1 = require('ejs');
12
- var require$$1$2 = require('inquirer');
12
+ var require$$1$3 = require('ejs');
13
+ var require$$1$4 = require('inquirer');
13
14
  var require$$0$5 = require('metalsmith');
14
15
  var require$$0$6 = require('lodash');
15
- var require$$1$3 = require('crypto');
16
+ var require$$1$5 = require('crypto');
16
17
  var require$$0$7 = require('miniprogram-ci');
17
18
  var require$$5 = require('glob-ignore');
18
- var require$$1$4 = require('fs-extra');
19
- var require$$9 = require('console');
19
+ var require$$1$6 = require('fs-extra');
20
20
  var require$$0$8 = require('strip-comments');
21
21
  var require$$0$9 = require('through2');
22
- var require$$1$5 = require('precinct');
23
- var require$$1$6 = require('htmlparser2');
22
+ var require$$1$7 = require('precinct');
23
+ var require$$1$8 = require('htmlparser2');
24
24
  var require$$0$a = require('gulp');
25
- var require$$1$7 = require('gulp-px-to-rpx');
26
- var require$$2$1 = require('gulp-watch');
27
- var require$$1$8 = require('semver');
25
+ var require$$0$b = require('gulp-watch');
26
+ var require$$1$9 = require('semver');
28
27
 
29
28
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
30
29
 
31
30
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
32
- var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
33
31
  var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
32
+ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
33
+ var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
34
34
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
35
- var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
35
+ var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
36
36
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
37
37
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
38
38
  var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
39
- var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
40
- var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
39
+ var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
40
+ var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
41
41
  var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
42
42
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
43
- var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
43
+ var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
44
44
  var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
45
45
  var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
46
- var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
47
- var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
46
+ var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
48
47
  var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
49
48
  var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
50
- var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
51
- var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
52
- var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
53
49
  var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
54
- var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
55
50
  var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
51
+ var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
52
+ var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
53
+ var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
56
54
 
57
55
  function getAugmentedNamespace(n) {
58
56
  if (n.__esModule) return n;
@@ -72,6 +70,7 @@ function getAugmentedNamespace(n) {
72
70
  var src$2 = {};
73
71
 
74
72
  const chalk$3 = require$$0__default;
73
+ const moment = require$$1__default;
75
74
  /**
76
75
  * 本文件提供无依赖的在终端打印彩色文字的方法。
77
76
  */
@@ -89,7 +88,7 @@ const fail$9 = (message = '') => {
89
88
 
90
89
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
91
90
 
92
- console.log(`${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
91
+ console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
93
92
  };
94
93
  /**
95
94
  * 打印绿底黑字格式的文字
@@ -103,7 +102,7 @@ const succeed$1 = (message = '') => {
103
102
 
104
103
  const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
105
104
 
106
- console.log(`${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
105
+ console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
107
106
  };
108
107
  /**
109
108
  * 打印warn提示
@@ -113,10 +112,10 @@ const succeed$1 = (message = '') => {
113
112
 
114
113
 
115
114
  const warn = message => {
116
- console.log(chalk$3.yellow(message));
115
+ console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
117
116
  };
118
117
 
119
- const info$9 = (...args) => console.log(...args);
118
+ const info$9 = (...args) => console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
120
119
 
121
120
  var log$1 = {
122
121
  fail: fail$9,
@@ -126,9 +125,9 @@ var log$1 = {
126
125
  };
127
126
 
128
127
  const program$1 = require$$0__default$1;
129
- const leven = require$$1__default;
128
+ const leven = require$$1__default$1;
130
129
  const ora = require$$2__default;
131
- const path$a = require$$3__default;
130
+ const path$b = require$$1__default$2;
132
131
  const fs$e = require$$0__default$2;
133
132
  const shelljs$6 = require$$0__default$3;
134
133
  const {
@@ -142,8 +141,8 @@ const shelljsOptions = {
142
141
 
143
142
  const cwd = process.cwd();
144
143
 
145
- function resolve$f(...args) {
146
- return path$a.resolve(cwd, ...args);
144
+ function resolve$g(...args) {
145
+ return path$b.resolve(cwd, ...args);
147
146
  }
148
147
  /**
149
148
  * 用户输入命令时,进行提示
@@ -200,7 +199,7 @@ function downloadRepoForGit$2(url, dest, branch) {
200
199
  return new Promise((resolve, reject) => {
201
200
  // 如果目标目录不存在
202
201
  if (fs$e.existsSync(dest)) {
203
- shelljs$6.rm('-rf', path$a.join(dest));
202
+ shelljs$6.rm('-rf', path$b.join(dest));
204
203
  }
205
204
 
206
205
  shelljs$6.mkdir('-p', dest);
@@ -251,7 +250,7 @@ function pullRepoForGit$1(dest, branch) {
251
250
 
252
251
  function npmInstall$1(dir) {
253
252
  return new Promise((resolve, reject) => {
254
- shelljs$6.exec('npx yarn --production --registry http://mirrors.tencent.com/npm/', {
253
+ shelljs$6.exec('npm install --production --registry http://mirrors.tencent.com/npm/', {
255
254
  cwd: dir,
256
255
  silent: true
257
256
  }, (code, stdout, stderr) => {
@@ -285,7 +284,6 @@ function createTask$3(task, startText, endText) {
285
284
  const start = Date.now();
286
285
  const spinner = ora(startText);
287
286
  spinner.start();
288
- info$8('\n');
289
287
  const result = await task(...args);
290
288
  endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
291
289
  spinner.stop();
@@ -300,8 +298,24 @@ function createTask$3(task, startText, endText) {
300
298
 
301
299
  const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
302
300
 
301
+ const mergeMap = function (obj, src) {
302
+ for (const [k, v] of src) {
303
+ if (obj.has(k)) {
304
+ obj.set(k, obj.get(k) + v);
305
+ } else {
306
+ obj.set(k, v);
307
+ }
308
+ }
309
+
310
+ return obj;
311
+ };
312
+
313
+ const relativeCwdPath$1 = function (file) {
314
+ return path$b.relative(process.cwd(), file);
315
+ };
316
+
303
317
  var widgets = {
304
- resolve: resolve$f,
318
+ resolve: resolve$g,
305
319
  isObject: isObject$2,
306
320
  isArray: isArray$1,
307
321
  createTask: createTask$3,
@@ -309,25 +323,27 @@ var widgets = {
309
323
  pullRepoForGit: pullRepoForGit$1,
310
324
  suggestCommands: suggestCommands$1,
311
325
  camelize,
312
- npmInstall: npmInstall$1
326
+ npmInstall: npmInstall$1,
327
+ mergeMap,
328
+ relativeCwdPath: relativeCwdPath$1
313
329
  };
314
330
 
315
- const path$9 = require('path');
331
+ const path$a = require('path');
316
332
 
317
333
  const os = require('os'); // 用户目录
318
334
 
319
335
 
320
336
  const HOME_DIR = os.homedir(); // 所有文件的缓存目录
321
337
 
322
- const CACHE_DIR$1 = path$9.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
338
+ const CACHE_DIR$1 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
323
339
 
324
- const TEMPLATE_DIR$1 = path$9.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
340
+ const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
325
341
 
326
- const MODULE_CODE_DIR$2 = path$9.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
342
+ const MODULE_CODE_DIR$2 = path$a.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
327
343
 
328
- const TEMPLATE_PATH$1 = path$9.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
344
+ const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
329
345
 
330
- const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
346
+ const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
331
347
 
332
348
  const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
333
349
  const TMS_PRIVATE_FILENAME$1 = 'tms.private.config.js'; // 模块代码的默认在modules子目录
@@ -336,10 +352,10 @@ const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目
336
352
 
337
353
  const DEFAULT_CLOUD_MODULE_DIR$1 = './cloud'; // 模块的配置文件的名称
338
354
 
339
- const MODULE_CONFIG_FILENAME$3 = 'module.config.json'; // 默认的webpack entry
355
+ const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
340
356
 
341
357
  const DEFAULT_WEBPACK_ENTRY = {
342
- app: path$9.resolve(process.cwd(), 'app')
358
+ app: path$a.resolve(process.cwd(), 'app')
343
359
  }; // 默认从源码拷贝到编译后的配置
344
360
 
345
361
  const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
@@ -356,11 +372,11 @@ var constant = /*#__PURE__*/Object.freeze({
356
372
  CACHE_DIR: CACHE_DIR$1,
357
373
  TEMPLATE_DIR: TEMPLATE_DIR$1,
358
374
  TEMPLATE_PATH: TEMPLATE_PATH$1,
359
- TMS_NAME: TMS_NAME$2,
375
+ TMS_NAME: TMS_NAME$1,
360
376
  TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
361
377
  TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME$1,
362
378
  DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
363
- MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$3,
379
+ MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
364
380
  DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
365
381
  DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
366
382
  MODULE_CODE_DIR: MODULE_CODE_DIR$2,
@@ -373,10 +389,13 @@ var constant = /*#__PURE__*/Object.freeze({
373
389
  var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
374
390
 
375
391
  const fs$d = require$$0__default$2;
376
- const path$8 = require$$3__default;
392
+ const path$9 = require$$1__default$2;
377
393
  const {
378
394
  info: info$7
379
395
  } = log$1;
396
+ const {
397
+ relativeCwdPath
398
+ } = widgets;
380
399
  /**
381
400
  * 判断目录是否为空
382
401
  * @param {string} dirname 目录名
@@ -414,7 +433,7 @@ const copyFile = function (src, dest) {
414
433
  fs$d.unlinkSync(dest);
415
434
  }
416
435
 
417
- const dir = path$8.dirname(dest);
436
+ const dir = path$9.dirname(dest);
418
437
  ensureDirExist(dir);
419
438
  fs$d.copyFileSync(src, dest);
420
439
  }; // 判断文件内容是否一致,不一致再进行拷贝
@@ -426,11 +445,11 @@ function diffContentCopyFile$3(originFile, destFile) {
426
445
  const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
427
446
 
428
447
  if (depDestContent !== depOriginContent) {
429
- info$7(`拷贝${originFile}内容到${destFile}`);
448
+ info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
430
449
  copyFile(originFile, destFile);
431
450
  }
432
451
  } else {
433
- info$7(`拷贝${originFile}内容到${destFile}`);
452
+ info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
434
453
  copyFile(originFile, destFile);
435
454
  }
436
455
  } // 添加后缀
@@ -474,7 +493,7 @@ const fileInDir$3 = (dir, file) => {
474
493
  return false;
475
494
  }
476
495
 
477
- const relativePath = path$8.relative(dir, file);
496
+ const relativePath = path$9.relative(dir, file);
478
497
 
479
498
  if (relativePath.startsWith('..')) {
480
499
  return false;
@@ -494,7 +513,7 @@ var io$2 = {
494
513
  };
495
514
 
496
515
  const async = require$$0__default$4;
497
- const ejs = require$$1__default$1;
516
+ const ejs = require$$1__default$3;
498
517
 
499
518
  const render$1 = (files, metalsmith, next) => {
500
519
  const keys = Object.keys(files);
@@ -514,9 +533,9 @@ const render$1 = (files, metalsmith, next) => {
514
533
  var render_1 = render$1;
515
534
 
516
535
  const fs$c = require$$0__default$2;
517
- const inquirer = require$$1__default$2;
536
+ const inquirer = require$$1__default$4;
518
537
  const {
519
- resolve: resolve$e
538
+ resolve: resolve$f
520
539
  } = widgets;
521
540
  const {
522
541
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -568,7 +587,7 @@ const isQuestionType = result => {
568
587
  };
569
588
 
570
589
  const ask$1 = templateDir => (files, metalsmith, next) => {
571
- const prompts = parseTemplateQuestions(resolve$e(templateDir, TEMPLATE_TKIT_DIR$1));
590
+ const prompts = parseTemplateQuestions(resolve$f(templateDir, TEMPLATE_TKIT_DIR$1));
572
591
  const metadata = metalsmith.metadata();
573
592
  const filteredPrompts = prompts.filter(prompt => {
574
593
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -610,7 +629,7 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
610
629
 
611
630
  var generator_1 = generator$1;
612
631
 
613
- const path$7 = require$$3__default;
632
+ const path$8 = require$$1__default$2;
614
633
  const fs$b = require$$0__default$2;
615
634
  const shelljs$5 = require$$0__default$3;
616
635
  const {
@@ -621,7 +640,7 @@ const {
621
640
  const {
622
641
  downloadRepoForGit: downloadRepoForGit$1,
623
642
  createTask: createTask$2,
624
- resolve: resolve$d
643
+ resolve: resolve$e
625
644
  } = widgets;
626
645
  const io$1 = io$2;
627
646
  const {
@@ -656,7 +675,7 @@ async function createAppDir(targetDir) {
656
675
 
657
676
  async function create(appName) {
658
677
  const cwd = process.cwd();
659
- const targetDir = path$7.resolve(cwd, appName);
678
+ const targetDir = path$8.resolve(cwd, appName);
660
679
  const appType = 'mp';
661
680
  await createAppDir(targetDir); // 创建缓存目录
662
681
 
@@ -664,13 +683,13 @@ async function create(appName) {
664
683
 
665
684
  await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
666
685
 
667
- generator(path$7.join(TEMPLATE_PATH, appType), targetDir, {
686
+ generator(path$8.join(TEMPLATE_PATH, appType), targetDir, {
668
687
  appName,
669
688
  appType
670
689
  }).then(() => {
671
690
  shelljs$5.cd(appName);
672
691
 
673
- const hooks = require(resolve$d(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
692
+ const hooks = require(resolve$e(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
674
693
 
675
694
  if (hooks.afterCreate) {
676
695
  hooks.afterCreate.forEach(item => {
@@ -684,7 +703,7 @@ async function create(appName) {
684
703
  });
685
704
  }
686
705
 
687
- shelljs$5.rm('-rf', resolve$d(appName, TEMPLATE_TKIT_DIR));
706
+ shelljs$5.rm('-rf', resolve$e(appName, TEMPLATE_TKIT_DIR));
688
707
  succeed('项目创建完成.');
689
708
  }).catch(err => {
690
709
  fail$8(err.message);
@@ -719,13 +738,12 @@ var defaultTmsConfig$1 = {
719
738
  const loadash = require$$0__default$6;
720
739
  const fs$a = require$$0__default$2;
721
740
  const {
722
- TMS_NAME: TMS_NAME$1,
723
741
  TMS_CONFIG_FILENAME,
724
- MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
742
+ MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
725
743
  TMS_PRIVATE_FILENAME
726
744
  } = require$$4;
727
745
  const {
728
- resolve: resolve$c,
746
+ resolve: resolve$d,
729
747
  isObject: isObject$1,
730
748
  isArray
731
749
  } = widgets;
@@ -733,14 +751,14 @@ const defaultTmsConfig = defaultTmsConfig$1;
733
751
  const {
734
752
  fail: fail$7
735
753
  } = log$1;
736
- const path$6 = require$$3__default;
754
+ const path$7 = require$$1__default$2;
737
755
  /**
738
756
  * 读取tms.config.js
739
757
  * @param env {string} 环境变量
740
758
  */
741
759
 
742
760
  const readTmsConfig$1 = function (env) {
743
- const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
761
+ const tmsConfigPath = resolve$d(TMS_CONFIG_FILENAME);
744
762
 
745
763
  if (!fs$a.existsSync(tmsConfigPath)) {
746
764
  fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
@@ -768,14 +786,14 @@ const convertModules = modules => {
768
786
  if (typeof module === 'string') {
769
787
  // 路径字符串
770
788
  Object.assign(newModule, {
771
- name: path$6.basename(module),
789
+ name: path$7.basename(module),
772
790
  path: module
773
791
  });
774
792
  } else if (typeof module === 'object') {
775
793
  Object.assign(newModule, module);
776
794
 
777
795
  if (module.name === undefined) {
778
- newModule.name = path$6.basename(module.path);
796
+ newModule.name = path$7.basename(module.path);
779
797
  }
780
798
  }
781
799
 
@@ -790,7 +808,7 @@ const convertModules = modules => {
790
808
 
791
809
  const readTmsPrivateCf$1 = function () {
792
810
  let tmsPrivateCf = {};
793
- const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
811
+ const tmsPrivatePath = resolve$d(TMS_PRIVATE_FILENAME);
794
812
 
795
813
  if (fs$a.existsSync(tmsPrivatePath)) {
796
814
  tmsPrivateCf = require(tmsPrivatePath);
@@ -813,7 +831,7 @@ const readTmsPrivateCf$1 = function () {
813
831
  */
814
832
 
815
833
 
816
- const checkModules$1 = function (tmsConfig, modules) {
834
+ const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
817
835
  const targetModules = [];
818
836
  modules.forEach(moduleName => {
819
837
  const module = tmsConfig.modules.find(module => module.name === moduleName);
@@ -821,8 +839,9 @@ const checkModules$1 = function (tmsConfig, modules) {
821
839
  });
822
840
 
823
841
  if (targetModules.length === 0) {
824
- fail$7(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
825
- process.exit(1);
842
+ fail$7(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
843
+ >name字段与module.config.json的name字段是否一致`);
844
+ isQuit && process.exit(1);
826
845
  }
827
846
 
828
847
  return targetModules;
@@ -883,7 +902,7 @@ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
883
902
  modules.forEach(({
884
903
  path
885
904
  }) => {
886
- const moduleConfigPath = resolve$c(path, moduleConfigFilename);
905
+ const moduleConfigPath = resolve$d(path, moduleConfigFilename);
887
906
 
888
907
  if (fs$a.existsSync(moduleConfigPath)) {
889
908
  const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
@@ -907,7 +926,7 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
907
926
  path: relativePath,
908
927
  name: moduleName
909
928
  }, moduleIndex) => {
910
- const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$2);
929
+ const moduleConfigPath = resolve$d(relativePath, MODULE_CONFIG_FILENAME$1);
911
930
 
912
931
  if (fs$a.existsSync(moduleConfigPath)) {
913
932
  try {
@@ -927,7 +946,7 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
927
946
  });
928
947
 
929
948
  if (!findModule) {
930
- fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
949
+ fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到或pages为空,请检查配置`);
931
950
  process.exit(1);
932
951
  }
933
952
  } catch (e) {
@@ -967,10 +986,13 @@ const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
967
986
  // 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
968
987
  // 否则递归处理,根据name找到相关配置加到modules里
969
988
  if (moduleNames.indexOf(item) === -1) {
970
- isOver = false;
971
989
  const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
972
- mergeModules = [...mergeModules, ...tmpModules];
973
- mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
990
+
991
+ if (tmpModules.length > 0) {
992
+ isOver = false;
993
+ mergeModules = [...mergeModules, ...tmpModules];
994
+ mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
995
+ }
974
996
  }
975
997
  });
976
998
  });
@@ -987,7 +1009,7 @@ var tmsMpconfig = {
987
1009
  subModulesMergeDepModules: subModulesMergeDepModules$2
988
1010
  };
989
1011
 
990
- const global$5 = {
1012
+ const global$6 = {
991
1013
  data: {},
992
1014
 
993
1015
  setData(...args) {
@@ -1009,19 +1031,19 @@ const global$5 = {
1009
1031
 
1010
1032
  };
1011
1033
  var global_1 = {
1012
- global: global$5
1034
+ global: global$6
1013
1035
  };
1014
1036
 
1015
1037
  const {
1016
1038
  fail: fail$6
1017
1039
  } = log$1;
1018
1040
  const {
1019
- global: global$4
1041
+ global: global$5
1020
1042
  } = global_1;
1021
1043
 
1022
1044
  function handleError$5(error) {
1023
1045
  const errMsg = typeof error === 'object' ? error.message : error;
1024
- const isDev = global$4.getData('isDev');
1046
+ const isDev = global$5.getData('isDev');
1025
1047
 
1026
1048
  if (isDev) {
1027
1049
  fail$6(errMsg);
@@ -1040,7 +1062,7 @@ var handleError_1 = {
1040
1062
  */
1041
1063
  const fs$9 = require$$0__default$2;
1042
1064
  const {
1043
- MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
1065
+ MODULE_CONFIG_FILENAME,
1044
1066
  MODULE_CONFIG_INVALID_KEY
1045
1067
  } = require$$4;
1046
1068
  const {
@@ -1051,7 +1073,7 @@ const {
1051
1073
  fail: fail$5
1052
1074
  } = log$1;
1053
1075
  const {
1054
- resolve: resolve$b,
1076
+ resolve: resolve$c,
1055
1077
  isObject
1056
1078
  } = widgets;
1057
1079
  const {
@@ -1210,16 +1232,16 @@ const fixAppJson = appJson => {
1210
1232
  function buildOutputAppJson$1(tmsConfig, modules) {
1211
1233
  try {
1212
1234
  // 获取当前 modules 下的所有子模块的配置内容
1213
- const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
1235
+ const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
1214
1236
 
1215
- const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
1237
+ const appJson = getAppJsonContent(resolve$c('./app.json')); // 更新app.json中的subpackages
1216
1238
 
1217
1239
  updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
1218
1240
 
1219
1241
  fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1220
1242
 
1221
1243
  updateMainPackages(appJson, tmsConfig.mainPackages);
1222
- fs$9.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1244
+ fs$9.writeFileSync(resolve$c(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1223
1245
  return appJson;
1224
1246
  } catch (e) {
1225
1247
  handleError$4(`生成app.json出现错误: ${e}`);
@@ -1232,7 +1254,7 @@ var buildAppJson = {
1232
1254
 
1233
1255
  const fs$8 = require$$0__default$2;
1234
1256
  const {
1235
- resolve: resolve$a
1257
+ resolve: resolve$b
1236
1258
  } = widgets;
1237
1259
  const {
1238
1260
  handleError: handleError$3
@@ -1249,7 +1271,12 @@ const symLink$1 = tmsConfig => {
1249
1271
  try {
1250
1272
  if (tmsConfig.cloudModules) {
1251
1273
  tmsConfig.cloudModules.forEach(item => {
1252
- fs$8.symlinkSync(resolve$a(item.path), resolve$a(DEFAULT_CLOUD_MODULE_DIR, item.name));
1274
+ const path = resolve$b(DEFAULT_CLOUD_MODULE_DIR, item.name);
1275
+ fs$8.access(path, fs$8.constants.F_OK, res => {
1276
+ if (res) {
1277
+ fs$8.symlinkSync(resolve$b(item.path), path);
1278
+ }
1279
+ });
1253
1280
  });
1254
1281
  }
1255
1282
  } catch (e) {
@@ -1265,11 +1292,11 @@ var symbolicLink = {
1265
1292
  * 下载第三方代码
1266
1293
  */
1267
1294
  const MetalSmith = require$$0__default$5;
1268
- const crypto$1 = require$$1__default$3;
1295
+ const crypto$1 = require$$1__default$5;
1269
1296
  const {
1270
1297
  downloadRepoForGit,
1271
1298
  pullRepoForGit,
1272
- resolve: resolve$9
1299
+ resolve: resolve$a
1273
1300
  } = widgets;
1274
1301
  const {
1275
1302
  fail: fail$4,
@@ -1281,7 +1308,7 @@ const {
1281
1308
  handleError: handleError$2
1282
1309
  } = handleError_1;
1283
1310
  const {
1284
- global: global$3
1311
+ global: global$4
1285
1312
  } = global_1;
1286
1313
  /**
1287
1314
  * 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
@@ -1291,15 +1318,15 @@ const {
1291
1318
  */
1292
1319
 
1293
1320
  function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1294
- var _tmsPrivateCf$gitAcco;
1321
+ var _tmsPrivateCf$gitAcco, _tmsPrivateCf$gitAcco2;
1295
1322
 
1296
1323
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1297
- const tmsPrivateCf = global$3.getData('tmsPrivateCf');
1324
+ const tmsPrivateCf = global$4.getData('tmsPrivateCf');
1298
1325
  let gitUrl = httpRepoUrl;
1299
1326
  const {
1300
1327
  username = '',
1301
1328
  pass = ''
1302
- } = (tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : (_tmsPrivateCf$gitAcco = tmsPrivateCf.gitAccout) === null || _tmsPrivateCf$gitAcco === void 0 ? void 0 : _tmsPrivateCf$gitAcco[moduleName]) || {};
1329
+ } = (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]) || {};
1303
1330
  const urlPrefixReg = /http(s)?:\/\//;
1304
1331
 
1305
1332
  if (username && pass && urlPrefixReg.test(gitUrl)) {
@@ -1354,7 +1381,8 @@ function md5ByGitUrlBranch(gitUrl, branch) {
1354
1381
 
1355
1382
 
1356
1383
  async function cloneModules$1(sourceDir, targetDir, modules) {
1357
- // 收集下载模块代码的任务
1384
+ const cwd = process.cwd(); // 收集下载模块代码的任务
1385
+
1358
1386
  const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules); // 开始执行下载和移动代码的任务
1359
1387
 
1360
1388
  const arrPromises = [];
@@ -1374,6 +1402,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1374
1402
  }));
1375
1403
  });
1376
1404
  await Promise.all(arrPromises);
1405
+ shelljs$4.cd(cwd);
1377
1406
  }
1378
1407
  /**
1379
1408
  * 收集下载模块代码的任务
@@ -1414,9 +1443,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1414
1443
 
1415
1444
  const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1416
1445
 
1417
- const sourcePath = resolve$9(sourceDir, md5Key); // 模块源码要放到目标目录
1446
+ const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
1418
1447
 
1419
- const targetPath = resolve$9(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1448
+ const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1420
1449
 
1421
1450
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1422
1451
 
@@ -1443,12 +1472,12 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1443
1472
 
1444
1473
  if (fs$7.existsSync(sourcePath) && fs$7.existsSync(`${sourcePath}/.git`)) {
1445
1474
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1446
- info$5(`git pull仓库:${httpRepoUrl}`);
1475
+ info$5(`git pull:${httpRepoUrl}`);
1447
1476
  return pullRepoForGit(sourcePath, branch);
1448
1477
  };
1449
1478
  } else {
1450
1479
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1451
- info$5(`git clone仓库: ${httpRepoUrl}`);
1480
+ info$5(`git clone: ${httpRepoUrl}`);
1452
1481
  return downloadRepoForGit(gitUrl, sourcePath, branch);
1453
1482
  };
1454
1483
  }
@@ -1503,7 +1532,7 @@ var cloneModules_1 = {
1503
1532
  };
1504
1533
 
1505
1534
  const ci = require$$0__default$7;
1506
- const path$5 = require$$3__default;
1535
+ const path$6 = require$$1__default$2;
1507
1536
  /**
1508
1537
  * 获取小程序ci的Project对象
1509
1538
  * @returns {Object} 小程序ci对象
@@ -1517,7 +1546,7 @@ const getMpCi = ({
1517
1546
  }) => {
1518
1547
  var _cfgJsonContent$packO;
1519
1548
 
1520
- const cfgJsonContent = require(path$5.join(projectPath, 'project.config.json'));
1549
+ const cfgJsonContent = require(path$6.join(projectPath, 'project.config.json'));
1521
1550
 
1522
1551
  const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
1523
1552
  value
@@ -1587,9 +1616,9 @@ var mpCi = {
1587
1616
  * 本文件主要负责项目或者分包依赖的npm的安装
1588
1617
  */
1589
1618
  const fs$6 = require$$0__default$2;
1590
- const fsExtra = require$$1__default$4;
1591
- const crypto = require$$1__default$3;
1592
- const path$4 = require$$3__default;
1619
+ const fsExtra = require$$1__default$6;
1620
+ const crypto = require$$1__default$5;
1621
+ const path$5 = require$$1__default$2;
1593
1622
  const shell = require$$0__default$3;
1594
1623
  const glob = require$$5__default;
1595
1624
  const log = log$1;
@@ -1599,9 +1628,6 @@ const {
1599
1628
  const {
1600
1629
  handleError: handleError$1
1601
1630
  } = handleError_1;
1602
- const {
1603
- info: info$4
1604
- } = require$$9__default;
1605
1631
  const shellJsOption = {
1606
1632
  async: false,
1607
1633
  silent: true
@@ -1632,14 +1658,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1632
1658
 
1633
1659
  if (Object.keys(md5Obj.dependencies).length !== 0) {
1634
1660
  const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
1635
- const cacheNMPath = path$4.join(cacheDir, md5Key);
1636
- const cacheNMTarFile = path$4.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
1661
+ const cacheNMPath = path$5.join(cacheDir, md5Key);
1662
+ const cacheNMTarFile = path$5.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
1637
1663
 
1638
1664
  const callback = {
1639
1665
  params: {
1640
1666
  cacheNMPath,
1641
1667
  cacheNMTarFile,
1642
- packageJsonDir: path$4.dirname(packageJsonPath),
1668
+ packageJsonDir: path$5.dirname(packageJsonPath),
1643
1669
  shell
1644
1670
  },
1645
1671
  fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
@@ -1648,8 +1674,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1648
1674
  const newShellJsOption = { ...shellJsOption,
1649
1675
  cwd: packageJsonDir
1650
1676
  };
1651
- shell.exec('tar -xzvf ./node_modules.tar.gz -C ./', newShellJsOption);
1652
- shell.exec('rm -rf ./node_modules.tar.gz', newShellJsOption);
1677
+ shell.exec('tar -xvf ./node_modules.tar.gz -C ./', newShellJsOption);
1678
+ shell.rm('-rf', './node_modules');
1653
1679
  }
1654
1680
  };
1655
1681
 
@@ -1666,13 +1692,13 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1666
1692
  promiseTask = (packageJsonPath, cacheNMPath, shell) => {
1667
1693
  fsExtra.emptydirSync(cacheNMPath);
1668
1694
  shell.cp('-f', packageJsonPath, cacheNMPath);
1669
- info$4(`npm install: ${packageJsonPath}`);
1695
+ log.info(`npm install: ${packageJsonPath}`);
1670
1696
  return npmInstall(cacheNMPath).then(() => {
1671
1697
  const newShellJsOption = { ...shellJsOption,
1672
1698
  cwd: cacheNMPath
1673
1699
  };
1674
- shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
1675
- shell.exec('rm -rf ./node_modules', newShellJsOption);
1700
+ shell.exec('tar -cvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
1701
+ shell.rm('-rf', './node_modules');
1676
1702
  });
1677
1703
  };
1678
1704
  }
@@ -1695,6 +1721,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1695
1721
 
1696
1722
 
1697
1723
  const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1724
+ const cwd = process.cwd();
1698
1725
  const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
1699
1726
 
1700
1727
  const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir); // 开始执行npm install和回调(移动)的任务
@@ -1716,6 +1743,7 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1716
1743
  }));
1717
1744
  });
1718
1745
  await Promise.all(arrPromises);
1746
+ shell.cd(cwd);
1719
1747
  };
1720
1748
  /**
1721
1749
  * 递归查找指定条件的文件
@@ -1751,7 +1779,7 @@ const findFilesByFilter = (startPath, filter) => {
1751
1779
 
1752
1780
  const files = fs$6.readdirSync(startPath);
1753
1781
  files.forEach(file => {
1754
- const filename = path$4.join(startPath, file);
1782
+ const filename = path$5.join(startPath, file);
1755
1783
  const stat = fs$6.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1756
1784
 
1757
1785
  if (stat.isDirectory()) {
@@ -1778,7 +1806,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1778
1806
  const packageJsonName = 'package.json'; // 查找文件名
1779
1807
 
1780
1808
  const cwd = contextDir || dirPath;
1781
- const result = [path$4.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1809
+ const result = [path$5.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1782
1810
 
1783
1811
  subRoots.forEach(subRoot => {
1784
1812
  if (!subRoot.root) {
@@ -1786,7 +1814,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1786
1814
  process.exit(1);
1787
1815
  }
1788
1816
 
1789
- const toppath = path$4.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1817
+ const toppath = path$5.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1790
1818
 
1791
1819
  const list = findFilesByFilter(toppath, packageJsonName);
1792
1820
  result.push(...list);
@@ -1802,7 +1830,7 @@ function cloudNpmInstall$1(contextDir) {
1802
1830
  }
1803
1831
 
1804
1832
  files.forEach(file => {
1805
- const dir = path$4.dirname(file);
1833
+ const dir = path$5.dirname(file);
1806
1834
  shell.cd(dir);
1807
1835
  shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
1808
1836
  silent: false
@@ -1821,7 +1849,7 @@ var npm = {
1821
1849
 
1822
1850
  const {
1823
1851
  createTask: createTask$1,
1824
- resolve: resolve$8
1852
+ resolve: resolve$9
1825
1853
  } = widgets;
1826
1854
  const {
1827
1855
  buildMpNpm
@@ -1834,21 +1862,21 @@ const {
1834
1862
  mpNpmInstallAll
1835
1863
  } = npm;
1836
1864
  const {
1837
- global: global$2
1865
+ global: global$3
1838
1866
  } = global_1;
1839
1867
 
1840
1868
  async function install$2(tmsConfig, modules, isCloud = false) {
1841
1869
  // 小程序npm install
1842
- await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
1843
- const tmsPrivateCf = global$2.getData('tmsPrivateCf'); // 构建miniprogram_npm
1870
+ await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
1871
+ const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
1844
1872
 
1845
1873
  await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
1846
1874
  appId: tmsConfig.appId,
1847
- projectPath: resolve$8('./'),
1875
+ projectPath: resolve$9('./'),
1848
1876
  privateKey: tmsPrivateCf.privateKey
1849
1877
  }); // 安装云函数的
1850
1878
 
1851
- isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$8(tmsConfig.cloudDir));
1879
+ isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$9(tmsConfig.cloudDir));
1852
1880
  }
1853
1881
 
1854
1882
  var install_1 = install$2;
@@ -1857,7 +1885,7 @@ const shelljs$3 = require$$0__default$3;
1857
1885
  const fs$5 = require$$0__default$2;
1858
1886
  const io = io$2;
1859
1887
  const {
1860
- resolve: resolve$7,
1888
+ resolve: resolve$8,
1861
1889
  createTask
1862
1890
  } = widgets;
1863
1891
  const {
@@ -1879,7 +1907,7 @@ const {
1879
1907
  } = tmsMpconfig;
1880
1908
  const {
1881
1909
  fail: fail$3,
1882
- info: info$3
1910
+ info: info$4
1883
1911
  } = log$1;
1884
1912
  const install$1 = install_1;
1885
1913
  /**
@@ -1891,31 +1919,31 @@ const install$1 = install_1;
1891
1919
  */
1892
1920
 
1893
1921
  const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1894
- const outputDir = resolve$7(tmsConfig.outputDir);
1922
+ const outputDir = resolve$8(tmsConfig.outputDir);
1895
1923
  io.ensureDirExist(outputDir);
1896
1924
  defaultFiles.forEach(item => {
1897
- if (fs$5.existsSync(resolve$7(item))) {
1898
- shelljs$3.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
1925
+ if (fs$5.existsSync(resolve$8(item))) {
1926
+ shelljs$3.cp('-rf', resolve$8(item), resolve$8(tmsConfig.outputDir, item));
1899
1927
  }
1900
1928
  }); // 拷贝模块的package.json到编译输出目录
1901
1929
 
1902
1930
  targetModules.forEach(item => {
1903
- const outputModuleDir = resolve$7(`${tmsConfig.outputDir}/${item.root}`);
1931
+ const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
1904
1932
 
1905
- if (!fs$5.existsSync(resolve$7(item.path))) {
1933
+ if (!fs$5.existsSync(resolve$8(item.path))) {
1906
1934
  fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1907
1935
  process.exit(1);
1908
1936
  }
1909
1937
 
1910
1938
  io.ensureDirExist(outputModuleDir);
1911
- const modulePackagePath = resolve$7(item.path, 'package.json');
1939
+ const modulePackagePath = resolve$8(item.path, 'package.json');
1912
1940
  if (fs$5.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
1913
1941
  });
1914
1942
  };
1915
1943
 
1916
1944
  async function task(tmsConfig, targetModules) {
1917
1945
  // 下载和移动代码
1918
- await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$7('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1946
+ await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$8('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1919
1947
 
1920
1948
  let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
1921
1949
 
@@ -1939,7 +1967,7 @@ async function init$5(tmsConfig, targetModules) {
1939
1967
  } catch (error) {
1940
1968
  const errMsg = typeof error === 'object' ? error.message : error;
1941
1969
  fail$3(`init流程出现错误${errMsg}`);
1942
- info$3('详细的错误信息', error);
1970
+ info$4('详细的错误信息', error);
1943
1971
  process.exit(1);
1944
1972
  }
1945
1973
  }
@@ -2004,8 +2032,8 @@ var pluginError_1 = {
2004
2032
 
2005
2033
  /* eslint-disable no-param-reassign */
2006
2034
  const through$2 = require$$0__default$9;
2007
- const precinct = require$$1__default$5;
2008
- const path$3 = require$$3__default;
2035
+ const precinct = require$$1__default$7;
2036
+ const path$4 = require$$1__default$2;
2009
2037
  const {
2010
2038
  findCssImports
2011
2039
  } = findCssImport;
@@ -2015,7 +2043,7 @@ const {
2015
2043
  diffContentCopyFile: diffContentCopyFile$2
2016
2044
  } = io$2;
2017
2045
  const {
2018
- resolve: resolve$6
2046
+ resolve: resolve$7
2019
2047
  } = widgets;
2020
2048
  const fs$4 = require$$0__default$2;
2021
2049
  const {
@@ -2035,11 +2063,11 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2035
2063
  pluginError$2(e, isWatch);
2036
2064
  }
2037
2065
 
2038
- const deps = cssFilter.indexOf(path$3.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
2066
+ const deps = cssFilter.indexOf(path$4.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
2039
2067
  deps.forEach(depItem => {
2040
2068
  if (depItem.startsWith('.')) {
2041
2069
  // 被依赖文件的存在的绝对路径
2042
- const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2070
+ const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2043
2071
 
2044
2072
  const {
2045
2073
  ext: extAlias,
@@ -2052,7 +2080,7 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2052
2080
  return;
2053
2081
  }
2054
2082
 
2055
- const depDestPath = resolve$6(path$3.dirname(anaFileDestFile), depItem);
2083
+ const depDestPath = resolve$7(path$4.dirname(anaFileDestFile), depItem);
2056
2084
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2057
2085
 
2058
2086
  if (!resDep.has(depDestFile)) {
@@ -2076,19 +2104,19 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2076
2104
  const stream = through$2.obj(function (file, enc, cb) {
2077
2105
  // 依赖分析的文件
2078
2106
  const anaFileOriginFile = file.history[0];
2079
- const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
2080
- const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2107
+ const anaFileRelativeModule = path$4.relative(resolve$7(module.from), anaFileOriginFile);
2108
+ const anaFileDestFile = resolve$7(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2081
2109
 
2082
2110
  if (file.isBuffer()) {
2083
2111
  let contents = String(file.contents);
2084
- const deps = cssFilter.indexOf(path$3.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
2112
+ const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
2085
2113
  const copyModules = new Map();
2086
2114
  Object.keys(tmsConfig.dependencies).forEach(includeName => {
2087
2115
  const includePath = tmsConfig.dependencies[includeName];
2088
2116
  deps.forEach(depItem => {
2089
2117
  if (depItem.indexOf(includeName) > -1) {
2090
2118
  // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
2091
- const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2119
+ const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2092
2120
 
2093
2121
  const {
2094
2122
  ext: extAlias,
@@ -2106,7 +2134,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2106
2134
  const regRes = depItem.match(reg) || [];
2107
2135
 
2108
2136
  if (regRes[2]) {
2109
- const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2137
+ const depDestPath = resolve$7(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2110
2138
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2111
2139
 
2112
2140
  if (!copyModules.has(depDestFile)) {
@@ -2114,7 +2142,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2114
2142
  depOriginFile,
2115
2143
  depDestFile,
2116
2144
  beforeDepPath: depItem,
2117
- afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2145
+ afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2118
2146
  });
2119
2147
  }
2120
2148
  }
@@ -2152,14 +2180,14 @@ var mpCommonDep_1 = {
2152
2180
 
2153
2181
  /* eslint-disable no-param-reassign */
2154
2182
  const through$1 = require$$0__default$9;
2155
- const path$2 = require$$3__default;
2183
+ const path$3 = require$$1__default$2;
2156
2184
  const {
2157
2185
  ext: ext$1,
2158
2186
  fileInDir: fileInDir$1,
2159
2187
  diffContentCopyFile: diffContentCopyFile$1
2160
2188
  } = io$2;
2161
2189
  const {
2162
- resolve: resolve$5
2190
+ resolve: resolve$6
2163
2191
  } = widgets;
2164
2192
  const fs$3 = require$$0__default$2;
2165
2193
  const {
@@ -2173,8 +2201,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2173
2201
  const stream = through$1.obj(function (file, enc, cb) {
2174
2202
  // 当前分析的文件的路径
2175
2203
  const anaFileOriginFile = file.history[0];
2176
- const anaFileRelativeModule = path$2.relative(resolve$5(module.from), anaFileOriginFile);
2177
- const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2204
+ const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
2205
+ const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2178
2206
 
2179
2207
  if (file.isBuffer()) {
2180
2208
  let contents = String(file.contents);
@@ -2194,7 +2222,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2194
2222
  const componentPath = contents.usingComponents[componentKey];
2195
2223
 
2196
2224
  if (componentPath.indexOf(includeName) > -1) {
2197
- const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
2225
+ const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
2198
2226
 
2199
2227
  const {
2200
2228
  ext: extAlias,
@@ -2213,7 +2241,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2213
2241
  const regRes = componentPath.match(reg) || [];
2214
2242
 
2215
2243
  if (regRes[2]) {
2216
- const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2244
+ const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2217
2245
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2218
2246
 
2219
2247
  if (!copyModules.has(depDestFile)) {
@@ -2222,7 +2250,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2222
2250
  depOriginExt: extAlias,
2223
2251
  depDestFile,
2224
2252
  beforeDepPath: componentPath,
2225
- afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2253
+ afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2226
2254
  });
2227
2255
  }
2228
2256
  }
@@ -2280,16 +2308,16 @@ var mpJsonDep_1 = {
2280
2308
 
2281
2309
  /* eslint-disable no-param-reassign */
2282
2310
  const through = require$$0__default$9;
2283
- const htmlparser2 = require$$1__default$6;
2311
+ const htmlparser2 = require$$1__default$8;
2284
2312
  const fs$2 = require$$0__default$2;
2285
- const path$1 = require$$3__default;
2313
+ const path$2 = require$$1__default$2;
2286
2314
  const {
2287
2315
  diffContentCopyFile,
2288
2316
  ext,
2289
2317
  fileInDir
2290
2318
  } = io$2;
2291
2319
  const {
2292
- resolve: resolve$4
2320
+ resolve: resolve$5
2293
2321
  } = widgets;
2294
2322
  const {
2295
2323
  dfsFindCommonDep
@@ -2338,7 +2366,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2338
2366
  var _attributes$src;
2339
2367
 
2340
2368
  if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
2341
- const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2369
+ const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2342
2370
 
2343
2371
  const {
2344
2372
  ext,
@@ -2351,7 +2379,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2351
2379
  return;
2352
2380
  }
2353
2381
 
2354
- const depDestPath = path$1.join(path$1.dirname(anaFileDestFile), attributes.src);
2382
+ const depDestPath = path$2.join(path$2.dirname(anaFileDestFile), attributes.src);
2355
2383
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
2356
2384
 
2357
2385
  if (['import', 'include'].indexOf(name) > -1) {
@@ -2403,8 +2431,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2403
2431
  const stream = through.obj(function (file, enc, cb) {
2404
2432
  // 依赖分析的文件
2405
2433
  const anaFileOriginFile = file.history[0];
2406
- const anaFileRelativeModule = path$1.relative(resolve$4(module.from), anaFileOriginFile);
2407
- const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2434
+ const anaFileRelativeModule = path$2.relative(resolve$5(module.from), anaFileOriginFile);
2435
+ const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2408
2436
 
2409
2437
  if (file.isBuffer()) {
2410
2438
  let contents = String(file.contents);
@@ -2414,7 +2442,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2414
2442
  const nameFilter = ['import', 'include', 'wxs'];
2415
2443
 
2416
2444
  if (nameFilter.indexOf(name) > -1 && attributes.src) {
2417
- const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2445
+ const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2418
2446
 
2419
2447
  const {
2420
2448
  ext,
@@ -2435,7 +2463,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2435
2463
  const regRes = attributes.src.match(reg) || [];
2436
2464
 
2437
2465
  if (regRes[2]) {
2438
- const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2466
+ const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2439
2467
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
2440
2468
 
2441
2469
  if (!copyModules.has(depDestFile)) {
@@ -2443,7 +2471,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2443
2471
  depOriginFile,
2444
2472
  depDestFile,
2445
2473
  beforeDepPath: attributes.src,
2446
- afterDepPath: path$1.relative(path$1.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2474
+ afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2447
2475
  });
2448
2476
  }
2449
2477
  }
@@ -2500,11 +2528,9 @@ var mpWxmlDep_1 = {
2500
2528
 
2501
2529
  const {
2502
2530
  src: src$1,
2503
- dest,
2504
- lastRun
2505
- } = require$$0__default$a;
2506
- const px2rpx = require$$1__default$7;
2507
- const watch = require$$2__default$1; // const cache = require('gulp-cache');
2531
+ dest
2532
+ } = require$$0__default$a; // const px2rpx = require('gulp-px-to-rpx');
2533
+ // const cache = require('gulp-cache');
2508
2534
  // const image = require('gulp-image');
2509
2535
  // const replaceEnv = require('./plugins/replaceEnv');
2510
2536
 
@@ -2521,87 +2547,168 @@ const {
2521
2547
 
2522
2548
  const {
2523
2549
  fail: fail$1
2524
- } = log$1;
2525
-
2526
- const since = task => file => lastRun(task) > file.stat.ctime ? lastRun(task) : 0;
2550
+ } = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
2527
2551
 
2528
2552
  var compile = function (tmsConfig, {
2529
2553
  glob,
2530
2554
  destPath,
2531
2555
  srcOption,
2532
2556
  module,
2533
- watchOption = {
2534
- events: ['change', 'add', 'unlink']
2535
- },
2536
2557
  isWatch
2537
2558
  }) {
2559
+ const compileTasksMap = new Map();
2538
2560
  Object.keys(glob).forEach(globKey => {
2539
2561
  const globValue = glob[globKey];
2540
2562
 
2541
- const task = () => src$1(globValue, { ...srcOption,
2542
- since: since(task)
2543
- });
2544
-
2545
- let srcPipe = task();
2546
-
2547
- if (isWatch) {
2548
- srcPipe = srcPipe.pipe(watch(globValue, watchOption));
2549
- }
2550
-
2551
2563
  switch (globKey) {
2552
2564
  case 'js':
2553
- srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
2554
- .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch)).pipe(dest(destPath)).on('error', err => {
2555
- fail$1(`js编译报错${err}`);
2565
+ compileTasksMap.set(globValue, {
2566
+ module,
2567
+ taskFn: () => {
2568
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2569
+ // const srcPipe = srcTask();
2570
+ const srcPipe = src$1(globValue, { ...srcOption
2571
+ });
2572
+ return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
2573
+ .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch)).pipe(dest(destPath)).on('error', err => {
2574
+ fail$1(`js编译报错${err}`);
2575
+ });
2576
+ }
2556
2577
  });
2557
2578
  break;
2558
2579
 
2559
2580
  case 'wxss':
2560
- srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).on('error', err => {
2561
- fail$1(`mpCommonDep编译报错${err}`);
2562
- }) // .pipe(postcss([base64()]))
2563
- // .on('error', (err) => {
2564
- // fail(`postcss编译报错${err}`);
2565
- // })
2566
- .pipe(px2rpx({
2567
- designWidth: 375,
2568
- // 设计稿宽度,默认为750
2569
- precision: 2 // 小数最大精度,默认为6
2570
-
2571
- })).pipe(dest(destPath));
2581
+ compileTasksMap.set(globValue, {
2582
+ module,
2583
+ taskFn: () => {
2584
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2585
+ // const srcPipe = srcTask();
2586
+ const srcPipe = src$1(globValue, { ...srcOption
2587
+ });
2588
+ return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).on('error', err => {
2589
+ fail$1(`mpCommonDep编译报错${err}`);
2590
+ }) // .pipe(postcss([base64()]))
2591
+ // .on('error', (err) => {
2592
+ // fail(`postcss编译报错${err}`);
2593
+ // })
2594
+ // .pipe(px2rpx({
2595
+ // designWidth: 375, // 设计稿宽度,默认为750
2596
+ // precision: 2, // 小数最大精度,默认为6
2597
+ // }))
2598
+ .pipe(dest(destPath));
2599
+ }
2600
+ });
2572
2601
  break;
2573
2602
 
2574
2603
  case 'json':
2575
- srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
2576
- fail$1(`mpJsonDep编译报错${err}`);
2577
- }).pipe(dest(destPath));
2604
+ compileTasksMap.set(globValue, {
2605
+ module,
2606
+ taskFn: () => {
2607
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2608
+ // const srcPipe = srcTask();
2609
+ const srcPipe = src$1(globValue, { ...srcOption
2610
+ });
2611
+ return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
2612
+ fail$1(`mpJsonDep编译报错${err}`);
2613
+ }).pipe(dest(destPath));
2614
+ }
2615
+ });
2578
2616
  break;
2579
2617
 
2580
2618
  case 'wxml':
2581
- srcPipe.pipe(mpWxmlDep(tmsConfig, module, isWatch)).pipe(dest(destPath));
2619
+ compileTasksMap.set(globValue, {
2620
+ module,
2621
+ taskFn: () => {
2622
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2623
+ // const srcPipe = srcTask();
2624
+ const srcPipe = src$1(globValue, { ...srcOption
2625
+ });
2626
+ return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isWatch)).pipe(dest(destPath));
2627
+ }
2628
+ });
2582
2629
  break;
2583
2630
 
2584
2631
  case 'image':
2585
- srcPipe // .pipe(cache(image()))
2586
- // .on('error', (err) => {
2587
- // fail(`image编译报错${err}`);
2588
- // })
2589
- .pipe(dest(destPath));
2632
+ compileTasksMap.set(globValue, {
2633
+ module,
2634
+ taskFn: () => {
2635
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2636
+ // const srcPipe = srcTask();
2637
+ const srcPipe = src$1(globValue, { ...srcOption
2638
+ });
2639
+ return srcPipe // .pipe(cache(image()))
2640
+ // .on('error', (err) => {
2641
+ // fail(`image编译报错${err}`);
2642
+ // })
2643
+ .pipe(dest(destPath));
2644
+ }
2645
+ });
2590
2646
  break;
2591
2647
 
2592
2648
  case 'other':
2593
- srcPipe.pipe(dest(destPath));
2649
+ compileTasksMap.set(globValue, {
2650
+ module,
2651
+ taskFn: () => {
2652
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2653
+ // const srcPipe = srcTask();
2654
+ const srcPipe = src$1(globValue, { ...srcOption
2655
+ });
2656
+ return srcPipe.pipe(dest(destPath));
2657
+ }
2658
+ });
2594
2659
  break;
2595
2660
  }
2596
2661
  });
2662
+ return compileTasksMap;
2663
+ };
2664
+
2665
+ const watch = require$$0__default$b;
2666
+ const path$1 = require$$1__default$2;
2667
+ const shellJs = require$$0__default$3;
2668
+ const {
2669
+ info: info$3
2670
+ } = log$1;
2671
+ const {
2672
+ resolve: resolve$4
2673
+ } = widgets;
2674
+ const {
2675
+ global: global$2
2676
+ } = global_1;
2677
+
2678
+ var watch_1 = function (glob, watchOptions, callback, module) {
2679
+ watch(glob, {
2680
+ readDelay: 100,
2681
+ ...watchOptions
2682
+ }, vinyl => {
2683
+ const file = vinyl.history[0];
2684
+ const fileDirArr = file.replace(/\\/g, '/').split('/');
2685
+ const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
2686
+
2687
+ if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
2688
+ const tmsConfig = global$2.getData('tmsConfig');
2689
+ const anaFileRelativeModule = path$1.relative(resolve$4(module.from), file);
2690
+ const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2691
+ info$3(`删除${fileName}`);
2692
+ shellJs.rm('-rf', anaFileDestFile);
2693
+ return;
2694
+ }
2695
+
2696
+ info$3(`更新${fileName}`);
2697
+ return callback(vinyl);
2698
+ });
2597
2699
  };
2598
2700
 
2599
2701
  (function (module) {
2600
- const path = require$$3__default;
2702
+ const path = require$$1__default$2;
2601
2703
  const fs = require$$0__default$2;
2602
- const watch = require$$2__default$1;
2704
+ const ora = require$$2__default;
2603
2705
  const {
2604
- resolve
2706
+ parallel,
2707
+ series
2708
+ } = require$$0__default$a;
2709
+ const {
2710
+ resolve,
2711
+ mergeMap
2605
2712
  } = widgets;
2606
2713
  const {
2607
2714
  buildOutputAppJson
@@ -2610,6 +2717,11 @@ var compile = function (tmsConfig, {
2610
2717
  DEFAULT_COPY_CONFIG
2611
2718
  } = require$$4;
2612
2719
  const compile$1 = compile;
2720
+ const watch = watch_1;
2721
+ const {
2722
+ info
2723
+ } = log$1;
2724
+ const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
2613
2725
 
2614
2726
  function excludeGlob(glob) {
2615
2727
  const otherArr = new Set();
@@ -2640,20 +2752,19 @@ var compile = function (tmsConfig, {
2640
2752
  }
2641
2753
 
2642
2754
  module.exports = async (tmsConfig, newModules, isWatch = true) => {
2643
- // 监听app.json
2755
+ const compileTasksMap = new Map(); // 监听app.json
2756
+
2644
2757
  if (isWatch) {
2645
- watch(resolve('app.json'), {
2758
+ watch([resolve('app.json')], {
2646
2759
  ignoreInitial: false,
2647
- events: ['add', 'change']
2648
- }, () => {
2649
- buildOutputAppJson(tmsConfig, newModules, isWatch);
2650
- });
2760
+ events: watchEvents
2761
+ }, () => buildOutputAppJson(tmsConfig, newModules, isWatch));
2651
2762
  } else {
2652
2763
  buildOutputAppJson(tmsConfig, newModules, isWatch);
2653
2764
  } // 监听根目录的文件
2654
2765
 
2655
2766
 
2656
- compile$1(tmsConfig, {
2767
+ mergeMap(compileTasksMap, compile$1(tmsConfig, {
2657
2768
  glob: {
2658
2769
  json: DEFAULT_COPY_CONFIG.map(item => resolve(item)) // wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
2659
2770
  // js: ['app.js', 'app.ts'].map(item => resolve(item)),
@@ -2668,7 +2779,7 @@ var compile = function (tmsConfig, {
2668
2779
  allowEmpty: true
2669
2780
  },
2670
2781
  isWatch
2671
- }); // 监听模块的文件
2782
+ })); // 监听模块的文件
2672
2783
 
2673
2784
  for (let module of newModules) {
2674
2785
  // 处理默认参数
@@ -2680,23 +2791,21 @@ var compile = function (tmsConfig, {
2680
2791
 
2681
2792
  if (isWatch) {
2682
2793
  // 监听模块配置文件
2683
- watch(`${resolve(module.path)}/**/module.config.json`, {
2684
- events: ['change']
2685
- }, () => {
2686
- buildOutputAppJson(tmsConfig, newModules, isWatch);
2687
- });
2794
+ watch([`${resolve(module.path)}/**/module.config.json`], {
2795
+ events: watchEvents
2796
+ }, () => buildOutputAppJson(tmsConfig, newModules, isWatch));
2688
2797
  }
2689
2798
 
2690
2799
  const excludes = module.exclude.map(key => `!${resolve(key)}`);
2691
2800
  const modulePath = adaptPath(module.path);
2692
2801
  const glob = {
2693
2802
  js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
2694
- json: [`${modulePath}/**/*.json`, ...excludes],
2803
+ json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
2695
2804
  wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
2696
2805
  wxml: [`${modulePath}/**/*.wxml`, ...excludes],
2697
2806
  image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
2698
2807
  };
2699
- compile$1(tmsConfig, {
2808
+ mergeMap(compileTasksMap, compile$1(tmsConfig, {
2700
2809
  glob: { ...glob,
2701
2810
  other: [`${modulePath}/**/*`, ...excludeGlob(glob)]
2702
2811
  },
@@ -2709,7 +2818,7 @@ var compile = function (tmsConfig, {
2709
2818
  allowEmpty: true
2710
2819
  },
2711
2820
  isWatch
2712
- });
2821
+ }));
2713
2822
  } // 静态资源目录-拷贝
2714
2823
 
2715
2824
 
@@ -2734,7 +2843,7 @@ var compile = function (tmsConfig, {
2734
2843
  }
2735
2844
 
2736
2845
  const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
2737
- compile$1(tmsConfig, {
2846
+ mergeMap(compileTasksMap, compile$1(tmsConfig, {
2738
2847
  glob,
2739
2848
  destPath: item.to,
2740
2849
  module: {
@@ -2745,18 +2854,56 @@ var compile = function (tmsConfig, {
2745
2854
  allowEmpty: true
2746
2855
  },
2747
2856
  isWatch
2857
+ }));
2858
+ }
2859
+ }
2860
+
2861
+ let sTime;
2862
+ let eTime;
2863
+ const spinner = ora();
2864
+
2865
+ function end(cb) {
2866
+ if (isWatch) {
2867
+ compileTasksMap.forEach(({
2868
+ taskFn,
2869
+ module
2870
+ }, globValue) => {
2871
+ watch(globValue, {
2872
+ ignoreInitial: true,
2873
+ events: watchEvents
2874
+ }, taskFn, module);
2748
2875
  });
2749
2876
  }
2877
+
2878
+ eTime = new Date().getTime() - sTime;
2879
+ spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即刻预览。`);
2880
+ spinner.stop();
2881
+ cb();
2750
2882
  }
2883
+
2884
+ function start(cb) {
2885
+ info('启动编译...');
2886
+ spinner.start();
2887
+ sTime = new Date().getTime();
2888
+ cb();
2889
+ }
2890
+
2891
+ const compileTasks = [];
2892
+ compileTasksMap.forEach(({
2893
+ taskFn
2894
+ }) => {
2895
+ compileTasks.push(taskFn);
2896
+ });
2897
+ series(start, parallel(...compileTasks), end)();
2751
2898
  };
2752
2899
  })(dev$3);
2753
2900
 
2754
2901
  const fs$1 = require$$0__default$2;
2755
- const semver$1 = require$$1__default$8;
2902
+ const semver$1 = require$$1__default$9;
2756
2903
  const {
2757
2904
  resolve: resolve$3
2758
2905
  } = widgets;
2759
- const path = require$$3__default;
2906
+ const path = require$$1__default$2;
2760
2907
  const shelljs$2 = require$$0__default$3;
2761
2908
  const {
2762
2909
  handleError
@@ -2848,7 +2995,6 @@ const {
2848
2995
  resolve: resolve$2
2849
2996
  } = widgets;
2850
2997
  const {
2851
- MODULE_CONFIG_FILENAME,
2852
2998
  MODULE_CODE_DIR
2853
2999
  } = require$$4;
2854
3000
  const {
@@ -2861,17 +3007,12 @@ const {
2861
3007
  fail
2862
3008
  } = log$1;
2863
3009
 
2864
- function checkModule(targetModules, contextDir) {
3010
+ function checkModule(targetModules) {
2865
3011
  // 判断\源码\dist\是否存在用户指定的模块
2866
3012
  for (const item of targetModules) {
2867
3013
  // 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
2868
3014
  if (!item.root) {
2869
3015
  return true;
2870
- } // 判断dist目录是否有该模块
2871
-
2872
-
2873
- if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
2874
- return true;
2875
3016
  } // 判断第三方远程模块git地址与branch是否有更新
2876
3017
 
2877
3018
 
@@ -2911,7 +3052,7 @@ function isInit$1(tmsConfig, targetModules, contextDir) {
2911
3052
  } // 判断模块信息
2912
3053
 
2913
3054
 
2914
- if (checkModule(targetModules, contextDir)) {
3055
+ if (checkModule(targetModules)) {
2915
3056
  return true;
2916
3057
  } // 判断package.json的版本是否有新的版本
2917
3058
 
@@ -3066,7 +3207,7 @@ async function run(commandName, cmd) {
3066
3207
  const tmsConfig = readTmsConfig(env); // 处理module参数
3067
3208
 
3068
3209
  const specificModules = getSpecificModules(handleModuleArg(cmd), tmsPrivateCf.modules, tmsConfig.modules);
3069
- const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])]); // tms.config.js的modules 合并 module.config.json的配置项
3210
+ const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])], true); // tms.config.js的modules 合并 module.config.json的配置项
3070
3211
 
3071
3212
  let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
3072
3213
 
@@ -3075,7 +3216,8 @@ async function run(commandName, cmd) {
3075
3216
  global.setData({
3076
3217
  env,
3077
3218
  cmd,
3078
- tmsPrivateCf
3219
+ tmsPrivateCf,
3220
+ tmsConfig
3079
3221
  });
3080
3222
 
3081
3223
  switch (commandName) {
@@ -3152,7 +3294,7 @@ var entry = [{
3152
3294
 
3153
3295
  var require$$7 = {
3154
3296
  name: "@tmsfe/tmskit",
3155
- version: "0.0.10",
3297
+ version: "0.0.13",
3156
3298
  description: "tmskit",
3157
3299
  main: "dist/index.cjs",
3158
3300
  bin: {
@@ -3195,9 +3337,6 @@ var require$$7 = {
3195
3337
  "fs-extra": "^10.0.1",
3196
3338
  "glob-ignore": "^1.0.2",
3197
3339
  gulp: "^4.0.2",
3198
- "gulp-cache": "^1.1.3",
3199
- "gulp-postcss": "^9.0.1",
3200
- "gulp-px-to-rpx": "^1.0.7",
3201
3340
  "gulp-watch": "^5.0.1",
3202
3341
  htmlparser2: "^7.2.0",
3203
3342
  inquirer: "^7.3.3",
@@ -3205,6 +3344,7 @@ var require$$7 = {
3205
3344
  lodash: "^4.17.21",
3206
3345
  metalsmith: "^2.3.0",
3207
3346
  "miniprogram-ci": "1.4.13",
3347
+ moment: "^2.29.1",
3208
3348
  "object-assign": "^4.0.1",
3209
3349
  ora: "^5.1.0",
3210
3350
  "plugin-error": "^1.0.0",
@@ -3224,7 +3364,7 @@ var require$$7 = {
3224
3364
  }
3225
3365
  };
3226
3366
 
3227
- const semver = require$$1__default$8;
3367
+ const semver = require$$1__default$9;
3228
3368
  const packageJson = require$$7;
3229
3369
  const chalk$1 = require$$0__default;
3230
3370
  const {
@@ -3300,15 +3440,12 @@ function registerCommand(program, commands) {
3300
3440
 
3301
3441
  registerCommand(program, commands);
3302
3442
  program.on('--help', () => {
3303
- info();
3304
3443
  info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
3305
- info();
3306
3444
  }); // 捕获未注册的命令
3307
3445
 
3308
3446
  program.arguments('<command>').action(cmd => {
3309
3447
  program.outputHelp();
3310
- info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
3311
- info();
3448
+ info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
3312
3449
  suggestCommands(cmd);
3313
3450
  process.exitCode = 1;
3314
3451
  });