@tmsfe/tmskit 0.0.13 → 0.0.15-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
@@ -5,25 +5,25 @@ var require$$1 = require('moment');
5
5
  var require$$0$1 = require('commander');
6
6
  var require$$1$1 = require('leven');
7
7
  var require$$2 = require('ora');
8
- var require$$1$2 = require('path');
8
+ var require$$3 = require('path');
9
9
  var require$$0$2 = require('fs');
10
10
  var require$$0$3 = require('shelljs');
11
11
  var require$$0$4 = require('async');
12
- var require$$1$3 = require('ejs');
13
- var require$$1$4 = require('inquirer');
12
+ var require$$1$2 = require('ejs');
13
+ var require$$1$3 = require('inquirer');
14
14
  var require$$0$5 = require('metalsmith');
15
15
  var require$$0$6 = require('lodash');
16
- var require$$1$5 = require('crypto');
16
+ var require$$1$4 = require('crypto');
17
17
  var require$$0$7 = require('miniprogram-ci');
18
18
  var require$$5 = require('glob-ignore');
19
- var require$$1$6 = require('fs-extra');
19
+ var require$$1$5 = require('fs-extra');
20
+ var require$$1$6 = require('semver');
20
21
  var require$$0$8 = require('strip-comments');
21
22
  var require$$0$9 = require('through2');
22
23
  var require$$1$7 = require('precinct');
23
24
  var require$$1$8 = require('htmlparser2');
24
25
  var require$$0$a = require('gulp');
25
26
  var require$$0$b = require('gulp-watch');
26
- var require$$1$9 = require('semver');
27
27
 
28
28
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
29
29
 
@@ -32,17 +32,18 @@ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
32
32
  var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
33
33
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
34
34
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
35
- var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
35
+ var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
36
36
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
37
37
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
38
38
  var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
39
+ var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
39
40
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
40
- var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
41
41
  var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
42
42
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
43
- var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
43
+ var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
44
44
  var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
45
45
  var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
46
+ var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
46
47
  var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
47
48
  var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
48
49
  var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
@@ -50,7 +51,6 @@ var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
50
51
  var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
51
52
  var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
52
53
  var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
53
- var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
54
54
 
