@tmsfe/tmskit 0.0.4 → 0.0.5-beta.3

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,22 +5,25 @@ var require$$1 = require('leven');
5
5
  var require$$2 = require('ora');
6
6
  var require$$1$1 = require('path');
7
7
  var require$$0$1 = require('fs');
8
- var require$$0$2 = require('shelljs');
8
+ var require$$5 = require('shelljs');
9
9
  var require$$6$1 = require('download-git-repo');
10
- var require$$0$3 = require('chalk');
11
- var require$$0$4 = require('async');
10
+ var require$$0$2 = require('chalk');
11
+ var require$$0$3 = require('async');
12
12
  var require$$1$2 = require('ejs');
13
13
  var require$$1$3 = require('inquirer');
14
- var require$$0$5 = require('metalsmith');
14
+ var require$$0$4 = require('metalsmith');
15
+ var require$$0$5 = require('lodash');
15
16
  var require$$0$6 = require('miniprogram-ci');
16
- var require$$0$7 = require('lodash');
17
- var require$$7 = require('replace-ext');
18
- var require$$0$8 = require('webpack-chain');
19
- var require$$0$9 = require('webpack');
20
- var require$$0$a = require('webpack/lib/SingleEntryPlugin');
21
- var require$$3$1 = require('copy-webpack-plugin');
22
- var require$$1$4 = require('semver');
23
- var require$$3$2 = require('glob-ignore');
17
+ var require$$3$1 = require('glob-ignore');
18
+ var require$$0$7 = require('through2');
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');
24
27
 
25
28
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
26
29
 
@@ -29,22 +32,25 @@ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
29
32
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
30
33
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
31
34
  var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
32
- var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
35
+ var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
33
36
  var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
37
+ var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
34
38
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
35
- var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
36
39
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
37
40
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
41
+ var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
38
42
  var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
39
43
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
40
- var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
41
- var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
42
- var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
43
- var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
44
- var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
45
44
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
45
+ var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
46
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);
49
+ var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
47
50
  var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
51
+ var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
52
+ var require$$5__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
53
+ var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
48
54
 
