@tmsfe/tmskit 0.0.1 → 0.0.5-beta.0

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
@@ -4,21 +4,23 @@ var require$$0 = require('commander');
4
4
  var require$$1 = require('leven');
5
5
  var require$$2 = require('ora');
6
6
  var require$$1$1 = require('path');
7
- var require$$1$2 = require('fs');
7
+ var require$$0$1 = require('fs');
8
8
  var require$$5 = require('shelljs');
9
9
  var require$$6$1 = require('download-git-repo');
10
- var require$$0$1 = require('chalk');
11
- var require$$0$2 = require('async');
12
- var require$$1$3 = require('ejs');
13
- var require$$1$4 = require('inquirer');
14
- var require$$0$3 = require('metalsmith');
15
- var require$$0$4 = require('miniprogram-ci');
10
+ var require$$0$2 = require('chalk');
11
+ var require$$0$3 = require('async');
12
+ var require$$1$2 = require('ejs');
13
+ var require$$1$3 = require('inquirer');
14
+ var require$$0$4 = require('metalsmith');
16
15
  var require$$0$5 = require('lodash');
17
- var require$$7 = require('replace-ext');
18
- var require$$0$6 = require('webpack-chain');
19
- var require$$0$7 = require('webpack');
20
- var require$$0$8 = require('webpack/lib/SingleEntryPlugin');
21
- var require$$3$1 = require('copy-webpack-plugin');
16
+ var require$$0$6 = require('miniprogram-ci');
17
+ var require$$3$1 = require('glob-ignore');
18
+ var require$$0$7 = require('through2');
19
+ var require$$1$4 = require('gulp');
20
+ var require$$2$1 = require('gulp-px-to-rpx');
21
+ var require$$3$2 = require('gulp-less');
22
+ var require$$4 = require('gulp-rename');
23
+ var require$$5$1 = require('gulp-watch');
22
24
  var require$$1$5 = require('semver');
23
25
 
24
26
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
@@ -27,21 +29,23 @@ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
27
29
  var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
28
30
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
29
31
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
30
- var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
32
+ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
31
33
  var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
32
34
  var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
33
- var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
34
35
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
35
- var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
36
- var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
37
36
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
37
+ var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
38
+ var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
38
39
  var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
39
40
  var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
40
- var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
41
41
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
42
- var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
43
- var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
44
42
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
43
+ var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
44
+ var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
45
+ var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
46
+ var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
47
+ var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
48
+ var require$$5__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
45
49
  var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
46
50
 
