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

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
@@ -16,12 +16,14 @@ var require$$0$5 = require('lodash');
16
16
  var require$$0$6 = require('miniprogram-ci');
17
17
  var require$$3$1 = require('glob-ignore');
18
18
  var require$$0$7 = require('through2');
19
- var require$$1$4 = require('gulp');
20
- var require$$2$1 = require('gulp-px-to-rpx');
21
- var require$$3$2 = require('gulp-less');
22
- var require$$4 = require('gulp-rename');
23
- var require$$5$1 = require('gulp-watch');
24
- var require$$1$5 = require('semver');
19
+ var require$$1$4 = require('precinct');
20
+ var require$$0$8 = require('gulp');
21
+ var require$$1$5 = require('gulp-px-to-rpx');
22
+ var require$$2$1 = require('gulp-less');
23
+ var require$$3$2 = require('gulp-rename');
24
+ var require$$4 = require('gulp-watch');
25
+ var require$$5$1 = require('gulp-image');
26
+ var require$$1$6 = require('semver');
25
27
 
26
28
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
27
29
 
@@ -42,11 +44,13 @@ var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
42
44
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
43
45
  var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
44
46
  var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
47
+ var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
48
+ var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
45
49
  var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
46
50
  var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
47
51
  var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
48
52
  var require$$5__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
49
- var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
53
+ var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
50
54
 
