@tmsfe/tmskit 0.0.20 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -9,13 +9,13 @@ var require$$1$2 = require('path');
9
9
  var require$$0$2 = require('fs');
10
10
  var require$$0$3 = require('shelljs');
11
11
  var require$$6 = require('glob-ignore');
12
- var require$$0$4 = require('async');
12
+ var require$$0$4 = require('lodash');
13
+ var require$$0$5 = require('async');
13
14
  var require$$1$3 = require('ejs');
14
15
  var require$$1$4 = require('inquirer');
15
- var require$$0$5 = require('metalsmith');
16
- var require$$9 = require('request');
16
+ var require$$0$6 = require('metalsmith');
17
+ var require$$9$1 = require('request');
17
18
  var require$$10 = require('unzipper');
18
- var require$$0$6 = require('lodash');
19
19
  var require$$1$5 = require('crypto');
20
20
  var require$$0$7 = require('miniprogram-ci');
21
21
  var require$$1$6 = require('fs-extra');
@@ -27,12 +27,12 @@ var require$$1$9 = require('htmlparser2');
27
27
  var require$$0$a = require('gulp');
28
28
  var require$$0$b = require('object-assign');
29
29
  var require$$3 = require('fancy-log');
30
- var require$$4$1 = require('ansi-colors');
31
- var require$$5 = require('chokidar');
30
+ var require$$4 = require('ansi-colors');
31
+ var require$$5$1 = require('chokidar');
32
32
  var require$$6$1 = require('readable-stream');
33
- var require$$7$1 = require('vinyl-file');
33
+ var require$$7 = require('vinyl-file');
34
34
  var require$$8 = require('vinyl');
35
- var require$$9$1 = require('anymatch');
35
+ var require$$9$2 = require('anymatch');
36
36
  var require$$11 = require('glob-parent');
37
37
  var require$$2$1 = require('plugin-error');
38
38
  var require$$10$1 = require('path-is-absolute');
@@ -50,12 +50,12 @@ var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
50
50
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
51
51
  var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
52
52
  var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
53
+ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
53
54
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
54
55
  var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
55
- var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
56
- var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
57
- var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
58
56
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
57
+ var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9$1);
58
+ var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
59
59
  var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
60
60
  var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
61
61
  var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
@@ -67,12 +67,12 @@ var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
67
67
  var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
68
68
  var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
69
69
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
70
- var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
71
- var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
70
+ var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
71
+ var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
72
72
  var require$$6__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
73
- var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7$1);
73
+ var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
74
74
  var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
75
- var require$$9__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$9$1);
75
+ var require$$9__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$9$2);
76
76
  var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
77
77
  var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
78
78
  var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
@@ -109,7 +109,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
109
109
  * @returns {undefined} 无
110
110
  */
111
111
 