49
55
  function getAugmentedNamespace(n) {
50
56
  if (n.__esModule) return n;
@@ -61,16 +67,16 @@ function getAugmentedNamespace(n) {
61
67
  return a;
62
68
  }
63
69
 
64
- var src$1 = {};
70
+ var src$2 = {};
65
71
 
66
72
  const program$1 = require$$0__default;
67
73
  const leven = require$$1__default;
68
74
  const ora = require$$2__default;
69
- const path$7 = require$$1__default$1;
70
- const fs$b = require$$0__default$1;
71
- const shelljs$6 = require$$0__default$2;
75
+ const path$8 = require$$1__default$1;
76
+ const fs$c = require$$0__default$1;
77
+ const shelljs$6 = require$$5__default;
72
78
  const download = require$$6__default;
73
- const chalk$3 = require$$0__default$3;
79
+ const chalk$3 = require$$0__default$2;
74
80
  const shelljsOptons = {
75
81
  slient: true
76
82
  }; // 获取当前目录
@@ -78,7 +84,7 @@ const shelljsOptons = {
78
84
  const cwd = process.cwd();
79
85
 
80
86
  function resolve$c(...args) {
81
- return path$7.resolve(cwd, ...args);
87
+ return path$8.resolve(cwd, ...args);
82
88
  }
83
89
  /**
84
90
  * 封装logs
@@ -147,7 +153,7 @@ function downloadRepo(dest, downloadOptions = {
147
153
  branch
148
154
  } = downloadOptions;
149
155
 
150
- if (fs$b.existsSync(dest)) {
156
+ if (fs$c.existsSync(dest)) {
151
157
  shelljs$6.rm('-rf', dest);
152
158
  }
153
159
 
@@ -179,8 +185,8 @@ function downloadRepoForGit$2(url, dest, branch) {
179
185
  const cwd = process.cwd();
180
186
  return new Promise(resolve => {
181
187
  // 如果目标目录不存在
182
- if (fs$b.existsSync(dest)) {
183
- shelljs$6.rm('-rf', path$7.join(dest));
188
+ if (fs$c.existsSync(dest)) {
189
+ shelljs$6.rm('-rf', path$8.join(dest));
184
190
  }
185
191
 
186
192
  shelljs$6.mkdir('-p', dest);
@@ -207,7 +213,7 @@ const cost = start => Date.now() - start;
207
213
  */
208
214
 
209
215
 
210
- function createTask$5(task, startText, endText) {
216
+ function createTask$4(task, startText, endText) {
211
217
  return async (...args) => {
212
218
  const start = Date.now();
213
219
  let result;
@@ -241,39 +247,39 @@ var widgets = {
241
247
  log: log$3,
242
248
  isObject: isObject$2,
243
249
  isArray: isArray$1,
244
- createTask: createTask$5,
250
+ createTask: createTask$4,
245
251
  downloadRepo,
246
252
  downloadRepoForGit: downloadRepoForGit$2,
247
253
  suggestCommands: suggestCommands$1,
248
254
  camelize
249
255
  };
250
256
 
251
- const path$6 = require('path'); // 用户目录
257
+ const path$7 = require('path'); // 用户目录
252
258
 
253
259
 
254
260
  const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
255
261
 
256
- const CACHE_DIR$1 = path$6.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
262
+ const CACHE_DIR$1 = path$7.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
257
263
 
258
- const TEMPLATE_DIR$1 = path$6.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
264
+ const TEMPLATE_DIR$1 = path$7.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
259
265
 
260
- const MODULE_CODE_DIR$1 = path$6.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
266
+ const MODULE_CODE_DIR$1 = path$7.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
261
267
 
262
- const TEMPLATE_PATH$1 = path$6.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
268
+ const TEMPLATE_PATH$1 = path$7.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
263
269
 
264
270
  const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
265
271
 
266
272
  const TMS_CONFIG_FILENAME$1 = 'tms.config.js'; // 模块代码的默认在modules子目录
267
273
 
268
- const DEFAULT_MODULE_DIR$5 = 'modules'; // 模块的配置文件的名称
274
+ const DEFAULT_MODULE_DIR$4 = 'modules'; // 模块的配置文件的名称
269
275
 
270
276
  const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
271
277
 
272
- const DEFAULT_WEBPACK_ENTRY$2 = {
273
- app: path$6.resolve(process.cwd(), 'app')
278
+ const DEFAULT_WEBPACK_ENTRY = {
279
+ app: path$7.resolve(process.cwd(), 'app')
274
280
  }; // 默认从源码拷贝到编译后的配置
275
281
 
276
- const DEFAULT_COPY_CONFIG$3 = ['package.json', 'app.js', 'app.ts', 'app.less', 'app.wxss', 'sitemap.json']; // 开发模式
282
+ const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
277
283
 
278
284
  const MODE$1 = {
279
285
  main: 'tkitmain',
@@ -294,10 +300,10 @@ var constant = /*#__PURE__*/Object.freeze({
294
300
  TEMPLATE_PATH: TEMPLATE_PATH$1,
295
301
  TMS_NAME: TMS_NAME$2,
296
302
  TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
297
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$5,
303
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$4,
298
304
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
299
- DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY$2,
300
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$3,
305
+ DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
306
+ DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
301
307
  MODULE_CODE_DIR: MODULE_CODE_DIR$1,
302
308
  MODE: MODE$1,
303
309
  ENV: ENV,
@@ -306,14 +312,15 @@ var constant = /*#__PURE__*/Object.freeze({
306
312
 
307
313
  var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
308
314
 
309
- const fs$a = require$$0__default$1;
315
+ const fs$b = require$$0__default$1;
316
+ const path$6 = require$$1__default$1;
310
317
  /**
311
318
  * 判断目录是否为空
312
319
  * @param {string} dirname 目录名
313
320
  * @returns
314
321
  */
315
322
 
316
- const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files.length === 0);
323
+ const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files.length === 0);
317
324
  /**
318
325
  * 确保目录存在,不存在就创建一个
319
326
  * @param {*} dirname 目录名
@@ -321,19 +328,70 @@ const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files
321
328
 
322
329
 
323
330
  const ensureDirExist = dirname => {
324
- if (!fs$a.existsSync(dirname)) {
325
- fs$a.mkdirSync(dirname, {
331
+ if (!fs$b.existsSync(dirname)) {
332
+ fs$b.mkdirSync(dirname, {
326
333
  recursive: true
327
334
  });
328
335
  }
336
+ }; // 复制文件
337
+
338
+
339
+ const copyFile$2 = function (src, dest) {
340
+ if (fs$b.existsSync(dest)) {
341
+ fs$b.unlinkSync(dest);
342
+ }
343
+
344
+ const dir = dest.substr(0, dest.lastIndexOf('/'));
345
+ ensureDirExist(dir);
346
+ fs$b.copyFileSync(src, dest);
347
+ }; // 添加后缀
348
+
349
+
350
+ function ext$2(filePath, extensions) {
351
+ let newFilePath = filePath;
352
+
353
+ try {
354
+ const stat = fs$b.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$b.existsSync(file)) {
365
+ return {
366
+ file,
367
+ ext
368
+ };
369
+ }
370
+ }
371
+
372
+ return null;
373
+ } // 判断文件是否在某个目录
374
+
375
+
376
+ const fileInDir$2 = (dir, file) => {
377
+ const relativePath = path$6.relative(dir, file);
378
+
379
+ if (relativePath.startsWith('..')) {
380
+ return false;
381
+ }
382
+
383
+ return true;
329
384
  };
330
385
 
331
386
  var io$2 = {
332
387
  isDirEmpty,
333
- ensureDirExist
388
+ copyFile: copyFile$2,
389
+ ensureDirExist,
390
+ ext: ext$2,
391
+ fileInDir: fileInDir$2
334
392
  };
335
393
 
336
- const chalk$2 = require$$0__default$3;
394
+ const chalk$2 = require$$0__default$2;
337
395
  /**
338
396
  * 本文件提供无依赖的在终端打印彩色文字的方法。
339
397
  */
@@ -346,7 +404,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
346
404
  * @returns {undefined} 无
347
405
  */
348
406
 
349
- const fail$a = (message = '') => {
407
+ const fail$9 = (message = '') => {
350
408
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
351
409
 
352
410
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
@@ -379,12 +437,12 @@ const warn = message => {
379
437
  };
380
438
 
381
439
  var log$2 = {
382
- fail: fail$a,
440
+ fail: fail$9,
383
441
  succeed: succeed$1,
384
442
  warn
385
443
  };
386
444
 
387
- const async = require$$0__default$4;
445
+ const async = require$$0__default$3;
388
446
  const ejs = require$$1__default$2;
389
447
 
390
448
  const render$1 = (files, metalsmith, next) => {
@@ -404,7 +462,7 @@ const render$1 = (files, metalsmith, next) => {
404
462
 
405
463
  var render_1 = render$1;
406
464
 
407
- const fs$9 = require$$0__default$1;
465
+ const fs$a = require$$0__default$1;
408
466
  const inquirer = require$$1__default$3;
409
467
  const {
410
468
  resolve: resolve$b
@@ -421,12 +479,12 @@ const {
421
479
  const parseTemplateQuestions = dir => {
422
480
  let prompts = [];
423
481
 
424
- if (!fs$9.existsSync(`${dir}/questions.json`)) {
482
+ if (!fs$a.existsSync(`${dir}/questions.json`)) {
425
483
  return prompts;
426
484
  }
427
485
 
428
486
  try {
429
- const json = JSON.parse(fs$9.readFileSync(`${dir}/questions.json`));
487
+ const json = JSON.parse(fs$a.readFileSync(`${dir}/questions.json`));
430
488
 
431
489
  if (Array.isArray(json) && json.length > 0) {
432
490
  json.forEach((item, index) => {
@@ -484,7 +542,7 @@ var ask_1 = ask$1;
484
542
  const FILES_TO_IGNORE$1 = ['node_modules'];
485
543
  var ignoreFiles = FILES_TO_IGNORE$1;
486
544
 
487
- const Metalsmith = require$$0__default$5;
545
+ const Metalsmith = require$$0__default$4;
488
546
  const render = render_1;
489
547
  const ask = ask_1;
490
548
  const FILES_TO_IGNORE = ignoreFiles;
@@ -502,8 +560,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
502
560
  var generator_1 = generator$1;
503
561
 
504
562
  const path$5 = require$$1__default$1;
505
- const fs$8 = require$$0__default$1;
506
- const shelljs$5 = require$$0__default$2;
563
+ const fs$9 = require$$0__default$1;
564
+ const shelljs$5 = require$$5__default;
507
565
  const {
508
566
  TEMPLATE_DIR,
509
567
  TEMPLATE_PATH,
@@ -511,12 +569,12 @@ const {
511
569
  } = require$$3;
512
570
  const {
513
571
  downloadRepoForGit: downloadRepoForGit$1,
514
- createTask: createTask$4,
572
+ createTask: createTask$3,
515
573
  resolve: resolve$a
516
574
  } = widgets;
517
575
  const io$1 = io$2;
518
576
  const {
519
- fail: fail$9,
577
+ fail: fail$8,
520
578
  succeed
521
579
  } = log$2;
522
580
  const generator = generator_1;
@@ -528,9 +586,9 @@ const generator = generator_1;
528
586
 
529
587
  async function createAppDir(targetDir) {
530
588
  // 如果目录非空或者已经存在,提示用户,做选择
531
- if (fs$8.existsSync(targetDir)) {
589
+ if (fs$9.existsSync(targetDir)) {
532
590
  if (!(await io$1.isDirEmpty(targetDir))) {
533
- fail$9('该目录名已经存在,换个项目名字吧~');
591
+ fail$8('该目录名已经存在,换个项目名字吧~');
534
592
  process.exit(1);
535
593
  }
536
594
  } else {
@@ -552,7 +610,7 @@ async function create(appName) {
552
610
 
553
611
  io$1.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
554
612
 
555
- await createTask$4(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
613
+ await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
556
614
 
557
615
  generator(path$5.join(TEMPLATE_PATH, appType), targetDir, {
558
616
  appName,
@@ -577,20 +635,20 @@ async function create(appName) {
577
635
  shelljs$5.rm('-rf', resolve$a(appName, TEMPLATE_TKIT_DIR));
578
636
  succeed('项目创建完成.');
579
637
  }).catch(err => {
580
- fail$9(err.message);
638
+ fail$8(err.message);
581
639
  console.log('详细的错误信息:', err);
582
640
  });
583
641
  }
584
642
 
585
643
  var create_1 = create;
586
644
 
587
- const fs$7 = require$$0__default$1;
645
+ const fs$8 = require$$0__default$1;
588
646
  const {
589
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$4,
647
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3,
590
648
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1
591
649
  } = require$$3;
592
650
  const {
593
- fail: fail$8
651
+ fail: fail$7
594
652
  } = log$2;
595
653
  const {
596
654
  resolve: resolve$9,
@@ -644,8 +702,8 @@ function getLocalModuleConfig(modules = [], appName, moduleDir, moduleConfigFile
644
702
  }) => {
645
703
  const moduleConfigPath = resolve$9(path, moduleConfigFilename);
646
704
 
647
- if (fs$7.existsSync(moduleConfigPath)) {
648
- const content = fs$7.readFileSync(moduleConfigPath, 'utf-8');
705
+ if (fs$8.existsSync(moduleConfigPath)) {
706
+ const content = fs$8.readFileSync(moduleConfigPath, 'utf-8');
649
707
  modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName, moduleDir);
650
708
  }
651
709
  });
@@ -670,7 +728,7 @@ function updateMainPackages(appJson, mainPackages = []) {
670
728
 
671
729
  foundMainPackages.forEach(subpackage => {
672
730
  if (!subpackage.pages || !subpackage.pages.length) {
673
- fail$8(`主包 ${subpackage} 不能没有 pages`);
731
+ fail$7(`主包 ${subpackage} 不能没有 pages`);
674
732
  process.exit(-1);
675
733
  }
676
734
 
@@ -696,12 +754,12 @@ function updateMainPackages(appJson, mainPackages = []) {
696
754
 
697
755
 
698
756
  const getAppJsonContent = sourceAppJsonPath => {
699
- if (!fs$7.existsSync(sourceAppJsonPath)) {
700
- fail$8(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
757
+ if (!fs$8.existsSync(sourceAppJsonPath)) {
758
+ fail$7(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
701
759
  process.exit(1);
702
760
  }
703
761
 
704
- const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
762
+ const appJson = JSON.parse(fs$8.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
705
763
 
706
764
  appJson.subpackages = [];
707
765
  appJson.pages = [];
@@ -732,245 +790,22 @@ const updateSubpackages = (appJson, modulesConfig) => {
732
790
  */
733
791
 
734
792
 
735
- function buildOutputAppJson$2(tmsConfig, modules) {
793
+ function buildOutputAppJson$1(tmsConfig, modules) {
736
794
  // 获取当前 modules 下的所有子模块的配置内容
737
- const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$4, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
795
+ const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$3, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
738
796
 
739
797
  const appJson = getAppJsonContent(resolve$9('./app.json')); // 更新app.json中的subpackages
740
798
 
741
799
  updateSubpackages(appJson, modulesConfig); // 更新主包,需在subpackages处理完成后执行, pages/
742
800
 
743
801
  updateMainPackages(appJson, tmsConfig.mainPackages);
744
- fs$7.writeFileSync(resolve$9(`${tmsConfig.webpack.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
802
+ fs$8.writeFileSync(resolve$9(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
745
803
  return appJson;
746
804
  }
747
805
 
748
806
  var buildAppJson = {
749
807
  setModuleConfig: setModuleConfig$1,
750
- buildOutputAppJson: buildOutputAppJson$2
751
- };
752
-
753
- /**
754
- * 本文件主要负责项目或者分包依赖的npm的安装
755
- */
756
- const fs$6 = require$$0__default$1;
757
- const path$4 = require$$1__default$1;
758
- const shell = require$$0__default$2;
759
- const LOG = log$2;
760
- const dirpath = process.cwd(); // 项目根目录
761
-
762
- const getTarNpmFilename = targetDir => `${targetDir.replaceAll('/', '-')}.tar.gz`; // 缓存npm包
763
-
764
-
765
- const npmCache = function (targetDir, cacheDir) {
766
- if (!fs$6.existsSync(cacheDir)) {
767
- fs$6.mkdirSync(cacheDir);
768
- }
769
-
770
- const tarNpmFilename = getTarNpmFilename(targetDir);
771
- const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
772
-
773
- if (fs$6.existsSync(tarNpmFilePath)) {
774
- shell.rm('-rf', tarNpmFilePath);
775
- }
776
-
777
- const cmd = `tar -zcvf ${tarNpmFilePath} ./node_modules`;
778
- shell.exec(cmd, {
779
- async: true,
780
- silent: true
781
- }); // tar -zcvf /Users/odile/.tmskit/node_modules.tar.gz ./node_modules
782
- }; // 获取缓存npm包
783
-
784
-
785
- const getNpmCache = function (targetDir, cacheDir) {
786
- const tarNpmFilename = getTarNpmFilename(targetDir);
787
- const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
788
-
789
- if (fs$6.existsSync(tarNpmFilePath)) {
790
- const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
791
- shell.exec(cmd, {
792
- async: false,
793
- silent: true
794
- });
795
- } // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
796
-
797
- }; // 遍历安装指定目录下所有项目的npm依赖
798
-
799
-
800
- const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
801
- const packageJsonFiles = await findAllPackageJson$1(modules, contextDir);
802
- await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
803
- const dir = path$4.dirname(file);
804
- shell.cd(dir);
805
-
806
- if (!fs$6.existsSync(`${dir}/node_modules`)) {
807
- getNpmCache(dir, cacheDir);
808
- }
809
-
810
- shell.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
811
- silent: false
812
- });
813
- resolve();
814
- npmCache(dir, cacheDir);
815
- })));
816
- };
817
- /**
818
- * 递归查找指定条件的文件
819
- * @param {String} startPath 开始查找的根路径
820
- * @param {String} filter 匹配的字符串
821
- * @returns {Array<String>} 查找到的文件路径列表
822
- */
823
-
824
-
825
- const findFilesByFilter = (startPath, filter) => {
826
- const result = [];
827
- /**
828
- * 根据指定的筛选器查找文件
829
- * @param {String} startPath 开始查找的文件夹路径
830
- * @param {String} filter 筛选器
831
- * @returns {Undefined} 无需返回值
832
- */
833
-
834
- const find = (startPath, filter) => {
835
- // 目录不存在
836
- if (!fs$6.existsSync(startPath)) {
837
- LOG.fail(`${startPath}目录不存在`);
838
- process.exit(-1);
839
- return;
840
- } // 当前目录下的所有文件 / 文件夹
841
-
842
-
843
- const exceptDir = ['node_modules', 'miniprogram_npm'];
844
-
845
- if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
846
- return;
847
- }
848
-
849
- const files = fs$6.readdirSync(startPath);
850
- files.forEach(file => {
851
- const filename = path$4.join(startPath, file);
852
- const stat = fs$6.lstatSync(filename); // 当前文件是文件夹类型,继续递归
853
-
854
- if (stat.isDirectory()) {
855
- find(filename, filter);
856
- } else if (filename.indexOf(filter) >= 0) {
857
- // 文件类型
858
- result.push(filename);
859
- }
860
- });
861
- };
862
-
863
- find(startPath, filter);
864
- return result;
865
- };
866
- /**
867
- * 找到项目中所有的package.json文件
868
- * @param {Array<String>} subRoots 需要安装npm依赖的路径
869
- * @param {String} contextDir 命令运行的目录
870
- * @returns {Array<String>} 找到的所有package.json文件的路径
871
- */
872
-
873
-
874
- const findAllPackageJson$1 = (subRoots = [], contextDir) => {
875
- const packageJsonName = 'package.json'; // 查找文件名
876
-
877
- const cwd = contextDir || dirpath;
878
- const result = [path$4.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
879
-
880
- subRoots.forEach(subRoot => {
881
- const toppath = path$4.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
882
-
883
- const list = findFilesByFilter(toppath, packageJsonName);
884
- result.push(...list);
885
- });
886
- return result;
887
- };
888
-
889
- var npmUtils = {
890
- npmInstallAll: npmInstallAll$1,
891
- findAllPackageJson: findAllPackageJson$1
892
- };
893
-
894
- /* eslint-disable require-jsdoc */
895
- const ci = require$$0__default$6;
896
- const path$3 = require$$1__default$1;
897
- /**
898
- * 获取小程序ci的Project对象
899
- * @returns {Object} 小程序ci对象
900
- */
901
-
902
- const getMpCi = ({
903
- appId,
904
- projectPath,
905
- type = 'miniProgram',
906
- privateKey = 'TODO'
907
- }) => {
908
- var _cfgJsonContent$packO;
909
-
910
- const cfgJsonContent = require(path$3.join(projectPath, 'project.config.json'));
911
-
912
- const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
913
- value
914
- }) => value)) || [];
915
- return new ci.Project({
916
- appid: appId,
917
- privateKey,
918
- type,
919
- projectPath,
920
- ignores: ['node_modules/**/*', ...ignores]
921
- });
922
- }; // 用小程序ci工具构建小程序
923
-
924
-
925
- const packMpProject = async project => {
926
- await ci.packNpm(project, {
927
- ignores: ['cloud/**/*']
928
- });
929
- };
930
- /**
931
- * 格式化构建npm结果信息
932
- * @param {Array<String>} warning 构建时的告警信息
933
- * @returns {String} npm构建错误信息
934
- */
935
-
936
-
937
- const formatPackNpmWarning = warning => {
938
- if (!warning) {
939
- return '';
940
- }
941
-
942
- const result = warning.map((it, index) => `${index + 1}. ${it.msg}
943
- \t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
944
- return result;
945
- };
946
- /**
947
- * 构建miniprogram_npm
948
- * @returns {Object} 小程序ci对象
949
- */
950
-
951
-
952
- const buildMpNpm$2 = async ({
953
- appId,
954
- projectPath,
955
- privateKey
956
- }) => {
957
- const mpCi = await getMpCi({
958
- appId,
959
- projectPath,
960
- privateKey
961
- });
962
- const packNpmWarning = await packMpProject(mpCi);
963
- const packNpmMsg = formatPackNpmWarning(packNpmWarning);
964
-
965
- if (packNpmMsg) {
966
- return Promise.reject(packNpmMsg);
967
- }
968
-
969
- return Promise.resolve();
970
- };
971
-
972
- var mpCiUtils = {
973
- buildMpNpm: buildMpNpm$2
808
+ buildOutputAppJson: buildOutputAppJson$1
974
809
  };
975
810
 
976
811
  class Globale {
@@ -1008,7 +843,7 @@ var global = {
1008
843
  getGlobalInstance: getGlobalInstance$1
1009
844
  };
1010
845
 
1011
- const MetalSmith = require$$0__default$5;
846
+ const MetalSmith = require$$0__default$4;
1012
847
  const {
1013
848
  getGlobalInstance
1014
849
  } = global;
@@ -1017,10 +852,10 @@ const {
1017
852
  resolve: resolve$8
1018
853
  } = widgets;
1019
854
  const {
1020
- fail: fail$7
855
+ fail: fail$6
1021
856
  } = log$2;
1022
- const fs$5 = require$$0__default$1;
1023
- const shelljs$4 = require$$0__default$2;
857
+ const fs$7 = require$$0__default$1;
858
+ const shelljs$4 = require$$5__default;
1024
859
  /**
1025
860
  * 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
1026
861
  * @param { string } sourceDir 缓存文件夹
@@ -1034,7 +869,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1034
869
  return new Promise(resolve => {
1035
870
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1036
871
  if (e) {
1037
- fail$7(e); // eslint-disable-line
872
+ fail$6(e); // eslint-disable-line
1038
873
 
1039
874
  console.log('MetalSmith 详细的错误信息:', e);
1040
875
  }
@@ -1094,13 +929,13 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
1094
929
  sourcePath = globalInstance.getModuleCache(httpRepoUrl, cloneBranch).dest;
1095
930
  }
1096
931
 
1097
- if (fs$5.existsSync(targetPath)) {
932
+ if (fs$7.existsSync(targetPath)) {
1098
933
  shelljs$4.rm('-rf', targetPath);
1099
934
  }
1100
935
 
1101
936
  await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
1102
937
  } catch (e) {
1103
- fail$7(`downLoadAndMoveModule ${e}`); // eslint-disable-line
938
+ fail$6(`downLoadAndMoveModule ${e}`); // eslint-disable-line
1104
939
 
1105
940
  process.exit(-1);
1106
941
  }
@@ -1115,7 +950,11 @@ var defaultTmsConfig$1 = {
1115
950
  envData: {},
1116
951
  // 模块配置信息
1117
952
  modules: [],
1118
- webpack: {
953
+ cloudDir: 'cloud',
954
+ gulp: {
955
+ // 第三方依赖代码需要拷贝到本项目的
956
+ dependencies: {},
957
+
1119
958
  /** 编译输出文件夹位置 */
1120
959
  outputDir: 'dist',
1121
960
 
@@ -1123,15 +962,12 @@ var defaultTmsConfig$1 = {
1123
962
  sourceDir: './',
1124
963
 
1125
964
  /** 源码Map */
1126
- sourceMap: 'none',
1127
-
1128
- /** 别名 */
1129
- alias: {}
965
+ copy: []
1130
966
  }
1131
967
  };
1132
968
 
1133
- const loadash = require$$0__default$7;
1134
- const fs$4 = require$$0__default$1;
969
+ const loadash = require$$0__default$5;
970
+ const fs$6 = require$$0__default$1;
1135
971
  const {
1136
972
  TMS_NAME: TMS_NAME$1,
1137
973
  TMS_CONFIG_FILENAME,
@@ -1146,7 +982,7 @@ const {
1146
982
  } = buildAppJson;
1147
983
  const defaultTmsConfig = defaultTmsConfig$1;
1148
984
  const {
1149
- fail: fail$6
985
+ fail: fail$5
1150
986
  } = log$2;
1151
987
  /**
1152
988
  * 读取tms.config.json
@@ -1156,8 +992,8 @@ const {
1156
992
  const readTmsConfig$1 = function (env) {
1157
993
  const tmsConfigPath = resolve$7(TMS_CONFIG_FILENAME);
1158
994
 
1159
- if (!fs$4.existsSync(tmsConfigPath)) {
1160
- fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
995
+ if (!fs$6.existsSync(tmsConfigPath)) {
996
+ fail$5('当前执行目录没有tms.config.js的配置项,请进行配置');
1161
997
  process.exit(1);
1162
998
  }
1163
999
 
@@ -1186,7 +1022,7 @@ const checkModules$1 = function (tmsConfig, modules) {
1186
1022
  });
1187
1023
 
1188
1024
  if (targetModules.length === 0) {
1189
- fail$6(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
1025
+ fail$5(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
1190
1026
  process.exit(1);
1191
1027
  }
1192
1028
 
@@ -1209,8 +1045,8 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName, moduleDir) => {
1209
1045
  }, moduleIndex) => {
1210
1046
  const moduleConfigPath = resolve$7(relativePath, MODULE_CONFIG_FILENAME);
1211
1047
 
1212
- if (fs$4.existsSync(moduleConfigPath)) {
1213
- let moduleConfigContent = fs$4.readFileSync(moduleConfigPath, 'utf-8');
1048
+ if (fs$6.existsSync(moduleConfigPath)) {
1049
+ let moduleConfigContent = fs$6.readFileSync(moduleConfigPath, 'utf-8');
1214
1050
  moduleConfigContent = setModuleConfig(moduleConfigContent, appName, moduleDir);
1215
1051
  const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
1216
1052
  moduleContentArr.forEach(({
@@ -1236,544 +1072,914 @@ var tkitUtils = {
1236
1072
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3
1237
1073
  };
1238
1074
 
1239
- const shelljs$3 = require$$0__default$2;
1240
- const fs$3 = require$$0__default$1;
1241
- const io = io$2;
1242
- const {
1243
- resolve: resolve$6,
1244
- createTask: createTask$3
1245
- } = widgets;
1246
- const {
1247
- buildOutputAppJson: buildOutputAppJson$1
1248
- } = buildAppJson;
1249
- const {
1250
- npmInstallAll
1251
- } = npmUtils;
1252
- const {
1075
+ /* eslint-disable require-jsdoc */
1076
+ const ci = require$$0__default$6;
1077
+ const path$4 = require$$1__default$1;
1078
+ /**
1079
+ * 获取小程序ci的Project对象
1080
+ * @returns {Object} 小程序ci对象
1081
+ */
1082
+
1083
+ const getMpCi = ({
1084
+ appId,
1085
+ projectPath,
1086
+ type = 'miniProgram',
1087
+ privateKey = 'TODO'
1088
+ }) => {
1089
+ var _cfgJsonContent$packO;
1090
+
1091
+ const cfgJsonContent = require(path$4.join(projectPath, 'project.config.json'));
1092
+
1093
+ const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
1094
+ value
1095
+ }) => value)) || [];
1096
+ return new ci.Project({
1097
+ appid: appId,
1098
+ privateKey,
1099
+ type,
1100
+ projectPath,
1101
+ ignores: ['node_modules/**/*', ...ignores]
1102
+ });
1103
+ }; // 用小程序ci工具构建小程序
1104
+
1105
+
1106
+ const packMpProject = async project => {
1107
+ await ci.packNpm(project, {
1108
+ ignores: ['cloud/**/*']
1109
+ });
1110
+ };
1111
+ /**
1112
+ * 格式化构建npm结果信息
1113
+ * @param {Array<String>} warning 构建时的告警信息
1114
+ * @returns {String} npm构建错误信息
1115
+ */
1116
+
1117
+
1118
+ const formatPackNpmWarning = warning => {
1119
+ if (!warning) {
1120
+ return '';
1121
+ }
1122
+
1123
+ const result = warning.map((it, index) => `${index + 1}. ${it.msg}
1124
+ \t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
1125
+ return result;
1126
+ };
1127
+ /**
1128
+ * 构建miniprogram_npm
1129
+ * @returns {Object} 小程序ci对象
1130
+ */
1131
+
1132
+
1133
+ const buildMpNpm$1 = async ({
1134
+ appId,
1135
+ projectPath,
1136
+ privateKey
1137
+ }) => {
1138
+ const mpCi = await getMpCi({
1139
+ appId,
1140
+ projectPath,
1141
+ privateKey
1142
+ });
1143
+ const packNpmWarning = await packMpProject(mpCi);
1144
+ const packNpmMsg = formatPackNpmWarning(packNpmWarning);
1145
+
1146
+ if (packNpmMsg) {
1147
+ return Promise.reject(packNpmMsg);
1148
+ }
1149
+
1150
+ return Promise.resolve();
1151
+ };
1152
+
1153
+ var mpCiUtils = {
1253
1154
  buildMpNpm: buildMpNpm$1
1254
- } = mpCiUtils;
1255
- const {
1256
- MODULE_CODE_DIR,
1257
- CACHE_DIR,
1258
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
1259
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3
1260
- } = require$$3;
1261
- const {
1262
- cloneModules
1263
- } = cloneModules_1;
1264
- const {
1265
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
1266
- } = tkitUtils;
1267
- const {
1268
- fail: fail$5
1269
- } = log$2;
1155
+ };
1156
+
1270
1157
  /**
1271
- * 拷贝package.json\模块的代码到编译输出目录
1272
- * @param { object } tmsConfig
1273
- * @param { array } modules
1274
- * @param { array } defaultFiles 默认需要拷贝的配置项
1275
- * @returns
1158
+ * 本文件主要负责项目或者分包依赖的npm的安装
1276
1159
  */
1160
+ const fs$5 = require$$0__default$1;
1161
+ const path$3 = require$$1__default$1;
1162
+ const shell = require$$5__default;
1163
+ const glob = require$$3__default;
1164
+ const LOG = log$2;
1165
+ const dirpath = process.cwd(); // 项目根目录
1277
1166
 
1278
- const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1279
- const outputDir = resolve$6(tmsConfig.webpack.outputDir);
1280
- io.ensureDirExist(outputDir);
1281
- defaultFiles.forEach(item => {
1282
- if (fs$3.existsSync(resolve$6(item))) {
1283
- shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.webpack.outputDir, item));
1167
+ const getTarNpmFilename = targetDir => `${targetDir.replace(/\//g, '-')}.tar.gz`; // 缓存npm包
1168
+
1169
+
1170
+ const npmCache = function (targetDir, cacheDir) {
1171
+ if (!fs$5.existsSync(cacheDir)) {
1172
+ fs$5.mkdirSync(cacheDir);
1173
+ }
1174
+
1175
+ const tarNpmFilename = getTarNpmFilename(targetDir);
1176
+ const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1177
+
1178
+ if (fs$5.existsSync(tarNpmFilePath)) {
1179
+ shell.rm('-rf', tarNpmFilePath);
1180
+ }
1181
+
1182
+ const cmd = `tar -zcvf ${tarNpmFilePath} ./node_modules`;
1183
+ shell.exec(cmd, {
1184
+ async: true,
1185
+ silent: true
1186
+ }); // tar -zcvf /Users/odile/.tmskit/node_modules.tar.gz ./node_modules
1187
+ }; // 获取缓存npm包
1188
+
1189
+
1190
+ const getNpmCache = function (targetDir, cacheDir) {
1191
+ const tarNpmFilename = getTarNpmFilename(targetDir);
1192
+ const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1193
+
1194
+ if (fs$5.existsSync(tarNpmFilePath)) {
1195
+ const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
1196
+ shell.exec(cmd, {
1197
+ async: false,
1198
+ silent: true
1199
+ });
1200
+ } // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
1201
+
1202
+ }; // 遍历安装指定目录下所有项目的npm依赖
1203
+
1204
+
1205
+ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1206
+ const packageJsonFiles = await findAllPackageJson(modules, contextDir);
1207
+ await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
1208
+ const dir = path$3.dirname(file);
1209
+ shell.cd(dir);
1210
+
1211
+ if (!fs$5.existsSync(`${dir}/node_modules`)) {
1212
+ getNpmCache(dir, cacheDir);
1284
1213
  }
1285
- }); // 拷贝模块的代码到编译输出目录
1286
1214
 
1287
- targetModules.forEach(item => {
1288
- const outputModuleDir = resolve$6(`${tmsConfig.webpack.outputDir}/${item.root}`);
1215
+ shell.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
1216
+ silent: false
1217
+ });
1218
+ resolve();
1219
+ npmCache(dir, cacheDir);
1220
+ })));
1221
+ };
1222
+ /**
1223
+ * 递归查找指定条件的文件
1224
+ * @param {String} startPath 开始查找的根路径
1225
+ * @param {String} filter 匹配的字符串
1226
+ * @returns {Array<String>} 查找到的文件路径列表
1227
+ */
1289
1228
 
1290
- if (!fs$3.existsSync(resolve$6(item.path))) {
1291
- fail$5(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1292
- process.exit(1);
1229
+
1230
+ const findFilesByFilter = (startPath, filter) => {
1231
+ const result = [];
1232
+ /**
1233
+ * 根据指定的筛选器查找文件
1234
+ * @param {String} startPath 开始查找的文件夹路径
1235
+ * @param {String} filter 筛选器
1236
+ * @returns {Undefined} 无需返回值
1237
+ */
1238
+
1239
+ const find = (startPath, filter) => {
1240
+ // 目录不存在
1241
+ if (!fs$5.existsSync(startPath)) {
1242
+ LOG.fail(`${startPath}目录不存在`);
1243
+ process.exit(-1);
1244
+ return;
1245
+ } // 当前目录下的所有文件 / 文件夹
1246
+
1247
+
1248
+ const exceptDir = ['node_modules', 'miniprogram_npm'];
1249
+
1250
+ if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
1251
+ return;
1293
1252
  }
1294
1253
 
1295
- if (!fs$3.existsSync(outputModuleDir)) {
1296
- shelljs$3.mkdir('-p', outputModuleDir);
1297
- } else {
1298
- // 删除除了node_modules、miniprogram_npm 的其他文件
1299
- // eslint-disable-next-line
1300
- shelljs$3.exec('find . -not \( -name node_modules -or -name miniprogram_npm \) -delete', {
1301
- silent: true
1302
- });
1254
+ const files = fs$5.readdirSync(startPath);
1255
+ files.forEach(file => {
1256
+ const filename = path$3.join(startPath, file);
1257
+ const stat = fs$5.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1258
+
1259
+ if (stat.isDirectory()) {
1260
+ find(filename, filter);
1261
+ } else if (filename.indexOf(filter) >= 0) {
1262
+ // 文件类型
1263
+ result.push(filename);
1264
+ }
1265
+ });
1266
+ };
1267
+
1268
+ find(startPath, filter);
1269
+ return result;
1270
+ };
1271
+ /**
1272
+ * 找到项目中所有的package.json文件
1273
+ * @param {Array<String>} subRoots 需要安装npm依赖的路径
1274
+ * @param {String} contextDir 命令运行的目录
1275
+ * @returns {Array<String>} 找到的所有package.json文件的路径
1276
+ */
1277
+
1278
+
1279
+ const findAllPackageJson = (subRoots = [], contextDir) => {
1280
+ const packageJsonName = 'package.json'; // 查找文件名
1281
+
1282
+ const cwd = contextDir || dirpath;
1283
+ const result = [path$3.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1284
+
1285
+ subRoots.forEach(subRoot => {
1286
+ if (!subRoot.root) {
1287
+ LOG.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
1288
+ process.exit(1);
1303
1289
  }
1304
1290
 
1305
- shelljs$3.cp('-Rf', `${resolve$6(item.path)}/*`, outputModuleDir);
1291
+ const toppath = path$3.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1292
+
1293
+ const list = findFilesByFilter(toppath, packageJsonName);
1294
+ result.push(...list);
1306
1295
  });
1296
+ return result;
1307
1297
  };
1308
1298
 
1309
- async function task(tmsConfig, targetModules) {
1310
- // 下载和移动代码
1311
- await createTask$3(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1299
+ function cloudNpmInstall$1(contextDir) {
1300
+ return new Promise((resolve, reject) => {
1301
+ glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
1302
+ if (err) {
1303
+ reject(err);
1304
+ }
1312
1305
 
1313
- const newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$3);
1314
- console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
1306
+ files.forEach(file => {
1307
+ const dir = path$3.dirname(file);
1308
+ shell.cd(dir);
1309
+ shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
1310
+ silent: false
1311
+ });
1312
+ });
1313
+ resolve();
1314
+ });
1315
+ });
1316
+ }
1315
1317
 
1316
- await createTask$3(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG$2); // npm install
1318
+ var npmUtils = {
1319
+ cloudNpmInstall: cloudNpmInstall$1,
1320
+ mpNpmInstallAll: mpNpmInstallAll$1,
1321
+ findAllPackageJson
1322
+ };
1317
1323
 
1318
- await createTask$3(npmInstallAll, '开始npm install', 'npm install 完成')(newModules, resolve$6(tmsConfig.webpack.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1324
+ const {
1325
+ createTask: createTask$2,
1326
+ resolve: resolve$6
1327
+ } = widgets;
1328
+ const {
1329
+ buildMpNpm
1330
+ } = mpCiUtils;
1331
+ const {
1332
+ CACHE_DIR,
1333
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$2
1334
+ } = require$$3;
1335
+ const {
1336
+ cloudNpmInstall,
1337
+ mpNpmInstallAll
1338
+ } = npmUtils;
1339
+ const {
1340
+ tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
1341
+ } = tkitUtils;
1342
+
1343
+ async function install$2(tmsConfig, modules, isCloud = true) {
1344
+ const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
1345
+
1346
+ await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$6(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1319
1347
 
1320
- await createTask$3(buildMpNpm$1, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1348
+ await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1321
1349
  appId: tmsConfig.appId,
1322
1350
  projectPath: resolve$6('./'),
1323
1351
  privateKey: tmsConfig.privateKey
1324
- }); // 动态生成编译后的app.json;
1352
+ }); // 安装云函数的
1325
1353
 
1326
- await createTask$3(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
1327
- return newModules;
1354
+ isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$6(tmsConfig.cloudDir));
1328
1355
  }
1329
1356
 
1330
- async function bootstrap(tmsConfig, targetModules) {
1331
- const newModules = await task(tmsConfig, targetModules);
1332
- return {
1333
- targetModules: newModules
1334
- };
1335
- }
1357
+ var install_1 = install$2;
1336
1358
 
1337
- var init$5 = bootstrap;
1338
-
1339
- const path$2 = require$$1__default$1;
1340
- const fs$2 = require$$0__default$1;
1359
+ const shelljs$3 = require$$5__default;
1360
+ const fs$4 = require$$0__default$1;
1361
+ const io = io$2;
1341
1362
  const {
1342
- resolve: resolve$5
1363
+ resolve: resolve$5,
1364
+ createTask: createTask$1
1343
1365
  } = widgets;
1344
1366
  const {
1345
1367
  buildOutputAppJson
1346
1368
  } = buildAppJson;
1369
+ const {
1370
+ MODULE_CODE_DIR,
1371
+ DEFAULT_COPY_CONFIG,
1372
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$1
1373
+ } = require$$3;
1374
+ const {
1375
+ cloneModules
1376
+ } = cloneModules_1;
1347
1377
  const {
1348
1378
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
1349
1379
  } = tkitUtils;
1350
- const {
1351
- findAllPackageJson
1352
- } = npmUtils;
1353
1380
  const {
1354
1381
  fail: fail$4
1355
1382
  } = log$2;
1356
- const replaceExt = require$$7__default;
1357
- const extensions = ['.ts', '.js'];
1358
-
1359
- function ext(entry, extensions) {
1360
- let newEntry = entry;
1361
-
1362
- try {
1363
- const stat = fs$2.lstatSync(newEntry);
1383
+ const install$1 = install_1;
1384
+ /**
1385
+ * 拷贝相关配置文件到编译输出目录
1386
+ * @param { object } tmsConfig
1387
+ * @param { array } modules
1388
+ * @param { array } defaultFiles 默认需要拷贝的配置项
1389
+ * @returns
1390
+ */
1364
1391
 
1365
- if (stat.isDirectory()) {
1366
- newEntry += newEntry[newEntry.length - 1] === '/' ? 'index' : '/index';
1392
+ const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1393
+ const outputDir = resolve$5(tmsConfig.gulp.outputDir);
1394
+ io.ensureDirExist(outputDir);
1395
+ defaultFiles.forEach(item => {
1396
+ if (fs$4.existsSync(resolve$5(item))) {
1397
+ shelljs$3.cp('-rf', resolve$5(item), resolve$5(tmsConfig.gulp.outputDir, item));
1367
1398
  }
1368
- } catch (e) {}
1399
+ }); // 拷贝模块的package.json到编译输出目录
1369
1400
 
1370
- for (const ext of extensions) {
1371
- const file = replaceExt(newEntry, ext);
1401
+ targetModules.forEach(item => {
1402
+ const outputModuleDir = resolve$5(`${tmsConfig.gulp.outputDir}/${item.root}`);
1372
1403
 
1373
- if (fs$2.existsSync(file)) {
1374
- return {
1375
- file,
1376
- ext
1377
- };
1404
+ if (!fs$4.existsSync(resolve$5(item.path))) {
1405
+ fail$4(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1406
+ process.exit(1);
1378
1407
  }
1379
- }
1380
-
1381
- return null;
1382
- } // 获取所有的package.json里的依赖包Dir
1383
1408
 
1384
-
1385
- function getAlias$1(modules) {
1386
- const alias = {};
1387
- const allPackages = findAllPackageJson(modules, resolve$5('./dist'));
1388
- allPackages.forEach(packageFilePath => {
1389
- const {
1390
- dependencies
1391
- } = require(packageFilePath);
1392
-
1393
- Object.keys(dependencies).forEach(dependence => {
1394
- alias[dependence] = path$2.join(path$2.dirname(packageFilePath), `./miniprogram_npm/${dependence}`);
1395
- });
1409
+ io.ensureDirExist(outputModuleDir);
1410
+ const modulePackagePath = resolve$5(item.path, 'package.json');
1411
+ if (fs$4.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
1396
1412
  });
1397
- return alias;
1398
- } // 根据用户选择的modules,找到module.config.json的配置信息,找到所有的page
1413
+ };
1399
1414
 
1415
+ async function task(tmsConfig, targetModules) {
1416
+ // 下载和移动代码
1417
+ await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$5('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1400
1418
 
1401
- function getPageEntry(modules, tmsConfig, moduleDir) {
1402
- const entry = {}; // tms.config.js的modules 合并 module.config.json的配置项
1419
+ const newModules = tmsModulesMergeLocalModuleCfg$1(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$1);
1420
+ console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
1403
1421
 
1404
- const newModules = tmsModulesMergeLocalModuleCfg$1(modules, tmsConfig.appName, moduleDir);
1405
- newModules.forEach(({
1406
- path: relativePath,
1407
- pages,
1408
- root
1409
- }) => {
1410
- pages.forEach(page => {
1411
- const pageJsonPath = `${resolve$5(relativePath, page)}.json`;
1422
+ await createTask$1(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
1412
1423
 
1413
- if (fs$2.existsSync(pageJsonPath)) {
1414
- const pageJsonContent = JSON.parse(fs$2.readFileSync(pageJsonPath, 'utf-8'));
1415
- const pageDir = path$2.dirname(pageJsonPath); // 该页面所在的目录
1424
+ await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
1416
1425
 
1417
- const extValue = ext(resolve$5(relativePath, page), extensions);
1426
+ await createTask$1(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
1427
+ return newModules;
1428
+ }
1418
1429
 
1419
- if (!extValue) {
1420
- fail$4(`当前${page}找不到入口.js或.ts文件`);
1421
- process.exit(1);
1422
- }
1430
+ async function bootstrap(tmsConfig, targetModules) {
1431
+ const newModules = await task(tmsConfig, targetModules);
1432
+ return {
1433
+ targetModules: newModules
1434
+ };
1435
+ }
1423
1436
 
1424
- const entryKey = `${root}/${page}${extValue.ext}`;
1425
- Object.assign(entry, {
1426
- [entryKey]: extValue.file
1427
- }, getComponentEntry(pageJsonContent, pageDir, path$2.dirname(entryKey)));
1428
- }
1429
- });
1430
- });
1431
- return entry;
1432
- } // 根据appJson,获取所有的page
1437
+ var init$5 = bootstrap;
1433
1438
 
1439
+ var dev$3 = {exports: {}};
1434
1440
 
1435
- function getEntry$2(defaultWebpackEntry, modules, tmsConfig, moduleDir) {
1436
- const defaultEntry = {};
1437
- Object.keys(defaultWebpackEntry).forEach(key => {
1438
- const extValue = ext(defaultWebpackEntry[key], extensions);
1439
- defaultEntry[key + extValue.ext] = extValue.file;
1440
- });
1441
- return { ...defaultEntry,
1442
- ...getPageEntry(modules, tmsConfig, moduleDir)
1443
- };
1444
- } // 根据pageJson,filePath,获取页面引入的所有component
1441
+ const through$2 = require$$0__default$7;
1445
1442
 
1443
+ function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
1444
+ const stream = through$2.obj(function (file, enc, cb) {
1445
+ if (file.isBuffer()) {
1446
+ let contents = String(file.contents);
1447
+ let resReg; // eslint-disable-next-line
1446
1448
 
1447
- function getComponentEntry(pageJson, pagePath, pageKey) {
1448
- const componentEntry = {};
1449
+ while ((resReg = reg.exec(contents)) !== null) {
1450
+ const [reg1, reg2, reg3] = resReg;
1449
1451
 
1450
- function task(json, dir, rootKey) {
1451
- if (!json.usingComponents) {
1452
- return;
1453
- }
1452
+ if (reg1 && reg2 && reg3) {
1453
+ const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
1454
+ contents = contents.replace(reg1, value);
1455
+ } else if (reg1 && !reg2 && !reg3) {
1456
+ contents = contents.replace(reg1, JSON.stringify(envData));
1457
+ }
1458
+ } // eslint-disable-next-line
1454
1459
 
1455
- const componentKeys = Object.keys(json.usingComponents); // 如果存在依赖的组件
1456
1460
 
1457
- componentKeys.forEach(key => {
1458
- if (json.usingComponents[key].startsWith('.')) {
1459
- // 拼出组件所在位置的绝对路径
1460
- const comValue = path$2.join(dir, json.usingComponents[key]);
1461
- const extValue = ext(comValue, extensions);
1462
- const comKey = path$2.resolve('/', rootKey, json.usingComponents[key]);
1461
+ file.contents = new Buffer(contents);
1462
+ }
1463
1463
 
1464
- if (!extValue) {
1465
- fail$4(`当前page: ${pagePath} component: ${comValue}找不到入口.js或.ts文件`);
1466
- process.exit(1);
1467
- }
1464
+ this.push(file);
1465
+ cb();
1466
+ });
1467
+ return stream;
1468
+ }
1468
1469
 
1469
- componentEntry[`${comKey.slice(1)}${extValue.ext}`] = extValue.file;
1470
- const comJsonPath = `${comValue}.json`;
1470
+ var replaceEnv_1 = replaceEnv$1;
1471
1471
 
1472
- if (fs$2.existsSync(comJsonPath)) {
1473
- const comJsonContent = JSON.parse(fs$2.readFileSync(comJsonPath, 'utf-8'));
1474
- const comDir = path$2.dirname(comJsonPath); // 该页面所在的目录
1472
+ const through$1 = require$$0__default$7;
1473
+ const precinct = require$$1__default$4;
1474
+ const path$2 = require$$1__default$1;
1475
+ const {
1476
+ copyFile: copyFile$1,
1477
+ ext: ext$1,
1478
+ fileInDir: fileInDir$1
1479
+ } = io$2;
1480
+ const {
1481
+ resolve: resolve$4
1482
+ } = widgets;
1483
+ const fs$3 = require$$0__default$1;
1484
+ const {
1485
+ fail: fail$3
1486
+ } = log$2;
1475
1487
 
1476
- task(comJsonContent, comDir, path$2.dirname(comKey));
1488
+ const dfsFindJsDep$1 = function (anaFileOriginFile, anaFileDestFile, extensions) {
1489
+ const resDep = new Map();
1490
+
1491
+ function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
1492
+ const contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
1493
+ const deps = precinct(contents);
1494
+ deps.forEach(depItem => {
1495
+ if (depItem.startsWith('.')) {
1496
+ // 被依赖文件的存在的绝对路径
1497
+ const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1498
+
1499
+ const depOriginPathExt = ext$1(depOriginPath, extensions);
1500
+
1501
+ if (!depOriginPathExt) {
1502
+ fail$3(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
1503
+ } // 被依赖文件是否存在 include的path中 (只处理include的文件)
1504
+
1505
+
1506
+ if (depOriginPathExt) {
1507
+ const depOriginFile = depOriginPathExt.file;
1508
+ const depDestPath = resolve$4(path$2.dirname(anaFileDestFile), depItem);
1509
+ const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext;
1510
+
1511
+ if (!resDep.has(depDestFile)) {
1512
+ resDep.set(depDestFile, {
1513
+ anaFileOriginFile,
1514
+ anaFileDestFile,
1515
+ depDestFile,
1516
+ depOriginFile
1517
+ });
1518
+ dfs(depOriginFile, depDestFile, extensions);
1519
+ }
1477
1520
  }
1478
1521
  }
1479
1522
  });
1480
1523
  }
1481
1524
 
1482
- task(pageJson, pagePath, pageKey);
1483
- return componentEntry;
1484
- } // 根据modules处理需要拷贝的模块,copy-webpack-plugin需要的参数
1485
-
1525
+ dfs(anaFileOriginFile, anaFileDestFile, extensions);
1526
+ return resDep;
1527
+ };
1486
1528
 
1487
- function getCopyPlugin$2(defaultCopyConfig, modules, tmsConfig, env) {
1488
- const toPath = tmsConfig.webpack.outputDir;
1529
+ function handleCopyFile$1(depDestFile, depOriginFile) {
1530
+ if (fs$3.existsSync(depDestFile)) {
1531
+ const depDestContent = fs$3.readFileSync(depDestFile, 'utf8');
1532
+ const depOriginContent = fs$3.readFileSync(depOriginFile, 'utf8');
1489
1533
 
1490
- function generatorAppJson(tmsConfig, modules) {
1491
- try {
1492
- return buildOutputAppJson(tmsConfig, modules);
1493
- } catch (e) {
1494
- fail$4(`动态生成app.json出现错误${e} 请检查你的配置项`);
1495
- return {};
1534
+ if (depDestContent !== depOriginContent) {
1535
+ console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1536
+ copyFile$1(depOriginFile, depDestFile);
1496
1537
  }
1538
+ } else {
1539
+ console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
1540
+ copyFile$1(depOriginFile, depDestFile);
1497
1541
  }
1542
+ }
1498
1543
 
1499
- const patterns = []; // 默认的一些配置拷贝文件 package.json、sitemap.json等
1500
-
1501
- defaultCopyConfig.forEach(item => {
1502
- if (fs$2.existsSync(resolve$5(item))) {
1503
- patterns.push({
1504
- from: resolve$5(item),
1505
- to: resolve$5(`./${toPath}/${item}`),
1506
- transform: {
1507
- cache: true
1508
- }
1544
+ function jsDep$1(tmsConfig, module, extensions = ['.js', '.ts', '.wxs']) {
1545
+ const stream = through$1.obj(function (file, enc, cb) {
1546
+ // 依赖分析的文件
1547
+ const anaFileOriginFile = file.history[0];
1548
+ const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
1549
+ const anaFileDestFile = resolve$4(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
1550
+
1551
+ if (file.isBuffer()) {
1552
+ let contents = String(file.contents);
1553
+ const deps = precinct(contents);
1554
+ const copyModules = new Map();
1555
+ Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
1556
+ const includePath = tmsConfig.gulp.dependencies[includeName];
1557
+ deps.forEach(depItem => {
1558
+ if (depItem.indexOf(includeName) > -1) {
1559
+ // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
1560
+ const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
1561
+
1562
+ const depOriginPathExt = ext$1(depOriginPath, extensions);
1563
+
1564
+ if (!depOriginPathExt) {
1565
+ fail$3(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
1566
+ }
1567
+
1568
+ const isFileInDir = fileInDir$1(includePath, depOriginPathExt.file);
1569
+
1570
+ if (!isFileInDir) {
1571
+ fail$3(`${depOriginPathExt.file}不在${includePath}不在文件夹内, 请检查应用路径`);
1572
+ } // 被依赖文件是否存在 include的path中 (只处理include的文件)
1573
+
1574
+
1575
+ if (depOriginPathExt && isFileInDir) {
1576
+ // eslint-disable-next-line
1577
+ const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
1578
+ const regRes = depItem.match(reg) || [];
1579
+
1580
+ if (regRes[2]) {
1581
+ const depDestPath = resolve$4(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
1582
+ const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext; // {
1583
+ // depOriginFile: '/Users/odile/workspace/tms-frontend1/miniprogram/thirdparty/libs/timer.js',
1584
+ // depDestFile: `/Users/odile/workspace/tms-frontend1/tools/demo1/dist/modules/
1585
+ // aggredriving/thirdparty/libs/timer.js`,
1586
+ // beforeDepPath: '../../../../thirdparty/libs/timer',
1587
+ // afterDepPath: '../../thirdparty/libs/timer'
1588
+ // }
1589
+
1590
+ if (!copyModules.has(depDestFile)) {
1591
+ copyModules.set(depDestFile, {
1592
+ depOriginFile: depOriginPathExt.file,
1593
+ depDestFile,
1594
+ beforeDepPath: depItem,
1595
+ afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestPath)
1596
+ });
1597
+ }
1598
+ }
1599
+ }
1600
+ }
1601
+ });
1509
1602
  });
1510
- }
1511
- }); // 拷贝模块的代码
1603
+ copyModules.forEach(({
1604
+ depOriginFile,
1605
+ depDestFile,
1606
+ beforeDepPath,
1607
+ afterDepPath
1608
+ }) => {
1609
+ handleCopyFile$1(depDestFile, depOriginFile);
1610
+ contents = contents.replace(beforeDepPath, afterDepPath);
1611
+ const defs = dfsFindJsDep$1(depOriginFile, depDestFile, extensions);
1612
+ defs.forEach(item => {
1613
+ handleCopyFile$1(item.depDestFile, item.depOriginFile);
1614
+ });
1615
+ }); // eslint-disable-next-line
1512
1616
 
1513
- modules.forEach(item => {
1514
- patterns.push({
1515
- from: resolve$5(item.path),
1516
- to: resolve$5(`./${toPath}/${item.root}`),
1517
- globOptions: {
1518
- ignore: ['**/*.js', '*.js', '**/*.ts', '*.ts']
1519
- },
1520
- transform: {
1521
- cache: true,
1522
- transformer: env === 'dev' ? (content, absoluteFrom) => {
1523
- // 监听module.config.json的修改, 自动生成编译后的app.json
1524
- if (absoluteFrom.indexOf('module.config.json') > -1) {
1525
- generatorAppJson(tmsConfig, modules);
1526
- }
1617
+ file.contents = new Buffer(contents);
1618
+ }
1527
1619
 
1528
- return content;
1529
- } : content => content
1530
- }
1531
- });
1620
+ this.push(file);
1621
+ cb();
1532
1622
  });
1623
+ return stream;
1624
+ }
1533
1625
 
1534
- if (env === 'dev') {
1535
- // 拷贝app.json时,自动生成编译后的app.json
1536
- const appJsonConfig = ['app.json'];
1537
- appJsonConfig.forEach(item => {
1538
- patterns.push({
1539
- from: resolve$5(item),
1540
- to: resolve$5(`./${toPath}/${item}`),
1541
- transform: {
1542
- cache: true,
1543
- transformer: () => {
1544
- const appJson = generatorAppJson(tmsConfig, modules);
1545
- return JSON.stringify(appJson, null, 2);
1546
- }
1547
- }
1548
- });
1549
- });
1550
- }
1551
-
1552
- return patterns;
1553
- } // dev时,给webpack注入相应的事件
1626
+ var jsDep_1 = {
1627
+ jsDep: jsDep$1,
1628
+ dfsFindJsDep: dfsFindJsDep$1
1629
+ };
1554
1630
 
1631
+ const through = require$$0__default$7;
1632
+ const path$1 = require$$1__default$1;
1633
+ const {
1634
+ copyFile,
1635
+ ext,
1636
+ fileInDir
1637
+ } = io$2;
1638
+ const {
1639
+ resolve: resolve$3
1640
+ } = widgets;
1641
+ const fs$2 = require$$0__default$1;
1642
+ const {
1643
+ fail: fail$2
1644
+ } = log$2;
1645
+ const {
1646
+ dfsFindJsDep
1647
+ } = jsDep_1;
1555
1648
 
1556
- const setupDevWebPackHooks$1 = (context, firstDone) => {
1557
- let tempFirstDone = true;
1649
+ function handleCopyFile(depDestFile, depOriginFile) {
1650
+ if (fs$2.existsSync(depDestFile)) {
1651
+ const depDestContent = fs$2.readFileSync(depDestFile, 'utf8');
1652
+ const depOriginContent = fs$2.readFileSync(depOriginFile, 'utf8');
1558
1653
 
1559
- const invalid = () => {
1560
- // eslint-disable-next-line
1561
- context.stats = undefined;
1562
- };
1654
+ if (depDestContent !== depOriginContent) {
1655
+ console.log(`json拷贝${depOriginFile}内容到${depDestFile}`);
1656
+ copyFile(depOriginFile, depDestFile);
1657
+ }
1658
+ } else {
1659
+ console.log(`json拷贝${depOriginFile}内容到${depDestFile}`);
1660
+ copyFile(depOriginFile, depDestFile);
1661
+ }
1662
+ }
1563
1663
 
1564
- const done = stats => {
1565
- // eslint-disable-next-line
1566
- context.stats = stats;
1567
- process.nextTick(() => {
1568
- const {
1569
- stats
1570
- } = context;
1571
- if (!stats) return;
1572
-
1573
- if (tempFirstDone) {
1574
- tempFirstDone = false;
1575
- firstDone();
1664
+ function mpJsonDep$1(tmsConfig, module, extensions = ['.wxml'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less']) {
1665
+ const stream = through.obj(function (file, enc, cb) {
1666
+ // 当前分析的文件的路径
1667
+ const anaFileOriginFile = file.history[0];
1668
+ const anaFileRelativeModule = path$1.relative(resolve$3(module.from), anaFileOriginFile);
1669
+ const anaFileDestFile = resolve$3(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
1670
+
1671
+ if (file.isBuffer()) {
1672
+ const copyModules = new Map();
1673
+ let contents = String(file.contents);
1674
+
1675
+ try {
1676
+ contents = JSON.parse(contents);
1677
+
1678
+ if (contents.usingComponents) {
1679
+ Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
1680
+ const includePath = tmsConfig.gulp.dependencies[includeName];
1681
+ Object.keys(contents.usingComponents).forEach(componentKey => {
1682
+ const componentPath = contents.usingComponents[componentKey];
1683
+
1684
+ if (componentPath.indexOf(includeName) > -1) {
1685
+ const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
1686
+
1687
+ const depOriginPathExt = ext(depOriginPath, extensions);
1688
+
1689
+ if (!depOriginPathExt) {
1690
+ fail$2(`${anaFileOriginFile}的${componentPath}引用路径存找不到文件,请检查引用路径`);
1691
+ }
1692
+
1693
+ const isFileInDir = fileInDir(includePath, depOriginPathExt.file);
1694
+
1695
+ if (!isFileInDir) {
1696
+ fail$2(`${depOriginPathExt.file}不在${includePath}不在文件夹内, 请检查应用路径`);
1697
+ }
1698
+
1699
+ if (depOriginPathExt && isFileInDir) {
1700
+ // eslint-disable-next-line
1701
+ const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
1702
+ const regRes = componentPath.match(reg) || [];
1703
+
1704
+ if (regRes[2]) {
1705
+ const depDestPath = resolve$3(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
1706
+ const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext;
1707
+
1708
+ if (!copyModules.has(depDestFile)) {
1709
+ copyModules.set(depDestFile, {
1710
+ depOriginFile: depOriginPathExt.file,
1711
+ depOriginExt: depOriginPathExt.ext,
1712
+ depDestFile,
1713
+ beforeDepPath: componentPath,
1714
+ afterDepPath: path$1.relative(path$1.dirname(anaFileDestFile), depDestPath)
1715
+ });
1716
+ }
1717
+ }
1718
+ }
1719
+ }
1720
+ });
1721
+ });
1722
+ }
1723
+ } catch (e) {
1724
+ fail$2(`解析jsonDep出现错误:${e}`);
1576
1725
  }
1577
- });
1578
- };
1579
1726
 
1580
- const {
1581
- compiler
1582
- } = context;
1583
- compiler.hooks.watchRun.tap('miniprogram-dev', invalid);
1584
- compiler.hooks.invalid.tap('miniprogram-dev', invalid);
1585
- compiler.hooks.done.tap('miniprogram-dev', done);
1586
- };
1727
+ copyModules.forEach(({
1728
+ depOriginFile,
1729
+ depOriginExt,
1730
+ depDestFile,
1731
+ beforeDepPath,
1732
+ afterDepPath
1733
+ }) => {
1734
+ filesExt.forEach(extKey => {
1735
+ const originFile = depOriginFile.replace(depOriginExt, extKey);
1736
+ const destFile = depDestFile.replace(depOriginExt, extKey);
1737
+
1738
+ if (fs$2.existsSync(originFile)) {
1739
+ handleCopyFile(destFile, originFile);
1740
+ const jsExtensions = ['.js', '.ts'];
1741
+
1742
+ if (jsExtensions.indexOf(extKey) > -1) {
1743
+ const defs = dfsFindJsDep(originFile, destFile, jsExtensions);
1744
+ defs.forEach(item => {
1745
+ handleCopyFile(item.depDestFile, item.depOriginFile);
1746
+ });
1747
+ }
1748
+ }
1749
+ });
1750
+ contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
1751
+ contents = contents.replace(beforeDepPath, afterDepPath);
1752
+ });
1753
+ contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents; // eslint-disable-next-line
1587
1754
 
1588
- const stringified$1 = raw => ({
1589
- 'process.env': Object.keys(raw).reduce((env, key) => {
1590
- // eslint-disable-next-line
1591
- env[key] = JSON.stringify(raw[key]);
1592
- return env;
1593
- }, {})
1594
- });
1755
+ file.contents = new Buffer(contents);
1756
+ }
1757
+
1758
+ this.push(file);
1759
+ cb();
1760
+ });
1761
+ return stream;
1762
+ }
1595
1763
 
1596
- var utils = {
1597
- getCopyPlugin: getCopyPlugin$2,
1598
- setupDevWebPackHooks: setupDevWebPackHooks$1,
1599
- getEntry: getEntry$2,
1600
- stringified: stringified$1,
1601
- getAlias: getAlias$1
1764
+ var mpJsonDep_1 = {
1765
+ mpJsonDep: mpJsonDep$1
1602
1766
  };
1603
1767
 
1604
- const WebpackChain = require$$0__default$8;
1605
- const webpack$2 = require$$0__default$9;
1606
1768
  const {
1607
- getEntry: getEntry$1,
1608
- stringified,
1609
- getAlias
1610
- } = utils;
1769
+ src: src$1,
1770
+ dest
1771
+ } = require$$0__default$8;
1772
+ const px2rpx = require$$1__default$5;
1773
+ const less = require$$2__default$1;
1774
+ const rename = require$$3__default$1;
1775
+ const watch = require$$4__default;
1776
+ const image = require$$5__default$1;
1777
+ const replaceEnv = replaceEnv_1;
1611
1778
  const {
1612
- resolve: resolve$4
1613
- } = widgets;
1779
+ jsDep
1780
+ } = jsDep_1;
1614
1781
  const {
1615
- DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY$1,
1616
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$2
1617
- } = require$$3;
1782
+ mpJsonDep
1783
+ } = mpJsonDep_1;
1784
+
1785
+ var compile = function (tmsConfig, {
1786
+ glob,
1787
+ destPath,
1788
+ srcOption,
1789
+ module,
1790
+ watchOption = {
1791
+ events: ['change', 'add', 'unlink']
1792
+ },
1793
+ isWatch
1794
+ }) {
1795
+ Object.keys(glob).forEach(globKey => {
1796
+ const globValue = glob[globKey];
1797
+ let srcPipe = src$1(globValue, srcOption);
1618
1798
 
1619
- var base = (tmsConfig, modules) => {
1620
- const {
1621
- envData = {},
1622
- webpack: tmsWebpack
1623
- } = tmsConfig;
1624
- let webpackConfig = new WebpackChain();
1625
- const alias = getAlias(modules);
1626
- const entry = getEntry$1(DEFAULT_WEBPACK_ENTRY$1, modules, tmsConfig, DEFAULT_MODULE_DIR$2);
1627
- webpackConfig.merge({
1628
- entry,
1629
- output: {
1630
- path: resolve$4(`./${tmsWebpack.outputDir}`),
1631
- libraryTarget: 'commonjs2',
1632
- filename: '[name]'
1633
- },
1634
- // TODO 有报错,先注释掉
1635
- // cache: {
1636
- // type: 'filesystem',
1637
- // cacheDirectory: resolve(`./${tmsConfig.webpack.outputDir}/node_modules/.cache`),
1638
- // },
1639
- resolve: {
1640
- extensions: ['.tsx', '.ts', '.js'],
1641
- alias: Object.assign(tmsWebpack.alias, alias)
1642
- },
1643
- devtool: tmsWebpack.sourceMap ? 'source-map' : false
1644
- });
1645
- webpackConfig.module.rule('ts-loader').test(/\.ts$/).use('ts-loader').loader(require.resolve('ts-loader')).options({
1646
- configFile: resolve$4('./tsconfig.json'),
1647
- // 只进行语法转换,不进行类型校验,提高构建速度
1648
- transpileOnly: true
1649
- }).end(); // webpackConfig.module
1650
- // .rule('babel')
1651
- // .test(/\.(js|mjs|jsx|ts|tsx)$/)
1652
- // .pre()
1653
- // .exclude.add(/(node_modules|miniprogram_npm)/).end()
1654
- // .use(require.resolve('babel-loader'))
1655
- // .loader(require.resolve('babel-loader'));
1656
-
1657
- webpackConfig.plugin('definePlugin').use(webpack$2.DefinePlugin, [stringified(envData)]).end(); // 执行tms.config.js自定义的webpackChain
1658
-
1659
- if (tmsWebpack.webpackChain) {
1660
- webpackConfig = tmsWebpack.webpackChain(webpackConfig, {
1661
- modules
1662
- });
1663
- }
1799
+ if (isWatch) {
1800
+ srcPipe = srcPipe.pipe(watch(globValue, watchOption));
1801
+ }
1664
1802
 
1665
- return webpackConfig;
1803
+ switch (globKey) {
1804
+ case 'js':
1805
+ srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(jsDep(tmsConfig, module)).pipe(dest(destPath));
1806
+ break;
1807
+
1808
+ case 'css':
1809
+ srcPipe.pipe(less()).pipe(px2rpx({
1810
+ designWidth: 375,
1811
+ // 设计稿宽度,默认为750
1812
+ precision: 2 // 小数最大精度,默认为6
1813
+
1814
+ })).pipe(rename({
1815
+ extname: '.wxss'
1816
+ })).pipe(dest(destPath));
1817
+ break;
1818
+
1819
+ case 'json':
1820
+ srcPipe.pipe(mpJsonDep(tmsConfig, module)).pipe(dest(destPath));
1821
+ break;
1822
+
1823
+ case 'html':
1824
+ srcPipe.pipe(dest(destPath));
1825
+ break;
1826
+
1827
+ case 'image':
1828
+ srcPipe.pipe(image()).pipe(dest(destPath));
1829
+ break;
1830
+
1831
+ case 'other':
1832
+ srcPipe.pipe(dest(destPath));
1833
+ break;
1834
+ }
1835
+ });
1666
1836
  };
1667
1837
 
1668
- const SingleEntryPlugin = require$$0__default$a;
1669
- const {
1670
- DEFAULT_WEBPACK_ENTRY,
1671
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$1
1672
- } = require$$3;
1673
- const {
1674
- getEntry
1675
- } = utils;
1676
-
1677
- class EntryExtraPlugin {
1678
- constructor(options = {}) {
1679
- this.options = options;
1680
- }
1838
+ (function (module) {
1839
+ const watch = require$$4__default;
1840
+ const {
1841
+ resolve
1842
+ } = widgets;
1843
+ const {
1844
+ buildOutputAppJson
1845
+ } = buildAppJson;
1846
+ const {
1847
+ DEFAULT_COPY_CONFIG
1848
+ } = require$$3;
1849
+ const compile$1 = compile;
1850
+
1851
+ function handleOtherGlob(glob) {
1852
+ const otherArr = new Set();
1853
+ Object.keys(glob).forEach(globKey => {
1854
+ if (typeof glob[globKey] === 'string') {
1855
+ const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
1856
+ otherArr.add(data);
1857
+ }
1681
1858
 
1682
- applyEntry(compiler, entry) {
1683
- const {
1684
- context
1685
- } = compiler.options;
1686
- Object.keys(entry).forEach(key => {
1687
- new SingleEntryPlugin(context, entry[key], key).apply(compiler);
1859
+ if (Array.isArray(glob[globKey])) {
1860
+ glob[globKey].forEach(value => {
1861
+ if (typeof value === 'string') {
1862
+ const data = value.startsWith('!') ? value : `!${value}`;
1863
+ otherArr.add(data);
1864
+ }
1865
+ });
1866
+ }
1688
1867
  });
1868
+ return Array.from(otherArr);
1689
1869
  }
1690
1870
 
1691
- apply(compiler) {
1692
- const {
1693
- tmsConfig = {},
1694
- modules = []
1695
- } = this.options;
1696
- compiler.hooks.watchRun.tap('EntryExtraPlugin', () => {
1697
- const entry = getEntry(DEFAULT_WEBPACK_ENTRY, modules, tmsConfig, DEFAULT_MODULE_DIR$1);
1698
- this.applyEntry(compiler, entry);
1699
- });
1700
- }
1871
+ module.exports = async (tmsConfig, newModules, isWatch = true) => {
1872
+ var _tmsConfig$gulp, _tmsConfig$gulp2;
1701
1873
 
1702
- }
1874
+ // 监听app.json
1875
+ if (isWatch) {
1876
+ watch(resolve('app.json'), {
1877
+ ignoreInitial: false,
1878
+ events: ['add', 'change']
1879
+ }, () => {
1880
+ buildOutputAppJson(tmsConfig, newModules);
1881
+ });
1882
+ } else {
1883
+ buildOutputAppJson(tmsConfig, newModules);
1884
+ } // 监听根目录的文件
1703
1885
 
1704
- var entryExtractPlugin = EntryExtraPlugin;
1705
1886
 
1706
- const webpackConfig$1 = base;
1707
- const {
1708
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
1709
- } = require$$3;
1710
- const {
1711
- getCopyPlugin: getCopyPlugin$1
1712
- } = utils;
1713
-
1714
- var dev$2 = (...args) => {
1715
- const [tmsConfig, modules] = args;
1716
- const webpackDevConfig = webpackConfig$1(...args);
1717
- webpackDevConfig.devtool('source-map');
1718
- webpackDevConfig.mode('development');
1719
- const copyPluginParams = getCopyPlugin$1(DEFAULT_COPY_CONFIG$1, modules, tmsConfig, 'dev'); // console.log('copyPluginParams', copyPluginParams);
1720
-
1721
- webpackDevConfig.plugin('copy-webpack-plugin').use(require$$3__default, [{
1722
- patterns: copyPluginParams
1723
- }]).end();
1724
- webpackDevConfig.plugin('ExtractPlugin').use(entryExtractPlugin, [{
1725
- tmsConfig,
1726
- modules
1727
- }]).end();
1728
- return webpackDevConfig;
1729
- };
1887
+ compile$1(tmsConfig, {
1888
+ glob: {
1889
+ json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
1890
+ css: ['app.less', 'app.wxss'].map(item => resolve(item)),
1891
+ js: ['app.js', 'app.ts'].map(item => resolve(item))
1892
+ },
1893
+ module: {
1894
+ from: '',
1895
+ to: ''
1896
+ },
1897
+ destPath: resolve(tmsConfig.gulp.outputDir),
1898
+ srcOption: {
1899
+ allowEmpty: true
1900
+ },
1901
+ isWatch
1902
+ }); // 监听模块的文件
1903
+
1904
+ for (let module of newModules) {
1905
+ // 处理默认参数
1906
+ module = { ...{
1907
+ exclude: []
1908
+ },
1909
+ ...module
1910
+ };
1730
1911
 
1731
- const webpack$1 = require$$0__default$9;
1732
- const webDevConfig = dev$2;
1733
- const {
1734
- setupDevWebPackHooks
1735
- } = utils;
1736
- const {
1737
- fail: fail$3
1738
- } = log$2;
1912
+ if (isWatch) {
1913
+ // 监听模块配置文件
1914
+ watch(`${resolve(module.path)}/**/module.config.json`, {
1915
+ events: ['change']
1916
+ }, () => {
1917
+ buildOutputAppJson(tmsConfig, newModules);
1918
+ });
1919
+ }
1920
+
1921
+ const excludes = module.exclude.map(key => `!${resolve(key)}`);
1922
+ const glob = {
1923
+ js: [`${resolve(module.path)}/**/*.{js,ts,wxs}`, ...excludes],
1924
+ json: [`${resolve(module.path)}/**/*.json`, ...excludes],
1925
+ css: [`${resolve(module.path)}/**/*.{less,wxss}`, ...excludes],
1926
+ html: [`${resolve(module.path)}/**/*.wxml`, ...excludes],
1927
+ image: [`${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
1928
+ };
1929
+ compile$1(tmsConfig, {
1930
+ glob: { ...glob,
1931
+ other: [`${resolve(module.path)}/**/*`, ...handleOtherGlob(glob)]
1932
+ },
1933
+ destPath: resolve(tmsConfig.gulp.outputDir, module.root),
1934
+ module: {
1935
+ from: module.path,
1936
+ to: module.root
1937
+ },
1938
+ srcOption: {
1939
+ allowEmpty: true
1940
+ },
1941
+ isWatch
1942
+ });
1943
+ } // 监听copy模块
1739
1944
 
1740
- var devServer = (...args) => {
1741
- const config = webDevConfig(...args);
1742
- const compiler = webpack$1(config.toConfig());
1743
- setupDevWebPackHooks({
1744
- compiler
1745
- }, () => {// TODO 判断open参数,打开微信开发者工具
1746
- // openDevtool(api.resolve(config.outputDir || 'dist'))
1747
- });
1748
- compiler.watch({
1749
- aggregateTimeout: 1000,
1750
- poll: undefined
1751
- }, (err, stats) => {
1752
- if (err) {
1753
- fail$3(err);
1754
- console.log('详细的错误信息:', err);
1755
- }
1756
1945
 
1757
- if (stats.hasErrors() || stats.hasWarnings()) {
1758
- console.log(stats.toString({
1759
- // 增加控制台颜色开关
1760
- colors: true
1761
- }));
1946
+ if (tmsConfig !== null && tmsConfig !== void 0 && (_tmsConfig$gulp = tmsConfig.gulp) !== null && _tmsConfig$gulp !== void 0 && _tmsConfig$gulp.copy && (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.copy.length) > 0) {
1947
+ for (const item of (_tmsConfig$gulp3 = tmsConfig.gulp) === null || _tmsConfig$gulp3 === void 0 ? void 0 : _tmsConfig$gulp3.copy) {
1948
+ var _tmsConfig$gulp3;
1949
+
1950
+ const glob = {
1951
+ js: `${item.from}/**/*.{js,ts,wxs}`,
1952
+ json: `${item.from}/**/*.json`,
1953
+ css: `${item.from}/**/*.{less,wxss}`,
1954
+ html: `${item.from}/**/*.wxml`,
1955
+ image: `${item.from}/**/*.{png,jpg,jpeg,gif,svg}`
1956
+ };
1957
+ compile$1(tmsConfig, {
1958
+ glob: { ...glob,
1959
+ other: [`${item.from}/**/*`, ...handleOtherGlob(glob)]
1960
+ },
1961
+ destPath: item.to,
1962
+ module: item,
1963
+ srcOption: {
1964
+ allowEmpty: true
1965
+ },
1966
+ isWatch
1967
+ });
1968
+ }
1762
1969
  }
1763
- });
1764
- return compiler;
1765
- };
1970
+ };
1971
+ })(dev$3);
1766
1972
 
1767
1973
  const fs$1 = require$$0__default$1;
1768
- const semver$1 = require$$1__default$4;
1974
+ const semver$1 = require$$1__default$6;
1769
1975
  const {
1770
- resolve: resolve$3
1976
+ resolve: resolve$2
1771
1977
  } = widgets;
1772
- const path$1 = require$$1__default$1;
1978
+ const path = require$$1__default$1;
1773
1979
  const {
1774
- fail: fail$2
1980
+ fail: fail$1
1775
1981
  } = log$2;
1776
- const shelljs$2 = require$$0__default$2;
1982
+ const shelljs$2 = require$$5__default;
1777
1983
 
1778
1984
  const getLatestVersion = npmName => {
1779
1985
  const data = shelljs$2.exec(`npm view ${npmName} version`);
@@ -1794,17 +2000,17 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
1794
2000
  // 1.1根目录的package.json
1795
2001
 
1796
2002
  const packageArr = [{
1797
- srcPackageDir: path$1.join(cwd, packageJsonName),
1798
- destNpmDir: resolve$3(outputDir, 'node_modules')
2003
+ srcPackageDir: path.join(cwd, packageJsonName),
2004
+ destNpmDir: resolve$2(outputDir, 'node_modules')
1799
2005
  }]; // 1.2模块的package.json
1800
2006
 
1801
2007
  modules.forEach(item => {
1802
- const srcPackageDir = path$1.join(cwd, item.path, 'package.json');
2008
+ const srcPackageDir = path.join(cwd, item.path, 'package.json');
1803
2009
 
1804
2010
  if (fs$1.existsSync(srcPackageDir)) {
1805
2011
  packageArr.push({
1806
2012
  srcPackageDir,
1807
- destNpmDir: resolve$3(outputDir, item.root, 'node_modules')
2013
+ destNpmDir: resolve$2(outputDir, item.root, 'node_modules')
1808
2014
  });
1809
2015
  }
1810
2016
  }); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
@@ -1816,20 +2022,20 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
1816
2022
  try {
1817
2023
  dependencies = JSON.parse(packageJson).dependencies;
1818
2024
  } catch (e) {
1819
- fail$2(`解析${packageJson}报错,请检查是否是正确的json配置项`);
2025
+ fail$1(`解析${packageJson}报错,请检查是否是正确的json配置项`);
1820
2026
  process.exit(1);
1821
2027
  }
1822
2028
 
1823
2029
  const dependenciesKeys = Object.keys(dependencies);
1824
2030
 
1825
2031
  for (const key of dependenciesKeys) {
1826
- const depPath = path$1.join(item.destNpmDir, key);
2032
+ const depPath = path.join(item.destNpmDir, key);
1827
2033
 
1828
2034
  if (!fs$1.existsSync(depPath)) {
1829
2035
  return true;
1830
2036
  }
1831
2037
 
1832
- const depPackagePath = path$1.join(depPath, 'package.json');
2038
+ const depPackagePath = path.join(depPath, 'package.json');
1833
2039
 
1834
2040
  if (fs$1.existsSync(depPackagePath)) {
1835
2041
  const packageData = require(depPackagePath);
@@ -1856,10 +2062,10 @@ var checkDependencies_1 = {
1856
2062
  checkDependencies: checkDependencies$1
1857
2063
  };
1858
2064
 
1859
- const webpackServer = devServer;
2065
+ const gulpDev = dev$3.exports;
1860
2066
  const fs = require$$0__default$1;
1861
2067
  const {
1862
- resolve: resolve$2
2068
+ resolve: resolve$1
1863
2069
  } = widgets;
1864
2070
  const init$4 = init$5;
1865
2071
  const {
@@ -1872,7 +2078,7 @@ const {
1872
2078
  checkDependencies
1873
2079
  } = checkDependencies_1;
1874
2080
  const {
1875
- fail: fail$1
2081
+ fail
1876
2082
  } = log$2;
1877
2083
 
1878
2084
  function isInit(tmsConfig, targetModules, contextDir) {
@@ -1909,162 +2115,64 @@ function isInit(tmsConfig, targetModules, contextDir) {
1909
2115
  } // 判断源码目录是否有该模块
1910
2116
 
1911
2117
 
1912
- if (item.path && !fs.existsSync(resolve$2(item.path))) {
1913
- fail$1(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
2118
+ if (item.path && !fs.existsSync(resolve$1(item.path))) {
2119
+ fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1914
2120
  process.exit(1);
1915
2121
  }
1916
2122
  } // 判断package.json的版本是否有新的版本
1917
2123
 
1918
2124
 
1919
- return checkDependencies(targetModules, resolve$2('./'), tmsConfig.webpack.outputDir);
2125
+ return checkDependencies(targetModules, resolve$1('./'), tmsConfig.gulp.outputDir);
1920
2126
  }
1921
2127
 
1922
- async function dev$1(tmsConfig, targetModules, env) {
2128
+ async function dev$2(tmsConfig, targetModules, env) {
1923
2129
  // tms.config.js的modules 合并 module.config.json的配置项
1924
2130
  let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR); // 判断是否进行init命令
1925
2131
 
1926
- if (isInit(tmsConfig, newModules, resolve$2('dist'))) {
2132
+ if (isInit(tmsConfig, newModules, resolve$1('dist'))) {
1927
2133
  // init函数会将 最新的tms.config.js的modules 合并 module.config.json的配置项 返回,不需要再做重复工作
1928
2134
  const initData = await init$4(tmsConfig, targetModules);
1929
2135
  newModules = initData.targetModules;
1930
2136
  }
1931
2137
 
1932
2138
  console.log('当前dev启动的有效模块', newModules.map(item => item.name));
1933
- webpackServer(tmsConfig, newModules, env);
1934
- }
1935
-
1936
- var dev_1 = dev$1;
1937
-
1938
- const webpackConfig = base;
1939
- const {
1940
- DEFAULT_COPY_CONFIG
1941
- } = require$$3;
1942
- const {
1943
- getCopyPlugin
1944
- } = utils;
1945
-
1946
- var build$2 = (...args) => {
1947
- const [tmsConfig, modules] = args;
1948
- const webpackBuildConfig = webpackConfig(...args);
1949
- webpackBuildConfig.mode('production');
1950
- const copyPluginParams = getCopyPlugin(DEFAULT_COPY_CONFIG, modules, tmsConfig, 'build'); // console.log('copyPluginParams', copyPluginParams);
1951
-
1952
- webpackBuildConfig.plugin('copy-webpack-plugin').use(require$$3__default, [{
1953
- patterns: copyPluginParams
1954
- }]).end();
1955
- return webpackBuildConfig;
1956
- };
1957
-
1958
- const webpack = require$$0__default$9;
1959
- const webBuildConfig = build$2;
1960
- const {
1961
- createTask: createTask$2
1962
- } = widgets;
1963
- const {
1964
- fail
1965
- } = log$2;
1966
-
1967
- function compilerRun(compiler) {
1968
- return new Promise(resolve => {
1969
- compiler.run((err, stats) => {
1970
- resolve({
1971
- err,
1972
- stats
1973
- });
1974
- });
1975
- });
2139
+ gulpDev(tmsConfig, newModules, env);
1976
2140
  }
1977
2141
 
1978
- var buildServer = async (...args) => {
1979
- const config = webBuildConfig(...args);
1980
- const compiler = webpack(config.toConfig());
1981
- const {
1982
- err,
1983
- stats
1984
- } = await createTask$2(compilerRun, '开始webpack打包编译', 'webpack打包编译完成')(compiler);
2142
+ var dev_1 = dev$2;
1985
2143
 
1986
- if (err) {
1987
- fail(err);
1988
- console.log('详细的错误信息:', err);
1989
- }
2144
+ const shelljs$1 = require$$5__default;
2145
+ const dev$1 = dev$3.exports;
1990
2146
 
1991
- if (stats.hasErrors() || stats.hasWarnings()) {
1992
- console.log(stats.toString({
1993
- // 增加控制台颜色开关
1994
- colors: true,
1995
- errorDetails: true
1996
- }));
1997
- }
1998
- return compiler;
2147
+ var build$2 = async (tmsConfig, newModules) => {
2148
+ shelljs$1.rm('-rf', tmsConfig.gulp.outputDir);
2149
+ dev$1(tmsConfig, newModules, false);
1999
2150
  };
2000
2151
 
2001
- const shelljs$1 = require$$0__default$2;
2002
- const webpackBuildServer = buildServer;
2152
+ const shelljs = require$$5__default;
2003
2153
  const {
2004
- resolve: resolve$1
2154
+ resolve
2005
2155
  } = widgets;
2006
2156
  const init$3 = init$5;
2157
+ const gulpBuild = build$2;
2007
2158
 
2008
2159
  async function build$1(tmsConfig, targetModules, env) {
2009
2160
  // 开始构建前,清理输出目录
2010
- await shelljs$1.rm('-rf', resolve$1('dist'));
2161
+ await shelljs.rm('-rf', resolve(tmsConfig.gulp.outputDir));
2011
2162
  const {
2012
2163
  targetModules: newModules
2013
2164
  } = await init$3(tmsConfig, targetModules);
2014
- webpackBuildServer(tmsConfig, newModules, env);
2165
+ gulpBuild(tmsConfig, newModules, env);
2015
2166
  }
2016
2167
 
2017
2168
  var build_1 = build$1;
2018
2169
 
2019
- const shelljs = require$$0__default$2;
2020
- const {
2021
- createTask: createTask$1
2022
- } = widgets;
2023
- const {
2024
- buildMpNpm
2025
- } = mpCiUtils;
2026
- const glob = require$$3__default$1;
2027
- const path = require$$1__default$1;
2028
-
2029
- function npmInstall(contextDir) {
2030
- return new Promise((resolve, reject) => {
2031
- glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
2032
- if (err) {
2033
- reject(err);
2034
- }
2035
-
2036
- files.forEach(file => {
2037
- const dir = path.dirname(file);
2038
- shelljs.cd(dir);
2039
- shelljs.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
2040
- silent: false
2041
- });
2042
- });
2043
- resolve();
2044
- });
2045
- });
2046
- }
2047
-
2048
- async function install$1(contextDir) {
2049
- // npm install
2050
- await createTask$1(npmInstall, '开始npm install', 'npm install完成')(contextDir); // 构建miniprograme_npm
2051
-
2052
- await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
2053
- appId: 'null',
2054
- projectPath: contextDir,
2055
- privateKey: 'null'
2056
- });
2057
- }
2058
-
2059
- var install_1 = install$1;
2060
-
2061
2170
  const init$2 = init$5;
2062
2171
  const dev = dev_1;
2063
2172
  const build = build_1;
2064
2173
  const install = install_1;
2065
2174
  const {
2066
- createTask,
2067
- resolve
2175
+ createTask
2068
2176
  } = widgets;
2069
2177
  const {
2070
2178
  MODE
@@ -2081,8 +2189,13 @@ const handleModulesArg = cmd => {
2081
2189
  } // 单模块 或 多模块开发
2082
2190
 
2083
2191
 
2192
+ const {
2193
+ argv
2194
+ } = process;
2195
+ const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
2196
+
2084
2197
  if (cmd.module) {
2085
- return [cmd.module, ...cmd.args];
2198
+ return [cmd.module, ...reset];
2086
2199
  } // 全量模块
2087
2200
 
2088
2201
 
@@ -2090,11 +2203,6 @@ const handleModulesArg = cmd => {
2090
2203
  };
2091
2204
 
2092
2205
  async function run(commandName, cmd) {
2093
- if (commandName === 'install') {
2094
- install(resolve('./'));
2095
- return;
2096
- }
2097
-
2098
2206
  const moduleArg = handleModulesArg(cmd);
2099
2207
  const {
2100
2208
  env
@@ -2121,6 +2229,10 @@ async function run(commandName, cmd) {
2121
2229
  dev(tmsConfig, modules, env);
2122
2230
  return;
2123
2231
 
2232
+ case 'install':
2233
+ install(tmsConfig, modules, env);
2234
+ return;
2235
+
2124
2236
  case 'build':
2125
2237
  build(tmsConfig, modules, env);
2126
2238
  return;
@@ -2139,17 +2251,43 @@ var entry = [{
2139
2251
  create_1(appName, cmd);
2140
2252
  }
2141
2253
  }, {
2142
- command: 'run <command-name>',
2143
- options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
2144
- description: '运行模块',
2145
- action: (commandName, cmd) => {
2146
- run_1(commandName, cmd);
2147
- }
2254
+ name: 'run',
2255
+ type: 'child',
2256
+ description: '项目开发使用的命令',
2257
+ commands: [{
2258
+ command: 'install',
2259
+ description: '安装依赖',
2260
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
2261
+ action: cmd => {
2262
+ run_1('install', cmd);
2263
+ }
2264
+ }, {
2265
+ command: 'dev',
2266
+ description: 'dev 打包编译',
2267
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
2268
+ action: cmd => {
2269
+ run_1('dev', cmd);
2270
+ }
2271
+ }, {
2272
+ command: 'build',
2273
+ description: 'prod 打包编译',
2274
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
2275
+ action: cmd => {
2276
+ run_1('build', cmd);
2277
+ }
2278
+ }, {
2279
+ command: 'init',
2280
+ description: '根据模块配置初始化项目(eg: 动态拷贝模块、下载依赖、生成app.json等)',
2281
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
2282
+ action: cmd => {
2283
+ run_1('init', cmd);
2284
+ }
2285
+ }]
2148
2286
  }];
2149
2287
 
2150
2288
  var require$$6 = {
2151
2289
  name: "@tmsfe/tmskit",
2152
- version: "0.0.4",
2290
+ version: "0.0.5-beta.3",
2153
2291
  description: "tmskit",
2154
2292
  main: "main.js",
2155
2293
  bin: {
@@ -2180,37 +2318,39 @@ var require$$6 = {
2180
2318
  dependencies: {
2181
2319
  async: "^3.2.2",
2182
2320
  chalk: "^4.1.0",
2183
- commander: "^6.2.1",
2321
+ commander: "^8.3.0",
2184
2322
  "copy-webpack-plugin": "^9.1.0",
2185
2323
  "download-git-repo": "^3.0.2",
2186
2324
  ejs: "^3.1.5",
2187
2325
  "glob-ignore": "^1.0.2",
2326
+ gulp: "^4.0.2",
2327
+ "gulp-image": "^5.1.0",
2328
+ "gulp-less": "^5.0.0",
2329
+ "gulp-px-to-rpx": "^1.0.7",
2330
+ "gulp-rename": "^2.0.0",
2331
+ "gulp-watch": "^5.0.1",
2188
2332
  inquirer: "^7.3.3",
2189
2333
  leven: "3.1.0",
2190
2334
  lodash: "^4.17.21",
2191
2335
  metalsmith: "^2.3.0",
2192
2336
  "miniprogram-ci": "1.4.13",
2193
2337
  ora: "^5.1.0",
2338
+ precinct: "^8.3.1",
2194
2339
  "replace-ext": "^2.0.0",
2195
2340
  shelljs: "^0.8.4",
2196
- "ts-loader": "^9.2.6",
2197
- webpack: "^5.64.0",
2198
- "webpack-chain": "^6.5.1"
2341
+ through2: "^4.0.2"
2199
2342
  },
2200
2343
  engines: {
2201
- node: "^12.17.0 || >= 14.0.0"
2344
+ node: "^12.17.0 || >= 14.13.1"
2202
2345
  },
2203
2346
  jest: {
2204
2347
  testEnvironment: "jest-environment-node"
2205
2348
  }
2206
2349
  };
2207
2350
 
2208
- const {
2209
- exec
2210
- } = require$$0__default$2;
2211
- const semver = require$$1__default$4;
2351
+ const semver = require$$1__default$6;
2212
2352
  const packageJson = require$$6;
2213
- const chalk$1 = require$$0__default$3;
2353
+ const chalk$1 = require$$0__default$2;
2214
2354
  const {
2215
2355
  log: log$1
2216
2356
  } = widgets;
@@ -2240,17 +2380,13 @@ const checkNodeVersion = (wanted, id) => {
2240
2380
  function initCliContext() {
2241
2381
  // 执行操作前检查node版本
2242
2382
  // 旧版本node直接提示升级,退出脚本
2243
- checkNodeVersion(requiredVersion, packName); // 执行前配置正确的npm源
2244
-
2245
- exec('npm config set registry https://mirrors.tencent.com/npm/ --global', {
2246
- silent: true
2247
- });
2383
+ checkNodeVersion(requiredVersion, packName);
2248
2384
  }
2249
2385
 
2250
2386
  var init$1 = initCliContext;
2251
2387
 
2252
- const chalk = require$$0__default$3;
2253
- const program = require$$0__default;
2388
+ const chalk = require$$0__default$2;
2389
+ const commander = require$$0__default;
2254
2390
  const {
2255
2391
  log,
2256
2392
  suggestCommands
@@ -2261,19 +2397,33 @@ const {
2261
2397
  const commands = entry;
2262
2398
  const init = init$1;
2263
2399
  init();
2264
- program.version(`${TMS_NAME} ${require$$6.version}`);
2265
- commands.forEach(cmd => {
2266
- var _cmd$options;
2267
-
2268
- const command = program.command(cmd.command);
2269
- cmd.usage && command.usage(cmd.usage);
2270
- cmd.description && command.description(cmd.description);
2271
- (_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
2272
- command.action(cmd.action);
2273
- });
2400
+ const program = new commander.Command(TMS_NAME);
2401
+ program.version(`${TMS_NAME} ${require$$6.version}`, '-v, -V, --version');
2402
+
2403
+ function registerCommand(program, commands) {
2404
+ commands.forEach(cmd => {
2405
+ if (cmd.type === 'child') {
2406
+ const childProgram = new commander.Command(cmd.name);
2407
+ cmd.usage && childProgram.usage(cmd.usage);
2408
+ cmd.description && childProgram.description(cmd.description);
2409
+ registerCommand(childProgram, cmd.commands);
2410
+ program.addCommand(childProgram);
2411
+ } else {
2412
+ var _cmd$options;
2413
+
2414
+ const command = program.command(cmd.command);
2415
+ cmd.usage && command.usage(cmd.usage);
2416
+ cmd.description && command.description(cmd.description);
2417
+ (_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
2418
+ command.action(cmd.action);
2419
+ }
2420
+ });
2421
+ }
2422
+
2423
+ registerCommand(program, commands);
2274
2424
  program.on('--help', () => {
2275
2425
  log();
2276
- log(` Run ${chalk.cyan('tms <command> --help')} for detailed usage of given command.`);
2426
+ log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
2277
2427
  log();
2278
2428
  }); // 捕获未注册的命令
2279
2429
 
@@ -2291,6 +2441,6 @@ if (!process.argv.slice(2).length) {
2291
2441
  }
2292
2442
 
2293
2443
  program.parse(process.argv);
2294
- var src = src$1;
2444
+ var src = src$2;
2295
2445
 
2296
2446
  module.exports = src;