@tmsfe/tmskit 0.0.5-beta.1 → 0.0.5-beta.2

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
@@ -72,8 +72,8 @@ var src$2 = {};
72
72
  const program$1 = require$$0__default;
73
73
  const leven = require$$1__default;
74
74
  const ora = require$$2__default;
75
- const path$7 = require$$1__default$1;
76
- const fs$b = require$$0__default$1;
75
+ const path$8 = require$$1__default$1;
76
+ const fs$c = require$$0__default$1;
77
77
  const shelljs$5 = require$$5__default;
78
78
  const download = require$$6__default;
79
79
  const chalk$3 = require$$0__default$2;
@@ -83,8 +83,8 @@ const shelljsOptons = {
83
83
 
84
84
  const cwd = process.cwd();
85
85
 
86
- function resolve$b(...args) {
87
- return path$7.resolve(cwd, ...args);
86
+ function resolve$c(...args) {
87
+ return path$8.resolve(cwd, ...args);
88
88
  }
89
89
  /**
90
90
  * 封装logs
@@ -153,7 +153,7 @@ function downloadRepo(dest, downloadOptions = {
153
153
  branch
154
154
  } = downloadOptions;
155
155
 
156
- if (fs$b.existsSync(dest)) {
156
+ if (fs$c.existsSync(dest)) {
157
157
  shelljs$5.rm('-rf', dest);
158
158
  }
159
159
 
@@ -185,8 +185,8 @@ function downloadRepoForGit$2(url, dest, branch) {
185
185
  const cwd = process.cwd();
186
186
  return new Promise(resolve => {
187
187
  // 如果目标目录不存在
188
- if (fs$b.existsSync(dest)) {
189
- shelljs$5.rm('-rf', path$7.join(dest));
188
+ if (fs$c.existsSync(dest)) {
189
+ shelljs$5.rm('-rf', path$8.join(dest));
190
190
  }
191
191
 
192
192
  shelljs$5.mkdir('-p', dest);
@@ -243,7 +243,7 @@ function createTask$4(task, startText, endText) {
243
243
  const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
244
244
 
245
245
  var widgets = {
246
- resolve: resolve$b,
246
+ resolve: resolve$c,
247
247
  log: log$3,
248
248
  isObject: isObject$2,
249
249
  isArray: isArray$1,
@@ -254,18 +254,18 @@ var widgets = {
254
254
  camelize
255
255
  };
256
256
 
257
- const path$6 = require('path'); // 用户目录
257
+ const path$7 = require('path'); // 用户目录
258
258
 
259
259
 
260
260
  const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
261
261
 
262
- const CACHE_DIR$1 = path$6.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
262
+ const CACHE_DIR$1 = path$7.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
263
263
 
264
- const TEMPLATE_DIR$1 = path$6.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
264
+ const TEMPLATE_DIR$1 = path$7.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
265
265
 
266
- const MODULE_CODE_DIR$1 = path$6.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
266
+ const MODULE_CODE_DIR$1 = path$7.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
267
267
 
268
- const TEMPLATE_PATH$1 = path$6.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
268
+ const TEMPLATE_PATH$1 = path$7.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
269
269
 
270
270
  const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
271
271
 
@@ -276,7 +276,7 @@ const DEFAULT_MODULE_DIR$4 = 'modules'; // 模块的配置文件的名称
276
276
  const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
277
277
 
278
278
  const DEFAULT_WEBPACK_ENTRY = {
279
- app: path$6.resolve(process.cwd(), 'app')
279
+ app: path$7.resolve(process.cwd(), 'app')
280
280
  }; // 默认从源码拷贝到编译后的配置
281
281
 
282
282
  const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
@@ -312,15 +312,15 @@ var constant = /*#__PURE__*/Object.freeze({
312
312
 
313
313
  var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
314
314
 
315
- const fs$a = require$$0__default$1;
316
- const path$5 = require$$1__default$1;
315
+ const fs$b = require$$0__default$1;
316
+ const path$6 = require$$1__default$1;
317
317
  /**
318
318
  * 判断目录是否为空
319
319
  * @param {string} dirname 目录名
320
320
  * @returns
321
321
  */
322
322
 
323
- const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files.length === 0);
323
+ const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files.length === 0);
324
324
  /**
325
325
  * 确保目录存在,不存在就创建一个
326
326
  * @param {*} dirname 目录名
@@ -328,30 +328,30 @@ const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files
328
328
 
329
329
 
330
330
  const ensureDirExist = dirname => {
331
- if (!fs$a.existsSync(dirname)) {
332
- fs$a.mkdirSync(dirname, {
331
+ if (!fs$b.existsSync(dirname)) {
332
+ fs$b.mkdirSync(dirname, {
333
333
  recursive: true
334
334
  });
335
335
  }
336
336
  }; // 复制文件
337
337
 
338
338
 
339
- const copyFile$1 = function (src, dest) {
340
- if (fs$a.existsSync(dest)) {
341
- fs$a.unlinkSync(dest);
339
+ const copyFile$2 = function (src, dest) {
340
+ if (fs$b.existsSync(dest)) {
341
+ fs$b.unlinkSync(dest);
342
342
  }
343
343
 
344
344
  const dir = dest.substr(0, dest.lastIndexOf('/'));
345
345
  ensureDirExist(dir);
346
- fs$a.copyFileSync(src, dest);
346
+ fs$b.copyFileSync(src, dest);
347
347
  }; // 添加后缀
348
348
 
349
349
 
350
- function ext$1(filePath, extensions) {
350
+ function ext$2(filePath, extensions) {
351
351
  let newFilePath = filePath;
352
352
 
353
353
  try {
354
- const stat = fs$a.lstatSync(newFilePath);
354
+ const stat = fs$b.lstatSync(newFilePath);
355
355
 
356
356
  if (stat.isDirectory()) {
357
357
  newFilePath += newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
@@ -361,7 +361,7 @@ function ext$1(filePath, extensions) {
361
361
  for (const ext of extensions) {
362
362
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
363
363
 
364
- if (fs$a.existsSync(file)) {
364
+ if (fs$b.existsSync(file)) {
365
365
  return {
366
366
  file,
367
367
  ext
@@ -373,8 +373,8 @@ function ext$1(filePath, extensions) {
373
373
  } // 判断文件是否在某个目录
374
374
 
375
375
 
376
- const fileInDir$1 = (dir, file) => {
377
- const relativePath = path$5.relative(dir, file);
376
+ const fileInDir$2 = (dir, file) => {
377
+ const relativePath = path$6.relative(dir, file);
378
378
 
379
379
  if (relativePath.startsWith('..')) {
380
380
  return false;
@@ -385,10 +385,10 @@ const fileInDir$1 = (dir, file) => {
385
385
 
386
386
  var io$2 = {
387
387
  isDirEmpty,
388
- copyFile: copyFile$1,
388
+ copyFile: copyFile$2,
389
389
  ensureDirExist,
390
- ext: ext$1,
391
- fileInDir: fileInDir$1
390
+ ext: ext$2,
391
+ fileInDir: fileInDir$2
392
392
  };
393
393
 
394
394
  const chalk$2 = require$$0__default$2;
@@ -404,7 +404,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
404
404
  * @returns {undefined} 无
405
405
  */
406
406
 
407
- const fail$8 = (message = '') => {
407
+ const fail$9 = (message = '') => {
408
408
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
409
409
 
410
410
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
@@ -437,7 +437,7 @@ const warn = message => {
437
437
  };
438
438
 
439
439
  var log$2 = {
440
- fail: fail$8,
440
+ fail: fail$9,
441
441
  succeed: succeed$1,
442
442
  warn
443
443
  };
@@ -462,10 +462,10 @@ const render$1 = (files, metalsmith, next) => {
462
462
 
463
463
  var render_1 = render$1;
464
464
 
465
- const fs$9 = require$$0__default$1;
465
+ const fs$a = require$$0__default$1;
466
466
  const inquirer = require$$1__default$3;
467
467
  const {
468
- resolve: resolve$a
468
+ resolve: resolve$b
469
469
  } = widgets;
470
470
  const {
471
471
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -479,12 +479,12 @@ const {
479
479
  const parseTemplateQuestions = dir => {
480
480
  let prompts = [];
481
481
 
482
- if (!fs$9.existsSync(`${dir}/questions.json`)) {
482
+ if (!fs$a.existsSync(`${dir}/questions.json`)) {
483
483
  return prompts;
484
484
  }
485
485
 
486
486
  try {
487
- const json = JSON.parse(fs$9.readFileSync(`${dir}/questions.json`));
487
+ const json = JSON.parse(fs$a.readFileSync(`${dir}/questions.json`));
488
488
 
489
489
  if (Array.isArray(json) && json.length > 0) {
490
490
  json.forEach((item, index) => {
@@ -517,7 +517,7 @@ const isQuestionType = result => {
517
517
  };
518
518
 
519
519
  const ask$1 = templateDir => (files, metalsmith, next) => {
520
- const prompts = parseTemplateQuestions(resolve$a(templateDir, TEMPLATE_TKIT_DIR$1));
520
+ const prompts = parseTemplateQuestions(resolve$b(templateDir, TEMPLATE_TKIT_DIR$1));
521
521
  const metadata = metalsmith.metadata();
522
522
  const filteredPrompts = prompts.filter(prompt => {
523
523
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -559,8 +559,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
559
559
 
560
560
  var generator_1 = generator$1;
561
561
 
562
- const path$4 = require$$1__default$1;
563
- const fs$8 = require$$0__default$1;
562
+ const path$5 = require$$1__default$1;
563
+ const fs$9 = require$$0__default$1;
564
564
  const shelljs$4 = require$$5__default;
565
565
  const {
566
566
  TEMPLATE_DIR,
@@ -570,11 +570,11 @@ const {
570
570
  const {
571
571
  downloadRepoForGit: downloadRepoForGit$1,
572
572
  createTask: createTask$3,
573
- resolve: resolve$9
573
+ resolve: resolve$a
574
574
  } = widgets;
575
575
  const io$1 = io$2;
576
576
  const {
577
- fail: fail$7,
577
+ fail: fail$8,
578
578
  succeed
579
579
  } = log$2;
580
580
  const generator = generator_1;
@@ -586,9 +586,9 @@ const generator = generator_1;
586
586
 
587
587
  async function createAppDir(targetDir) {
588
588
  // 如果目录非空或者已经存在,提示用户,做选择
589
- if (fs$8.existsSync(targetDir)) {
589
+ if (fs$9.existsSync(targetDir)) {
590
590
  if (!(await io$1.isDirEmpty(targetDir))) {
591
- fail$7('该目录名已经存在,换个项目名字吧~');
591
+ fail$8('该目录名已经存在,换个项目名字吧~');
592
592
  process.exit(1);
593
593
  }
594
594
  } else {
@@ -604,7 +604,7 @@ async function createAppDir(targetDir) {
604
604
 
605
605
  async function create(appName) {
606
606
  const cwd = process.cwd();
607
- const targetDir = path$4.resolve(cwd, appName);
607
+ const targetDir = path$5.resolve(cwd, appName);
608
608
  const appType = 'mp';
609
609
  await createAppDir(targetDir); // 创建缓存目录
610
610
 
@@ -612,13 +612,13 @@ async function create(appName) {
612
612
 
613
613
  await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
614
614
 
615
- generator(path$4.join(TEMPLATE_PATH, appType), targetDir, {
615
+ generator(path$5.join(TEMPLATE_PATH, appType), targetDir, {
616
616
  appName,
617
617
  appType
618
618
  }).then(() => {
619
619
  shelljs$4.cd(appName);
620
620
 
621
- const hooks = require(resolve$9(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
621
+ const hooks = require(resolve$a(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
622
622
 
623
623
  if (hooks.afterCreate) {
624
624
  hooks.afterCreate.forEach(item => {
@@ -632,26 +632,26 @@ async function create(appName) {
632
632
  });
633
633
  }
634
634
 
635
- shelljs$4.rm('-rf', resolve$9(appName, TEMPLATE_TKIT_DIR));
635
+ shelljs$4.rm('-rf', resolve$a(appName, TEMPLATE_TKIT_DIR));
636
636
  succeed('项目创建完成.');
637
637
  }).catch(err => {
638
- fail$7(err.message);
638
+ fail$8(err.message);
639
639
  console.log('详细的错误信息:', err);
640
640
  });
641
641
  }
642
642
 
643
643
  var create_1 = create;
644
644
 
645
- const fs$7 = require$$0__default$1;
645
+ const fs$8 = require$$0__default$1;
646
646
  const {
647
647
  DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3,
648
648
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1
649
649
  } = require$$3;
650
650
  const {
651
- fail: fail$6
651
+ fail: fail$7
652
652
  } = log$2;
653
653
  const {
654
- resolve: resolve$8,
654
+ resolve: resolve$9,
655
655
  isObject: isObject$1,
656
656
  isArray
657
657
  } = widgets;
@@ -700,10 +700,10 @@ function getLocalModuleConfig(modules = [], appName, moduleDir, moduleConfigFile
700
700
  modules.forEach(({
701
701
  path
702
702
  }) => {
703
- const moduleConfigPath = resolve$8(path, moduleConfigFilename);
703
+ const moduleConfigPath = resolve$9(path, moduleConfigFilename);
704
704
 
705
- if (fs$7.existsSync(moduleConfigPath)) {
706
- const content = fs$7.readFileSync(moduleConfigPath, 'utf-8');
705
+ if (fs$8.existsSync(moduleConfigPath)) {
706
+ const content = fs$8.readFileSync(moduleConfigPath, 'utf-8');
707
707
  modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName, moduleDir);
708
708
  }
709
709
  });
@@ -728,7 +728,7 @@ function updateMainPackages(appJson, mainPackages = []) {
728
728
 
729
729
  foundMainPackages.forEach(subpackage => {
730
730
  if (!subpackage.pages || !subpackage.pages.length) {
731
- fail$6(`主包 ${subpackage} 不能没有 pages`);
731
+ fail$7(`主包 ${subpackage} 不能没有 pages`);
732
732
  process.exit(-1);
733
733
  }
734
734
 
@@ -754,12 +754,12 @@ function updateMainPackages(appJson, mainPackages = []) {
754
754
 
755
755
 
756
756
  const getAppJsonContent = sourceAppJsonPath => {
757
- if (!fs$7.existsSync(sourceAppJsonPath)) {
758
- fail$6(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
757
+ if (!fs$8.existsSync(sourceAppJsonPath)) {
758
+ fail$7(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
759
759
  process.exit(1);
760
760
  }
761
761
 
762
- const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
762
+ const appJson = JSON.parse(fs$8.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
763
763
 
764
764
  appJson.subpackages = [];
765
765
  appJson.pages = [];
@@ -794,12 +794,12 @@ function buildOutputAppJson$1(tmsConfig, modules) {
794
794
  // 获取当前 modules 下的所有子模块的配置内容
795
795
  const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$3, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
796
796
 
797
- const appJson = getAppJsonContent(resolve$8('./app.json')); // 更新app.json中的subpackages
797
+ const appJson = getAppJsonContent(resolve$9('./app.json')); // 更新app.json中的subpackages
798
798
 
799
799
  updateSubpackages(appJson, modulesConfig); // 更新主包,需在subpackages处理完成后执行, pages/
800
800
 
801
801
  updateMainPackages(appJson, tmsConfig.mainPackages);
802
- fs$7.writeFileSync(resolve$8(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
802
+ fs$8.writeFileSync(resolve$9(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
803
803
  return appJson;
804
804
  }
805
805
 
@@ -849,12 +849,12 @@ const {
849
849
  } = global;
850
850
  const {
851
851
  downloadRepoForGit,
852
- resolve: resolve$7
852
+ resolve: resolve$8
853
853
  } = widgets;
854
854
  const {
855
- fail: fail$5
855
+ fail: fail$6
856
856
  } = log$2;
857
- const fs$6 = require$$0__default$1;
857
+ const fs$7 = require$$0__default$1;
858
858
  const shelljs$3 = require$$5__default;
859
859
  /**
860
860
  * 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
@@ -869,7 +869,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
869
869
  return new Promise(resolve => {
870
870
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
871
871
  if (e) {
872
- fail$5(e); // eslint-disable-line
872
+ fail$6(e); // eslint-disable-line
873
873
 
874
874
  console.log('MetalSmith 详细的错误信息:', e);
875
875
  }
@@ -912,9 +912,9 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
912
912
  path
913
913
  } = moduleInfo; // 源码临时存在的源目录
914
914
 
915
- let sourcePath = resolve$7(sourceDir, path); // 源码要放到目标目录
915
+ let sourcePath = resolve$8(sourceDir, path); // 源码要放到目标目录
916
916
 
917
- const targetPath = resolve$7(targetDir, path); // 设置模块的构建分支
917
+ const targetPath = resolve$8(targetDir, path); // 设置模块的构建分支
918
918
 
919
919
  const cloneBranch = buildGitTag && typeof buildGitTag === 'string' ? buildGitTag : 'master'; // 检查缓存中有没有
920
920
 
@@ -929,13 +929,13 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
929
929
  sourcePath = globalInstance.getModuleCache(httpRepoUrl, cloneBranch).dest;
930
930
  }
931
931
 
932
- if (fs$6.existsSync(targetPath)) {
932
+ if (fs$7.existsSync(targetPath)) {
933
933
  shelljs$3.rm('-rf', targetPath);
934
934
  }
935
935
 
936
936
  await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
937
937
  } catch (e) {
938
- fail$5(`downLoadAndMoveModule ${e}`); // eslint-disable-line
938
+ fail$6(`downLoadAndMoveModule ${e}`); // eslint-disable-line
939
939
 
940
940
  process.exit(-1);
941
941
  }
@@ -967,14 +967,14 @@ var defaultTmsConfig$1 = {
967
967
  };
968
968
 
969
969
  const loadash = require$$0__default$5;
970
- const fs$5 = require$$0__default$1;
970
+ const fs$6 = require$$0__default$1;
971
971
  const {
972
972
  TMS_NAME: TMS_NAME$1,
973
973
  TMS_CONFIG_FILENAME,
974
974
  MODULE_CONFIG_FILENAME
975
975
  } = require$$3;
976
976
  const {
977
- resolve: resolve$6,
977
+ resolve: resolve$7,
978
978
  isObject
979
979
  } = widgets;
980
980
  const {
@@ -982,7 +982,7 @@ const {
982
982
  } = buildAppJson;
983
983
  const defaultTmsConfig = defaultTmsConfig$1;
984
984
  const {
985
- fail: fail$4
985
+ fail: fail$5
986
986
  } = log$2;
987
987
  /**
988
988
  * 读取tms.config.json
@@ -990,10 +990,10 @@ const {
990
990
  */
991
991
 
992
992
  const readTmsConfig$1 = function (env) {
993
- const tmsConfigPath = resolve$6(TMS_CONFIG_FILENAME);
993
+ const tmsConfigPath = resolve$7(TMS_CONFIG_FILENAME);
994
994
 
995
- if (!fs$5.existsSync(tmsConfigPath)) {
996
- fail$4('当前执行目录没有tms.config.js的配置项,请进行配置');
995
+ if (!fs$6.existsSync(tmsConfigPath)) {
996
+ fail$5('当前执行目录没有tms.config.js的配置项,请进行配置');
997
997
  process.exit(1);
998
998
  }
999
999
 
@@ -1022,7 +1022,7 @@ const checkModules$1 = function (tmsConfig, modules) {
1022
1022
  });
1023
1023
 
1024
1024
  if (targetModules.length === 0) {
1025
- fail$4(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
1025
+ fail$5(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
1026
1026
  process.exit(1);
1027
1027
  }
1028
1028
 
@@ -1043,10 +1043,10 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName, moduleDir) => {
1043
1043
  path: relativePath,
1044
1044
  name: moduleName
1045
1045
  }, moduleIndex) => {
1046
- const moduleConfigPath = resolve$6(relativePath, MODULE_CONFIG_FILENAME);
1046
+ const moduleConfigPath = resolve$7(relativePath, MODULE_CONFIG_FILENAME);
1047
1047
 
1048
- if (fs$5.existsSync(moduleConfigPath)) {
1049
- let moduleConfigContent = fs$5.readFileSync(moduleConfigPath, 'utf-8');
1048
+ if (fs$6.existsSync(moduleConfigPath)) {
1049
+ let moduleConfigContent = fs$6.readFileSync(moduleConfigPath, 'utf-8');
1050
1050
  moduleConfigContent = setModuleConfig(moduleConfigContent, appName, moduleDir);
1051
1051
  const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
1052
1052
  moduleContentArr.forEach(({
@@ -1074,7 +1074,7 @@ var tkitUtils = {
1074
1074
 
1075
1075
  /* eslint-disable require-jsdoc */
1076
1076
  const ci = require$$0__default$6;
1077
- const path$3 = require$$1__default$1;
1077
+ const path$4 = require$$1__default$1;
1078
1078
  /**
1079
1079
  * 获取小程序ci的Project对象
1080
1080
  * @returns {Object} 小程序ci对象
@@ -1088,7 +1088,7 @@ const getMpCi = ({
1088
1088
  }) => {
1089
1089
  var _cfgJsonContent$packO;
1090
1090
 
1091
- const cfgJsonContent = require(path$3.join(projectPath, 'project.config.json'));
1091
+ const cfgJsonContent = require(path$4.join(projectPath, 'project.config.json'));
1092
1092
 
1093
1093
  const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
1094
1094
  value
@@ -1157,8 +1157,8 @@ var mpCiUtils = {
1157
1157
  /**
1158
1158
  * 本文件主要负责项目或者分包依赖的npm的安装
1159
1159
  */
1160
- const fs$4 = require$$0__default$1;
1161
- const path$2 = require$$1__default$1;
1160
+ const fs$5 = require$$0__default$1;
1161
+ const path$3 = require$$1__default$1;
1162
1162
  const shell = require$$5__default;
1163
1163
  const glob = require$$3__default;
1164
1164
  const LOG = log$2;
@@ -1168,14 +1168,14 @@ const getTarNpmFilename = targetDir => `${targetDir.replace(/\//g, '-')}.tar.gz`
1168
1168
 
1169
1169
 
1170
1170
  const npmCache = function (targetDir, cacheDir) {
1171
- if (!fs$4.existsSync(cacheDir)) {
1172
- fs$4.mkdirSync(cacheDir);
1171
+ if (!fs$5.existsSync(cacheDir)) {
1172
+ fs$5.mkdirSync(cacheDir);
1173
1173
  }
1174
1174
 
1175
1175
  const tarNpmFilename = getTarNpmFilename(targetDir);
1176
1176
  const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1177
1177
 
1178
- if (fs$4.existsSync(tarNpmFilePath)) {
1178
+ if (fs$5.existsSync(tarNpmFilePath)) {
1179
1179
  shell.rm('-rf', tarNpmFilePath);
1180
1180
  }
1181
1181
 
@@ -1191,7 +1191,7 @@ const getNpmCache = function (targetDir, cacheDir) {
1191
1191
  const tarNpmFilename = getTarNpmFilename(targetDir);
1192
1192
  const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1193
1193
 
1194
- if (fs$4.existsSync(tarNpmFilePath)) {
1194
+ if (fs$5.existsSync(tarNpmFilePath)) {
1195
1195
  const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
1196
1196
  shell.exec(cmd, {
1197
1197
  async: false,
@@ -1205,10 +1205,10 @@ const getNpmCache = function (targetDir, cacheDir) {
1205
1205
  const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1206
1206
  const packageJsonFiles = await findAllPackageJson(modules, contextDir);
1207
1207
  await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
1208
- const dir = path$2.dirname(file);
1208
+ const dir = path$3.dirname(file);
1209
1209
  shell.cd(dir);
1210
1210
 
1211
- if (!fs$4.existsSync(`${dir}/node_modules`)) {
1211
+ if (!fs$5.existsSync(`${dir}/node_modules`)) {
1212
1212
  getNpmCache(dir, cacheDir);
1213
1213
  }
1214
1214
 
@@ -1238,7 +1238,7 @@ const findFilesByFilter = (startPath, filter) => {
1238
1238
 
1239
1239
  const find = (startPath, filter) => {
1240
1240
  // 目录不存在
1241
- if (!fs$4.existsSync(startPath)) {
1241
+ if (!fs$5.existsSync(startPath)) {
1242
1242
  LOG.fail(`${startPath}目录不存在`);
1243
1243
  process.exit(-1);
1244
1244
  return;
@@ -1251,10 +1251,10 @@ const findFilesByFilter = (startPath, filter) => {
1251
1251
  return;
1252
1252
  }
1253
1253
 
1254
- const files = fs$4.readdirSync(startPath);
1254
+ const files = fs$5.readdirSync(startPath);
1255
1255
  files.forEach(file => {
1256
- const filename = path$2.join(startPath, file);
1257
- const stat = fs$4.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1256
+ const filename = path$3.join(startPath, file);
1257
+ const stat = fs$5.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1258
1258
 
1259
1259
  if (stat.isDirectory()) {
1260
1260
  find(filename, filter);
@@ -1280,7 +1280,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1280
1280
  const packageJsonName = 'package.json'; // 查找文件名
1281
1281
 
1282
1282
  const cwd = contextDir || dirpath;
1283
- const result = [path$2.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1283
+ const result = [path$3.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1284
1284
 
1285
1285
  subRoots.forEach(subRoot => {
1286
1286
  if (!subRoot.root) {
@@ -1288,7 +1288,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1288
1288
  process.exit(1);
1289
1289
  }
1290
1290
 
1291
- const toppath = path$2.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1291
+ const toppath = path$3.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1292
1292
 
1293
1293
  const list = findFilesByFilter(toppath, packageJsonName);
1294
1294
  result.push(...list);
@@ -1304,7 +1304,7 @@ function cloudNpmInstall$1(contextDir) {
1304
1304
  }
1305
1305
 
1306
1306
  files.forEach(file => {
1307
- const dir = path$2.dirname(file);
1307
+ const dir = path$3.dirname(file);
1308
1308
  shell.cd(dir);
1309
1309
  shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
1310
1310
  silent: false
@@ -1323,7 +1323,7 @@ var npmUtils = {
1323
1323
 
1324
1324
  const {
1325
1325
  createTask: createTask$2,
1326
- resolve: resolve$5
1326
+ resolve: resolve$6
1327
1327
  } = widgets;
1328
1328
  const {
1329
1329
  buildMpNpm
@@ -1343,24 +1343,24 @@ const {
1343
1343
  async function install$2(tmsConfig, modules, isCloud = true) {
1344
1344
  const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
1345
1345
 
1346
- await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$5(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1346
+ await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$6(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1347
1347
 
1348
1348
  await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1349
1349
  appId: tmsConfig.appId,
1350
- projectPath: resolve$5('./'),
1350
+ projectPath: resolve$6('./'),
1351
1351
  privateKey: tmsConfig.privateKey
1352
1352
  }); // 安装云函数的
1353
1353
 
1354
- isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$5(tmsConfig.cloudDir));
1354
+ isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$6(tmsConfig.cloudDir));
1355
1355
  }
1356
1356
 
1357
1357
  var install_1 = install$2;
1358
1358
 
1359
1359
  const shelljs$2 = require$$5__default;
1360
- const fs$3 = require$$0__default$1;
1360
+ const fs$4 = require$$0__default$1;
1361
1361
  const io = io$2;
1362
1362
  const {
1363
- resolve: resolve$4,
1363
+ resolve: resolve$5,
1364
1364
  createTask: createTask$1
1365
1365
  } = widgets;
1366
1366
  const {
@@ -1378,7 +1378,7 @@ const {
1378
1378
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
1379
1379
  } = tkitUtils;
1380
1380
  const {
1381
- fail: fail$3
1381
+ fail: fail$4
1382
1382
  } = log$2;
1383
1383
  const install$1 = install_1;
1384
1384
  /**
@@ -1390,31 +1390,31 @@ const install$1 = install_1;
1390
1390
  */
1391
1391
 
1392
1392
  const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1393
- const outputDir = resolve$4(tmsConfig.gulp.outputDir);
1393
+ const outputDir = resolve$5(tmsConfig.gulp.outputDir);
1394
1394
  io.ensureDirExist(outputDir);
1395
1395
  defaultFiles.forEach(item => {
1396
- if (fs$3.existsSync(resolve$4(item))) {
1397
- shelljs$2.cp('-rf', resolve$4(item), resolve$4(tmsConfig.gulp.outputDir, item));
1396
+ if (fs$4.existsSync(resolve$5(item))) {
1397
+ shelljs$2.cp('-rf', resolve$5(item), resolve$5(tmsConfig.gulp.outputDir, item));
1398
1398
  }
1399
1399
  }); // 拷贝模块的package.json到编译输出目录
1400
1400
 
1401
1401
  targetModules.forEach(item => {
1402
- const outputModuleDir = resolve$4(`${tmsConfig.gulp.outputDir}/${item.root}`);
1402
+ const outputModuleDir = resolve$5(`${tmsConfig.gulp.outputDir}/${item.root}`);
1403
1403
 
1404
- if (!fs$3.existsSync(resolve$4(item.path))) {
1405
- fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1404
+ if (!fs$4.existsSync(resolve$5(item.path))) {
1405
+ fail$4(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1406
1406
  process.exit(1);
1407
1407
  }
1408
1408
 
1409
1409
  io.ensureDirExist(outputModuleDir);
1410
- const modulePackagePath = resolve$4(item.path, 'package.json');
1411
- if (fs$3.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
1410
+ const modulePackagePath = resolve$5(item.path, 'package.json');
1411
+ if (fs$4.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
1412
1412
  });
1413
1413
  };
1414
1414
 
1415
1415
  async function task(tmsConfig, targetModules) {
1416
1416
  // 下载和移动代码
1417
- await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$4('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1417
+ await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$5('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1418
1418
 
1419
1419
  const newModules = tmsModulesMergeLocalModuleCfg$1(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$1);
1420
1420
  console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
@@ -1438,10 +1438,10 @@ var init$5 = bootstrap;
1438
1438
 
1439
1439
  var dev$3 = {exports: {}};
1440
1440
 
1441
- const through$1 = require$$0__default$7;
1441
+ const through$2 = require$$0__default$7;
1442
1442
 
1443
1443
  function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
1444
- const stream = through$1.obj(function (file, enc, cb) {
1444
+ const stream = through$2.obj(function (file, enc, cb) {
1445
1445
  if (file.isBuffer()) {
1446
1446
  let contents = String(file.contents);
1447
1447
  let resReg; // eslint-disable-next-line
@@ -1469,93 +1469,116 @@ function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
1469
1469
 
1470
1470
  var replaceEnv_1 = replaceEnv$1;
1471
1471
 
1472
- const through = require$$0__default$7;
1472
+ const through$1 = require$$0__default$7;
1473
1473
  const precinct = require$$1__default$4;
1474
- const path$1 = require$$1__default$1;
1474
+ const path$2 = require$$1__default$1;
1475
1475
  const {
1476
- copyFile,
1477
- ext,
1478
- fileInDir
1476
+ copyFile: copyFile$1,
1477
+ ext: ext$1,
1478
+ fileInDir: fileInDir$1
1479
1479
  } = io$2;
1480
1480
  const {
1481
- resolve: resolve$3
1481
+ resolve: resolve$4
1482
1482
  } = widgets;
1483
- const fs$2 = require$$0__default$1;
1483
+ const fs$3 = require$$0__default$1;
1484
1484
  const {
1485
- fail: fail$2
1485
+ fail: fail$3
1486
1486
  } = log$2;
1487
1487
 
1488
- const dfsDep = function (includePath, anaFileOriginFile, anaFileDestFile, extensions) {
1489
- const contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
1490
- const deps = precinct(contents);
1491
- deps.forEach(depItem => {
1492
- if (depItem.startsWith('.')) {
1493
- // 被依赖文件的存在的绝对路径
1494
- const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1495
-
1496
- const depOriginPathExt = ext(depOriginPath, extensions);
1497
-
1498
- if (!depOriginPathExt) {
1499
- fail$2(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
1500
- } // 被依赖文件是否存在 include的path中 (只处理include的文件)
1501
-
1502
-
1503
- if (depOriginPathExt && fileInDir(includePath, depOriginPathExt.file)) {
1504
- const depOriginFile = depOriginPathExt.file;
1505
- const depDestPath = resolve$3(path$1.dirname(anaFileDestFile), depItem);
1506
- const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext;
1507
-
1508
- if (fs$2.existsSync(depDestFile)) {
1509
- const depDestContent = fs$2.readFileSync(depDestFile, 'utf8');
1510
- const depOriginContent = fs$2.readFileSync(depOriginFile, 'utf8');
1511
-
1512
- if (depDestContent !== depOriginContent) {
1513
- console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1514
- copyFile(depOriginFile, depDestFile);
1488
+ const dfsFindJsDep$1 = function (anaFileOriginFile, anaFileDestFile, extensions) {
1489
+ const resDep = new Map();
1490
+
1491
+ function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
1492
+ const contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
1493
+ const deps = precinct(contents);
1494
+ deps.forEach(depItem => {
1495
+ if (depItem.startsWith('.')) {
1496
+ // 被依赖文件的存在的绝对路径
1497
+ const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1498
+
1499
+ const depOriginPathExt = ext$1(depOriginPath, extensions);
1500
+
1501
+ if (!depOriginPathExt) {
1502
+ fail$3(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
1503
+ } // 被依赖文件是否存在 include的path中 (只处理include的文件)
1504
+
1505
+
1506
+ if (depOriginPathExt) {
1507
+ const depOriginFile = depOriginPathExt.file;
1508
+ const depDestPath = resolve$4(path$2.dirname(anaFileDestFile), depItem);
1509
+ const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext;
1510
+
1511
+ if (!resDep.has(depDestFile)) {
1512
+ resDep.set(depDestFile, {
1513
+ anaFileOriginFile,
1514
+ anaFileDestFile,
1515
+ depDestFile,
1516
+ depOriginFile
1517
+ });
1518
+ dfs(depOriginFile, depDestFile, extensions);
1515
1519
  }
1516
- } else {
1517
- console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1518
- copyFile(depOriginFile, depDestFile);
1519
1520
  }
1520
-
1521
- dfsDep(includePath, depOriginFile, depDestFile, extensions);
1522
1521
  }
1523
- }
1524
- });
1522
+ });
1523
+ }
1524
+
1525
+ dfs(anaFileOriginFile, anaFileDestFile, extensions);
1526
+ return resDep;
1525
1527
  };
1526
1528
 
1527
- function includeThirdParty(tmsConfig, module, extensions = ['.js', '.ts', '.wxs']) {
1528
- const stream = through.obj(function (file, enc, cb) {
1529
+ function handleCopyFile$1(depDestFile, depOriginFile) {
1530
+ if (fs$3.existsSync(depDestFile)) {
1531
+ const depDestContent = fs$3.readFileSync(depDestFile, 'utf8');
1532
+ const depOriginContent = fs$3.readFileSync(depOriginFile, 'utf8');
1533
+
1534
+ if (depDestContent !== depOriginContent) {
1535
+ console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1536
+ copyFile$1(depOriginFile, depDestFile);
1537
+ }
1538
+ } else {
1539
+ console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1540
+ copyFile$1(depOriginFile, depDestFile);
1541
+ }
1542
+ }
1543
+
1544
+ function jsDep$1(tmsConfig, module, extensions = ['.js', '.ts', '.wxs']) {
1545
+ const stream = through$1.obj(function (file, enc, cb) {
1529
1546
  // 依赖分析的文件
1530
1547
  const anaFileOriginFile = file.history[0];
1531
- const anaFileRelativeModule = path$1.relative(resolve$3(module.from), anaFileOriginFile);
1532
- const anaFileDestFile = resolve$3(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
1548
+ const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
1549
+ const anaFileDestFile = resolve$4(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
1533
1550
 
1534
1551
  if (file.isBuffer()) {
1535
1552
  let contents = String(file.contents);
1536
1553
  const deps = precinct(contents);
1537
- const copyModules = [];
1554
+ const copyModules = new Map();
1538
1555
  Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
1539
1556
  const includePath = tmsConfig.gulp.dependencies[includeName];
1540
1557
  deps.forEach(depItem => {
1541
1558
  if (depItem.indexOf(includeName) > -1) {
1542
1559
  // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
1543
- const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1560
+ const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1544
1561
 
1545
- const depOriginPathExt = ext(depOriginPath, extensions);
1562
+ const depOriginPathExt = ext$1(depOriginPath, extensions);
1546
1563
 
1547
1564
  if (!depOriginPathExt) {
1548
- fail$2(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
1565
+ fail$3(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
1566
+ }
1567
+
1568
+ const isFileInDir = fileInDir$1(includePath, depOriginPathExt.file);
1569
+
1570
+ if (!isFileInDir) {
1571
+ fail$3(`${depOriginPathExt.file}不在${includePath}不在文件夹内, 请检查应用路径`);
1549
1572
  } // 被依赖文件是否存在 include的path中 (只处理include的文件)
1550
1573
 
1551
1574
 
1552
- if (depOriginPathExt && fileInDir(includePath, depOriginPathExt.file)) {
1575
+ if (depOriginPathExt && isFileInDir) {
1553
1576
  // eslint-disable-next-line
1554
1577
  const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
1555
1578
  const regRes = depItem.match(reg) || [];
1556
1579
 
1557
1580
  if (regRes[2]) {
1558
- const depDestPath = resolve$3(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
1581
+ const depDestPath = resolve$4(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
1559
1582
  const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext; // {
1560
1583
  // depOriginFile: '/Users/odile/workspace/tms-frontend1/miniprogram/thirdparty/libs/timer.js',
1561
1584
  // depDestFile: `/Users/odile/workspace/tms-frontend1/tools/demo1/dist/modules/
@@ -1564,41 +1587,170 @@ function includeThirdParty(tmsConfig, module, extensions = ['.js', '.ts', '.wxs'
1564
1587
  // afterDepPath: '../../thirdparty/libs/timer'
1565
1588
  // }
1566
1589
 
1567
- copyModules.push({
1568
- depOriginFile: depOriginPathExt.file,
1569
- depDestFile,
1570
- beforeDepPath: depItem,
1571
- afterDepPath: path$1.relative(path$1.dirname(anaFileDestFile), depDestPath),
1572
- includePath
1573
- });
1590
+ if (!copyModules.has(depDestFile)) {
1591
+ copyModules.set(depDestFile, {
1592
+ depOriginFile: depOriginPathExt.file,
1593
+ depDestFile,
1594
+ beforeDepPath: depItem,
1595
+ afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestPath)
1596
+ });
1597
+ }
1574
1598
  }
1575
1599
  }
1576
1600
  }
1577
1601
  });
1578
1602
  });
1579
1603
  copyModules.forEach(({
1580
- includePath,
1581
1604
  depOriginFile,
1582
1605
  depDestFile,
1583
1606
  beforeDepPath,
1584
1607
  afterDepPath
1585
1608
  }) => {
1586
- if (fs$2.existsSync(depDestFile)) {
1587
- const depDestContent = fs$2.readFileSync(depDestFile, 'utf8');
1588
- const depOriginContent = fs$2.readFileSync(depOriginFile, 'utf8');
1609
+ handleCopyFile$1(depDestFile, depOriginFile);
1610
+ contents = contents.replace(beforeDepPath, afterDepPath);
1611
+ const defs = dfsFindJsDep$1(depOriginFile, depDestFile, extensions);
1612
+ defs.forEach(item => {
1613
+ handleCopyFile$1(item.depDestFile, item.depOriginFile);
1614
+ });
1615
+ }); // eslint-disable-next-line
1589
1616
 
1590
- if (depDestContent !== depOriginContent) {
1591
- console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1592
- copyFile(depOriginFile, depDestFile);
1593
- }
1594
- } else {
1595
- console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1596
- copyFile(depOriginFile, depDestFile);
1617
+ file.contents = new Buffer(contents);
1618
+ }
1619
+
1620
+ this.push(file);
1621
+ cb();
1622
+ });
1623
+ return stream;
1624
+ }
1625
+
1626
+ var jsDep_1 = {
1627
+ jsDep: jsDep$1,
1628
+ dfsFindJsDep: dfsFindJsDep$1
1629
+ };
1630
+
1631
+ const through = require$$0__default$7;
1632
+ const path$1 = require$$1__default$1;
1633
+ const {
1634
+ copyFile,
1635
+ ext,
1636
+ fileInDir
1637
+ } = io$2;
1638
+ const {
1639
+ resolve: resolve$3
1640
+ } = widgets;
1641
+ const fs$2 = require$$0__default$1;
1642
+ const {
1643
+ fail: fail$2
1644
+ } = log$2;
1645
+ const {
1646
+ dfsFindJsDep
1647
+ } = jsDep_1;
1648
+
1649
+ function handleCopyFile(depDestFile, depOriginFile) {
1650
+ if (fs$2.existsSync(depDestFile)) {
1651
+ const depDestContent = fs$2.readFileSync(depDestFile, 'utf8');
1652
+ const depOriginContent = fs$2.readFileSync(depOriginFile, 'utf8');
1653
+
1654
+ if (depDestContent !== depOriginContent) {
1655
+ console.log(`json拷贝${depOriginFile}内容到${depDestFile}`);
1656
+ copyFile(depOriginFile, depDestFile);
1657
+ }
1658
+ } else {
1659
+ console.log(`json拷贝${depOriginFile}内容到${depDestFile}`);
1660
+ copyFile(depOriginFile, depDestFile);
1661
+ }
1662
+ }
1663
+
1664
+ function mpJsonDep$1(tmsConfig, module, extensions = ['.wxml'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less']) {
1665
+ const stream = through.obj(function (file, enc, cb) {
1666
+ // 当前分析的文件的路径
1667
+ const anaFileOriginFile = file.history[0];
1668
+ const anaFileRelativeModule = path$1.relative(resolve$3(module.from), anaFileOriginFile);
1669
+ const anaFileDestFile = resolve$3(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
1670
+
1671
+ if (file.isBuffer()) {
1672
+ const copyModules = new Map();
1673
+ let contents = String(file.contents);
1674
+
1675
+ try {
1676
+ contents = JSON.parse(contents);
1677
+
1678
+ if (contents.usingComponents) {
1679
+ Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
1680
+ const includePath = tmsConfig.gulp.dependencies[includeName];
1681
+ Object.keys(contents.usingComponents).forEach(componentKey => {
1682
+ const componentPath = contents.usingComponents[componentKey];
1683
+
1684
+ if (componentPath.indexOf(includeName) > -1) {
1685
+ const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
1686
+
1687
+ const depOriginPathExt = ext(depOriginPath, extensions);
1688
+
1689
+ if (!depOriginPathExt) {
1690
+ fail$2(`${anaFileOriginFile}的${componentPath}引用路径存找不到文件,请检查引用路径`);
1691
+ }
1692
+
1693
+ const isFileInDir = fileInDir(includePath, depOriginPathExt.file);
1694
+
1695
+ if (!isFileInDir) {
1696
+ fail$2(`${depOriginPathExt.file}不在${includePath}不在文件夹内, 请检查应用路径`);
1697
+ }
1698
+
1699
+ if (depOriginPathExt && isFileInDir) {
1700
+ // eslint-disable-next-line
1701
+ const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
1702
+ const regRes = componentPath.match(reg) || [];
1703
+
1704
+ if (regRes[2]) {
1705
+ const depDestPath = resolve$3(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
1706
+ const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext;
1707
+
1708
+ if (!copyModules.has(depDestFile)) {
1709
+ copyModules.set(depDestFile, {
1710
+ depOriginFile: depOriginPathExt.file,
1711
+ depOriginExt: depOriginPathExt.ext,
1712
+ depDestFile,
1713
+ beforeDepPath: componentPath,
1714
+ afterDepPath: path$1.relative(path$1.dirname(anaFileDestFile), depDestPath)
1715
+ });
1716
+ }
1717
+ }
1718
+ }
1719
+ }
1720
+ });
1721
+ });
1597
1722
  }
1723
+ } catch (e) {
1724
+ fail$2(`解析jsonDep出现错误:${e}`);
1725
+ }
1598
1726
 
1727
+ copyModules.forEach(({
1728
+ depOriginFile,
1729
+ depOriginExt,
1730
+ depDestFile,
1731
+ beforeDepPath,
1732
+ afterDepPath
1733
+ }) => {
1734
+ filesExt.forEach(extKey => {
1735
+ const originFile = depOriginFile.replace(depOriginExt, extKey);
1736
+ const destFile = depDestFile.replace(depOriginExt, extKey);
1737
+
1738
+ if (fs$2.existsSync(originFile)) {
1739
+ handleCopyFile(destFile, originFile);
1740
+ const jsExtensions = ['.js', '.ts'];
1741
+
1742
+ if (jsExtensions.indexOf(extKey) > -1) {
1743
+ const defs = dfsFindJsDep(originFile, destFile, jsExtensions);
1744
+ defs.forEach(item => {
1745
+ handleCopyFile(item.depDestFile, item.depOriginFile);
1746
+ });
1747
+ }
1748
+ }
1749
+ });
1750
+ contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
1599
1751
  contents = contents.replace(beforeDepPath, afterDepPath);
1600
- dfsDep(includePath, depOriginFile, depDestFile, extensions);
1601
- }); // eslint-disable-next-line
1752
+ });
1753
+ contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents; // eslint-disable-next-line
1602
1754
 
1603
1755
  file.contents = new Buffer(contents);
1604
1756
  }
@@ -1609,7 +1761,9 @@ function includeThirdParty(tmsConfig, module, extensions = ['.js', '.ts', '.wxs'
1609
1761
  return stream;
1610
1762
  }
1611
1763
 
1612
- var includeDep$1 = includeThirdParty;
1764
+ var mpJsonDep_1 = {
1765
+ mpJsonDep: mpJsonDep$1
1766
+ };
1613
1767
 
1614
1768
  const {
1615
1769
  src: src$1,
@@ -1621,7 +1775,12 @@ const rename = require$$3__default$1;
1621
1775
  const watch = require$$4__default;
1622
1776
  const image = require$$5__default$1;
1623
1777
  const replaceEnv = replaceEnv_1;
1624
- const includeDep = includeDep$1;
1778
+ const {
1779
+ jsDep
1780
+ } = jsDep_1;
1781
+ const {
1782
+ mpJsonDep
1783
+ } = mpJsonDep_1;
1625
1784
 
1626
1785
  var compile = function (tmsConfig, {
1627
1786
  glob,
@@ -1643,7 +1802,7 @@ var compile = function (tmsConfig, {
1643
1802
 
1644
1803
  switch (globKey) {
1645
1804
  case 'js':
1646
- srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(includeDep(tmsConfig, module)).pipe(dest(destPath));
1805
+ srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(jsDep(tmsConfig, module)).pipe(dest(destPath));
1647
1806
  break;
1648
1807
 
1649
1808
  case 'css':
@@ -1658,7 +1817,7 @@ var compile = function (tmsConfig, {
1658
1817
  break;
1659
1818
 
1660
1819
  case 'json':
1661
- srcPipe.pipe(dest(destPath));
1820
+ srcPipe.pipe(mpJsonDep(tmsConfig, module)).pipe(dest(destPath));
1662
1821
  break;
1663
1822
 
1664
1823
  case 'html':
@@ -1689,6 +1848,26 @@ var compile = function (tmsConfig, {
1689
1848
  } = require$$3;
1690
1849
  const compile$1 = compile;
1691
1850
 
1851
+ function handleOtherGlob(glob) {
1852
+ const otherArr = [];
1853
+ Object.keys(glob).forEach(globKey => {
1854
+ if (typeof glob[globKey] === 'string') {
1855
+ const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
1856
+ otherArr.push(data);
1857
+ }
1858
+
1859
+ if (Array.isArray(glob[globKey])) {
1860
+ glob[globKey].forEach(value => {
1861
+ if (typeof value === 'string') {
1862
+ const data = value.startsWith('!') ? value : `!${value}`;
1863
+ otherArr.push(data);
1864
+ }
1865
+ });
1866
+ }
1867
+ });
1868
+ return otherArr;
1869
+ }
1870
+
1692
1871
  module.exports = async (tmsConfig, newModules, isWatch = true) => {
1693
1872
  var _tmsConfig$gulp;
1694
1873
 
@@ -1722,7 +1901,14 @@ var compile = function (tmsConfig, {
1722
1901
  isWatch
1723
1902
  }); // 监听模块的文件
1724
1903
 
1725
- for (const module of newModules) {
1904
+ for (let module of newModules) {
1905
+ // 处理默认参数
1906
+ module = { ...{
1907
+ excludes: []
1908
+ },
1909
+ ...module
1910
+ };
1911
+
1726
1912
  if (isWatch) {
1727
1913
  // 监听模块配置文件
1728
1914
  watch(`${resolve(module.path)}/**/module.config.json`, {
@@ -1730,20 +1916,19 @@ var compile = function (tmsConfig, {
1730
1916
  }, () => {
1731
1917
  buildOutputAppJson(tmsConfig, newModules);
1732
1918
  });
1733
- } else {
1734
- buildOutputAppJson(tmsConfig, newModules);
1735
1919
  }
1736
1920
 
1921
+ const excludes = module.exclude.map(key => `!${resolve(key)}`);
1737
1922
  const glob = {
1738
- js: `${resolve(module.path)}/**/*.{js,ts,wxs}`,
1739
- json: `${resolve(module.path)}/**/*.json`,
1740
- css: `${resolve(module.path)}/**/*.{less,wxss}`,
1741
- html: `${resolve(module.path)}/**/*.wxml`,
1742
- image: `${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`
1923
+ js: [`${resolve(module.path)}/**/*.{js,ts,wxs}`, ...excludes],
1924
+ json: [`${resolve(module.path)}/**/*.json`, ...excludes],
1925
+ css: [`${resolve(module.path)}/**/*.{less,wxss}`, ...excludes],
1926
+ html: [`${resolve(module.path)}/**/*.wxml`, ...excludes],
1927
+ image: [`${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
1743
1928
  };
1744
1929
  compile$1(tmsConfig, {
1745
1930
  glob: { ...glob,
1746
- other: [`${resolve(module.path)}/**/*`, ...Object.keys(glob).map(key => `!${glob[key]}`)]
1931
+ other: [`${resolve(module.path)}/**/*`, ...handleOtherGlob(glob)]
1747
1932
  },
1748
1933
  destPath: resolve(tmsConfig.gulp.outputDir, module.root),
1749
1934
  module: {
@@ -1771,7 +1956,7 @@ var compile = function (tmsConfig, {
1771
1956
  };
1772
1957
  compile$1(tmsConfig, {
1773
1958
  glob: { ...glob,
1774
- other: [`${item.from}/**/*`, ...Object.keys(glob).map(key => `!${glob[key]}`)]
1959
+ other: [`${item.from}/**/*`, ...handleOtherGlob(glob)]
1775
1960
  },
1776
1961
  destPath: item.to,
1777
1962
  module: item,
@@ -2100,7 +2285,7 @@ var entry = [{
2100
2285
 
2101
2286
  var require$$6 = {
2102
2287
  name: "@tmsfe/tmskit",
2103
- version: "0.0.5-beta.1",
2288
+ version: "0.0.5-beta.2",
2104
2289
  description: "tmskit",
2105
2290
  main: "main.js",
2106
2291
  bin: {