51
55
  function getAugmentedNamespace(n) {
52
56
  if (n.__esModule) return n;
@@ -63,13 +67,13 @@ function getAugmentedNamespace(n) {
63
67
  return a;
64
68
  }
65
69
 
66
- var src$1 = {};
70
+ var src$2 = {};
67
71
 
68
72
  const program$1 = require$$0__default;
69
73
  const leven = require$$1__default;
70
74
  const ora = require$$2__default;
71
- const path$5 = require$$1__default$1;
72
- const fs$a = require$$0__default$1;
75
+ const path$7 = require$$1__default$1;
76
+ const fs$b = require$$0__default$1;
73
77
  const shelljs$5 = require$$5__default;
74
78
  const download = require$$6__default;
75
79
  const chalk$3 = require$$0__default$2;
@@ -79,8 +83,8 @@ const shelljsOptons = {
79
83
 
80
84
  const cwd = process.cwd();
81
85
 
82
- function resolve$a(...args) {
83
- return path$5.resolve(cwd, ...args);
86
+ function resolve$b(...args) {
87
+ return path$7.resolve(cwd, ...args);
84
88
  }
85
89
  /**
86
90
  * 封装logs
@@ -149,7 +153,7 @@ function downloadRepo(dest, downloadOptions = {
149
153
  branch
150
154
  } = downloadOptions;
151
155
 
152
- if (fs$a.existsSync(dest)) {
156
+ if (fs$b.existsSync(dest)) {
153
157
  shelljs$5.rm('-rf', dest);
154
158
  }
155
159
 
@@ -181,8 +185,8 @@ function downloadRepoForGit$2(url, dest, branch) {
181
185
  const cwd = process.cwd();
182
186
  return new Promise(resolve => {
183
187
  // 如果目标目录不存在
184
- if (fs$a.existsSync(dest)) {
185
- shelljs$5.rm('-rf', path$5.join(dest));
188
+ if (fs$b.existsSync(dest)) {
189
+ shelljs$5.rm('-rf', path$7.join(dest));
186
190
  }
187
191
 
188
192
  shelljs$5.mkdir('-p', dest);
@@ -239,7 +243,7 @@ function createTask$4(task, startText, endText) {
239
243
  const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
240
244
 
241
245
  var widgets = {
242
- resolve: resolve$a,
246
+ resolve: resolve$b,
243
247
  log: log$3,
244
248
  isObject: isObject$2,
245
249
  isArray: isArray$1,
@@ -250,18 +254,18 @@ var widgets = {
250
254
  camelize
251
255
  };
252
256
 
253
- const path$4 = require('path'); // 用户目录
257
+ const path$6 = require('path'); // 用户目录
254
258
 
255
259
 
256
260
  const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
257
261
 
258
- const CACHE_DIR$1 = path$4.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
262
+ const CACHE_DIR$1 = path$6.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
259
263
 
260
- const TEMPLATE_DIR$1 = path$4.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
264
+ const TEMPLATE_DIR$1 = path$6.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
261
265
 
262
- const MODULE_CODE_DIR$1 = path$4.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
266
+ const MODULE_CODE_DIR$1 = path$6.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
263
267
 
264
- const TEMPLATE_PATH$1 = path$4.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
268
+ const TEMPLATE_PATH$1 = path$6.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
265
269
 
266
270
  const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
267
271
 
@@ -272,7 +276,7 @@ const DEFAULT_MODULE_DIR$4 = 'modules'; // 模块的配置文件的名称
272
276
  const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
273
277
 
274
278
  const DEFAULT_WEBPACK_ENTRY = {
275
- app: path$4.resolve(process.cwd(), 'app')
279
+ app: path$6.resolve(process.cwd(), 'app')
276
280
  }; // 默认从源码拷贝到编译后的配置
277
281
 
278
282
  const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
@@ -308,14 +312,15 @@ var constant = /*#__PURE__*/Object.freeze({
308
312
 
309
313
  var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
310
314
 
311
- const fs$9 = require$$0__default$1;
315
+ const fs$a = require$$0__default$1;
316
+ const path$5 = require$$1__default$1;
312
317
  /**
313
318
  * 判断目录是否为空
314
319
  * @param {string} dirname 目录名
315
320
  * @returns
316
321
  */
317
322
 
318
- const isDirEmpty = dirname => fs$9.promises.readdir(dirname).then(files => files.length === 0);
323
+ const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files.length === 0);
319
324
  /**
320
325
  * 确保目录存在,不存在就创建一个
321
326
  * @param {*} dirname 目录名
@@ -323,16 +328,67 @@ const isDirEmpty = dirname => fs$9.promises.readdir(dirname).then(files => files
323
328
 
324
329
 
325
330
  const ensureDirExist = dirname => {
326
- if (!fs$9.existsSync(dirname)) {
327
- fs$9.mkdirSync(dirname, {
331
+ if (!fs$a.existsSync(dirname)) {
332
+ fs$a.mkdirSync(dirname, {
328
333
  recursive: true
329
334
  });
330
335
  }
336
+ }; // 复制文件
337
+
338
+
339
+ const copyFile$1 = function (src, dest) {
340
+ if (fs$a.existsSync(dest)) {
341
+ fs$a.unlinkSync(dest);
342
+ }
343
+
344
+ const dir = dest.substr(0, dest.lastIndexOf('/'));
345
+ ensureDirExist(dir);
346
+ fs$a.copyFileSync(src, dest);
347
+ }; // 添加后缀
348
+
349
+
350
+ function ext$1(filePath, extensions) {
351
+ let newFilePath = filePath;
352
+
353
+ try {
354
+ const stat = fs$a.lstatSync(newFilePath);
355
+
356
+ if (stat.isDirectory()) {
357
+ newFilePath += newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
358
+ }
359
+ } catch (e) {}
360
+
361
+ for (const ext of extensions) {
362
+ const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
363
+
364
+ if (fs$a.existsSync(file)) {
365
+ return {
366
+ file,
367
+ ext
368
+ };
369
+ }
370
+ }
371
+
372
+ return null;
373
+ } // 判断文件是否在某个目录
374
+
375
+
376
+ const fileInDir$1 = (dir, file) => {
377
+ const relativePath = path$5.relative(dir, file);
378
+
379
+ if (relativePath.startsWith('..')) {
380
+ return false;
381
+ }
382
+
383
+ return true;
331
384
  };
332
385
 
333
386
  var io$2 = {
334
387
  isDirEmpty,
335
- ensureDirExist
388
+ copyFile: copyFile$1,
389
+ ensureDirExist,
390
+ ext: ext$1,
391
+ fileInDir: fileInDir$1
336
392
  };
337
393
 
338
394
  const chalk$2 = require$$0__default$2;
@@ -348,7 +404,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
348
404
  * @returns {undefined} 无
349
405
  */
350
406
 
351
- const fail$7 = (message = '') => {
407
+ const fail$8 = (message = '') => {
352
408
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
353
409
 
354
410
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
@@ -381,7 +437,7 @@ const warn = message => {
381
437
  };
382
438
 
383
439
  var log$2 = {
384
- fail: fail$7,
440
+ fail: fail$8,
385
441
  succeed: succeed$1,
386
442
  warn
387
443
  };
@@ -406,10 +462,10 @@ const render$1 = (files, metalsmith, next) => {
406
462
 
407
463
  var render_1 = render$1;
408
464
 
409
- const fs$8 = require$$0__default$1;
465
+ const fs$9 = require$$0__default$1;
410
466
  const inquirer = require$$1__default$3;
411
467
  const {
412
- resolve: resolve$9
468
+ resolve: resolve$a
413
469
  } = widgets;
414
470
  const {
415
471
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -423,12 +479,12 @@ const {
423
479
  const parseTemplateQuestions = dir => {
424
480
  let prompts = [];
425
481
 
426
- if (!fs$8.existsSync(`${dir}/questions.json`)) {
482
+ if (!fs$9.existsSync(`${dir}/questions.json`)) {
427
483
  return prompts;
428
484
  }
429
485
 
430
486
  try {
431
- const json = JSON.parse(fs$8.readFileSync(`${dir}/questions.json`));
487
+ const json = JSON.parse(fs$9.readFileSync(`${dir}/questions.json`));
432
488
 
433
489
  if (Array.isArray(json) && json.length > 0) {
434
490
  json.forEach((item, index) => {
@@ -461,7 +517,7 @@ const isQuestionType = result => {
461
517
  };
462
518
 
463
519
  const ask$1 = templateDir => (files, metalsmith, next) => {
464
- const prompts = parseTemplateQuestions(resolve$9(templateDir, TEMPLATE_TKIT_DIR$1));
520
+ const prompts = parseTemplateQuestions(resolve$a(templateDir, TEMPLATE_TKIT_DIR$1));
465
521
  const metadata = metalsmith.metadata();
466
522
  const filteredPrompts = prompts.filter(prompt => {
467
523
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -503,8 +559,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
503
559
 
504
560
  var generator_1 = generator$1;
505
561
 
506
- const path$3 = require$$1__default$1;
507
- const fs$7 = require$$0__default$1;
562
+ const path$4 = require$$1__default$1;
563
+ const fs$8 = require$$0__default$1;
508
564
  const shelljs$4 = require$$5__default;
509
565
  const {
510
566
  TEMPLATE_DIR,
@@ -514,11 +570,11 @@ const {
514
570
  const {
515
571
  downloadRepoForGit: downloadRepoForGit$1,
516
572
  createTask: createTask$3,
517
- resolve: resolve$8
573
+ resolve: resolve$9
518
574
  } = widgets;
519
575
  const io$1 = io$2;
520
576
  const {
521
- fail: fail$6,
577
+ fail: fail$7,
522
578
  succeed
523
579
  } = log$2;
524
580
  const generator = generator_1;
@@ -530,9 +586,9 @@ const generator = generator_1;
530
586
 
531
587
  async function createAppDir(targetDir) {
532
588
  // 如果目录非空或者已经存在,提示用户,做选择
533
- if (fs$7.existsSync(targetDir)) {
589
+ if (fs$8.existsSync(targetDir)) {
534
590
  if (!(await io$1.isDirEmpty(targetDir))) {
535
- fail$6('该目录名已经存在,换个项目名字吧~');
591
+ fail$7('该目录名已经存在,换个项目名字吧~');
536
592
  process.exit(1);
537
593
  }
538
594
  } else {
@@ -548,7 +604,7 @@ async function createAppDir(targetDir) {
548
604
 
549
605
  async function create(appName) {
550
606
  const cwd = process.cwd();
551
- const targetDir = path$3.resolve(cwd, appName);
607
+ const targetDir = path$4.resolve(cwd, appName);
552
608
  const appType = 'mp';
553
609
  await createAppDir(targetDir); // 创建缓存目录
554
610
 
@@ -556,13 +612,13 @@ async function create(appName) {
556
612
 
557
613
  await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
558
614
 
559
- generator(path$3.join(TEMPLATE_PATH, appType), targetDir, {
615
+ generator(path$4.join(TEMPLATE_PATH, appType), targetDir, {
560
616
  appName,
561
617
  appType
562
618
  }).then(() => {
563
619
  shelljs$4.cd(appName);
564
620
 
565
- const hooks = require(resolve$8(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
621
+ const hooks = require(resolve$9(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
566
622
 
567
623
  if (hooks.afterCreate) {
568
624
  hooks.afterCreate.forEach(item => {
@@ -576,26 +632,26 @@ async function create(appName) {
576
632
  });
577
633
  }
578
634
 
579
- shelljs$4.rm('-rf', resolve$8(appName, TEMPLATE_TKIT_DIR));
635
+ shelljs$4.rm('-rf', resolve$9(appName, TEMPLATE_TKIT_DIR));
580
636
  succeed('项目创建完成.');
581
637
  }).catch(err => {
582
- fail$6(err.message);
638
+ fail$7(err.message);
583
639
  console.log('详细的错误信息:', err);
584
640
  });
585
641
  }
586
642
 
587
643
  var create_1 = create;
588
644
 
589
- const fs$6 = require$$0__default$1;
645
+ const fs$7 = require$$0__default$1;
590
646
  const {
591
647
  DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3,
592
648
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1
593
649
  } = require$$3;
594
650
  const {
595
- fail: fail$5
651
+ fail: fail$6
596
652
  } = log$2;
597
653
  const {
598
- resolve: resolve$7,
654
+ resolve: resolve$8,
599
655
  isObject: isObject$1,
600
656
  isArray
601
657
  } = widgets;
@@ -644,10 +700,10 @@ function getLocalModuleConfig(modules = [], appName, moduleDir, moduleConfigFile
644
700
  modules.forEach(({
645
701
  path
646
702
  }) => {
647
- const moduleConfigPath = resolve$7(path, moduleConfigFilename);
703
+ const moduleConfigPath = resolve$8(path, moduleConfigFilename);
648
704
 
649
- if (fs$6.existsSync(moduleConfigPath)) {
650
- const content = fs$6.readFileSync(moduleConfigPath, 'utf-8');
705
+ if (fs$7.existsSync(moduleConfigPath)) {
706
+ const content = fs$7.readFileSync(moduleConfigPath, 'utf-8');
651
707
  modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName, moduleDir);
652
708
  }
653
709
  });
@@ -672,7 +728,7 @@ function updateMainPackages(appJson, mainPackages = []) {
672
728
 
673
729
  foundMainPackages.forEach(subpackage => {
674
730
  if (!subpackage.pages || !subpackage.pages.length) {
675
- fail$5(`主包 ${subpackage} 不能没有 pages`);
731
+ fail$6(`主包 ${subpackage} 不能没有 pages`);
676
732
  process.exit(-1);
677
733
  }
678
734
 
@@ -698,12 +754,12 @@ function updateMainPackages(appJson, mainPackages = []) {
698
754
 
699
755
 
700
756
  const getAppJsonContent = sourceAppJsonPath => {
701
- if (!fs$6.existsSync(sourceAppJsonPath)) {
702
- fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
757
+ if (!fs$7.existsSync(sourceAppJsonPath)) {
758
+ fail$6(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
703
759
  process.exit(1);
704
760
  }
705
761
 
706
- const appJson = JSON.parse(fs$6.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
762
+ const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
707
763
 
708
764
  appJson.subpackages = [];
709
765
  appJson.pages = [];
@@ -738,12 +794,12 @@ function buildOutputAppJson$1(tmsConfig, modules) {
738
794
  // 获取当前 modules 下的所有子模块的配置内容
739
795
  const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$3, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
740
796
 
741
- const appJson = getAppJsonContent(resolve$7('./app.json')); // 更新app.json中的subpackages
797
+ const appJson = getAppJsonContent(resolve$8('./app.json')); // 更新app.json中的subpackages
742
798
 
743
799
  updateSubpackages(appJson, modulesConfig); // 更新主包,需在subpackages处理完成后执行, pages/
744
800
 
745
801
  updateMainPackages(appJson, tmsConfig.mainPackages);
746
- fs$6.writeFileSync(resolve$7(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
802
+ fs$7.writeFileSync(resolve$8(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
747
803
  return appJson;
748
804
  }
749
805
 
@@ -793,12 +849,12 @@ const {
793
849
  } = global;
794
850
  const {
795
851
  downloadRepoForGit,
796
- resolve: resolve$6
852
+ resolve: resolve$7
797
853
  } = widgets;
798
854
  const {
799
- fail: fail$4
855
+ fail: fail$5
800
856
  } = log$2;
801
- const fs$5 = require$$0__default$1;
857
+ const fs$6 = require$$0__default$1;
802
858
  const shelljs$3 = require$$5__default;
803
859
  /**
804
860
  * 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
@@ -813,7 +869,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
813
869
  return new Promise(resolve => {
814
870
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
815
871
  if (e) {
816
- fail$4(e); // eslint-disable-line
872
+ fail$5(e); // eslint-disable-line
817
873
 
818
874
  console.log('MetalSmith 详细的错误信息:', e);
819
875
  }
@@ -856,9 +912,9 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
856
912
  path
857
913
  } = moduleInfo; // 源码临时存在的源目录
858
914
 
859
- let sourcePath = resolve$6(sourceDir, path); // 源码要放到目标目录
915
+ let sourcePath = resolve$7(sourceDir, path); // 源码要放到目标目录
860
916
 
861
- const targetPath = resolve$6(targetDir, path); // 设置模块的构建分支
917
+ const targetPath = resolve$7(targetDir, path); // 设置模块的构建分支
862
918
 
863
919
  const cloneBranch = buildGitTag && typeof buildGitTag === 'string' ? buildGitTag : 'master'; // 检查缓存中有没有
864
920
 
@@ -873,13 +929,13 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
873
929
  sourcePath = globalInstance.getModuleCache(httpRepoUrl, cloneBranch).dest;
874
930
  }
875
931
 
876
- if (fs$5.existsSync(targetPath)) {
932
+ if (fs$6.existsSync(targetPath)) {
877
933
  shelljs$3.rm('-rf', targetPath);
878
934
  }
879
935
 
880
936
  await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
881
937
  } catch (e) {
882
- fail$4(`downLoadAndMoveModule ${e}`); // eslint-disable-line
938
+ fail$5(`downLoadAndMoveModule ${e}`); // eslint-disable-line
883
939
 
884
940
  process.exit(-1);
885
941
  }
@@ -896,6 +952,9 @@ var defaultTmsConfig$1 = {
896
952
  modules: [],
897
953
  cloudDir: 'cloud',
898
954
  gulp: {
955
+ // 第三方依赖代码需要拷贝到本项目的
956
+ dependencies: {},
957
+
899
958
  /** 编译输出文件夹位置 */
900
959
  outputDir: 'dist',
901
960
 
@@ -908,14 +967,14 @@ var defaultTmsConfig$1 = {
908
967
  };
909
968
 
910
969
  const loadash = require$$0__default$5;
911
- const fs$4 = require$$0__default$1;
970
+ const fs$5 = require$$0__default$1;
912
971
  const {
913
972
  TMS_NAME: TMS_NAME$1,
914
973
  TMS_CONFIG_FILENAME,
915
974
  MODULE_CONFIG_FILENAME
916
975
  } = require$$3;
917
976
  const {
918
- resolve: resolve$5,
977
+ resolve: resolve$6,
919
978
  isObject
920
979
  } = widgets;
921
980
  const {
@@ -923,7 +982,7 @@ const {
923
982
  } = buildAppJson;
924
983
  const defaultTmsConfig = defaultTmsConfig$1;
925
984
  const {
926
- fail: fail$3
985
+ fail: fail$4
927
986
  } = log$2;
928
987
  /**
929
988
  * 读取tms.config.json
@@ -931,10 +990,10 @@ const {
931
990
  */
932
991
 
933
992
  const readTmsConfig$1 = function (env) {
934
- const tmsConfigPath = resolve$5(TMS_CONFIG_FILENAME);
993
+ const tmsConfigPath = resolve$6(TMS_CONFIG_FILENAME);
935
994
 
936
- if (!fs$4.existsSync(tmsConfigPath)) {
937
- fail$3('当前执行目录没有tms.config.js的配置项,请进行配置');
995
+ if (!fs$5.existsSync(tmsConfigPath)) {
996
+ fail$4('当前执行目录没有tms.config.js的配置项,请进行配置');
938
997
  process.exit(1);
939
998
  }
940
999
 
@@ -963,7 +1022,7 @@ const checkModules$1 = function (tmsConfig, modules) {
963
1022
  });
964
1023
 
965
1024
  if (targetModules.length === 0) {
966
- fail$3(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
1025
+ fail$4(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
967
1026
  process.exit(1);
968
1027
  }
969
1028
 
@@ -984,10 +1043,10 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName, moduleDir) => {
984
1043
  path: relativePath,
985
1044
  name: moduleName
986
1045
  }, moduleIndex) => {
987
- const moduleConfigPath = resolve$5(relativePath, MODULE_CONFIG_FILENAME);
1046
+ const moduleConfigPath = resolve$6(relativePath, MODULE_CONFIG_FILENAME);
988
1047
 
989
- if (fs$4.existsSync(moduleConfigPath)) {
990
- let moduleConfigContent = fs$4.readFileSync(moduleConfigPath, 'utf-8');
1048
+ if (fs$5.existsSync(moduleConfigPath)) {
1049
+ let moduleConfigContent = fs$5.readFileSync(moduleConfigPath, 'utf-8');
991
1050
  moduleConfigContent = setModuleConfig(moduleConfigContent, appName, moduleDir);
992
1051
  const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
993
1052
  moduleContentArr.forEach(({
@@ -1015,7 +1074,7 @@ var tkitUtils = {
1015
1074
 
1016
1075
  /* eslint-disable require-jsdoc */
1017
1076
  const ci = require$$0__default$6;
1018
- const path$2 = require$$1__default$1;
1077
+ const path$3 = require$$1__default$1;
1019
1078
  /**
1020
1079
  * 获取小程序ci的Project对象
1021
1080
  * @returns {Object} 小程序ci对象
@@ -1029,7 +1088,7 @@ const getMpCi = ({
1029
1088
  }) => {
1030
1089
  var _cfgJsonContent$packO;
1031
1090
 
1032
- const cfgJsonContent = require(path$2.join(projectPath, 'project.config.json'));
1091
+ const cfgJsonContent = require(path$3.join(projectPath, 'project.config.json'));
1033
1092
 
1034
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(({
1035
1094
  value
@@ -1098,8 +1157,8 @@ var mpCiUtils = {
1098
1157
  /**
1099
1158
  * 本文件主要负责项目或者分包依赖的npm的安装
1100
1159
  */
1101
- const fs$3 = require$$0__default$1;
1102
- const path$1 = require$$1__default$1;
1160
+ const fs$4 = require$$0__default$1;
1161
+ const path$2 = require$$1__default$1;
1103
1162
  const shell = require$$5__default;
1104
1163
  const glob = require$$3__default;
1105
1164
  const LOG = log$2;
@@ -1109,14 +1168,14 @@ const getTarNpmFilename = targetDir => `${targetDir.replace(/\//g, '-')}.tar.gz`
1109
1168
 
1110
1169
 
1111
1170
  const npmCache = function (targetDir, cacheDir) {
1112
- if (!fs$3.existsSync(cacheDir)) {
1113
- fs$3.mkdirSync(cacheDir);
1171
+ if (!fs$4.existsSync(cacheDir)) {
1172
+ fs$4.mkdirSync(cacheDir);
1114
1173
  }
1115
1174
 
1116
1175
  const tarNpmFilename = getTarNpmFilename(targetDir);
1117
1176
  const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1118
1177
 
1119
- if (fs$3.existsSync(tarNpmFilePath)) {
1178
+ if (fs$4.existsSync(tarNpmFilePath)) {
1120
1179
  shell.rm('-rf', tarNpmFilePath);
1121
1180
  }
1122
1181
 
@@ -1132,7 +1191,7 @@ const getNpmCache = function (targetDir, cacheDir) {
1132
1191
  const tarNpmFilename = getTarNpmFilename(targetDir);
1133
1192
  const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1134
1193
 
1135
- if (fs$3.existsSync(tarNpmFilePath)) {
1194
+ if (fs$4.existsSync(tarNpmFilePath)) {
1136
1195
  const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
1137
1196
  shell.exec(cmd, {
1138
1197
  async: false,
@@ -1146,10 +1205,10 @@ const getNpmCache = function (targetDir, cacheDir) {
1146
1205
  const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1147
1206
  const packageJsonFiles = await findAllPackageJson(modules, contextDir);
1148
1207
  await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
1149
- const dir = path$1.dirname(file);
1208
+ const dir = path$2.dirname(file);
1150
1209
  shell.cd(dir);
1151
1210
 
1152
- if (!fs$3.existsSync(`${dir}/node_modules`)) {
1211
+ if (!fs$4.existsSync(`${dir}/node_modules`)) {
1153
1212
  getNpmCache(dir, cacheDir);
1154
1213
  }
1155
1214
 
@@ -1179,7 +1238,7 @@ const findFilesByFilter = (startPath, filter) => {
1179
1238
 
1180
1239
  const find = (startPath, filter) => {
1181
1240
  // 目录不存在
1182
- if (!fs$3.existsSync(startPath)) {
1241
+ if (!fs$4.existsSync(startPath)) {
1183
1242
  LOG.fail(`${startPath}目录不存在`);
1184
1243
  process.exit(-1);
1185
1244
  return;
@@ -1192,10 +1251,10 @@ const findFilesByFilter = (startPath, filter) => {
1192
1251
  return;
1193
1252
  }
1194
1253
 
1195
- const files = fs$3.readdirSync(startPath);
1254
+ const files = fs$4.readdirSync(startPath);
1196
1255
  files.forEach(file => {
1197
- const filename = path$1.join(startPath, file);
1198
- const stat = fs$3.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1256
+ const filename = path$2.join(startPath, file);
1257
+ const stat = fs$4.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1199
1258
 
1200
1259
  if (stat.isDirectory()) {
1201
1260
  find(filename, filter);
@@ -1221,11 +1280,15 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1221
1280
  const packageJsonName = 'package.json'; // 查找文件名
1222
1281
 
1223
1282
  const cwd = contextDir || dirpath;
1224
- const result = [path$1.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1283
+ const result = [path$2.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1225
1284
 
1226
1285
  subRoots.forEach(subRoot => {
1227
- console.log('>>>>>>>>>>>>', subRoot);
1228
- const toppath = path$1.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1286
+ if (!subRoot.root) {
1287
+ LOG.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
1288
+ process.exit(1);
1289
+ }
1290
+
1291
+ const toppath = path$2.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1229
1292
 
1230
1293
  const list = findFilesByFilter(toppath, packageJsonName);
1231
1294
  result.push(...list);
@@ -1241,7 +1304,7 @@ function cloudNpmInstall$1(contextDir) {
1241
1304
  }
1242
1305
 
1243
1306
  files.forEach(file => {
1244
- const dir = path$1.dirname(file);
1307
+ const dir = path$2.dirname(file);
1245
1308
  shell.cd(dir);
1246
1309
  shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
1247
1310
  silent: false
@@ -1260,7 +1323,7 @@ var npmUtils = {
1260
1323
 
1261
1324
  const {
1262
1325
  createTask: createTask$2,
1263
- resolve: resolve$4
1326
+ resolve: resolve$5
1264
1327
  } = widgets;
1265
1328
  const {
1266
1329
  buildMpNpm
@@ -1280,24 +1343,24 @@ const {
1280
1343
  async function install$2(tmsConfig, modules, isCloud = true) {
1281
1344
  const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
1282
1345
 
1283
- await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$4(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1346
+ await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$5(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1284
1347
 
1285
1348
  await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1286
1349
  appId: tmsConfig.appId,
1287
- projectPath: resolve$4('./'),
1350
+ projectPath: resolve$5('./'),
1288
1351
  privateKey: tmsConfig.privateKey
1289
1352
  }); // 安装云函数的
1290
1353
 
1291
- isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$4(tmsConfig.cloudDir));
1354
+ isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$5(tmsConfig.cloudDir));
1292
1355
  }
1293
1356
 
1294
1357
  var install_1 = install$2;
1295
1358
 
1296
1359
  const shelljs$2 = require$$5__default;
1297
- const fs$2 = require$$0__default$1;
1360
+ const fs$3 = require$$0__default$1;
1298
1361
  const io = io$2;
1299
1362
  const {
1300
- resolve: resolve$3,
1363
+ resolve: resolve$4,
1301
1364
  createTask: createTask$1
1302
1365
  } = widgets;
1303
1366
  const {
@@ -1315,7 +1378,7 @@ const {
1315
1378
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
1316
1379
  } = tkitUtils;
1317
1380
  const {
1318
- fail: fail$2
1381
+ fail: fail$3
1319
1382
  } = log$2;
1320
1383
  const install$1 = install_1;
1321
1384
  /**
@@ -1327,31 +1390,31 @@ const install$1 = install_1;
1327
1390
  */
1328
1391
 
1329
1392
  const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1330
- const outputDir = resolve$3(tmsConfig.gulp.outputDir);
1393
+ const outputDir = resolve$4(tmsConfig.gulp.outputDir);
1331
1394
  io.ensureDirExist(outputDir);
1332
1395
  defaultFiles.forEach(item => {
1333
- if (fs$2.existsSync(resolve$3(item))) {
1334
- shelljs$2.cp('-rf', resolve$3(item), resolve$3(tmsConfig.gulp.outputDir, item));
1396
+ if (fs$3.existsSync(resolve$4(item))) {
1397
+ shelljs$2.cp('-rf', resolve$4(item), resolve$4(tmsConfig.gulp.outputDir, item));
1335
1398
  }
1336
1399
  }); // 拷贝模块的package.json到编译输出目录
1337
1400
 
1338
1401
  targetModules.forEach(item => {
1339
- const outputModuleDir = resolve$3(`${tmsConfig.gulp.outputDir}/${item.root}`);
1402
+ const outputModuleDir = resolve$4(`${tmsConfig.gulp.outputDir}/${item.root}`);
1340
1403
 
1341
- if (!fs$2.existsSync(resolve$3(item.path))) {
1342
- fail$2(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1404
+ if (!fs$3.existsSync(resolve$4(item.path))) {
1405
+ fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1343
1406
  process.exit(1);
1344
1407
  }
1345
1408
 
1346
1409
  io.ensureDirExist(outputModuleDir);
1347
- const modulePackagePath = resolve$3(item.path, 'package.json');
1348
- if (fs$2.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
1410
+ const modulePackagePath = resolve$4(item.path, 'package.json');
1411
+ if (fs$3.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
1349
1412
  });
1350
1413
  };
1351
1414
 
1352
1415
  async function task(tmsConfig, targetModules) {
1353
1416
  // 下载和移动代码
1354
- await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$3('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1417
+ await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$4('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1355
1418
 
1356
1419
  const newModules = tmsModulesMergeLocalModuleCfg$1(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$1);
1357
1420
  console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
@@ -1373,12 +1436,12 @@ async function bootstrap(tmsConfig, targetModules) {
1373
1436
 
1374
1437
  var init$5 = bootstrap;
1375
1438
 
1376
- var dev$2 = {exports: {}};
1439
+ var dev$3 = {exports: {}};
1377
1440
 
1378
- const through = require$$0__default$7;
1441
+ const through$1 = require$$0__default$7;
1379
1442
 
1380
- function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
1381
- const stream = through.obj(function (file, enc, cb) {
1443
+ function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
1444
+ const stream = through$1.obj(function (file, enc, cb) {
1382
1445
  if (file.isBuffer()) {
1383
1446
  let contents = String(file.contents);
1384
1447
  let resReg; // eslint-disable-next-line
@@ -1404,18 +1467,217 @@ function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
1404
1467
  return stream;
1405
1468
  }
1406
1469
 
1407
- var replaceEnv_1 = replaceEnv;
1470
+ var replaceEnv_1 = replaceEnv$1;
1471
+
1472
+ const through = require$$0__default$7;
1473
+ const precinct = require$$1__default$4;
1474
+ const path$1 = require$$1__default$1;
1475
+ const {
1476
+ copyFile,
1477
+ ext,
1478
+ fileInDir
1479
+ } = io$2;
1480
+ const {
1481
+ resolve: resolve$3
1482
+ } = widgets;
1483
+ const fs$2 = require$$0__default$1;
1484
+ const {
1485
+ fail: fail$2
1486
+ } = log$2;
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);
1515
+ }
1516
+ } else {
1517
+ console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1518
+ copyFile(depOriginFile, depDestFile);
1519
+ }
1520
+
1521
+ dfsDep(includePath, depOriginFile, depDestFile, extensions);
1522
+ }
1523
+ }
1524
+ });
1525
+ };
1526
+
1527
+ function includeThirdParty(tmsConfig, module, extensions = ['.js', '.ts', '.wxs']) {
1528
+ const stream = through.obj(function (file, enc, cb) {
1529
+ // 依赖分析的文件
1530
+ 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);
1533
+
1534
+ if (file.isBuffer()) {
1535
+ let contents = String(file.contents);
1536
+ const deps = precinct(contents);
1537
+ const copyModules = [];
1538
+ Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
1539
+ const includePath = tmsConfig.gulp.dependencies[includeName];
1540
+ deps.forEach(depItem => {
1541
+ if (depItem.indexOf(includeName) > -1) {
1542
+ // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
1543
+ const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1544
+
1545
+ const depOriginPathExt = ext(depOriginPath, extensions);
1546
+
1547
+ if (!depOriginPathExt) {
1548
+ fail$2(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
1549
+ } // 被依赖文件是否存在 include的path中 (只处理include的文件)
1550
+
1551
+
1552
+ if (depOriginPathExt && fileInDir(includePath, depOriginPathExt.file)) {
1553
+ // eslint-disable-next-line
1554
+ const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
1555
+ const regRes = depItem.match(reg) || [];
1556
+
1557
+ if (regRes[2]) {
1558
+ const depDestPath = resolve$3(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
1559
+ const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext; // {
1560
+ // depOriginFile: '/Users/odile/workspace/tms-frontend1/miniprogram/thirdparty/libs/timer.js',
1561
+ // depDestFile: `/Users/odile/workspace/tms-frontend1/tools/demo1/dist/modules/
1562
+ // aggredriving/thirdparty/libs/timer.js`,
1563
+ // beforeDepPath: '../../../../thirdparty/libs/timer',
1564
+ // afterDepPath: '../../thirdparty/libs/timer'
1565
+ // }
1566
+
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
+ });
1574
+ }
1575
+ }
1576
+ }
1577
+ });
1578
+ });
1579
+ copyModules.forEach(({
1580
+ includePath,
1581
+ depOriginFile,
1582
+ depDestFile,
1583
+ beforeDepPath,
1584
+ afterDepPath
1585
+ }) => {
1586
+ if (fs$2.existsSync(depDestFile)) {
1587
+ const depDestContent = fs$2.readFileSync(depDestFile, 'utf8');
1588
+ const depOriginContent = fs$2.readFileSync(depOriginFile, 'utf8');
1589
+
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);
1597
+ }
1598
+
1599
+ contents = contents.replace(beforeDepPath, afterDepPath);
1600
+ dfsDep(includePath, depOriginFile, depDestFile, extensions);
1601
+ }); // eslint-disable-next-line
1602
+
1603
+ file.contents = new Buffer(contents);
1604
+ }
1605
+
1606
+ this.push(file);
1607
+ cb();
1608
+ });
1609
+ return stream;
1610
+ }
1611
+
1612
+ var includeDep$1 = includeThirdParty;
1613
+
1614
+ const {
1615
+ src: src$1,
1616
+ dest
1617
+ } = require$$0__default$8;
1618
+ const px2rpx = require$$1__default$5;
1619
+ const less = require$$2__default$1;
1620
+ const rename = require$$3__default$1;
1621
+ const watch = require$$4__default;
1622
+ const image = require$$5__default$1;
1623
+ const replaceEnv = replaceEnv_1;
1624
+ const includeDep = includeDep$1;
1625
+
1626
+ var compile = function (tmsConfig, {
1627
+ glob,
1628
+ destPath,
1629
+ srcOption,
1630
+ module,
1631
+ watchOption = {
1632
+ events: ['change', 'add', 'unlink']
1633
+ },
1634
+ isWatch
1635
+ }) {
1636
+ Object.keys(glob).forEach(globKey => {
1637
+ const globValue = glob[globKey];
1638
+ let srcPipe = src$1(globValue, srcOption);
1639
+
1640
+ if (isWatch) {
1641
+ srcPipe = srcPipe.pipe(watch(globValue, watchOption));
1642
+ }
1643
+
1644
+ switch (globKey) {
1645
+ case 'js':
1646
+ srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(includeDep(tmsConfig, module)).pipe(dest(destPath));
1647
+ break;
1648
+
1649
+ case 'css':
1650
+ srcPipe.pipe(less()).pipe(px2rpx({
1651
+ designWidth: 375,
1652
+ // 设计稿宽度,默认为750
1653
+ precision: 2 // 小数最大精度,默认为6
1654
+
1655
+ })).pipe(rename({
1656
+ extname: '.wxss'
1657
+ })).pipe(dest(destPath));
1658
+ break;
1659
+
1660
+ case 'json':
1661
+ srcPipe.pipe(dest(destPath));
1662
+ break;
1663
+
1664
+ case 'html':
1665
+ srcPipe.pipe(dest(destPath));
1666
+ break;
1667
+
1668
+ case 'image':
1669
+ srcPipe.pipe(image()).pipe(dest(destPath));
1670
+ break;
1671
+
1672
+ case 'other':
1673
+ srcPipe.pipe(dest(destPath));
1674
+ break;
1675
+ }
1676
+ });
1677
+ };
1408
1678
 
1409
1679
  (function (module) {
1410
- const fs = require$$0__default$1;
1411
- const {
1412
- src,
1413
- dest
1414
- } = require$$1__default$4;
1415
- const px2rpx = require$$2__default$1;
1416
- const less = require$$3__default$1;
1417
- const rename = require$$4__default;
1418
- const watch = require$$5__default$1;
1680
+ const watch = require$$4__default;
1419
1681
  const {
1420
1682
  resolve
1421
1683
  } = widgets;
@@ -1425,73 +1687,73 @@ var replaceEnv_1 = replaceEnv;
1425
1687
  const {
1426
1688
  DEFAULT_COPY_CONFIG
1427
1689
  } = require$$3;
1428
- const replaceEnv = replaceEnv_1;
1690
+ const compile$1 = compile;
1429
1691
 
1430
- module.exports = async (tmsConfig, newModules) => {
1692
+ module.exports = async (tmsConfig, newModules, isWatch = true) => {
1431
1693
  var _tmsConfig$gulp;
1432
1694
 
1433
1695
  // 监听app.json
1434
- watch(resolve('app.json'), {
1435
- ignoreInitial: false,
1436
- events: ['add', 'change']
1437
- }, () => {
1696
+ if (isWatch) {
1697
+ watch(resolve('app.json'), {
1698
+ ignoreInitial: false,
1699
+ events: ['add', 'change']
1700
+ }, () => {
1701
+ buildOutputAppJson(tmsConfig, newModules);
1702
+ });
1703
+ } else {
1438
1704
  buildOutputAppJson(tmsConfig, newModules);
1439
- }); // 监听根目录的文件
1705
+ } // 监听根目录的文件
1706
+
1707
+
1708
+ compile$1(tmsConfig, {
1709
+ glob: {
1710
+ json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
1711
+ css: ['app.less', 'app.wxss'].map(item => resolve(item)),
1712
+ js: ['app.js', 'app.ts'].map(item => resolve(item))
1713
+ },
1714
+ module: {
1715
+ from: '',
1716
+ to: ''
1717
+ },
1718
+ destPath: resolve(tmsConfig.gulp.outputDir),
1719
+ srcOption: {
1720
+ allowEmpty: true
1721
+ },
1722
+ isWatch
1723
+ }); // 监听模块的文件
1440
1724
 
1441
- DEFAULT_COPY_CONFIG.forEach(item => {
1442
- if (fs.existsSync(resolve(item))) {
1443
- src(resolve(item)).pipe(watch(resolve(item), {
1725
+ for (const module of newModules) {
1726
+ if (isWatch) {
1727
+ // 监听模块配置文件
1728
+ watch(`${resolve(module.path)}/**/module.config.json`, {
1444
1729
  events: ['change']
1445
- })).pipe(dest(resolve(tmsConfig.gulp.outputDir)));
1730
+ }, () => {
1731
+ buildOutputAppJson(tmsConfig, newModules);
1732
+ });
1733
+ } else {
1734
+ buildOutputAppJson(tmsConfig, newModules);
1446
1735
  }
1447
- });
1448
- src([resolve('app.less'), resolve('app.wxss')], {
1449
- allowEmpty: true
1450
- }).pipe(watch(`${resolve()}/(app.less|app.wxss)`, {
1451
- events: ['change']
1452
- })).pipe(less()).pipe(px2rpx({
1453
- designWidth: 375,
1454
- // 设计稿宽度,默认为750
1455
- precision: 2 // 小数最大精度,默认为6
1456
-
1457
- })).pipe(rename({
1458
- extname: '.wxss'
1459
- })).pipe(dest(resolve(tmsConfig.gulp.outputDir)));
1460
- src([resolve('app.js'), resolve('app.ts')], {
1461
- allowEmpty: true
1462
- }).pipe(watch(`${resolve()}/(app.js|app.ts)`, {
1463
- events: ['change']
1464
- })).pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(dest(resolve(tmsConfig.gulp.outputDir))); // 监听模块的文件
1465
1736
 
1466
- for (const module of newModules) {
1467
- // 监听模块js文件
1468
- src([`${resolve(module.path)}/**/*.js`, `${resolve(module.path)}/**/*.ts`, `${resolve(module.path)}/**/*.wxs`]).pipe(watch(`${resolve(module.path)}/**/(*.js|*.ts|*.wxs)`, {
1469
- events: ['add', 'change']
1470
- })).pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听json文件
1471
-
1472
- src([`${resolve(module.path)}/**/*.json`]).pipe(watch(`${resolve(module.path)}/**/*.json`, {
1473
- events: ['add', 'change']
1474
- })).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听css文件
1475
-
1476
- src([`${resolve(module.path)}/**/*.less`, `${resolve(module.path)}/**/*.wxss`]).pipe(watch(`${resolve(module.path)}/**/(*.less|*.wxss)`, {
1477
- events: ['add', 'change']
1478
- })).pipe(less()).pipe(px2rpx({
1479
- designWidth: 375,
1480
- // 设计稿宽度,默认为750
1481
- precision: 2 // 小数最大精度,默认为6
1482
-
1483
- })).pipe(rename({
1484
- extname: '.wxss'
1485
- })).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听wxml文件
1486
-
1487
- src([`${resolve(module.path)}/**/*.wxml`]).pipe(watch(`${resolve(module.path)}/**/*.wxml`, {
1488
- events: ['add', 'change']
1489
- })).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听模块配置文件
1490
-
1491
- watch(`${resolve(module.path)}/**/module.config.json`, {
1492
- events: ['change']
1493
- }, () => {
1494
- buildOutputAppJson(tmsConfig, newModules);
1737
+ 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}`
1743
+ };
1744
+ compile$1(tmsConfig, {
1745
+ glob: { ...glob,
1746
+ other: [`${resolve(module.path)}/**/*`, ...Object.keys(glob).map(key => `!${glob[key]}`)]
1747
+ },
1748
+ destPath: resolve(tmsConfig.gulp.outputDir, module.root),
1749
+ module: {
1750
+ from: module.path,
1751
+ to: module.root
1752
+ },
1753
+ srcOption: {
1754
+ allowEmpty: true
1755
+ },
1756
+ isWatch
1495
1757
  });
1496
1758
  } // 监听copy模块
1497
1759
 
@@ -1500,16 +1762,31 @@ var replaceEnv_1 = replaceEnv;
1500
1762
  for (const item of (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.copyDir) {
1501
1763
  var _tmsConfig$gulp2;
1502
1764
 
1503
- src([item.from]).pipe(watch(item.from, {
1504
- events: ['add', 'change']
1505
- })).pipe(dest(item.to));
1765
+ const glob = {
1766
+ js: `${item.from}/**/*.{js,ts,wxs}`,
1767
+ json: `${item.from}/**/*.json`,
1768
+ css: `${item.from}/**/*.{less,wxss}`,
1769
+ html: `${item.from}/**/*.wxml`,
1770
+ image: `${item.from}/**/*.{png,jpg,jpeg,gif,svg}`
1771
+ };
1772
+ compile$1(tmsConfig, {
1773
+ glob: { ...glob,
1774
+ other: [`${item.from}/**/*`, ...Object.keys(glob).map(key => `!${glob[key]}`)]
1775
+ },
1776
+ destPath: item.to,
1777
+ module: item,
1778
+ srcOption: {
1779
+ allowEmpty: true
1780
+ },
1781
+ isWatch
1782
+ });
1506
1783
  }
1507
1784
  }
1508
1785
  };
1509
- })(dev$2);
1786
+ })(dev$3);
1510
1787
 
1511
1788
  const fs$1 = require$$0__default$1;
1512
- const semver$1 = require$$1__default$5;
1789
+ const semver$1 = require$$1__default$6;
1513
1790
  const {
1514
1791
  resolve: resolve$2
1515
1792
  } = widgets;
@@ -1600,7 +1877,7 @@ var checkDependencies_1 = {
1600
1877
  checkDependencies: checkDependencies$1
1601
1878
  };
1602
1879
 
1603
- const gulpDev = dev$2.exports;
1880
+ const gulpDev = dev$3.exports;
1604
1881
  const fs = require$$0__default$1;
1605
1882
  const {
1606
1883
  resolve: resolve$1
@@ -1663,7 +1940,7 @@ function isInit(tmsConfig, targetModules, contextDir) {
1663
1940
  return checkDependencies(targetModules, resolve$1('./'), tmsConfig.gulp.outputDir);
1664
1941
  }
1665
1942
 
1666
- async function dev$1(tmsConfig, targetModules, env) {
1943
+ async function dev$2(tmsConfig, targetModules, env) {
1667
1944
  // tms.config.js的modules 合并 module.config.json的配置项
1668
1945
  let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR); // 判断是否进行init命令
1669
1946
 
@@ -1677,90 +1954,20 @@ async function dev$1(tmsConfig, targetModules, env) {
1677
1954
  gulpDev(tmsConfig, newModules, env);
1678
1955
  }
1679
1956
 
1680
- var dev_1 = dev$1;
1681
-
1682
- var build$2 = {exports: {}};
1683
-
1684
- (function (module) {
1685
- const fs = require$$0__default$1;
1686
- const {
1687
- src,
1688
- dest
1689
- } = require$$1__default$4;
1690
- const px2rpx = require$$2__default$1;
1691
- const less = require$$3__default$1;
1692
- const rename = require$$4__default;
1693
- const {
1694
- resolve
1695
- } = widgets;
1696
- const {
1697
- buildOutputAppJson
1698
- } = buildAppJson;
1699
- const {
1700
- DEFAULT_COPY_CONFIG
1701
- } = require$$3;
1702
- const replaceEnv = replaceEnv_1;
1703
-
1704
- module.exports = async (tmsConfig, newModules) => {
1705
- var _tmsConfig$gulp;
1706
-
1707
- // app.json
1708
- buildOutputAppJson(tmsConfig, newModules); // 监听根目录的文件
1709
-
1710
- DEFAULT_COPY_CONFIG.forEach(item => {
1711
- if (fs.existsSync(resolve(item))) {
1712
- src(resolve(item)).pipe(dest(resolve(tmsConfig.gulp.outputDir)));
1713
- }
1714
- });
1715
- src([resolve('app.less'), resolve('app.wxss')], {
1716
- allowEmpty: true
1717
- }).pipe(less()).pipe(px2rpx({
1718
- designWidth: 375,
1719
- // 设计稿宽度,默认为750
1720
- precision: 2 // 小数最大精度,默认为6
1721
-
1722
- })).pipe(rename({
1723
- extname: '.wxss'
1724
- })).pipe(dest(resolve(tmsConfig.gulp.outputDir)));
1725
- src([resolve('app.js'), resolve('app.ts')], {
1726
- allowEmpty: true
1727
- }).pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(dest(resolve(tmsConfig.gulp.outputDir))); // 监听模块的文件
1728
-
1729
- for (const module of newModules) {
1730
- // 监听模块js文件
1731
- src([`${resolve(module.path)}/**/*.js`, `${resolve(module.path)}/**/*.ts`, `${resolve(module.path)}/**/*.wxs`]).pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听json文件
1732
-
1733
- src([`${resolve(module.path)}/**/*.json`]).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听css文件
1734
-
1735
- src([`${resolve(module.path)}/**/*.less`, `${resolve(module.path)}/**/*.wxss`]).pipe(less()).pipe(px2rpx({
1736
- designWidth: 375,
1737
- // 设计稿宽度,默认为750
1738
- precision: 2 // 小数最大精度,默认为6
1957
+ var dev_1 = dev$2;
1739
1958
 
1740
- })).pipe(rename({
1741
- extname: '.wxss'
1742
- })).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听wxml文件
1959
+ const dev$1 = dev$3.exports;
1743
1960
 
1744
- src([`${resolve(module.path)}/**/*.wxml`]).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
1745
- } // 监听copy模块
1746
-
1747
-
1748
- if ((tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gulp = tmsConfig.gulp) === null || _tmsConfig$gulp === void 0 ? void 0 : _tmsConfig$gulp.copyDir.length) > 0) {
1749
- for (const item of (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.copyDir) {
1750
- var _tmsConfig$gulp2;
1751
-
1752
- src([item.from]).pipe(dest(item.to));
1753
- }
1754
- }
1755
- };
1756
- })(build$2);
1961
+ var build$2 = async (tmsConfig, newModules) => {
1962
+ dev$1(tmsConfig, newModules, false);
1963
+ };
1757
1964
 
1758
1965
  const shelljs = require$$5__default;
1759
1966
  const {
1760
1967
  resolve
1761
1968
  } = widgets;
1762
1969
  const init$3 = init$5;
1763
- const gulpBuild = build$2.exports;
1970
+ const gulpBuild = build$2;
1764
1971
 
1765
1972
  async function build$1(tmsConfig, targetModules, env) {
1766
1973
  // 开始构建前,清理输出目录
@@ -1893,7 +2100,7 @@ var entry = [{
1893
2100
 
1894
2101
  var require$$6 = {
1895
2102
  name: "@tmsfe/tmskit",
1896
- version: "0.0.5-beta.0",
2103
+ version: "0.0.5-beta.1",
1897
2104
  description: "tmskit",
1898
2105
  main: "main.js",
1899
2106
  bin: {
@@ -1930,6 +2137,7 @@ var require$$6 = {
1930
2137
  ejs: "^3.1.5",
1931
2138
  "glob-ignore": "^1.0.2",
1932
2139
  gulp: "^4.0.2",
2140
+ "gulp-image": "^5.1.0",
1933
2141
  "gulp-less": "^5.0.0",
1934
2142
  "gulp-px-to-rpx": "^1.0.7",
1935
2143
  "gulp-rename": "^2.0.0",
@@ -1946,14 +2154,14 @@ var require$$6 = {
1946
2154
  through2: "^4.0.2"
1947
2155
  },
1948
2156
  engines: {
1949
- node: "^12.17.0 || >= 14.0.0"
2157
+ node: "^12.17.0 || >= 14.13.1"
1950
2158
  },
1951
2159
  jest: {
1952
2160
  testEnvironment: "jest-environment-node"
1953
2161
  }
1954
2162
  };
1955
2163
 
1956
- const semver = require$$1__default$5;
2164
+ const semver = require$$1__default$6;
1957
2165
  const packageJson = require$$6;
1958
2166
  const chalk$1 = require$$0__default$2;
1959
2167
  const {
@@ -2046,6 +2254,6 @@ if (!process.argv.slice(2).length) {
2046
2254
  }
2047
2255
 
2048
2256
  program.parse(process.argv);
2049
- var src = src$1;
2257
+ var src = src$2;
2050
2258
 
2051
2259
  module.exports = src;