112
- const fail$a = (message = '') => {
112
+ const fail$9 = (message = '') => {
113
113
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
114
114
 
115
115
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
@@ -144,7 +144,7 @@ const warn$2 = message => {
144
144
  const info$d = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
145
145
 
146
146
  var log$1 = {
147
- fail: fail$a,
147
+ fail: fail$9,
148
148
  succeed: succeed$2,
149
149
  warn: warn$2,
150
150
  info: info$d
@@ -154,7 +154,7 @@ const program$1 = require$$0__default$1;
154
154
  const leven = require$$1__default$1;
155
155
  const ora$1 = require$$2__default;
156
156
  const path$e = require$$1__default$2;
157
- const fs$g = require$$0__default$2;
157
+ const fs$h = require$$0__default$2;
158
158
  const shelljs$7 = require$$0__default$3;
159
159
  const glob$1 = require$$6__default;
160
160
  const {
@@ -168,7 +168,7 @@ const shelljsOptions = {
168
168
 
169
169
  const cwd = process.cwd();
170
170
 
171
- function resolve$f(...args) {
171
+ function resolve$g(...args) {
172
172
  return path$e.resolve(cwd, ...args);
173
173
  }
174
174
  /**
@@ -225,7 +225,7 @@ function downloadRepoForGit$1(url, dest, branch) {
225
225
  const cwd = process.cwd();
226
226
  return new Promise((resolve, reject) => {
227
227
  // 如果目标目录不存在
228
- if (fs$g.existsSync(dest)) {
228
+ if (fs$h.existsSync(dest)) {
229
229
  shelljs$7.rm('-rf', path$e.join(dest));
230
230
  }
231
231
 
@@ -371,10 +371,18 @@ function findFiles(globPath, filter = []) {
371
371
  resolve(files);
372
372
  });
373
373
  });
374
+ } // 获取绝对路径
375
+
376
+
377
+ function getAbsolutePath$3(pathDir, cwd = '') {
378
+ let newPath = pathDir;
379
+ newPath = newPath.startsWith('/') ? newPath : resolve$g(cwd, newPath);
380
+ newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
381
+ return newPath;
374
382
  }
375
383
 
376
384
  var widgets = {
377
- resolve: resolve$f,
385
+ resolve: resolve$g,
378
386
  isObject,
379
387
  isArray,
380
388
  createTask: createTask$2,
@@ -386,9 +394,12 @@ var widgets = {
386
394
  mergeMap: mergeMap$1,
387
395
  relativeCwdPath: relativeCwdPath$1,
388
396
  filterField: filterField$4,
389
- findFiles
397
+ findFiles,
398
+ getAbsolutePath: getAbsolutePath$3
390
399
  };
391
400
 
401
+ var tmsMpconfig = {exports: {}};
402
+
392
403
  const path$d = require('path');
393
404
 
394
405
  const os = require('os'); // 用户目录
@@ -464,9 +475,354 @@ var constant = /*#__PURE__*/Object.freeze({
464
475
  TEMPLATE_URL: TEMPLATE_URL$1
465
476
  });
466
477
 
467
- var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
478
+ var require$$5 = /*@__PURE__*/getAugmentedNamespace(constant);
468
479
 
469
- const fs$f = require$$0__default$2;
480
+ var defaultTmsConfig = {
481
+ // 全局的环境配置项
482
+ envData: {},
483
+ // 模块配置信息
484
+ modules: {},
485
+ cloudDir: 'cloud',
486
+ // 第三方依赖代码需要拷贝到本项目的
487
+ dependencies: {},
488
+
489
+ /** 编译输出文件夹位置 */
490
+ outputDir: 'dist',
491
+
492
+ /** 源码监听路径 */
493
+ sourceDir: './',
494
+
495
+ /** 静态资源目录 */
496
+ static: []
497
+ };
498
+
499
+ /**
500
+ * 用来读取处理tms.config.js与module.config.json字段
501
+ */
502
+
503
+ (function (module) {
504
+ /* eslint-disable no-param-reassign, no-nested-ternary */
505
+ const loadash = require$$0__default$4;
506
+ const fs = require$$0__default$2;
507
+ const path = require$$1__default$2;
508
+ const {
509
+ TMS_CONFIG_FILENAME,
510
+ MODULE_CONFIG_FILENAME,
511
+ TMS_PRIVATE_FILENAME
512
+ } = require$$5;
513
+ const {
514
+ resolve,
515
+ isObject,
516
+ isArray,
517
+ getAbsolutePath
518
+ } = widgets;
519
+ const defaultTmsConfig$1 = defaultTmsConfig;
520
+ const {
521
+ fail
522
+ } = log$1;
523
+ /**
524
+ * 读取tms.config.js
525
+ * @param env {string} 环境变量
526
+ */
527
+
528
+ const readTmsConfig = function () {
529
+ const tmsConfigPath = resolve(TMS_CONFIG_FILENAME);
530
+
531
+ if (!fs.existsSync(tmsConfigPath)) {
532
+ fail('当前执行目录没有tms.config.js的配置项,请进行配置');
533
+ process.exit(1);
534
+ }
535
+
536
+ const tmsConfigFn = require(tmsConfigPath);
537
+
538
+ const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn() : tmsConfigFn; // 合并默认值
539
+
540
+ return loadash.mergeWith(defaultTmsConfig$1, tmsConfig);
541
+ };
542
+ /**
543
+ * 读取tms.private.config.js
544
+ */
545
+
546
+
547
+ const readTmsPrivateCf = function () {
548
+ let tmsPrivateCf = {};
549
+ const tmsPrivatePath = resolve(TMS_PRIVATE_FILENAME);
550
+
551
+ if (fs.existsSync(tmsPrivatePath)) {
552
+ const tmsPrivateFn = require(tmsPrivatePath);
553
+
554
+ tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn() : tmsPrivateFn;
555
+ }
556
+
557
+ return tmsPrivateCf;
558
+ };
559
+ /**
560
+ * 获取tms.config.js, tms.private.config.js的配置项
561
+ * @returns
562
+ */
563
+
564
+
565
+ const getTmsConfig = () => {
566
+ const tmsPrivateCf = readTmsPrivateCf();
567
+ const tmsConfig = readTmsConfig();
568
+ const modules = {};
569
+
570
+ if (Array.isArray(tmsConfig.modules)) {
571
+ modules.all = tmsConfig.modules;
572
+ tmsConfig.modules = modules;
573
+ } // 合并默认值
574
+
575
+
576
+ const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
577
+ if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
578
+ return objValue.concat(srcValue);
579
+ }
580
+ });
581
+ return res;
582
+ };
583
+ /**
584
+ * 根据moduleNames获取modules
585
+ * @param { object } tmsConfig
586
+ * @param { array } moduleNames
587
+ * @param {boolean} errorIsQuit 找不到配置文件是否退出
588
+ * @returns
589
+ */
590
+
591
+
592
+ const getModulesByModuleNames = function (tmsConfig, moduleNames = []) {
593
+ const targetModules = [];
594
+ moduleNames.forEach(moduleName => {
595
+ const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
596
+
597
+ if (!module) {
598
+ throw new Error(`你启动的模块${moduleName}在tms.config.js的modules.all中没有注册`);
599
+ }
600
+
601
+ targetModules.push(module);
602
+ });
603
+ return targetModules;
604
+ };
605
+ /**
606
+ * 适配处理module.config.json的字段
607
+ * @param { object } fileContent module.config.json的内容
608
+ * @param { string } appName 小程序的名称
609
+ */
610
+
611
+
612
+ function adaptMpCgContent(fileContent, appName) {
613
+ const handleContent = function (appName, current) {
614
+ let res = current;
615
+
616
+ if (appName && current.mpConfig && current.mpConfig[appName]) {
617
+ res = { ...current,
618
+ ...current.mpConfig[appName]
619
+ };
620
+ }
621
+
622
+ delete res.mpConfig;
623
+ delete res.isSubpackages;
624
+ return res;
625
+ };
626
+
627
+ let content = fileContent;
628
+
629
+ if (isArray(content)) {
630
+ let i = content.length - 1;
631
+
632
+ while (i >= 0) {
633
+ content[i] = handleContent(appName, content[i]);
634
+ i--; // eslint-disable-line
635
+ }
636
+ } else {
637
+ content = handleContent(appName, content);
638
+ }
639
+
640
+ return content;
641
+ }
642
+
643
+ const adaptDependencies = function (dependencies, subPackages) {
644
+ const newDependencies = dependencies || [];
645
+ subPackages.forEach(item => {
646
+ if (item.dependencies) {
647
+ dependencies = newDependencies.concat(item.dependencies);
648
+ }
649
+ });
650
+ return newDependencies;
651
+ };
652
+
653
+ const adaptSubPackages = function (moduleConfig, appName) {
654
+ const subPackages = isObject(moduleConfig) && moduleConfig.subPackages ? moduleConfig.subPackages : isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
655
+ return adaptMpCgContent(subPackages, appName);
656
+ };
657
+ /**
658
+ * 获取模块module.config.json中的配置信息
659
+ * @param {array} modules 用户要编译的模块列表
660
+ * @param { string } appName 小程序的名称
661
+ */
662
+
663
+
664
+ function getModulesConfig(modules = [], appName) {
665
+ const modulesConfig = [];
666
+ modules.forEach(moduleItem => {
667
+ const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
668
+ let moduleConfig;
669
+
670
+ try {
671
+ moduleConfig = JSON.parse(fs.readFileSync(moduleConfigPath, 'utf-8'));
672
+ } catch (e) {
673
+ throw new Error(`${moduleConfigPath}json解析报错: ${e}`);
674
+ } // 兼容历史逻辑,后续可删除--- start
675
+
676
+
677
+ const subPackages = adaptSubPackages(moduleConfig, appName);
678
+ const dependencies = adaptDependencies(moduleConfig.dependencies, subPackages);
679
+ moduleConfig = { ...(isObject(moduleConfig) ? moduleConfig : {}),
680
+ subPackages,
681
+ dependencies
682
+ }; // 兼容逻辑--- end
683
+
684
+ modulesConfig.push(moduleConfig);
685
+ });
686
+ return modulesConfig;
687
+ }
688
+ /**
689
+ * 获取分包内容 (读取module.config.json的配置项)
690
+ * @param {array} modules
691
+ * @returns
692
+ */
693
+
694
+
695
+ const getSubPackages = modules => {
696
+ const newSubPackages = [];
697
+ modules.forEach(module => {
698
+ (module.subPackages || []).forEach(subPackage => {
699
+ newSubPackages.push({ ...subPackage
700
+ });
701
+ });
702
+ });
703
+ return newSubPackages;
704
+ };
705
+ /**
706
+ * 获取分包的root字段
707
+ * @param {*} modulePath 模块的编译路径
708
+ * @param {*} root 分包的root字段
709
+ * @returns
710
+ */
711
+
712
+
713
+ const getSubPackageRoot = function (modulePath, root) {
714
+ return root.startsWith(modulePath) ? root : `${modulePath}/${root}`;
715
+ }; // 获取分包的源码路径
716
+
717
+
718
+ const getSubPackageSrcPath = function (tmsConfig, module, subPackage) {
719
+ const srcModulePath = getAbsolutePath(module.path);
720
+ const buildModulePath = resolve(tmsConfig.outputDir, module.modulePath);
721
+ const subPackageRoot = getSubPackageRoot(module.modulePath, subPackage.root);
722
+ const buildSubPackagePath = resolve(tmsConfig.outputDir, subPackageRoot);
723
+ const subPackageRelativeModule = path.relative(buildModulePath, buildSubPackagePath);
724
+ const srcSubPackagePath = path.join(srcModulePath, subPackageRelativeModule);
725
+ return srcSubPackagePath;
726
+ };
727
+
728
+ const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
729
+ const newModuleItem = { ...tmsModuleItem,
730
+ ...moduleConfig
731
+ }; // 兼容逻辑
732
+
733
+ if (!newModuleItem.moduleName) newModuleItem.moduleName = newModuleItem.name;
734
+ delete newModuleItem.name; // 参数校验-模块源码路径
735
+
736
+ if (!newModuleItem.path) {
737
+ throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
738
+ } // 参数校验-模块编译路径
739
+
740
+
741
+ if (!newModuleItem.modulePath) {
742
+ throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到modulePath字段`);
743
+ } // 参数校验-分包校验
744
+
745
+
746
+ for (const subPackage of newModuleItem.subPackages) {
747
+ if (!subPackage.root) {
748
+ throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到${subPackage.name}分包的root字段`);
749
+ } // 参数校验-判断分包源码目录是否存在
750
+
751
+
752
+ const subPackageSrcPath = getSubPackageSrcPath(tmsConfig, newModuleItem, subPackage);
753
+
754
+ if (!subPackageSrcPath || !fs.existsSync(subPackageSrcPath)) {
755
+ throw new Error(`没有找到${newModuleItem.moduleName}模块的${subPackage.name}分包源码:${subPackageSrcPath}`);
756
+ }
757
+
758
+ subPackage.path = subPackageSrcPath;
759
+ }
760
+
761
+ return newModuleItem;
762
+ };
763
+ /**
764
+ * 获取所有的模块,合并模块的依赖模块
765
+ * @param { object } tmsConfig
766
+ * @param {array} modules
767
+ * @param {boolean} errorIsQuit 找不到配置文件是否退出
768
+ * @returns
769
+ */
770
+
771
+
772
+ const getModulesByMergeDepModules = (tmsConfig, modules, errorIsQuit = false) => {
773
+ const allModules = new Map();
774
+
775
+ function dfs(tmsConfig, modules) {
776
+ modules.forEach(moduleItem => {
777
+ const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
778
+
779
+ if (!fs.existsSync(moduleConfigPath)) {
780
+ if (!allModules.has(moduleItem.moduleName)) {
781
+ allModules.set(moduleItem.moduleName, moduleItem);
782
+ }
783
+
784
+ if (errorIsQuit) {
785
+ throw new Error(`${moduleItem.moduleName}模块的配置文件module.config.json在${moduleItem.path}目录下没有找到`);
786
+ }
787
+
788
+ return;
789
+ }
790
+
791
+ const [moduleConfig = {}] = getModulesConfig([moduleItem], tmsConfig.appName);
792
+
793
+ if (!allModules.has(moduleItem.moduleName)) {
794
+ allModules.set(moduleItem.moduleName, checkModuleItem(tmsConfig, moduleItem, moduleConfig));
795
+ const dependenciesModules = getModulesByModuleNames(tmsConfig, moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies);
796
+
797
+ if (dependenciesModules.length) {
798
+ dfs(tmsConfig, dependenciesModules);
799
+ }
800
+ }
801
+ });
802
+ }
803
+
804
+ dfs(tmsConfig, modules);
805
+ const modulesArr = [];
806
+
807
+ for (const module of allModules.values()) {
808
+ modulesArr.push(module);
809
+ }
810
+
811
+ return modulesArr;
812
+ };
813
+
814
+ module.exports = {
815
+ readTmsConfig,
816
+ readTmsPrivateCf,
817
+ getModulesConfig,
818
+ getModulesByModuleNames,
819
+ getSubPackages,
820
+ getModulesByMergeDepModules,
821
+ getTmsConfig
822
+ };
823
+ })(tmsMpconfig);
824
+
825
+ const fs$g = require$$0__default$2;
470
826
  const path$c = require$$1__default$2;
471
827
  const {
472
828
  info: info$b
@@ -480,12 +836,12 @@ const {
480
836
  * @returns
481
837
  */
482
838
 
483
- const isDirEmpty = dirname => fs$f.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
839
+ const isDirEmpty = dirname => fs$g.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
484
840
 
485
841
 
486
842
  const isFile = pathName => {
487
843
  try {
488
- const stat = fs$f.lstatSync(pathName);
844
+ const stat = fs$g.lstatSync(pathName);
489
845
  return stat.isFile();
490
846
  } catch {
491
847
  return false;
@@ -498,8 +854,8 @@ const isFile = pathName => {
498
854
 
499
855
 
500
856
  const ensureDirExist$2 = dirname => {
501
- if (!fs$f.existsSync(dirname)) {
502
- fs$f.mkdirSync(dirname, {
857
+ if (!fs$g.existsSync(dirname)) {
858
+ fs$g.mkdirSync(dirname, {
503
859
  recursive: true
504
860
  });
505
861
  }
@@ -507,20 +863,20 @@ const ensureDirExist$2 = dirname => {
507
863
 
508
864
 
509
865
  const copyFile = function (src, dest) {
510
- if (fs$f.existsSync(dest)) {
511
- fs$f.unlinkSync(dest);
866
+ if (fs$g.existsSync(dest)) {
867
+ fs$g.unlinkSync(dest);
512
868
  }
513
869
 
514
870
  const dir = path$c.dirname(dest);
515
871
  ensureDirExist$2(dir);
516
- fs$f.copyFileSync(src, dest);
872
+ fs$g.copyFileSync(src, dest);
517
873
  }; // 判断文件内容是否一致,不一致再进行拷贝
518
874
 
519
875
 
520
876
  function diffContentCopyFile$3(originFile, destFile) {
521
- if (fs$f.existsSync(destFile)) {
522
- const depDestContent = fs$f.readFileSync(destFile, 'utf8');
523
- const depOriginContent = fs$f.readFileSync(originFile, 'utf8');
877
+ if (fs$g.existsSync(destFile)) {
878
+ const depDestContent = fs$g.readFileSync(destFile, 'utf8');
879
+ const depOriginContent = fs$g.readFileSync(originFile, 'utf8');
524
880
 
525
881
  if (depDestContent !== depOriginContent) {
526
882
  info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
@@ -538,7 +894,7 @@ function ext$3(filePath, extensions) {
538
894
  let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
539
895
 
540
896
  try {
541
- const stat = fs$f.lstatSync(newFilePath);
897
+ const stat = fs$g.lstatSync(newFilePath);
542
898
 
543
899
  if (stat.isDirectory()) {
544
900
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
@@ -549,7 +905,7 @@ function ext$3(filePath, extensions) {
549
905
  for (const ext of extensions) {
550
906
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
551
907
 
552
- if (fs$f.existsSync(file)) {
908
+ if (fs$g.existsSync(file)) {
553
909
  return {
554
910
  ext,
555
911
  extPath: extPath + ext,
@@ -567,7 +923,7 @@ function ext$3(filePath, extensions) {
567
923
 
568
924
 
569
925
  const fileInDir$3 = (dir, file) => {
570
- if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
926
+ if (!fs$g.existsSync(dir) || !fs$g.existsSync(file)) {
571
927
  return false;
572
928
  }
573
929
 
@@ -584,10 +940,10 @@ function findAllFilesOfDir$1(dir) {
584
940
  const list = [];
585
941
 
586
942
  function listFile(dir) {
587
- const arr = fs$f.readdirSync(dir);
943
+ const arr = fs$g.readdirSync(dir);
588
944
  arr.forEach(item => {
589
945
  const fullPath = path$c.join(dir, item);
590
- const stats = fs$f.statSync(fullPath);
946
+ const stats = fs$g.statSync(fullPath);
591
947
 
592
948
  if (stats.isDirectory()) {
593
949
  listFile(fullPath);
@@ -613,7 +969,7 @@ var io$3 = {
613
969
  findAllFilesOfDir: findAllFilesOfDir$1
614
970
  };
615
971
 
616
- const async = require$$0__default$4;
972
+ const async = require$$0__default$5;
617
973
  const ejs = require$$1__default$3;
618
974
 
619
975
  const render$1 = (files, metalsmith, next) => {
@@ -633,14 +989,14 @@ const render$1 = (files, metalsmith, next) => {
633
989
 
634
990
  var render_1 = render$1;
635
991
 
636
- const fs$e = require$$0__default$2;
992
+ const fs$f = require$$0__default$2;
637
993
  const inquirer$1 = require$$1__default$4;
638
994
  const {
639
- resolve: resolve$e
995
+ resolve: resolve$f
640
996
  } = widgets;
641
997
  const {
642
998
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
643
- } = require$$4;
999
+ } = require$$5;
644
1000
  /**
645
1001
  * 获取模板内的问题
646
1002
  * @param {string} dir questions.json所在的目录
@@ -650,12 +1006,12 @@ const {
650
1006
  const parseTemplateQuestions = dir => {
651
1007
  let prompts = [];
652
1008
 
653
- if (!fs$e.existsSync(`${dir}/questions.json`)) {
1009
+ if (!fs$f.existsSync(`${dir}/questions.json`)) {
654
1010
  return prompts;
655
1011
  }
656
1012
 
657
1013
  try {
658
- const json = JSON.parse(fs$e.readFileSync(`${dir}/questions.json`));
1014
+ const json = JSON.parse(fs$f.readFileSync(`${dir}/questions.json`));
659
1015
 
660
1016
  if (Array.isArray(json) && json.length > 0) {
661
1017
  json.forEach((item, index) => {
@@ -688,7 +1044,7 @@ const isQuestionType = result => {
688
1044
  };
689
1045
 
690
1046
  const ask$1 = templateDir => (files, metalsmith, next) => {
691
- const prompts = parseTemplateQuestions(resolve$e(templateDir, TEMPLATE_TKIT_DIR$1));
1047
+ const prompts = parseTemplateQuestions(resolve$f(templateDir, TEMPLATE_TKIT_DIR$1));
692
1048
  const metadata = metalsmith.metadata();
693
1049
  const filteredPrompts = prompts.filter(prompt => {
694
1050
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -713,7 +1069,7 @@ var ask_1 = ask$1;
713
1069
  const FILES_TO_IGNORE$1 = ['node_modules'];
714
1070
  var ignoreFiles = FILES_TO_IGNORE$1;
715
1071
 
716
- const Metalsmith = require$$0__default$5;
1072
+ const Metalsmith = require$$0__default$6;
717
1073
  const render = render_1;
718
1074
  const ask = ask_1;
719
1075
  const FILES_TO_IGNORE = ignoreFiles;
@@ -731,7 +1087,7 @@ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolv
731
1087
  var generator_1 = generator$1;
732
1088
 
733
1089
  const path$b = require$$1__default$2;
734
- const fs$d = require$$0__default$2;
1090
+ const fs$e = require$$0__default$2;
735
1091
  const shelljs$6 = require$$0__default$3;
736
1092
  const inquirer = require$$1__default$4;
737
1093
  const {
@@ -740,13 +1096,13 @@ const {
740
1096
  TEMPLATE_NAME,
741
1097
  TEMPLATE_TKIT_DIR,
742
1098
  CREATE_TEMPLATE_QUESTION
743
- } = require$$4;
1099
+ } = require$$5;
744
1100
  const {
745
- resolve: resolve$d
1101
+ resolve: resolve$e
746
1102
  } = widgets;
747
1103
  const io$2 = io$3;
748
1104
  const {
749
- fail: fail$9,
1105
+ fail: fail$8,
750
1106
  succeed: succeed$1,
751
1107
  info: info$a
752
1108
  } = log$1;
@@ -761,9 +1117,9 @@ const unzip = require$$10__default;
761
1117
 
762
1118
  async function createProjectDir(targetDir) {
763
1119
  // 如果目录非空或者已经存在,提示用户,做选择
764
- if (fs$d.existsSync(targetDir)) {
1120
+ if (fs$e.existsSync(targetDir)) {
765
1121
  if (!(await io$2.isDirEmpty(targetDir))) {
766
- fail$9('该目录名已经存在,换个项目名字吧~');
1122
+ fail$8('该目录名已经存在,换个项目名字吧~');
767
1123
  process.exit(1);
768
1124
  }
769
1125
  } else {
@@ -782,350 +1138,82 @@ async function createProjectDir(targetDir) {
782
1138
  function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
783
1139
  return new Promise((resolve, reject) => {
784
1140
  const localZipPath = `${templateDir}/${templateName}.zip`;
785
- const stream = fs$d.createWriteStream(localZipPath);
1141
+ const stream = fs$e.createWriteStream(localZipPath);
786
1142
  request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
787
1143
  if (err) {
788
1144
  reject(err);
789
1145
  return;
790
1146
  }
791
1147
 
792
- fs$d.createReadStream(localZipPath).pipe(unzip.Extract({
1148
+ fs$e.createReadStream(localZipPath).pipe(unzip.Extract({
793
1149
  path: templateDir
794
1150
  })).on('close', err => {
795
1151
  if (err) {
796
- reject(err);
797
- return;
798
- }
799
-
800
- resolve();
801
- });
802
- });
803
- });
804
- }
805
- /**
806
- * 创建本地小程序运行环境
807
- * @param { string } projectType 项目类型
808
- * @param { string } projectName 项目名称
809
- */
810
-
811
-
812
- async function create(projectName) {
813
- const cwd = process.cwd();
814
- const targetDir = path$b.resolve(cwd, projectName);
815
- const {
816
- projectType
817
- } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION); // 创建项目目录
818
-
819
- await createProjectDir(targetDir); // 新创建缓存目录
820
-
821
- if (fs$d.existsSync(TEMPLATE_DIR)) {
822
- shelljs$6.rm('-rf', TEMPLATE_DIR);
823
- }
824
-
825
- fs$d.mkdirSync(TEMPLATE_DIR, {
826
- recursive: true
827
- }); // 下载和解压模板
828
-
829
- await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
830
-
831
- generator(path$b.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
832
- shelljs$6.cd(projectName);
833
- const hookFilePath = resolve$d(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
834
-
835
- if (fs$d.existsSync(hookFilePath)) {
836
- const hooks = require(hookFilePath);
837
-
838
- if (hooks.afterCreate) {
839
- hooks.afterCreate.forEach(item => {
840
- if (typeof item === 'function') {
841
- item.call(null, shelljs$6, {
842
- projectName
843
- });
844
- } else {
845
- shelljs$6.exec(item);
846
- }
847
- });
848
- }
849
-
850
- shelljs$6.rm('-rf', resolve$d(projectName, TEMPLATE_TKIT_DIR));
851
- }
852
-
853
- succeed$1('项目创建完成.');
854
- }).catch(err => {
855
- fail$9(err.message);
856
- info$a('详细的错误信息:', err);
857
- });
858
- }
859
-
860
- var create_1 = create;
861
-
862
- var tmsMpconfig = {exports: {}};
863
-
864
- var defaultTmsConfig = {
865
- // 全局的环境配置项
866
- envData: {},
867
- // 模块配置信息
868
- modules: {},
869
- cloudDir: 'cloud',
870
- // 第三方依赖代码需要拷贝到本项目的
871
- dependencies: {},
872
-
873
- /** 编译输出文件夹位置 */
874
- outputDir: 'dist',
875
-
876
- /** 源码监听路径 */
877
- sourceDir: './',
878
-
879
- /** 静态资源目录 */
880
- static: []
881
- };
882
-
883
- /**
884
- * 用来读取处理tms.config.js与module.config.json字段
885
- */
886
-
887
- (function (module) {
888
- /* eslint-disable no-param-reassign, no-nested-ternary */
889
- const loadash = require$$0__default$6;
890
- const fs = require$$0__default$2;
891
- const {
892
- TMS_CONFIG_FILENAME,
893
- MODULE_CONFIG_FILENAME,
894
- TMS_PRIVATE_FILENAME
895
- } = require$$4;
896
- const {
897
- resolve,
898
- isObject,
899
- isArray
900
- } = widgets;
901
- const defaultTmsConfig$1 = defaultTmsConfig;
902
- const {
903
- fail
904
- } = log$1;
905
- /**
906
- * 读取tms.config.js
907
- * @param env {string} 环境变量
908
- */
909
-
910
- const readTmsConfig = function (env) {
911
- const tmsConfigPath = resolve(TMS_CONFIG_FILENAME);
912
-
913
- if (!fs.existsSync(tmsConfigPath)) {
914
- fail('当前执行目录没有tms.config.js的配置项,请进行配置');
915
- process.exit(1);
916
- }
917
-
918
- const tmsConfigFn = require(tmsConfigPath);
919
-
920
- const tmsConfig = tmsConfigFn({
921
- env
922
- }); // 合并默认值
923
-
924
- return loadash.mergeWith(defaultTmsConfig$1, tmsConfig);
925
- };
926
- /**
927
- * 读取tms.private.config.js
928
- */
929
-
930
-
931
- const readTmsPrivateCf = function () {
932
- let tmsPrivateCf = {};
933
- const tmsPrivatePath = resolve(TMS_PRIVATE_FILENAME);
934
-
935
- if (fs.existsSync(tmsPrivatePath)) {
936
- tmsPrivateCf = require(tmsPrivatePath);
937
- }
938
-
939
- return tmsPrivateCf;
940
- };
941
- /**
942
- * 从tms.config.json中检索用户传入的有效modules
943
- * @param { object } tmsConfig
944
- * @param { array } modules
945
- * @returns
946
- */
947
-
948
-
949
- const checkModules = function (tmsConfig, modules, isQuit = false) {
950
- const targetModules = [];
951
- modules.forEach(moduleName => {
952
- const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
953
- module && targetModules.push(module);
954
- });
955
-
956
- if (targetModules.length === 0) {
957
- fail(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
958
- >name字段与module.config.json的name字段是否一致`);
959
- isQuit && process.exit(1);
960
- }
961
-
962
- return targetModules;
963
- };
964
- /**
965
- * 适配处理module.config.json的字段
966
- * @param { object } fileContent module.config.json的内容
967
- * @param { string } appName 小程序的名称
968
- */
969
-
970
-
971
- function adaptMpCgContent(fileContent, appName) {
972
- const handleContent = function (appName, current) {
973
- let res = current;
974
-
975
- if (appName && current.mpConfig && current.mpConfig[appName]) {
976
- res = { ...current,
977
- ...current.mpConfig[appName]
978
- };
979
- }
980
-
981
- delete res.mpConfig;
982
- delete res.isSubpackages;
983
- return res;
984
- };
985
-
986
- let content = fileContent;
987
-
988
- if (isArray(content)) {
989
- let i = content.length - 1;
990
-
991
- while (i >= 0) {
992
- content[i] = handleContent(appName, content[i]);
993
- i--; // eslint-disable-line
994
- }
995
- } else {
996
- content = handleContent(appName, content);
997
- }
998
-
999
- return content;
1000
- }
1001
- /**
1002
- * 获取模块module.config.json中的配置信息
1003
- * @param {array} modules 用户要编译的模块列表
1004
- * @param { string } appName 小程序的名称
1005
- * @param {boolean} notFindIsQuit 找不到配置文件是否退出
1006
- */
1007
-
1008
-
1009
- function getModulesConfig(modules = [], appName, notFindIsQuit) {
1010
- const modulesConfig = [];
1011
- modules.forEach(moduleItem => {
1012
- if (!moduleItem.path) {
1013
- throw new Error(`${moduleItem.moduleName}模块路径配置没有找到`);
1014
- }
1015
-
1016
- const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
1017
-
1018
- if (!fs.existsSync(moduleConfigPath)) {
1019
- if (notFindIsQuit) {
1020
- throw new Error(`${moduleItem.moduleName}模块的配置文件module.config.json在${moduleItem.path}目录下没有找到`);
1021
- }
1022
-
1023
- return;
1024
- }
1025
-
1026
- let moduleConfig;
1027
-
1028
- try {
1029
- moduleConfig = JSON.parse(fs.readFileSync(moduleConfigPath, 'utf-8'));
1030
- } catch (e) {
1031
- throw new Error(`${moduleConfigPath}json解析报错: ${e}`);
1032
- } // 兼容历史逻辑,后续可删除--- start
1152
+ reject(err);
1153
+ return;
1154
+ }
1033
1155
 
1156
+ resolve();
1157
+ });
1158
+ });
1159
+ });
1160
+ }
1161
+ /**
1162
+ * 创建本地小程序运行环境
1163
+ * @param { string } projectType 项目类型
1164
+ * @param { string } projectName 项目名称
1165
+ */
1034
1166
 
1035
- if (!moduleItem.moduleName) moduleItem.moduleName = moduleItem.name;
1036
- delete moduleItem.name;
1037
- let subPackages = isObject(moduleConfig) && moduleConfig.subPackages ? moduleConfig.subPackages : isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
1038
- subPackages = adaptMpCgContent(subPackages, appName);
1039
- let dependencies = moduleConfig.dependencies || [];
1040
- subPackages.forEach(item => {
1041
- item.path = moduleItem.path;
1042
1167
 
1043
- if (item.dependencies) {
1044
- dependencies = dependencies.concat(item.dependencies);
1045
- }
1046
- });
1047
- moduleItem.subPackages = subPackages;
1048
- moduleItem.dependencies = dependencies; // 兼容逻辑--- end
1168
+ async function create(projectName) {
1169
+ const cwd = process.cwd();
1170
+ const targetDir = path$b.resolve(cwd, projectName);
1171
+ const {
1172
+ projectType
1173
+ } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION); // 创建项目目录
1049
1174
 
1050
- modulesConfig.push(moduleItem);
1051
- });
1052
- return modulesConfig;
1053
- }
1054
- /**
1055
- * 获取分包内容 (读取module.config.json的配置项)
1056
- * @param {array} modules
1057
- * @returns
1058
- */
1175
+ await createProjectDir(targetDir); // 新创建缓存目录
1059
1176
 
1177
+ if (fs$e.existsSync(TEMPLATE_DIR)) {
1178
+ shelljs$6.rm('-rf', TEMPLATE_DIR);
1179
+ }
1060
1180
 
1061
- const getSubPackages = modules => {
1062
- const newSubPackages = [];
1063
- modules.forEach(module => {
1064
- (module.subPackages || []).forEach(item => {
1065
- newSubPackages.push({
1066
- path: module.path,
1067
- ...item
1068
- });
1069
- });
1070
- });
1071
- return newSubPackages;
1072
- };
1073
- /**
1074
- * 获取所有的模块,合并模块的依赖模块
1075
- * @param { object } tmsConfig
1076
- * @param {array} modules
1077
- * @param {boolean} notFindIsQuit 找不到配置文件是否退出
1078
- * @returns
1079
- */
1181
+ fs$e.mkdirSync(TEMPLATE_DIR, {
1182
+ recursive: true
1183
+ }); // 下载和解压模板
1080
1184
 
1185
+ await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
1081
1186
 
1082
- const getModulesByMergeDepModules = (tmsConfig, modules, notFindIsQuit = false) => {
1083
- const allModules = new Map();
1187
+ generator(path$b.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1188
+ shelljs$6.cd(projectName);
1189
+ const hookFilePath = resolve$e(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1084
1190
 
1085
- function dfs(tmsConfig, modules) {
1086
- modules.forEach(moduleItem => {
1087
- const [moduleConfig = {}] = getModulesConfig([moduleItem], tmsConfig.appName, notFindIsQuit);
1191
+ if (fs$e.existsSync(hookFilePath)) {
1192
+ const hooks = require(hookFilePath);
1088
1193
 
1089
- if (!allModules.has(moduleItem.moduleName)) {
1090
- allModules.set(moduleItem.moduleName, { ...moduleItem,
1091
- ...moduleConfig
1092
- });
1093
- const dependenciesModules = [];
1094
- ((moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies) || []).forEach(dependenciesModule => {
1095
- tmsConfig.modules.all.forEach(module => {
1096
- if (dependenciesModule === module.moduleName) {
1097
- dependenciesModules.push({ ...module
1098
- });
1099
- }
1194
+ if (hooks.afterCreate) {
1195
+ hooks.afterCreate.forEach(item => {
1196
+ if (typeof item === 'function') {
1197
+ item.call(null, shelljs$6, {
1198
+ projectName
1100
1199
  });
1101
- });
1102
-
1103
- if (dependenciesModules.length) {
1104
- dfs(tmsConfig, dependenciesModules);
1200
+ } else {
1201
+ shelljs$6.exec(item);
1105
1202
  }
1106
- }
1107
- });
1108
- }
1109
-
1110
- dfs(tmsConfig, modules);
1111
- const modulesArr = [];
1203
+ });
1204
+ }
1112
1205
 
1113
- for (const module of allModules.values()) {
1114
- modulesArr.push(module);
1206
+ shelljs$6.rm('-rf', resolve$e(projectName, TEMPLATE_TKIT_DIR));
1115
1207
  }
1116
1208
 
1117
- return modulesArr;
1118
- };
1209
+ succeed$1('项目创建完成.');
1210
+ }).catch(err => {
1211
+ fail$8(err.message);
1212
+ info$a('详细的错误信息:', err);
1213
+ });
1214
+ }
1119
1215
 
1120
- module.exports = {
1121
- readTmsConfig,
1122
- readTmsPrivateCf,
1123
- getModulesConfig,
1124
- checkModules,
1125
- getSubPackages,
1126
- getModulesByMergeDepModules
1127
- };
1128
- })(tmsMpconfig);
1216
+ var create_1 = create;
1129
1217
 
1130
1218
  const global$6 = {
1131
1219
  data: {},
@@ -1153,32 +1241,32 @@ var global_1 = {
1153
1241
  };
1154
1242
 
1155
1243
  const {
1156
- fail: fail$8
1244
+ fail: fail$7
1157
1245
  } = log$1;
1158
1246
  const {
1159
1247
  global: global$5
1160
1248
  } = global_1;
1161
1249
 
1162
- function handleError$6(error, isQuit = false) {
1250
+ function handleError$5(error, isQuit = false) {
1163
1251
  const errMsg = typeof error === 'object' ? error.message : error;
1164
1252
 
1165
1253
  if (isQuit) {
1166
- fail$8(errMsg);
1254
+ fail$7(errMsg);
1167
1255
  process.exit(1);
1168
1256
  }
1169
1257
 
1170
1258
  const isDev = global$5.getData('isDev');
1171
1259
 
1172
1260
  if (isDev) {
1173
- fail$8(errMsg);
1261
+ fail$7(errMsg);
1174
1262
  } else {
1175
- fail$8(errMsg);
1263
+ fail$7(errMsg);
1176
1264
  process.exit(1);
1177
1265
  }
1178
1266
  }
1179
1267
 
1180
1268
  var handleError_1 = {
1181
- handleError: handleError$6
1269
+ handleError: handleError$5
1182
1270
  };
1183
1271
 
1184
1272
  /**
@@ -1186,21 +1274,21 @@ var handleError_1 = {
1186
1274
  */
1187
1275
  /* eslint-disable no-param-reassign */
1188
1276
 
1189
- const fs$c = require$$0__default$2;
1277
+ const fs$d = require$$0__default$2;
1190
1278
  const {
1191
1279
  getSubPackages: getSubPackages$3,
1192
1280
  getModulesConfig
1193
1281
  } = tmsMpconfig.exports;
1194
1282
  const {
1195
- fail: fail$7,
1283
+ fail: fail$6,
1196
1284
  info: info$9
1197
1285
  } = log$1;
1198
1286
  const {
1199
- resolve: resolve$c,
1287
+ resolve: resolve$d,
1200
1288
  filterField: filterField$3
1201
1289
  } = widgets;
1202
1290
  const {
1203
- handleError: handleError$5
1291
+ handleError: handleError$4
1204
1292
  } = handleError_1;
1205
1293
  const {
1206
1294
  global: global$4
@@ -1223,7 +1311,7 @@ function updateMainPackages(appJson, mainPackages = []) {
1223
1311
 
1224
1312
  foundMainPackages.forEach(subpackage => {
1225
1313
  if (!subpackage.pages || !subpackage.pages.length) {
1226
- fail$7(`主包 ${subpackage} 不能没有 pages`);
1314
+ fail$6(`主包 ${subpackage} 不能没有 pages`);
1227
1315
  process.exit(-1);
1228
1316
  }
1229
1317
 
@@ -1248,12 +1336,12 @@ function updateMainPackages(appJson, mainPackages = []) {
1248
1336
 
1249
1337
 
1250
1338
  const getAppJsonContent = sourceAppJsonPath => {
1251
- if (!fs$c.existsSync(sourceAppJsonPath)) {
1252
- fail$7(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1339
+ if (!fs$d.existsSync(sourceAppJsonPath)) {
1340
+ fail$6(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1253
1341
  process.exit(1);
1254
1342
  }
1255
1343
 
1256
- const appJson = JSON.parse(fs$c.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1344
+ const appJson = JSON.parse(fs$d.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1257
1345
 
1258
1346
  appJson.subpackages = [];
1259
1347
  appJson.pages = [];
@@ -1332,7 +1420,7 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1332
1420
 
1333
1421
  const subPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
1334
1422
 
1335
- const appJson = getAppJsonContent(resolve$c('./app.json')); // 更新app.json中的subpackages
1423
+ const appJson = getAppJsonContent(resolve$d('./app.json')); // 更新app.json中的subpackages
1336
1424
 
1337
1425
  appJson.subpackages = subPackages;
1338
1426
  appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name)); // 处理appJson中重复||冲突的地方
@@ -1340,7 +1428,7 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1340
1428
  fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1341
1429
 
1342
1430
  updateMainPackages(appJson, tmsConfig.mainPackages);
1343
- fs$c.writeFileSync(resolve$c(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1431
+ fs$d.writeFileSync(resolve$d(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1344
1432
 
1345
1433
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
1346
1434
  var _tmsConfig$hooks2;
@@ -1355,7 +1443,7 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1355
1443
 
1356
1444
  return appJson;
1357
1445
  } catch (e) {
1358
- handleError$5(`生成app.json出现错误: ${e}`);
1446
+ handleError$4(`生成app.json出现错误: ${e}`);
1359
1447
  info$9(e);
1360
1448
  }
1361
1449
  }
@@ -1367,21 +1455,21 @@ var buildAppJson = {
1367
1455
  /**
1368
1456
  * 下载第三方代码
1369
1457
  */
1370
- const MetalSmith = require$$0__default$5;
1458
+ const MetalSmith = require$$0__default$6;
1371
1459
  const crypto$2 = require$$1__default$5;
1372
1460
  const {
1373
1461
  downloadRepoForGit,
1374
1462
  pullRepoForGit,
1375
- resolve: resolve$b
1463
+ resolve: resolve$c
1376
1464
  } = widgets;
1377
1465
  const {
1378
- fail: fail$6,
1466
+ fail: fail$5,
1379
1467
  info: info$8
1380
1468
  } = log$1;
1381
- const fs$b = require$$0__default$2;
1469
+ const fs$c = require$$0__default$2;
1382
1470
  const shelljs$5 = require$$0__default$3;
1383
1471
  const {
1384
- handleError: handleError$4
1472
+ handleError: handleError$3
1385
1473
  } = handleError_1;
1386
1474
  const {
1387
1475
  global: global$3
@@ -1425,7 +1513,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1425
1513
  return new Promise((resolve, reject) => {
1426
1514
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1427
1515
  if (e) {
1428
- fail$6(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1516
+ fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1429
1517
  reject(e);
1430
1518
  }
1431
1519
 
@@ -1474,7 +1562,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1474
1562
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1475
1563
  return Promise.all(callArr);
1476
1564
  }).catch(e => {
1477
- handleError$4(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1565
+ handleError$3(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1478
1566
  }));
1479
1567
  });
1480
1568
  await Promise.all(arrPromises);
@@ -1519,9 +1607,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1519
1607
 
1520
1608
  const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1521
1609
 
1522
- const sourcePath = resolve$b(sourceDir, md5Key); // 模块源码要放到目标目录
1610
+ const sourcePath = resolve$c(sourceDir, md5Key); // 模块源码要放到目标目录
1523
1611
 
1524
- const targetPath = resolve$b(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1612
+ const targetPath = resolve$c(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1525
1613
 
1526
1614
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1527
1615
 
@@ -1531,7 +1619,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1531
1619
  targetPath
1532
1620
  },
1533
1621
  fn: async (sourceModulePath, targetPath) => {
1534
- if (fs$b.existsSync(targetPath)) {
1622
+ if (fs$c.existsSync(targetPath)) {
1535
1623
  shelljs$5.rm('-rf', `${targetPath}/*`);
1536
1624
  }
1537
1625
 
@@ -1546,7 +1634,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1546
1634
  } else {
1547
1635
  let promiseTask;
1548
1636
 
1549
- if (fs$b.existsSync(sourcePath) && fs$b.existsSync(`${sourcePath}/.git`)) {
1637
+ if (fs$c.existsSync(sourcePath) && fs$c.existsSync(`${sourcePath}/.git`)) {
1550
1638
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1551
1639
  info$8(`git pull:${httpRepoUrl}`);
1552
1640
  return pullRepoForGit(sourcePath, branch);
@@ -1594,7 +1682,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
1594
1682
  const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
1595
1683
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
1596
1684
 
1597
- if (!fs$b.existsSync(`${sourceDir}/${md5Key}`)) {
1685
+ if (!fs$c.existsSync(`${sourceDir}/${md5Key}`)) {
1598
1686
  return true;
1599
1687
  }
1600
1688
  }
@@ -1688,12 +1776,12 @@ var mpCi = {
1688
1776
  buildMpNpm: buildMpNpm$1
1689
1777
  };
1690
1778
 
1691
- const fs$a = require$$0__default$2;
1779
+ const fs$b = require$$0__default$2;
1692
1780
  const path$9 = require$$1__default$2;
1693
1781
  const {
1694
1782
  CACHE_FILE,
1695
1783
  CACHE_DIR: CACHE_DIR$2
1696
- } = require$$4;
1784
+ } = require$$5;
1697
1785
  const {
1698
1786
  ensureDirExist: ensureDirExist$1
1699
1787
  } = io$3;
@@ -1703,7 +1791,7 @@ function getCache$1(projectDir, type) {
1703
1791
 
1704
1792
  const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
1705
1793
 
1706
- if (!fs$a.existsSync(filePath)) {
1794
+ if (!fs$b.existsSync(filePath)) {
1707
1795
  return null;
1708
1796
  }
1709
1797
 
@@ -1715,10 +1803,10 @@ function getCache$1(projectDir, type) {
1715
1803
  function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1716
1804
  const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
1717
1805
 
1718
- if (!fs$a.existsSync(filePath)) {
1806
+ if (!fs$b.existsSync(filePath)) {
1719
1807
  const dir = path$9.dirname(filePath);
1720
1808
  ensureDirExist$1(dir);
1721
- fs$a.writeFileSync(filePath, '{}');
1809
+ fs$b.writeFileSync(filePath, '{}');
1722
1810
  }
1723
1811
 
1724
1812
  const content = require(filePath);
@@ -1730,7 +1818,7 @@ function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1730
1818
  content[projectDir] = {
1731
1819
  [type]: data
1732
1820
  };
1733
- fs$a.writeFileSync(filePath, JSON.stringify(content, null, 2));
1821
+ fs$b.writeFileSync(filePath, JSON.stringify(content, null, 2));
1734
1822
  }
1735
1823
 
1736
1824
  var cache = {
@@ -1741,7 +1829,7 @@ var cache = {
1741
1829
  /**
1742
1830
  * 本文件主要负责项目或者分包依赖的npm的安装
1743
1831
  */
1744
- const fs$9 = require$$0__default$2;
1832
+ const fs$a = require$$0__default$2;
1745
1833
  const fsExtra = require$$1__default$6;
1746
1834
  const crypto$1 = require$$1__default$5;
1747
1835
  const path$8 = require$$1__default$2;
@@ -1752,7 +1840,7 @@ const {
1752
1840
  npmInstall: npmInstall$1
1753
1841
  } = widgets;
1754
1842
  const {
1755
- handleError: handleError$3
1843
+ handleError: handleError$2
1756
1844
  } = handleError_1;
1757
1845
  const shellJsOption = {
1758
1846
  async: false,
@@ -1776,7 +1864,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1776
1864
  const npmTasksMap = new Map();
1777
1865
 
1778
1866
  for (const packageJsonPath of packageJsonFiles) {
1779
- const packageContent = fs$9.readFileSync(packageJsonPath);
1867
+ const packageContent = fs$a.readFileSync(packageJsonPath);
1780
1868
  let packageJson;
1781
1869
 
1782
1870
  try {
@@ -1855,9 +1943,9 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1855
1943
  }; // 遍历安装指定目录下所有项目的npm依赖
1856
1944
 
1857
1945
 
1858
- const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1946
+ const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
1859
1947
  const cwd = process.cwd();
1860
- const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
1948
+ const packageJsonFiles = await findAllPackageJson(subPackages, contextDir); // 收集npm install的任务
1861
1949
 
1862
1950
  const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir); // 开始执行npm install和回调(移动)的任务
1863
1951
 
@@ -1874,7 +1962,7 @@ const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1874
1962
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1875
1963
  return Promise.all(callArr);
1876
1964
  }).catch(e => {
1877
- handleError$3(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
1965
+ handleError$2(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
1878
1966
  }));
1879
1967
  });
1880
1968
  await Promise.all(arrPromises);
@@ -1900,7 +1988,7 @@ const findFilesByFilter = (startPath, filter) => {
1900
1988
 
1901
1989
  const find = (startPath, filter) => {
1902
1990
  // 目录不存在
1903
- if (!fs$9.existsSync(startPath)) {
1991
+ if (!fs$a.existsSync(startPath)) {
1904
1992
  log.fail(`${startPath}目录不存在`);
1905
1993
  process.exit(-1);
1906
1994
  return;
@@ -1913,10 +2001,10 @@ const findFilesByFilter = (startPath, filter) => {
1913
2001
  return;
1914
2002
  }
1915
2003
 
1916
- const files = fs$9.readdirSync(startPath);
2004
+ const files = fs$a.readdirSync(startPath);
1917
2005
  files.forEach(file => {
1918
2006
  const filename = path$8.join(startPath, file);
1919
- const stat = fs$9.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2007
+ const stat = fs$a.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1920
2008
 
1921
2009
  if (stat.isDirectory()) {
1922
2010
  find(filename, filter);
@@ -1945,11 +2033,6 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1945
2033
  const result = [path$8.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1946
2034
 
1947
2035
  subRoots.forEach(subRoot => {
1948
- if (!subRoot.root) {
1949
- log.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
1950
- process.exit(1);
1951
- }
1952
-
1953
2036
  const toppath = path$8.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1954
2037
 
1955
2038
  const list = findFilesByFilter(toppath, packageJsonName);
@@ -1980,16 +2063,17 @@ function cloudNpmInstall(contextDir) {
1980
2063
  var npm = {
1981
2064
  cloudNpmInstall,
1982
2065
  npmInstallAll: npmInstallAll$1,
1983
- findAllPackageJson
2066
+ findAllPackageJson,
2067
+ findFilesByFilter
1984
2068
  };
1985
2069
 
1986
2070
  const crypto = require$$1__default$5;
1987
- const fs$8 = require$$0__default$2;
2071
+ const fs$9 = require$$0__default$2;
1988
2072
 
1989
2073
  function fileMd5$1(filePath) {
1990
2074
  return new Promise((resolve, reject) => {
1991
2075
  const md5sum = crypto.createHash('md5');
1992
- const stream = fs$8.ReadStream(filePath);
2076
+ const stream = fs$9.ReadStream(filePath);
1993
2077
  stream.on('data', d => {
1994
2078
  md5sum.update(d);
1995
2079
  });
@@ -2007,15 +2091,16 @@ var md5 = {
2007
2091
  fileMd5: fileMd5$1
2008
2092
  };
2009
2093
 
2010
- const fs$7 = require$$0__default$2;
2094
+ const fs$8 = require$$0__default$2;
2011
2095
  const semver$1 = require$$1__default$7;
2012
2096
  const {
2013
- resolve: resolve$a
2097
+ resolve: resolve$b,
2098
+ getAbsolutePath: getAbsolutePath$2
2014
2099
  } = widgets;
2015
2100
  const path$7 = require$$1__default$2;
2016
2101
  const shelljs$4 = require$$0__default$3;
2017
2102
  const {
2018
- handleError: handleError$2
2103
+ handleError: handleError$1
2019
2104
  } = handleError_1;
2020
2105
 
2021
2106
  const getLatestVersion = npmName => {
@@ -2024,22 +2109,22 @@ const getLatestVersion = npmName => {
2024
2109
  }; // 收集package.json
2025
2110
 
2026
2111
 
2027
- function collectHasPackageJson(modules, cwd, outputDir) {
2112
+ function collectPackageJson(subPackages, cwd, outputDir) {
2028
2113
  const packageJsonName = 'package.json'; // 查找文件名
2029
2114
  // 1.1根目录的package.json
2030
2115
 
2031
2116
  const packageArr = [{
2032
2117
  srcPackageDir: path$7.join(cwd, packageJsonName),
2033
- destNpmDir: resolve$a(outputDir, 'node_modules')
2118
+ destNpmDir: resolve$b(outputDir, 'node_modules')
2034
2119
  }]; // 1.2模块的package.json
2035
2120
 
2036
- modules.forEach(item => {
2037
- const srcPackageDir = path$7.join(cwd, item.path, 'package.json');
2121
+ subPackages.forEach(item => {
2122
+ const srcPackageDir = `${getAbsolutePath$2(item.path)}/package.json`;
2038
2123
 
2039
- if (fs$7.existsSync(srcPackageDir)) {
2124
+ if (fs$8.existsSync(srcPackageDir)) {
2040
2125
  packageArr.push({
2041
2126
  srcPackageDir,
2042
- destNpmDir: resolve$a(outputDir, item.root, 'node_modules')
2127
+ destNpmDir: resolve$b(outputDir, item.root, 'node_modules')
2043
2128
  });
2044
2129
  }
2045
2130
  });
@@ -2048,30 +2133,30 @@ function collectHasPackageJson(modules, cwd, outputDir) {
2048
2133
 
2049
2134
 
2050
2135
  function readPackageDependencies(srcPackageDir) {
2051
- const packageJson = fs$7.readFileSync(srcPackageDir, 'utf-8');
2136
+ const packageJson = fs$8.readFileSync(srcPackageDir, 'utf-8');
2052
2137
  let dependencies = {};
2053
2138
 
2054
2139
  try {
2055
2140
  const json = packageJson ? JSON.parse(packageJson) : {};
2056
2141
  dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
2057
2142
  } catch (e) {
2058
- handleError$2(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2143
+ handleError$1(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2059
2144
  }
2060
2145
 
2061
2146
  return dependencies;
2062
2147
  }
2063
2148
  /**
2064
2149
  * 检查package.json的依赖大于node_module的版本,则返回true
2065
- * @param {*} modules 模块
2150
+ * @param {*} subPackages 模块
2066
2151
  * @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
2067
2152
  * @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
2068
2153
  * @returns
2069
2154
  */
2070
2155
 
2071
2156
 
2072
- const isDependenciesUpdate$1 = (modules, cwd, outputDir) => {
2157
+ const isDependenciesUpdate$1 = (subPackages, cwd, outputDir) => {
2073
2158
  // 步骤1. 收集package.json
2074
- const packageArr = collectHasPackageJson(modules, cwd, outputDir); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
2159
+ const packageArr = collectPackageJson(subPackages, cwd, outputDir); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
2075
2160
 
2076
2161
  return checkPackageVersion$1(packageArr);
2077
2162
  }; // 比较package.json的依赖与node_modules依赖的版本号
@@ -2085,13 +2170,13 @@ const checkPackageVersion$1 = packageArr => {
2085
2170
  for (const key of dependenciesKeys) {
2086
2171
  const depPath = path$7.join(item.destNpmDir, key);
2087
2172
 
2088
- if (!fs$7.existsSync(depPath)) {
2173
+ if (!fs$8.existsSync(depPath)) {
2089
2174
  return true;
2090
2175
  }
2091
2176
 
2092
2177
  const depPackagePath = path$7.join(depPath, 'package.json');
2093
2178
 
2094
- if (fs$7.existsSync(depPackagePath)) {
2179
+ if (fs$8.existsSync(depPackagePath)) {
2095
2180
  const packageData = require(depPackagePath);
2096
2181
 
2097
2182
  if (dependencies[key] === 'latest') {
@@ -2118,12 +2203,13 @@ var checkDependencies = {
2118
2203
  };
2119
2204
 
2120
2205
  const shelljs$3 = require$$0__default$3;
2121
- const fs$6 = require$$0__default$2;
2206
+ const fs$7 = require$$0__default$2;
2122
2207
  const path$6 = require$$1__default$2;
2123
2208
  const io$1 = io$3;
2124
2209
  const {
2125
2210
  createTask: createTask$1,
2126
- resolve: resolve$9
2211
+ resolve: resolve$a,
2212
+ getAbsolutePath: getAbsolutePath$1
2127
2213
  } = widgets;
2128
2214
  const {
2129
2215
  buildMpNpm
@@ -2134,12 +2220,11 @@ const {
2134
2220
  } = cache;
2135
2221
  const {
2136
2222
  CACHE_DIR: CACHE_DIR$1
2137
- } = require$$4;
2223
+ } = require$$5;
2138
2224
  const {
2139
2225
  npmInstallAll
2140
2226
  } = npm;
2141
2227
  const {
2142
- fail: fail$5,
2143
2228
  info: info$7
2144
2229
  } = log$1;
2145
2230
  const {
@@ -2149,24 +2234,24 @@ const {
2149
2234
  isDependenciesUpdate
2150
2235
  } = checkDependencies;
2151
2236
 
2152
- async function install$2(tmsConfig, modules, useCache = true) {
2237
+ async function install$2(tmsConfig, subPackages, useCache = true) {
2153
2238
  const cwd = process.cwd();
2154
- const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, modules, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2239
+ const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2155
2240
 
2156
2241
  if (!npmInstallRes.isCache) {
2157
2242
  // 构建miniprogram_npm, 不使用缓存
2158
- await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, modules, false);
2243
+ await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
2159
2244
  } else {
2160
2245
  // 构建miniprogram_npm
2161
- await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, modules, useCache);
2246
+ await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2162
2247
  }
2163
2248
 
2164
2249
  shelljs$3.cd(cwd);
2165
2250
  }
2166
2251
 
2167
- async function npmInstall(tmsConfig, modules, useCache) {
2252
+ async function npmInstall(tmsConfig, subPackages, useCache) {
2168
2253
  // 如果依赖没有更新和使用缓存数据(则命中缓存)
2169
- if (!isDependenciesUpdate(modules, resolve$9('./'), tmsConfig.outputDir) && useCache) {
2254
+ if (!isDependenciesUpdate(subPackages, resolve$a('./'), tmsConfig.outputDir) && useCache) {
2170
2255
  info$7('node_modules命中缓存');
2171
2256
  return {
2172
2257
  isCache: true
@@ -2174,37 +2259,31 @@ async function npmInstall(tmsConfig, modules, useCache) {
2174
2259
  } // 拷贝模块的package.json到编译输出目录
2175
2260
 
2176
2261
 
2177
- modules.forEach(item => {
2178
- const outputModuleDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
2179
-
2180
- if (!fs$6.existsSync(resolve$9(item.path))) {
2181
- fail$5(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2182
- process.exit(1);
2183
- }
2184
-
2262
+ subPackages.forEach(item => {
2263
+ const outputModuleDir = resolve$a(`${tmsConfig.outputDir}/${item.root}`);
2185
2264
  io$1.ensureDirExist(outputModuleDir);
2186
- const modulePackagePath = resolve$9(item.path, 'package.json');
2187
- if (fs$6.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
2265
+ const modulePackagePath = `${getAbsolutePath$1(item.path)}/package.json`;
2266
+ if (fs$7.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
2188
2267
  });
2189
- await npmInstallAll(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
2268
+ await npmInstallAll(subPackages, resolve$a(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
2190
2269
  return {
2191
2270
  isCache: false
2192
2271
  };
2193
2272
  } // 构建miniprogram_npm
2194
2273
 
2195
2274
 
2196
- async function mpCiInstall(tmsConfig, modules, useCache) {
2275
+ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2197
2276
  const packageJsonFiles = [];
2198
- const rootPackFile = resolve$9(`${tmsConfig.outputDir}/package.json`);
2277
+ const rootPackFile = resolve$a(`${tmsConfig.outputDir}/package.json`);
2199
2278
 
2200
- if (fs$6.existsSync(rootPackFile)) {
2279
+ if (fs$7.existsSync(rootPackFile)) {
2201
2280
  packageJsonFiles.push(rootPackFile);
2202
2281
  }
2203
2282
 
2204
- modules.forEach(item => {
2205
- const packageJsonFile = resolve$9(`${tmsConfig.outputDir}/${item.root}/package.json`);
2283
+ subPackages.forEach(item => {
2284
+ const packageJsonFile = resolve$a(`${tmsConfig.outputDir}/${item.root}/package.json`);
2206
2285
 
2207
- if (fs$6.existsSync(packageJsonFile)) {
2286
+ if (fs$7.existsSync(packageJsonFile)) {
2208
2287
  packageJsonFiles.push(packageJsonFile);
2209
2288
  }
2210
2289
  });
@@ -2218,7 +2297,7 @@ async function mpCiInstall(tmsConfig, modules, useCache) {
2218
2297
  let flag = true;
2219
2298
  await Promise.all(packageJsonFiles.map(async item => {
2220
2299
  const packageDir = path$6.dirname(item);
2221
- const mpDir = resolve$9(`${packageDir}/miniprogram_npm`);
2300
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2222
2301
  const md5Value = await getMNPMd5(packageDir);
2223
2302
  const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
2224
2303
  // 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
@@ -2238,7 +2317,7 @@ async function mpCiInstall(tmsConfig, modules, useCache) {
2238
2317
 
2239
2318
  await Promise.all(packageJsonFiles.map(async item => {
2240
2319
  const packageDir = path$6.dirname(item);
2241
- const mpDir = resolve$9(`${packageDir}/miniprogram_npm`);
2320
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2242
2321
  setCache(mpDir, 'miniprogram_npm', {
2243
2322
  md5: '',
2244
2323
  status: statusMap.doing
@@ -2246,13 +2325,13 @@ async function mpCiInstall(tmsConfig, modules, useCache) {
2246
2325
  }));
2247
2326
  await buildMpNpm({
2248
2327
  appId: tmsConfig.appId,
2249
- projectPath: resolve$9('./'),
2328
+ projectPath: resolve$a('./'),
2250
2329
  privateKey: tmsConfig.privateKey
2251
2330
  }); // 构建成功后,计算md5写入cache
2252
2331
 
2253
2332
  await Promise.all(packageJsonFiles.map(async item => {
2254
2333
  const packageDir = path$6.dirname(item);
2255
- const mpDir = resolve$9(`${packageDir}/miniprogram_npm`);
2334
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2256
2335
  const md5Value = await getMNPMd5(packageDir);
2257
2336
  setCache(mpDir, 'miniprogram_npm', {
2258
2337
  md5: md5Value,
@@ -2269,7 +2348,7 @@ async function getMNPMd5(cwd) {
2269
2348
  };
2270
2349
  shelljs$3.cd(cwd);
2271
2350
 
2272
- if (fs$6.existsSync('miniprogram_npm')) {
2351
+ if (fs$7.existsSync('miniprogram_npm')) {
2273
2352
  shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2274
2353
  cwd,
2275
2354
  ...shellJsOption
@@ -2286,10 +2365,10 @@ async function getMNPMd5(cwd) {
2286
2365
  var install_1 = install$2;
2287
2366
 
2288
2367
  const shelljs$2 = require$$0__default$3;
2289
- const fs$5 = require$$0__default$2;
2368
+ const fs$6 = require$$0__default$2;
2290
2369
  const io = io$3;
2291
2370
  const {
2292
- resolve: resolve$8,
2371
+ resolve: resolve$9,
2293
2372
  createTask
2294
2373
  } = widgets;
2295
2374
  const {
@@ -2298,7 +2377,7 @@ const {
2298
2377
  const {
2299
2378
  MODULE_CODE_DIR,
2300
2379
  DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
2301
- } = require$$4;
2380
+ } = require$$5;
2302
2381
  const {
2303
2382
  cloneModules
2304
2383
  } = cloneModules_1;
@@ -2320,48 +2399,26 @@ const install$1 = install_1;
2320
2399
  */
2321
2400
 
2322
2401
  const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2323
- const outputDir = resolve$8(tmsConfig.outputDir);
2402
+ const outputDir = resolve$9(tmsConfig.outputDir);
2324
2403
  io.ensureDirExist(outputDir);
2325
2404
  defaultFiles.forEach(item => {
2326
- if (fs$5.existsSync(resolve$8(item))) {
2327
- shelljs$2.cp('-rf', resolve$8(item), resolve$8(tmsConfig.outputDir, item));
2405
+ if (fs$6.existsSync(resolve$9(item))) {
2406
+ shelljs$2.cp('-rf', resolve$9(item), resolve$9(tmsConfig.outputDir, item));
2328
2407
  }
2329
2408
  });
2330
2409
  };
2331
- /**
2332
- * 校验相关配置项
2333
- * @param {*} targetModules
2334
- * @returns
2335
- */
2336
-
2337
-
2338
- function checkConfig(targetModules) {
2339
- for (const item of targetModules) {
2340
- if (!item.root) {
2341
- throw new Error(`检查${item.name} module.config.json的root字段`);
2342
- } // 判断源码目录是否有该模块
2343
-
2344
-
2345
- if (item.path && !fs$5.existsSync(resolve$8(item.path))) {
2346
- throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2347
- }
2348
- }
2349
-
2350
- return true;
2351
- }
2352
2410
 
2353
2411
  async function task(tmsConfig, targetModules) {
2354
2412
  // 下载和移动代码
2355
- await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$8('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2413
+ await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$9('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2356
2414
 
2357
2415
  const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
2358
2416
 
2359
- const newSubPackages = getSubPackages$2(newModules);
2360
- checkConfig(newSubPackages); // 拷贝相关配置文件到输出目录
2417
+ const newSubPackages = getSubPackages$2(newModules); // 拷贝相关配置文件到输出目录
2361
2418
 
2362
2419
  await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
2363
2420
 
2364
- await install$1(tmsConfig, newSubPackages); // 动态生成编译后的app.json;
2421
+ await install$1(tmsConfig, newSubPackages, true); // 动态生成编译后的app.json;
2365
2422
 
2366
2423
  await createTask(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2367
2424
  return {
@@ -2370,19 +2427,19 @@ async function task(tmsConfig, targetModules) {
2370
2427
  };
2371
2428
  }
2372
2429
 
2373
- async function init$5(tmsConfig, targetModules) {
2430
+ async function init$3(tmsConfig, targetModules) {
2374
2431
  try {
2375
2432
  const taskRes = await task(tmsConfig, targetModules);
2376
2433
  return taskRes;
2377
2434
  } catch (error) {
2378
2435
  const errMsg = typeof error === 'object' ? error.message : error;
2379
- fail$4(`初始化流程出现错误${errMsg}`);
2436
+ fail$4(`初始化流程出现错误: ${errMsg}`);
2380
2437
  info$6('详细的错误信息', error);
2381
2438
  process.exit(1);
2382
2439
  }
2383
2440
  }
2384
2441
 
2385
- var init_1 = init$5;
2442
+ var init_1 = init$3;
2386
2443
 
2387
2444
  /* eslint-disable no-param-reassign */
2388
2445
  const strip = require$$0__default$8; // 匹配规则
@@ -2451,9 +2508,9 @@ const {
2451
2508
  diffContentCopyFile: diffContentCopyFile$2
2452
2509
  } = io$3;
2453
2510
  const {
2454
- resolve: resolve$7
2511
+ resolve: resolve$8
2455
2512
  } = widgets;
2456
- const fs$4 = require$$0__default$2;
2513
+ const fs$5 = require$$0__default$2;
2457
2514
  const {
2458
2515
  pluginError: pluginError$2
2459
2516
  } = pluginError_1;
@@ -2466,7 +2523,7 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2466
2523
  let contents = '';
2467
2524
 
2468
2525
  try {
2469
- contents = fs$4.readFileSync(anaFileOriginFile, 'utf8');
2526
+ contents = fs$5.readFileSync(anaFileOriginFile, 'utf8');
2470
2527
  } catch (e) {
2471
2528
  pluginError$2(e, isWatch);
2472
2529
  }
@@ -2483,12 +2540,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2483
2540
  extPath
2484
2541
  } = ext$2(depOriginPath, extensions);
2485
2542
 
2486
- if (!fs$4.existsSync(depOriginFile)) {
2543
+ if (!fs$5.existsSync(depOriginFile)) {
2487
2544
  pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
2488
2545
  return;
2489
2546
  }
2490
2547
 
2491
- const depDestPath = resolve$7(path$5.dirname(anaFileDestFile), depItem);
2548
+ const depDestPath = resolve$8(path$5.dirname(anaFileDestFile), depItem);
2492
2549
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2493
2550
 
2494
2551
  if (!resDep.has(depDestFile)) {
@@ -2512,8 +2569,8 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2512
2569
  const stream = through$2.obj(function (file, enc, cb) {
2513
2570
  // 依赖分析的文件
2514
2571
  const anaFileOriginFile = file.history[0];
2515
- const anaFileRelativeModule = path$5.relative(resolve$7(module.from), anaFileOriginFile);
2516
- const anaFileDestFile = resolve$7(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2572
+ const anaFileRelativeModule = path$5.relative(resolve$8(module.from), anaFileOriginFile);
2573
+ const anaFileDestFile = resolve$8(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2517
2574
 
2518
2575
  if (file.isBuffer()) {
2519
2576
  let contents = String(file.contents);
@@ -2542,7 +2599,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2542
2599
  const regRes = depItem.match(reg) || [];
2543
2600
 
2544
2601
  if (regRes[2]) {
2545
- const depDestPath = resolve$7(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2602
+ const depDestPath = resolve$8(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2546
2603
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2547
2604
 
2548
2605
  if (!copyModules.has(depDestFile)) {
@@ -2595,9 +2652,9 @@ const {
2595
2652
  diffContentCopyFile: diffContentCopyFile$1
2596
2653
  } = io$3;
2597
2654
  const {
2598
- resolve: resolve$6
2655
+ resolve: resolve$7
2599
2656
  } = widgets;
2600
- const fs$3 = require$$0__default$2;
2657
+ const fs$4 = require$$0__default$2;
2601
2658
  const {
2602
2659
  pluginError: pluginError$1
2603
2660
  } = pluginError_1;
@@ -2609,8 +2666,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2609
2666
  const stream = through$1.obj(function (file, enc, cb) {
2610
2667
  // 当前分析的文件的路径
2611
2668
  const anaFileOriginFile = file.history[0];
2612
- const anaFileRelativeModule = path$4.relative(resolve$6(module.from), anaFileOriginFile);
2613
- const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2669
+ const anaFileRelativeModule = path$4.relative(resolve$7(module.from), anaFileOriginFile);
2670
+ const anaFileDestFile = resolve$7(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2614
2671
 
2615
2672
  if (file.isBuffer()) {
2616
2673
  let contents = String(file.contents);
@@ -2649,7 +2706,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2649
2706
  const regRes = componentPath.match(reg) || [];
2650
2707
 
2651
2708
  if (regRes[2]) {
2652
- const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2709
+ const depDestPath = resolve$7(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2653
2710
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2654
2711
 
2655
2712
  if (!copyModules.has(depDestFile)) {
@@ -2683,7 +2740,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2683
2740
  const originFile = depOriginFile.replace(depOriginExt, extKey);
2684
2741
  const destFile = depDestFile.replace(depOriginExt, extKey);
2685
2742
 
2686
- if (fs$3.existsSync(originFile)) {
2743
+ if (fs$4.existsSync(originFile)) {
2687
2744
  diffContentCopyFile$1(originFile, destFile);
2688
2745
  const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
2689
2746
 
@@ -2717,7 +2774,7 @@ var mpJsonDep_1 = {
2717
2774
  /* eslint-disable no-param-reassign */
2718
2775
  const through = require$$0__default$9;
2719
2776
  const htmlparser2 = require$$1__default$9;
2720
- const fs$2 = require$$0__default$2;
2777
+ const fs$3 = require$$0__default$2;
2721
2778
  const path$3 = require$$1__default$2;
2722
2779
  const {
2723
2780
  diffContentCopyFile,
@@ -2725,7 +2782,7 @@ const {
2725
2782
  fileInDir
2726
2783
  } = io$3;
2727
2784
  const {
2728
- resolve: resolve$5
2785
+ resolve: resolve$6
2729
2786
  } = widgets;
2730
2787
  const {
2731
2788
  dfsFindCommonDep
@@ -2764,7 +2821,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2764
2821
  let contents = '';
2765
2822
 
2766
2823
  try {
2767
- contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
2824
+ contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
2768
2825
  } catch (e) {
2769
2826
  pluginError(e, isWatch);
2770
2827
  }
@@ -2782,7 +2839,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2782
2839
  extPath
2783
2840
  } = extFile(name, depOriginPath);
2784
2841
 
2785
- if (!fs$2.existsSync(depOriginFile)) {
2842
+ if (!fs$3.existsSync(depOriginFile)) {
2786
2843
  pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
2787
2844
  return;
2788
2845
  }
@@ -2839,8 +2896,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2839
2896
  const stream = through.obj(function (file, enc, cb) {
2840
2897
  // 依赖分析的文件
2841
2898
  const anaFileOriginFile = file.history[0];
2842
- const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
2843
- const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2899
+ const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
2900
+ const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2844
2901
 
2845
2902
  if (file.isBuffer()) {
2846
2903
  let contents = String(file.contents);
@@ -2871,7 +2928,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2871
2928
  const regRes = attributes.src.match(reg) || [];
2872
2929
 
2873
2930
  if (regRes[2]) {
2874
- const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2931
+ const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2875
2932
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
2876
2933
 
2877
2934
  if (!copyModules.has(depDestFile)) {
@@ -2898,7 +2955,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2898
2955
  beforeDepPath,
2899
2956
  afterDepPath
2900
2957
  }) => {
2901
- if (fs$2.existsSync(depOriginFile)) {
2958
+ if (fs$3.existsSync(depOriginFile)) {
2902
2959
  diffContentCopyFile(depOriginFile, depDestFile);
2903
2960
  const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
2904
2961
  contents = contents.replace(reg, `"${afterDepPath}"`);
@@ -3271,7 +3328,7 @@ const {
3271
3328
  fail: fail$1
3272
3329
  } = log$1;
3273
3330
  const {
3274
- resolve: resolve$4
3331
+ resolve: resolve$5
3275
3332
  } = widgets;
3276
3333
  const {
3277
3334
  global: global$2
@@ -3317,8 +3374,8 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
3317
3374
  };
3318
3375
 
3319
3376
  const getTargetFile = (sourceFile, module, outputDir) => {
3320
- const sourceFileRelativeModule = path$1.relative(resolve$4(module.from), sourceFile);
3321
- const targetFile = resolve$4(outputDir, module.to, sourceFileRelativeModule);
3377
+ const sourceFileRelativeModule = path$1.relative(resolve$5(module.from), sourceFile);
3378
+ const targetFile = resolve$5(outputDir, module.to, sourceFileRelativeModule);
3322
3379
  return targetFile;
3323
3380
  };
3324
3381
 
@@ -3360,7 +3417,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3360
3417
  };
3361
3418
 
3362
3419
  const path = require$$1__default$2;
3363
- const fs$1 = require$$0__default$2;
3420
+ const fs$2 = require$$0__default$2;
3364
3421
  const ora = require$$2__default;
3365
3422
  const chalk$2 = require$$0__default;
3366
3423
  const {
@@ -3368,16 +3425,17 @@ const {
3368
3425
  series
3369
3426
  } = require$$0__default$a;
3370
3427
  const {
3371
- resolve: resolve$3,
3428
+ resolve: resolve$4,
3372
3429
  mergeMap,
3373
- filterField: filterField$2
3430
+ filterField: filterField$2,
3431
+ getAbsolutePath
3374
3432
  } = widgets;
3375
3433
  const {
3376
3434
  buildOutputAppJson
3377
3435
  } = buildAppJson;
3378
3436
  const {
3379
3437
  DEFAULT_COPY_CONFIG
3380
- } = require$$4;
3438
+ } = require$$5;
3381
3439
  const compile = compile$1;
3382
3440
  const watch = watch_1;
3383
3441
  const {
@@ -3406,75 +3464,69 @@ function excludeGlob(glob) {
3406
3464
  return Array.from(otherArr);
3407
3465
  }
3408
3466
 
3409
- function adaptPath(pathDir, cwd = '') {
3410
- let newPath = pathDir;
3411
- newPath = newPath.startsWith('/') ? newPath : resolve$3(cwd, newPath);
3412
- newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
3413
- return newPath;
3414
- }
3415
-
3416
- var dev$3 = async (tmsConfig, modules, subPackages, isDev = true) => {
3467
+ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3417
3468
  const compileTasksMap = new Map(); // 监听根目录的文件
3418
3469
 
3419
3470
  mergeMap(compileTasksMap, compile(tmsConfig, {
3420
3471
  glob: {
3421
- json: DEFAULT_COPY_CONFIG.map(item => resolve$3(item))
3472
+ json: DEFAULT_COPY_CONFIG.map(item => resolve$4(item))
3422
3473
  },
3423
3474
  module: {
3424
- from: resolve$3(),
3425
- to: resolve$3(tmsConfig.outputDir)
3475
+ from: resolve$4(),
3476
+ to: resolve$4(tmsConfig.outputDir)
3426
3477
  },
3427
- destPath: resolve$3(tmsConfig.outputDir),
3478
+ destPath: resolve$4(tmsConfig.outputDir),
3428
3479
  srcOption: {
3429
3480
  allowEmpty: true
3430
3481
  },
3431
3482
  isDev
3432
3483
  })); // 监听模块的文件
3433
3484
 
3434
- for (let pkg of subPackages) {
3485
+ for (let moduleItem of modules) {
3435
3486
  // 处理默认参数
3436
- pkg = { ...{
3487
+ moduleItem = { ...{
3437
3488
  exclude: []
3438
3489
  },
3439
- ...pkg
3490
+ ...moduleItem
3440
3491
  };
3441
- const packagePath = adaptPath(pkg.path);
3492
+ const srcModulePath = getAbsolutePath(moduleItem.path);
3493
+ const buildModulePath = resolve$4(tmsConfig.outputDir, moduleItem.modulePath);
3442
3494
 
3443
3495
  if (isDev) {
3444
3496
  // 监听模块配置文件
3445
- watch([`${packagePath}/**/module.config.json`], {
3497
+ watch([`${srcModulePath}/**/module.config.json`], {
3446
3498
  events: watchEvents
3447
3499
  }, () => buildOutputAppJson(tmsConfig, modules, isDev), {
3448
- from: packagePath,
3449
- to: packagePath
3500
+ from: srcModulePath,
3501
+ to: buildModulePath
3450
3502
  });
3451
3503
  }
3452
3504
 
3453
- const excludes = pkg.exclude.map(ePath => {
3454
- const newPath = adaptPath(ePath, packagePath);
3505
+ const excludes = moduleItem.exclude.map(ePath => {
3506
+ const newPath = getAbsolutePath(ePath, srcModulePath);
3455
3507
  const ext = path.extname(ePath).slice(1);
3456
3508
 
3457
3509
  if (ext) {
3458
- return `!${resolve$3(packagePath, newPath)}`;
3510
+ return `!${resolve$4(srcModulePath, newPath)}`;
3459
3511
  }
3460
3512
 
3461
- return `!${resolve$3(packagePath, newPath)}/**/*`;
3513
+ return `!${resolve$4(srcModulePath, newPath)}/**/*`;
3462
3514
  });
3463
3515
  const glob = {
3464
- js: [`${packagePath}/**/*.{js,ts,wxs}`, ...excludes],
3465
- json: [`${packagePath}/**/*.json`, `!${packagePath}/**/module.config.json`, ...excludes],
3466
- wxss: [`${packagePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
3467
- wxml: [`${packagePath}/**/*.wxml`, ...excludes],
3468
- image: [`${packagePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
3516
+ js: [`${srcModulePath}/**/*.{js,ts,wxs}`, ...excludes],
3517
+ json: [`${srcModulePath}/**/*.json`, `!${srcModulePath}/**/module.config.json`, ...excludes],
3518
+ wxss: [`${srcModulePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
3519
+ wxml: [`${srcModulePath}/**/*.wxml`, ...excludes],
3520
+ image: [`${srcModulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
3469
3521
  };
3470
3522
  mergeMap(compileTasksMap, compile(tmsConfig, {
3471
3523
  glob: { ...glob,
3472
- other: [`${packagePath}/**/*`, ...excludeGlob(glob)]
3524
+ other: [`${srcModulePath}/**/*`, ...excludeGlob(glob)]
3473
3525
  },
3474
- destPath: resolve$3(tmsConfig.outputDir, pkg.root),
3526
+ destPath: buildModulePath,
3475
3527
  module: {
3476
- from: pkg.path,
3477
- to: pkg.root
3528
+ from: srcModulePath,
3529
+ to: buildModulePath
3478
3530
  },
3479
3531
  srcOption: {
3480
3532
  allowEmpty: true
@@ -3486,8 +3538,8 @@ var dev$3 = async (tmsConfig, modules, subPackages, isDev = true) => {
3486
3538
 
3487
3539
  if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
3488
3540
  for (const item of tmsConfig.static) {
3489
- item.from = adaptPath(item.from);
3490
- item.to = adaptPath(item.to);
3541
+ item.from = getAbsolutePath(item.from);
3542
+ item.to = getAbsolutePath(item.to);
3491
3543
  let glob = {};
3492
3544
  const ext = path.extname(item.from).slice(1);
3493
3545
 
@@ -3504,7 +3556,7 @@ var dev$3 = async (tmsConfig, modules, subPackages, isDev = true) => {
3504
3556
  glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
3505
3557
  }
3506
3558
 
3507
- const from = fs$1.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
3559
+ const from = fs$2.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
3508
3560
  mergeMap(compileTasksMap, compile(tmsConfig, {
3509
3561
  glob,
3510
3562
  destPath: item.to,
@@ -3536,12 +3588,12 @@ var dev$3 = async (tmsConfig, modules, subPackages, isDev = true) => {
3536
3588
 
3537
3589
  if (isDev) {
3538
3590
  // 监听app.json
3539
- watch([resolve$3('app.json')], {
3591
+ watch([resolve$4('app.json')], {
3540
3592
  ignoreInitial: false,
3541
3593
  events: watchEvents
3542
3594
  }, () => buildOutputAppJson(tmsConfig, modules, isDev), {
3543
- from: resolve$3(),
3544
- to: resolve$3(tmsConfig.outputDir)
3595
+ from: resolve$4(),
3596
+ to: resolve$4(tmsConfig.outputDir)
3545
3597
  }); // 监听其他文件
3546
3598
 
3547
3599
  compileTasksMap.forEach(({
@@ -3587,10 +3639,10 @@ var dev$3 = async (tmsConfig, modules, subPackages, isDev = true) => {
3587
3639
  const shelljs$1 = require$$0__default$3;
3588
3640
  const compileDev = dev$3;
3589
3641
  const {
3590
- resolve: resolve$2,
3642
+ resolve: resolve$3,
3591
3643
  filterField: filterField$1
3592
3644
  } = widgets;
3593
- const init$4 = init_1;
3645
+ const init$2 = init_1;
3594
3646
  const {
3595
3647
  getModulesByMergeDepModules: getModulesByMergeDepModules$1,
3596
3648
  getSubPackages: getSubPackages$1
@@ -3603,7 +3655,7 @@ const {
3603
3655
  } = global_1;
3604
3656
  const {
3605
3657
  CACHE_DIR
3606
- } = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3658
+ } = require$$5; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3607
3659
 
3608
3660
  function delOtherPackages(tmsConfig, targetSubPackages) {
3609
3661
  // 获取所有模块,合并模块依赖的模块
@@ -3613,7 +3665,7 @@ function delOtherPackages(tmsConfig, targetSubPackages) {
3613
3665
  const targetSubPackagesName = targetSubPackages.map(item => item.name);
3614
3666
  allSubPackages.forEach(item => {
3615
3667
  if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
3616
- const moduleRootDir = resolve$2(`${tmsConfig.outputDir}/${item.root}`);
3668
+ const moduleRootDir = resolve$3(`${tmsConfig.outputDir}/${item.root}`);
3617
3669
  shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
3618
3670
  silent: true
3619
3671
  }); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
@@ -3630,7 +3682,7 @@ async function dev$2(tmsConfig, targetModules) {
3630
3682
  } = global$1.getData('cmd');
3631
3683
 
3632
3684
  if (noCache) {
3633
- shelljs$1.rm('-rf', resolve$2(tmsConfig.outputDir));
3685
+ shelljs$1.rm('-rf', resolve$3(tmsConfig.outputDir));
3634
3686
  shelljs$1.rm('-rf', CACHE_DIR);
3635
3687
  } // 初始化操作
3636
3688
 
@@ -3638,7 +3690,7 @@ async function dev$2(tmsConfig, targetModules) {
3638
3690
  const {
3639
3691
  subPackages,
3640
3692
  modules: newModules
3641
- } = await init$4(tmsConfig, targetModules);
3693
+ } = await init$2(tmsConfig, targetModules);
3642
3694
  info$3('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3643
3695
 
3644
3696
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
@@ -3651,34 +3703,33 @@ async function dev$2(tmsConfig, targetModules) {
3651
3703
  }));
3652
3704
  }
3653
3705
  delOtherPackages(tmsConfig, subPackages);
3654
- compileDev(tmsConfig, newModules, subPackages, true);
3706
+ compileDev(tmsConfig, newModules, true);
3655
3707
  }
3656
3708
 
3657
3709
  var dev_1 = dev$2;
3658
3710
 
3659
3711
  const dev$1 = dev$3;
3660
3712
 
3661
- var build$2 = async (tmsConfig, newModules, subPackages, isDev) => {
3662
- dev$1(tmsConfig, newModules, subPackages, isDev);
3713
+ var build$2 = async (tmsConfig, newModules, isDev) => {
3714
+ dev$1(tmsConfig, newModules, isDev);
3663
3715
  };
3664
3716
 
3665
3717
  const shelljs = require$$0__default$3;
3666
3718
  const {
3667
- resolve: resolve$1,
3719
+ resolve: resolve$2,
3668
3720
  filterField
3669
3721
  } = widgets;
3670
- const init$3 = init_1;
3722
+ const init$1 = init_1;
3671
3723
  const compileBuild = build$2;
3672
3724
 
3673
3725
  async function build$1(tmsConfig, targetModules) {
3674
3726
  var _tmsConfig$hooks;
3675
3727
 
3676
3728
  // 开始构建前,清理输出目录
3677
- await shelljs.rm('-rf', resolve$1(tmsConfig.outputDir));
3729
+ await shelljs.rm('-rf', resolve$2(tmsConfig.outputDir));
3678
3730
  const {
3679
- modules: newModules,
3680
- subPackages
3681
- } = await init$3(tmsConfig, targetModules);
3731
+ modules: newModules
3732
+ } = await init$1(tmsConfig, targetModules);
3682
3733
  const isDev = false;
3683
3734
 
3684
3735
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
@@ -3690,23 +3741,21 @@ async function build$1(tmsConfig, targetModules) {
3690
3741
  modules: newModules
3691
3742
  }));
3692
3743
  }
3693
- compileBuild(tmsConfig, newModules, subPackages, isDev);
3744
+ compileBuild(tmsConfig, newModules, isDev);
3694
3745
  }
3695
3746
 
3696
3747
  var build_1 = build$1;
3697
3748
 
3698
- const fs = require$$0__default$2;
3749
+ const fs$1 = require$$0__default$2;
3699
3750
  const {
3700
- resolve
3751
+ resolve: resolve$1
3701
3752
  } = widgets;
3702
- const {
3703
- handleError: handleError$1
3704
- } = handleError_1;
3705
3753
  const {
3706
3754
  ensureDirExist
3707
3755
  } = io$3;
3708
3756
  const {
3709
- warn
3757
+ warn,
3758
+ succeed
3710
3759
  } = log$1;
3711
3760
  /**
3712
3761
  * 根据相关配置创建软链接
@@ -3714,26 +3763,25 @@ const {
3714
3763
  */
3715
3764
 
3716
3765
  const symLink$1 = tmsConfig => {
3717
- try {
3718
- ensureDirExist(resolve(tmsConfig.cloudDir));
3766
+ ensureDirExist(resolve$1(tmsConfig.cloudDir));
3719
3767
 
3720
- if (tmsConfig.cloudModules) {
3721
- tmsConfig.cloudModules.forEach(item => {
3722
- const sourcePath = resolve(item.path);
3723
- const targetPath = resolve(tmsConfig.cloudDir, item.name);
3768
+ if (tmsConfig.cloudModules) {
3769
+ tmsConfig.cloudModules.forEach(item => {
3770
+ const sourcePath = resolve$1(item.path);
3771
+ const targetPath = resolve$1(tmsConfig.cloudDir, item.name);
3724
3772
 
3725
- if (!fs.existsSync(sourcePath)) {
3726
- warn(`云函数${sourcePath}不存在`);
3727
- return;
3728
- }
3773
+ if (!fs$1.existsSync(sourcePath)) {
3774
+ warn(`云函数${sourcePath}不存在`);
3775
+ return;
3776
+ }
3729
3777
 
3730
- if (!fs.existsSync(targetPath)) {
3731
- fs.symlinkSync(sourcePath, targetPath);
3732
- }
3733
- });
3734
- }
3735
- } catch (e) {
3736
- handleError$1(`创建软链错误: ${e}`);
3778
+ if (!fs$1.existsSync(targetPath)) {
3779
+ fs$1.symlinkSync(sourcePath, targetPath);
3780
+ }
3781
+ });
3782
+ succeed('云函数创建软链成功');
3783
+ } else {
3784
+ warn('你没有在tms.config.js的cloudModules注册云函数');
3737
3785
  }
3738
3786
  };
3739
3787
 
@@ -3747,22 +3795,17 @@ const {
3747
3795
  const {
3748
3796
  handleError
3749
3797
  } = handleError_1;
3750
- const {
3751
- succeed
3752
- } = log$1;
3753
3798
 
3754
3799
  var cloud$1 = async tmsConfig => {
3755
3800
  try {
3756
3801
  await symLink(tmsConfig);
3757
- succeed('云函数创建软链成功');
3758
3802
  } catch (e) {
3759
3803
  handleError(`创建软链错误: ${e}`);
3760
3804
  }
3761
3805
  };
3762
3806
 
3763
3807
  /* eslint-disable no-param-reassign */
3764
- const loadash = require$$0__default$6;
3765
- const init$2 = init_1;
3808
+ const init = init_1;
3766
3809
  const dev = dev_1;
3767
3810
  const build = build_1;
3768
3811
  const install = install_1;
@@ -3775,11 +3818,10 @@ const {
3775
3818
  global
3776
3819
  } = global_1;
3777
3820
  const {
3778
- readTmsConfig,
3779
- readTmsPrivateCf,
3780
- checkModules,
3821
+ getTmsConfig: getTmsConfig$1,
3781
3822
  getModulesByMergeDepModules,
3782
- getSubPackages
3823
+ getSubPackages,
3824
+ getModulesByModuleNames
3783
3825
  } = tmsMpconfig.exports;
3784
3826
 
3785
3827
  const handleModuleArg = cmd => {
@@ -3798,7 +3840,7 @@ const handleModuleArg = cmd => {
3798
3840
  */
3799
3841
 
3800
3842
 
3801
- const getSpecificModules = (moduleArg, modules) => {
3843
+ const getSpecificModuleNames = (moduleArg, modules) => {
3802
3844
  if (moduleArg.length > 0) {
3803
3845
  return moduleArg;
3804
3846
  }
@@ -3824,80 +3866,23 @@ const getSpecificModules = (moduleArg, modules) => {
3824
3866
 
3825
3867
  return all.map(item => item.moduleName);
3826
3868
  };
3827
- /**
3828
- * 合并tms.config.js 与 tms.private.config.js的配置项
3829
- * @param {*} tmsConfig
3830
- * @param {*} tmsPrivateCf
3831
- * @returns
3832
- */
3833
-
3834
-
3835
- const mergeConfig = (tmsConfig, tmsPrivateCf) => {
3836
- const modules = {};
3837
-
3838
- if (Array.isArray(tmsConfig.modules)) {
3839
- modules.all = tmsConfig.modules;
3840
- tmsConfig.modules = modules;
3841
- } // 合并默认值
3842
-
3843
-
3844
- const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
3845
- if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
3846
- return objValue.concat(srcValue);
3847
- }
3848
- });
3849
- return res;
3850
- };
3851
3869
 
3852
3870
  async function run(commandName, cmd) {
3853
3871
  try {
3854
- // 用户本地的私有项目配置
3855
- const tmsPrivateCf = readTmsPrivateCf();
3856
- const {
3857
- env = tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : tmsPrivateCf.env
3858
- } = cmd;
3859
- let tmsConfig = readTmsConfig(env);
3860
- tmsConfig = mergeConfig(tmsConfig, tmsPrivateCf); // 处理module参数
3861
-
3862
- const specificModules = getSpecificModules(handleModuleArg(cmd), tmsConfig.modules);
3863
- const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])], true); // 获取所有模块,合并模块依赖的模块
3864
-
3865
- const newModules = getModulesByMergeDepModules(tmsConfig, modules); // 获取所有的分包
3866
-
3867
- const subPackages = getSubPackages(newModules); // 缓存数据
3872
+ // 用户本地的配置
3873
+ const tmsConfig = getTmsConfig$1(); // 缓存数据
3868
3874
 
3869
3875
  global.setData({
3870
- env,
3871
3876
  cmd,
3872
3877
  tmsConfig
3873
3878
  });
3874
3879
 
3875
- switch (commandName) {
3876
- case 'init':
3877
- init$2(tmsConfig, newModules);
3878
- return;
3879
-
3880
- case 'dev':
3881
- global.setData('isDev', true);
3882
- dev(tmsConfig, newModules);
3883
- return;
3884
-
3885
- case 'cloud':
3886
- cloud(tmsConfig);
3887
- return;
3888
-
3889
- case 'install':
3890
- install(tmsConfig, subPackages, false);
3891
- return;
3892
-
3893
- case 'build':
3894
- global.setData('isDev', false);
3895
- build(tmsConfig, newModules);
3896
- return;
3897
-
3898
- default:
3899
- return;
3880
+ if (commandName === 'cloud') {
3881
+ cloud(tmsConfig);
3882
+ return;
3900
3883
  }
3884
+
3885
+ otherCommands(tmsConfig, commandName, cmd);
3901
3886
  } catch (error) {
3902
3887
  const errMsg = typeof error === 'object' ? error.message : error;
3903
3888
  fail(`构建出现错误: ${errMsg}`);
@@ -3906,11 +3891,46 @@ async function run(commandName, cmd) {
3906
3891
  }
3907
3892
  }
3908
3893
 
3894
+ function otherCommands(tmsConfig, commandName, cmd) {
3895
+ // 处理module参数
3896
+ const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmd), tmsConfig.modules); // moduleNames => ['home', 'car']
3897
+
3898
+ const moduleNames = [...new Set([...specificModuleNames])];
3899
+ const modules = getModulesByModuleNames(tmsConfig, moduleNames, false); // 获取所有模块,合并模块依赖的模块
3900
+
3901
+ const newModules = getModulesByMergeDepModules(tmsConfig, modules, false); // 获取所有的分包
3902
+
3903
+ const subPackages = getSubPackages(newModules);
3904
+
3905
+ switch (commandName) {
3906
+ case 'init':
3907
+ init(tmsConfig, newModules);
3908
+ return;
3909
+
3910
+ case 'dev':
3911
+ global.setData('isDev', true);
3912
+ dev(tmsConfig, newModules);
3913
+ return;
3914
+
3915
+ case 'install':
3916
+ install(tmsConfig, subPackages, false);
3917
+ return;
3918
+
3919
+ case 'build':
3920
+ global.setData('isDev', false);
3921
+ build(tmsConfig, newModules);
3922
+ return;
3923
+
3924
+ default:
3925
+ return;
3926
+ }
3927
+ }
3928
+
3909
3929
  var run_1 = run;
3910
3930
 
3911
3931
  var entry = [{
3912
3932
  command: 'create <project-name>',
3913
- description: '创建新的应用',
3933
+ description: '创建项目',
3914
3934
  action: projectName => {
3915
3935
  create_1(projectName);
3916
3936
  }
@@ -3961,9 +3981,9 @@ var entry = [{
3961
3981
  ]
3962
3982
  }];
3963
3983
 
3964
- var require$$7 = {
3984
+ var require$$9 = {
3965
3985
  name: "@tmsfe/tmskit",
3966
- version: "0.0.20",
3986
+ version: "0.0.21",
3967
3987
  description: "tmskit",
3968
3988
  main: "dist/index.cjs",
3969
3989
  bin: {
@@ -4050,7 +4070,7 @@ var require$$7 = {
4050
4070
  };
4051
4071
 
4052
4072
  const semver = require$$1__default$7;
4053
- const packageJson = require$$7;
4073
+ const packageJson = require$$9;
4054
4074
  const chalk$1 = require$$0__default;
4055
4075
  const {
4056
4076
  info: info$1
@@ -4074,34 +4094,38 @@ const checkNodeVersion = (wanted, id) => {
4074
4094
  };
4075
4095
  /**
4076
4096
  * 检查运行环境
4077
- * @returns {Undefined} 无需返回值
4078
4097
  */
4079
4098
 
4080
4099
 
4081
- function initCliContext() {
4100
+ function check$1() {
4082
4101
  // 执行操作前检查node版本
4083
4102
  // 旧版本node直接提示升级,退出脚本
4084
4103
  checkNodeVersion(requiredVersion, packName);
4085
4104
  }
4086
4105
 
4087
- var init$1 = initCliContext;
4106
+ var check_1 = check$1;
4088
4107
 
4089
4108
  const chalk = require$$0__default;
4090
4109
  const commander = require$$0__default$1;
4091
4110
  const {
4092
- suggestCommands
4111
+ suggestCommands,
4112
+ resolve
4093
4113
  } = widgets;
4094
4114
  const {
4095
4115
  info
4096
4116
  } = log$1;
4117
+ const {
4118
+ getTmsConfig
4119
+ } = tmsMpconfig.exports;
4097
4120
  const {
4098
4121
  TMS_NAME
4099
- } = require$$4;
4122
+ } = require$$5;
4100
4123
  const commands = entry;
4101
- const init = init$1;
4102
- init();
4124
+ const check = check_1;
4125
+ const fs = require$$0__default$2;
4126
+ check();
4103
4127
  const program = new commander.Command(TMS_NAME);
4104
- program.version(`${TMS_NAME} ${require$$7.version}`, '-v, -V, --version');
4128
+ program.version(`${TMS_NAME} ${require$$9.version}`, '-v, -V, --version');
4105
4129
 
4106
4130
  function registerCommand(program, commands) {
4107
4131
  commands.forEach(cmd => {
@@ -4123,7 +4147,20 @@ function registerCommand(program, commands) {
4123
4147
  });
4124
4148
  }
4125
4149
 
4126
- registerCommand(program, commands);
4150
+ function register() {
4151
+ // 注册脚手架内部命令
4152
+ registerCommand(program, commands); // 注册扩展命令
4153
+
4154
+ if (fs.existsSync(resolve('tms.config.js'))) {
4155
+ const tmsConfig = getTmsConfig();
4156
+
4157
+ if (Array.isArray(tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.commands)) {
4158
+ registerCommand(program, tmsConfig.commands);
4159
+ }
4160
+ }
4161
+ }
4162
+
4163
+ register();
4127
4164
  program.on('--help', () => {
4128
4165
  info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
4129
4166
  }); // 捕获未注册的命令