47
51
  function getAugmentedNamespace(n) {
@@ -64,11 +68,11 @@ var src$1 = {};
64
68
  const program$1 = require$$0__default;
65
69
  const leven = require$$1__default;
66
70
  const ora = require$$2__default;
67
- const path$6 = require$$1__default$1;
68
- const fs$c = require$$1__default$2;
71
+ const path$5 = require$$1__default$1;
72
+ const fs$a = require$$0__default$1;
69
73
  const shelljs$5 = require$$5__default;
70
74
  const download = require$$6__default;
71
- const chalk$3 = require$$0__default$1;
75
+ const chalk$3 = require$$0__default$2;
72
76
  const shelljsOptons = {
73
77
  slient: true
74
78
  }; // 获取当前目录
@@ -76,7 +80,7 @@ const shelljsOptons = {
76
80
  const cwd = process.cwd();
77
81
 
78
82
  function resolve$a(...args) {
79
- return path$6.resolve(cwd, ...args);
83
+ return path$5.resolve(cwd, ...args);
80
84
  }
81
85
  /**
82
86
  * 封装logs
@@ -145,7 +149,7 @@ function downloadRepo(dest, downloadOptions = {
145
149
  branch
146
150
  } = downloadOptions;
147
151
 
148
- if (fs$c.existsSync(dest)) {
152
+ if (fs$a.existsSync(dest)) {
149
153
  shelljs$5.rm('-rf', dest);
150
154
  }
151
155
 
@@ -175,23 +179,17 @@ function downloadRepo(dest, downloadOptions = {
175
179
 
176
180
  function downloadRepoForGit$2(url, dest, branch) {
177
181
  const cwd = process.cwd();
178
- return new Promise((resolve, reject) => {
182
+ return new Promise(resolve => {
179
183
  // 如果目标目录不存在
180
- if (fs$c.existsSync(dest)) {
181
- shelljs$5.rm('-rf', path$6.join(dest));
184
+ if (fs$a.existsSync(dest)) {
185
+ shelljs$5.rm('-rf', path$5.join(dest));
182
186
  }
183
187
 
184
188
  shelljs$5.mkdir('-p', dest);
185
189
  shelljs$5.cd(dest);
186
- shelljs$5.exec(`git clone ${url} ${dest} --depth=1`, shelljsOptons);
187
- shelljs$5.exec(`git checkout ${branch}`, code => {
188
- if (code === 0) {
189
- shelljs$5.cd(cwd);
190
- resolve();
191
- }
192
-
193
- reject();
194
- });
190
+ shelljs$5.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptons);
191
+ shelljs$5.cd(cwd);
192
+ resolve();
195
193
  });
196
194
  }
197
195
  /**
@@ -252,32 +250,32 @@ var widgets = {
252
250
  camelize
253
251
  };
254
252
 
255
- const path$5 = require('path'); // 用户目录
253
+ const path$4 = require('path'); // 用户目录
256
254
 
257
255
 
258
256
  const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
259
257
 
260
- const CACHE_DIR$1 = path$5.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
258
+ const CACHE_DIR$1 = path$4.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
261
259
 
262
- const TEMPLATE_DIR$1 = path$5.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
260
+ const TEMPLATE_DIR$1 = path$4.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
263
261
 
264
- const MODULE_CODE_DIR$1 = path$5.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
262
+ const MODULE_CODE_DIR$1 = path$4.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
265
263
 
266
- const TEMPLATE_PATH$1 = path$5.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
264
+ const TEMPLATE_PATH$1 = path$4.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
267
265
 
268
266
  const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
269
267
 
270
268
  const TMS_CONFIG_FILENAME$1 = 'tms.config.js'; // 模块代码的默认在modules子目录
271
269
 
272
- const DEFAULT_MODULE_DIR$5 = 'modules'; // 模块的配置文件的名称
270
+ const DEFAULT_MODULE_DIR$4 = 'modules'; // 模块的配置文件的名称
273
271
 
274
272
  const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
275
273
 
276
- const DEFAULT_WEBPACK_ENTRY$2 = {
277
- app: path$5.resolve(process.cwd(), 'app')
274
+ const DEFAULT_WEBPACK_ENTRY = {
275
+ app: path$4.resolve(process.cwd(), 'app')
278
276
  }; // 默认从源码拷贝到编译后的配置
279
277
 
280
- const DEFAULT_COPY_CONFIG$3 = ['package.json', 'app.js', 'app.ts', 'app.less', 'app.wxss', 'sitemap.json']; // 开发模式
278
+ const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
281
279
 
282
280
  const MODE$1 = {
283
281
  main: 'tkitmain',
@@ -288,6 +286,7 @@ const ENV = {
288
286
  dev: 'development',
289
287
  prod: 'production'
290
288
  };
289
+ const TEMPLATE_TKIT_DIR$2 = '_tmskit';
291
290
 
292
291
  var constant = /*#__PURE__*/Object.freeze({
293
292
  __proto__: null,
@@ -297,25 +296,26 @@ var constant = /*#__PURE__*/Object.freeze({
297
296
  TEMPLATE_PATH: TEMPLATE_PATH$1,
298
297
  TMS_NAME: TMS_NAME$2,
299
298
  TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
300
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$5,
299
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$4,
301
300
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
302
- DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY$2,
303
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$3,
301
+ DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
302
+ DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
304
303
  MODULE_CODE_DIR: MODULE_CODE_DIR$1,
305
304
  MODE: MODE$1,
306
- ENV: ENV
305
+ ENV: ENV,
306
+ TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2
307
307
  });
308
308
 
309
309
  var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
310
310
 
311
- const fs$b = require$$1__default$2;
311
+ const fs$9 = require$$0__default$1;
312
312
  /**
313
313
  * 判断目录是否为空
314
314
  * @param {string} dirname 目录名
315
315
  * @returns
316
316
  */
317
317
 
318
- const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files.length === 0);
318
+ const isDirEmpty = dirname => fs$9.promises.readdir(dirname).then(files => files.length === 0);
319
319
  /**
320
320
  * 确保目录存在,不存在就创建一个
321
321
  * @param {*} dirname 目录名
@@ -323,8 +323,8 @@ const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files
323
323
 
324
324
 
325
325
  const ensureDirExist = dirname => {
326
- if (!fs$b.existsSync(dirname)) {
327
- fs$b.mkdirSync(dirname, {
326
+ if (!fs$9.existsSync(dirname)) {
327
+ fs$9.mkdirSync(dirname, {
328
328
  recursive: true
329
329
  });
330
330
  }
@@ -335,7 +335,7 @@ var io$2 = {
335
335
  ensureDirExist
336
336
  };
337
337
 
338
- const chalk$2 = require$$0__default$1;
338
+ const chalk$2 = require$$0__default$2;
339
339
  /**
340
340
  * 本文件提供无依赖的在终端打印彩色文字的方法。
341
341
  */
@@ -348,7 +348,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
348
348
  * @returns {undefined} 无
349
349
  */
350
350
 
351
- const fail$a = (message = '') => {
351
+ const fail$7 = (message = '') => {
352
352
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
353
353
 
354
354
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
@@ -381,13 +381,13 @@ const warn = message => {
381
381
  };
382
382
 
383
383
  var log$2 = {
384
- fail: fail$a,
384
+ fail: fail$7,
385
385
  succeed: succeed$1,
386
386
  warn
387
387
  };
388
388
 
389
- const async = require$$0__default$2;
390
- const ejs = require$$1__default$3;
389
+ const async = require$$0__default$3;
390
+ const ejs = require$$1__default$2;
391
391
 
392
392
  const render$1 = (files, metalsmith, next) => {
393
393
  const keys = Object.keys(files);
@@ -406,23 +406,29 @@ const render$1 = (files, metalsmith, next) => {
406
406
 
407
407
  var render_1 = render$1;
408
408
 
409
- const fs$a = require$$1__default$2;
410
- const inquirer = require$$1__default$4;
409
+ const fs$8 = require$$0__default$1;
410
+ const inquirer = require$$1__default$3;
411
+ const {
412
+ resolve: resolve$9
413
+ } = widgets;
414
+ const {
415
+ TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
416
+ } = require$$3;
411
417
  /**
412
418
  * 获取模板内的问题
413
- * @param {string} templateDir 模板目录
419
+ * @param {string} dir questions.json所在的目录
414
420
  * @returns {Array} inquirer 问题数组
415
421
  */
416
422
 
417
- const parseTemplateQuestions = templateDir => {
423
+ const parseTemplateQuestions = dir => {
418
424
  let prompts = [];
419
425
 
420
- if (!fs$a.existsSync(`${templateDir}/questions.json`)) {
426
+ if (!fs$8.existsSync(`${dir}/questions.json`)) {
421
427
  return prompts;
422
428
  }
423
429
 
424
430
  try {
425
- const json = JSON.parse(fs$a.readFileSync(`${templateDir}/questions.json`));
431
+ const json = JSON.parse(fs$8.readFileSync(`${dir}/questions.json`));
426
432
 
427
433
  if (Array.isArray(json) && json.length > 0) {
428
434
  json.forEach((item, index) => {
@@ -455,7 +461,7 @@ const isQuestionType = result => {
455
461
  };
456
462
 
457
463
  const ask$1 = templateDir => (files, metalsmith, next) => {
458
- const prompts = parseTemplateQuestions(templateDir);
464
+ const prompts = parseTemplateQuestions(resolve$9(templateDir, TEMPLATE_TKIT_DIR$1));
459
465
  const metadata = metalsmith.metadata();
460
466
  const filteredPrompts = prompts.filter(prompt => {
461
467
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -480,8 +486,7 @@ var ask_1 = ask$1;
480
486
  const FILES_TO_IGNORE$1 = ['node_modules'];
481
487
  var ignoreFiles = FILES_TO_IGNORE$1;
482
488
 
483
- const Metalsmith = require$$0__default$3;
484
- const fs$9 = require$$1__default$2;
489
+ const Metalsmith = require$$0__default$4;
485
490
  const render = render_1;
486
491
  const ask = ask_1;
487
492
  const FILES_TO_IGNORE = ignoreFiles;
@@ -491,7 +496,6 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
491
496
  if (err) {
492
497
  reject(err);
493
498
  } else {
494
- fs$9.unlinkSync(`${distDir}/questions.json`);
495
499
  resolve('finish');
496
500
  }
497
501
  });
@@ -499,21 +503,22 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
499
503
 
500
504
  var generator_1 = generator$1;
501
505
 
502
- const path$4 = require$$1__default$1;
503
- const fs$8 = require$$1__default$2;
506
+ const path$3 = require$$1__default$1;
507
+ const fs$7 = require$$0__default$1;
504
508
  const shelljs$4 = require$$5__default;
505
509
  const {
506
510
  TEMPLATE_DIR,
507
- TEMPLATE_PATH
511
+ TEMPLATE_PATH,
512
+ TEMPLATE_TKIT_DIR
508
513
  } = require$$3;
509
514
  const {
510
515
  downloadRepoForGit: downloadRepoForGit$1,
511
516
  createTask: createTask$3,
512
- resolve: resolve$9
517
+ resolve: resolve$8
513
518
  } = widgets;
514
519
  const io$1 = io$2;
515
520
  const {
516
- fail: fail$9,
521
+ fail: fail$6,
517
522
  succeed
518
523
  } = log$2;
519
524
  const generator = generator_1;
@@ -525,9 +530,9 @@ const generator = generator_1;
525
530
 
526
531
  async function createAppDir(targetDir) {
527
532
  // 如果目录非空或者已经存在,提示用户,做选择
528
- if (fs$8.existsSync(targetDir)) {
533
+ if (fs$7.existsSync(targetDir)) {
529
534
  if (!(await io$1.isDirEmpty(targetDir))) {
530
- fail$9('该目录名已经存在,换个项目名字吧~');
535
+ fail$6('该目录名已经存在,换个项目名字吧~');
531
536
  process.exit(1);
532
537
  }
533
538
  } else {
@@ -543,42 +548,54 @@ async function createAppDir(targetDir) {
543
548
 
544
549
  async function create(appName) {
545
550
  const cwd = process.cwd();
546
- const targetDir = path$4.resolve(cwd, appName);
551
+ const targetDir = path$3.resolve(cwd, appName);
547
552
  const appType = 'mp';
548
- createAppDir(targetDir); // 创建缓存目录
553
+ await createAppDir(targetDir); // 创建缓存目录
549
554
 
550
555
  io$1.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
551
556
 
552
557
  await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
553
558
 
554
- generator(path$4.join(TEMPLATE_PATH, appType), targetDir, {
559
+ generator(path$3.join(TEMPLATE_PATH, appType), targetDir, {
555
560
  appName,
556
561
  appType
557
562
  }).then(() => {
558
- succeed('项目创建完成,开始初始化...');
559
- shelljs$4.cd(appName); // 初始化构件主包的代码, 让用户打开项目可以跑起来
563
+ shelljs$4.cd(appName);
564
+
565
+ const hooks = require(resolve$8(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
560
566
 
561
- if (fs$8.existsSync(resolve$9(`${appName}/tms.config.js`))) {
562
- shelljs$4.exec('tmskit run build');
567
+ if (hooks.afterCreate) {
568
+ hooks.afterCreate.forEach(item => {
569
+ if (typeof item === 'function') {
570
+ item.call(null, shelljs$4, {
571
+ appName
572
+ });
573
+ } else {
574
+ shelljs$4.exec(item);
575
+ }
576
+ });
563
577
  }
578
+
579
+ shelljs$4.rm('-rf', resolve$8(appName, TEMPLATE_TKIT_DIR));
580
+ succeed('项目创建完成.');
564
581
  }).catch(err => {
565
- fail$9(err.message);
582
+ fail$6(err.message);
566
583
  console.log('详细的错误信息:', err);
567
584
  });
568
585
  }
569
586
 
570
587
  var create_1 = create;
571
588
 
572
- const fs$7 = require$$1__default$2;
589
+ const fs$6 = require$$0__default$1;
573
590
  const {
574
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$4,
591
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3,
575
592
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1
576
593
  } = require$$3;
577
594
  const {
578
- fail: fail$8
595
+ fail: fail$5
579
596
  } = log$2;
580
597
  const {
581
- resolve: resolve$8,
598
+ resolve: resolve$7,
582
599
  isObject: isObject$1,
583
600
  isArray
584
601
  } = widgets;
@@ -627,10 +644,10 @@ function getLocalModuleConfig(modules = [], appName, moduleDir, moduleConfigFile
627
644
  modules.forEach(({
628
645
  path
629
646
  }) => {
630
- const moduleConfigPath = resolve$8(path, moduleConfigFilename);
647
+ const moduleConfigPath = resolve$7(path, moduleConfigFilename);
631
648
 
632
- if (fs$7.existsSync(moduleConfigPath)) {
633
- const content = fs$7.readFileSync(moduleConfigPath, 'utf-8');
649
+ if (fs$6.existsSync(moduleConfigPath)) {
650
+ const content = fs$6.readFileSync(moduleConfigPath, 'utf-8');
634
651
  modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName, moduleDir);
635
652
  }
636
653
  });
@@ -655,7 +672,7 @@ function updateMainPackages(appJson, mainPackages = []) {
655
672
 
656
673
  foundMainPackages.forEach(subpackage => {
657
674
  if (!subpackage.pages || !subpackage.pages.length) {
658
- fail$8(`主包 ${subpackage} 不能没有 pages`);
675
+ fail$5(`主包 ${subpackage} 不能没有 pages`);
659
676
  process.exit(-1);
660
677
  }
661
678
 
@@ -681,12 +698,12 @@ function updateMainPackages(appJson, mainPackages = []) {
681
698
 
682
699
 
683
700
  const getAppJsonContent = sourceAppJsonPath => {
684
- if (!fs$7.existsSync(sourceAppJsonPath)) {
685
- fail$8(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
701
+ if (!fs$6.existsSync(sourceAppJsonPath)) {
702
+ fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
686
703
  process.exit(1);
687
704
  }
688
705
 
689
- const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
706
+ const appJson = JSON.parse(fs$6.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
690
707
 
691
708
  appJson.subpackages = [];
692
709
  appJson.pages = [];
@@ -717,245 +734,22 @@ const updateSubpackages = (appJson, modulesConfig) => {
717
734
  */
718
735
 
719
736
 
720
- function buildOutputAppJson$2(tmsConfig, modules) {
737
+ function buildOutputAppJson$1(tmsConfig, modules) {
721
738
  // 获取当前 modules 下的所有子模块的配置内容
722
- const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$4, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
739
+ const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$3, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
723
740
 
724
- const appJson = getAppJsonContent(resolve$8('./app.json')); // 更新app.json中的subpackages
741
+ const appJson = getAppJsonContent(resolve$7('./app.json')); // 更新app.json中的subpackages
725
742
 
726
743
  updateSubpackages(appJson, modulesConfig); // 更新主包,需在subpackages处理完成后执行, pages/
727
744
 
728
745
  updateMainPackages(appJson, tmsConfig.mainPackages);
729
- fs$7.writeFileSync(resolve$8(`${tmsConfig.webpack.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
746
+ fs$6.writeFileSync(resolve$7(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
730
747
  return appJson;
731
748
  }
732
749
 
733
750
  var buildAppJson = {
734
751
  setModuleConfig: setModuleConfig$1,
735
- buildOutputAppJson: buildOutputAppJson$2
736
- };
737
-
738
- /**
739
- * 本文件主要负责项目或者分包依赖的npm的安装
740
- */
741
- const fs$6 = require$$1__default$2;
742
- const path$3 = require$$1__default$1;
743
- const shell = require$$5__default;
744
- const LOG = log$2;
745
- const dirpath = process.cwd(); // 项目根目录
746
-
747
- const getTarNpmFilename = targetDir => `${targetDir.replaceAll('/', '-')}.tar.gz`; // 缓存npm包
748
-
749
-
750
- const npmCache = function (targetDir, cacheDir) {
751
- if (!fs$6.existsSync(cacheDir)) {
752
- fs$6.mkdirSync(cacheDir);
753
- }
754
-
755
- const tarNpmFilename = getTarNpmFilename(targetDir);
756
- const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
757
-
758
- if (fs$6.existsSync(tarNpmFilePath)) {
759
- shell.rm('-rf', tarNpmFilePath);
760
- }
761
-
762
- const cmd = `tar -zcvf ${tarNpmFilePath} ./node_modules`;
763
- shell.exec(cmd, {
764
- async: true,
765
- silent: true
766
- }); // tar -zcvf /Users/odile/.tmskit/node_modules.tar.gz ./node_modules
767
- }; // 获取缓存npm包
768
-
769
-
770
- const getNpmCache = function (targetDir, cacheDir) {
771
- const tarNpmFilename = getTarNpmFilename(targetDir);
772
- const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
773
-
774
- if (fs$6.existsSync(tarNpmFilePath)) {
775
- const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
776
- shell.exec(cmd, {
777
- async: false,
778
- silent: true
779
- });
780
- } // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
781
-
782
- }; // 遍历安装指定目录下所有项目的npm依赖
783
-
784
-
785
- const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
786
- const packageJsonFiles = await findAllPackageJson$1(modules, contextDir);
787
- await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
788
- const dir = path$3.dirname(file);
789
- shell.cd(dir);
790
-
791
- if (!fs$6.existsSync(`${dir}/node_modules`)) {
792
- getNpmCache(dir, cacheDir);
793
- }
794
-
795
- shell.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
796
- silent: false
797
- });
798
- resolve();
799
- npmCache(dir, cacheDir);
800
- })));
801
- };
802
- /**
803
- * 递归查找指定条件的文件
804
- * @param {String} startPath 开始查找的根路径
805
- * @param {String} filter 匹配的字符串
806
- * @returns {Array<String>} 查找到的文件路径列表
807
- */
808
-
809
-
810
- const findFilesByFilter = (startPath, filter) => {
811
- const result = [];
812
- /**
813
- * 根据指定的筛选器查找文件
814
- * @param {String} startPath 开始查找的文件夹路径
815
- * @param {String} filter 筛选器
816
- * @returns {Undefined} 无需返回值
817
- */
818
-
819
- const find = (startPath, filter) => {
820
- // 目录不存在
821
- if (!fs$6.existsSync(startPath)) {
822
- LOG.fail(`${startPath}目录不存在`);
823
- process.exit(-1);
824
- return;
825
- } // 当前目录下的所有文件 / 文件夹
826
-
827
-
828
- const exceptDir = ['node_modules', 'miniprogram_npm'];
829
-
830
- if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
831
- return;
832
- }
833
-
834
- const files = fs$6.readdirSync(startPath);
835
- files.forEach(file => {
836
- const filename = path$3.join(startPath, file);
837
- const stat = fs$6.lstatSync(filename); // 当前文件是文件夹类型,继续递归
838
-
839
- if (stat.isDirectory()) {
840
- find(filename, filter);
841
- } else if (filename.indexOf(filter) >= 0) {
842
- // 文件类型
843
- result.push(filename);
844
- }
845
- });
846
- };
847
-
848
- find(startPath, filter);
849
- return result;
850
- };
851
- /**
852
- * 找到项目中所有的package.json文件
853
- * @param {Array<String>} subRoots 需要安装npm依赖的路径
854
- * @param {String} contextDir 命令运行的目录
855
- * @returns {Array<String>} 找到的所有package.json文件的路径
856
- */
857
-
858
-
859
- const findAllPackageJson$1 = (subRoots = [], contextDir) => {
860
- const packageJsonName = 'package.json'; // 查找文件名
861
-
862
- const cwd = contextDir || dirpath;
863
- const result = [path$3.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
864
-
865
- subRoots.forEach(subRoot => {
866
- const toppath = path$3.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
867
-
868
- const list = findFilesByFilter(toppath, packageJsonName);
869
- result.push(...list);
870
- });
871
- return result;
872
- };
873
-
874
- var npmUtils = {
875
- npmInstallAll: npmInstallAll$1,
876
- findAllPackageJson: findAllPackageJson$1
877
- };
878
-
879
- /* eslint-disable require-jsdoc */
880
- const ci = require$$0__default$4;
881
- const path$2 = require$$1__default$1;
882
- /**
883
- * 获取小程序ci的Project对象
884
- * @returns {Object} 小程序ci对象
885
- */
886
-
887
- const getMpCi = ({
888
- appId,
889
- projectPath,
890
- type = 'miniProgram',
891
- privateKey = 'TODO'
892
- }) => {
893
- var _cfgJsonContent$packO;
894
-
895
- const cfgJsonContent = require(path$2.join(projectPath, 'project.config.json'));
896
-
897
- const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
898
- value
899
- }) => value)) || [];
900
- return new ci.Project({
901
- appid: appId,
902
- privateKey,
903
- type,
904
- projectPath,
905
- ignores: ['node_modules/**/*', ...ignores]
906
- });
907
- }; // 用小程序ci工具构建小程序
908
-
909
-
910
- const packMpProject = async project => {
911
- await ci.packNpm(project, {
912
- ignores: ['cloud/**/*']
913
- });
914
- };
915
- /**
916
- * 格式化构建npm结果信息
917
- * @param {Array<String>} warning 构建时的告警信息
918
- * @returns {String} npm构建错误信息
919
- */
920
-
921
-
922
- const formatPackNpmWarning = warning => {
923
- if (!warning) {
924
- return '';
925
- }
926
-
927
- const result = warning.map((it, index) => `${index + 1}. ${it.msg}
928
- \t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
929
- return result;
930
- };
931
- /**
932
- * 构建miniprogram_npm
933
- * @returns {Object} 小程序ci对象
934
- */
935
-
936
-
937
- const buildMpNpm$1 = async ({
938
- appId,
939
- projectPath,
940
- privateKey
941
- }) => {
942
- const mpCi = await getMpCi({
943
- appId,
944
- projectPath,
945
- privateKey
946
- });
947
- const packNpmWarning = await packMpProject(mpCi);
948
- const packNpmMsg = formatPackNpmWarning(packNpmWarning);
949
-
950
- if (packNpmMsg) {
951
- return Promise.reject(packNpmMsg);
952
- }
953
-
954
- return Promise.resolve();
955
- };
956
-
957
- var mpCiUtils = {
958
- buildMpNpm: buildMpNpm$1
752
+ buildOutputAppJson: buildOutputAppJson$1
959
753
  };
960
754
 
961
755
  class Globale {
@@ -993,18 +787,18 @@ var global = {
993
787
  getGlobalInstance: getGlobalInstance$1
994
788
  };
995
789
 
996
- const MetalSmith = require$$0__default$3;
790
+ const MetalSmith = require$$0__default$4;
997
791
  const {
998
792
  getGlobalInstance
999
793
  } = global;
1000
794
  const {
1001
795
  downloadRepoForGit,
1002
- resolve: resolve$7
796
+ resolve: resolve$6
1003
797
  } = widgets;
1004
798
  const {
1005
- fail: fail$7
799
+ fail: fail$4
1006
800
  } = log$2;
1007
- const fs$5 = require$$1__default$2;
801
+ const fs$5 = require$$0__default$1;
1008
802
  const shelljs$3 = require$$5__default;
1009
803
  /**
1010
804
  * 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
@@ -1019,7 +813,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1019
813
  return new Promise(resolve => {
1020
814
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1021
815
  if (e) {
1022
- fail$7(e); // eslint-disable-line
816
+ fail$4(e); // eslint-disable-line
1023
817
 
1024
818
  console.log('MetalSmith 详细的错误信息:', e);
1025
819
  }
@@ -1062,9 +856,9 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
1062
856
  path
1063
857
  } = moduleInfo; // 源码临时存在的源目录
1064
858
 
1065
- let sourcePath = resolve$7(sourceDir, path); // 源码要放到目标目录
859
+ let sourcePath = resolve$6(sourceDir, path); // 源码要放到目标目录
1066
860
 
1067
- const targetPath = resolve$7(targetDir, path); // 设置模块的构建分支
861
+ const targetPath = resolve$6(targetDir, path); // 设置模块的构建分支
1068
862
 
1069
863
  const cloneBranch = buildGitTag && typeof buildGitTag === 'string' ? buildGitTag : 'master'; // 检查缓存中有没有
1070
864
 
@@ -1085,7 +879,7 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
1085
879
 
1086
880
  await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
1087
881
  } catch (e) {
1088
- fail$7(`downLoadAndMoveModule ${e}`); // eslint-disable-line
882
+ fail$4(`downLoadAndMoveModule ${e}`); // eslint-disable-line
1089
883
 
1090
884
  process.exit(-1);
1091
885
  }
@@ -1100,7 +894,8 @@ var defaultTmsConfig$1 = {
1100
894
  envData: {},
1101
895
  // 模块配置信息
1102
896
  modules: [],
1103
- webpack: {
897
+ cloudDir: 'cloud',
898
+ gulp: {
1104
899
  /** 编译输出文件夹位置 */
1105
900
  outputDir: 'dist',
1106
901
 
@@ -1108,22 +903,19 @@ var defaultTmsConfig$1 = {
1108
903
  sourceDir: './',
1109
904
 
1110
905
  /** 源码Map */
1111
- sourceMap: 'none',
1112
-
1113
- /** 别名 */
1114
- alias: {}
906
+ copyDir: []
1115
907
  }
1116
908
  };
1117
909
 
1118
910
  const loadash = require$$0__default$5;
1119
- const fs$4 = require$$1__default$2;
911
+ const fs$4 = require$$0__default$1;
1120
912
  const {
1121
913
  TMS_NAME: TMS_NAME$1,
1122
914
  TMS_CONFIG_FILENAME,
1123
915
  MODULE_CONFIG_FILENAME
1124
916
  } = require$$3;
1125
917
  const {
1126
- resolve: resolve$6,
918
+ resolve: resolve$5,
1127
919
  isObject
1128
920
  } = widgets;
1129
921
  const {
@@ -1131,7 +923,7 @@ const {
1131
923
  } = buildAppJson;
1132
924
  const defaultTmsConfig = defaultTmsConfig$1;
1133
925
  const {
1134
- fail: fail$6
926
+ fail: fail$3
1135
927
  } = log$2;
1136
928
  /**
1137
929
  * 读取tms.config.json
@@ -1139,10 +931,10 @@ const {
1139
931
  */
1140
932
 
1141
933
  const readTmsConfig$1 = function (env) {
1142
- const tmsConfigPath = resolve$6(TMS_CONFIG_FILENAME);
934
+ const tmsConfigPath = resolve$5(TMS_CONFIG_FILENAME);
1143
935
 
1144
936
  if (!fs$4.existsSync(tmsConfigPath)) {
1145
- fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
937
+ fail$3('当前执行目录没有tms.config.js的配置项,请进行配置');
1146
938
  process.exit(1);
1147
939
  }
1148
940
 
@@ -1171,7 +963,7 @@ const checkModules$1 = function (tmsConfig, modules) {
1171
963
  });
1172
964
 
1173
965
  if (targetModules.length === 0) {
1174
- fail$6(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
966
+ fail$3(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
1175
967
  process.exit(1);
1176
968
  }
1177
969
 
@@ -1192,7 +984,7 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName, moduleDir) => {
1192
984
  path: relativePath,
1193
985
  name: moduleName
1194
986
  }, moduleIndex) => {
1195
- const moduleConfigPath = resolve$6(relativePath, MODULE_CONFIG_FILENAME);
987
+ const moduleConfigPath = resolve$5(relativePath, MODULE_CONFIG_FILENAME);
1196
988
 
1197
989
  if (fs$4.existsSync(moduleConfigPath)) {
1198
990
  let moduleConfigContent = fs$4.readFileSync(moduleConfigPath, 'utf-8');
@@ -1221,543 +1013,509 @@ var tkitUtils = {
1221
1013
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3
1222
1014
  };
1223
1015
 
1224
- const shelljs$2 = require$$5__default;
1225
- const fs$3 = require$$1__default$2;
1226
- const io = io$2;
1227
- const {
1228
- resolve: resolve$5,
1229
- createTask: createTask$2
1230
- } = widgets;
1231
- const {
1232
- buildOutputAppJson: buildOutputAppJson$1
1233
- } = buildAppJson;
1234
- const {
1235
- npmInstallAll
1236
- } = npmUtils;
1237
- const {
1238
- buildMpNpm
1239
- } = mpCiUtils;
1240
- const {
1241
- MODULE_CODE_DIR,
1242
- CACHE_DIR,
1243
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
1244
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3
1245
- } = require$$3;
1246
- const {
1247
- cloneModules
1248
- } = cloneModules_1;
1249
- const {
1250
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
1251
- } = tkitUtils;
1252
- const {
1253
- fail: fail$5
1254
- } = log$2;
1016
+ /* eslint-disable require-jsdoc */
1017
+ const ci = require$$0__default$6;
1018
+ const path$2 = require$$1__default$1;
1255
1019
  /**
1256
- * 拷贝package.json\模块的代码到编译输出目录
1257
- * @param { object } tmsConfig
1258
- * @param { array } modules
1259
- * @param { array } defaultFiles 默认需要拷贝的配置项
1260
- * @returns
1020
+ * 获取小程序ci的Project对象
1021
+ * @returns {Object} 小程序ci对象
1261
1022
  */
1262
1023
 
1263
- const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1264
- const outputDir = resolve$5(tmsConfig.webpack.outputDir);
1265
- io.ensureDirExist(outputDir);
1266
- defaultFiles.forEach(item => {
1267
- if (fs$3.existsSync(resolve$5(item))) {
1268
- shelljs$2.cp('-rf', resolve$5(item), resolve$5(tmsConfig.webpack.outputDir, item));
1269
- }
1270
- }); // 拷贝模块的代码到编译输出目录
1024
+ const getMpCi = ({
1025
+ appId,
1026
+ projectPath,
1027
+ type = 'miniProgram',
1028
+ privateKey = 'TODO'
1029
+ }) => {
1030
+ var _cfgJsonContent$packO;
1271
1031
 
1272
- targetModules.forEach(item => {
1273
- const outputModuleDir = resolve$5(`${tmsConfig.webpack.outputDir}/${item.root}`);
1032
+ const cfgJsonContent = require(path$2.join(projectPath, 'project.config.json'));
1274
1033
 
1275
- if (!fs$3.existsSync(resolve$5(item.path))) {
1276
- fail$5(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1277
- process.exit(1);
1278
- }
1034
+ const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
1035
+ value
1036
+ }) => value)) || [];
1037
+ return new ci.Project({
1038
+ appid: appId,
1039
+ privateKey,
1040
+ type,
1041
+ projectPath,
1042
+ ignores: ['node_modules/**/*', ...ignores]
1043
+ });
1044
+ }; // 用小程序ci工具构建小程序
1279
1045
 
1280
- if (!fs$3.existsSync(outputModuleDir)) {
1281
- shelljs$2.mkdir('-p', outputModuleDir);
1282
- } else {
1283
- // 删除除了node_modules、miniprogram_npm 的其他文件
1284
- // eslint-disable-next-line
1285
- shelljs$2.exec('find . -not \( -name node_modules -or -name miniprogram_npm \) -delete', {
1286
- silent: true
1287
- });
1288
- }
1289
1046
 
1290
- shelljs$2.cp('-Rf', `${resolve$5(item.path)}/*`, outputModuleDir);
1047
+ const packMpProject = async project => {
1048
+ await ci.packNpm(project, {
1049
+ ignores: ['cloud/**/*']
1291
1050
  });
1292
1051
  };
1052
+ /**
1053
+ * 格式化构建npm结果信息
1054
+ * @param {Array<String>} warning 构建时的告警信息
1055
+ * @returns {String} npm构建错误信息
1056
+ */
1293
1057
 
1294
- async function task(tmsConfig, targetModules) {
1295
- // 下载和移动代码
1296
- await createTask$2(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$5('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1297
1058
 
1298
- const newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$3);
1299
- console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
1059
+ const formatPackNpmWarning = warning => {
1060
+ if (!warning) {
1061
+ return '';
1062
+ }
1300
1063
 
1301
- await createTask$2(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG$2); // npm install
1064
+ const result = warning.map((it, index) => `${index + 1}. ${it.msg}
1065
+ \t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
1066
+ return result;
1067
+ };
1068
+ /**
1069
+ * 构建miniprogram_npm
1070
+ * @returns {Object} 小程序ci对象
1071
+ */
1302
1072
 
1303
- await createTask$2(npmInstallAll, '开始npm install', 'npm install 完成')(newModules, resolve$5(tmsConfig.webpack.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1304
1073
 
1305
- await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1306
- appId: tmsConfig.appId,
1307
- projectPath: resolve$5('./'),
1308
- privateKey: tmsConfig.privateKey
1309
- }); // 动态生成编译后的app.json;
1074
+ const buildMpNpm$1 = async ({
1075
+ appId,
1076
+ projectPath,
1077
+ privateKey
1078
+ }) => {
1079
+ const mpCi = await getMpCi({
1080
+ appId,
1081
+ projectPath,
1082
+ privateKey
1083
+ });
1084
+ const packNpmWarning = await packMpProject(mpCi);
1085
+ const packNpmMsg = formatPackNpmWarning(packNpmWarning);
1310
1086
 
1311
- await createTask$2(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
1312
- return newModules;
1313
- }
1087
+ if (packNpmMsg) {
1088
+ return Promise.reject(packNpmMsg);
1089
+ }
1314
1090
 
1315
- async function bootstrap(tmsConfig, targetModules) {
1316
- const newModules = await task(tmsConfig, targetModules);
1317
- return {
1318
- targetModules: newModules
1319
- };
1320
- }
1091
+ return Promise.resolve();
1092
+ };
1321
1093
 
1322
- var init$5 = bootstrap;
1094
+ var mpCiUtils = {
1095
+ buildMpNpm: buildMpNpm$1
1096
+ };
1323
1097
 
1098
+ /**
1099
+ * 本文件主要负责项目或者分包依赖的npm的安装
1100
+ */
1101
+ const fs$3 = require$$0__default$1;
1324
1102
  const path$1 = require$$1__default$1;
1325
- const fs$2 = require$$1__default$2;
1326
- const {
1327
- resolve: resolve$4
1328
- } = widgets;
1329
- const {
1330
- buildOutputAppJson
1331
- } = buildAppJson;
1332
- const {
1333
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
1334
- } = tkitUtils;
1335
- const {
1336
- findAllPackageJson
1337
- } = npmUtils;
1338
- const {
1339
- fail: fail$4
1340
- } = log$2;
1341
- const replaceExt = require$$7__default;
1342
- const extensions = ['.ts', '.js'];
1103
+ const shell = require$$5__default;
1104
+ const glob = require$$3__default;
1105
+ const LOG = log$2;
1106
+ const dirpath = process.cwd(); // 项目根目录
1343
1107
 
1344
- function ext(entry, extensions) {
1345
- let newEntry = entry;
1108
+ const getTarNpmFilename = targetDir => `${targetDir.replace(/\//g, '-')}.tar.gz`; // 缓存npm包
1346
1109
 
1347
- try {
1348
- const stat = fs$2.lstatSync(newEntry);
1349
1110
 
1350
- if (stat.isDirectory()) {
1351
- newEntry += newEntry[newEntry.length - 1] === '/' ? 'index' : '/index';
1352
- }
1353
- } catch (e) {}
1111
+ const npmCache = function (targetDir, cacheDir) {
1112
+ if (!fs$3.existsSync(cacheDir)) {
1113
+ fs$3.mkdirSync(cacheDir);
1114
+ }
1354
1115
 
1355
- for (const ext of extensions) {
1356
- const file = replaceExt(newEntry, ext);
1116
+ const tarNpmFilename = getTarNpmFilename(targetDir);
1117
+ const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1357
1118
 
1358
- if (fs$2.existsSync(file)) {
1359
- return {
1360
- file,
1361
- ext
1362
- };
1363
- }
1119
+ if (fs$3.existsSync(tarNpmFilePath)) {
1120
+ shell.rm('-rf', tarNpmFilePath);
1364
1121
  }
1365
1122
 
1366
- return null;
1367
- } // 获取所有的package.json里的依赖包Dir
1123
+ const cmd = `tar -zcvf ${tarNpmFilePath} ./node_modules`;
1124
+ shell.exec(cmd, {
1125
+ async: true,
1126
+ silent: true
1127
+ }); // tar -zcvf /Users/odile/.tmskit/node_modules.tar.gz ./node_modules
1128
+ }; // 获取缓存npm包
1368
1129
 
1369
1130
 
1370
- function getAlias$1(modules) {
1371
- const alias = {};
1372
- const allPackages = findAllPackageJson(modules, resolve$4('./dist'));
1373
- allPackages.forEach(packageFilePath => {
1374
- const {
1375
- dependencies
1376
- } = require(packageFilePath);
1131
+ const getNpmCache = function (targetDir, cacheDir) {
1132
+ const tarNpmFilename = getTarNpmFilename(targetDir);
1133
+ const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1377
1134
 
1378
- Object.keys(dependencies).forEach(dependence => {
1379
- alias[dependence] = path$1.join(path$1.dirname(packageFilePath), `./miniprogram_npm/${dependence}`);
1135
+ if (fs$3.existsSync(tarNpmFilePath)) {
1136
+ const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
1137
+ shell.exec(cmd, {
1138
+ async: false,
1139
+ silent: true
1380
1140
  });
1381
- });
1382
- return alias;
1383
- } // 根据用户选择的modules,找到module.config.json的配置信息,找到所有的page
1384
-
1385
-
1386
- function getPageEntry(modules, tmsConfig, moduleDir) {
1387
- const entry = {}; // tms.config.js的modules 合并 module.config.json的配置项
1141
+ } // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
1388
1142
 
1389
- const newModules = tmsModulesMergeLocalModuleCfg$1(modules, tmsConfig.appName, moduleDir);
1390
- newModules.forEach(({
1391
- path: relativePath,
1392
- pages,
1393
- root
1394
- }) => {
1395
- pages.forEach(page => {
1396
- const pageJsonPath = `${resolve$4(relativePath, page)}.json`;
1143
+ }; // 遍历安装指定目录下所有项目的npm依赖
1397
1144
 
1398
- if (fs$2.existsSync(pageJsonPath)) {
1399
- const pageJsonContent = JSON.parse(fs$2.readFileSync(pageJsonPath, 'utf-8'));
1400
- const pageDir = path$1.dirname(pageJsonPath); // 该页面所在的目录
1401
1145
 
1402
- const extValue = ext(resolve$4(relativePath, page), extensions);
1146
+ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
1147
+ const packageJsonFiles = await findAllPackageJson(modules, contextDir);
1148
+ await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
1149
+ const dir = path$1.dirname(file);
1150
+ shell.cd(dir);
1403
1151
 
1404
- if (!extValue) {
1405
- fail$4(`当前${page}找不到入口.js或.ts文件`);
1406
- process.exit(1);
1407
- }
1152
+ if (!fs$3.existsSync(`${dir}/node_modules`)) {
1153
+ getNpmCache(dir, cacheDir);
1154
+ }
1408
1155
 
1409
- const entryKey = `${root}/${page}${extValue.ext}`;
1410
- Object.assign(entry, {
1411
- [entryKey]: extValue.file
1412
- }, getComponentEntry(pageJsonContent, pageDir, path$1.dirname(entryKey)));
1413
- }
1156
+ shell.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
1157
+ silent: false
1414
1158
  });
1415
- });
1416
- return entry;
1417
- } // 根据appJson,获取所有的page
1418
-
1419
-
1420
- function getEntry$2(defaultWebpackEntry, modules, tmsConfig, moduleDir) {
1421
- const defaultEntry = {};
1422
- Object.keys(defaultWebpackEntry).forEach(key => {
1423
- const extValue = ext(defaultWebpackEntry[key], extensions);
1424
- defaultEntry[key + extValue.ext] = extValue.file;
1425
- });
1426
- return { ...defaultEntry,
1427
- ...getPageEntry(modules, tmsConfig, moduleDir)
1428
- };
1429
- } // 根据pageJson,filePath,获取页面引入的所有component
1159
+ resolve();
1160
+ npmCache(dir, cacheDir);
1161
+ })));
1162
+ };
1163
+ /**
1164
+ * 递归查找指定条件的文件
1165
+ * @param {String} startPath 开始查找的根路径
1166
+ * @param {String} filter 匹配的字符串
1167
+ * @returns {Array<String>} 查找到的文件路径列表
1168
+ */
1430
1169
 
1431
1170
 
1432
- function getComponentEntry(pageJson, pagePath, pageKey) {
1433
- const componentEntry = {};
1171
+ const findFilesByFilter = (startPath, filter) => {
1172
+ const result = [];
1173
+ /**
1174
+ * 根据指定的筛选器查找文件
1175
+ * @param {String} startPath 开始查找的文件夹路径
1176
+ * @param {String} filter 筛选器
1177
+ * @returns {Undefined} 无需返回值
1178
+ */
1434
1179
 
1435
- function task(json, dir, rootKey) {
1436
- if (!json.usingComponents) {
1180
+ const find = (startPath, filter) => {
1181
+ // 目录不存在
1182
+ if (!fs$3.existsSync(startPath)) {
1183
+ LOG.fail(`${startPath}目录不存在`);
1184
+ process.exit(-1);
1437
1185
  return;
1438
- }
1439
-
1440
- const componentKeys = Object.keys(json.usingComponents); // 如果存在依赖的组件
1186
+ } // 当前目录下的所有文件 / 文件夹
1441
1187
 
1442
- componentKeys.forEach(key => {
1443
- if (json.usingComponents[key].startsWith('.')) {
1444
- // 拼出组件所在位置的绝对路径
1445
- const comValue = path$1.join(dir, json.usingComponents[key]);
1446
- const extValue = ext(comValue, extensions);
1447
- const comKey = path$1.resolve('/', rootKey, json.usingComponents[key]);
1448
1188
 
1449
- if (!extValue) {
1450
- fail$4(`当前page: ${pagePath} component: ${comValue}找不到入口.js或.ts文件`);
1451
- process.exit(1);
1452
- }
1189
+ const exceptDir = ['node_modules', 'miniprogram_npm'];
1453
1190
 
1454
- componentEntry[`${comKey.slice(1)}${extValue.ext}`] = extValue.file;
1455
- const comJsonPath = `${comValue}.json`;
1191
+ if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
1192
+ return;
1193
+ }
1456
1194
 
1457
- if (fs$2.existsSync(comJsonPath)) {
1458
- const comJsonContent = JSON.parse(fs$2.readFileSync(comJsonPath, 'utf-8'));
1459
- const comDir = path$1.dirname(comJsonPath); // 该页面所在的目录
1195
+ const files = fs$3.readdirSync(startPath);
1196
+ files.forEach(file => {
1197
+ const filename = path$1.join(startPath, file);
1198
+ const stat = fs$3.lstatSync(filename); // 当前文件是文件夹类型,继续递归
1460
1199
 
1461
- task(comJsonContent, comDir, path$1.dirname(comKey));
1462
- }
1200
+ if (stat.isDirectory()) {
1201
+ find(filename, filter);
1202
+ } else if (filename.indexOf(filter) >= 0) {
1203
+ // 文件类型
1204
+ result.push(filename);
1463
1205
  }
1464
1206
  });
1465
- }
1207
+ };
1466
1208
 
1467
- task(pageJson, pagePath, pageKey);
1468
- return componentEntry;
1469
- } // 根据modules处理需要拷贝的模块,copy-webpack-plugin需要的参数
1209
+ find(startPath, filter);
1210
+ return result;
1211
+ };
1212
+ /**
1213
+ * 找到项目中所有的package.json文件
1214
+ * @param {Array<String>} subRoots 需要安装npm依赖的路径
1215
+ * @param {String} contextDir 命令运行的目录
1216
+ * @returns {Array<String>} 找到的所有package.json文件的路径
1217
+ */
1470
1218
 
1471
1219
 
1472
- function getCopyPlugin$2(defaultCopyConfig, modules, tmsConfig, env) {
1473
- const toPath = tmsConfig.webpack.outputDir;
1220
+ const findAllPackageJson = (subRoots = [], contextDir) => {
1221
+ const packageJsonName = 'package.json'; // 查找文件名
1474
1222
 
1475
- function generatorAppJson(tmsConfig, modules) {
1476
- try {
1477
- return buildOutputAppJson(tmsConfig, modules);
1478
- } catch (e) {
1479
- fail$4(`动态生成app.json出现错误${e} 请检查你的配置项`);
1480
- return {};
1481
- }
1482
- }
1223
+ const cwd = contextDir || dirpath;
1224
+ const result = [path$1.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1483
1225
 
1484
- const patterns = []; // 默认的一些配置拷贝文件 package.json、sitemap.json等
1226
+ subRoots.forEach(subRoot => {
1227
+ console.log('>>>>>>>>>>>>', subRoot);
1228
+ const toppath = path$1.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
1485
1229
 
1486
- defaultCopyConfig.forEach(item => {
1487
- if (fs$2.existsSync(resolve$4(item))) {
1488
- patterns.push({
1489
- from: resolve$4(item),
1490
- to: resolve$4(`./${toPath}/${item}`),
1491
- transform: {
1492
- cache: true
1493
- }
1494
- });
1495
- }
1496
- }); // 拷贝模块的代码
1230
+ const list = findFilesByFilter(toppath, packageJsonName);
1231
+ result.push(...list);
1232
+ });
1233
+ return result;
1234
+ };
1497
1235
 
1498
- modules.forEach(item => {
1499
- patterns.push({
1500
- from: resolve$4(item.path),
1501
- to: resolve$4(`./${toPath}/${item.root}`),
1502
- globOptions: {
1503
- ignore: ['**/*.js', '*.js', '**/*.ts', '*.ts']
1504
- },
1505
- transform: {
1506
- cache: true,
1507
- transformer: env === 'dev' ? (content, absoluteFrom) => {
1508
- // 监听module.config.json的修改, 自动生成编译后的app.json
1509
- if (absoluteFrom.indexOf('module.config.json') > -1) {
1510
- generatorAppJson(tmsConfig, modules);
1511
- }
1512
-
1513
- return content;
1514
- } : content => content
1236
+ function cloudNpmInstall$1(contextDir) {
1237
+ return new Promise((resolve, reject) => {
1238
+ glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
1239
+ if (err) {
1240
+ reject(err);
1515
1241
  }
1516
- });
1517
- });
1518
1242
 
1519
- if (env === 'dev') {
1520
- // 拷贝app.json时,自动生成编译后的app.json
1521
- const appJsonConfig = ['app.json'];
1522
- appJsonConfig.forEach(item => {
1523
- patterns.push({
1524
- from: resolve$4(item),
1525
- to: resolve$4(`./${toPath}/${item}`),
1526
- transform: {
1527
- cache: true,
1528
- transformer: () => {
1529
- const appJson = generatorAppJson(tmsConfig, modules);
1530
- return JSON.stringify(appJson, null, 2);
1531
- }
1532
- }
1243
+ files.forEach(file => {
1244
+ const dir = path$1.dirname(file);
1245
+ shell.cd(dir);
1246
+ shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
1247
+ silent: false
1248
+ });
1533
1249
  });
1250
+ resolve();
1534
1251
  });
1535
- }
1536
-
1537
- return patterns;
1538
- } // dev时,给webpack注入相应的事件
1539
-
1540
-
1541
- const setupDevWebPackHooks$1 = (context, firstDone) => {
1542
- let tempFirstDone = true;
1543
-
1544
- const invalid = () => {
1545
- // eslint-disable-next-line
1546
- context.stats = undefined;
1547
- };
1548
-
1549
- const done = stats => {
1550
- // eslint-disable-next-line
1551
- context.stats = stats;
1552
- process.nextTick(() => {
1553
- const {
1554
- stats
1555
- } = context;
1556
- if (!stats) return;
1557
-
1558
- if (tempFirstDone) {
1559
- tempFirstDone = false;
1560
- firstDone();
1561
- }
1562
- });
1563
- };
1564
-
1565
- const {
1566
- compiler
1567
- } = context;
1568
- compiler.hooks.watchRun.tap('miniprogram-dev', invalid);
1569
- compiler.hooks.invalid.tap('miniprogram-dev', invalid);
1570
- compiler.hooks.done.tap('miniprogram-dev', done);
1571
- };
1572
-
1573
- const stringified$1 = raw => ({
1574
- 'process.env': Object.keys(raw).reduce((env, key) => {
1575
- // eslint-disable-next-line
1576
- env[key] = JSON.stringify(raw[key]);
1577
- return env;
1578
- }, {})
1579
- });
1252
+ });
1253
+ }
1580
1254
 
1581
- var utils = {
1582
- getCopyPlugin: getCopyPlugin$2,
1583
- setupDevWebPackHooks: setupDevWebPackHooks$1,
1584
- getEntry: getEntry$2,
1585
- stringified: stringified$1,
1586
- getAlias: getAlias$1
1255
+ var npmUtils = {
1256
+ cloudNpmInstall: cloudNpmInstall$1,
1257
+ mpNpmInstallAll: mpNpmInstallAll$1,
1258
+ findAllPackageJson
1587
1259
  };
1588
1260
 
1589
- const WebpackChain = require$$0__default$6;
1590
- const webpack$2 = require$$0__default$7;
1591
1261
  const {
1592
- getEntry: getEntry$1,
1593
- stringified,
1594
- getAlias
1595
- } = utils;
1596
- const {
1597
- resolve: resolve$3
1262
+ createTask: createTask$2,
1263
+ resolve: resolve$4
1598
1264
  } = widgets;
1599
1265
  const {
1600
- DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY$1,
1266
+ buildMpNpm
1267
+ } = mpCiUtils;
1268
+ const {
1269
+ CACHE_DIR,
1601
1270
  DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$2
1602
1271
  } = require$$3;
1603
-
1604
- var base = (tmsConfig, modules) => {
1605
- const {
1606
- envData = {},
1607
- webpack: tmsWebpack
1608
- } = tmsConfig;
1609
- let webpackConfig = new WebpackChain();
1610
- const alias = getAlias(modules);
1611
- const entry = getEntry$1(DEFAULT_WEBPACK_ENTRY$1, modules, tmsConfig, DEFAULT_MODULE_DIR$2);
1612
- webpackConfig.merge({
1613
- entry,
1614
- output: {
1615
- path: resolve$3(`./${tmsWebpack.outputDir}`),
1616
- libraryTarget: 'commonjs2',
1617
- filename: '[name]'
1618
- },
1619
- // TODO 有报错,先注释掉
1620
- // cache: {
1621
- // type: 'filesystem',
1622
- // cacheDirectory: resolve(`./${tmsConfig.webpack.outputDir}/node_modules/.cache`),
1623
- // },
1624
- resolve: {
1625
- extensions: ['.tsx', '.ts', '.js'],
1626
- alias: Object.assign(tmsWebpack.alias, alias)
1627
- },
1628
- devtool: tmsWebpack.sourceMap ? 'source-map' : false
1629
- });
1630
- webpackConfig.module.rule('ts-loader').test(/\.ts$/).use('ts-loader').loader(require.resolve('ts-loader')).options({
1631
- configFile: resolve$3('./tsconfig.json'),
1632
- // 只进行语法转换,不进行类型校验,提高构建速度
1633
- transpileOnly: true
1634
- }).end(); // webpackConfig.module
1635
- // .rule('babel')
1636
- // .test(/\.(js|mjs|jsx|ts|tsx)$/)
1637
- // .pre()
1638
- // .exclude.add(/(node_modules|miniprogram_npm)/).end()
1639
- // .use(require.resolve('babel-loader'))
1640
- // .loader(require.resolve('babel-loader'));
1641
-
1642
- webpackConfig.plugin('definePlugin').use(webpack$2.DefinePlugin, [stringified(envData)]).end(); // 执行tms.config.js自定义的webpackChain
1643
-
1644
- if (tmsWebpack.webpackChain) {
1645
- webpackConfig = tmsWebpack.webpackChain(webpackConfig, {
1646
- modules
1647
- });
1648
- }
1649
-
1650
- return webpackConfig;
1651
- };
1652
-
1653
- const SingleEntryPlugin = require$$0__default$8;
1654
1272
  const {
1655
- DEFAULT_WEBPACK_ENTRY,
1656
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$1
1657
- } = require$$3;
1273
+ cloudNpmInstall,
1274
+ mpNpmInstallAll
1275
+ } = npmUtils;
1658
1276
  const {
1659
- getEntry
1660
- } = utils;
1277
+ tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
1278
+ } = tkitUtils;
1661
1279
 
1662
- class EntryExtraPlugin {
1663
- constructor(options = {}) {
1664
- this.options = options;
1665
- this.scriptExtensions = options.scriptExtensions || ['.ts', '.js'];
1666
- }
1280
+ async function install$2(tmsConfig, modules, isCloud = true) {
1281
+ const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
1667
1282
 
1668
- applyEntry(compiler, entry) {
1669
- const {
1670
- context
1671
- } = compiler.options;
1672
- Object.keys(entry).forEach(key => {
1673
- new SingleEntryPlugin(context, entry[key], key).apply(compiler);
1674
- });
1675
- }
1283
+ await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$4(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1676
1284
 
1677
- apply(compiler) {
1678
- const {
1679
- tmsConfig = {},
1680
- modules = []
1681
- } = this.options;
1682
- compiler.hooks.watchRun.tap('EntryExtraPlugin', () => {
1683
- const entry = getEntry(DEFAULT_WEBPACK_ENTRY, modules, tmsConfig, DEFAULT_MODULE_DIR$1);
1684
- this.applyEntry(compiler, entry);
1685
- });
1686
- }
1285
+ await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1286
+ appId: tmsConfig.appId,
1287
+ projectPath: resolve$4('./'),
1288
+ privateKey: tmsConfig.privateKey
1289
+ }); // 安装云函数的
1687
1290
 
1291
+ isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$4(tmsConfig.cloudDir));
1688
1292
  }
1689
1293
 
1690
- var entryExtractPlugin = EntryExtraPlugin;
1294
+ var install_1 = install$2;
1691
1295
 
1692
- const webpackConfig$1 = base;
1296
+ const shelljs$2 = require$$5__default;
1297
+ const fs$2 = require$$0__default$1;
1298
+ const io = io$2;
1693
1299
  const {
1694
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
1300
+ resolve: resolve$3,
1301
+ createTask: createTask$1
1302
+ } = widgets;
1303
+ const {
1304
+ buildOutputAppJson
1305
+ } = buildAppJson;
1306
+ const {
1307
+ MODULE_CODE_DIR,
1308
+ DEFAULT_COPY_CONFIG,
1309
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$1
1695
1310
  } = require$$3;
1696
1311
  const {
1697
- getCopyPlugin: getCopyPlugin$1
1698
- } = utils;
1699
-
1700
- var dev$2 = (...args) => {
1701
- const [tmsConfig, modules] = args;
1702
- const webpackDevConfig = webpackConfig$1(...args);
1703
- webpackDevConfig.devtool('source-map');
1704
- webpackDevConfig.mode('development');
1705
- const copyPluginParams = getCopyPlugin$1(DEFAULT_COPY_CONFIG$1, modules, tmsConfig, 'dev'); // console.log('copyPluginParams', copyPluginParams);
1706
-
1707
- webpackDevConfig.plugin('copy-webpack-plugin').use(require$$3__default, [{
1708
- patterns: copyPluginParams
1709
- }]).end();
1710
- webpackDevConfig.plugin('ExtractPlugin').use(entryExtractPlugin, [{
1711
- tmsConfig,
1712
- modules
1713
- }]).end();
1714
- return webpackDevConfig;
1715
- };
1716
-
1717
- const webpack$1 = require$$0__default$7;
1718
- const webDevConfig = dev$2;
1312
+ cloneModules
1313
+ } = cloneModules_1;
1719
1314
  const {
1720
- setupDevWebPackHooks
1721
- } = utils;
1315
+ tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
1316
+ } = tkitUtils;
1722
1317
  const {
1723
- fail: fail$3
1318
+ fail: fail$2
1724
1319
  } = log$2;
1320
+ const install$1 = install_1;
1321
+ /**
1322
+ * 拷贝相关配置文件到编译输出目录
1323
+ * @param { object } tmsConfig
1324
+ * @param { array } modules
1325
+ * @param { array } defaultFiles 默认需要拷贝的配置项
1326
+ * @returns
1327
+ */
1725
1328
 
1726
- var devServer = (...args) => {
1727
- const config = webDevConfig(...args);
1728
- const compiler = webpack$1(config.toConfig());
1729
- setupDevWebPackHooks({
1730
- compiler
1731
- }, () => {// TODO 判断open参数,打开微信开发者工具
1732
- // openDevtool(api.resolve(config.outputDir || 'dist'))
1733
- });
1734
- compiler.watch({
1735
- aggregateTimeout: 1000,
1736
- poll: undefined
1737
- }, (err, stats) => {
1738
- if (err) {
1739
- fail$3(err);
1740
- console.log('详细的错误信息:', err);
1329
+ const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1330
+ const outputDir = resolve$3(tmsConfig.gulp.outputDir);
1331
+ io.ensureDirExist(outputDir);
1332
+ defaultFiles.forEach(item => {
1333
+ if (fs$2.existsSync(resolve$3(item))) {
1334
+ shelljs$2.cp('-rf', resolve$3(item), resolve$3(tmsConfig.gulp.outputDir, item));
1741
1335
  }
1336
+ }); // 拷贝模块的package.json到编译输出目录
1742
1337
 
1743
- if (stats.hasErrors() || stats.hasWarnings()) {
1744
- console.log(stats.toString({
1745
- // 增加控制台颜色开关
1746
- colors: true
1747
- }));
1338
+ targetModules.forEach(item => {
1339
+ const outputModuleDir = resolve$3(`${tmsConfig.gulp.outputDir}/${item.root}`);
1340
+
1341
+ if (!fs$2.existsSync(resolve$3(item.path))) {
1342
+ fail$2(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1343
+ process.exit(1);
1748
1344
  }
1345
+
1346
+ io.ensureDirExist(outputModuleDir);
1347
+ const modulePackagePath = resolve$3(item.path, 'package.json');
1348
+ if (fs$2.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
1749
1349
  });
1750
- return compiler;
1751
1350
  };
1752
1351
 
1753
- const fs$1 = require$$1__default$2;
1352
+ async function task(tmsConfig, targetModules) {
1353
+ // 下载和移动代码
1354
+ await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$3('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
1355
+
1356
+ const newModules = tmsModulesMergeLocalModuleCfg$1(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$1);
1357
+ console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
1358
+
1359
+ await createTask$1(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
1360
+
1361
+ await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
1362
+
1363
+ await createTask$1(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
1364
+ return newModules;
1365
+ }
1366
+
1367
+ async function bootstrap(tmsConfig, targetModules) {
1368
+ const newModules = await task(tmsConfig, targetModules);
1369
+ return {
1370
+ targetModules: newModules
1371
+ };
1372
+ }
1373
+
1374
+ var init$5 = bootstrap;
1375
+
1376
+ var dev$2 = {exports: {}};
1377
+
1378
+ const through = require$$0__default$7;
1379
+
1380
+ function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
1381
+ const stream = through.obj(function (file, enc, cb) {
1382
+ if (file.isBuffer()) {
1383
+ let contents = String(file.contents);
1384
+ let resReg; // eslint-disable-next-line
1385
+
1386
+ while ((resReg = reg.exec(contents)) !== null) {
1387
+ const [reg1, reg2, reg3] = resReg;
1388
+
1389
+ if (reg1 && reg2 && reg3) {
1390
+ const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
1391
+ contents = contents.replace(reg1, value);
1392
+ } else if (reg1 && !reg2 && !reg3) {
1393
+ contents = contents.replace(reg1, JSON.stringify(envData));
1394
+ }
1395
+ } // eslint-disable-next-line
1396
+
1397
+
1398
+ file.contents = new Buffer(contents);
1399
+ }
1400
+
1401
+ this.push(file);
1402
+ cb();
1403
+ });
1404
+ return stream;
1405
+ }
1406
+
1407
+ var replaceEnv_1 = replaceEnv;
1408
+
1409
+ (function (module) {
1410
+ const fs = require$$0__default$1;
1411
+ const {
1412
+ src,
1413
+ dest
1414
+ } = require$$1__default$4;
1415
+ const px2rpx = require$$2__default$1;
1416
+ const less = require$$3__default$1;
1417
+ const rename = require$$4__default;
1418
+ const watch = require$$5__default$1;
1419
+ const {
1420
+ resolve
1421
+ } = widgets;
1422
+ const {
1423
+ buildOutputAppJson
1424
+ } = buildAppJson;
1425
+ const {
1426
+ DEFAULT_COPY_CONFIG
1427
+ } = require$$3;
1428
+ const replaceEnv = replaceEnv_1;
1429
+
1430
+ module.exports = async (tmsConfig, newModules) => {
1431
+ var _tmsConfig$gulp;
1432
+
1433
+ // 监听app.json
1434
+ watch(resolve('app.json'), {
1435
+ ignoreInitial: false,
1436
+ events: ['add', 'change']
1437
+ }, () => {
1438
+ buildOutputAppJson(tmsConfig, newModules);
1439
+ }); // 监听根目录的文件
1440
+
1441
+ DEFAULT_COPY_CONFIG.forEach(item => {
1442
+ if (fs.existsSync(resolve(item))) {
1443
+ src(resolve(item)).pipe(watch(resolve(item), {
1444
+ events: ['change']
1445
+ })).pipe(dest(resolve(tmsConfig.gulp.outputDir)));
1446
+ }
1447
+ });
1448
+ src([resolve('app.less'), resolve('app.wxss')], {
1449
+ allowEmpty: true
1450
+ }).pipe(watch(`${resolve()}/(app.less|app.wxss)`, {
1451
+ events: ['change']
1452
+ })).pipe(less()).pipe(px2rpx({
1453
+ designWidth: 375,
1454
+ // 设计稿宽度,默认为750
1455
+ precision: 2 // 小数最大精度,默认为6
1456
+
1457
+ })).pipe(rename({
1458
+ extname: '.wxss'
1459
+ })).pipe(dest(resolve(tmsConfig.gulp.outputDir)));
1460
+ src([resolve('app.js'), resolve('app.ts')], {
1461
+ allowEmpty: true
1462
+ }).pipe(watch(`${resolve()}/(app.js|app.ts)`, {
1463
+ events: ['change']
1464
+ })).pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(dest(resolve(tmsConfig.gulp.outputDir))); // 监听模块的文件
1465
+
1466
+ for (const module of newModules) {
1467
+ // 监听模块js文件
1468
+ src([`${resolve(module.path)}/**/*.js`, `${resolve(module.path)}/**/*.ts`, `${resolve(module.path)}/**/*.wxs`]).pipe(watch(`${resolve(module.path)}/**/(*.js|*.ts|*.wxs)`, {
1469
+ events: ['add', 'change']
1470
+ })).pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听json文件
1471
+
1472
+ src([`${resolve(module.path)}/**/*.json`]).pipe(watch(`${resolve(module.path)}/**/*.json`, {
1473
+ events: ['add', 'change']
1474
+ })).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听css文件
1475
+
1476
+ src([`${resolve(module.path)}/**/*.less`, `${resolve(module.path)}/**/*.wxss`]).pipe(watch(`${resolve(module.path)}/**/(*.less|*.wxss)`, {
1477
+ events: ['add', 'change']
1478
+ })).pipe(less()).pipe(px2rpx({
1479
+ designWidth: 375,
1480
+ // 设计稿宽度,默认为750
1481
+ precision: 2 // 小数最大精度,默认为6
1482
+
1483
+ })).pipe(rename({
1484
+ extname: '.wxss'
1485
+ })).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听wxml文件
1486
+
1487
+ src([`${resolve(module.path)}/**/*.wxml`]).pipe(watch(`${resolve(module.path)}/**/*.wxml`, {
1488
+ events: ['add', 'change']
1489
+ })).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听模块配置文件
1490
+
1491
+ watch(`${resolve(module.path)}/**/module.config.json`, {
1492
+ events: ['change']
1493
+ }, () => {
1494
+ buildOutputAppJson(tmsConfig, newModules);
1495
+ });
1496
+ } // 监听copy模块
1497
+
1498
+
1499
+ if ((tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gulp = tmsConfig.gulp) === null || _tmsConfig$gulp === void 0 ? void 0 : _tmsConfig$gulp.copyDir.length) > 0) {
1500
+ for (const item of (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.copyDir) {
1501
+ var _tmsConfig$gulp2;
1502
+
1503
+ src([item.from]).pipe(watch(item.from, {
1504
+ events: ['add', 'change']
1505
+ })).pipe(dest(item.to));
1506
+ }
1507
+ }
1508
+ };
1509
+ })(dev$2);
1510
+
1511
+ const fs$1 = require$$0__default$1;
1754
1512
  const semver$1 = require$$1__default$5;
1755
1513
  const {
1756
1514
  resolve: resolve$2
1757
1515
  } = widgets;
1758
1516
  const path = require$$1__default$1;
1759
1517
  const {
1760
- fail: fail$2
1518
+ fail: fail$1
1761
1519
  } = log$2;
1762
1520
  const shelljs$1 = require$$5__default;
1763
1521
 
@@ -1802,7 +1560,7 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
1802
1560
  try {
1803
1561
  dependencies = JSON.parse(packageJson).dependencies;
1804
1562
  } catch (e) {
1805
- fail$2(`解析${packageJson}报错,请检查是否是正确的json配置项`);
1563
+ fail$1(`解析${packageJson}报错,请检查是否是正确的json配置项`);
1806
1564
  process.exit(1);
1807
1565
  }
1808
1566
 
@@ -1842,8 +1600,8 @@ var checkDependencies_1 = {
1842
1600
  checkDependencies: checkDependencies$1
1843
1601
  };
1844
1602
 
1845
- const webpackServer = devServer;
1846
- const fs = require$$1__default$2;
1603
+ const gulpDev = dev$2.exports;
1604
+ const fs = require$$0__default$1;
1847
1605
  const {
1848
1606
  resolve: resolve$1
1849
1607
  } = widgets;
@@ -1858,7 +1616,7 @@ const {
1858
1616
  checkDependencies
1859
1617
  } = checkDependencies_1;
1860
1618
  const {
1861
- fail: fail$1
1619
+ fail
1862
1620
  } = log$2;
1863
1621
 
1864
1622
  function isInit(tmsConfig, targetModules, contextDir) {
@@ -1896,13 +1654,13 @@ function isInit(tmsConfig, targetModules, contextDir) {
1896
1654
 
1897
1655
 
1898
1656
  if (item.path && !fs.existsSync(resolve$1(item.path))) {
1899
- fail$1(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1657
+ fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1900
1658
  process.exit(1);
1901
1659
  }
1902
1660
  } // 判断package.json的版本是否有新的版本
1903
1661
 
1904
1662
 
1905
- return checkDependencies(targetModules, resolve$1('./'), tmsConfig.webpack.outputDir);
1663
+ return checkDependencies(targetModules, resolve$1('./'), tmsConfig.gulp.outputDir);
1906
1664
  }
1907
1665
 
1908
1666
  async function dev$1(tmsConfig, targetModules, env) {
@@ -1916,88 +1674,101 @@ async function dev$1(tmsConfig, targetModules, env) {
1916
1674
  }
1917
1675
 
1918
1676
  console.log('当前dev启动的有效模块', newModules.map(item => item.name));
1919
- webpackServer(tmsConfig, newModules, env);
1677
+ gulpDev(tmsConfig, newModules, env);
1920
1678
  }
1921
1679
 
1922
1680
  var dev_1 = dev$1;
1923
1681
 
1924
- const webpackConfig = base;
1925
- const {
1926
- DEFAULT_COPY_CONFIG
1927
- } = require$$3;
1928
- const {
1929
- getCopyPlugin
1930
- } = utils;
1931
-
1932
- var build$2 = (...args) => {
1933
- const [tmsConfig, modules] = args;
1934
- const webpackBuildConfig = webpackConfig(...args);
1935
- webpackBuildConfig.mode('production');
1936
- const copyPluginParams = getCopyPlugin(DEFAULT_COPY_CONFIG, modules, tmsConfig, 'build'); // console.log('copyPluginParams', copyPluginParams);
1937
-
1938
- webpackBuildConfig.plugin('copy-webpack-plugin').use(require$$3__default, [{
1939
- patterns: copyPluginParams
1940
- }]).end();
1941
- return webpackBuildConfig;
1942
- };
1682
+ var build$2 = {exports: {}};
1943
1683
 
1944
- const webpack = require$$0__default$7;
1945
- const webBuildConfig = build$2;
1946
- const {
1947
- createTask: createTask$1
1948
- } = widgets;
1949
- const {
1950
- fail
1951
- } = log$2;
1684
+ (function (module) {
1685
+ const fs = require$$0__default$1;
1686
+ const {
1687
+ src,
1688
+ dest
1689
+ } = require$$1__default$4;
1690
+ const px2rpx = require$$2__default$1;
1691
+ const less = require$$3__default$1;
1692
+ const rename = require$$4__default;
1693
+ const {
1694
+ resolve
1695
+ } = widgets;
1696
+ const {
1697
+ buildOutputAppJson
1698
+ } = buildAppJson;
1699
+ const {
1700
+ DEFAULT_COPY_CONFIG
1701
+ } = require$$3;
1702
+ const replaceEnv = replaceEnv_1;
1952
1703
 
1953
- function compilerRun(compiler) {
1954
- return new Promise(resolve => {
1955
- compiler.run((err, stats) => {
1956
- resolve({
1957
- err,
1958
- stats
1959
- });
1704
+ module.exports = async (tmsConfig, newModules) => {
1705
+ var _tmsConfig$gulp;
1706
+
1707
+ // app.json
1708
+ buildOutputAppJson(tmsConfig, newModules); // 监听根目录的文件
1709
+
1710
+ DEFAULT_COPY_CONFIG.forEach(item => {
1711
+ if (fs.existsSync(resolve(item))) {
1712
+ src(resolve(item)).pipe(dest(resolve(tmsConfig.gulp.outputDir)));
1713
+ }
1960
1714
  });
1961
- });
1962
- }
1715
+ src([resolve('app.less'), resolve('app.wxss')], {
1716
+ allowEmpty: true
1717
+ }).pipe(less()).pipe(px2rpx({
1718
+ designWidth: 375,
1719
+ // 设计稿宽度,默认为750
1720
+ precision: 2 // 小数最大精度,默认为6
1963
1721
 
1964
- var buildServer = async (...args) => {
1965
- const config = webBuildConfig(...args);
1966
- const compiler = webpack(config.toConfig());
1967
- const {
1968
- err,
1969
- stats
1970
- } = await createTask$1(compilerRun, '开始webpack打包编译', 'webpack打包编译完成')(compiler);
1722
+ })).pipe(rename({
1723
+ extname: '.wxss'
1724
+ })).pipe(dest(resolve(tmsConfig.gulp.outputDir)));
1725
+ src([resolve('app.js'), resolve('app.ts')], {
1726
+ allowEmpty: true
1727
+ }).pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(dest(resolve(tmsConfig.gulp.outputDir))); // 监听模块的文件
1971
1728
 
1972
- if (err) {
1973
- fail(err);
1974
- console.log('详细的错误信息:', err);
1975
- }
1729
+ for (const module of newModules) {
1730
+ // 监听模块js文件
1731
+ src([`${resolve(module.path)}/**/*.js`, `${resolve(module.path)}/**/*.ts`, `${resolve(module.path)}/**/*.wxs`]).pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听json文件
1976
1732
 
1977
- if (stats.hasErrors() || stats.hasWarnings()) {
1978
- console.log(stats.toString({
1979
- // 增加控制台颜色开关
1980
- colors: true,
1981
- errorDetails: true
1982
- }));
1983
- }
1984
- return compiler;
1985
- };
1733
+ src([`${resolve(module.path)}/**/*.json`]).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听css文件
1734
+
1735
+ src([`${resolve(module.path)}/**/*.less`, `${resolve(module.path)}/**/*.wxss`]).pipe(less()).pipe(px2rpx({
1736
+ designWidth: 375,
1737
+ // 设计稿宽度,默认为750
1738
+ precision: 2 // 小数最大精度,默认为6
1739
+
1740
+ })).pipe(rename({
1741
+ extname: '.wxss'
1742
+ })).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root))); // 监听wxml文件
1743
+
1744
+ src([`${resolve(module.path)}/**/*.wxml`]).pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
1745
+ } // 监听copy模块
1746
+
1747
+
1748
+ if ((tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gulp = tmsConfig.gulp) === null || _tmsConfig$gulp === void 0 ? void 0 : _tmsConfig$gulp.copyDir.length) > 0) {
1749
+ for (const item of (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.copyDir) {
1750
+ var _tmsConfig$gulp2;
1751
+
1752
+ src([item.from]).pipe(dest(item.to));
1753
+ }
1754
+ }
1755
+ };
1756
+ })(build$2);
1986
1757
 
1987
1758
  const shelljs = require$$5__default;
1988
- const webpackBuildServer = buildServer;
1989
1759
  const {
1990
1760
  resolve
1991
1761
  } = widgets;
1992
1762
  const init$3 = init$5;
1763
+ const gulpBuild = build$2.exports;
1993
1764
 
1994
1765
  async function build$1(tmsConfig, targetModules, env) {
1995
1766
  // 开始构建前,清理输出目录
1996
- await shelljs.rm('-rf', resolve('dist'));
1767
+ await shelljs.rm('-rf', resolve(tmsConfig.gulp.outputDir));
1997
1768
  const {
1998
1769
  targetModules: newModules
1999
1770
  } = await init$3(tmsConfig, targetModules);
2000
- webpackBuildServer(tmsConfig, newModules, env);
1771
+ gulpBuild(tmsConfig, newModules, env);
2001
1772
  }
2002
1773
 
2003
1774
  var build_1 = build$1;
@@ -2005,6 +1776,7 @@ var build_1 = build$1;
2005
1776
  const init$2 = init$5;
2006
1777
  const dev = dev_1;
2007
1778
  const build = build_1;
1779
+ const install = install_1;
2008
1780
  const {
2009
1781
  createTask
2010
1782
  } = widgets;
@@ -2023,8 +1795,13 @@ const handleModulesArg = cmd => {
2023
1795
  } // 单模块 或 多模块开发
2024
1796
 
2025
1797
 
1798
+ const {
1799
+ argv
1800
+ } = process;
1801
+ const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
1802
+
2026
1803
  if (cmd.module) {
2027
- return [cmd.module, ...cmd.args];
1804
+ return [cmd.module, ...reset];
2028
1805
  } // 全量模块
2029
1806
 
2030
1807
 
@@ -2058,6 +1835,10 @@ async function run(commandName, cmd) {
2058
1835
  dev(tmsConfig, modules, env);
2059
1836
  return;
2060
1837
 
1838
+ case 'install':
1839
+ install(tmsConfig, modules, env);
1840
+ return;
1841
+
2061
1842
  case 'build':
2062
1843
  build(tmsConfig, modules, env);
2063
1844
  return;
@@ -2076,17 +1857,43 @@ var entry = [{
2076
1857
  create_1(appName, cmd);
2077
1858
  }
2078
1859
  }, {
2079
- command: 'run <command-name>',
2080
- options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
2081
- description: '运行模块',
2082
- action: (commandName, cmd) => {
2083
- run_1(commandName, cmd);
2084
- }
1860
+ name: 'run',
1861
+ type: 'child',
1862
+ description: '项目开发使用的命令',
1863
+ commands: [{
1864
+ command: 'install',
1865
+ description: '安装依赖',
1866
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
1867
+ action: cmd => {
1868
+ run_1('install', cmd);
1869
+ }
1870
+ }, {
1871
+ command: 'dev',
1872
+ description: 'dev 打包编译',
1873
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
1874
+ action: cmd => {
1875
+ run_1('dev', cmd);
1876
+ }
1877
+ }, {
1878
+ command: 'build',
1879
+ description: 'prod 打包编译',
1880
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
1881
+ action: cmd => {
1882
+ run_1('build', cmd);
1883
+ }
1884
+ }, {
1885
+ command: 'init',
1886
+ description: '根据模块配置初始化项目(eg: 动态拷贝模块、下载依赖、生成app.json等)',
1887
+ options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
1888
+ action: cmd => {
1889
+ run_1('init', cmd);
1890
+ }
1891
+ }]
2085
1892
  }];
2086
1893
 
2087
1894
  var require$$6 = {
2088
1895
  name: "@tmsfe/tmskit",
2089
- version: "0.0.1",
1896
+ version: "0.0.5-beta.0",
2090
1897
  description: "tmskit",
2091
1898
  main: "main.js",
2092
1899
  bin: {
@@ -2104,50 +1911,39 @@ var require$$6 = {
2104
1911
  ]
2105
1912
  },
2106
1913
  devDependencies: {
2107
- "@babel/core": "^7.15.0",
2108
- "@babel/plugin-transform-modules-commonjs": "^7.16.0",
2109
- "@babel/preset-env": "^7.16.0",
2110
1914
  "@rollup/plugin-babel": "^5.0.2",
2111
1915
  "@rollup/plugin-commonjs": "^19.0.0",
2112
1916
  "@rollup/plugin-dynamic-import-vars": "^1.1.1",
2113
1917
  "@rollup/plugin-json": "^4.0.3",
2114
- async: "^3.2.2",
2115
- "babel-core": "^6.26.3",
2116
- "babel-loader": "^8.2.3",
2117
- "copy-webpack-plugin": "^9.1.0",
2118
- "cross-env": "^7.0.3",
2119
- leven: "3.1.0",
2120
- metalsmith: "^2.3.0",
2121
- minimist: "^1.2.5",
2122
1918
  rollup: "^2.6.1",
2123
1919
  "rollup-plugin-node-resolve": "^5.2.0",
1920
+ "rollup-plugin-replace": "^2.2.0",
2124
1921
  "rollup-plugin-terser": "^6.1.0",
2125
- "rollup-plugin-typescript2": "0.27.0",
2126
- "ts-loader": "^9.2.6",
2127
- "url-loader": "^4.1.1",
2128
- webpack: "^5.64.0",
2129
- "webpack-cli": "^4.9.1"
1922
+ "rollup-plugin-typescript2": "0.27.0"
2130
1923
  },
2131
1924
  dependencies: {
2132
- axios: "^0.21.4",
1925
+ async: "^3.2.2",
2133
1926
  chalk: "^4.1.0",
2134
- commander: "^6.2.1",
1927
+ commander: "^8.3.0",
1928
+ "copy-webpack-plugin": "^9.1.0",
2135
1929
  "download-git-repo": "^3.0.2",
2136
1930
  ejs: "^3.1.5",
2137
- "file-loader": "^6.2.0",
2138
- "fs-extra": "^9.0.1",
1931
+ "glob-ignore": "^1.0.2",
1932
+ gulp: "^4.0.2",
1933
+ "gulp-less": "^5.0.0",
1934
+ "gulp-px-to-rpx": "^1.0.7",
1935
+ "gulp-rename": "^2.0.0",
1936
+ "gulp-watch": "^5.0.1",
2139
1937
  inquirer: "^7.3.3",
1938
+ leven: "3.1.0",
2140
1939
  lodash: "^4.17.21",
2141
- "mini-css-extract-plugin": "^2.4.5",
1940
+ metalsmith: "^2.3.0",
2142
1941
  "miniprogram-ci": "1.4.13",
2143
1942
  ora: "^5.1.0",
1943
+ precinct: "^8.3.1",
2144
1944
  "replace-ext": "^2.0.0",
2145
- "rollup-plugin-replace": "^2.2.0",
2146
1945
  shelljs: "^0.8.4",
2147
- tslib: "^1.14.1",
2148
- typescript: "^3.8.3",
2149
- username: "5.1.0",
2150
- "webpack-chain": "^6.5.1"
1946
+ through2: "^4.0.2"
2151
1947
  },
2152
1948
  engines: {
2153
1949
  node: "^12.17.0 || >= 14.0.0"
@@ -2157,12 +1953,9 @@ var require$$6 = {
2157
1953
  }
2158
1954
  };
2159
1955
 
2160
- const {
2161
- exec
2162
- } = require$$5__default;
2163
1956
  const semver = require$$1__default$5;
2164
1957
  const packageJson = require$$6;
2165
- const chalk$1 = require$$0__default$1;
1958
+ const chalk$1 = require$$0__default$2;
2166
1959
  const {
2167
1960
  log: log$1
2168
1961
  } = widgets;
@@ -2192,17 +1985,13 @@ const checkNodeVersion = (wanted, id) => {
2192
1985
  function initCliContext() {
2193
1986
  // 执行操作前检查node版本
2194
1987
  // 旧版本node直接提示升级,退出脚本
2195
- checkNodeVersion(requiredVersion, packName); // 执行前配置正确的npm源
2196
-
2197
- exec('npm config set registry https://mirrors.tencent.com/npm/ --global', {
2198
- silent: true
2199
- });
1988
+ checkNodeVersion(requiredVersion, packName);
2200
1989
  }
2201
1990
 
2202
1991
  var init$1 = initCliContext;
2203
1992
 
2204
- const chalk = require$$0__default$1;
2205
- const program = require$$0__default;
1993
+ const chalk = require$$0__default$2;
1994
+ const commander = require$$0__default;
2206
1995
  const {
2207
1996
  log,
2208
1997
  suggestCommands
@@ -2213,19 +2002,33 @@ const {
2213
2002
  const commands = entry;
2214
2003
  const init = init$1;
2215
2004
  init();
2216
- program.version(`${TMS_NAME} ${require$$6.version}`);
2217
- commands.forEach(cmd => {
2218
- var _cmd$options;
2219
-
2220
- const command = program.command(cmd.command);
2221
- cmd.usage && command.usage(cmd.usage);
2222
- cmd.description && command.description(cmd.description);
2223
- (_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
2224
- command.action(cmd.action);
2225
- });
2005
+ const program = new commander.Command(TMS_NAME);
2006
+ program.version(`${TMS_NAME} ${require$$6.version}`, '-v, -V, --version');
2007
+
2008
+ function registerCommand(program, commands) {
2009
+ commands.forEach(cmd => {
2010
+ if (cmd.type === 'child') {
2011
+ const childProgram = new commander.Command(cmd.name);
2012
+ cmd.usage && childProgram.usage(cmd.usage);
2013
+ cmd.description && childProgram.description(cmd.description);
2014
+ registerCommand(childProgram, cmd.commands);
2015
+ program.addCommand(childProgram);
2016
+ } else {
2017
+ var _cmd$options;
2018
+
2019
+ const command = program.command(cmd.command);
2020
+ cmd.usage && command.usage(cmd.usage);
2021
+ cmd.description && command.description(cmd.description);
2022
+ (_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
2023
+ command.action(cmd.action);
2024
+ }
2025
+ });
2026
+ }
2027
+
2028
+ registerCommand(program, commands);
2226
2029
  program.on('--help', () => {
2227
2030
  log();
2228
- log(` Run ${chalk.cyan('tms <command> --help')} for detailed usage of given command.`);
2031
+ log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
2229
2032
  log();
2230
2033
  }); // 捕获未注册的命令
2231
2034