@tmsfe/tmskit 0.0.4 → 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
@@ -5,22 +5,23 @@ 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('gulp');
20
+ var require$$2$1 = require('gulp-px-to-rpx');
21
+ var require$$3$2 = require('gulp-less');
22
+ var require$$4 = require('gulp-rename');
23
+ var require$$5$1 = require('gulp-watch');
24
+ var require$$1$5 = require('semver');
24
25
 
25
26
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
26
27
 
@@ -29,22 +30,23 @@ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
29
30
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
30
31
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
31
32
  var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
32
- var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
33
+ var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
33
34
  var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
35
+ var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
34
36
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
35
- var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
36
37
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
37
38
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
39
+ var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
38
40
  var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
39
41
  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
42
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
43
+ var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
46
44
  var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
45
+ var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
47
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);
49
+ var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
48
50
 
49
51
  function getAugmentedNamespace(n) {
50
52
  if (n.__esModule) return n;
@@ -66,19 +68,19 @@ var src$1 = {};
66
68
  const program$1 = require$$0__default;
67
69
  const leven = require$$1__default;
68
70
  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;
71
+ const path$5 = require$$1__default$1;
72
+ const fs$a = require$$0__default$1;
73
+ const shelljs$5 = require$$5__default;
72
74
  const download = require$$6__default;
73
- const chalk$3 = require$$0__default$3;
75
+ const chalk$3 = require$$0__default$2;
74
76
  const shelljsOptons = {
75
77
  slient: true
76
78
  }; // 获取当前目录
77
79
 
78
80
  const cwd = process.cwd();
79
81
 
80
- function resolve$c(...args) {
81
- return path$7.resolve(cwd, ...args);
82
+ function resolve$a(...args) {
83
+ return path$5.resolve(cwd, ...args);
82
84
  }
83
85
  /**
84
86
  * 封装logs
@@ -147,11 +149,11 @@ function downloadRepo(dest, downloadOptions = {
147
149
  branch
148
150
  } = downloadOptions;
149
151
 
150
- if (fs$b.existsSync(dest)) {
151
- shelljs$6.rm('-rf', dest);
152
+ if (fs$a.existsSync(dest)) {
153
+ shelljs$5.rm('-rf', dest);
152
154
  }
153
155
 
154
- shelljs$6.mkdir('-p', dest);
156
+ shelljs$5.mkdir('-p', dest);
155
157
  return new Promise(resolve => {
156
158
  download(`${repoUrl}#${branch}`, dest, {
157
159
  clone: true
@@ -179,14 +181,14 @@ function downloadRepoForGit$2(url, dest, branch) {
179
181
  const cwd = process.cwd();
180
182
  return new Promise(resolve => {
181
183
  // 如果目标目录不存在
182
- if (fs$b.existsSync(dest)) {
183
- shelljs$6.rm('-rf', path$7.join(dest));
184
+ if (fs$a.existsSync(dest)) {
185
+ shelljs$5.rm('-rf', path$5.join(dest));
184
186
  }
185
187
 
186
- shelljs$6.mkdir('-p', dest);
187
- shelljs$6.cd(dest);
188
- shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptons);
189
- shelljs$6.cd(cwd);
188
+ shelljs$5.mkdir('-p', dest);
189
+ shelljs$5.cd(dest);
190
+ shelljs$5.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptons);
191
+ shelljs$5.cd(cwd);
190
192
  resolve();
191
193
  });
192
194
  }
@@ -207,7 +209,7 @@ const cost = start => Date.now() - start;
207
209
  */
208
210
 
209
211
 
210
- function createTask$5(task, startText, endText) {
212
+ function createTask$4(task, startText, endText) {
211
213
  return async (...args) => {
212
214
  const start = Date.now();
213
215
  let result;
@@ -237,43 +239,43 @@ function createTask$5(task, startText, endText) {
237
239
  const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
238
240
 
239
241
  var widgets = {
240
- resolve: resolve$c,
242
+ resolve: resolve$a,
241
243
  log: log$3,
242
244
  isObject: isObject$2,
243
245
  isArray: isArray$1,
244
- createTask: createTask$5,
246
+ createTask: createTask$4,
245
247
  downloadRepo,
246
248
  downloadRepoForGit: downloadRepoForGit$2,
247
249
  suggestCommands: suggestCommands$1,
248
250
  camelize
249
251
  };
250
252
 
251
- const path$6 = require('path'); // 用户目录
253
+ const path$4 = require('path'); // 用户目录
252
254
 
253
255
 
254
256
  const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
255
257
 
256
- const CACHE_DIR$1 = path$6.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
258
+ const CACHE_DIR$1 = path$4.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
257
259
 
258
- const TEMPLATE_DIR$1 = path$6.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
260
+ const TEMPLATE_DIR$1 = path$4.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
259
261
 
260
- const MODULE_CODE_DIR$1 = path$6.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
262
+ const MODULE_CODE_DIR$1 = path$4.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
261
263
 
262
- const TEMPLATE_PATH$1 = path$6.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
264
+ const TEMPLATE_PATH$1 = path$4.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
263
265
 
264
266
  const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
265
267
 
266
268
  const TMS_CONFIG_FILENAME$1 = 'tms.config.js'; // 模块代码的默认在modules子目录
267
269
 
268
- const DEFAULT_MODULE_DIR$5 = 'modules'; // 模块的配置文件的名称
270
+ const DEFAULT_MODULE_DIR$4 = 'modules'; // 模块的配置文件的名称
269
271
 
270
272
  const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
271
273
 
272
- const DEFAULT_WEBPACK_ENTRY$2 = {
273
- app: path$6.resolve(process.cwd(), 'app')
274
+ const DEFAULT_WEBPACK_ENTRY = {
275
+ app: path$4.resolve(process.cwd(), 'app')
274
276
  }; // 默认从源码拷贝到编译后的配置
275
277
 
276
- 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']; // 开发模式
277
279
 
278
280
  const MODE$1 = {
279
281
  main: 'tkitmain',
@@ -294,10 +296,10 @@ var constant = /*#__PURE__*/Object.freeze({
294
296
  TEMPLATE_PATH: TEMPLATE_PATH$1,
295
297
  TMS_NAME: TMS_NAME$2,
296
298
  TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
297
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$5,
299
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$4,
298
300
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
299
- DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY$2,
300
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$3,
301
+ DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
302
+ DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
301
303
  MODULE_CODE_DIR: MODULE_CODE_DIR$1,
302
304
  MODE: MODE$1,
303
305
  ENV: ENV,
@@ -306,14 +308,14 @@ var constant = /*#__PURE__*/Object.freeze({
306
308
 
307
309
  var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
308
310
 
309
- const fs$a = require$$0__default$1;
311
+ const fs$9 = require$$0__default$1;
310
312
  /**
311
313
  * 判断目录是否为空
312
314
  * @param {string} dirname 目录名
313
315
  * @returns
314
316
  */
315
317
 
316
- const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files.length === 0);
318
+ const isDirEmpty = dirname => fs$9.promises.readdir(dirname).then(files => files.length === 0);
317
319
  /**
318
320
  * 确保目录存在,不存在就创建一个
319
321
  * @param {*} dirname 目录名
@@ -321,8 +323,8 @@ const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files
321
323
 
322
324
 
323
325
  const ensureDirExist = dirname => {
324
- if (!fs$a.existsSync(dirname)) {
325
- fs$a.mkdirSync(dirname, {
326
+ if (!fs$9.existsSync(dirname)) {
327
+ fs$9.mkdirSync(dirname, {
326
328
  recursive: true
327
329
  });
328
330
  }
@@ -333,7 +335,7 @@ var io$2 = {
333
335
  ensureDirExist
334
336
  };
335
337
 
336
- const chalk$2 = require$$0__default$3;
338
+ const chalk$2 = require$$0__default$2;
337
339
  /**
338
340
  * 本文件提供无依赖的在终端打印彩色文字的方法。
339
341
  */
@@ -346,7 +348,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
346
348
  * @returns {undefined} 无
347
349
  */
348
350
 
349
- const fail$a = (message = '') => {
351
+ const fail$7 = (message = '') => {
350
352
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
351
353
 
352
354
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
@@ -379,12 +381,12 @@ const warn = message => {
379
381
  };
380
382
 
381
383
  var log$2 = {
382
- fail: fail$a,
384
+ fail: fail$7,
383
385
  succeed: succeed$1,
384
386
  warn
385
387
  };
386
388
 
387
- const async = require$$0__default$4;
389
+ const async = require$$0__default$3;
388
390
  const ejs = require$$1__default$2;
389
391
 
390
392
  const render$1 = (files, metalsmith, next) => {
@@ -404,10 +406,10 @@ const render$1 = (files, metalsmith, next) => {
404
406
 
405
407
  var render_1 = render$1;
406
408
 
407
- const fs$9 = require$$0__default$1;
409
+ const fs$8 = require$$0__default$1;
408
410
  const inquirer = require$$1__default$3;
409
411
  const {
410
- resolve: resolve$b
412
+ resolve: resolve$9
411
413
  } = widgets;
412
414
  const {
413
415
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -421,12 +423,12 @@ const {
421
423
  const parseTemplateQuestions = dir => {
422
424
  let prompts = [];
423
425
 
424
- if (!fs$9.existsSync(`${dir}/questions.json`)) {
426
+ if (!fs$8.existsSync(`${dir}/questions.json`)) {
425
427
  return prompts;
426
428
  }
427
429
 
428
430
  try {
429
- const json = JSON.parse(fs$9.readFileSync(`${dir}/questions.json`));
431
+ const json = JSON.parse(fs$8.readFileSync(`${dir}/questions.json`));
430
432
 
431
433
  if (Array.isArray(json) && json.length > 0) {
432
434
  json.forEach((item, index) => {
@@ -459,7 +461,7 @@ const isQuestionType = result => {
459
461
  };
460
462
 
461
463
  const ask$1 = templateDir => (files, metalsmith, next) => {
462
- const prompts = parseTemplateQuestions(resolve$b(templateDir, TEMPLATE_TKIT_DIR$1));
464
+ const prompts = parseTemplateQuestions(resolve$9(templateDir, TEMPLATE_TKIT_DIR$1));
463
465
  const metadata = metalsmith.metadata();
464
466
  const filteredPrompts = prompts.filter(prompt => {
465
467
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -484,7 +486,7 @@ var ask_1 = ask$1;
484
486
  const FILES_TO_IGNORE$1 = ['node_modules'];
485
487
  var ignoreFiles = FILES_TO_IGNORE$1;
486
488
 
487
- const Metalsmith = require$$0__default$5;
489
+ const Metalsmith = require$$0__default$4;
488
490
  const render = render_1;
489
491
  const ask = ask_1;
490
492
  const FILES_TO_IGNORE = ignoreFiles;
@@ -501,9 +503,9 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
501
503
 
502
504
  var generator_1 = generator$1;
503
505
 
504
- const path$5 = require$$1__default$1;
505
- const fs$8 = require$$0__default$1;
506
- const shelljs$5 = require$$0__default$2;
506
+ const path$3 = require$$1__default$1;
507
+ const fs$7 = require$$0__default$1;
508
+ const shelljs$4 = require$$5__default;
507
509
  const {
508
510
  TEMPLATE_DIR,
509
511
  TEMPLATE_PATH,
@@ -511,12 +513,12 @@ const {
511
513
  } = require$$3;
512
514
  const {
513
515
  downloadRepoForGit: downloadRepoForGit$1,
514
- createTask: createTask$4,
515
- resolve: resolve$a
516
+ createTask: createTask$3,
517
+ resolve: resolve$8
516
518
  } = widgets;
517
519
  const io$1 = io$2;
518
520
  const {
519
- fail: fail$9,
521
+ fail: fail$6,
520
522
  succeed
521
523
  } = log$2;
522
524
  const generator = generator_1;
@@ -528,13 +530,13 @@ const generator = generator_1;
528
530
 
529
531
  async function createAppDir(targetDir) {
530
532
  // 如果目录非空或者已经存在,提示用户,做选择
531
- if (fs$8.existsSync(targetDir)) {
533
+ if (fs$7.existsSync(targetDir)) {
532
534
  if (!(await io$1.isDirEmpty(targetDir))) {
533
- fail$9('该目录名已经存在,换个项目名字吧~');
535
+ fail$6('该目录名已经存在,换个项目名字吧~');
534
536
  process.exit(1);
535
537
  }
536
538
  } else {
537
- shelljs$5.mkdir('-p', targetDir);
539
+ shelljs$4.mkdir('-p', targetDir);
538
540
  }
539
541
  }
540
542
  /**
@@ -546,54 +548,54 @@ async function createAppDir(targetDir) {
546
548
 
547
549
  async function create(appName) {
548
550
  const cwd = process.cwd();
549
- const targetDir = path$5.resolve(cwd, appName);
551
+ const targetDir = path$3.resolve(cwd, appName);
550
552
  const appType = 'mp';
551
553
  await createAppDir(targetDir); // 创建缓存目录
552
554
 
553
555
  io$1.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
554
556
 
555
- await createTask$4(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
557
+ await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
556
558
 
557
- generator(path$5.join(TEMPLATE_PATH, appType), targetDir, {
559
+ generator(path$3.join(TEMPLATE_PATH, appType), targetDir, {
558
560
  appName,
559
561
  appType
560
562
  }).then(() => {
561
- shelljs$5.cd(appName);
563
+ shelljs$4.cd(appName);
562
564
 
563
- const hooks = require(resolve$a(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
565
+ const hooks = require(resolve$8(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
564
566
 
565
567
  if (hooks.afterCreate) {
566
568
  hooks.afterCreate.forEach(item => {
567
569
  if (typeof item === 'function') {
568
- item.call(null, shelljs$5, {
570
+ item.call(null, shelljs$4, {
569
571
  appName
570
572
  });
571
573
  } else {
572
- shelljs$5.exec(item);
574
+ shelljs$4.exec(item);
573
575
  }
574
576
  });
575
577
  }
576
578
 
577
- shelljs$5.rm('-rf', resolve$a(appName, TEMPLATE_TKIT_DIR));
579
+ shelljs$4.rm('-rf', resolve$8(appName, TEMPLATE_TKIT_DIR));
578
580
  succeed('项目创建完成.');
579
581
  }).catch(err => {
580
- fail$9(err.message);
582
+ fail$6(err.message);
581
583
  console.log('详细的错误信息:', err);
582
584
  });
583
585
  }
584
586
 
585
587
  var create_1 = create;
586
588
 
587
- const fs$7 = require$$0__default$1;
589
+ const fs$6 = require$$0__default$1;
588
590
  const {
589
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$4,
591
+ DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3,
590
592
  MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1
591
593
  } = require$$3;
592
594
  const {
593
- fail: fail$8
595
+ fail: fail$5
594
596
  } = log$2;
595
597
  const {
596
- resolve: resolve$9,
598
+ resolve: resolve$7,
597
599
  isObject: isObject$1,
598
600
  isArray
599
601
  } = widgets;
@@ -642,10 +644,10 @@ function getLocalModuleConfig(modules = [], appName, moduleDir, moduleConfigFile
642
644
  modules.forEach(({
643
645
  path
644
646
  }) => {
645
- const moduleConfigPath = resolve$9(path, moduleConfigFilename);
647
+ const moduleConfigPath = resolve$7(path, moduleConfigFilename);
646
648
 
647
- if (fs$7.existsSync(moduleConfigPath)) {
648
- const content = fs$7.readFileSync(moduleConfigPath, 'utf-8');
649
+ if (fs$6.existsSync(moduleConfigPath)) {
650
+ const content = fs$6.readFileSync(moduleConfigPath, 'utf-8');
649
651
  modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName, moduleDir);
650
652
  }
651
653
  });
@@ -670,7 +672,7 @@ function updateMainPackages(appJson, mainPackages = []) {
670
672
 
671
673
  foundMainPackages.forEach(subpackage => {
672
674
  if (!subpackage.pages || !subpackage.pages.length) {
673
- fail$8(`主包 ${subpackage} 不能没有 pages`);
675
+ fail$5(`主包 ${subpackage} 不能没有 pages`);
674
676
  process.exit(-1);
675
677
  }
676
678
 
@@ -696,12 +698,12 @@ function updateMainPackages(appJson, mainPackages = []) {
696
698
 
697
699
 
698
700
  const getAppJsonContent = sourceAppJsonPath => {
699
- if (!fs$7.existsSync(sourceAppJsonPath)) {
700
- fail$8(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
701
+ if (!fs$6.existsSync(sourceAppJsonPath)) {
702
+ fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
701
703
  process.exit(1);
702
704
  }
703
705
 
704
- const appJson = JSON.parse(fs$7.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
706
+ const appJson = JSON.parse(fs$6.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
705
707
 
706
708
  appJson.subpackages = [];
707
709
  appJson.pages = [];
@@ -732,245 +734,22 @@ const updateSubpackages = (appJson, modulesConfig) => {
732
734
  */
733
735
 
734
736
 
735
- function buildOutputAppJson$2(tmsConfig, modules) {
737
+ function buildOutputAppJson$1(tmsConfig, modules) {
736
738
  // 获取当前 modules 下的所有子模块的配置内容
737
- 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的配置
738
740
 
739
- const appJson = getAppJsonContent(resolve$9('./app.json')); // 更新app.json中的subpackages
741
+ const appJson = getAppJsonContent(resolve$7('./app.json')); // 更新app.json中的subpackages
740
742
 
741
743
  updateSubpackages(appJson, modulesConfig); // 更新主包,需在subpackages处理完成后执行, pages/
742
744
 
743
745
  updateMainPackages(appJson, tmsConfig.mainPackages);
744
- fs$7.writeFileSync(resolve$9(`${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');
745
747
  return appJson;
746
748
  }
747
749
 
748
750
  var buildAppJson = {
749
751
  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
752
+ buildOutputAppJson: buildOutputAppJson$1
974
753
  };
975
754
 
976
755
  class Globale {
@@ -1008,19 +787,19 @@ var global = {
1008
787
  getGlobalInstance: getGlobalInstance$1
1009
788
  };
1010
789
 
1011
- const MetalSmith = require$$0__default$5;
790
+ const MetalSmith = require$$0__default$4;
1012
791
  const {
1013
792
  getGlobalInstance
1014
793
  } = global;
1015
794
  const {
1016
795
  downloadRepoForGit,
1017
- resolve: resolve$8
796
+ resolve: resolve$6
1018
797
  } = widgets;
1019
798
  const {
1020
- fail: fail$7
799
+ fail: fail$4
1021
800
  } = log$2;
1022
801
  const fs$5 = require$$0__default$1;
1023
- const shelljs$4 = require$$0__default$2;
802
+ const shelljs$3 = require$$5__default;
1024
803
  /**
1025
804
  * 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
1026
805
  * @param { string } sourceDir 缓存文件夹
@@ -1034,7 +813,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
1034
813
  return new Promise(resolve => {
1035
814
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1036
815
  if (e) {
1037
- fail$7(e); // eslint-disable-line
816
+ fail$4(e); // eslint-disable-line
1038
817
 
1039
818
  console.log('MetalSmith 详细的错误信息:', e);
1040
819
  }
@@ -1077,9 +856,9 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
1077
856
  path
1078
857
  } = moduleInfo; // 源码临时存在的源目录
1079
858
 
1080
- let sourcePath = resolve$8(sourceDir, path); // 源码要放到目标目录
859
+ let sourcePath = resolve$6(sourceDir, path); // 源码要放到目标目录
1081
860
 
1082
- const targetPath = resolve$8(targetDir, path); // 设置模块的构建分支
861
+ const targetPath = resolve$6(targetDir, path); // 设置模块的构建分支
1083
862
 
1084
863
  const cloneBranch = buildGitTag && typeof buildGitTag === 'string' ? buildGitTag : 'master'; // 检查缓存中有没有
1085
864
 
@@ -1095,12 +874,12 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
1095
874
  }
1096
875
 
1097
876
  if (fs$5.existsSync(targetPath)) {
1098
- shelljs$4.rm('-rf', targetPath);
877
+ shelljs$3.rm('-rf', targetPath);
1099
878
  }
1100
879
 
1101
880
  await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
1102
881
  } catch (e) {
1103
- fail$7(`downLoadAndMoveModule ${e}`); // eslint-disable-line
882
+ fail$4(`downLoadAndMoveModule ${e}`); // eslint-disable-line
1104
883
 
1105
884
  process.exit(-1);
1106
885
  }
@@ -1115,7 +894,8 @@ var defaultTmsConfig$1 = {
1115
894
  envData: {},
1116
895
  // 模块配置信息
1117
896
  modules: [],
1118
- webpack: {
897
+ cloudDir: 'cloud',
898
+ gulp: {
1119
899
  /** 编译输出文件夹位置 */
1120
900
  outputDir: 'dist',
1121
901
 
@@ -1123,14 +903,11 @@ var defaultTmsConfig$1 = {
1123
903
  sourceDir: './',
1124
904
 
1125
905
  /** 源码Map */
1126
- sourceMap: 'none',
1127
-
1128
- /** 别名 */
1129
- alias: {}
906
+ copyDir: []
1130
907
  }
1131
908
  };
1132
909
 
1133
- const loadash = require$$0__default$7;
910
+ const loadash = require$$0__default$5;
1134
911
  const fs$4 = require$$0__default$1;
1135
912
  const {
1136
913
  TMS_NAME: TMS_NAME$1,
@@ -1138,7 +915,7 @@ const {
1138
915
  MODULE_CONFIG_FILENAME
1139
916
  } = require$$3;
1140
917
  const {
1141
- resolve: resolve$7,
918
+ resolve: resolve$5,
1142
919
  isObject
1143
920
  } = widgets;
1144
921
  const {
@@ -1146,7 +923,7 @@ const {
1146
923
  } = buildAppJson;
1147
924
  const defaultTmsConfig = defaultTmsConfig$1;
1148
925
  const {
1149
- fail: fail$6
926
+ fail: fail$3
1150
927
  } = log$2;
1151
928
  /**
1152
929
  * 读取tms.config.json
@@ -1154,10 +931,10 @@ const {
1154
931
  */
1155
932
 
1156
933
  const readTmsConfig$1 = function (env) {
1157
- const tmsConfigPath = resolve$7(TMS_CONFIG_FILENAME);
934
+ const tmsConfigPath = resolve$5(TMS_CONFIG_FILENAME);
1158
935
 
1159
936
  if (!fs$4.existsSync(tmsConfigPath)) {
1160
- fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
937
+ fail$3('当前执行目录没有tms.config.js的配置项,请进行配置');
1161
938
  process.exit(1);
1162
939
  }
1163
940
 
@@ -1186,7 +963,7 @@ const checkModules$1 = function (tmsConfig, modules) {
1186
963
  });
1187
964
 
1188
965
  if (targetModules.length === 0) {
1189
- fail$6(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
966
+ fail$3(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
1190
967
  process.exit(1);
1191
968
  }
1192
969
 
@@ -1207,7 +984,7 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName, moduleDir) => {
1207
984
  path: relativePath,
1208
985
  name: moduleName
1209
986
  }, moduleIndex) => {
1210
- const moduleConfigPath = resolve$7(relativePath, MODULE_CONFIG_FILENAME);
987
+ const moduleConfigPath = resolve$5(relativePath, MODULE_CONFIG_FILENAME);
1211
988
 
1212
989
  if (fs$4.existsSync(moduleConfigPath)) {
1213
990
  let moduleConfigContent = fs$4.readFileSync(moduleConfigPath, 'utf-8');
@@ -1236,547 +1013,514 @@ var tkitUtils = {
1236
1013
  tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3
1237
1014
  };
1238
1015
 
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 {
1253
- 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;
1270
- /**
1271
- * 拷贝package.json\模块的代码到编译输出目录
1272
- * @param { object } tmsConfig
1273
- * @param { array } modules
1274
- * @param { array } defaultFiles 默认需要拷贝的配置项
1275
- * @returns
1016
+ /* eslint-disable require-jsdoc */
1017
+ const ci = require$$0__default$6;
1018
+ const path$2 = require$$1__default$1;
1019
+ /**
1020
+ * 获取小程序ci的Project对象
1021
+ * @returns {Object} 小程序ci对象
1276
1022
  */
1277
1023
 
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));
1284
- }
1285
- }); // 拷贝模块的代码到编译输出目录
1024
+ const getMpCi = ({
1025
+ appId,
1026
+ projectPath,
1027
+ type = 'miniProgram',
1028
+ privateKey = 'TODO'
1029
+ }) => {
1030
+ var _cfgJsonContent$packO;
1286
1031
 
1287
- targetModules.forEach(item => {
1288
- const outputModuleDir = resolve$6(`${tmsConfig.webpack.outputDir}/${item.root}`);
1032
+ const cfgJsonContent = require(path$2.join(projectPath, 'project.config.json'));
1289
1033
 
1290
- if (!fs$3.existsSync(resolve$6(item.path))) {
1291
- fail$5(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1292
- process.exit(1);
1293
- }
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工具构建小程序
1294
1045
 
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
- });
1303
- }
1304
1046
 
1305
- shelljs$3.cp('-Rf', `${resolve$6(item.path)}/*`, outputModuleDir);
1047
+ const packMpProject = async project => {
1048
+ await ci.packNpm(project, {
1049
+ ignores: ['cloud/**/*']
1306
1050
  });
1307
1051
  };
1052
+ /**
1053
+ * 格式化构建npm结果信息
1054
+ * @param {Array<String>} warning 构建时的告警信息
1055
+ * @returns {String} npm构建错误信息
1056
+ */
1308
1057
 
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的配置项
1312
1058
 
1313
- const newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$3);
1314
- console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
1059
+ const formatPackNpmWarning = warning => {
1060
+ if (!warning) {
1061
+ return '';
1062
+ }
1315
1063
 
1316
- await createTask$3(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
+ */
1317
1072
 
1318
- await createTask$3(npmInstallAll, '开始npm install', 'npm install 完成')(newModules, resolve$6(tmsConfig.webpack.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1319
1073
 
1320
- await createTask$3(buildMpNpm$1, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1321
- appId: tmsConfig.appId,
1322
- projectPath: resolve$6('./'),
1323
- privateKey: tmsConfig.privateKey
1324
- }); // 动态生成编译后的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);
1325
1086
 
1326
- await createTask$3(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
1327
- return newModules;
1328
- }
1087
+ if (packNpmMsg) {
1088
+ return Promise.reject(packNpmMsg);
1089
+ }
1329
1090
 
1330
- async function bootstrap(tmsConfig, targetModules) {
1331
- const newModules = await task(tmsConfig, targetModules);
1332
- return {
1333
- targetModules: newModules
1334
- };
1335
- }
1091
+ return Promise.resolve();
1092
+ };
1336
1093
 
1337
- var init$5 = bootstrap;
1094
+ var mpCiUtils = {
1095
+ buildMpNpm: buildMpNpm$1
1096
+ };
1338
1097
 
1339
- const path$2 = require$$1__default$1;
1340
- const fs$2 = require$$0__default$1;
1341
- const {
1342
- resolve: resolve$5
1343
- } = widgets;
1344
- const {
1345
- buildOutputAppJson
1346
- } = buildAppJson;
1347
- const {
1348
- tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
1349
- } = tkitUtils;
1350
- const {
1351
- findAllPackageJson
1352
- } = npmUtils;
1353
- const {
1354
- fail: fail$4
1355
- } = log$2;
1356
- const replaceExt = require$$7__default;
1357
- const extensions = ['.ts', '.js'];
1098
+ /**
1099
+ * 本文件主要负责项目或者分包依赖的npm的安装
1100
+ */
1101
+ const fs$3 = require$$0__default$1;
1102
+ const path$1 = require$$1__default$1;
1103
+ const shell = require$$5__default;
1104
+ const glob = require$$3__default;
1105
+ const LOG = log$2;
1106
+ const dirpath = process.cwd(); // 项目根目录
1358
1107
 
1359
- function ext(entry, extensions) {
1360
- let newEntry = entry;
1108
+ const getTarNpmFilename = targetDir => `${targetDir.replace(/\//g, '-')}.tar.gz`; // 缓存npm包
1361
1109
 
1362
- try {
1363
- const stat = fs$2.lstatSync(newEntry);
1364
1110
 
1365
- if (stat.isDirectory()) {
1366
- newEntry += newEntry[newEntry.length - 1] === '/' ? 'index' : '/index';
1367
- }
1368
- } catch (e) {}
1111
+ const npmCache = function (targetDir, cacheDir) {
1112
+ if (!fs$3.existsSync(cacheDir)) {
1113
+ fs$3.mkdirSync(cacheDir);
1114
+ }
1369
1115
 
1370
- for (const ext of extensions) {
1371
- const file = replaceExt(newEntry, ext);
1116
+ const tarNpmFilename = getTarNpmFilename(targetDir);
1117
+ const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1372
1118
 
1373
- if (fs$2.existsSync(file)) {
1374
- return {
1375
- file,
1376
- ext
1377
- };
1378
- }
1119
+ if (fs$3.existsSync(tarNpmFilePath)) {
1120
+ shell.rm('-rf', tarNpmFilePath);
1379
1121
  }
1380
1122
 
1381
- return null;
1382
- } // 获取所有的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包
1383
1129
 
1384
1130
 
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);
1131
+ const getNpmCache = function (targetDir, cacheDir) {
1132
+ const tarNpmFilename = getTarNpmFilename(targetDir);
1133
+ const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
1392
1134
 
1393
- Object.keys(dependencies).forEach(dependence => {
1394
- alias[dependence] = path$2.join(path$2.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
1395
1140
  });
1396
- });
1397
- return alias;
1398
- } // 根据用户选择的modules,找到module.config.json的配置信息,找到所有的page
1399
-
1400
-
1401
- function getPageEntry(modules, tmsConfig, moduleDir) {
1402
- const entry = {}; // tms.config.js的modules 合并 module.config.json的配置项
1141
+ } // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
1403
1142
 
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`;
1143
+ }; // 遍历安装指定目录下所有项目的npm依赖
1412
1144
 
1413
- if (fs$2.existsSync(pageJsonPath)) {
1414
- const pageJsonContent = JSON.parse(fs$2.readFileSync(pageJsonPath, 'utf-8'));
1415
- const pageDir = path$2.dirname(pageJsonPath); // 该页面所在的目录
1416
1145
 
1417
- const extValue = ext(resolve$5(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);
1418
1151
 
1419
- if (!extValue) {
1420
- fail$4(`当前${page}找不到入口.js或.ts文件`);
1421
- process.exit(1);
1422
- }
1152
+ if (!fs$3.existsSync(`${dir}/node_modules`)) {
1153
+ getNpmCache(dir, cacheDir);
1154
+ }
1423
1155
 
1424
- const entryKey = `${root}/${page}${extValue.ext}`;
1425
- Object.assign(entry, {
1426
- [entryKey]: extValue.file
1427
- }, getComponentEntry(pageJsonContent, pageDir, path$2.dirname(entryKey)));
1428
- }
1156
+ shell.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
1157
+ silent: false
1429
1158
  });
1430
- });
1431
- return entry;
1432
- } // 根据appJson,获取所有的page
1433
-
1434
-
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
1159
+ resolve();
1160
+ npmCache(dir, cacheDir);
1161
+ })));
1162
+ };
1163
+ /**
1164
+ * 递归查找指定条件的文件
1165
+ * @param {String} startPath 开始查找的根路径
1166
+ * @param {String} filter 匹配的字符串
1167
+ * @returns {Array<String>} 查找到的文件路径列表
1168
+ */
1445
1169
 
1446
1170
 
1447
- function getComponentEntry(pageJson, pagePath, pageKey) {
1448
- const componentEntry = {};
1171
+ const findFilesByFilter = (startPath, filter) => {
1172
+ const result = [];
1173
+ /**
1174
+ * 根据指定的筛选器查找文件
1175
+ * @param {String} startPath 开始查找的文件夹路径
1176
+ * @param {String} filter 筛选器
1177
+ * @returns {Undefined} 无需返回值
1178
+ */
1449
1179
 
1450
- function task(json, dir, rootKey) {
1451
- if (!json.usingComponents) {
1180
+ const find = (startPath, filter) => {
1181
+ // 目录不存在
1182
+ if (!fs$3.existsSync(startPath)) {
1183
+ LOG.fail(`${startPath}目录不存在`);
1184
+ process.exit(-1);
1452
1185
  return;
1453
- }
1454
-
1455
- const componentKeys = Object.keys(json.usingComponents); // 如果存在依赖的组件
1186
+ } // 当前目录下的所有文件 / 文件夹
1456
1187
 
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]);
1463
1188
 
1464
- if (!extValue) {
1465
- fail$4(`当前page: ${pagePath} component: ${comValue}找不到入口.js或.ts文件`);
1466
- process.exit(1);
1467
- }
1189
+ const exceptDir = ['node_modules', 'miniprogram_npm'];
1468
1190
 
1469
- componentEntry[`${comKey.slice(1)}${extValue.ext}`] = extValue.file;
1470
- const comJsonPath = `${comValue}.json`;
1191
+ if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
1192
+ return;
1193
+ }
1471
1194
 
1472
- if (fs$2.existsSync(comJsonPath)) {
1473
- const comJsonContent = JSON.parse(fs$2.readFileSync(comJsonPath, 'utf-8'));
1474
- const comDir = path$2.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); // 当前文件是文件夹类型,继续递归
1475
1199
 
1476
- task(comJsonContent, comDir, path$2.dirname(comKey));
1477
- }
1200
+ if (stat.isDirectory()) {
1201
+ find(filename, filter);
1202
+ } else if (filename.indexOf(filter) >= 0) {
1203
+ // 文件类型
1204
+ result.push(filename);
1478
1205
  }
1479
1206
  });
1480
- }
1207
+ };
1481
1208
 
1482
- task(pageJson, pagePath, pageKey);
1483
- return componentEntry;
1484
- } // 根据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
+ */
1485
1218
 
1486
1219
 
1487
- function getCopyPlugin$2(defaultCopyConfig, modules, tmsConfig, env) {
1488
- const toPath = tmsConfig.webpack.outputDir;
1220
+ const findAllPackageJson = (subRoots = [], contextDir) => {
1221
+ const packageJsonName = 'package.json'; // 查找文件名
1489
1222
 
1490
- function generatorAppJson(tmsConfig, modules) {
1491
- try {
1492
- return buildOutputAppJson(tmsConfig, modules);
1493
- } catch (e) {
1494
- fail$4(`动态生成app.json出现错误${e} 请检查你的配置项`);
1495
- return {};
1496
- }
1497
- }
1223
+ const cwd = contextDir || dirpath;
1224
+ const result = [path$1.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
1498
1225
 
1499
- 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文件
1500
1229
 
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
- }
1509
- });
1510
- }
1511
- }); // 拷贝模块的代码
1230
+ const list = findFilesByFilter(toppath, packageJsonName);
1231
+ result.push(...list);
1232
+ });
1233
+ return result;
1234
+ };
1512
1235
 
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
- }
1527
-
1528
- return content;
1529
- } : 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);
1530
1241
  }
1531
- });
1532
- });
1533
1242
 
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
- }
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
+ });
1548
1249
  });
1250
+ resolve();
1549
1251
  });
1550
- }
1551
-
1552
- return patterns;
1553
- } // dev时,给webpack注入相应的事件
1554
-
1555
-
1556
- const setupDevWebPackHooks$1 = (context, firstDone) => {
1557
- let tempFirstDone = true;
1558
-
1559
- const invalid = () => {
1560
- // eslint-disable-next-line
1561
- context.stats = undefined;
1562
- };
1563
-
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();
1576
- }
1577
- });
1578
- };
1579
-
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
- };
1587
-
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
- });
1252
+ });
1253
+ }
1595
1254
 
1596
- var utils = {
1597
- getCopyPlugin: getCopyPlugin$2,
1598
- setupDevWebPackHooks: setupDevWebPackHooks$1,
1599
- getEntry: getEntry$2,
1600
- stringified: stringified$1,
1601
- getAlias: getAlias$1
1255
+ var npmUtils = {
1256
+ cloudNpmInstall: cloudNpmInstall$1,
1257
+ mpNpmInstallAll: mpNpmInstallAll$1,
1258
+ findAllPackageJson
1602
1259
  };
1603
1260
 
1604
- const WebpackChain = require$$0__default$8;
1605
- const webpack$2 = require$$0__default$9;
1606
- const {
1607
- getEntry: getEntry$1,
1608
- stringified,
1609
- getAlias
1610
- } = utils;
1611
1261
  const {
1262
+ createTask: createTask$2,
1612
1263
  resolve: resolve$4
1613
1264
  } = widgets;
1614
1265
  const {
1615
- DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY$1,
1266
+ buildMpNpm
1267
+ } = mpCiUtils;
1268
+ const {
1269
+ CACHE_DIR,
1616
1270
  DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$2
1617
1271
  } = require$$3;
1618
-
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
- }
1664
-
1665
- return webpackConfig;
1666
- };
1667
-
1668
- const SingleEntryPlugin = require$$0__default$a;
1669
1272
  const {
1670
- DEFAULT_WEBPACK_ENTRY,
1671
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$1
1672
- } = require$$3;
1273
+ cloudNpmInstall,
1274
+ mpNpmInstallAll
1275
+ } = npmUtils;
1673
1276
  const {
1674
- getEntry
1675
- } = utils;
1277
+ tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
1278
+ } = tkitUtils;
1676
1279
 
1677
- class EntryExtraPlugin {
1678
- constructor(options = {}) {
1679
- this.options = options;
1680
- }
1280
+ async function install$2(tmsConfig, modules, isCloud = true) {
1281
+ const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
1681
1282
 
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);
1688
- });
1689
- }
1283
+ await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$4(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1690
1284
 
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
- }
1285
+ await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1286
+ appId: tmsConfig.appId,
1287
+ projectPath: resolve$4('./'),
1288
+ privateKey: tmsConfig.privateKey
1289
+ }); // 安装云函数的
1701
1290
 
1291
+ isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$4(tmsConfig.cloudDir));
1702
1292
  }
1703
1293
 
1704
- var entryExtractPlugin = EntryExtraPlugin;
1294
+ var install_1 = install$2;
1705
1295
 
1706
- const webpackConfig$1 = base;
1296
+ const shelljs$2 = require$$5__default;
1297
+ const fs$2 = require$$0__default$1;
1298
+ const io = io$2;
1707
1299
  const {
1708
- 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
1709
1310
  } = require$$3;
1710
1311
  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
- };
1730
-
1731
- const webpack$1 = require$$0__default$9;
1732
- const webDevConfig = dev$2;
1312
+ cloneModules
1313
+ } = cloneModules_1;
1733
1314
  const {
1734
- setupDevWebPackHooks
1735
- } = utils;
1315
+ tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
1316
+ } = tkitUtils;
1736
1317
  const {
1737
- fail: fail$3
1318
+ fail: fail$2
1738
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
+ */
1739
1328
 
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);
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));
1755
1335
  }
1336
+ }); // 拷贝模块的package.json到编译输出目录
1337
+
1338
+ targetModules.forEach(item => {
1339
+ const outputModuleDir = resolve$3(`${tmsConfig.gulp.outputDir}/${item.root}`);
1756
1340
 
1757
- if (stats.hasErrors() || stats.hasWarnings()) {
1758
- console.log(stats.toString({
1759
- // 增加控制台颜色开关
1760
- colors: true
1761
- }));
1341
+ if (!fs$2.existsSync(resolve$3(item.path))) {
1342
+ fail$2(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1343
+ process.exit(1);
1762
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);
1763
1349
  });
1764
- return compiler;
1765
1350
  };
1766
1351
 
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
+
1767
1511
  const fs$1 = require$$0__default$1;
1768
- const semver$1 = require$$1__default$4;
1512
+ const semver$1 = require$$1__default$5;
1769
1513
  const {
1770
- resolve: resolve$3
1514
+ resolve: resolve$2
1771
1515
  } = widgets;
1772
- const path$1 = require$$1__default$1;
1516
+ const path = require$$1__default$1;
1773
1517
  const {
1774
- fail: fail$2
1518
+ fail: fail$1
1775
1519
  } = log$2;
1776
- const shelljs$2 = require$$0__default$2;
1520
+ const shelljs$1 = require$$5__default;
1777
1521
 
1778
1522
  const getLatestVersion = npmName => {
1779
- const data = shelljs$2.exec(`npm view ${npmName} version`);
1523
+ const data = shelljs$1.exec(`npm view ${npmName} version`);
1780
1524
  return data.stdout || '0.0.0';
1781
1525
  };
1782
1526
  /**
@@ -1794,17 +1538,17 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
1794
1538
  // 1.1根目录的package.json
1795
1539
 
1796
1540
  const packageArr = [{
1797
- srcPackageDir: path$1.join(cwd, packageJsonName),
1798
- destNpmDir: resolve$3(outputDir, 'node_modules')
1541
+ srcPackageDir: path.join(cwd, packageJsonName),
1542
+ destNpmDir: resolve$2(outputDir, 'node_modules')
1799
1543
  }]; // 1.2模块的package.json
1800
1544
 
1801
1545
  modules.forEach(item => {
1802
- const srcPackageDir = path$1.join(cwd, item.path, 'package.json');
1546
+ const srcPackageDir = path.join(cwd, item.path, 'package.json');
1803
1547
 
1804
1548
  if (fs$1.existsSync(srcPackageDir)) {
1805
1549
  packageArr.push({
1806
1550
  srcPackageDir,
1807
- destNpmDir: resolve$3(outputDir, item.root, 'node_modules')
1551
+ destNpmDir: resolve$2(outputDir, item.root, 'node_modules')
1808
1552
  });
1809
1553
  }
1810
1554
  }); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
@@ -1816,20 +1560,20 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
1816
1560
  try {
1817
1561
  dependencies = JSON.parse(packageJson).dependencies;
1818
1562
  } catch (e) {
1819
- fail$2(`解析${packageJson}报错,请检查是否是正确的json配置项`);
1563
+ fail$1(`解析${packageJson}报错,请检查是否是正确的json配置项`);
1820
1564
  process.exit(1);
1821
1565
  }
1822
1566
 
1823
1567
  const dependenciesKeys = Object.keys(dependencies);
1824
1568
 
1825
1569
  for (const key of dependenciesKeys) {
1826
- const depPath = path$1.join(item.destNpmDir, key);
1570
+ const depPath = path.join(item.destNpmDir, key);
1827
1571
 
1828
1572
  if (!fs$1.existsSync(depPath)) {
1829
1573
  return true;
1830
1574
  }
1831
1575
 
1832
- const depPackagePath = path$1.join(depPath, 'package.json');
1576
+ const depPackagePath = path.join(depPath, 'package.json');
1833
1577
 
1834
1578
  if (fs$1.existsSync(depPackagePath)) {
1835
1579
  const packageData = require(depPackagePath);
@@ -1856,10 +1600,10 @@ var checkDependencies_1 = {
1856
1600
  checkDependencies: checkDependencies$1
1857
1601
  };
1858
1602
 
1859
- const webpackServer = devServer;
1603
+ const gulpDev = dev$2.exports;
1860
1604
  const fs = require$$0__default$1;
1861
1605
  const {
1862
- resolve: resolve$2
1606
+ resolve: resolve$1
1863
1607
  } = widgets;
1864
1608
  const init$4 = init$5;
1865
1609
  const {
@@ -1872,7 +1616,7 @@ const {
1872
1616
  checkDependencies
1873
1617
  } = checkDependencies_1;
1874
1618
  const {
1875
- fail: fail$1
1619
+ fail
1876
1620
  } = log$2;
1877
1621
 
1878
1622
  function isInit(tmsConfig, targetModules, contextDir) {
@@ -1909,162 +1653,132 @@ function isInit(tmsConfig, targetModules, contextDir) {
1909
1653
  } // 判断源码目录是否有该模块
1910
1654
 
1911
1655
 
1912
- if (item.path && !fs.existsSync(resolve$2(item.path))) {
1913
- fail$1(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1656
+ if (item.path && !fs.existsSync(resolve$1(item.path))) {
1657
+ fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
1914
1658
  process.exit(1);
1915
1659
  }
1916
1660
  } // 判断package.json的版本是否有新的版本
1917
1661
 
1918
1662
 
1919
- return checkDependencies(targetModules, resolve$2('./'), tmsConfig.webpack.outputDir);
1663
+ return checkDependencies(targetModules, resolve$1('./'), tmsConfig.gulp.outputDir);
1920
1664
  }
1921
1665
 
1922
1666
  async function dev$1(tmsConfig, targetModules, env) {
1923
1667
  // tms.config.js的modules 合并 module.config.json的配置项
1924
1668
  let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR); // 判断是否进行init命令
1925
1669
 
1926
- if (isInit(tmsConfig, newModules, resolve$2('dist'))) {
1670
+ if (isInit(tmsConfig, newModules, resolve$1('dist'))) {
1927
1671
  // init函数会将 最新的tms.config.js的modules 合并 module.config.json的配置项 返回,不需要再做重复工作
1928
1672
  const initData = await init$4(tmsConfig, targetModules);
1929
1673
  newModules = initData.targetModules;
1930
1674
  }
1931
1675
 
1932
1676
  console.log('当前dev启动的有效模块', newModules.map(item => item.name));
1933
- webpackServer(tmsConfig, newModules, env);
1677
+ gulpDev(tmsConfig, newModules, env);
1934
1678
  }
1935
1679
 
1936
1680
  var dev_1 = dev$1;
1937
1681
 
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
- };
1682
+ var build$2 = {exports: {}};
1957
1683
 
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;
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;
1966
1703
 
1967
- function compilerRun(compiler) {
1968
- return new Promise(resolve => {
1969
- compiler.run((err, stats) => {
1970
- resolve({
1971
- err,
1972
- stats
1973
- });
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
+ }
1974
1714
  });
1975
- });
1976
- }
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
1977
1721
 
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);
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))); // 监听模块的文件
1985
1728
 
1986
- if (err) {
1987
- fail(err);
1988
- console.log('详细的错误信息:', err);
1989
- }
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文件
1990
1732
 
1991
- if (stats.hasErrors() || stats.hasWarnings()) {
1992
- console.log(stats.toString({
1993
- // 增加控制台颜色开关
1994
- colors: true,
1995
- errorDetails: true
1996
- }));
1997
- }
1998
- return compiler;
1999
- };
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);
2000
1757
 
2001
- const shelljs$1 = require$$0__default$2;
2002
- const webpackBuildServer = buildServer;
1758
+ const shelljs = require$$5__default;
2003
1759
  const {
2004
- resolve: resolve$1
1760
+ resolve
2005
1761
  } = widgets;
2006
1762
  const init$3 = init$5;
1763
+ const gulpBuild = build$2.exports;
2007
1764
 
2008
1765
  async function build$1(tmsConfig, targetModules, env) {
2009
1766
  // 开始构建前,清理输出目录
2010
- await shelljs$1.rm('-rf', resolve$1('dist'));
1767
+ await shelljs.rm('-rf', resolve(tmsConfig.gulp.outputDir));
2011
1768
  const {
2012
1769
  targetModules: newModules
2013
1770
  } = await init$3(tmsConfig, targetModules);
2014
- webpackBuildServer(tmsConfig, newModules, env);
1771
+ gulpBuild(tmsConfig, newModules, env);
2015
1772
  }
2016
1773
 
2017
1774
  var build_1 = build$1;
2018
1775
 
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
1776
  const init$2 = init$5;
2062
1777
  const dev = dev_1;
2063
1778
  const build = build_1;
2064
1779
  const install = install_1;
2065
1780
  const {
2066
- createTask,
2067
- resolve
1781
+ createTask
2068
1782
  } = widgets;
2069
1783
  const {
2070
1784
  MODE
@@ -2081,8 +1795,13 @@ const handleModulesArg = cmd => {
2081
1795
  } // 单模块 或 多模块开发
2082
1796
 
2083
1797
 
1798
+ const {
1799
+ argv
1800
+ } = process;
1801
+ const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
1802
+
2084
1803
  if (cmd.module) {
2085
- return [cmd.module, ...cmd.args];
1804
+ return [cmd.module, ...reset];
2086
1805
  } // 全量模块
2087
1806
 
2088
1807
 
@@ -2090,11 +1809,6 @@ const handleModulesArg = cmd => {
2090
1809
  };
2091
1810
 
2092
1811
  async function run(commandName, cmd) {
2093
- if (commandName === 'install') {
2094
- install(resolve('./'));
2095
- return;
2096
- }
2097
-
2098
1812
  const moduleArg = handleModulesArg(cmd);
2099
1813
  const {
2100
1814
  env
@@ -2121,6 +1835,10 @@ async function run(commandName, cmd) {
2121
1835
  dev(tmsConfig, modules, env);
2122
1836
  return;
2123
1837
 
1838
+ case 'install':
1839
+ install(tmsConfig, modules, env);
1840
+ return;
1841
+
2124
1842
  case 'build':
2125
1843
  build(tmsConfig, modules, env);
2126
1844
  return;
@@ -2139,17 +1857,43 @@ var entry = [{
2139
1857
  create_1(appName, cmd);
2140
1858
  }
2141
1859
  }, {
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
- }
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
+ }]
2148
1892
  }];
2149
1893
 
2150
1894
  var require$$6 = {
2151
1895
  name: "@tmsfe/tmskit",
2152
- version: "0.0.4",
1896
+ version: "0.0.5-beta.0",
2153
1897
  description: "tmskit",
2154
1898
  main: "main.js",
2155
1899
  bin: {
@@ -2180,22 +1924,26 @@ var require$$6 = {
2180
1924
  dependencies: {
2181
1925
  async: "^3.2.2",
2182
1926
  chalk: "^4.1.0",
2183
- commander: "^6.2.1",
1927
+ commander: "^8.3.0",
2184
1928
  "copy-webpack-plugin": "^9.1.0",
2185
1929
  "download-git-repo": "^3.0.2",
2186
1930
  ejs: "^3.1.5",
2187
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",
2188
1937
  inquirer: "^7.3.3",
2189
1938
  leven: "3.1.0",
2190
1939
  lodash: "^4.17.21",
2191
1940
  metalsmith: "^2.3.0",
2192
1941
  "miniprogram-ci": "1.4.13",
2193
1942
  ora: "^5.1.0",
1943
+ precinct: "^8.3.1",
2194
1944
  "replace-ext": "^2.0.0",
2195
1945
  shelljs: "^0.8.4",
2196
- "ts-loader": "^9.2.6",
2197
- webpack: "^5.64.0",
2198
- "webpack-chain": "^6.5.1"
1946
+ through2: "^4.0.2"
2199
1947
  },
2200
1948
  engines: {
2201
1949
  node: "^12.17.0 || >= 14.0.0"
@@ -2205,12 +1953,9 @@ var require$$6 = {
2205
1953
  }
2206
1954
  };
2207
1955
 
2208
- const {
2209
- exec
2210
- } = require$$0__default$2;
2211
- const semver = require$$1__default$4;
1956
+ const semver = require$$1__default$5;
2212
1957
  const packageJson = require$$6;
2213
- const chalk$1 = require$$0__default$3;
1958
+ const chalk$1 = require$$0__default$2;
2214
1959
  const {
2215
1960
  log: log$1
2216
1961
  } = widgets;
@@ -2240,17 +1985,13 @@ const checkNodeVersion = (wanted, id) => {
2240
1985
  function initCliContext() {
2241
1986
  // 执行操作前检查node版本
2242
1987
  // 旧版本node直接提示升级,退出脚本
2243
- checkNodeVersion(requiredVersion, packName); // 执行前配置正确的npm源
2244
-
2245
- exec('npm config set registry https://mirrors.tencent.com/npm/ --global', {
2246
- silent: true
2247
- });
1988
+ checkNodeVersion(requiredVersion, packName);
2248
1989
  }
2249
1990
 
2250
1991
  var init$1 = initCliContext;
2251
1992
 
2252
- const chalk = require$$0__default$3;
2253
- const program = require$$0__default;
1993
+ const chalk = require$$0__default$2;
1994
+ const commander = require$$0__default;
2254
1995
  const {
2255
1996
  log,
2256
1997
  suggestCommands
@@ -2261,19 +2002,33 @@ const {
2261
2002
  const commands = entry;
2262
2003
  const init = init$1;
2263
2004
  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
- });
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);
2274
2029
  program.on('--help', () => {
2275
2030
  log();
2276
- 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.`);
2277
2032
  log();
2278
2033
  }); // 捕获未注册的命令
2279
2034