55
55
  function getAugmentedNamespace(n) {
56
56
  if (n.__esModule) return n;
@@ -83,12 +83,12 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
83
83
  * @returns {undefined} 无
84
84
  */
85
85
 
86
- const fail$9 = (message = '') => {
86
+ const fail$8 = (message = '') => {
87
87
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
88
88
 
89
89
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
90
90
 
91
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
91
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
92
92
  };
93
93
  /**
94
94
  * 打印绿底黑字格式的文字
@@ -102,7 +102,7 @@ const succeed$1 = (message = '') => {
102
102
 
103
103
  const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
104
104
 
105
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
105
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
106
106
  };
107
107
  /**
108
108
  * 打印warn提示
@@ -111,24 +111,24 @@ const succeed$1 = (message = '') => {
111
111
  */
112
112
 
113
113
 
114
- const warn = message => {
115
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
114
+ const warn$1 = message => {
115
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
116
116
  };
117
117
 
118
- const info$9 = (...args) => console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
118
+ const info$9 = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
119
119
 
120
120
  var log$1 = {
121
- fail: fail$9,
121
+ fail: fail$8,
122
122
  succeed: succeed$1,
123
- warn,
123
+ warn: warn$1,
124
124
  info: info$9
125
125
  };
126
126
 
127
127
  const program$1 = require$$0__default$1;
128
128
  const leven = require$$1__default$1;
129
129
  const ora = require$$2__default;
130
- const path$b = require$$1__default$2;
131
- const fs$e = require$$0__default$2;
130
+ const path$b = require$$3__default;
131
+ const fs$c = require$$0__default$2;
132
132
  const shelljs$6 = require$$0__default$3;
133
133
  const {
134
134
  info: info$8
@@ -141,7 +141,7 @@ const shelljsOptions = {
141
141
 
142
142
  const cwd = process.cwd();
143
143
 
144
- function resolve$g(...args) {
144
+ function resolve$e(...args) {
145
145
  return path$b.resolve(cwd, ...args);
146
146
  }
147
147
  /**
@@ -198,7 +198,7 @@ function downloadRepoForGit$2(url, dest, branch) {
198
198
  const cwd = process.cwd();
199
199
  return new Promise((resolve, reject) => {
200
200
  // 如果目标目录不存在
201
- if (fs$e.existsSync(dest)) {
201
+ if (fs$c.existsSync(dest)) {
202
202
  shelljs$6.rm('-rf', path$b.join(dest));
203
203
  }
204
204
 
@@ -282,10 +282,11 @@ const cost = start => Date.now() - start;
282
282
  function createTask$3(task, startText, endText) {
283
283
  return async (...args) => {
284
284
  const start = Date.now();
285
- const spinner = ora(startText);
285
+ const spinner = ora();
286
+ info$8(startText);
286
287
  spinner.start();
287
288
  const result = await task(...args);
288
- endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
289
+ endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
289
290
  spinner.stop();
290
291
  return result;
291
292
  };
@@ -315,7 +316,7 @@ const relativeCwdPath$1 = function (file) {
315
316
  };
316
317
 
317
318
  var widgets = {
318
- resolve: resolve$g,
319
+ resolve: resolve$e,
319
320
  isObject: isObject$2,
320
321
  isArray: isArray$1,
321
322
  createTask: createTask$3,
@@ -335,11 +336,11 @@ const os = require('os'); // 用户目录
335
336
 
336
337
  const HOME_DIR = os.homedir(); // 所有文件的缓存目录
337
338
 
338
- const CACHE_DIR$1 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
339
+ const CACHE_DIR$2 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
339
340
 
340
- const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
341
+ const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
341
342
 
342
- const MODULE_CODE_DIR$2 = path$a.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
343
+ const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
343
344
 
344
345
  const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
345
346
 
@@ -350,7 +351,7 @@ const TMS_PRIVATE_FILENAME$1 = 'tms.private.config.js'; // 模块代码的默认
350
351
 
351
352
  const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目录
352
353
 
353
- const DEFAULT_CLOUD_MODULE_DIR$1 = './cloud'; // 模块的配置文件的名称
354
+ const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
354
355
 
355
356
  const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
356
357
 
@@ -369,7 +370,7 @@ const MODULE_CONFIG_INVALID_KEY$1 = ['entranceDeclare', 'entryPagePath'];
369
370
  var constant = /*#__PURE__*/Object.freeze({
370
371
  __proto__: null,
371
372
  HOME_DIR: HOME_DIR,
372
- CACHE_DIR: CACHE_DIR$1,
373
+ CACHE_DIR: CACHE_DIR$2,
373
374
  TEMPLATE_DIR: TEMPLATE_DIR$1,
374
375
  TEMPLATE_PATH: TEMPLATE_PATH$1,
375
376
  TMS_NAME: TMS_NAME$1,
@@ -379,17 +380,17 @@ var constant = /*#__PURE__*/Object.freeze({
379
380
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
380
381
  DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
381
382
  DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
382
- MODULE_CODE_DIR: MODULE_CODE_DIR$2,
383
+ MODULE_CODE_DIR: MODULE_CODE_DIR$1,
383
384
  ENV: ENV,
384
385
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
385
386
  MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1,
386
- DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR$1
387
+ DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
387
388
  });
388
389
 
389
390
  var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
390
391
 
391
- const fs$d = require$$0__default$2;
392
- const path$9 = require$$1__default$2;
392
+ const fs$b = require$$0__default$2;
393
+ const path$9 = require$$3__default;
393
394
  const {
394
395
  info: info$7
395
396
  } = log$1;
@@ -402,12 +403,12 @@ const {
402
403
  * @returns
403
404
  */
404
405
 
405
- const isDirEmpty = dirname => fs$d.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
406
+ const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
406
407
 
407
408
 
408
409
  const isFile = pathName => {
409
410
  try {
410
- const stat = fs$d.lstatSync(pathName);
411
+ const stat = fs$b.lstatSync(pathName);
411
412
  return stat.isFile();
412
413
  } catch {
413
414
  return false;
@@ -420,8 +421,8 @@ const isFile = pathName => {
420
421
 
421
422
 
422
423
  const ensureDirExist = dirname => {
423
- if (!fs$d.existsSync(dirname)) {
424
- fs$d.mkdirSync(dirname, {
424
+ if (!fs$b.existsSync(dirname)) {
425
+ fs$b.mkdirSync(dirname, {
425
426
  recursive: true
426
427
  });
427
428
  }
@@ -429,20 +430,20 @@ const ensureDirExist = dirname => {
429
430
 
430
431
 
431
432
  const copyFile = function (src, dest) {
432
- if (fs$d.existsSync(dest)) {
433
- fs$d.unlinkSync(dest);
433
+ if (fs$b.existsSync(dest)) {
434
+ fs$b.unlinkSync(dest);
434
435
  }
435
436
 
436
437
  const dir = path$9.dirname(dest);
437
438
  ensureDirExist(dir);
438
- fs$d.copyFileSync(src, dest);
439
+ fs$b.copyFileSync(src, dest);
439
440
  }; // 判断文件内容是否一致,不一致再进行拷贝
440
441
 
441
442
 
442
443
  function diffContentCopyFile$3(originFile, destFile) {
443
- if (fs$d.existsSync(destFile)) {
444
- const depDestContent = fs$d.readFileSync(destFile, 'utf8');
445
- const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
444
+ if (fs$b.existsSync(destFile)) {
445
+ const depDestContent = fs$b.readFileSync(destFile, 'utf8');
446
+ const depOriginContent = fs$b.readFileSync(originFile, 'utf8');
446
447
 
447
448
  if (depDestContent !== depOriginContent) {
448
449
  info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
@@ -460,7 +461,7 @@ function ext$3(filePath, extensions) {
460
461
  let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
461
462
 
462
463
  try {
463
- const stat = fs$d.lstatSync(newFilePath);
464
+ const stat = fs$b.lstatSync(newFilePath);
464
465
 
465
466
  if (stat.isDirectory()) {
466
467
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
@@ -471,7 +472,7 @@ function ext$3(filePath, extensions) {
471
472
  for (const ext of extensions) {
472
473
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
473
474
 
474
- if (fs$d.existsSync(file)) {
475
+ if (fs$b.existsSync(file)) {
475
476
  return {
476
477
  ext,
477
478
  extPath: extPath + ext,
@@ -489,7 +490,7 @@ function ext$3(filePath, extensions) {
489
490
 
490
491
 
491
492
  const fileInDir$3 = (dir, file) => {
492
- if (!fs$d.existsSync(dir) || !fs$d.existsSync(file)) {
493
+ if (!fs$b.existsSync(dir) || !fs$b.existsSync(file)) {
493
494
  return false;
494
495
  }
495
496
 
@@ -513,7 +514,7 @@ var io$2 = {
513
514
  };
514
515
 
515
516
  const async = require$$0__default$4;
516
- const ejs = require$$1__default$3;
517
+ const ejs = require$$1__default$2;
517
518
 
518
519
  const render$1 = (files, metalsmith, next) => {
519
520
  const keys = Object.keys(files);
@@ -532,10 +533,10 @@ const render$1 = (files, metalsmith, next) => {
532
533
 
533
534
  var render_1 = render$1;
534
535
 
535
- const fs$c = require$$0__default$2;
536
- const inquirer = require$$1__default$4;
536
+ const fs$a = require$$0__default$2;
537
+ const inquirer = require$$1__default$3;
537
538
  const {
538
- resolve: resolve$f
539
+ resolve: resolve$d
539
540
  } = widgets;
540
541
  const {
541
542
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -549,12 +550,12 @@ const {
549
550
  const parseTemplateQuestions = dir => {
550
551
  let prompts = [];
551
552
 
552
- if (!fs$c.existsSync(`${dir}/questions.json`)) {
553
+ if (!fs$a.existsSync(`${dir}/questions.json`)) {
553
554
  return prompts;
554
555
  }
555
556
 
556
557
  try {
557
- const json = JSON.parse(fs$c.readFileSync(`${dir}/questions.json`));
558
+ const json = JSON.parse(fs$a.readFileSync(`${dir}/questions.json`));
558
559
 
559
560
  if (Array.isArray(json) && json.length > 0) {
560
561
  json.forEach((item, index) => {
@@ -587,7 +588,7 @@ const isQuestionType = result => {
587
588
  };
588
589
 
589
590
  const ask$1 = templateDir => (files, metalsmith, next) => {
590
- const prompts = parseTemplateQuestions(resolve$f(templateDir, TEMPLATE_TKIT_DIR$1));
591
+ const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
591
592
  const metadata = metalsmith.metadata();
592
593
  const filteredPrompts = prompts.filter(prompt => {
593
594
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -629,8 +630,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
629
630
 
630
631
  var generator_1 = generator$1;
631
632
 
632
- const path$8 = require$$1__default$2;
633
- const fs$b = require$$0__default$2;
633
+ const path$8 = require$$3__default;
634
+ const fs$9 = require$$0__default$2;
634
635
  const shelljs$5 = require$$0__default$3;
635
636
  const {
636
637
  TEMPLATE_DIR,
@@ -640,11 +641,11 @@ const {
640
641
  const {
641
642
  downloadRepoForGit: downloadRepoForGit$1,
642
643
  createTask: createTask$2,
643
- resolve: resolve$e
644
+ resolve: resolve$c
644
645
  } = widgets;
645
646
  const io$1 = io$2;
646
647
  const {
647
- fail: fail$8,
648
+ fail: fail$7,
648
649
  succeed,
649
650
  info: info$6
650
651
  } = log$1;
@@ -657,9 +658,9 @@ const generator = generator_1;
657
658
 
658
659
  async function createAppDir(targetDir) {
659
660
  // 如果目录非空或者已经存在,提示用户,做选择
660
- if (fs$b.existsSync(targetDir)) {
661
+ if (fs$9.existsSync(targetDir)) {
661
662
  if (!(await io$1.isDirEmpty(targetDir))) {
662
- fail$8('该目录名已经存在,换个项目名字吧~');
663
+ fail$7('该目录名已经存在,换个项目名字吧~');
663
664
  process.exit(1);
664
665
  }
665
666
  } else {
@@ -689,7 +690,7 @@ async function create(appName) {
689
690
  }).then(() => {
690
691
  shelljs$5.cd(appName);
691
692
 
692
- const hooks = require(resolve$e(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
693
+ const hooks = require(resolve$c(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
693
694
 
694
695
  if (hooks.afterCreate) {
695
696
  hooks.afterCreate.forEach(item => {
@@ -703,10 +704,10 @@ async function create(appName) {
703
704
  });
704
705
  }
705
706
 
706
- shelljs$5.rm('-rf', resolve$e(appName, TEMPLATE_TKIT_DIR));
707
+ shelljs$5.rm('-rf', resolve$c(appName, TEMPLATE_TKIT_DIR));
707
708
  succeed('项目创建完成.');
708
709
  }).catch(err => {
709
- fail$8(err.message);
710
+ fail$7(err.message);
710
711
  info$6('详细的错误信息:', err);
711
712
  });
712
713
  }
@@ -736,32 +737,32 @@ var defaultTmsConfig$1 = {
736
737
  * 用来读取处理tms.config.js与module.config.json字段
737
738
  */
738
739
  const loadash = require$$0__default$6;
739
- const fs$a = require$$0__default$2;
740
+ const fs$8 = require$$0__default$2;
740
741
  const {
741
742
  TMS_CONFIG_FILENAME,
742
743
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
743
744
  TMS_PRIVATE_FILENAME
744
745
  } = require$$4;
745
746
  const {
746
- resolve: resolve$d,
747
+ resolve: resolve$b,
747
748
  isObject: isObject$1,
748
749
  isArray
749
750
  } = widgets;
750
751
  const defaultTmsConfig = defaultTmsConfig$1;
751
752
  const {
752
- fail: fail$7
753
+ fail: fail$6
753
754
  } = log$1;
754
- const path$7 = require$$1__default$2;
755
+ const path$7 = require$$3__default;
755
756
  /**
756
757
  * 读取tms.config.js
757
758
  * @param env {string} 环境变量
758
759
  */
759
760
 
760
761
  const readTmsConfig$1 = function (env) {
761
- const tmsConfigPath = resolve$d(TMS_CONFIG_FILENAME);
762
+ const tmsConfigPath = resolve$b(TMS_CONFIG_FILENAME);
762
763
 
763
- if (!fs$a.existsSync(tmsConfigPath)) {
764
- fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
764
+ if (!fs$8.existsSync(tmsConfigPath)) {
765
+ fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
765
766
  process.exit(1);
766
767
  }
767
768
 
@@ -808,9 +809,9 @@ const convertModules = modules => {
808
809
 
809
810
  const readTmsPrivateCf$1 = function () {
810
811
  let tmsPrivateCf = {};
811
- const tmsPrivatePath = resolve$d(TMS_PRIVATE_FILENAME);
812
+ const tmsPrivatePath = resolve$b(TMS_PRIVATE_FILENAME);
812
813
 
813
- if (fs$a.existsSync(tmsPrivatePath)) {
814
+ if (fs$8.existsSync(tmsPrivatePath)) {
814
815
  tmsPrivateCf = require(tmsPrivatePath);
815
816
  } // 处理modules字段
816
817
 
@@ -839,7 +840,7 @@ const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
839
840
  });
840
841
 
841
842
  if (targetModules.length === 0) {
842
- fail$7(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
843
+ fail$6(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
843
844
  >name字段与module.config.json的name字段是否一致`);
844
845
  isQuit && process.exit(1);
845
846
  }
@@ -902,10 +903,10 @@ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
902
903
  modules.forEach(({
903
904
  path
904
905
  }) => {
905
- const moduleConfigPath = resolve$d(path, moduleConfigFilename);
906
+ const moduleConfigPath = resolve$b(path, moduleConfigFilename);
906
907
 
907
- if (fs$a.existsSync(moduleConfigPath)) {
908
- const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
908
+ if (fs$8.existsSync(moduleConfigPath)) {
909
+ const content = fs$8.readFileSync(moduleConfigPath, 'utf-8');
909
910
  modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
910
911
  }
911
912
  });
@@ -926,12 +927,12 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
926
927
  path: relativePath,
927
928
  name: moduleName
928
929
  }, moduleIndex) => {
929
- const moduleConfigPath = resolve$d(relativePath, MODULE_CONFIG_FILENAME$1);
930
+ const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME$1);
930
931
 
931
- if (fs$a.existsSync(moduleConfigPath)) {
932
+ if (fs$8.existsSync(moduleConfigPath)) {
932
933
  try {
933
934
  let findModule = false;
934
- let moduleConfigContent = fs$a.readFileSync(moduleConfigPath, 'utf-8');
935
+ let moduleConfigContent = fs$8.readFileSync(moduleConfigPath, 'utf-8');
935
936
  moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
936
937
  const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
937
938
  getValidModules$1(moduleContentArr).forEach(({
@@ -946,11 +947,11 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
946
947
  });
947
948
 
948
949
  if (!findModule) {
949
- fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到或pages为空,请检查配置`);
950
+ fail$6(`启动模块${moduleName}在${moduleConfigPath}没有找到或pages为空,请检查配置`);
950
951
  process.exit(1);
951
952
  }
952
953
  } catch (e) {
953
- fail$7(`${moduleConfigPath}配置错误: ${e}`);
954
+ fail$6(`${moduleConfigPath}配置错误: ${e}`);
954
955
  newModules.push({ ...modules[moduleIndex]
955
956
  });
956
957
  }
@@ -1035,32 +1036,32 @@ var global_1 = {
1035
1036
  };
1036
1037
 
1037
1038
  const {
1038
- fail: fail$6
1039
+ fail: fail$5
1039
1040
  } = log$1;
1040
1041
  const {
1041
1042
  global: global$5
1042
1043
  } = global_1;
1043
1044
 
1044
- function handleError$5(error) {
1045
+ function handleError$4(error) {
1045
1046
  const errMsg = typeof error === 'object' ? error.message : error;
1046
1047
  const isDev = global$5.getData('isDev');
1047
1048
 
1048
1049
  if (isDev) {
1049
- fail$6(errMsg);
1050
+ fail$5(errMsg);
1050
1051
  } else {
1051
- fail$6(errMsg);
1052
+ fail$5(errMsg);
1052
1053
  process.exit(1);
1053
1054
  }
1054
1055
  }
1055
1056
 
1056
1057
  var handleError_1 = {
1057
- handleError: handleError$5
1058
+ handleError: handleError$4
1058
1059
  };
1059
1060
 
1060
1061
  /**
1061
1062
  * 生成编译后的app.json
1062
1063
  */
1063
- const fs$9 = require$$0__default$2;
1064
+ const fs$7 = require$$0__default$2;
1064
1065
  const {
1065
1066
  MODULE_CONFIG_FILENAME,
1066
1067
  MODULE_CONFIG_INVALID_KEY
@@ -1070,14 +1071,14 @@ const {
1070
1071
  getValidModules
1071
1072
  } = tmsMpconfig;
1072
1073
  const {
1073
- fail: fail$5
1074
+ fail: fail$4
1074
1075
  } = log$1;
1075
1076
  const {
1076
- resolve: resolve$c,
1077
+ resolve: resolve$a,
1077
1078
  isObject
1078
1079
  } = widgets;
1079
1080
  const {
1080
- handleError: handleError$4
1081
+ handleError: handleError$3
1081
1082
  } = handleError_1;
1082
1083
  /**
1083
1084
  * 更新appJson里面的主包配置
@@ -1097,7 +1098,7 @@ function updateMainPackages(appJson, mainPackages = []) {
1097
1098
 
1098
1099
  foundMainPackages.forEach(subpackage => {
1099
1100
  if (!subpackage.pages || !subpackage.pages.length) {
1100
- fail$5(`主包 ${subpackage} 不能没有 pages`);
1101
+ fail$4(`主包 ${subpackage} 不能没有 pages`);
1101
1102
  process.exit(-1);
1102
1103
  }
1103
1104
 
@@ -1123,12 +1124,12 @@ function updateMainPackages(appJson, mainPackages = []) {
1123
1124
 
1124
1125
 
1125
1126
  const getAppJsonContent = sourceAppJsonPath => {
1126
- if (!fs$9.existsSync(sourceAppJsonPath)) {
1127
- fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1127
+ if (!fs$7.existsSync(sourceAppJsonPath)) {
1128
+ fail$4(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1128
1129
  process.exit(1);
1129
1130
  }
1130
1131
 
1131
- const appJson = JSON.parse(fs$9.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1132
+ const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1132
1133
 
1133
1134
  appJson.subpackages = [];
1134
1135
  appJson.pages = []; // appJson.plugins = {};
@@ -1198,7 +1199,7 @@ const fixAppJson = appJson => {
1198
1199
  });
1199
1200
 
1200
1201
  if (invalidKeys.length) {
1201
- fail$5(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
1202
+ fail$4(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
1202
1203
  } // eslint-disable-next-line
1203
1204
 
1204
1205
 
@@ -1215,7 +1216,7 @@ const fixAppJson = appJson => {
1215
1216
  }).reduce((pre, cur) => pre + cur, '');
1216
1217
 
1217
1218
  if (pluginsErrMsg) {
1218
- fail$5(`plugins配置出现错误:${pluginsErrMsg}`);
1219
+ fail$4(`plugins配置出现错误:${pluginsErrMsg}`);
1219
1220
  } // eslint-disable-next-line
1220
1221
 
1221
1222
 
@@ -1231,20 +1232,29 @@ const fixAppJson = appJson => {
1231
1232
 
1232
1233
  function buildOutputAppJson$1(tmsConfig, modules) {
1233
1234
  try {
1235
+ var _tmsConfig$hooks;
1236
+
1234
1237
  // 获取当前 modules 下的所有子模块的配置内容
1235
1238
  const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
1236
1239
 
1237
- const appJson = getAppJsonContent(resolve$c('./app.json')); // 更新app.json中的subpackages
1240
+ const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
1238
1241
 
1239
1242
  updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
1240
1243
 
1241
1244
  fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1242
1245
 
1243
1246
  updateMainPackages(appJson, tmsConfig.mainPackages);
1244
- fs$9.writeFileSync(resolve$c(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1247
+ fs$7.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1248
+
1249
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
1250
+ var _tmsConfig$hooks2;
1251
+
1252
+ tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson(appJson);
1253
+ }
1254
+
1245
1255
  return appJson;
1246
1256
  } catch (e) {
1247
- handleError$4(`生成app.json出现错误: ${e}`);
1257
+ handleError$3(`生成app.json出现错误: ${e}`);
1248
1258
  }
1249
1259
  }
1250
1260
 
@@ -1252,57 +1262,21 @@ var buildAppJson = {
1252
1262
  buildOutputAppJson: buildOutputAppJson$1
1253
1263
  };
1254
1264
 
1255
- const fs$8 = require$$0__default$2;
1256
- const {
1257
- resolve: resolve$b
1258
- } = widgets;
1259
- const {
1260
- handleError: handleError$3
1261
- } = handleError_1;
1262
- const {
1263
- DEFAULT_CLOUD_MODULE_DIR
1264
- } = require$$4;
1265
- /**
1266
- * 根据相关配置创建软链接
1267
- * @param { object } tmsConfig
1268
- */
1269
-
1270
- const symLink$1 = tmsConfig => {
1271
- try {
1272
- if (tmsConfig.cloudModules) {
1273
- tmsConfig.cloudModules.forEach(item => {
1274
- const path = resolve$b(DEFAULT_CLOUD_MODULE_DIR, item.name);
1275
- fs$8.access(path, fs$8.constants.F_OK, res => {
1276
- if (res) {
1277
- fs$8.symlinkSync(resolve$b(item.path), path);
1278
- }
1279
- });
1280
- });
1281
- }
1282
- } catch (e) {
1283
- handleError$3(`创建软链错误: ${e}`);
1284
- }
1285
- };
1286
-
1287
- var symbolicLink = {
1288
- symLink: symLink$1
1289
- };
1290
-
1291
1265
  /**
1292
1266
  * 下载第三方代码
1293
1267
  */
1294
1268
  const MetalSmith = require$$0__default$5;
1295
- const crypto$1 = require$$1__default$5;
1269
+ const crypto$1 = require$$1__default$4;
1296
1270
  const {
1297
1271
  downloadRepoForGit,
1298
1272
  pullRepoForGit,
1299
- resolve: resolve$a
1273
+ resolve: resolve$9
1300
1274
  } = widgets;
1301
1275
  const {
1302
- fail: fail$4,
1276
+ fail: fail$3,
1303
1277
  info: info$5
1304
1278
  } = log$1;
1305
- const fs$7 = require$$0__default$2;
1279
+ const fs$6 = require$$0__default$2;
1306
1280
  const shelljs$4 = require$$0__default$3;
1307
1281
  const {
1308
1282
  handleError: handleError$2
@@ -1349,7 +1323,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1349
1323
  return new Promise((resolve, reject) => {
1350
1324
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1351
1325
  if (e) {
1352
- fail$4(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1326
+ fail$3(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1353
1327
  reject(e);
1354
1328
  }
1355
1329
 
@@ -1443,9 +1417,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1443
1417
 
1444
1418
  const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1445
1419
 
1446
- const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
1420
+ const sourcePath = resolve$9(sourceDir, md5Key); // 模块源码要放到目标目录
1447
1421
 
1448
- const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1422
+ const targetPath = resolve$9(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1449
1423
 
1450
1424
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1451
1425
 
@@ -1455,7 +1429,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1455
1429
  targetPath
1456
1430
  },
1457
1431
  fn: async (sourceModulePath, targetPath) => {
1458
- if (fs$7.existsSync(targetPath)) {
1432
+ if (fs$6.existsSync(targetPath)) {
1459
1433
  shelljs$4.rm('-rf', `${targetPath}/*`);
1460
1434
  }
1461
1435
 
@@ -1470,7 +1444,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1470
1444
  } else {
1471
1445
  let promiseTask;
1472
1446
 
1473
- if (fs$7.existsSync(sourcePath) && fs$7.existsSync(`${sourcePath}/.git`)) {
1447
+ if (fs$6.existsSync(sourcePath) && fs$6.existsSync(`${sourcePath}/.git`)) {
1474
1448
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1475
1449
  info$5(`git pull:${httpRepoUrl}`);
1476
1450
  return pullRepoForGit(sourcePath, branch);
@@ -1506,7 +1480,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1506
1480
  */
1507
1481
 
1508
1482
 
1509
- function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
1483
+ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
1510
1484
  if (moduleInfo.repoInfo) {
1511
1485
  const {
1512
1486
  repoInfo: {
@@ -1518,7 +1492,7 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
1518
1492
  const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
1519
1493
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
1520
1494
 
1521
- if (!fs$7.existsSync(`${sourceDir}/${md5Key}`)) {
1495
+ if (!fs$6.existsSync(`${sourceDir}/${md5Key}`)) {
1522
1496
  return true;
1523
1497
  }
1524
1498
  }
@@ -1528,11 +1502,11 @@ function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
1528
1502
 
1529
1503
  var cloneModules_1 = {
1530
1504
  cloneModules: cloneModules$1,
1531
- checkRemoteModGitUrlBranch: checkRemoteModGitUrlBranch$1
1505
+ checkRemoteModGitUrlBranch
1532
1506
  };
1533
1507
 
1534
1508
  const ci = require$$0__default$7;
1535
- const path$6 = require$$1__default$2;
1509
+ const path$6 = require$$3__default;
1536
1510
  /**
1537
1511
  * 获取小程序ci的Project对象
1538
1512
  * @returns {Object} 小程序ci对象
@@ -1556,7 +1530,7 @@ const getMpCi = ({
1556
1530
  privateKey,
1557
1531
  type,
1558
1532
  projectPath,
1559
- ignores: ['node_modules/**/*', ...ignores]
1533
+ ignores: ['node_modules/**/*', 'cloud/**/*', ...ignores]
1560
1534
  });
1561
1535
  }; // 用小程序ci工具构建小程序
1562
1536
 
@@ -1615,10 +1589,10 @@ var mpCi = {
1615
1589
  /**
1616
1590
  * 本文件主要负责项目或者分包依赖的npm的安装
1617
1591
  */
1618
- const fs$6 = require$$0__default$2;
1619
- const fsExtra = require$$1__default$6;
1620
- const crypto = require$$1__default$5;
1621
- const path$5 = require$$1__default$2;
1592
+ const fs$5 = require$$0__default$2;
1593
+ const fsExtra = require$$1__default$5;
1594
+ const crypto = require$$1__default$4;
1595
+ const path$5 = require$$3__default;
1622
1596
  const shell = require$$0__default$3;
1623
1597
  const glob = require$$5__default;
1624
1598
  const log = log$1;
@@ -1650,7 +1624,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1650
1624
  const npmTasksMap = new Map();
1651
1625
 
1652
1626
  for (const packageJsonPath of packageJsonFiles) {
1653
- const packageContent = fs$6.readFileSync(packageJsonPath);
1627
+ const packageContent = fs$5.readFileSync(packageJsonPath);
1654
1628
  const packageJson = JSON.parse(packageContent);
1655
1629
  const md5Obj = {
1656
1630
  dependencies: packageJson.dependencies || {}
@@ -1674,8 +1648,9 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1674
1648
  const newShellJsOption = { ...shellJsOption,
1675
1649
  cwd: packageJsonDir
1676
1650
  };
1651
+ shell.cd(packageJsonDir);
1677
1652
  shell.exec('tar -xvf ./node_modules.tar.gz -C ./', newShellJsOption);
1678
- shell.rm('-rf', './node_modules');
1653
+ shell.rm('-rf', './node_modules.tar.gz');
1679
1654
  }
1680
1655
  };
1681
1656
 
@@ -1697,6 +1672,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1697
1672
  const newShellJsOption = { ...shellJsOption,
1698
1673
  cwd: cacheNMPath
1699
1674
  };
1675
+ shell.cd(cacheNMPath);
1700
1676
  shell.exec('tar -cvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
1701
1677
  shell.rm('-rf', './node_modules');
1702
1678
  });
@@ -1764,7 +1740,7 @@ const findFilesByFilter = (startPath, filter) => {
1764
1740
 
1765
1741
  const find = (startPath, filter) => {
1766
1742
  // 目录不存在
1767
- if (!fs$6.existsSync(startPath)) {
1743
+ if (!fs$5.existsSync(startPath)) {
1768
1744
  log.fail(`${startPath}目录不存在`);
1769
1745
  process.exit(-1);
1770
1746
  return;
@@ -1777,10 +1753,10 @@ const findFilesByFilter = (startPath, filter) => {
1777
1753
  return;
1778
1754
  }
1779
1755
 
1780
- const files = fs$6.readdirSync(startPath);
1756
+ const files = fs$5.readdirSync(startPath);
1781
1757
  files.forEach(file => {
1782
1758
  const filename = path$5.join(startPath, file);
1783
- const stat = fs$6.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1759
+ const stat = fs$5.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1784
1760
 
1785
1761
  if (stat.isDirectory()) {
1786
1762
  find(filename, filter);
@@ -1822,7 +1798,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
1822
1798
  return result;
1823
1799
  };
1824
1800
 
1825
- function cloudNpmInstall$1(contextDir) {
1801
+ function cloudNpmInstall(contextDir) {
1826
1802
  return new Promise((resolve, reject) => {
1827
1803
  glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
1828
1804
  if (err) {
@@ -1842,60 +1818,146 @@ function cloudNpmInstall$1(contextDir) {
1842
1818
  }
1843
1819
 
1844
1820
  var npm = {
1845
- cloudNpmInstall: cloudNpmInstall$1,
1821
+ cloudNpmInstall,
1846
1822
  mpNpmInstallAll: mpNpmInstallAll$1,
1847
1823
  findAllPackageJson
1848
1824
  };
1849
1825
 
1850
1826
  const {
1851
1827
  createTask: createTask$1,
1852
- resolve: resolve$9
1828
+ resolve: resolve$8
1853
1829
  } = widgets;
1854
1830
  const {
1855
1831
  buildMpNpm
1856
1832
  } = mpCi;
1857
1833
  const {
1858
- CACHE_DIR
1834
+ CACHE_DIR: CACHE_DIR$1
1859
1835
  } = require$$4;
1860
1836
  const {
1861
- cloudNpmInstall,
1862
1837
  mpNpmInstallAll
1863
1838
  } = npm;
1864
1839
  const {
1865
1840
  global: global$3
1866
1841
  } = global_1;
1867
1842
 
1868
- async function install$2(tmsConfig, modules, isCloud = false) {
1843
+ async function install$2(tmsConfig, modules) {
1869
1844
  // 小程序npm install
1870
- await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
1845
+ await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
1871
1846
  const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
1872
1847
 
1873
1848
  await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
1874
1849
  appId: tmsConfig.appId,
1875
- projectPath: resolve$9('./'),
1850
+ projectPath: resolve$8('./'),
1876
1851
  privateKey: tmsPrivateCf.privateKey
1877
- }); // 安装云函数的
1878
-
1879
- isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$9(tmsConfig.cloudDir));
1852
+ });
1880
1853
  }
1881
1854
 
1882
1855
  var install_1 = install$2;
1883
1856
 
1857
+ const fs$4 = require$$0__default$2;
1858
+ const semver$1 = require$$1__default$6;
1859
+ const {
1860
+ resolve: resolve$7
1861
+ } = widgets;
1862
+ const path$4 = require$$3__default;
1884
1863
  const shelljs$3 = require$$0__default$3;
1885
- const fs$5 = require$$0__default$2;
1864
+ const {
1865
+ handleError
1866
+ } = handleError_1;
1867
+
1868
+ const getLatestVersion = npmName => {
1869
+ const data = shelljs$3.exec(`npm view ${npmName} version`);
1870
+ return data.stdout || '0.0.0';
1871
+ };
1872
+ /**
1873
+ * 检查package.json的依赖大于node_module的版本,则返回true
1874
+ * @param {*} modules 模块
1875
+ * @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
1876
+ * @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
1877
+ * @returns
1878
+ */
1879
+
1880
+
1881
+ const checkDependencies$1 = (modules, cwd, outputDir) => {
1882
+ // 步骤1. 收集package.json
1883
+ const packageJsonName = 'package.json'; // 查找文件名
1884
+ // 1.1根目录的package.json
1885
+
1886
+ const packageArr = [{
1887
+ srcPackageDir: path$4.join(cwd, packageJsonName),
1888
+ destNpmDir: resolve$7(outputDir, 'node_modules')
1889
+ }]; // 1.2模块的package.json
1890
+
1891
+ modules.forEach(item => {
1892
+ const srcPackageDir = path$4.join(cwd, item.path, 'package.json');
1893
+
1894
+ if (fs$4.existsSync(srcPackageDir)) {
1895
+ packageArr.push({
1896
+ srcPackageDir,
1897
+ destNpmDir: resolve$7(outputDir, item.root, 'node_modules')
1898
+ });
1899
+ }
1900
+ }); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
1901
+
1902
+ for (const item of packageArr) {
1903
+ const packageJson = fs$4.readFileSync(item.srcPackageDir, 'utf-8');
1904
+ let dependencies = {};
1905
+
1906
+ try {
1907
+ const json = JSON.parse(packageJson);
1908
+ dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
1909
+ } catch (e) {
1910
+ handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
1911
+ }
1912
+
1913
+ const dependenciesKeys = Object.keys(dependencies);
1914
+
1915
+ for (const key of dependenciesKeys) {
1916
+ const depPath = path$4.join(item.destNpmDir, key);
1917
+
1918
+ if (!fs$4.existsSync(depPath)) {
1919
+ return true;
1920
+ }
1921
+
1922
+ const depPackagePath = path$4.join(depPath, 'package.json');
1923
+
1924
+ if (fs$4.existsSync(depPackagePath)) {
1925
+ const packageData = require(depPackagePath);
1926
+
1927
+ if (dependencies[key] === 'latest') {
1928
+ dependencies[key] = getLatestVersion(key);
1929
+ }
1930
+
1931
+ if (packageData.version === 'latest') {
1932
+ packageData.version = getLatestVersion(key);
1933
+ }
1934
+
1935
+ if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
1936
+ return true;
1937
+ }
1938
+ }
1939
+ }
1940
+ }
1941
+
1942
+ return false;
1943
+ };
1944
+
1945
+ var checkDependencies_1 = {
1946
+ checkDependencies: checkDependencies$1
1947
+ };
1948
+
1949
+ const shelljs$2 = require$$0__default$3;
1950
+ const fs$3 = require$$0__default$2;
1886
1951
  const io = io$2;
1887
1952
  const {
1888
- resolve: resolve$8,
1953
+ resolve: resolve$6,
1889
1954
  createTask
1890
1955
  } = widgets;
1891
1956
  const {
1892
1957
  buildOutputAppJson
1893
1958
  } = buildAppJson;
1894
1959
  const {
1895
- symLink
1896
- } = symbolicLink;
1897
- const {
1898
- MODULE_CODE_DIR: MODULE_CODE_DIR$1,
1960
+ MODULE_CODE_DIR,
1899
1961
  DEFAULT_COPY_CONFIG
1900
1962
  } = require$$4;
1901
1963
  const {
@@ -1906,10 +1968,13 @@ const {
1906
1968
  subModulesMergeDepModules: subModulesMergeDepModules$1
1907
1969
  } = tmsMpconfig;
1908
1970
  const {
1909
- fail: fail$3,
1971
+ fail: fail$2,
1910
1972
  info: info$4
1911
1973
  } = log$1;
1912
1974
  const install$1 = install_1;
1975
+ const {
1976
+ checkDependencies
1977
+ } = checkDependencies_1;
1913
1978
  /**
1914
1979
  * 拷贝相关配置文件到编译输出目录
1915
1980
  * @param { object } tmsConfig
@@ -1919,42 +1984,66 @@ const install$1 = install_1;
1919
1984
  */
1920
1985
 
1921
1986
  const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1922
- const outputDir = resolve$8(tmsConfig.outputDir);
1987
+ const outputDir = resolve$6(tmsConfig.outputDir);
1923
1988
  io.ensureDirExist(outputDir);
1924
1989
  defaultFiles.forEach(item => {
1925
- if (fs$5.existsSync(resolve$8(item))) {
1926
- shelljs$3.cp('-rf', resolve$8(item), resolve$8(tmsConfig.outputDir, item));
1990
+ if (fs$3.existsSync(resolve$6(item))) {
1991
+ shelljs$2.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
1927
1992
  }
1928
1993
  }); // 拷贝模块的package.json到编译输出目录
1929
1994
 
1930
1995
  targetModules.forEach(item => {
1931
- const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
1996
+ const outputModuleDir = resolve$6(`${tmsConfig.outputDir}/${item.root}`);
1932
1997
 
1933
- if (!fs$5.existsSync(resolve$8(item.path))) {
1934
- fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1998
+ if (!fs$3.existsSync(resolve$6(item.path))) {
1999
+ fail$2(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1935
2000
  process.exit(1);
1936
2001
  }
1937
2002
 
1938
2003
  io.ensureDirExist(outputModuleDir);
1939
- const modulePackagePath = resolve$8(item.path, 'package.json');
1940
- if (fs$5.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
2004
+ const modulePackagePath = resolve$6(item.path, 'package.json');
2005
+ if (fs$3.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
1941
2006
  });
1942
2007
  };
2008
+ /**
2009
+ * 校验相关配置项
2010
+ * @param {*} targetModules
2011
+ * @returns
2012
+ */
2013
+
2014
+
2015
+ function checkConfig(targetModules) {
2016
+ for (const item of targetModules) {
2017
+ if (!item.root) {
2018
+ throw new Error(`检查${item.name} module.config.json的root字段`);
2019
+ } // 判断源码目录是否有该模块
2020
+
2021
+
2022
+ if (item.path && !fs$3.existsSync(resolve$6(item.path))) {
2023
+ throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2024
+ }
2025
+ }
2026
+
2027
+ return true;
2028
+ }
1943
2029
 
1944
2030
  async function task(tmsConfig, targetModules) {
1945
2031
  // 下载和移动代码
1946
- await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$8('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
2032
+ await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1947
2033
 
1948
2034
  let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
1949
2035
 
1950
- newModules = subModulesMergeDepModules$1(tmsConfig, newModules); // 拷贝相关配置文件到输出目录
2036
+ newModules = subModulesMergeDepModules$1(tmsConfig, newModules);
2037
+ checkConfig(newModules); // 拷贝相关配置文件到输出目录
1951
2038
 
1952
2039
  await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
1953
2040
 
1954
- await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
2041
+ if (checkDependencies(newModules, resolve$6('./'), tmsConfig.outputDir)) {
2042
+ await install$1(tmsConfig, newModules);
2043
+ } // 动态生成编译后的app.json;
2044
+
1955
2045
 
1956
2046
  await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
1957
- await createTask(symLink, '开始创建软链接', '创建软链接完成')(tmsConfig);
1958
2047
  return newModules;
1959
2048
  }
1960
2049
 
@@ -1966,7 +2055,7 @@ async function init$5(tmsConfig, targetModules) {
1966
2055
  };
1967
2056
  } catch (error) {
1968
2057
  const errMsg = typeof error === 'object' ? error.message : error;
1969
- fail$3(`init流程出现错误${errMsg}`);
2058
+ fail$2(`初始化流程出现错误${errMsg}`);
1970
2059
  info$4('详细的错误信息', error);
1971
2060
  process.exit(1);
1972
2061
  }
@@ -2012,16 +2101,16 @@ var findCssImport = {
2012
2101
 
2013
2102
  /* eslint-disable no-param-reassign */
2014
2103
  const {
2015
- fail: fail$2
2104
+ fail: fail$1
2016
2105
  } = log$1;
2017
2106
 
2018
2107
  function pluginError$3(error, isWatch) {
2019
2108
  const errMsg = error.message;
2020
2109
 
2021
2110
  if (isWatch) {
2022
- fail$2(errMsg);
2111
+ fail$1(errMsg);
2023
2112
  } else {
2024
- fail$2(errMsg);
2113
+ fail$1(errMsg);
2025
2114
  process.exit(1);
2026
2115
  }
2027
2116
  }
@@ -2033,7 +2122,7 @@ var pluginError_1 = {
2033
2122
  /* eslint-disable no-param-reassign */
2034
2123
  const through$2 = require$$0__default$9;
2035
2124
  const precinct = require$$1__default$7;
2036
- const path$4 = require$$1__default$2;
2125
+ const path$3 = require$$3__default;
2037
2126
  const {
2038
2127
  findCssImports
2039
2128
  } = findCssImport;
@@ -2043,9 +2132,9 @@ const {
2043
2132
  diffContentCopyFile: diffContentCopyFile$2
2044
2133
  } = io$2;
2045
2134
  const {
2046
- resolve: resolve$7
2135
+ resolve: resolve$5
2047
2136
  } = widgets;
2048
- const fs$4 = require$$0__default$2;
2137
+ const fs$2 = require$$0__default$2;
2049
2138
  const {
2050
2139
  pluginError: pluginError$2
2051
2140
  } = pluginError_1;
@@ -2058,16 +2147,16 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2058
2147
  let contents = '';
2059
2148
 
2060
2149
  try {
2061
- contents = fs$4.readFileSync(anaFileOriginFile, 'utf8');
2150
+ contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
2062
2151
  } catch (e) {
2063
2152
  pluginError$2(e, isWatch);
2064
2153
  }
2065
2154
 
2066
- const deps = cssFilter.indexOf(path$4.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
2155
+ const deps = cssFilter.indexOf(path$3.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
2067
2156
  deps.forEach(depItem => {
2068
2157
  if (depItem.startsWith('.')) {
2069
2158
  // 被依赖文件的存在的绝对路径
2070
- const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2159
+ const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2071
2160
 
2072
2161
  const {
2073
2162
  ext: extAlias,
@@ -2075,12 +2164,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
2075
2164
  extPath
2076
2165
  } = ext$2(depOriginPath, extensions);
2077
2166
 
2078
- if (!fs$4.existsSync(depOriginFile)) {
2167
+ if (!fs$2.existsSync(depOriginFile)) {
2079
2168
  pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
2080
2169
  return;
2081
2170
  }
2082
2171
 
2083
- const depDestPath = resolve$7(path$4.dirname(anaFileDestFile), depItem);
2172
+ const depDestPath = resolve$5(path$3.dirname(anaFileDestFile), depItem);
2084
2173
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2085
2174
 
2086
2175
  if (!resDep.has(depDestFile)) {
@@ -2104,19 +2193,19 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2104
2193
  const stream = through$2.obj(function (file, enc, cb) {
2105
2194
  // 依赖分析的文件
2106
2195
  const anaFileOriginFile = file.history[0];
2107
- const anaFileRelativeModule = path$4.relative(resolve$7(module.from), anaFileOriginFile);
2108
- const anaFileDestFile = resolve$7(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2196
+ const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
2197
+ const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2109
2198
 
2110
2199
  if (file.isBuffer()) {
2111
2200
  let contents = String(file.contents);
2112
- const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
2201
+ const deps = cssFilter.indexOf(path$3.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
2113
2202
  const copyModules = new Map();
2114
2203
  Object.keys(tmsConfig.dependencies).forEach(includeName => {
2115
2204
  const includePath = tmsConfig.dependencies[includeName];
2116
2205
  deps.forEach(depItem => {
2117
2206
  if (depItem.indexOf(includeName) > -1) {
2118
2207
  // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
2119
- const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2208
+ const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2120
2209
 
2121
2210
  const {
2122
2211
  ext: extAlias,
@@ -2134,7 +2223,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2134
2223
  const regRes = depItem.match(reg) || [];
2135
2224
 
2136
2225
  if (regRes[2]) {
2137
- const depDestPath = resolve$7(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2226
+ const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2138
2227
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2139
2228
 
2140
2229
  if (!copyModules.has(depDestFile)) {
@@ -2142,7 +2231,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2142
2231
  depOriginFile,
2143
2232
  depDestFile,
2144
2233
  beforeDepPath: depItem,
2145
- afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2234
+ afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2146
2235
  });
2147
2236
  }
2148
2237
  }
@@ -2180,16 +2269,16 @@ var mpCommonDep_1 = {
2180
2269
 
2181
2270
  /* eslint-disable no-param-reassign */
2182
2271
  const through$1 = require$$0__default$9;
2183
- const path$3 = require$$1__default$2;
2272
+ const path$2 = require$$3__default;
2184
2273
  const {
2185
2274
  ext: ext$1,
2186
2275
  fileInDir: fileInDir$1,
2187
2276
  diffContentCopyFile: diffContentCopyFile$1
2188
2277
  } = io$2;
2189
2278
  const {
2190
- resolve: resolve$6
2279
+ resolve: resolve$4
2191
2280
  } = widgets;
2192
- const fs$3 = require$$0__default$2;
2281
+ const fs$1 = require$$0__default$2;
2193
2282
  const {
2194
2283
  pluginError: pluginError$1
2195
2284
  } = pluginError_1;
@@ -2201,8 +2290,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2201
2290
  const stream = through$1.obj(function (file, enc, cb) {
2202
2291
  // 当前分析的文件的路径
2203
2292
  const anaFileOriginFile = file.history[0];
2204
- const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
2205
- const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2293
+ const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
2294
+ const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2206
2295
 
2207
2296
  if (file.isBuffer()) {
2208
2297
  let contents = String(file.contents);
@@ -2222,7 +2311,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2222
2311
  const componentPath = contents.usingComponents[componentKey];
2223
2312
 
2224
2313
  if (componentPath.indexOf(includeName) > -1) {
2225
- const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
2314
+ const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
2226
2315
 
2227
2316
  const {
2228
2317
  ext: extAlias,
@@ -2241,7 +2330,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2241
2330
  const regRes = componentPath.match(reg) || [];
2242
2331
 
2243
2332
  if (regRes[2]) {
2244
- const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2333
+ const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2245
2334
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2246
2335
 
2247
2336
  if (!copyModules.has(depDestFile)) {
@@ -2250,7 +2339,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2250
2339
  depOriginExt: extAlias,
2251
2340
  depDestFile,
2252
2341
  beforeDepPath: componentPath,
2253
- afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2342
+ afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2254
2343
  });
2255
2344
  }
2256
2345
  }
@@ -2275,7 +2364,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
2275
2364
  const originFile = depOriginFile.replace(depOriginExt, extKey);
2276
2365
  const destFile = depDestFile.replace(depOriginExt, extKey);
2277
2366
 
2278
- if (fs$3.existsSync(originFile)) {
2367
+ if (fs$1.existsSync(originFile)) {
2279
2368
  diffContentCopyFile$1(originFile, destFile);
2280
2369
  const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
2281
2370
 
@@ -2309,15 +2398,15 @@ var mpJsonDep_1 = {
2309
2398
  /* eslint-disable no-param-reassign */
2310
2399
  const through = require$$0__default$9;
2311
2400
  const htmlparser2 = require$$1__default$8;
2312
- const fs$2 = require$$0__default$2;
2313
- const path$2 = require$$1__default$2;
2401
+ const fs = require$$0__default$2;
2402
+ const path$1 = require$$3__default;
2314
2403
  const {
2315
2404
  diffContentCopyFile,
2316
2405
  ext,
2317
2406
  fileInDir
2318
2407
  } = io$2;
2319
2408
  const {
2320
- resolve: resolve$5
2409
+ resolve: resolve$3
2321
2410
  } = widgets;
2322
2411
  const {
2323
2412
  dfsFindCommonDep
@@ -2356,7 +2445,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2356
2445
  let contents = '';
2357
2446
 
2358
2447
  try {
2359
- contents = fs$2.readFileSync(anaFileOriginFile, 'utf8');
2448
+ contents = fs.readFileSync(anaFileOriginFile, 'utf8');
2360
2449
  } catch (e) {
2361
2450
  pluginError(e, isWatch);
2362
2451
  }
@@ -2366,7 +2455,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2366
2455
  var _attributes$src;
2367
2456
 
2368
2457
  if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
2369
- const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2458
+ const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2370
2459
 
2371
2460
  const {
2372
2461
  ext,
@@ -2374,12 +2463,12 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
2374
2463
  extPath
2375
2464
  } = extFile(name, depOriginPath);
2376
2465
 
2377
- if (!fs$2.existsSync(depOriginFile)) {
2466
+ if (!fs.existsSync(depOriginFile)) {
2378
2467
  pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
2379
2468
  return;
2380
2469
  }
2381
2470
 
2382
- const depDestPath = path$2.join(path$2.dirname(anaFileDestFile), attributes.src);
2471
+ const depDestPath = path$1.join(path$1.dirname(anaFileDestFile), attributes.src);
2383
2472
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
2384
2473
 
2385
2474
  if (['import', 'include'].indexOf(name) > -1) {
@@ -2431,8 +2520,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2431
2520
  const stream = through.obj(function (file, enc, cb) {
2432
2521
  // 依赖分析的文件
2433
2522
  const anaFileOriginFile = file.history[0];
2434
- const anaFileRelativeModule = path$2.relative(resolve$5(module.from), anaFileOriginFile);
2435
- const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2523
+ const anaFileRelativeModule = path$1.relative(resolve$3(module.from), anaFileOriginFile);
2524
+ const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2436
2525
 
2437
2526
  if (file.isBuffer()) {
2438
2527
  let contents = String(file.contents);
@@ -2442,7 +2531,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2442
2531
  const nameFilter = ['import', 'include', 'wxs'];
2443
2532
 
2444
2533
  if (nameFilter.indexOf(name) > -1 && attributes.src) {
2445
- const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2534
+ const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2446
2535
 
2447
2536
  const {
2448
2537
  ext,
@@ -2463,7 +2552,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2463
2552
  const regRes = attributes.src.match(reg) || [];
2464
2553
 
2465
2554
  if (regRes[2]) {
2466
- const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2555
+ const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2467
2556
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
2468
2557
 
2469
2558
  if (!copyModules.has(depDestFile)) {
@@ -2471,7 +2560,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2471
2560
  depOriginFile,
2472
2561
  depDestFile,
2473
2562
  beforeDepPath: attributes.src,
2474
- afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2563
+ afterDepPath: path$1.relative(path$1.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2475
2564
  });
2476
2565
  }
2477
2566
  }
@@ -2490,7 +2579,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2490
2579
  beforeDepPath,
2491
2580
  afterDepPath
2492
2581
  }) => {
2493
- if (fs$2.existsSync(depOriginFile)) {
2582
+ if (fs.existsSync(depOriginFile)) {
2494
2583
  diffContentCopyFile(depOriginFile, depDestFile);
2495
2584
  const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
2496
2585
  contents = contents.replace(reg, `"${afterDepPath}"`);
@@ -2546,7 +2635,7 @@ const {
2546
2635
  // const base64 = require('./plugins/postcss-font-base64');
2547
2636
 
2548
2637
  const {
2549
- fail: fail$1
2638
+ fail
2550
2639
  } = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
2551
2640
 
2552
2641
  var compile = function (tmsConfig, {
@@ -2554,7 +2643,7 @@ var compile = function (tmsConfig, {
2554
2643
  destPath,
2555
2644
  srcOption,
2556
2645
  module,
2557
- isWatch
2646
+ isDev
2558
2647
  }) {
2559
2648
  const compileTasksMap = new Map();
2560
2649
  Object.keys(glob).forEach(globKey => {
@@ -2564,14 +2653,18 @@ var compile = function (tmsConfig, {
2564
2653
  case 'js':
2565
2654
  compileTasksMap.set(globValue, {
2566
2655
  module,
2567
- taskFn: () => {
2568
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2569
- // const srcPipe = srcTask();
2570
- const srcPipe = src$1(globValue, { ...srcOption
2656
+ taskFn: (sourceFile, targetPath) => {
2657
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
2658
+ const newDestPath = targetPath ? targetPath : destPath;
2659
+ const srcPipe = src$1(newGlobValue, { ...srcOption
2571
2660
  });
2572
2661
  return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
2573
- .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch)).pipe(dest(destPath)).on('error', err => {
2574
- fail$1(`js编译报错${err}`);
2662
+ .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
2663
+ fail(`mpCommonDep编译报错${err}`);
2664
+ }).pipe(dest(newDestPath, {
2665
+ overwrite: true
2666
+ })).on('error', err => {
2667
+ fail(`js编译报错${err}`);
2575
2668
  });
2576
2669
  }
2577
2670
  });
@@ -2580,13 +2673,13 @@ var compile = function (tmsConfig, {
2580
2673
  case 'wxss':
2581
2674
  compileTasksMap.set(globValue, {
2582
2675
  module,
2583
- taskFn: () => {
2584
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2585
- // const srcPipe = srcTask();
2586
- const srcPipe = src$1(globValue, { ...srcOption
2676
+ taskFn: (sourceFile, targetPath) => {
2677
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
2678
+ const newDestPath = targetPath ? targetPath : destPath;
2679
+ const srcPipe = src$1(newGlobValue, { ...srcOption
2587
2680
  });
2588
- return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).on('error', err => {
2589
- fail$1(`mpCommonDep编译报错${err}`);
2681
+ return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
2682
+ fail(`mpCommonDep编译报错${err}`);
2590
2683
  }) // .pipe(postcss([base64()]))
2591
2684
  // .on('error', (err) => {
2592
2685
  // fail(`postcss编译报错${err}`);
@@ -2595,7 +2688,9 @@ var compile = function (tmsConfig, {
2595
2688
  // designWidth: 375, // 设计稿宽度,默认为750
2596
2689
  // precision: 2, // 小数最大精度,默认为6
2597
2690
  // }))
2598
- .pipe(dest(destPath));
2691
+ .pipe(dest(newDestPath)).on('error', err => {
2692
+ fail(`wxss编译报错${err}`);
2693
+ });
2599
2694
  }
2600
2695
  });
2601
2696
  break;
@@ -2603,14 +2698,16 @@ var compile = function (tmsConfig, {
2603
2698
  case 'json':
2604
2699
  compileTasksMap.set(globValue, {
2605
2700
  module,
2606
- taskFn: () => {
2607
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2608
- // const srcPipe = srcTask();
2609
- const srcPipe = src$1(globValue, { ...srcOption
2701
+ taskFn: (sourceFile, targetPath) => {
2702
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
2703
+ const newDestPath = targetPath ? targetPath : destPath;
2704
+ const srcPipe = src$1(newGlobValue, { ...srcOption
2705
+ });
2706
+ return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
2707
+ fail(`mpJsonDep编译报错${err}`);
2708
+ }).pipe(dest(newDestPath)).on('error', err => {
2709
+ fail(`json编译报错${err}`);
2610
2710
  });
2611
- return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
2612
- fail$1(`mpJsonDep编译报错${err}`);
2613
- }).pipe(dest(destPath));
2614
2711
  }
2615
2712
  });
2616
2713
  break;
@@ -2618,12 +2715,16 @@ var compile = function (tmsConfig, {
2618
2715
  case 'wxml':
2619
2716
  compileTasksMap.set(globValue, {
2620
2717
  module,
2621
- taskFn: () => {
2622
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2623
- // const srcPipe = srcTask();
2624
- const srcPipe = src$1(globValue, { ...srcOption
2718
+ taskFn: (sourceFile, targetPath) => {
2719
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
2720
+ const newDestPath = targetPath ? targetPath : destPath;
2721
+ const srcPipe = src$1(newGlobValue, { ...srcOption
2722
+ });
2723
+ return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
2724
+ fail(`mpWxmlDep编译报错${err}`);
2725
+ }).pipe(dest(newDestPath)).on('error', err => {
2726
+ fail(`wxml编译报错${err}`);
2625
2727
  });
2626
- return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isWatch)).pipe(dest(destPath));
2627
2728
  }
2628
2729
  });
2629
2730
  break;
@@ -2631,16 +2732,18 @@ var compile = function (tmsConfig, {
2631
2732
  case 'image':
2632
2733
  compileTasksMap.set(globValue, {
2633
2734
  module,
2634
- taskFn: () => {
2635
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2636
- // const srcPipe = srcTask();
2637
- const srcPipe = src$1(globValue, { ...srcOption
2735
+ taskFn: (sourceFile, targetPath) => {
2736
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
2737
+ const newDestPath = targetPath ? targetPath : destPath;
2738
+ const srcPipe = src$1(newGlobValue, { ...srcOption
2638
2739
  });
2639
2740
  return srcPipe // .pipe(cache(image()))
2640
2741
  // .on('error', (err) => {
2641
2742
  // fail(`image编译报错${err}`);
2642
2743
  // })
2643
- .pipe(dest(destPath));
2744
+ .pipe(dest(newDestPath)).on('error', err => {
2745
+ fail(`image编译报错${err}`);
2746
+ });
2644
2747
  }
2645
2748
  });
2646
2749
  break;
@@ -2648,12 +2751,14 @@ var compile = function (tmsConfig, {
2648
2751
  case 'other':
2649
2752
  compileTasksMap.set(globValue, {
2650
2753
  module,
2651
- taskFn: () => {
2652
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
2653
- // const srcPipe = srcTask();
2654
- const srcPipe = src$1(globValue, { ...srcOption
2754
+ taskFn: (sourceFile, targetPath) => {
2755
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
2756
+ const newDestPath = targetPath ? targetPath : destPath;
2757
+ const srcPipe = src$1(newGlobValue, { ...srcOption
2758
+ });
2759
+ return srcPipe.pipe(dest(newDestPath)).on('error', err => {
2760
+ fail(`编译报错${err}`);
2655
2761
  });
2656
- return srcPipe.pipe(dest(destPath));
2657
2762
  }
2658
2763
  });
2659
2764
  break;
@@ -2663,43 +2768,59 @@ var compile = function (tmsConfig, {
2663
2768
  };
2664
2769
 
2665
2770
  const watch = require$$0__default$b;
2666
- const path$1 = require$$1__default$2;
2771
+ const path = require$$3__default;
2667
2772
  const shellJs = require$$0__default$3;
2668
2773
  const {
2669
- info: info$3
2774
+ info: info$3,
2775
+ warn
2670
2776
  } = log$1;
2671
2777
  const {
2672
- resolve: resolve$4
2778
+ resolve: resolve$2
2673
2779
  } = widgets;
2674
2780
  const {
2675
2781
  global: global$2
2676
2782
  } = global_1;
2783
+ const TIP_MAP = {
2784
+ 'package.json': '若依赖有变动,请重新执行tmskit run dev',
2785
+ 'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效'
2786
+ };
2787
+
2788
+ const logTip = (fileName, tipMap) => {
2789
+ // eslint-disable-next-line
2790
+ for (const item in tipMap) {
2791
+ if (fileName.indexOf(item) > -1) {
2792
+ warn(`${fileName}有更新, ${tipMap[item]}`);
2793
+ return;
2794
+ }
2795
+ }
2796
+
2797
+ info$3(`${fileName}有更新`);
2798
+ };
2677
2799
 
2678
- var watch_1 = function (glob, watchOptions, callback, module) {
2679
- watch(glob, {
2680
- readDelay: 100,
2800
+ var watch_1 = function (globValue, watchOptions, callback, module) {
2801
+ watch(globValue, { // readDelay: 100,
2681
2802
  ...watchOptions
2682
2803
  }, vinyl => {
2683
- const file = vinyl.history[0];
2684
- const fileDirArr = file.replace(/\\/g, '/').split('/');
2685
- const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
2804
+ const sourceFile = vinyl.history[0];
2805
+ const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
2806
+ const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
2807
+ const tmsConfig = global$2.getData('tmsConfig');
2808
+ const sourceFileRelativeModule = path.relative(resolve$2(module.from), sourceFile);
2809
+ const targetFile = resolve$2(tmsConfig.outputDir, module.to, sourceFileRelativeModule);
2686
2810
 
2687
2811
  if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
2688
- const tmsConfig = global$2.getData('tmsConfig');
2689
- const anaFileRelativeModule = path$1.relative(resolve$4(module.from), file);
2690
- const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2691
- info$3(`删除${fileName}`);
2692
- shellJs.rm('-rf', anaFileDestFile);
2812
+ info$3(`删除${sourceFileName}`);
2813
+ shellJs.rm('-rf', targetFile);
2693
2814
  return;
2694
2815
  }
2695
2816
 
2696
- info$3(`更新${fileName}`);
2697
- return callback(vinyl);
2817
+ logTip(sourceFileName, TIP_MAP);
2818
+ return callback([sourceFile], path.dirname(targetFile));
2698
2819
  });
2699
2820
  };
2700
2821
 
2701
2822
  (function (module) {
2702
- const path = require$$1__default$2;
2823
+ const path = require$$3__default;
2703
2824
  const fs = require$$0__default$2;
2704
2825
  const ora = require$$2__default;
2705
2826
  const {
@@ -2751,16 +2872,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
2751
2872
  return newPath;
2752
2873
  }
2753
2874
 
2754
- module.exports = async (tmsConfig, newModules, isWatch = true) => {
2875
+ module.exports = async (tmsConfig, newModules, isDev = true) => {
2755
2876
  const compileTasksMap = new Map(); // 监听app.json
2756
2877
 
2757
- if (isWatch) {
2878
+ if (isDev) {
2758
2879
  watch([resolve('app.json')], {
2759
2880
  ignoreInitial: false,
2760
2881
  events: watchEvents
2761
- }, () => buildOutputAppJson(tmsConfig, newModules, isWatch));
2882
+ }, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
2883
+ from: resolve(),
2884
+ to: resolve(tmsConfig.outputDir)
2885
+ });
2762
2886
  } else {
2763
- buildOutputAppJson(tmsConfig, newModules, isWatch);
2887
+ buildOutputAppJson(tmsConfig, newModules, isDev);
2764
2888
  } // 监听根目录的文件
2765
2889
 
2766
2890
 
@@ -2771,14 +2895,14 @@ var watch_1 = function (glob, watchOptions, callback, module) {
2771
2895
 
2772
2896
  },
2773
2897
  module: {
2774
- from: '',
2775
- to: ''
2898
+ from: resolve(),
2899
+ to: resolve(tmsConfig.outputDir)
2776
2900
  },
2777
2901
  destPath: resolve(tmsConfig.outputDir),
2778
2902
  srcOption: {
2779
2903
  allowEmpty: true
2780
2904
  },
2781
- isWatch
2905
+ isDev
2782
2906
  })); // 监听模块的文件
2783
2907
 
2784
2908
  for (let module of newModules) {
@@ -2788,16 +2912,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
2788
2912
  },
2789
2913
  ...module
2790
2914
  };
2915
+ const modulePath = adaptPath(module.path);
2791
2916
 
2792
- if (isWatch) {
2917
+ if (isDev) {
2793
2918
  // 监听模块配置文件
2794
- watch([`${resolve(module.path)}/**/module.config.json`], {
2919
+ watch([`${modulePath}/**/module.config.json`], {
2795
2920
  events: watchEvents
2796
- }, () => buildOutputAppJson(tmsConfig, newModules, isWatch));
2921
+ }, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
2922
+ from: modulePath,
2923
+ to: modulePath
2924
+ });
2797
2925
  }
2798
2926
 
2799
2927
  const excludes = module.exclude.map(key => `!${resolve(key)}`);
2800
- const modulePath = adaptPath(module.path);
2801
2928
  const glob = {
2802
2929
  js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
2803
2930
  json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
@@ -2817,7 +2944,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
2817
2944
  srcOption: {
2818
2945
  allowEmpty: true
2819
2946
  },
2820
- isWatch
2947
+ isDev
2821
2948
  }));
2822
2949
  } // 静态资源目录-拷贝
2823
2950
 
@@ -2853,7 +2980,7 @@ var watch_1 = function (glob, watchOptions, callback, module) {
2853
2980
  srcOption: {
2854
2981
  allowEmpty: true
2855
2982
  },
2856
- isWatch
2983
+ isDev
2857
2984
  }));
2858
2985
  }
2859
2986
  }
@@ -2862,8 +2989,17 @@ var watch_1 = function (glob, watchOptions, callback, module) {
2862
2989
  let eTime;
2863
2990
  const spinner = ora();
2864
2991
 
2992
+ function start(cb) {
2993
+ info('启动编译...');
2994
+ spinner.start();
2995
+ sTime = new Date().getTime();
2996
+ cb();
2997
+ }
2998
+
2865
2999
  function end(cb) {
2866
- if (isWatch) {
3000
+ var _tmsConfig$hooks;
3001
+
3002
+ if (isDev) {
2867
3003
  compileTasksMap.forEach(({
2868
3004
  taskFn,
2869
3005
  module
@@ -2876,15 +3012,19 @@ var watch_1 = function (glob, watchOptions, callback, module) {
2876
3012
  }
2877
3013
 
2878
3014
  eTime = new Date().getTime() - sTime;
2879
- spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即刻预览。`);
2880
- spinner.stop();
2881
- cb();
2882
- }
2883
3015
 
2884
- function start(cb) {
2885
- info('启动编译...');
2886
- spinner.start();
2887
- sTime = new Date().getTime();
3016
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
3017
+ var _tmsConfig$hooks2;
3018
+
3019
+ tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
3020
+ isDev,
3021
+ tmsConfig,
3022
+ modules: newModules
3023
+ });
3024
+ }
3025
+
3026
+ spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
3027
+ spinner.stop();
2888
3028
  cb();
2889
3029
  }
2890
3030
 
@@ -2898,185 +3038,12 @@ var watch_1 = function (glob, watchOptions, callback, module) {
2898
3038
  };
2899
3039
  })(dev$3);
2900
3040
 
2901
- const fs$1 = require$$0__default$2;
2902
- const semver$1 = require$$1__default$9;
2903
- const {
2904
- resolve: resolve$3
2905
- } = widgets;
2906
- const path = require$$1__default$2;
2907
- const shelljs$2 = require$$0__default$3;
2908
- const {
2909
- handleError
2910
- } = handleError_1;
2911
-
2912
- const getLatestVersion = npmName => {
2913
- const data = shelljs$2.exec(`npm view ${npmName} version`);
2914
- return data.stdout || '0.0.0';
2915
- };
2916
- /**
2917
- * 检查package.json的依赖大于node_module的版本,则返回true
2918
- * @param {*} modules 模块
2919
- * @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
2920
- * @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
2921
- * @returns
2922
- */
2923
-
2924
-
2925
- const checkDependencies$1 = (modules, cwd, outputDir) => {
2926
- // 步骤1. 收集package.json
2927
- const packageJsonName = 'package.json'; // 查找文件名
2928
- // 1.1根目录的package.json
2929
-
2930
- const packageArr = [{
2931
- srcPackageDir: path.join(cwd, packageJsonName),
2932
- destNpmDir: resolve$3(outputDir, 'node_modules')
2933
- }]; // 1.2模块的package.json
2934
-
2935
- modules.forEach(item => {
2936
- const srcPackageDir = path.join(cwd, item.path, 'package.json');
2937
-
2938
- if (fs$1.existsSync(srcPackageDir)) {
2939
- packageArr.push({
2940
- srcPackageDir,
2941
- destNpmDir: resolve$3(outputDir, item.root, 'node_modules')
2942
- });
2943
- }
2944
- }); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
2945
-
2946
- for (const item of packageArr) {
2947
- const packageJson = fs$1.readFileSync(item.srcPackageDir, 'utf-8');
2948
- let dependencies = {};
2949
-
2950
- try {
2951
- const json = JSON.parse(packageJson);
2952
- dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
2953
- } catch (e) {
2954
- handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2955
- }
2956
-
2957
- const dependenciesKeys = Object.keys(dependencies);
2958
-
2959
- for (const key of dependenciesKeys) {
2960
- const depPath = path.join(item.destNpmDir, key);
2961
-
2962
- if (!fs$1.existsSync(depPath)) {
2963
- return true;
2964
- }
2965
-
2966
- const depPackagePath = path.join(depPath, 'package.json');
2967
-
2968
- if (fs$1.existsSync(depPackagePath)) {
2969
- const packageData = require(depPackagePath);
2970
-
2971
- if (dependencies[key] === 'latest') {
2972
- dependencies[key] = getLatestVersion(key);
2973
- }
2974
-
2975
- if (packageData.version === 'latest') {
2976
- packageData.version = getLatestVersion(key);
2977
- }
2978
-
2979
- if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
2980
- return true;
2981
- }
2982
- }
2983
- }
2984
- }
2985
-
2986
- return false;
2987
- };
2988
-
2989
- var checkDependencies_1 = {
2990
- checkDependencies: checkDependencies$1
2991
- };
2992
-
2993
- const fs = require$$0__default$2;
2994
- const {
2995
- resolve: resolve$2
2996
- } = widgets;
2997
- const {
2998
- MODULE_CODE_DIR
2999
- } = require$$4;
3000
- const {
3001
- checkRemoteModGitUrlBranch
3002
- } = cloneModules_1;
3003
- const {
3004
- checkDependencies
3005
- } = checkDependencies_1;
3006
- const {
3007
- fail
3008
- } = log$1;
3009
-
3010
- function checkModule(targetModules) {
3011
- // 判断\源码\dist\是否存在用户指定的模块
3012
- for (const item of targetModules) {
3013
- // 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
3014
- if (!item.root) {
3015
- return true;
3016
- } // 判断第三方远程模块git地址与branch是否有更新
3017
-
3018
-
3019
- if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
3020
- return true;
3021
- } // 判断源码目录是否有该模块
3022
-
3023
-
3024
- if (item.path && !fs.existsSync(resolve$2(item.path))) {
3025
- fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
3026
- process.exit(1);
3027
- }
3028
- }
3029
-
3030
- return false;
3031
- }
3032
-
3033
- function isInit$1(tmsConfig, targetModules, contextDir) {
3034
- // 判断是否存在dist目录
3035
- if (!fs.existsSync(contextDir)) {
3036
- return true;
3037
- } // 判断dist是否存在node_modules
3038
-
3039
-
3040
- if (!fs.existsSync(`${contextDir}/node_modules`)) {
3041
- return true;
3042
- } // 判断dist是否存在miniprogram_npm
3043
-
3044
-
3045
- if (!fs.existsSync(`${contextDir}/miniprogram_npm`)) {
3046
- return true;
3047
- } // 判断dist是否存在app.json
3048
-
3049
-
3050
- if (!fs.existsSync(`${contextDir}/app.json`)) {
3051
- return true;
3052
- } // 判断模块信息
3053
-
3054
-
3055
- if (checkModule(targetModules)) {
3056
- return true;
3057
- } // 判断package.json的版本是否有新的版本
3058
-
3059
-
3060
- if (checkDependencies(targetModules, resolve$2('./'), tmsConfig.outputDir)) {
3061
- return true;
3062
- }
3063
-
3064
- return false;
3065
- }
3066
-
3067
- var isInIt = {
3068
- isInit: isInit$1
3069
- };
3070
-
3071
3041
  const shelljs$1 = require$$0__default$3;
3072
3042
  const compileDev = dev$3.exports;
3073
3043
  const {
3074
3044
  resolve: resolve$1
3075
3045
  } = widgets;
3076
3046
  const init$4 = init_1;
3077
- const {
3078
- isInit
3079
- } = isInIt;
3080
3047
  const {
3081
3048
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
3082
3049
  } = tmsMpconfig;
@@ -3085,7 +3052,10 @@ const {
3085
3052
  } = log$1;
3086
3053
  const {
3087
3054
  global: global$1
3088
- } = global_1; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3055
+ } = global_1;
3056
+ const {
3057
+ CACHE_DIR
3058
+ } = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3089
3059
 
3090
3060
  function delOtherModule(tmsConfig, targetModules) {
3091
3061
  const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
@@ -3102,16 +3072,32 @@ function delOtherModule(tmsConfig, targetModules) {
3102
3072
  }
3103
3073
 
3104
3074
  async function dev$2(tmsConfig, targetModules, env) {
3075
+ var _tmsConfig$hooks;
3076
+
3105
3077
  let newModules = targetModules;
3106
- const isLatest = global$1.getData('cmd').latest; // 判断是否进行init命令
3078
+ const {
3079
+ noCache
3080
+ } = global$1.getData('cmd');
3107
3081
 
3108
- if (isLatest || isInit(tmsConfig, targetModules, resolve$1('dist'))) {
3109
- // init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
3110
- const initData = await init$4(tmsConfig, newModules);
3111
- newModules = initData.targetModules;
3112
- }
3082
+ if (noCache) {
3083
+ shelljs$1.rm('-rf', resolve$1('dist'));
3084
+ shelljs$1.rm('-rf', CACHE_DIR);
3085
+ } // 初始化操作
3113
3086
 
3087
+
3088
+ const initData = await init$4(tmsConfig, newModules);
3089
+ newModules = initData.targetModules;
3114
3090
  info$2('当前dev启动的有效模块', newModules.map(item => item.name).sort());
3091
+
3092
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
3093
+ var _tmsConfig$hooks2;
3094
+
3095
+ tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
3096
+ isDev: true,
3097
+ tmsConfig,
3098
+ modules: newModules
3099
+ });
3100
+ }
3115
3101
  delOtherModule(tmsConfig, newModules);
3116
3102
  compileDev(tmsConfig, newModules, env);
3117
3103
  }
@@ -3266,7 +3252,7 @@ var entry = [{
3266
3252
  }, {
3267
3253
  command: 'dev',
3268
3254
  description: 'dev 打包编译',
3269
- options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-latest, --latest', '下载最新第三方模块代码、安装最新依赖']],
3255
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-noCache, --noCache', '不使用缓存功能']],
3270
3256
  action: cmd => {
3271
3257
  run_1('dev', cmd);
3272
3258
  }
@@ -3294,7 +3280,7 @@ var entry = [{
3294
3280
 
3295
3281
  var require$$7 = {
3296
3282
  name: "@tmsfe/tmskit",
3297
- version: "0.0.13",
3283
+ version: "0.0.15-beta.1",
3298
3284
  description: "tmskit",
3299
3285
  main: "dist/index.cjs",
3300
3286
  bin: {
@@ -3308,7 +3294,11 @@ var require$$7 = {
3308
3294
  ],
3309
3295
  scripts: {
3310
3296
  dev: "rollup -wc --environment TARGET:tmskit",
3311
- build: "rollup -c --environment TARGET:tmskit"
3297
+ build: "rollup -c --environment TARGET:tmskit",
3298
+ "pub:patch": "sh build/publish.sh patch",
3299
+ "pub:minor": "sh build/publish.sh minor",
3300
+ "pub:major": "sh build/publish.sh major",
3301
+ postinstall: "cd node_modules/gulp-watch && npm install chokidar@3.5.3"
3312
3302
  },
3313
3303
  author: "tms·web",
3314
3304
  license: "ISC",
@@ -3347,6 +3337,7 @@ var require$$7 = {
3347
3337
  moment: "^2.29.1",
3348
3338
  "object-assign": "^4.0.1",
3349
3339
  ora: "^5.1.0",
3340
+ "patch-package": "^6.4.7",
3350
3341
  "plugin-error": "^1.0.0",
3351
3342
  postcss: "^8.4.6",
3352
3343
  precinct: "^8.3.1",
@@ -3364,7 +3355,7 @@ var require$$7 = {
3364
3355
  }
3365
3356
  };
3366
3357
 
3367
- const semver = require$$1__default$9;
3358
+ const semver = require$$1__default$6;
3368
3359
  const packageJson = require$$7;
3369
3360
  const chalk$1 = require$$0__default;
3370
3361
  const {