@tmsfe/tmskit 0.0.24 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -5,25 +5,25 @@ var require$$1 = require('moment');
5
5
  var require$$0 = require('ora');
6
6
  var require$$1$1 = require('path');
7
7
  var require$$0$1 = require('fs');
8
- var require$$2 = require('shelljs');
8
+ var require$$0$2 = require('shelljs');
9
9
  var require$$4 = require('glob-ignore');
10
10
  var require$$1$2 = require('os');
11
- var require$$0$2 = require('lodash');
12
- var require$$0$3 = require('async');
11
+ var require$$0$3 = require('lodash');
12
+ var require$$0$4 = require('async');
13
13
  var require$$1$3 = require('ejs');
14
14
  var require$$1$4 = require('inquirer');
15
- var require$$0$4 = require('metalsmith');
16
- var require$$0$5 = require('request');
15
+ var require$$0$5 = require('metalsmith');
16
+ var require$$0$6 = require('request');
17
17
  var require$$10 = require('unzipper');
18
18
  var require$$1$5 = require('crypto');
19
- var require$$0$6 = require('miniprogram-ci');
19
+ var require$$0$7 = require('miniprogram-ci');
20
20
  var require$$1$6 = require('fs-extra');
21
21
  var require$$1$7 = require('semver');
22
- var require$$0$7 = require('gulp');
23
- var require$$2$1 = require('minimatch');
22
+ var require$$0$8 = require('gulp');
23
+ var require$$2 = require('minimatch');
24
24
  var require$$3$1 = require('gulp-if');
25
25
  var require$$6 = require('through2');
26
- var require$$0$8 = require('object-assign');
26
+ var require$$0$9 = require('object-assign');
27
27
  var require$$3$2 = require('fancy-log');
28
28
  var require$$4$1 = require('ansi-colors');
29
29
  var require$$5 = require('chokidar');
@@ -32,7 +32,7 @@ var require$$7 = require('vinyl-file');
32
32
  var require$$8 = require('vinyl');
33
33
  var require$$9 = require('anymatch');
34
34
  var require$$11 = require('glob-parent');
35
- var require$$2$2 = require('plugin-error');
35
+ var require$$2$1 = require('plugin-error');
36
36
  var require$$10$1 = require('path-is-absolute');
37
37
  var require$$12$1 = require('slash');
38
38
  var require$$1$8 = require('commander');
@@ -44,25 +44,25 @@ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
44
44
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
45
45
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
46
46
  var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
47
- var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
47
+ var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
48
48
  var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
49
49
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
50
- var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
51
50
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
51
+ var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
52
52
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
53
53
  var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
54
- var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
55
54
  var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
55
+ var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
56
56
  var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
57
57
  var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
58
- var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
58
+ var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
59
59
  var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
60
60
  var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
61
- var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
62
- var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
61
+ var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
62
+ var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
63
63
  var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
64
64
  var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
65
- var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
65
+ var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
66
66
  var require$$3__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
67
67
  var require$$4__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
68
68
  var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
@@ -71,15 +71,15 @@ var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
71
71
  var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
72
72
  var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
73
73
  var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
74
- var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
74
+ var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
75
75
  var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
76
76
  var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12$1);
77
77
  var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
78
78
 
79
- var src$2 = {};
79
+ var src$3 = {};
80
80
 
81
81
  const chalk$4 = require$$3__default;
82
- const moment = require$$1__default;
82
+ const moment$1 = require$$1__default;
83
83
  /**
84
84
  * 本文件提供无依赖的在终端打印彩色文字的方法。
85
85
  */
@@ -92,12 +92,12 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
92
92
  * @returns {undefined} 无
93
93
  */
94
94
 
95
- const fail$9 = (message = '') => {
95
+ const fail$a = (message = '') => {
96
96
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
97
97
 
98
98
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
99
99
 
100
- console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
100
+ console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
101
101
  };
102
102
  /**
103
103
  * 打印绿底黑字格式的文字
@@ -111,7 +111,7 @@ const succeed$2 = (message = '') => {
111
111
 
112
112
  const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
113
113
 
114
- console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
114
+ console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
115
115
  };
116
116
  /**
117
117
  * 打印warn提示
@@ -121,28 +121,28 @@ const succeed$2 = (message = '') => {
121
121
 
122
122
 
123
123
  const warn$2 = message => {
124
- console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$4.yellow(message));
124
+ console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, chalk$4.yellow(message));
125
125
  };
126
126
 
127
- const info$d = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
127
+ const info$j = (...args) => console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
128
128
 
129
- const infoNoTime$2 = (...args) => console.log(...args);
129
+ const infoNoTime$1 = (...args) => console.log(...args);
130
130
 
131
131
  var log$1 = {
132
- fail: fail$9,
132
+ fail: fail$a,
133
133
  succeed: succeed$2,
134
134
  warn: warn$2,
135
- info: info$d,
136
- infoNoTime: infoNoTime$2
135
+ info: info$j,
136
+ infoNoTime: infoNoTime$1
137
137
  };
138
138
 
139
- const ora$1 = require$$0__default;
140
- const path$f = require$$1__default$1;
141
- const fs$g = require$$0__default$1;
142
- const shelljs$9 = require$$2__default;
139
+ const ora$2 = require$$0__default;
140
+ const path$g = require$$1__default$1;
141
+ const fs$j = require$$0__default$1;
142
+ const shelljs$7 = require$$0__default$2;
143
143
  const glob = require$$4__default;
144
144
  const {
145
- info: info$c
145
+ info: info$i
146
146
  } = log$1;
147
147
  const shelljsOptions = {
148
148
  slient: true,
@@ -151,8 +151,8 @@ const shelljsOptions = {
151
151
 
152
152
  const cwd = process.cwd();
153
153
 
154
- function resolve$e(...args) {
155
- return path$f.resolve(cwd, ...args);
154
+ function resolve$j(...args) {
155
+ return path$g.resolve(cwd, ...args);
156
156
  }
157
157
  /**
158
158
  * 判断变量是否是一个数组
@@ -186,20 +186,20 @@ function downloadRepoForGit$1(url, dest, branch) {
186
186
  const cwd = process.cwd();
187
187
  return new Promise((resolve, reject) => {
188
188
  // 如果目标目录不存在
189
- if (fs$g.existsSync(dest)) {
190
- shelljs$9.rm('-rf', path$f.join(dest));
189
+ if (fs$j.existsSync(dest)) {
190
+ shelljs$7.rm('-rf', path$g.join(dest));
191
191
  }
192
192
 
193
- shelljs$9.mkdir('-p', dest);
194
- shelljs$9.cd(dest);
195
- shelljs$9.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
193
+ shelljs$7.mkdir('-p', dest);
194
+ shelljs$7.cd(dest);
195
+ shelljs$7.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
196
196
  silent: true
197
197
  }, (code, stdout, stderr) => {
198
198
  if (code !== 0) {
199
199
  reject(stderr);
200
200
  }
201
201
 
202
- shelljs$9.cd(cwd);
202
+ shelljs$7.cd(cwd);
203
203
  resolve();
204
204
  });
205
205
  });
@@ -215,16 +215,16 @@ function downloadRepoForGit$1(url, dest, branch) {
215
215
  function pullRepoForGit$1(dest, branch) {
216
216
  const cwd = process.cwd();
217
217
  return new Promise((resolve, reject) => {
218
- shelljs$9.cd(dest);
219
- shelljs$9.exec('git config pull.rebase false', shelljsOptions);
220
- shelljs$9.exec(`git pull origin ${branch}`, {
218
+ shelljs$7.cd(dest);
219
+ shelljs$7.exec('git config pull.rebase false', shelljsOptions);
220
+ shelljs$7.exec(`git pull origin ${branch}`, {
221
221
  silent: true
222
222
  }, (code, stdout, stderr) => {
223
223
  if (code !== 0) {
224
224
  reject(stderr);
225
225
  }
226
226
 
227
- shelljs$9.cd(cwd);
227
+ shelljs$7.cd(cwd);
228
228
  resolve();
229
229
  });
230
230
  });
@@ -237,10 +237,10 @@ function pullRepoForGit$1(dest, branch) {
237
237
  */
238
238
 
239
239
 
240
- function npmInstall$2(dir, npmConfig) {
240
+ function npmInstall$3(dir, npmConfig) {
241
241
  return new Promise((resolve, reject) => {
242
242
  const registry = getNpmRegistry(npmConfig);
243
- shelljs$9.exec(`npm install --production ${registry}`, {
243
+ shelljs$7.exec(`npm install --production ${registry}`, {
244
244
  cwd: dir,
245
245
  silent: true
246
246
  }, (code, stdout, stderr) => {
@@ -293,11 +293,11 @@ const cost = start => Date.now() - start;
293
293
  */
294
294
 
295
295
 
296
- function createTask$3(task, startText, endText) {
296
+ function createTask$6(task, startText, endText) {
297
297
  return async (...args) => {
298
298
  const start = Date.now();
299
- const spinner = ora$1();
300
- info$c(startText);
299
+ const spinner = ora$2();
300
+ info$i(startText);
301
301
  spinner.start();
302
302
  const result = await task(...args);
303
303
  endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
@@ -322,7 +322,7 @@ const mergeMap$1 = function (obj, src) {
322
322
  };
323
323
 
324
324
  const relativeCwdPath$1 = function (file) {
325
- return path$f.relative(process.cwd(), file);
325
+ return path$g.relative(process.cwd(), file);
326
326
  };
327
327
  /**
328
328
  * 从一个对象中,检索出去几个字段
@@ -332,7 +332,7 @@ const relativeCwdPath$1 = function (file) {
332
332
  */
333
333
 
334
334
 
335
- const filterField$5 = (obj, filterNames = []) => {
335
+ const filterField$7 = (obj, filterNames = []) => {
336
336
  const newObj = { ...obj
337
337
  };
338
338
  filterNames.forEach(name => {
@@ -357,15 +357,15 @@ function findFiles(globPath, filter = []) {
357
357
  } // 获取绝对路径
358
358
 
359
359
 
360
- function getAbsolutePath$3(pathDir, cwd = '') {
360
+ function getAbsolutePath$6(pathDir, cwd = '') {
361
361
  let newPath = pathDir;
362
- newPath = newPath.startsWith('/') ? newPath : resolve$e(cwd, newPath);
362
+ newPath = newPath.startsWith('/') ? newPath : resolve$j(cwd, newPath);
363
363
  newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
364
364
  return newPath;
365
365
  } // 版本比较 => 1(大于), 0(等于), -1(小于)
366
366
 
367
367
 
368
- function versionCompare$1(v1, v2) {
368
+ function versionCompare(v1, v2) {
369
369
  // 将两个版本号拆成数组
370
370
  const arr1 = v1.split('.');
371
371
  const arr2 = v2.split('.');
@@ -385,46 +385,55 @@ function versionCompare$1(v1, v2) {
385
385
  return arr1.length > arr2.length ? 1 : -1;
386
386
  }
387
387
 
388
+ function getGitUser$2() {
389
+ const res = shelljs$7.exec('git config user.name', {
390
+ async: false,
391
+ silent: true
392
+ });
393
+ return res.stdout;
394
+ }
395
+
388
396
  var widgets = {
389
- resolve: resolve$e,
397
+ resolve: resolve$j,
390
398
  isObject,
391
399
  isArray,
392
- createTask: createTask$3,
400
+ createTask: createTask$6,
393
401
  downloadRepoForGit: downloadRepoForGit$1,
394
402
  pullRepoForGit: pullRepoForGit$1,
395
403
  camelize,
396
- npmInstall: npmInstall$2,
404
+ npmInstall: npmInstall$3,
397
405
  mergeMap: mergeMap$1,
398
406
  relativeCwdPath: relativeCwdPath$1,
399
- filterField: filterField$5,
407
+ filterField: filterField$7,
400
408
  findFiles,
401
- getAbsolutePath: getAbsolutePath$3,
409
+ getAbsolutePath: getAbsolutePath$6,
402
410
  getNpmRegistry,
403
- versionCompare: versionCompare$1
411
+ versionCompare,
412
+ getGitUser: getGitUser$2
404
413
  };
405
414
 
406
415
  var tmsMpconfig = {exports: {}};
407
416
 
408
- const path$e = require$$1__default$1;
417
+ const path$f = require$$1__default$1;
409
418
  const os = require$$1__default$2; // 用户目录
410
419
 
411
420
  const HOME_DIR = os.homedir(); // 所有文件的缓存目录
412
421
 
413
- const CACHE_DIR = path$e.resolve(HOME_DIR, '.tmskit'); // 版本管理的CDN地址
422
+ const CACHE_DIR = path$f.resolve(HOME_DIR, '.tmskit'); // 版本管理的CDN地址
414
423
 
415
- const VERSION_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json'; // version缓存文件
424
+ const VERSION_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json'; // version缓存文件
416
425
 
417
- const VERSION_CACHE_FILE$1 = path$e.resolve(CACHE_DIR, 'version_cache_file.json'); // npm缓存文件
426
+ const VERSION_CACHE_FILE = path$f.resolve(CACHE_DIR, 'version_cache_file.json'); // npm缓存文件
418
427
 
419
- const NPM_CACHE_FILE$1 = path$e.resolve(CACHE_DIR, 'npm_cache_file.json'); // 脚手架模板代码所在目录
428
+ const NPM_CACHE_FILE$1 = path$f.resolve(CACHE_DIR, 'npm_cache_file.json'); // 脚手架模板代码所在目录
420
429
 
421
- const TEMPLATE_DIR$1 = path$e.resolve(CACHE_DIR, 'template'); // 第三方模块源码存放的临时缓存目录
430
+ const TEMPLATE_DIR$1 = path$f.resolve(CACHE_DIR, 'template'); // 第三方模块源码存放的临时缓存目录
422
431
 
423
- const MODULE_CODE_DIR$2 = path$e.resolve(CACHE_DIR, 'modules_code'); // 缓存分包node_modules的目录
432
+ const MODULE_CODE_DIR$2 = path$f.resolve(CACHE_DIR, 'modules_code'); // 缓存分包node_modules的目录
424
433
 
425
- const NODE_MODULES_DIR$2 = path$e.resolve(CACHE_DIR, 'node_modules'); // 扩展命令源码的存放处
434
+ const NODE_MODULES_DIR$2 = path$f.resolve(CACHE_DIR, 'node_modules'); // 扩展命令源码的存放处
426
435
 
427
- const EXTEND_CMD$1 = path$e.resolve(CACHE_DIR, 'cmd'); // 创建模板的名称
436
+ const EXTEND_CMD$1 = path$f.resolve(CACHE_DIR, 'cmd'); // 创建模板的名称
428
437
 
429
438
  const TEMPLATE_NAME$1 = 'tmskit-template'; // 脚手架模板的远程地址
430
439
 
@@ -442,7 +451,7 @@ const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
442
451
  const MODULE_CONFIG_FILENAME = 'module.config.json'; // 默认的webpack entry
443
452
 
444
453
  const DEFAULT_WEBPACK_ENTRY = {
445
- app: path$e.resolve(process.cwd(), 'app')
454
+ app: path$f.resolve(process.cwd(), 'app')
446
455
  }; // 默认从源码拷贝到编译后的配置
447
456
 
448
457
  const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json', 'project.config.json'];
@@ -473,7 +482,7 @@ var constant = {
473
482
  HOME_DIR,
474
483
  CACHE_DIR,
475
484
  NPM_CACHE_FILE: NPM_CACHE_FILE$1,
476
- VERSION_CACHE_FILE: VERSION_CACHE_FILE$1,
485
+ VERSION_CACHE_FILE,
477
486
  TEMPLATE_DIR: TEMPLATE_DIR$1,
478
487
  TEMPLATE_NAME: TEMPLATE_NAME$1,
479
488
  TMS_NAME: TMS_NAME$1,
@@ -491,7 +500,7 @@ var constant = {
491
500
  DEFAULT_CLOUD_MODULE_DIR,
492
501
  CREATE_TEMPLATE_QUESTION: CREATE_TEMPLATE_QUESTION$1,
493
502
  TEMPLATE_URL: TEMPLATE_URL$1,
494
- VERSION_URL: VERSION_URL$1
503
+ VERSION_URL
495
504
  };
496
505
 
497
506
  var defaultTmsConfig = {
@@ -510,7 +519,36 @@ var defaultTmsConfig = {
510
519
  sourceDir: './',
511
520
 
512
521
  /** 静态资源目录 */
513
- static: []
522
+ static: [],
523
+
524
+ /** 上传是的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E7%BC%96%E8%AF%91%E8%AE%BE%E7%BD%AE */
525
+ upload: {
526
+ setting: {
527
+ es6: true,
528
+ es7: true,
529
+ minify: true,
530
+ minifyJS: true,
531
+ minifyWXML: true,
532
+ minifyWXSS: true,
533
+ autoPrefixWXSS: true
534
+ }
535
+ },
536
+
537
+ /** 预览的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88 */
538
+ preview: {
539
+ setting: {
540
+ es6: true,
541
+ es7: true,
542
+ minify: true,
543
+ minifyJS: true,
544
+ minifyWXML: true,
545
+ minifyWXSS: true,
546
+ autoPrefixWXSS: true
547
+ }
548
+ },
549
+ npm: {
550
+ registry: 'https://registry.npmjs.org/'
551
+ }
514
552
  };
515
553
 
516
554
  /**
@@ -519,7 +557,7 @@ var defaultTmsConfig = {
519
557
 
520
558
  (function (module) {
521
559
  /* eslint-disable no-param-reassign, no-nested-ternary */
522
- const loadash = require$$0__default$2;
560
+ const loadash = require$$0__default$3;
523
561
  const fs = require$$0__default$1;
524
562
  const path = require$$1__default$1;
525
563
  const {
@@ -659,18 +697,10 @@ var defaultTmsConfig = {
659
697
  return content;
660
698
  }
661
699
 
662
- const adaptDependencies = function (dependencies, subPackages) {
663
- const newDependencies = dependencies || [];
664
- subPackages.forEach(item => {
665
- if (item.dependencies) {
666
- dependencies = newDependencies.concat(item.dependencies);
667
- }
668
- });
669
- return newDependencies;
670
- };
671
-
672
700
  const adaptSubPackages = function (moduleConfig, appName) {
673
- const subPackages = isObject(moduleConfig) && moduleConfig.subPackages ? moduleConfig.subPackages : isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
701
+ const {
702
+ subPackages
703
+ } = moduleConfig;
674
704
  return adaptMpCgContent(subPackages, appName);
675
705
  };
676
706
  /**
@@ -694,10 +724,8 @@ var defaultTmsConfig = {
694
724
 
695
725
 
696
726
  const subPackages = adaptSubPackages(moduleConfig, appName);
697
- const dependencies = adaptDependencies(moduleConfig.dependencies, subPackages);
698
727
  moduleConfig = { ...(isObject(moduleConfig) ? moduleConfig : {}),
699
- subPackages,
700
- dependencies
728
+ subPackages
701
729
  }; // 兼容逻辑--- end
702
730
 
703
731
  modulesConfig.push(moduleConfig);
@@ -747,10 +775,7 @@ var defaultTmsConfig = {
747
775
  const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
748
776
  const newModuleItem = { ...tmsModuleItem,
749
777
  ...moduleConfig
750
- }; // 兼容逻辑
751
-
752
- if (!newModuleItem.moduleName) newModuleItem.moduleName = newModuleItem.name;
753
- delete newModuleItem.name; // 参数校验-模块源码路径
778
+ }; // 参数校验-模块源码路径
754
779
 
755
780
  if (!newModuleItem.path) {
756
781
  throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
@@ -793,6 +818,10 @@ var defaultTmsConfig = {
793
818
 
794
819
  function dfs(tmsConfig, modules) {
795
820
  modules.forEach(moduleItem => {
821
+ if (!moduleItem.path) {
822
+ throw new Error(`${moduleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
823
+ }
824
+
796
825
  const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
797
826
 
798
827
  if (!fs.existsSync(moduleConfigPath)) {
@@ -841,10 +870,10 @@ var defaultTmsConfig = {
841
870
  };
842
871
  })(tmsMpconfig);
843
872
 
844
- const fs$f = require$$0__default$1;
845
- const path$d = require$$1__default$1;
873
+ const fs$i = require$$0__default$1;
874
+ const path$e = require$$1__default$1;
846
875
  const {
847
- info: info$b
876
+ info: info$h
848
877
  } = log$1;
849
878
  const {
850
879
  relativeCwdPath
@@ -855,12 +884,12 @@ const {
855
884
  * @returns
856
885
  */
857
886
 
858
- const isDirEmpty = dirname => fs$f.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
887
+ const isDirEmpty = dirname => fs$i.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
859
888
 
860
889
 
861
890
  const isFile = pathName => {
862
891
  try {
863
- const stat = fs$f.lstatSync(pathName);
892
+ const stat = fs$i.lstatSync(pathName);
864
893
  return stat.isFile();
865
894
  } catch {
866
895
  return false;
@@ -872,9 +901,9 @@ const isFile = pathName => {
872
901
  */
873
902
 
874
903
 
875
- const ensureDirExist$4 = dirname => {
876
- if (!fs$f.existsSync(dirname)) {
877
- fs$f.mkdirSync(dirname, {
904
+ const ensureDirExist$6 = dirname => {
905
+ if (!fs$i.existsSync(dirname)) {
906
+ fs$i.mkdirSync(dirname, {
878
907
  recursive: true
879
908
  });
880
909
  }
@@ -882,27 +911,27 @@ const ensureDirExist$4 = dirname => {
882
911
 
883
912
 
884
913
  const copyFile = function (src, dest) {
885
- if (fs$f.existsSync(dest)) {
886
- fs$f.unlinkSync(dest);
914
+ if (fs$i.existsSync(dest)) {
915
+ fs$i.unlinkSync(dest);
887
916
  }
888
917
 
889
- const dir = path$d.dirname(dest);
890
- ensureDirExist$4(dir);
891
- fs$f.copyFileSync(src, dest);
918
+ const dir = path$e.dirname(dest);
919
+ ensureDirExist$6(dir);
920
+ fs$i.copyFileSync(src, dest);
892
921
  }; // 判断文件内容是否一致,不一致再进行拷贝
893
922
 
894
923
 
895
924
  function diffContentCopyFile(originFile, destFile) {
896
- if (fs$f.existsSync(destFile)) {
897
- const depDestContent = fs$f.readFileSync(destFile, 'utf8');
898
- const depOriginContent = fs$f.readFileSync(originFile, 'utf8');
925
+ if (fs$i.existsSync(destFile)) {
926
+ const depDestContent = fs$i.readFileSync(destFile, 'utf8');
927
+ const depOriginContent = fs$i.readFileSync(originFile, 'utf8');
899
928
 
900
929
  if (depDestContent !== depOriginContent) {
901
- info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
930
+ info$h(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
902
931
  copyFile(originFile, destFile);
903
932
  }
904
933
  } else {
905
- info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
934
+ info$h(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
906
935
  copyFile(originFile, destFile);
907
936
  }
908
937
  } // 添加后缀
@@ -913,7 +942,7 @@ function ext(filePath, extensions) {
913
942
  let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
914
943
 
915
944
  try {
916
- const stat = fs$f.lstatSync(newFilePath);
945
+ const stat = fs$i.lstatSync(newFilePath);
917
946
 
918
947
  if (stat.isDirectory()) {
919
948
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
@@ -924,7 +953,7 @@ function ext(filePath, extensions) {
924
953
  for (const ext of extensions) {
925
954
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
926
955
 
927
- if (fs$f.existsSync(file)) {
956
+ if (fs$i.existsSync(file)) {
928
957
  return {
929
958
  ext,
930
959
  extPath: extPath + ext,
@@ -942,11 +971,11 @@ function ext(filePath, extensions) {
942
971
 
943
972
 
944
973
  const fileInDir = (dir, file) => {
945
- if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
974
+ if (!fs$i.existsSync(dir) || !fs$i.existsSync(file)) {
946
975
  return false;
947
976
  }
948
977
 
949
- const relativePath = path$d.relative(dir, file);
978
+ const relativePath = path$e.relative(dir, file);
950
979
 
951
980
  if (relativePath.startsWith('..')) {
952
981
  return false;
@@ -959,10 +988,10 @@ function findAllFilesOfDir(dir) {
959
988
  const list = [];
960
989
 
961
990
  function listFile(dir) {
962
- const arr = fs$f.readdirSync(dir);
991
+ const arr = fs$i.readdirSync(dir);
963
992
  arr.forEach(item => {
964
- const fullPath = path$d.join(dir, item);
965
- const stats = fs$f.statSync(fullPath);
993
+ const fullPath = path$e.join(dir, item);
994
+ const stats = fs$i.statSync(fullPath);
966
995
 
967
996
  if (stats.isDirectory()) {
968
997
  listFile(fullPath);
@@ -981,14 +1010,14 @@ var io$3 = {
981
1010
  isDirEmpty,
982
1011
  copyFile,
983
1012
  diffContentCopyFile,
984
- ensureDirExist: ensureDirExist$4,
1013
+ ensureDirExist: ensureDirExist$6,
985
1014
  ext,
986
1015
  fileInDir,
987
1016
  isFile,
988
1017
  findAllFilesOfDir
989
1018
  };
990
1019
 
991
- const async = require$$0__default$3;
1020
+ const async = require$$0__default$4;
992
1021
  const ejs = require$$1__default$3;
993
1022
 
994
1023
  const render$1 = (files, metalsmith, next) => {
@@ -1008,10 +1037,10 @@ const render$1 = (files, metalsmith, next) => {
1008
1037
 
1009
1038
  var render_1 = render$1;
1010
1039
 
1011
- const fs$e = require$$0__default$1;
1012
- const inquirer$2 = require$$1__default$4;
1040
+ const fs$h = require$$0__default$1;
1041
+ const inquirer$1 = require$$1__default$4;
1013
1042
  const {
1014
- resolve: resolve$d
1043
+ resolve: resolve$i
1015
1044
  } = widgets;
1016
1045
  const {
1017
1046
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -1025,12 +1054,12 @@ const {
1025
1054
  const parseTemplateQuestions = dir => {
1026
1055
  let prompts = [];
1027
1056
 
1028
- if (!fs$e.existsSync(`${dir}/questions.json`)) {
1057
+ if (!fs$h.existsSync(`${dir}/questions.json`)) {
1029
1058
  return prompts;
1030
1059
  }
1031
1060
 
1032
1061
  try {
1033
- const json = JSON.parse(fs$e.readFileSync(`${dir}/questions.json`));
1062
+ const json = JSON.parse(fs$h.readFileSync(`${dir}/questions.json`));
1034
1063
 
1035
1064
  if (Array.isArray(json) && json.length > 0) {
1036
1065
  json.forEach((item, index) => {
@@ -1063,7 +1092,7 @@ const isQuestionType = result => {
1063
1092
  };
1064
1093
 
1065
1094
  const ask$1 = templateDir => (files, metalsmith, next) => {
1066
- const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
1095
+ const prompts = parseTemplateQuestions(resolve$i(templateDir, TEMPLATE_TKIT_DIR$1));
1067
1096
  const metadata = metalsmith.metadata();
1068
1097
  const filteredPrompts = prompts.filter(prompt => {
1069
1098
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -1072,7 +1101,7 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
1072
1101
 
1073
1102
  return true;
1074
1103
  });
1075
- inquirer$2.prompt(filteredPrompts).then(res => {
1104
+ inquirer$1.prompt(filteredPrompts).then(res => {
1076
1105
  for (const prompt of filteredPrompts) {
1077
1106
  metadata[prompt.name] = res[prompt.name];
1078
1107
  }
@@ -1088,7 +1117,7 @@ var ask_1 = ask$1;
1088
1117
  const FILES_TO_IGNORE$1 = ['node_modules'];
1089
1118
  var ignoreFiles = FILES_TO_IGNORE$1;
1090
1119
 
1091
- const Metalsmith = require$$0__default$4;
1120
+ const Metalsmith = require$$0__default$5;
1092
1121
  const render = render_1;
1093
1122
  const ask = ask_1;
1094
1123
  const FILES_TO_IGNORE = ignoreFiles;
@@ -1105,24 +1134,18 @@ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolv
1105
1134
 
1106
1135
  var generator_1 = generator$1;
1107
1136
 
1108
- const request$2 = require$$0__default$5;
1109
- const shelljs$8 = require$$2__default;
1137
+ const request$1 = require$$0__default$6;
1138
+ const {
1139
+ getGitUser: getGitUser$1
1140
+ } = widgets;
1110
1141
  const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
1111
1142
 
1112
- function getGitUser() {
1113
- const res = shelljs$8.exec('git config user.name', {
1114
- async: false,
1115
- silent: true
1116
- });
1117
- return res.stdout;
1118
- }
1119
-
1120
- const report$8 = (name, attrs = {}) => {
1143
+ const report$a = (name, attrs = {}) => {
1121
1144
  try {
1122
1145
  const param = [];
1123
1146
  param[27] = name;
1124
1147
  param[28] = 'tmskit';
1125
- param[29] = getGitUser();
1148
+ param[29] = getGitUser$1();
1126
1149
  param[30] = JSON.stringify(attrs);
1127
1150
 
1128
1151
  for (let i = 0; i < 40; i++) {
@@ -1130,23 +1153,23 @@ const report$8 = (name, attrs = {}) => {
1130
1153
  }
1131
1154
 
1132
1155
  ;
1133
- request$2.post({
1156
+ request$1.post({
1134
1157
  url: apiUrl,
1135
1158
  json: {
1136
1159
  param
1137
1160
  }
1138
- }); // (error, response, body) => {
1161
+ }, () => {}); // (error, response, body) => {
1139
1162
  // console.log('body:', body);
1140
1163
  // }
1141
1164
  } catch (e) {}
1142
1165
  };
1143
1166
 
1144
- var report_1 = report$8;
1167
+ var report_1 = report$a;
1145
1168
 
1146
- const path$c = require$$1__default$1;
1147
- const fs$d = require$$0__default$1;
1148
- const shelljs$7 = require$$2__default;
1149
- const inquirer$1 = require$$1__default$4;
1169
+ const path$d = require$$1__default$1;
1170
+ const fs$g = require$$0__default$1;
1171
+ const shelljs$6 = require$$0__default$2;
1172
+ const inquirer = require$$1__default$4;
1150
1173
  const {
1151
1174
  TEMPLATE_DIR,
1152
1175
  TEMPLATE_URL,
@@ -1155,18 +1178,18 @@ const {
1155
1178
  CREATE_TEMPLATE_QUESTION
1156
1179
  } = constant;
1157
1180
  const {
1158
- resolve: resolve$c
1181
+ resolve: resolve$h
1159
1182
  } = widgets;
1160
1183
  const io$2 = io$3;
1161
1184
  const {
1162
- fail: fail$8,
1185
+ fail: fail$9,
1163
1186
  succeed: succeed$1,
1164
- info: info$a
1187
+ info: info$g
1165
1188
  } = log$1;
1166
1189
  const generator = generator_1;
1167
- const request$1 = require$$0__default$5;
1190
+ const request = require$$0__default$6;
1168
1191
  const unzip = require$$10__default;
1169
- const report$7 = report_1;
1192
+ const report$9 = report_1;
1170
1193
  /**
1171
1194
  * 如果该目录下面存在文件,换个名字
1172
1195
  * @param { string } targetDir 当前文件夹
@@ -1175,13 +1198,13 @@ const report$7 = report_1;
1175
1198
 
1176
1199
  async function createProjectDir(targetDir) {
1177
1200
  // 如果目录非空或者已经存在,提示用户,做选择
1178
- if (fs$d.existsSync(targetDir)) {
1201
+ if (fs$g.existsSync(targetDir)) {
1179
1202
  if (!(await io$2.isDirEmpty(targetDir))) {
1180
- fail$8('该目录名已经存在,换个项目名字吧~');
1203
+ fail$9('该目录名已经存在,换个项目名字吧~');
1181
1204
  process.exit(1);
1182
1205
  }
1183
1206
  } else {
1184
- shelljs$7.mkdir('-p', targetDir);
1207
+ shelljs$6.mkdir('-p', targetDir);
1185
1208
  }
1186
1209
  }
1187
1210
  /**
@@ -1196,14 +1219,14 @@ async function createProjectDir(targetDir) {
1196
1219
  function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1197
1220
  return new Promise((resolve, reject) => {
1198
1221
  const localZipPath = `${templateDir}/${templateName}.zip`;
1199
- const stream = fs$d.createWriteStream(localZipPath);
1200
- request$1(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
1222
+ const stream = fs$g.createWriteStream(localZipPath);
1223
+ request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
1201
1224
  if (err) {
1202
1225
  reject(err);
1203
1226
  return;
1204
1227
  }
1205
1228
 
1206
- fs$d.createReadStream(localZipPath).pipe(unzip.Extract({
1229
+ fs$g.createReadStream(localZipPath).pipe(unzip.Extract({
1207
1230
  path: templateDir
1208
1231
  })).on('close', err => {
1209
1232
  if (err) {
@@ -1225,75 +1248,75 @@ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1225
1248
 
1226
1249
  async function create(projectName) {
1227
1250
  const cwd = process.cwd();
1228
- const targetDir = path$c.resolve(cwd, projectName);
1251
+ const targetDir = path$d.resolve(cwd, projectName);
1229
1252
  const {
1230
1253
  projectType
1231
- } = await inquirer$1.prompt(CREATE_TEMPLATE_QUESTION);
1232
- report$7('create-start', {
1254
+ } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
1255
+ report$9('create-start', {
1233
1256
  projectType
1234
1257
  }); // 创建项目目录
1235
1258
 
1236
1259
  await createProjectDir(targetDir); // 新创建缓存目录
1237
1260
 
1238
- if (fs$d.existsSync(TEMPLATE_DIR)) {
1239
- shelljs$7.rm('-rf', TEMPLATE_DIR);
1261
+ if (fs$g.existsSync(TEMPLATE_DIR)) {
1262
+ shelljs$6.rm('-rf', TEMPLATE_DIR);
1240
1263
  }
1241
1264
 
1242
- fs$d.mkdirSync(TEMPLATE_DIR, {
1265
+ fs$g.mkdirSync(TEMPLATE_DIR, {
1243
1266
  recursive: true
1244
1267
  }); // 下载和解压模板
1245
1268
 
1246
1269
  await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
1247
1270
 
1248
- generator(path$c.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1249
- shelljs$7.cd(projectName);
1250
- const hookFilePath = resolve$c(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1271
+ generator(path$d.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1272
+ shelljs$6.cd(projectName);
1273
+ const hookFilePath = resolve$h(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1251
1274
 
1252
- if (fs$d.existsSync(hookFilePath)) {
1275
+ if (fs$g.existsSync(hookFilePath)) {
1253
1276
  const hooks = require(hookFilePath);
1254
1277
 
1255
1278
  if (hooks.afterCreate) {
1256
1279
  hooks.afterCreate.forEach(item => {
1257
1280
  if (typeof item === 'function') {
1258
- item.call(null, shelljs$7, {
1281
+ item.call(null, shelljs$6, {
1259
1282
  projectName
1260
1283
  });
1261
1284
  } else {
1262
- shelljs$7.exec(item);
1285
+ shelljs$6.exec(item);
1263
1286
  }
1264
1287
  });
1265
1288
  }
1266
1289
 
1267
- shelljs$7.rm('-rf', resolve$c(projectName, TEMPLATE_TKIT_DIR));
1290
+ shelljs$6.rm('-rf', resolve$h(projectName, TEMPLATE_TKIT_DIR));
1268
1291
  }
1269
1292
 
1270
- report$7('create-success', {
1293
+ report$9('create-success', {
1271
1294
  projectType
1272
1295
  });
1273
1296
  succeed$1('项目创建完成.');
1274
1297
  }).catch(err => {
1275
- fail$8(err.message);
1276
- info$a('详细的错误信息:', err);
1298
+ fail$9(err.message);
1299
+ info$g('详细的错误信息:', err);
1277
1300
  });
1278
1301
  }
1279
1302
 
1280
1303
  var create_1 = create;
1281
1304
 
1282
- const fs$c = require$$0__default$1;
1283
- const path$b = require$$1__default$1;
1284
- const shellJs$1 = require$$2__default;
1305
+ const fs$f = require$$0__default$1;
1306
+ const path$c = require$$1__default$1;
1307
+ const shellJs$3 = require$$0__default$2;
1285
1308
  const {
1286
- ensureDirExist: ensureDirExist$3
1309
+ ensureDirExist: ensureDirExist$5
1287
1310
  } = io$3;
1288
1311
  const {
1289
1312
  EXTEND_CMD
1290
1313
  } = constant;
1291
1314
  const {
1292
- createTask: createTask$2
1315
+ createTask: createTask$5
1293
1316
  } = widgets;
1294
1317
  const {
1295
- info: info$9,
1296
- fail: fail$7
1318
+ info: info$f,
1319
+ fail: fail$8
1297
1320
  } = log$1;
1298
1321
  /**
1299
1322
  * 下载扩展命令的npm包
@@ -1305,17 +1328,17 @@ async function installCmd(npmName, cmd) {
1305
1328
  try {
1306
1329
  const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1307
1330
 
1308
- if (!fs$c.existsSync(cmdPackageJson)) {
1309
- ensureDirExist$3(EXTEND_CMD);
1310
- fs$c.writeFileSync(cmdPackageJson, JSON.stringify({
1331
+ if (!fs$f.existsSync(cmdPackageJson)) {
1332
+ ensureDirExist$5(EXTEND_CMD);
1333
+ fs$f.writeFileSync(cmdPackageJson, JSON.stringify({
1311
1334
  dependencies: {}
1312
1335
  }, null, 2));
1313
1336
  }
1314
1337
 
1315
- shellJs$1.cd(EXTEND_CMD);
1316
- await createTask$2(npmName => new Promise((resolve, reject) => {
1338
+ shellJs$3.cd(EXTEND_CMD);
1339
+ await createTask$5(npmName => new Promise((resolve, reject) => {
1317
1340
  const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
1318
- shellJs$1.exec(`npm install --save ${npmName} ${registry}`, {
1341
+ shellJs$3.exec(`npm install --save ${npmName} ${registry}`, {
1319
1342
  cwd: EXTEND_CMD,
1320
1343
  silent: true
1321
1344
  }, (code, stdout, stderr) => {
@@ -1327,8 +1350,8 @@ async function installCmd(npmName, cmd) {
1327
1350
  });
1328
1351
  }), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
1329
1352
  } catch (e) {
1330
- fail$7('构建出现错误:');
1331
- info$9(e);
1353
+ fail$8('构建出现错误:');
1354
+ info$f(e);
1332
1355
  process.exit(1);
1333
1356
  }
1334
1357
  }
@@ -1342,17 +1365,17 @@ function loadExtendCmd$1() {
1342
1365
  const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1343
1366
  const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
1344
1367
 
1345
- if (fs$c.existsSync(cmdPackageJson)) {
1346
- const content = fs$c.readFileSync(cmdPackageJson, 'utf8');
1368
+ if (fs$f.existsSync(cmdPackageJson)) {
1369
+ const content = fs$f.readFileSync(cmdPackageJson, 'utf8');
1347
1370
  const json = JSON.parse(content);
1348
1371
  const deps = json.dependencies || {};
1349
1372
  const cmdConfigs = [];
1350
1373
  Object.keys(deps).forEach(name => {
1351
1374
  // 检索cmd的npm包
1352
1375
  if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
1353
- const cmdConfig = path$b.join(cmdNpmDir, name, 'tms.config.js');
1376
+ const cmdConfig = path$c.join(cmdNpmDir, name, 'tms.config.js');
1354
1377
 
1355
- if (fs$c.existsSync(cmdConfig)) {
1378
+ if (fs$f.existsSync(cmdConfig)) {
1356
1379
  cmdConfigs.push(cmdConfig);
1357
1380
  }
1358
1381
  });
@@ -1367,7 +1390,7 @@ var extendCmd = {
1367
1390
  loadExtendCmd: loadExtendCmd$1
1368
1391
  };
1369
1392
 
1370
- const global$7 = {
1393
+ const global$b = {
1371
1394
  data: {},
1372
1395
 
1373
1396
  setData(...args) {
@@ -1389,36 +1412,36 @@ const global$7 = {
1389
1412
 
1390
1413
  };
1391
1414
  var global_1 = {
1392
- global: global$7
1415
+ global: global$b
1393
1416
  };
1394
1417
 
1395
1418
  const {
1396
- fail: fail$6
1419
+ fail: fail$7
1397
1420
  } = log$1;
1398
1421
  const {
1399
- global: global$6
1422
+ global: global$a
1400
1423
  } = global_1;
1401
1424
 
1402
- function handleError$5(error, isQuit = false) {
1425
+ function handleError$8(error, isQuit = false) {
1403
1426
  const errMsg = typeof error === 'object' ? error.message : error;
1404
1427
 
1405
1428
  if (isQuit) {
1406
- fail$6(errMsg);
1429
+ fail$7(errMsg);
1407
1430
  process.exit(1);
1408
1431
  }
1409
1432
 
1410
- const isDev = global$6.getData('isDev');
1433
+ const isDev = global$a.getData('isDev');
1411
1434
 
1412
1435
  if (isDev) {
1413
- fail$6(errMsg);
1436
+ fail$7(errMsg);
1414
1437
  } else {
1415
- fail$6(errMsg);
1438
+ fail$7(errMsg);
1416
1439
  process.exit(1);
1417
1440
  }
1418
1441
  }
1419
1442
 
1420
1443
  var handleError_1 = {
1421
- handleError: handleError$5
1444
+ handleError: handleError$8
1422
1445
  };
1423
1446
 
1424
1447
  /**
@@ -1426,26 +1449,26 @@ var handleError_1 = {
1426
1449
  */
1427
1450
  /* eslint-disable no-param-reassign */
1428
1451
 
1429
- const fs$b = require$$0__default$1;
1452
+ const fs$e = require$$0__default$1;
1430
1453
  const {
1431
1454
  getSubPackages: getSubPackages$3,
1432
1455
  getModulesConfig
1433
1456
  } = tmsMpconfig.exports;
1434
1457
  const {
1435
- fail: fail$5,
1436
- info: info$8
1458
+ fail: fail$6,
1459
+ info: info$e
1437
1460
  } = log$1;
1438
1461
  const {
1439
- resolve: resolve$b,
1440
- filterField: filterField$4
1462
+ resolve: resolve$g,
1463
+ filterField: filterField$6
1441
1464
  } = widgets;
1442
1465
  const {
1443
- handleError: handleError$4
1466
+ handleError: handleError$7
1444
1467
  } = handleError_1;
1445
1468
  const {
1446
- global: global$5
1469
+ global: global$9
1447
1470
  } = global_1;
1448
- const report$6 = report_1;
1471
+ const report$8 = report_1;
1449
1472
  /**
1450
1473
  * 更新appJson里面的主包配置
1451
1474
  * @param { object } appJson appJson信息
@@ -1453,7 +1476,7 @@ const report$6 = report_1;
1453
1476
  * @returns { object } appJson小程序主页配置信息
1454
1477
  */
1455
1478
 
1456
- function updateMainPackages(appJson, mainPackages) {
1479
+ function updateMainPackages(appJson, mainPackages = []) {
1457
1480
  let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
1458
1481
 
1459
1482
  if (foundMainPackages.length === 0) {
@@ -1464,7 +1487,7 @@ function updateMainPackages(appJson, mainPackages) {
1464
1487
 
1465
1488
  foundMainPackages.forEach(subpackage => {
1466
1489
  if (!subpackage.pages || !subpackage.pages.length) {
1467
- fail$5(`主包 ${subpackage} 不能没有 pages`);
1490
+ fail$6(`主包 ${subpackage} 不能没有 pages`);
1468
1491
  process.exit(-1);
1469
1492
  }
1470
1493
 
@@ -1489,12 +1512,12 @@ function updateMainPackages(appJson, mainPackages) {
1489
1512
 
1490
1513
 
1491
1514
  const getAppJsonContent = sourceAppJsonPath => {
1492
- if (!fs$b.existsSync(sourceAppJsonPath)) {
1493
- fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1515
+ if (!fs$e.existsSync(sourceAppJsonPath)) {
1516
+ fail$6(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1494
1517
  process.exit(1);
1495
1518
  }
1496
1519
 
1497
- const appJson = JSON.parse(fs$b.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1520
+ const appJson = JSON.parse(fs$e.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1498
1521
 
1499
1522
  appJson.subpackages = [];
1500
1523
  appJson.pages = [];
@@ -1539,7 +1562,7 @@ const fixAppJson = appJson => {
1539
1562
  appJson[key] = preloadRuleMap;
1540
1563
  }
1541
1564
  });
1542
- return filterField$4(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1565
+ return filterField$6(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1543
1566
  }); // 如果plugins重复,则错误提示
1544
1567
 
1545
1568
  const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
@@ -1573,7 +1596,7 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1573
1596
 
1574
1597
  const subPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
1575
1598
 
1576
- const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
1599
+ const appJson = getAppJsonContent(resolve$g('./app.json')); // 更新app.json中的subpackages
1577
1600
 
1578
1601
  appJson.subpackages = subPackages;
1579
1602
  appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name)); // 处理appJson中重复||冲突的地方
@@ -1581,24 +1604,25 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1581
1604
  fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1582
1605
 
1583
1606
  updateMainPackages(appJson, tmsConfig.mainPackages);
1584
- fs$b.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1607
+ fs$e.writeFileSync(resolve$g(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1585
1608
 
1586
1609
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
1587
1610
  var _tmsConfig$hooks2;
1588
1611
 
1589
1612
  tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
1590
- tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
1613
+ tmsConfig: filterField$6(tmsConfig, ['gitAccount']),
1614
+ cmdOptions: global$9.getData('cmdOptions'),
1591
1615
  modules,
1592
1616
  appJson,
1593
- isDev: global$5.getData('isDev')
1617
+ isDev: global$9.getData('isDev')
1594
1618
  });
1595
- report$6('hooks:updateAppJson');
1619
+ report$8('hooks:updateAppJson');
1596
1620
  }
1597
1621
 
1598
1622
  return appJson;
1599
1623
  } catch (e) {
1600
- handleError$4(`生成app.json出现错误: ${e}`);
1601
- info$8(e);
1624
+ handleError$7(`生成app.json出现错误: ${e}`);
1625
+ info$e(e);
1602
1626
  }
1603
1627
  }
1604
1628
 
@@ -1609,24 +1633,24 @@ var buildAppJson = {
1609
1633
  /**
1610
1634
  * 下载第三方代码
1611
1635
  */
1612
- const MetalSmith = require$$0__default$4;
1636
+ const MetalSmith = require$$0__default$5;
1613
1637
  const crypto$2 = require$$1__default$5;
1614
1638
  const {
1615
1639
  downloadRepoForGit,
1616
1640
  pullRepoForGit,
1617
- resolve: resolve$a
1641
+ resolve: resolve$f
1618
1642
  } = widgets;
1619
1643
  const {
1620
- fail: fail$4,
1621
- info: info$7
1644
+ fail: fail$5,
1645
+ info: info$d
1622
1646
  } = log$1;
1623
- const fs$a = require$$0__default$1;
1624
- const shelljs$6 = require$$2__default;
1647
+ const fs$d = require$$0__default$1;
1648
+ const shelljs$5 = require$$0__default$2;
1625
1649
  const {
1626
- handleError: handleError$3
1650
+ handleError: handleError$6
1627
1651
  } = handleError_1;
1628
1652
  const {
1629
- global: global$4
1653
+ global: global$8
1630
1654
  } = global_1;
1631
1655
  /**
1632
1656
  * 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
@@ -1636,15 +1660,15 @@ const {
1636
1660
  */
1637
1661
 
1638
1662
  function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1639
- var _tmsConfig$gitAccount;
1663
+ var _tmsConfig$gitAccount, _tmsConfig$gitAccount2;
1640
1664
 
1641
1665
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1642
- const tmsConfig = global$4.getData('tmsConfig');
1666
+ const tmsConfig = global$8.getData('tmsConfig');
1643
1667
  let gitUrl = httpRepoUrl;
1644
1668
  const {
1645
1669
  username = '',
1646
1670
  pass = ''
1647
- } = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
1671
+ } = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount2 = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount2 === void 0 ? void 0 : _tmsConfig$gitAccount2[httpRepoUrl]) || {};
1648
1672
  const urlPrefixReg = /http(s)?:\/\//;
1649
1673
 
1650
1674
  if (username && pass && urlPrefixReg.test(gitUrl)) {
@@ -1662,16 +1686,16 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1662
1686
  */
1663
1687
 
1664
1688
 
1665
- function moveFile(sourceDir, targetDir, ignore) {
1666
- if (fs$a.existsSync(targetDir)) {
1667
- shelljs$6.rm('-rf', targetDir);
1689
+ function moveFile(sourceDir, targetDir, ignore = []) {
1690
+ if (fs$d.existsSync(targetDir)) {
1691
+ shelljs$5.rm('-rf', targetDir);
1668
1692
  } // 删除不是文件夹的文件
1669
1693
 
1670
1694
 
1671
1695
  return new Promise((resolve, reject) => {
1672
1696
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1673
1697
  if (e) {
1674
- fail$4(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1698
+ fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1675
1699
  reject(e);
1676
1700
  }
1677
1701
 
@@ -1720,11 +1744,11 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1720
1744
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1721
1745
  return Promise.all(callArr);
1722
1746
  }).catch(e => {
1723
- handleError$3(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1747
+ handleError$6(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1724
1748
  }));
1725
1749
  });
1726
1750
  await Promise.all(arrPromises);
1727
- shelljs$6.cd(cwd);
1751
+ shelljs$5.cd(cwd);
1728
1752
  }
1729
1753
  /**
1730
1754
  * 收集下载模块代码的任务
@@ -1765,9 +1789,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1765
1789
 
1766
1790
  const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1767
1791
 
1768
- const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
1792
+ const sourcePath = resolve$f(sourceDir, md5Key); // 模块源码要放到目标目录
1769
1793
 
1770
- const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1794
+ const targetPath = resolve$f(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1771
1795
 
1772
1796
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1773
1797
 
@@ -1777,8 +1801,8 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1777
1801
  targetPath
1778
1802
  },
1779
1803
  fn: async (sourceModulePath, targetPath) => {
1780
- if (fs$a.existsSync(targetPath)) {
1781
- shelljs$6.rm('-rf', `${targetPath}/*`);
1804
+ if (fs$d.existsSync(targetPath)) {
1805
+ shelljs$5.rm('-rf', `${targetPath}/*`);
1782
1806
  }
1783
1807
 
1784
1808
  await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
@@ -1792,14 +1816,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1792
1816
  } else {
1793
1817
  let promiseTask;
1794
1818
 
1795
- if (fs$a.existsSync(sourcePath) && fs$a.existsSync(`${sourcePath}/.git`)) {
1819
+ if (fs$d.existsSync(sourcePath) && fs$d.existsSync(`${sourcePath}/.git`)) {
1796
1820
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1797
- info$7(`git pull:${httpRepoUrl}`);
1821
+ info$d(`git pull:${httpRepoUrl} --branch: ${branch}`);
1798
1822
  return pullRepoForGit(sourcePath, branch);
1799
1823
  };
1800
1824
  } else {
1801
1825
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1802
- info$7(`git clone: ${httpRepoUrl}`);
1826
+ info$d(`git clone: ${httpRepoUrl}`);
1803
1827
  return downloadRepoForGit(gitUrl, sourcePath, branch);
1804
1828
  };
1805
1829
  }
@@ -1840,7 +1864,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
1840
1864
  const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
1841
1865
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
1842
1866
 
1843
- if (!fs$a.existsSync(`${sourceDir}/${md5Key}`)) {
1867
+ if (!fs$d.existsSync(`${sourceDir}/${md5Key}`)) {
1844
1868
  return true;
1845
1869
  }
1846
1870
  }
@@ -1853,8 +1877,8 @@ var cloneModules_1 = {
1853
1877
  checkRemoteModGitUrlBranch
1854
1878
  };
1855
1879
 
1856
- const ci = require$$0__default$6;
1857
- const path$a = require$$1__default$1;
1880
+ const ci = require$$0__default$7;
1881
+ const path$b = require$$1__default$1;
1858
1882
  /**
1859
1883
  * 获取小程序ci的Project对象
1860
1884
  * @returns {Object} 小程序ci对象
@@ -1866,11 +1890,11 @@ const getMpCi = ({
1866
1890
  type = 'miniProgram',
1867
1891
  privateKey = 'TODO'
1868
1892
  }) => {
1869
- var _cfgJsonContent$packO;
1893
+ var _projectCg$packOption, _projectCg$packOption2;
1870
1894
 
1871
- const cfgJsonContent = require(path$a.join(projectPath, 'project.config.json'));
1895
+ const projectCg = require(path$b.join(projectPath, 'project.config.json'));
1872
1896
 
1873
- const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
1897
+ const ignores = (projectCg === null || projectCg === void 0 ? void 0 : (_projectCg$packOption = projectCg.packOptions) === null || _projectCg$packOption === void 0 ? void 0 : (_projectCg$packOption2 = _projectCg$packOption.ignore) === null || _projectCg$packOption2 === void 0 ? void 0 : _projectCg$packOption2.map(({
1874
1898
  value
1875
1899
  }) => value)) || [];
1876
1900
  return new ci.Project({
@@ -1880,13 +1904,6 @@ const getMpCi = ({
1880
1904
  projectPath,
1881
1905
  ignores: ['node_modules/**/*', 'cloud/**/*', ...ignores]
1882
1906
  });
1883
- }; // 用小程序ci工具构建小程序
1884
-
1885
-
1886
- const packMpProject = async project => {
1887
- await ci.packNpm(project, {
1888
- ignores: ['cloud/**/*']
1889
- });
1890
1907
  };
1891
1908
  /**
1892
1909
  * 格式化构建npm结果信息
@@ -1905,8 +1922,12 @@ const formatPackNpmWarning = warning => {
1905
1922
  return result;
1906
1923
  };
1907
1924
  /**
1908
- * 构建miniprogram_npm
1909
- * @returns {Object} 小程序ci对象
1925
+ * 构建miniprogram_npm https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E6%9E%84%E5%BB%BAnpm
1926
+ * * @param {object} {
1927
+ * appId,
1928
+ * peojectPath,
1929
+ * privateKey,
1930
+ * }
1910
1931
  */
1911
1932
 
1912
1933
 
@@ -1915,12 +1936,14 @@ const buildMpNpm$1 = async ({
1915
1936
  projectPath,
1916
1937
  privateKey
1917
1938
  }) => {
1918
- const mpCi = await getMpCi({
1939
+ const mpCi = getMpCi({
1919
1940
  appId,
1920
1941
  projectPath,
1921
1942
  privateKey
1922
1943
  });
1923
- const packNpmWarning = await packMpProject(mpCi);
1944
+ const packNpmWarning = await ci.packNpm(mpCi, {
1945
+ ignores: ['cloud/**/*']
1946
+ });
1924
1947
  const packNpmMsg = formatPackNpmWarning(packNpmWarning);
1925
1948
 
1926
1949
  if (packNpmMsg) {
@@ -1929,18 +1952,80 @@ const buildMpNpm$1 = async ({
1929
1952
 
1930
1953
  return Promise.resolve();
1931
1954
  };
1955
+ /**
1956
+ * 预览小程序码 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88
1957
+ * @param {object} {
1958
+ * appId,
1959
+ * peojectPath,
1960
+ * privateKey,
1961
+ * desc
1962
+ * robot
1963
+ * }
1964
+ */
1932
1965
 
1933
- var mpCi = {
1934
- buildMpNpm: buildMpNpm$1
1966
+
1967
+ const previewMp = async (params = {}) => {
1968
+ const {
1969
+ appId,
1970
+ projectPath,
1971
+ privateKey,
1972
+ ...resetParams
1973
+ } = params;
1974
+ const mpCi = await getMpCi({
1975
+ appId,
1976
+ projectPath,
1977
+ privateKey
1978
+ });
1979
+ return await ci.preview({
1980
+ project: mpCi,
1981
+ ...resetParams,
1982
+ onProgressUpdate: () => {}
1983
+ });
1935
1984
  };
1985
+ /**
1986
+ * 上传小程序 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E4%B8%8A%E4%BC%A0
1987
+ * @param {object} {
1988
+ * appId,
1989
+ * peojectPath,
1990
+ * privateKey,
1991
+ * version,
1992
+ * desc
1993
+ * }
1994
+ */
1936
1995
 
1937
- const fs$9 = require$$0__default$1;
1938
- const path$9 = require$$1__default$1;
1996
+
1997
+ const uploadMp = async (params = {}) => {
1998
+ const {
1999
+ appId,
2000
+ projectPath,
2001
+ privateKey,
2002
+ ...resetParams
2003
+ } = params;
2004
+ const mpCi = await getMpCi({
2005
+ appId,
2006
+ projectPath,
2007
+ privateKey
2008
+ });
2009
+ return await ci.upload({
2010
+ project: mpCi,
2011
+ ...resetParams,
2012
+ onProgressUpdate: () => {}
2013
+ });
2014
+ };
2015
+
2016
+ var mpCi$2 = {
2017
+ buildMpNpm: buildMpNpm$1,
2018
+ previewMp,
2019
+ uploadMp
2020
+ };
2021
+
2022
+ const fs$c = require$$0__default$1;
2023
+ const path$a = require$$1__default$1;
1939
2024
  const {
1940
2025
  NPM_CACHE_FILE
1941
2026
  } = constant;
1942
2027
  const {
1943
- ensureDirExist: ensureDirExist$2
2028
+ ensureDirExist: ensureDirExist$4
1944
2029
  } = io$3;
1945
2030
 
1946
2031
  function getCache$1(projectDir, type) {
@@ -1948,7 +2033,7 @@ function getCache$1(projectDir, type) {
1948
2033
 
1949
2034
  const filePath = NPM_CACHE_FILE;
1950
2035
 
1951
- if (!fs$9.existsSync(filePath)) {
2036
+ if (!fs$c.existsSync(filePath)) {
1952
2037
  return null;
1953
2038
  }
1954
2039
 
@@ -1960,10 +2045,10 @@ function getCache$1(projectDir, type) {
1960
2045
  function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1961
2046
  const filePath = NPM_CACHE_FILE;
1962
2047
 
1963
- if (!fs$9.existsSync(filePath)) {
1964
- const dir = path$9.dirname(filePath);
1965
- ensureDirExist$2(dir);
1966
- fs$9.writeFileSync(filePath, '{}');
2048
+ if (!fs$c.existsSync(filePath)) {
2049
+ const dir = path$a.dirname(filePath);
2050
+ ensureDirExist$4(dir);
2051
+ fs$c.writeFileSync(filePath, '{}');
1967
2052
  }
1968
2053
 
1969
2054
  const content = require(filePath);
@@ -1975,7 +2060,7 @@ function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1975
2060
  content[projectDir] = {
1976
2061
  [type]: data
1977
2062
  };
1978
- fs$9.writeFileSync(filePath, JSON.stringify(content, null, 2));
2063
+ fs$c.writeFileSync(filePath, JSON.stringify(content, null, 2));
1979
2064
  }
1980
2065
 
1981
2066
  var cache = {
@@ -1986,20 +2071,20 @@ var cache = {
1986
2071
  /**
1987
2072
  * 本文件主要负责项目或者分包依赖的npm的安装
1988
2073
  */
1989
- const fs$8 = require$$0__default$1;
2074
+ const fs$b = require$$0__default$1;
1990
2075
  const fsExtra = require$$1__default$6;
1991
2076
  const crypto$1 = require$$1__default$5;
1992
- const path$8 = require$$1__default$1;
1993
- const shell = require$$2__default;
2077
+ const path$9 = require$$1__default$1;
2078
+ const shell = require$$0__default$2;
1994
2079
  const log = log$1;
1995
2080
  const {
1996
- npmInstall: npmInstall$1
2081
+ npmInstall: npmInstall$2
1997
2082
  } = widgets;
1998
2083
  const {
1999
- handleError: handleError$2
2084
+ handleError: handleError$5
2000
2085
  } = handleError_1;
2001
2086
  const {
2002
- global: global$3
2087
+ global: global$7
2003
2088
  } = global_1;
2004
2089
  const shellJsOption = {
2005
2090
  async: false,
@@ -2023,7 +2108,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2023
2108
  const npmTasksMap = new Map();
2024
2109
 
2025
2110
  for (const packageJsonPath of packageJsonFiles) {
2026
- const packageContent = fs$8.readFileSync(packageJsonPath);
2111
+ const packageContent = fs$b.readFileSync(packageJsonPath);
2027
2112
  let packageJson;
2028
2113
 
2029
2114
  try {
@@ -2038,14 +2123,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2038
2123
 
2039
2124
  if (Object.keys(md5Obj.dependencies).length !== 0) {
2040
2125
  const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
2041
- const cacheNMPath = path$8.join(cacheDir, md5Key);
2042
- const cacheNMTarFile = path$8.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
2126
+ const cacheNMPath = path$9.join(cacheDir, md5Key);
2127
+ const cacheNMTarFile = path$9.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
2043
2128
 
2044
2129
  const callback = {
2045
2130
  params: {
2046
2131
  cacheNMPath,
2047
2132
  cacheNMTarFile,
2048
- packageJsonDir: path$8.dirname(packageJsonPath),
2133
+ packageJsonDir: path$9.dirname(packageJsonPath),
2049
2134
  shell
2050
2135
  },
2051
2136
  fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
@@ -2074,8 +2159,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2074
2159
  fsExtra.emptydirSync(cacheNMPath);
2075
2160
  shell.cp('-f', packageJsonPath, cacheNMPath);
2076
2161
  log.info(`npm install: ${packageJsonPath}`);
2077
- const tmsConfig = global$3.getData('tmsConfig');
2078
- return npmInstall$1(cacheNMPath, tmsConfig.npm).then(() => {
2162
+ const tmsConfig = global$7.getData('tmsConfig');
2163
+ return npmInstall$2(cacheNMPath, tmsConfig.npm).then(() => {
2079
2164
  const newShellJsOption = { ...shellJsOption,
2080
2165
  cwd: cacheNMPath
2081
2166
  };
@@ -2122,7 +2207,7 @@ const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
2122
2207
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
2123
2208
  return Promise.all(callArr);
2124
2209
  }).catch(e => {
2125
- handleError$2(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
2210
+ handleError$5(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
2126
2211
  }));
2127
2212
  });
2128
2213
  await Promise.all(arrPromises);
@@ -2148,7 +2233,7 @@ const findFilesByFilter = (startPath, filter) => {
2148
2233
 
2149
2234
  const find = (startPath, filter) => {
2150
2235
  // 目录不存在
2151
- if (!fs$8.existsSync(startPath)) {
2236
+ if (!fs$b.existsSync(startPath)) {
2152
2237
  log.fail(`${startPath}目录不存在`);
2153
2238
  process.exit(-1);
2154
2239
  return;
@@ -2161,10 +2246,10 @@ const findFilesByFilter = (startPath, filter) => {
2161
2246
  return;
2162
2247
  }
2163
2248
 
2164
- const files = fs$8.readdirSync(startPath);
2249
+ const files = fs$b.readdirSync(startPath);
2165
2250
  files.forEach(file => {
2166
- const filename = path$8.join(startPath, file);
2167
- const stat = fs$8.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2251
+ const filename = path$9.join(startPath, file);
2252
+ const stat = fs$b.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2168
2253
 
2169
2254
  if (stat.isDirectory()) {
2170
2255
  find(filename, filter);
@@ -2190,10 +2275,10 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
2190
2275
  const packageJsonName = 'package.json'; // 查找文件名
2191
2276
 
2192
2277
  const cwd = contextDir || dirPath;
2193
- const result = [path$8.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
2278
+ const result = [path$9.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
2194
2279
 
2195
2280
  subRoots.forEach(subRoot => {
2196
- const toppath = path$8.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
2281
+ const toppath = path$9.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
2197
2282
 
2198
2283
  const list = findFilesByFilter(toppath, packageJsonName);
2199
2284
  result.push(...list);
@@ -2208,12 +2293,12 @@ var npm = {
2208
2293
  };
2209
2294
 
2210
2295
  const crypto = require$$1__default$5;
2211
- const fs$7 = require$$0__default$1;
2296
+ const fs$a = require$$0__default$1;
2212
2297
 
2213
2298
  function fileMd5$1(filePath) {
2214
2299
  return new Promise((resolve, reject) => {
2215
2300
  const md5sum = crypto.createHash('md5');
2216
- const stream = fs$7.ReadStream(filePath);
2301
+ const stream = fs$a.ReadStream(filePath);
2217
2302
  stream.on('data', d => {
2218
2303
  md5sum.update(d);
2219
2304
  });
@@ -2231,20 +2316,20 @@ var md5 = {
2231
2316
  fileMd5: fileMd5$1
2232
2317
  };
2233
2318
 
2234
- const fs$6 = require$$0__default$1;
2319
+ const fs$9 = require$$0__default$1;
2235
2320
  const semver$1 = require$$1__default$7;
2236
2321
  const {
2237
- resolve: resolve$9,
2238
- getAbsolutePath: getAbsolutePath$2
2322
+ resolve: resolve$e,
2323
+ getAbsolutePath: getAbsolutePath$5
2239
2324
  } = widgets;
2240
- const path$7 = require$$1__default$1;
2241
- const shelljs$5 = require$$2__default;
2325
+ const path$8 = require$$1__default$1;
2326
+ const shelljs$4 = require$$0__default$2;
2242
2327
  const {
2243
- handleError: handleError$1
2328
+ handleError: handleError$4
2244
2329
  } = handleError_1;
2245
2330
 
2246
2331
  const getLatestVersion = npmName => {
2247
- const data = shelljs$5.exec(`npm view ${npmName} version`);
2332
+ const data = shelljs$4.exec(`npm view ${npmName} version`);
2248
2333
 
2249
2334
  if (data.code === 0) {
2250
2335
  return data.stdout;
@@ -2259,17 +2344,17 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2259
2344
  // 1.1根目录的package.json
2260
2345
 
2261
2346
  const packageArr = [{
2262
- srcPackageDir: path$7.join(cwd, packageJsonName),
2263
- destNpmDir: resolve$9(outputDir, 'node_modules')
2347
+ srcPackageDir: path$8.join(cwd, packageJsonName),
2348
+ destNpmDir: resolve$e(outputDir, 'node_modules')
2264
2349
  }]; // 1.2模块的package.json
2265
2350
 
2266
2351
  subPackages.forEach(item => {
2267
- const srcPackageDir = `${getAbsolutePath$2(item.path)}/package.json`;
2352
+ const srcPackageDir = `${getAbsolutePath$5(item.path)}/package.json`;
2268
2353
 
2269
- if (fs$6.existsSync(srcPackageDir)) {
2354
+ if (fs$9.existsSync(srcPackageDir)) {
2270
2355
  packageArr.push({
2271
2356
  srcPackageDir,
2272
- destNpmDir: resolve$9(outputDir, item.root, 'node_modules')
2357
+ destNpmDir: resolve$e(outputDir, item.root, 'node_modules')
2273
2358
  });
2274
2359
  }
2275
2360
  });
@@ -2278,14 +2363,14 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2278
2363
 
2279
2364
 
2280
2365
  function readPackageDependencies(srcPackageDir) {
2281
- const packageJson = fs$6.readFileSync(srcPackageDir, 'utf-8');
2366
+ const packageJson = fs$9.readFileSync(srcPackageDir, 'utf-8');
2282
2367
  let dependencies = {};
2283
2368
 
2284
2369
  try {
2285
2370
  const json = packageJson ? JSON.parse(packageJson) : {};
2286
2371
  dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
2287
2372
  } catch (e) {
2288
- handleError$1(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2373
+ handleError$4(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2289
2374
  }
2290
2375
 
2291
2376
  return dependencies;
@@ -2313,15 +2398,15 @@ const checkPackageVersion$1 = packageArr => {
2313
2398
  const dependenciesKeys = Object.keys(dependencies);
2314
2399
 
2315
2400
  for (const key of dependenciesKeys) {
2316
- const depPath = path$7.join(item.destNpmDir, key);
2401
+ const depPath = path$8.join(item.destNpmDir, key);
2317
2402
 
2318
- if (!fs$6.existsSync(depPath)) {
2403
+ if (!fs$9.existsSync(depPath)) {
2319
2404
  return true;
2320
2405
  }
2321
2406
 
2322
- const depPackagePath = path$7.join(depPath, 'package.json');
2407
+ const depPackagePath = path$8.join(depPath, 'package.json');
2323
2408
 
2324
- if (fs$6.existsSync(depPackagePath)) {
2409
+ if (fs$9.existsSync(depPackagePath)) {
2325
2410
  const packageData = require(depPackagePath);
2326
2411
 
2327
2412
  if (dependencies[key] === 'latest') {
@@ -2347,18 +2432,18 @@ var checkDependencies = {
2347
2432
  checkPackageVersion: checkPackageVersion$1
2348
2433
  };
2349
2434
 
2350
- const shelljs$4 = require$$2__default;
2351
- const fs$5 = require$$0__default$1;
2352
- const path$6 = require$$1__default$1;
2435
+ const shelljs$3 = require$$0__default$2;
2436
+ const fs$8 = require$$0__default$1;
2437
+ const path$7 = require$$1__default$1;
2353
2438
  const io$1 = io$3;
2354
2439
  const {
2355
- createTask: createTask$1,
2356
- resolve: resolve$8,
2357
- getAbsolutePath: getAbsolutePath$1
2440
+ createTask: createTask$4,
2441
+ resolve: resolve$d,
2442
+ getAbsolutePath: getAbsolutePath$4
2358
2443
  } = widgets;
2359
2444
  const {
2360
2445
  buildMpNpm
2361
- } = mpCi;
2446
+ } = mpCi$2;
2362
2447
  const {
2363
2448
  setCache,
2364
2449
  getCache
@@ -2370,7 +2455,7 @@ const {
2370
2455
  npmInstallAll
2371
2456
  } = npm;
2372
2457
  const {
2373
- info: info$6
2458
+ info: info$c
2374
2459
  } = log$1;
2375
2460
  const {
2376
2461
  fileMd5
@@ -2379,25 +2464,25 @@ const {
2379
2464
  isDependenciesUpdate
2380
2465
  } = checkDependencies;
2381
2466
 
2382
- async function install$2(tmsConfig, subPackages, useCache) {
2467
+ async function install$3(tmsConfig, subPackages, useCache = true) {
2383
2468
  const cwd = process.cwd();
2384
- const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2469
+ const npmInstallRes = await createTask$4(npmInstall$1, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2385
2470
 
2386
2471
  if (!npmInstallRes.isCache) {
2387
2472
  // 构建miniprogram_npm, 不使用缓存
2388
- await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
2473
+ await createTask$4(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
2389
2474
  } else {
2390
2475
  // 构建miniprogram_npm
2391
- await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2476
+ await createTask$4(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2392
2477
  }
2393
2478
 
2394
- shelljs$4.cd(cwd);
2479
+ shelljs$3.cd(cwd);
2395
2480
  }
2396
2481
 
2397
- async function npmInstall(tmsConfig, subPackages, useCache) {
2482
+ async function npmInstall$1(tmsConfig, subPackages, useCache) {
2398
2483
  // 如果依赖没有更新和使用缓存数据(则命中缓存)
2399
- if (!isDependenciesUpdate(subPackages, resolve$8('./'), tmsConfig.outputDir) && useCache) {
2400
- info$6('node_modules命中缓存');
2484
+ if (!isDependenciesUpdate(subPackages, resolve$d('./'), tmsConfig.outputDir) && useCache) {
2485
+ info$c('node_modules命中缓存');
2401
2486
  return {
2402
2487
  isCache: true
2403
2488
  };
@@ -2405,12 +2490,12 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
2405
2490
 
2406
2491
 
2407
2492
  subPackages.forEach(item => {
2408
- const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
2493
+ const outputModuleDir = resolve$d(`${tmsConfig.outputDir}/${item.root}`);
2409
2494
  io$1.ensureDirExist(outputModuleDir);
2410
- const modulePackagePath = `${getAbsolutePath$1(item.path)}/package.json`;
2411
- if (fs$5.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
2495
+ const modulePackagePath = `${getAbsolutePath$4(item.path)}/package.json`;
2496
+ if (fs$8.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
2412
2497
  });
2413
- await npmInstallAll(subPackages, resolve$8(tmsConfig.outputDir), NODE_MODULES_DIR$1);
2498
+ await npmInstallAll(subPackages, resolve$d(tmsConfig.outputDir), NODE_MODULES_DIR$1);
2414
2499
  return {
2415
2500
  isCache: false
2416
2501
  };
@@ -2419,16 +2504,16 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
2419
2504
 
2420
2505
  async function mpCiInstall(tmsConfig, subPackages, useCache) {
2421
2506
  const packageJsonFiles = [];
2422
- const rootPackFile = resolve$8(`${tmsConfig.outputDir}/package.json`);
2507
+ const rootPackFile = resolve$d(`${tmsConfig.outputDir}/package.json`);
2423
2508
 
2424
- if (fs$5.existsSync(rootPackFile)) {
2509
+ if (fs$8.existsSync(rootPackFile)) {
2425
2510
  packageJsonFiles.push(rootPackFile);
2426
2511
  }
2427
2512
 
2428
2513
  subPackages.forEach(item => {
2429
- const packageJsonFile = resolve$8(`${tmsConfig.outputDir}/${item.root}/package.json`);
2514
+ const packageJsonFile = resolve$d(`${tmsConfig.outputDir}/${item.root}/package.json`);
2430
2515
 
2431
- if (fs$5.existsSync(packageJsonFile)) {
2516
+ if (fs$8.existsSync(packageJsonFile)) {
2432
2517
  packageJsonFiles.push(packageJsonFile);
2433
2518
  }
2434
2519
  });
@@ -2441,8 +2526,8 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2441
2526
  if (useCache) {
2442
2527
  let flag = true;
2443
2528
  await Promise.all(packageJsonFiles.map(async item => {
2444
- const packageDir = path$6.dirname(item);
2445
- const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2529
+ const packageDir = path$7.dirname(item);
2530
+ const mpDir = resolve$d(`${packageDir}/miniprogram_npm`);
2446
2531
  const md5Value = await getMNPMd5(packageDir);
2447
2532
  const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
2448
2533
  // 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
@@ -2455,14 +2540,14 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2455
2540
  }
2456
2541
 
2457
2542
  if (isCache) {
2458
- info$6('miniprogram_npm命中缓存');
2543
+ info$c('miniprogram_npm命中缓存');
2459
2544
  return;
2460
2545
  } // 即将构建,在cache中标记开始
2461
2546
 
2462
2547
 
2463
2548
  await Promise.all(packageJsonFiles.map(async item => {
2464
- const packageDir = path$6.dirname(item);
2465
- const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2549
+ const packageDir = path$7.dirname(item);
2550
+ const mpDir = resolve$d(`${packageDir}/miniprogram_npm`);
2466
2551
  setCache(mpDir, 'miniprogram_npm', {
2467
2552
  md5: '',
2468
2553
  status: statusMap.doing
@@ -2470,13 +2555,13 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2470
2555
  }));
2471
2556
  await buildMpNpm({
2472
2557
  appId: tmsConfig.appId,
2473
- projectPath: resolve$8('./'),
2558
+ projectPath: resolve$d('./'),
2474
2559
  privateKey: tmsConfig.privateKey
2475
2560
  }); // 构建成功后,计算md5写入cache
2476
2561
 
2477
2562
  await Promise.all(packageJsonFiles.map(async item => {
2478
- const packageDir = path$6.dirname(item);
2479
- const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2563
+ const packageDir = path$7.dirname(item);
2564
+ const mpDir = resolve$d(`${packageDir}/miniprogram_npm`);
2480
2565
  const md5Value = await getMNPMd5(packageDir);
2481
2566
  setCache(mpDir, 'miniprogram_npm', {
2482
2567
  md5: md5Value,
@@ -2491,30 +2576,30 @@ async function getMNPMd5(cwd) {
2491
2576
  async: false,
2492
2577
  silent: true
2493
2578
  };
2494
- shelljs$4.cd(cwd);
2579
+ shelljs$3.cd(cwd);
2495
2580
 
2496
- if (fs$5.existsSync('miniprogram_npm')) {
2497
- shelljs$4.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2581
+ if (fs$8.existsSync('miniprogram_npm')) {
2582
+ shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2498
2583
  cwd,
2499
2584
  ...shellJsOption
2500
2585
  });
2501
- const tarDir = path$6.join(cwd, './miniprogram_npm.tar.gz');
2586
+ const tarDir = path$7.join(cwd, './miniprogram_npm.tar.gz');
2502
2587
  const md5Value = await fileMd5(tarDir);
2503
- shelljs$4.rm('-rf', tarDir);
2588
+ shelljs$3.rm('-rf', tarDir);
2504
2589
  return md5Value;
2505
2590
  }
2506
2591
 
2507
2592
  return '';
2508
2593
  }
2509
2594
 
2510
- var install_1 = install$2;
2595
+ var install_1 = install$3;
2511
2596
 
2512
- const shelljs$3 = require$$2__default;
2513
- const fs$4 = require$$0__default$1;
2597
+ const shelljs$2 = require$$0__default$2;
2598
+ const fs$7 = require$$0__default$1;
2514
2599
  const io = io$3;
2515
2600
  const {
2516
- resolve: resolve$7,
2517
- createTask
2601
+ resolve: resolve$c,
2602
+ createTask: createTask$3
2518
2603
  } = widgets;
2519
2604
  const {
2520
2605
  buildOutputAppJson: buildOutputAppJson$1
@@ -2531,10 +2616,10 @@ const {
2531
2616
  getSubPackages: getSubPackages$2
2532
2617
  } = tmsMpconfig.exports;
2533
2618
  const {
2534
- fail: fail$3,
2535
- info: info$5
2619
+ fail: fail$4,
2620
+ info: info$b
2536
2621
  } = log$1;
2537
- const install$1 = install_1;
2622
+ const install$2 = install_1;
2538
2623
  /**
2539
2624
  * 拷贝相关配置文件到编译输出目录
2540
2625
  * @param { object } tmsConfig
@@ -2544,28 +2629,28 @@ const install$1 = install_1;
2544
2629
  */
2545
2630
 
2546
2631
  const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2547
- const outputDir = resolve$7(tmsConfig.outputDir);
2632
+ const outputDir = resolve$c(tmsConfig.outputDir);
2548
2633
  io.ensureDirExist(outputDir);
2549
2634
  defaultFiles.forEach(item => {
2550
- if (fs$4.existsSync(resolve$7(item))) {
2551
- shelljs$3.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
2635
+ if (fs$7.existsSync(resolve$c(item))) {
2636
+ shelljs$2.cp('-rf', resolve$c(item), resolve$c(tmsConfig.outputDir, item));
2552
2637
  }
2553
2638
  });
2554
2639
  };
2555
2640
 
2556
2641
  async function task(tmsConfig, targetModules) {
2557
2642
  // 下载和移动代码
2558
- await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$7('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2643
+ await createTask$3(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$c('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2559
2644
 
2560
2645
  const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
2561
2646
 
2562
2647
  const newSubPackages = getSubPackages$2(newModules); // 拷贝相关配置文件到输出目录
2563
2648
 
2564
- await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
2649
+ await createTask$3(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
2565
2650
 
2566
- await install$1(tmsConfig, newSubPackages, true); // 动态生成编译后的app.json;
2651
+ await install$2(tmsConfig, newSubPackages, true); // 动态生成编译后的app.json;
2567
2652
 
2568
- await createTask(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2653
+ await createTask$3(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2569
2654
  return {
2570
2655
  modules: newModules,
2571
2656
  subPackages: newSubPackages
@@ -2578,8 +2663,8 @@ async function init$3(tmsConfig, targetModules) {
2578
2663
  return taskRes;
2579
2664
  } catch (error) {
2580
2665
  const errMsg = typeof error === 'object' ? error.message : error;
2581
- fail$3(`初始化流程出现错误: ${errMsg}`);
2582
- info$5('详细的错误信息', error);
2666
+ fail$4(`初始化流程出现错误: ${errMsg}`);
2667
+ info$b('详细的错误信息', error);
2583
2668
  process.exit(1);
2584
2669
  }
2585
2670
  }
@@ -2606,24 +2691,24 @@ function mpProjectJson$1() {
2606
2691
  var mpProjectJson_1 = mpProjectJson$1;
2607
2692
 
2608
2693
  const {
2609
- src: src$1,
2610
- dest
2611
- } = require$$0__default$7;
2612
- const path$5 = require$$1__default$1;
2613
- const minimatch = require$$2__default$1;
2694
+ src: src$2,
2695
+ dest: dest$1
2696
+ } = require$$0__default$8;
2697
+ const path$6 = require$$1__default$1;
2698
+ const minimatch = require$$2__default;
2614
2699
  const gulpif = require$$3__default$1;
2615
2700
  const mpProjectJson = mpProjectJson_1;
2616
2701
  const {
2617
- resolve: resolve$6
2702
+ resolve: resolve$b
2618
2703
  } = widgets;
2619
2704
  const through = require$$6__default;
2620
2705
  const {
2621
- fail: fail$2
2706
+ fail: fail$3
2622
2707
  } = log$1;
2623
2708
 
2624
- const getTargetFile$1 = (sourceFile, module, outputDir) => {
2625
- const sourceFileRelativeModule = path$5.relative(resolve$6(module.from), sourceFile);
2626
- const targetFile = resolve$6(outputDir, module.to, sourceFileRelativeModule);
2709
+ const getTargetFile$2 = (sourceFile, module, outputDir) => {
2710
+ const sourceFileRelativeModule = path$6.relative(resolve$b(module.from), sourceFile);
2711
+ const targetFile = resolve$b(outputDir, module.to, sourceFileRelativeModule);
2627
2712
  return targetFile;
2628
2713
  };
2629
2714
 
@@ -2641,7 +2726,7 @@ const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
2641
2726
  tmsConfig,
2642
2727
  sourceFile,
2643
2728
  vinyl,
2644
- targetFile: getTargetFile$1(sourceFile, pluginParams.module, tmsConfig.outputDir),
2729
+ targetFile: getTargetFile$2(sourceFile, pluginParams.module, tmsConfig.outputDir),
2645
2730
  isDev: pluginParams.isDev,
2646
2731
  next
2647
2732
  });
@@ -2662,15 +2747,15 @@ var compile$1 = function (tmsConfig, {
2662
2747
  taskFn: (sourceFile, targetPath) => {
2663
2748
  const newGlobValue = Array.isArray(sourceFile) ? sourceFile : glob;
2664
2749
  const newDestPath = targetPath ? targetPath : destPath;
2665
- let srcPipe = src$1(newGlobValue, { ...srcOption
2750
+ let srcPipe = src$2(newGlobValue, { ...srcOption
2666
2751
  });
2667
2752
  const pluginParams = {
2668
2753
  module,
2669
2754
  isDev
2670
2755
  };
2671
2756
  srcPipe = addPlugins(tmsConfig, srcPipe, pluginParams);
2672
- return srcPipe.pipe(dest(newDestPath)).on('error', err => {
2673
- fail$2(`编译报错${err}`);
2757
+ return srcPipe.pipe(dest$1(newDestPath)).on('error', err => {
2758
+ fail$3(`编译报错${err}`);
2674
2759
  });
2675
2760
  }
2676
2761
  });
@@ -2680,9 +2765,9 @@ var compile$1 = function (tmsConfig, {
2680
2765
  /* eslint-disable */
2681
2766
  // 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
2682
2767
 
2683
- const assign = require$$0__default$8;
2684
- const path$4 = require$$1__default$1;
2685
- const PluginError = require$$2__default$2;
2768
+ const assign = require$$0__default$9;
2769
+ const path$5 = require$$1__default$1;
2770
+ const PluginError = require$$2__default$1;
2686
2771
  const fancyLog = require$$3__default$2;
2687
2772
  const colors = require$$4__default$1;
2688
2773
  const chokidar = require$$5__default;
@@ -2712,7 +2797,7 @@ function normalizeGlobs(globs) {
2712
2797
  return globs;
2713
2798
  }
2714
2799
 
2715
- function watch$2(globs, opts, cb) {
2800
+ function watch$3(globs, opts, cb) {
2716
2801
  globs = normalizeGlobs(globs);
2717
2802
 
2718
2803
  if (typeof opts === 'function') {
@@ -2720,16 +2805,16 @@ function watch$2(globs, opts, cb) {
2720
2805
  opts = {};
2721
2806
  }
2722
2807
 
2723
- opts = assign({}, watch$2._defaultOptions, opts);
2808
+ opts = assign({}, watch$3._defaultOptions, opts);
2724
2809
 
2725
2810
  cb = cb || function () {};
2726
2811
 
2727
2812
  function resolveFilepath(filepath) {
2728
2813
  if (pathIsAbsolute(filepath)) {
2729
- return path$4.normalize(filepath);
2814
+ return path$5.normalize(filepath);
2730
2815
  }
2731
2816
 
2732
- return path$4.resolve(opts.cwd || process.cwd(), filepath);
2817
+ return path$5.resolve(opts.cwd || process.cwd(), filepath);
2733
2818
  }
2734
2819
 
2735
2820
  function resolveGlob(glob) {
@@ -2785,7 +2870,7 @@ function watch$2(globs, opts, cb) {
2785
2870
  let glob;
2786
2871
  let currentFilepath = filepath;
2787
2872
 
2788
- while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$4.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
2873
+ while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$5.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
2789
2874
 
2790
2875
 
2791
2876
  if (!glob) {
@@ -2794,7 +2879,7 @@ function watch$2(globs, opts, cb) {
2794
2879
  }
2795
2880
 
2796
2881
  if (!baseForced) {
2797
- fileOpts.base = path$4.normalize(globParent(glob));
2882
+ fileOpts.base = path$5.normalize(globParent(glob));
2798
2883
  } // Do not stat deleted files
2799
2884
 
2800
2885
 
@@ -2845,36 +2930,36 @@ function watch$2(globs, opts, cb) {
2845
2930
  // Avoid modifying gulp-watch's default options inside a library/reusable package, please.
2846
2931
 
2847
2932
 
2848
- watch$2._defaultOptions = {
2933
+ watch$3._defaultOptions = {
2849
2934
  events: ['add', 'change', 'unlink'],
2850
2935
  ignoreInitial: true,
2851
2936
  readDelay: 10
2852
2937
  };
2853
- var gulpWatch = watch$2;
2938
+ var gulpWatch = watch$3;
2854
2939
 
2855
2940
  /* eslint-disable no-restricted-syntax */
2856
- const watch$1 = gulpWatch;
2857
- const path$3 = require$$1__default$1;
2858
- const shellJs = require$$2__default;
2941
+ const watch$2 = gulpWatch;
2942
+ const path$4 = require$$1__default$1;
2943
+ const shellJs$2 = require$$0__default$2;
2859
2944
  const {
2860
- series: series$1
2861
- } = require$$0__default$7;
2945
+ series: series$2
2946
+ } = require$$0__default$8;
2862
2947
  const {
2863
- info: info$4,
2948
+ info: info$a,
2864
2949
  warn: warn$1,
2865
- fail: fail$1
2950
+ fail: fail$2
2866
2951
  } = log$1;
2867
2952
  const {
2868
- resolve: resolve$5,
2869
- filterField: filterField$3
2953
+ resolve: resolve$a,
2954
+ filterField: filterField$5
2870
2955
  } = widgets;
2871
2956
  const {
2872
- global: global$2
2957
+ global: global$6
2873
2958
  } = global_1;
2874
2959
  const {
2875
2960
  checkPackageVersion
2876
2961
  } = checkDependencies;
2877
- const report$5 = report_1;
2962
+ const report$7 = report_1;
2878
2963
  const TIP_MAP = {
2879
2964
  'package.json': {
2880
2965
  tip: '依赖版本有变动,请重新执行tmskit run dev',
@@ -2903,31 +2988,31 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
2903
2988
  }
2904
2989
  }
2905
2990
 
2906
- info$4(`${fileName}有更新`);
2991
+ info$a(`${fileName}有更新`);
2907
2992
  } catch (e) {
2908
- fail$1(`${sourceFile}文件更新提示出现错误: ${e.message}`);
2993
+ fail$2(`${sourceFile}文件更新提示出现错误: ${e.message}`);
2909
2994
  }
2910
2995
  };
2911
2996
 
2912
- const getTargetFile = (sourceFile, module, outputDir) => {
2913
- const sourceFileRelativeModule = path$3.relative(resolve$5(module.from), sourceFile);
2914
- const targetFile = resolve$5(outputDir, module.to, sourceFileRelativeModule);
2997
+ const getTargetFile$1 = (sourceFile, module, outputDir) => {
2998
+ const sourceFileRelativeModule = path$4.relative(resolve$a(module.from), sourceFile);
2999
+ const targetFile = resolve$a(outputDir, module.to, sourceFileRelativeModule);
2915
3000
  return targetFile;
2916
3001
  };
2917
3002
 
2918
3003
  var watch_1 = function (globValue, watchOptions, callback, module) {
2919
- watch$1(globValue, { // readDelay: 100,
3004
+ watch$2(globValue, { // readDelay: 100,
2920
3005
  ...watchOptions
2921
3006
  }, vinyl => {
2922
3007
  const sourceFile = vinyl.history[0];
2923
3008
  const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
2924
3009
  const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
2925
- const tmsConfig = global$2.getData('tmsConfig');
2926
- const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
3010
+ const tmsConfig = global$6.getData('tmsConfig');
3011
+ const targetFile = getTargetFile$1(sourceFile, module, tmsConfig.outputDir);
2927
3012
 
2928
3013
  if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
2929
- info$4(`删除${sourceFileName}`);
2930
- shellJs.rm('-rf', targetFile);
3014
+ info$a(`删除${sourceFileName}`);
3015
+ shellJs$2.rm('-rf', targetFile);
2931
3016
  updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
2932
3017
  return;
2933
3018
  }
@@ -2954,13 +3039,13 @@ async function runCallback({
2954
3039
  // callbacl.name === taskFn 代表进入gulp编译流程
2955
3040
  // series为gulp编译串行执行,callback执行完毕后,执行updateFileHooks钩子
2956
3041
  if (callback.name === 'taskFn') {
2957
- series$1(callback.bind(null, [sourceFile], path$3.dirname(targetFile)), cb => {
3042
+ series$2(callback.bind(null, [sourceFile], path$4.dirname(targetFile)), cb => {
2958
3043
  cb();
2959
3044
  updateFileHook(tmsConfig, sourceFile, targetFile, type);
2960
3045
  })();
2961
3046
  } else {
2962
3047
  // 普通的callback函数
2963
- await callback([sourceFile], path$3.dirname(targetFile));
3048
+ await callback([sourceFile], path$4.dirname(targetFile));
2964
3049
  await updateFileHook(tmsConfig, sourceFile, targetFile, type);
2965
3050
  }
2966
3051
  } // 执行源码文件更新的钩子
@@ -2971,28 +3056,29 @@ async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
2971
3056
 
2972
3057
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateFile) === 'function') {
2973
3058
  await tmsConfig.hooks.updateFile({
2974
- tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
3059
+ tmsConfig: filterField$5(tmsConfig, ['gitAccount']),
3060
+ cmdOptions: global$6.getData('cmdOptions'),
2975
3061
  sourceFile,
2976
3062
  targetFile,
2977
3063
  type
2978
3064
  });
2979
- report$5('hooks:updateFile');
3065
+ report$7('hooks:updateFile');
2980
3066
  }
2981
3067
  }
2982
3068
 
2983
- const path$2 = require$$1__default$1;
2984
- const fs$3 = require$$0__default$1;
2985
- const ora = require$$0__default;
3069
+ const path$3 = require$$1__default$1;
3070
+ const fs$6 = require$$0__default$1;
3071
+ const ora$1 = require$$0__default;
2986
3072
  const chalk$3 = require$$3__default;
2987
3073
  const {
2988
- parallel,
2989
- series
2990
- } = require$$0__default$7;
3074
+ parallel: parallel$1,
3075
+ series: series$1
3076
+ } = require$$0__default$8;
2991
3077
  const {
2992
- resolve: resolve$4,
3078
+ resolve: resolve$9,
2993
3079
  mergeMap,
2994
- filterField: filterField$2,
2995
- getAbsolutePath
3080
+ filterField: filterField$4,
3081
+ getAbsolutePath: getAbsolutePath$3
2996
3082
  } = widgets;
2997
3083
  const {
2998
3084
  buildOutputAppJson
@@ -3001,23 +3087,26 @@ const {
3001
3087
  DEFAULT_COPY_CONFIG
3002
3088
  } = constant;
3003
3089
  const compile = compile$1;
3004
- const watch = watch_1;
3090
+ const watch$1 = watch_1;
3005
3091
  const {
3006
- info: info$3
3092
+ info: info$9
3007
3093
  } = log$1;
3008
- const report$4 = report_1;
3094
+ const report$6 = report_1;
3095
+ const {
3096
+ global: global$5
3097
+ } = global_1;
3009
3098
  const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
3010
3099
 
3011
- var dev$3 = async (tmsConfig, modules, isDev = true) => {
3100
+ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3012
3101
  const compileTasksMap = new Map(); // 监听根目录的文件
3013
3102
 
3014
3103
  mergeMap(compileTasksMap, compile(tmsConfig, {
3015
- glob: DEFAULT_COPY_CONFIG.map(item => resolve$4(item)),
3104
+ glob: DEFAULT_COPY_CONFIG.map(item => resolve$9(item)),
3016
3105
  module: {
3017
- from: resolve$4(),
3018
- to: resolve$4(tmsConfig.outputDir)
3106
+ from: resolve$9(),
3107
+ to: resolve$9(tmsConfig.outputDir)
3019
3108
  },
3020
- destPath: resolve$4(tmsConfig.outputDir),
3109
+ destPath: resolve$9(tmsConfig.outputDir),
3021
3110
  srcOption: {
3022
3111
  allowEmpty: true
3023
3112
  },
@@ -3031,12 +3120,12 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3031
3120
  },
3032
3121
  ...moduleItem
3033
3122
  };
3034
- const srcModulePath = getAbsolutePath(moduleItem.path);
3035
- const buildModulePath = resolve$4(tmsConfig.outputDir, moduleItem.modulePath);
3123
+ const srcModulePath = getAbsolutePath$3(moduleItem.path);
3124
+ const buildModulePath = resolve$9(tmsConfig.outputDir, moduleItem.modulePath);
3036
3125
 
3037
3126
  if (isDev) {
3038
3127
  // 监听模块配置文件
3039
- watch([`${srcModulePath}/**/module.config.json`], {
3128
+ watch$1([`${srcModulePath}/**/module.config.json`], {
3040
3129
  events: watchEvents
3041
3130
  }, () => buildOutputAppJson(tmsConfig, modules, isDev), {
3042
3131
  from: srcModulePath,
@@ -3045,14 +3134,14 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3045
3134
  }
3046
3135
 
3047
3136
  const excludes = moduleItem.exclude.map(ePath => {
3048
- const newPath = getAbsolutePath(ePath, srcModulePath);
3049
- const ext = path$2.extname(ePath).slice(1);
3137
+ const newPath = getAbsolutePath$3(ePath, srcModulePath);
3138
+ const ext = path$3.extname(ePath).slice(1);
3050
3139
 
3051
3140
  if (ext) {
3052
- return `!${resolve$4(srcModulePath, newPath)}`;
3141
+ return `!${resolve$9(srcModulePath, newPath)}`;
3053
3142
  }
3054
3143
 
3055
- return `!${resolve$4(srcModulePath, newPath)}/**/*`;
3144
+ return `!${resolve$9(srcModulePath, newPath)}/**/*`;
3056
3145
  });
3057
3146
  mergeMap(compileTasksMap, compile(tmsConfig, {
3058
3147
  glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
@@ -3071,10 +3160,10 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3071
3160
 
3072
3161
  if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
3073
3162
  for (const item of tmsConfig.static) {
3074
- item.from = getAbsolutePath(item.from);
3075
- item.to = getAbsolutePath(item.to);
3163
+ item.from = getAbsolutePath$3(item.from);
3164
+ item.to = getAbsolutePath$3(item.to);
3076
3165
  let glob = {};
3077
- const ext = path$2.extname(item.from).slice(1);
3166
+ const ext = path$3.extname(item.from).slice(1);
3078
3167
 
3079
3168
  if (ext) {
3080
3169
  glob = [item.from];
@@ -3082,7 +3171,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3082
3171
  glob = [`${item.from}/**/*`];
3083
3172
  }
3084
3173
 
3085
- const from = fs$3.lstatSync(item.from).isFile() ? path$2.dirname(item.from) : item.from;
3174
+ const from = fs$6.lstatSync(item.from).isFile() ? path$3.dirname(item.from) : item.from;
3086
3175
  mergeMap(compileTasksMap, compile(tmsConfig, {
3087
3176
  glob,
3088
3177
  destPath: item.to,
@@ -3100,10 +3189,10 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3100
3189
 
3101
3190
  let sTime;
3102
3191
  let eTime;
3103
- const spinner = ora();
3192
+ const spinner = ora$1();
3104
3193
 
3105
3194
  function start(cb) {
3106
- info$3('启动编译...');
3195
+ info$9('启动编译...');
3107
3196
  spinner.start();
3108
3197
  sTime = new Date().getTime();
3109
3198
  cb();
@@ -3114,19 +3203,19 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3114
3203
 
3115
3204
  if (isDev) {
3116
3205
  // 监听app.json
3117
- watch([resolve$4('app.json')], {
3206
+ watch$1([resolve$9('app.json')], {
3118
3207
  ignoreInitial: false,
3119
3208
  events: watchEvents
3120
3209
  }, () => buildOutputAppJson(tmsConfig, modules, isDev), {
3121
- from: resolve$4(),
3122
- to: resolve$4(tmsConfig.outputDir)
3210
+ from: resolve$9(),
3211
+ to: resolve$9(tmsConfig.outputDir)
3123
3212
  }); // 监听其他文件
3124
3213
 
3125
3214
  compileTasksMap.forEach(({
3126
3215
  taskFn,
3127
3216
  module
3128
3217
  }, globValue) => {
3129
- watch(globValue, {
3218
+ watch$1(globValue, {
3130
3219
  ignoreInitial: true,
3131
3220
  events: watchEvents
3132
3221
  }, taskFn, module);
@@ -3142,10 +3231,11 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3142
3231
 
3143
3232
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterFirstCompile({
3144
3233
  isDev,
3145
- tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
3146
- modules
3234
+ tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
3235
+ modules,
3236
+ cmdOptions: global$5.getData('cmdOptions')
3147
3237
  }));
3148
- report$4('hooks:afterCompile');
3238
+ report$6('hooks:afterCompile');
3149
3239
  }
3150
3240
 
3151
3241
  spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
@@ -3160,410 +3250,703 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3160
3250
  compileTasks.push(taskFn);
3161
3251
  }); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
3162
3252
 
3163
- series(start, parallel(...compileTasks), end)();
3253
+ series$1(start, parallel$1(...compileTasks), end)();
3164
3254
  };
3165
3255
 
3166
- var require$$12 = {
3167
- name: "@tmsfe/tmskit",
3168
- version: "0.0.24",
3169
- description: "tmskit",
3170
- main: "dist/index.cjs",
3171
- bin: {
3172
- tmskit: "main.js"
3173
- },
3174
- files: [
3175
- "build",
3176
- "src",
3177
- "dist",
3178
- "main.js",
3179
- "package.json"
3180
- ],
3181
- scripts: {
3182
- dev: "rollup -wc --environment TARGET:tmskit",
3183
- build: "rollup -c --environment TARGET:tmskit",
3184
- "pub:patch": "sh build/publish.sh patch",
3185
- "pub:minor": "sh build/publish.sh minor",
3186
- "pub:major": "sh build/publish.sh major"
3187
- },
3188
- author: "tms·web",
3189
- license: "ISC",
3190
- buildOptions: {
3191
- formats: [
3192
- "cjs"
3193
- ]
3194
- },
3195
- devDependencies: {
3196
- "@rollup/plugin-babel": "^5.0.2",
3197
- "@rollup/plugin-commonjs": "^19.0.0",
3198
- "@rollup/plugin-json": "^4.0.3",
3199
- rollup: "^2.6.1"
3200
- },
3201
- dependencies: {
3202
- "ansi-colors": "1.1.0",
3203
- anymatch: "^1.3.0",
3204
- async: "^3.2.2",
3205
- chalk: "^4.1.0",
3206
- chokidar: "^3.5.3",
3207
- commander: "^8.3.0",
3208
- "copy-webpack-plugin": "^9.1.0",
3209
- ejs: "^3.1.5",
3210
- "fancy-log": "1.3.2",
3211
- "fs-extra": "^10.0.1",
3212
- "glob-ignore": "^1.0.2",
3213
- "glob-parent": "^3.0.1",
3214
- gulp: "^4.0.2",
3215
- "gulp-if": "^3.0.0",
3216
- "gulp-watch": "^5.0.1",
3217
- htmlparser2: "^7.2.0",
3218
- inquirer: "^7.3.3",
3219
- leven: "3.1.0",
3220
- lodash: "^4.17.21",
3221
- metalsmith: "^2.3.0",
3222
- minimatch: "^5.1.0",
3223
- "miniprogram-ci": "1.4.13",
3224
- moment: "^2.29.2",
3225
- "object-assign": "^4.0.1",
3226
- ora: "^5.1.0",
3227
- "path-is-absolute": "^1.0.1",
3228
- "plugin-error": "^1.0.0",
3229
- postcss: "^8.4.6",
3230
- precinct: "^8.3.1",
3231
- "readable-stream": "^2.2.2",
3232
- "replace-ext": "^2.0.0",
3233
- request: "^2.88.2",
3234
- shelljs: "^0.8.4",
3235
- slash: "^1.0.0",
3236
- "strip-comments": "^2.0.1",
3237
- through2: "^4.0.2",
3238
- unzipper: "^0.10.11",
3239
- vinyl: "^2.1.0",
3240
- "vinyl-file": "^2.0.0",
3241
- "vinyl-sourcemaps-apply": "^0.2.0"
3242
- },
3243
- engines: {
3244
- node: "^12.17.0 || >= 14.13.1"
3245
- },
3246
- jest: {
3247
- testEnvironment: "jest-environment-node"
3248
- }
3249
- };
3250
-
3251
- const fs$2 = require$$0__default$1;
3252
- const path$1 = require$$1__default$1;
3253
- const shelljs$2 = require$$2__default;
3254
- const chalk$2 = require$$3__default;
3255
- const request = require$$0__default$5;
3256
- const inquirer = require$$1__default$4;
3256
+ const shelljs$1 = require$$0__default$2;
3257
+ const compileDev = dev$4;
3257
3258
  const {
3258
- infoNoTime: infoNoTime$1
3259
- } = log$1;
3260
- const packageJson$1 = require$$12;
3259
+ resolve: resolve$8,
3260
+ filterField: filterField$3
3261
+ } = widgets;
3262
+ const init$2 = init_1;
3261
3263
  const {
3262
- VERSION_CACHE_FILE,
3263
- VERSION_URL
3264
- } = constant;
3264
+ getModulesByMergeDepModules: getModulesByMergeDepModules$1,
3265
+ getSubPackages: getSubPackages$1
3266
+ } = tmsMpconfig.exports;
3265
3267
  const {
3266
- ensureDirExist: ensureDirExist$1
3267
- } = io$3;
3268
+ info: info$8
3269
+ } = log$1;
3270
+ const {
3271
+ global: global$4
3272
+ } = global_1;
3268
3273
  const {
3269
- versionCompare
3270
- } = widgets; // 获取推荐的tmskit版本
3274
+ MODULE_CODE_DIR,
3275
+ NODE_MODULES_DIR
3276
+ } = constant;
3277
+ const report$5 = report_1; // const { recommendVersion } = require('../../../core/recommendVersion');
3278
+ // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3271
3279
 
3272
- function getRecommendVersion() {
3273
- return new Promise((resolve, reject) => {
3274
- request(`${VERSION_URL}?v=${new Date().getTime()}`, (error, response, body) => {
3275
- if (!error && response && response.statusCode === 200) {
3276
- resolve(JSON.parse(body));
3277
- } else {
3278
- reject(response.statusCode);
3279
- }
3280
- });
3280
+ function delOtherPackages(tmsConfig, targetSubPackages) {
3281
+ // 获取所有模块,合并模块依赖的模块
3282
+ const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all); // 获取所有的分包
3283
+
3284
+ const allSubPackages = getSubPackages$1(allModules);
3285
+ const targetSubPackagesName = targetSubPackages.map(item => item.name);
3286
+ allSubPackages.forEach(item => {
3287
+ if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
3288
+ const moduleRootDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
3289
+ shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
3290
+ silent: true
3291
+ }); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
3292
+ // io.ensureDirExist(moduleRootDir);
3293
+ }
3281
3294
  });
3282
- } // 获取当前用户tmskit的版本
3295
+ }
3283
3296
 
3297
+ async function dev$3(tmsConfig, targetModules) {
3298
+ var _tmsConfig$hooks;
3284
3299
 
3285
- function getUserTmskitVersion() {
3286
- const data = shelljs$2.exec('tmskit -v', {
3287
- async: false,
3288
- silent: true
3289
- });
3300
+ const {
3301
+ noCache
3302
+ } = global$4.getData('cmdOptions');
3290
3303
 
3291
- if (data.code === 0) {
3292
- // tmskit 0.0.21 => 0.0.21
3293
- return data.slice(7);
3304
+ if (noCache) {
3305
+ shelljs$1.rm('-rf', resolve$8(tmsConfig.outputDir));
3306
+ shelljs$1.rm('-rf', MODULE_CODE_DIR);
3307
+ shelljs$1.rm('-rf', NODE_MODULES_DIR);
3308
+ } // 推荐tmskit的版本
3309
+ // await recommendVersion();
3310
+ // 初始化操作
3311
+
3312
+
3313
+ const {
3314
+ subPackages,
3315
+ modules: newModules
3316
+ } = await init$2(tmsConfig, targetModules);
3317
+ info$8('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3318
+
3319
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
3320
+ var _tmsConfig$hooks2;
3321
+
3322
+ await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
3323
+ isDev: true,
3324
+ tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
3325
+ modules: newModules,
3326
+ cmdOptions: global$4.getData('cmdOptions')
3327
+ }));
3328
+ report$5('hooks:beforeCompile');
3294
3329
  }
3330
+ delOtherPackages(tmsConfig, subPackages);
3331
+ compileDev(tmsConfig, newModules, true);
3332
+ }
3295
3333
 
3296
- return '0.0.0';
3297
- } // 询问用户是否安装最新版本
3334
+ var dev_1 = dev$3;
3298
3335
 
3336
+ const dev$2 = dev$4;
3299
3337
 
3300
- function isInstallLatestVersion() {
3301
- return inquirer.prompt([{
3302
- type: 'confirm',
3303
- name: 'isInstall',
3304
- message: '是否安装最新版本',
3305
- choices: [{
3306
- name: '否',
3307
- value: false
3308
- }, {
3309
- name: '是',
3310
- value: true
3311
- }]
3312
- }]);
3313
- } // 获取tmskit的版本是否推荐过
3338
+ var build$2 = async (tmsConfig, newModules, isDev) => {
3339
+ dev$2(tmsConfig, newModules, isDev);
3340
+ };
3314
3341
 
3342
+ const shelljs = require$$0__default$2;
3343
+ const {
3344
+ resolve: resolve$7,
3345
+ filterField: filterField$2
3346
+ } = widgets;
3347
+ const init$1 = init_1;
3348
+ const {
3349
+ info: info$7
3350
+ } = log$1;
3351
+ const compileBuild = build$2;
3352
+ const report$4 = report_1;
3353
+ const {
3354
+ global: global$3
3355
+ } = global_1;
3315
3356
 
3316
- function getVersionIsRecommend(version) {
3317
- const filePath = VERSION_CACHE_FILE;
3357
+ async function build$1(tmsConfig, targetModules) {
3358
+ var _tmsConfig$hooks;
3318
3359
 
3319
- if (!fs$2.existsSync(filePath)) {
3320
- return false;
3321
- }
3360
+ // 开始构建前,清理输出目录
3361
+ await shelljs.rm('-rf', resolve$7(tmsConfig.outputDir));
3362
+ const {
3363
+ modules: newModules
3364
+ } = await init$1(tmsConfig, targetModules);
3365
+ info$7('当前build有效模块', newModules.map(item => item.moduleName).sort());
3366
+ const isDev = false;
3322
3367
 
3323
- const content = require(filePath);
3368
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
3369
+ var _tmsConfig$hooks2;
3324
3370
 
3325
- return content === null || content === void 0 ? void 0 : content[version];
3326
- } // 设置tmskit版本推荐过
3371
+ await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
3372
+ isDev,
3373
+ tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
3374
+ modules: newModules,
3375
+ cmdOptions: global$3.getData('cmdOptions')
3376
+ }));
3377
+ report$4('hooks:beforeCompile');
3378
+ }
3379
+ compileBuild(tmsConfig, newModules, isDev);
3380
+ }
3381
+
3382
+ var build_1 = build$1;
3327
3383
 
3384
+ const moment = require$$1__default;
3385
+ const path$2 = require$$1__default$1;
3386
+ const fs$5 = require$$0__default$1;
3387
+ const {
3388
+ getGitUser,
3389
+ getAbsolutePath: getAbsolutePath$2
3390
+ } = widgets;
3391
+ const {
3392
+ ensureDirExist: ensureDirExist$3
3393
+ } = io$3;
3328
3394
 
3329
- function setVersionRecommend(version, isRecommend) {
3330
- const filePath = VERSION_CACHE_FILE;
3395
+ function getAllSize$2(data = {}) {
3396
+ let allSize;
3331
3397
 
3332
- if (!fs$2.existsSync(filePath)) {
3333
- const dir = path$1.dirname(filePath);
3334
- ensureDirExist$1(dir);
3335
- fs$2.writeFileSync(filePath, '{}');
3398
+ for (const item of data === null || data === void 0 ? void 0 : data.subPackageInfo) {
3399
+ if (item.name === '__FULL__') {
3400
+ allSize = item.size;
3401
+ break;
3402
+ }
3336
3403
  }
3337
3404
 
3338
- const content = require(filePath);
3405
+ return allSize;
3406
+ }
3339
3407
 
3340
- content[version] = isRecommend;
3341
- fs$2.writeFileSync(filePath, JSON.stringify(content, null, 2));
3342
- } // 推荐理由
3408
+ const getDesc$2 = (desc = '') => {
3409
+ const user = getGitUser();
3410
+ const date = moment().format('YYYY-MM-DD HH:mm:ss');
3411
+ return `构建描述:${desc}; 构建人: ${user}; 构建时间:${date}`;
3412
+ };
3343
3413
 
3414
+ const outputInfo$2 = (infoOutput, data) => {
3415
+ const outPath = getAbsolutePath$2(infoOutput);
3416
+ const dir = path$2.dirname(outPath);
3417
+ ensureDirExist$3(dir);
3418
+ fs$5.writeFileSync(outPath, JSON.stringify(data, null, 2));
3419
+ };
3344
3420
 
3345
- function displayRecommends(arr) {
3346
- infoNoTime$1(chalk$2.green('构建工具有新的版本~~:'));
3347
- arr.forEach(item => {
3348
- infoNoTime$1(chalk$2.green(item));
3349
- });
3350
- } // 推荐tmskit的安装版本
3421
+ const getDetaultVersion = () => {
3422
+ const version = moment().format('gggg,mm').split(',');
3423
+ version.push('0');
3424
+ return version.join('.');
3425
+ };
3351
3426
 
3427
+ var utils = {
3428
+ getAllSize: getAllSize$2,
3429
+ getDesc: getDesc$2,
3430
+ outputInfo: outputInfo$2,
3431
+ getDetaultVersion
3432
+ };
3352
3433
 
3353
- async function recommendVersion$1() {
3434
+ const mpCi$1 = mpCi$2;
3435
+ const fs$4 = require$$0__default$1;
3436
+ const {
3437
+ resolve: resolve$6,
3438
+ createTask: createTask$2,
3439
+ getAbsolutePath: getAbsolutePath$1,
3440
+ filterField: filterField$1
3441
+ } = widgets;
3442
+ const {
3443
+ handleError: handleError$3
3444
+ } = handleError_1;
3445
+ const {
3446
+ info: info$6
3447
+ } = log$1;
3448
+ const {
3449
+ global: global$2
3450
+ } = global_1;
3451
+ const {
3452
+ getAllSize: getAllSize$1,
3453
+ outputInfo: outputInfo$1,
3454
+ getDesc: getDesc$1
3455
+ } = utils;
3456
+ const report$3 = report_1;
3457
+
3458
+ const handleParams$1 = (tmsConfig, cmdOptions) => {
3459
+ const params = { ...(tmsConfig.preview ? tmsConfig.preview : {}),
3460
+ ...cmdOptions
3461
+ };
3462
+ return { ...params,
3463
+ appId: params.appId || tmsConfig.appId,
3464
+ projectPath: resolve$6(tmsConfig.outputDir),
3465
+ privateKey: params.privateKey || tmsConfig.privateKey,
3466
+ robot: params.robot || 30,
3467
+ desc: params.desc || getDesc$1(params.desc),
3468
+ qrcodeOutputDest: getAbsolutePath$1(params.qrcodeOutputDest || '')
3469
+ };
3470
+ };
3471
+ /**
3472
+ * 预览
3473
+ * @params {object} tmsConfig
3474
+ * @param {object} cmdOptions {qrcodeFormat: 'base64', qrcodeOutputDest: './a.txt', robot: 2, infoOutput: './a.txt' }
3475
+ */
3476
+
3477
+
3478
+ async function preview$1(tmsConfig, cmdOptions) {
3354
3479
  try {
3355
- // 获取当前用户安装的版本
3356
- const tmskitVersion = getUserTmskitVersion(); // 获取官方推荐版本
3480
+ var _tmsConfig$hooks;
3357
3481
 
3358
- const recommendRes = await getRecommendVersion();
3359
- const recommendVersion = recommendRes.version; // 当前用户安装版本小于官方推荐版本 && 该版本没有推荐过
3482
+ const params = handleParams$1(tmsConfig, cmdOptions);
3360
3483
 
3361
- if (versionCompare(tmskitVersion, recommendVersion) === -1 && !getVersionIsRecommend(recommendVersion)) {
3362
- displayRecommends(recommendRes.version_detail); // 设置该版本推荐过
3484
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforePreview) === 'function') {
3485
+ var _tmsConfig$hooks2;
3363
3486
 
3364
- setVersionRecommend(recommendVersion, true); // 询问用户是否安装最新版本
3487
+ await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforePreview({
3488
+ tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
3489
+ cmdOptions: global$2.getData('cmdOptions'),
3490
+ params
3491
+ }));
3492
+ report$3('hooks:beforePreview');
3493
+ }
3365
3494
 
3366
- const installRes = await isInstallLatestVersion(recommendRes);
3495
+ ;
3496
+ const previewRes = await createTask$2(mpCi$1.previewMp, '正在构建预览码', '构建预览码完成')({ ...params
3497
+ });
3498
+ const allSize = getAllSize$1(previewRes);
3367
3499
 
3368
- if (installRes.isInstall) {
3369
- // mac
3370
- if (process.platform === 'darwin') {
3371
- infoNoTime$1(`将执行以下命令: ${chalk$2.green(`sudo npm install -g ${packageJson$1.name}@${recommendVersion}`)}`);
3372
- shelljs$2.exec(`sudo npm install -g ${packageJson$1.name}@${recommendVersion}`, {
3373
- async: false,
3374
- silent: false
3375
- });
3376
- process.exit(-1);
3377
- } else {
3378
- // window
3379
- infoNoTime$1(`请使用超级管理员执行以下命令: ${chalk$2.green(`npm install -g ${packageJson$1.name}@${recommendVersion}`)}`);
3380
- process.exit(-1);
3381
- }
3500
+ if (params.infoOutput) {
3501
+ let qrcodeBase64 = '';
3502
+
3503
+ if (params.qrcodeFormat === 'base64' && fs$4.existsSync(params.qrcodeOutputDest)) {
3504
+ qrcodeBase64 = fs$4.readFileSync(params.qrcodeOutputDest, 'utf8');
3382
3505
  }
3506
+
3507
+ outputInfo$1(params.infoOutput, {
3508
+ sourceCode: params.projectPath,
3509
+ qrcodeBase64,
3510
+ ...previewRes
3511
+ });
3383
3512
  }
3384
- } catch {}
3513
+
3514
+ info$6('预览包大小:', `${allSize}k`);
3515
+ } catch (e) {
3516
+ console.log('详细错误:', e);
3517
+ handleError$3(`预览错误: ${e.message}`, true);
3518
+ }
3385
3519
  }
3386
3520
 
3387
- var recommendVersion_1 = {
3388
- recommendVersion: recommendVersion$1
3389
- };
3521
+ var preview_1 = preview$1;
3390
3522
 
3391
- const shelljs$1 = require$$2__default;
3392
- const compileDev = dev$3;
3523
+ const mpCi = mpCi$2;
3393
3524
  const {
3394
- resolve: resolve$3,
3395
- filterField: filterField$1
3525
+ resolve: resolve$5,
3526
+ createTask: createTask$1,
3527
+ filterField
3396
3528
  } = widgets;
3397
- const init$2 = init_1;
3398
3529
  const {
3399
- getModulesByMergeDepModules: getModulesByMergeDepModules$1,
3400
- getSubPackages: getSubPackages$1
3401
- } = tmsMpconfig.exports;
3530
+ handleError: handleError$2
3531
+ } = handleError_1;
3402
3532
  const {
3403
- info: info$2
3533
+ info: info$5
3404
3534
  } = log$1;
3405
3535
  const {
3406
3536
  global: global$1
3407
3537
  } = global_1;
3408
3538
  const {
3409
- MODULE_CODE_DIR,
3410
- NODE_MODULES_DIR
3411
- } = constant;
3412
- const report$3 = report_1;
3413
- const {
3414
- recommendVersion
3415
- } = recommendVersion_1; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3539
+ getAllSize,
3540
+ outputInfo,
3541
+ getDesc
3542
+ } = utils;
3543
+ const report$2 = report_1;
3416
3544
 
3417
- function delOtherPackages(tmsConfig, targetSubPackages) {
3418
- // 获取所有模块,合并模块依赖的模块
3419
- const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all); // 获取所有的分包
3545
+ const handleParams = (tmsConfig, cmdOptions) => {
3546
+ const params = { ...(tmsConfig.upload ? tmsConfig.upload : {}),
3547
+ ...cmdOptions
3548
+ };
3420
3549
 
3421
- const allSubPackages = getSubPackages$1(allModules);
3422
- const targetSubPackagesName = targetSubPackages.map(item => item.name);
3423
- allSubPackages.forEach(item => {
3424
- if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
3425
- const moduleRootDir = resolve$3(`${tmsConfig.outputDir}/${item.root}`);
3426
- shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
3427
- silent: true
3428
- }); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
3429
- // io.ensureDirExist(moduleRootDir);
3550
+ if (!params.version) {
3551
+ throw new Error('请指定传入版本号 eg: tmskit run upload --version 2022.28.5');
3552
+ }
3553
+
3554
+ return { ...params,
3555
+ appId: params.appId || tmsConfig.appId,
3556
+ projectPath: resolve$5(tmsConfig.outputDir),
3557
+ privateKey: params.privateKey || tmsConfig.privateKey,
3558
+ robot: params.robot || 30,
3559
+ desc: params.desc || getDesc(params.desc)
3560
+ };
3561
+ };
3562
+ /**
3563
+ * 上传
3564
+ * @param {object} tmsConfig
3565
+ * @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
3566
+ */
3567
+
3568
+
3569
+ async function upload$1(tmsConfig, cmdOptions) {
3570
+ try {
3571
+ var _tmsConfig$hooks;
3572
+
3573
+ const params = handleParams(tmsConfig, cmdOptions);
3574
+
3575
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeUpload) === 'function') {
3576
+ var _tmsConfig$hooks2;
3577
+
3578
+ await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeUpload({
3579
+ tmsConfig: filterField(tmsConfig, ['gitAccount']),
3580
+ cmdOptions: global$1.getData('cmdOptions'),
3581
+ params
3582
+ }));
3583
+ report$2('hooks:beforeUpload');
3430
3584
  }
3431
- });
3585
+
3586
+ ;
3587
+ const uploadRes = await createTask$1(mpCi.uploadMp, '正在上传小程序代码', '上传小程序代码完成')({ ...params
3588
+ });
3589
+ const allSize = getAllSize(uploadRes);
3590
+
3591
+ if (params.infoOutput) {
3592
+ outputInfo(params.infoOutput, {
3593
+ sourceCode: params.projectPath,
3594
+ ...uploadRes
3595
+ });
3596
+ }
3597
+
3598
+ info$5(`上传包大小: ${allSize}k; 上传包版本: ${params.version}`);
3599
+ } catch (e) {
3600
+ console.log('详细错误:', e);
3601
+ handleError$2(`上传错误: ${e.message}`, true);
3602
+ }
3432
3603
  }
3433
3604
 
3434
- async function dev$2(tmsConfig, targetModules) {
3435
- var _tmsConfig$hooks;
3605
+ var upload_1 = upload$1;
3606
+
3607
+ const {
3608
+ resolve: resolve$4,
3609
+ getAbsolutePath
3610
+ } = widgets; // 处理tms.config.cloudModules的兼容数据
3436
3611
 
3612
+ function getTmsCloudModules(tmsConfig) {
3437
3613
  const {
3438
- noCache
3439
- } = global$1.getData('cmd');
3614
+ cloudModules
3615
+ } = tmsConfig;
3440
3616
 
3441
- if (noCache) {
3442
- shelljs$1.rm('-rf', resolve$3(tmsConfig.outputDir));
3443
- shelljs$1.rm('-rf', MODULE_CODE_DIR);
3444
- shelljs$1.rm('-rf', NODE_MODULES_DIR);
3445
- } // 推荐tmskit的版本
3617
+ if (Array.isArray(tmsConfig.cloudModules)) {
3618
+ return {
3619
+ all: [...tmsConfig.cloudModules],
3620
+ include: []
3621
+ };
3622
+ }
3623
+
3624
+ return cloudModules;
3625
+ }
3626
+ /**
3627
+ * 获取需要监听的云函数
3628
+ * @param {*} tmsConfig {}
3629
+ * @param {*} cmdOptions eg:{clouds: 'aggrecarshop,car'}
3630
+ * @returns
3631
+ * [{ name: '', sourcePath: '', targetPath: ''}]
3632
+ */
3446
3633
 
3447
3634
 
3448
- await recommendVersion(); // 初始化操作
3635
+ function getCloudsOfListen$2(tmsConfig, cmdOptions) {
3636
+ var _cmdOptions$cloud;
3449
3637
 
3450
- const {
3451
- subPackages,
3452
- modules: newModules
3453
- } = await init$2(tmsConfig, targetModules);
3454
- info$2('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3638
+ // 获取tmsconfig配置的云函数的配置项
3639
+ const cloudModules = getTmsCloudModules(tmsConfig);
3640
+ let includeClouds = (cmdOptions === null || cmdOptions === void 0 ? void 0 : (_cmdOptions$cloud = cmdOptions.cloud) === null || _cmdOptions$cloud === void 0 ? void 0 : _cmdOptions$cloud.split(',')) || cloudModules.include || []; // 如果没有配置include, 默认使用所有的数据云函数列表
3455
3641
 
3456
- if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
3457
- var _tmsConfig$hooks2;
3642
+ if (includeClouds.length === 0) {
3643
+ includeClouds = cloudModules.all.map(item => item.name);
3644
+ }
3458
3645
 
3459
- await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
3460
- isDev: true,
3461
- tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
3462
- modules: newModules
3463
- }));
3464
- report$3('hooks:beforeCompile');
3646
+ const result = [];
3647
+
3648
+ for (const item of cloudModules.all) {
3649
+ if (includeClouds.includes(item.name)) {
3650
+ result.push({
3651
+ name: item.name,
3652
+ sourcePath: `${getAbsolutePath(item.path)}`,
3653
+ targetPath: resolve$4(tmsConfig.cloudDir, item.name)
3654
+ });
3655
+ }
3465
3656
  }
3466
- delOtherPackages(tmsConfig, subPackages);
3467
- compileDev(tmsConfig, newModules, true);
3468
- }
3469
3657
 
3470
- var dev_1 = dev$2;
3658
+ return result;
3659
+ }
3471
3660
 
3472
- const dev$1 = dev$3;
3661
+ var getClouds = getCloudsOfListen$2;
3473
3662
 
3474
- var build$2 = async (tmsConfig, newModules, isDev) => {
3475
- dev$1(tmsConfig, newModules, isDev);
3476
- };
3663
+ const fs$3 = require$$0__default$1;
3664
+ /**
3665
+ * 检查云函数的配置项
3666
+ * @param {*} tmsConfig
3667
+ */
3477
3668
 
3478
- const shelljs = require$$2__default;
3479
- const {
3480
- resolve: resolve$2,
3481
- filterField
3482
- } = widgets;
3483
- const init$1 = init_1;
3484
- const compileBuild = build$2;
3485
- const report$2 = report_1;
3669
+ function checkCloudConfig$2(tmsConfig) {
3670
+ if (!tmsConfig.cloudModules) {
3671
+ return '你没有在tms.config.js的cloudModules注册云函数';
3672
+ }
3486
3673
 
3487
- async function build$1(tmsConfig, targetModules) {
3488
- var _tmsConfig$hooks;
3674
+ if (!tmsConfig.cloudDir) {
3675
+ return '你没有在tms.config.js配置云函数编译目录cloudDir';
3676
+ }
3489
3677
 
3490
- // 开始构建前,清理输出目录
3491
- await shelljs.rm('-rf', resolve$2(tmsConfig.outputDir));
3492
- const {
3493
- modules: newModules
3494
- } = await init$1(tmsConfig, targetModules);
3495
- const isDev = false;
3678
+ return;
3679
+ }
3680
+ /**
3681
+ * 检查云函数源码目录是否存在
3682
+ * @param {Array} clouds [{name: '', sourcePath: '', targetPath: ''}]
3683
+ */
3496
3684
 
3497
- if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
3498
- var _tmsConfig$hooks2;
3499
3685
 
3500
- await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
3501
- isDev,
3502
- tmsConfig: filterField(tmsConfig, ['gitAccount']),
3503
- modules: newModules
3504
- }));
3505
- report$2('hooks:beforeCompile');
3686
+ function checkSrcPathIsExist$1(clouds) {
3687
+ for (const item of clouds) {
3688
+ if (!fs$3.existsSync(item.sourcePath)) {
3689
+ return `${item.name}云函数的${item.sourcePath}目录不存在, 请检查tms.config.js>cloudModules>all云函数的配置目录`;
3690
+ }
3506
3691
  }
3507
- compileBuild(tmsConfig, newModules, isDev);
3692
+
3693
+ return;
3508
3694
  }
3509
3695
 
3510
- var build_1 = build$1;
3696
+ var check$2 = {
3697
+ checkCloudConfig: checkCloudConfig$2,
3698
+ checkSrcPathIsExist: checkSrcPathIsExist$1
3699
+ };
3511
3700
 
3512
- const fs$1 = require$$0__default$1;
3701
+ const fs$2 = require$$0__default$1;
3702
+ const {
3703
+ info: info$4
3704
+ } = log$1;
3513
3705
  const {
3514
- resolve: resolve$1
3706
+ resolve: resolve$3
3515
3707
  } = widgets;
3516
3708
  const {
3517
- ensureDirExist
3709
+ ensureDirExist: ensureDirExist$2
3518
3710
  } = io$3;
3519
3711
  const {
3520
3712
  warn,
3521
3713
  succeed
3522
3714
  } = log$1;
3523
- /**
3524
- * 根据相关配置创建软链接
3525
- * @param { object } tmsConfig
3526
- */
3715
+ const getCloudsOfListen$1 = getClouds;
3716
+ const {
3717
+ handleError: handleError$1
3718
+ } = handleError_1;
3719
+ const {
3720
+ checkCloudConfig: checkCloudConfig$1
3721
+ } = check$2;
3527
3722
 
3528
- const symLink$1 = tmsConfig => {
3529
- ensureDirExist(resolve$1(tmsConfig.cloudDir));
3723
+ var link = async (tmsConfig, cmdOptions) => {
3724
+ try {
3725
+ ensureDirExist$2(resolve$3(tmsConfig.cloudDir));
3726
+ checkCloudConfig$1(tmsConfig); // 获取需要监听的云函数列表
3530
3727
 
3531
- if (tmsConfig.cloudModules) {
3532
- tmsConfig.cloudModules.forEach(item => {
3533
- const sourcePath = resolve$1(item.path);
3534
- const targetPath = resolve$1(tmsConfig.cloudDir, item.name);
3728
+ const clouds = getCloudsOfListen$1(tmsConfig, cmdOptions); // 打印启动云函数列表
3535
3729
 
3536
- if (!fs$1.existsSync(sourcePath)) {
3537
- warn(`云函数${sourcePath}不存在`);
3730
+ info$4('当前启动云函数列表:', clouds.map(item => item.name).sort());
3731
+ clouds.forEach(item => {
3732
+ if (!fs$2.existsSync(item.sourcePath)) {
3733
+ warn(`云函数${item.sourcePath}不存在`);
3538
3734
  return;
3539
3735
  }
3540
3736
 
3541
- if (!fs$1.existsSync(targetPath)) {
3542
- fs$1.symlinkSync(sourcePath, targetPath);
3737
+ const stat = fs$2.lstatSync(item.targetPath);
3738
+
3739
+ if (!stat.isSymbolicLink()) {
3740
+ fs$2.symlinkSync(item.sourcePath, item.targetPath);
3543
3741
  }
3544
3742
  });
3545
3743
  succeed('云函数创建软链成功');
3546
- } else {
3547
- warn('你没有在tms.config.js的cloudModules注册云函数');
3744
+ } catch (e) {
3745
+ info$4('创建软链详细错误', e);
3746
+ handleError$1(`创建软链错误: ${e}`, true);
3747
+ }
3748
+ };
3749
+
3750
+ const shellJs$1 = require$$0__default$2;
3751
+ const fs$1 = require$$0__default$1;
3752
+ const {
3753
+ resolve: resolve$2,
3754
+ npmInstall
3755
+ } = widgets;
3756
+ const {
3757
+ ensureDirExist: ensureDirExist$1
3758
+ } = io$3;
3759
+ const {
3760
+ info: info$3
3761
+ } = log$1;
3762
+ /**
3763
+ * npm install
3764
+ * @param {array} clouds [{name: '', sourcePath: '', targetPath: ''}]
3765
+ */
3766
+
3767
+ const runInstall$1 = async (clouds, tmsConfig) => {
3768
+ const promises = [];
3769
+
3770
+ for (const item of clouds) {
3771
+ ensureDirExist$1(item.targetPath);
3772
+ const packageFilePath = resolve$2(item.sourcePath, 'package.json');
3773
+
3774
+ if (fs$1.existsSync(packageFilePath)) {
3775
+ shellJs$1.cp('-Rf', resolve$2(packageFilePath), item.targetPath);
3776
+ promises.push(() => {
3777
+ info$3(`云函数${item.name}: npm install`);
3778
+ return npmInstall(item.targetPath, tmsConfig.npm);
3779
+ });
3780
+ }
3548
3781
  }
3782
+ await Promise.all(promises.map(item => item()));
3549
3783
  };
3550
3784
 
3551
- var symbolicLink = {
3552
- symLink: symLink$1
3785
+ var install$1 = {
3786
+ runInstall: runInstall$1
3553
3787
  };
3554
3788
 
3789
+ const shellJs = require$$0__default$2;
3790
+ const ora = require$$0__default;
3791
+ const path$1 = require$$1__default$1;
3792
+ const chalk$2 = require$$3__default;
3555
3793
  const {
3556
- symLink
3557
- } = symbolicLink;
3794
+ resolve: resolve$1,
3795
+ createTask
3796
+ } = widgets;
3558
3797
  const {
3559
3798
  handleError
3560
3799
  } = handleError_1;
3800
+ const {
3801
+ ensureDirExist
3802
+ } = io$3;
3803
+ const {
3804
+ src: src$1,
3805
+ dest,
3806
+ parallel,
3807
+ series
3808
+ } = require$$0__default$8;
3809
+ const watch = gulpWatch;
3810
+ const {
3811
+ info: info$2,
3812
+ fail: fail$1
3813
+ } = log$1;
3814
+ const getCloudsOfListen = getClouds;
3815
+ const {
3816
+ checkCloudConfig,
3817
+ checkSrcPathIsExist
3818
+ } = check$2;
3819
+ const {
3820
+ runInstall
3821
+ } = install$1;
3822
+ /**
3823
+ * 获取云函数的编译任务
3824
+ * @param {array} clouds [{name: '', sourcePath: '', targetPath: ''}]
3825
+ * @param {object} srcOption gulp.src的参数
3826
+ * @returns Map {'${sourcePath}': {taskFn: () => {}, targetPath: 'xxx'}}
3827
+ */
3828
+
3829
+ const getCompileTasks = (clouds, srcOption) => {
3830
+ const compileTasksMap = new Map();
3831
+ clouds.forEach(item => {
3832
+ compileTasksMap.set(item.sourcePath, {
3833
+ targetPath: item.targetPath,
3834
+ taskFn: (sourceFile, targetPath) => {
3835
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : `${item.sourcePath}/**/*`;
3836
+ const newDestPath = targetPath ? targetPath : item.targetPath;
3837
+ const srcPipe = src$1(newGlobValue, srcOption);
3838
+ return srcPipe.pipe(dest(newDestPath)).on('error', err => {
3839
+ fail$1(`监听报错${err}`);
3840
+ });
3841
+ }
3842
+ });
3843
+ });
3844
+ return compileTasksMap;
3845
+ };
3846
+
3847
+ const getTargetFile = (sourceFile, sourcePath, targetPath) => {
3848
+ const sourceFileRelativeModule = path$1.relative(sourcePath, sourceFile);
3849
+ const targetFile = resolve$1(targetPath, sourceFileRelativeModule);
3850
+ return targetFile;
3851
+ };
3852
+ /**
3853
+ * 开始启动编译
3854
+ * @param {Map} compileTasksMap {'${sourcePath}': {taskFn: () => {}, targetPath: 'xxx'}}
3855
+ */
3856
+
3857
+
3858
+ const runCompile = (compileTasksMap, callback) => {
3859
+ async function end(next) {
3860
+ // 监听其他文件
3861
+ compileTasksMap.forEach(({
3862
+ taskFn,
3863
+ targetPath
3864
+ }, sourcePath) => {
3865
+ runWatch(sourcePath, {
3866
+ ignoreInitial: true,
3867
+ events: ['add', 'change', 'unlink', 'addDir', 'unlinkDir']
3868
+ }, taskFn, targetPath);
3869
+ });
3870
+ callback && callback();
3871
+ next();
3872
+ }
3873
+
3874
+ const compileTasksArr = [];
3875
+ compileTasksMap.forEach(({
3876
+ taskFn
3877
+ }) => {
3878
+ compileTasksArr.push(taskFn);
3879
+ }); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
3880
+
3881
+ series(parallel(...compileTasksArr), end)();
3882
+ };
3883
+ /**
3884
+ * 监听文件变动
3885
+ * @param {*} sourcePath 云函数的源码目录
3886
+ * @param {*} watchOptions gulp-watch的参数
3887
+ * @param {*} callback 监听到变动的回调
3888
+ * @param {*} targetPath 云函数的编译目录
3889
+ */
3890
+
3891
+
3892
+ const runWatch = (sourcePath, watchOptions, callback, targetPath) => {
3893
+ watch(sourcePath, { ...watchOptions
3894
+ }, vinyl => {
3895
+ const sourceFile = vinyl.history[0];
3896
+ const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
3897
+ const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
3898
+ const targetFile = getTargetFile(sourceFile, sourcePath, targetPath);
3899
+
3900
+ if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
3901
+ info$2(`删除${sourceFileName}`);
3902
+ shellJs.rm('-rf', targetFile);
3903
+ return;
3904
+ }
3905
+
3906
+ info$2(`${sourceFileName}有更新`);
3907
+ return callback([sourceFile], path$1.dirname(targetFile));
3908
+ });
3909
+ };
3561
3910
 
3562
- var cloud$1 = async tmsConfig => {
3911
+ var dev$1 = async (tmsConfig, cmdOptions) => {
3563
3912
  try {
3564
- await symLink(tmsConfig);
3913
+ const sTime = new Date().getTime();
3914
+ const spinner = ora();
3915
+ spinner.start(); // 检查云函数的配置项
3916
+
3917
+ const configErrMsg = checkCloudConfig(tmsConfig);
3918
+
3919
+ if (configErrMsg) {
3920
+ throw new Error(configErrMsg);
3921
+ } // 确保云函数的编译目录存在
3922
+
3923
+
3924
+ ensureDirExist(resolve$1(tmsConfig.cloudDir)); // 获取需要监听的云函数列表
3925
+
3926
+ const clouds = getCloudsOfListen(tmsConfig, cmdOptions); // 检查云函数源码目录是否存在
3927
+
3928
+ const srcNotExistErrMsg = checkSrcPathIsExist(clouds);
3929
+
3930
+ if (srcNotExistErrMsg) {
3931
+ throw new Error(srcNotExistErrMsg);
3932
+ } // 打印启动云函数列表
3933
+
3934
+
3935
+ info$2('当前启动云函数列表:', clouds.map(item => item.name).sort()); // npm install
3936
+
3937
+ await createTask(runInstall, '开始npm install', 'npm install完成')(clouds, tmsConfig); // 获取云函数列表的编译任务
3938
+
3939
+ const compileTasksMap = getCompileTasks(clouds, {
3940
+ allowEmpty: true
3941
+ });
3942
+ runCompile(compileTasksMap, () => {
3943
+ const eTime = new Date().getTime() - sTime;
3944
+ spinner.succeed(chalk$2.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
3945
+ spinner.stop();
3946
+ });
3565
3947
  } catch (e) {
3566
- handleError(`创建软链错误: ${e}`);
3948
+ info$2('编译出现详细错误', e);
3949
+ handleError(`编译出现错误: ${e}`, true);
3567
3950
  }
3568
3951
  };
3569
3952
 
@@ -3572,7 +3955,10 @@ const init = init_1;
3572
3955
  const dev = dev_1;
3573
3956
  const build = build_1;
3574
3957
  const install = install_1;
3575
- const cloud = cloud$1;
3958
+ const preview = preview_1;
3959
+ const upload = upload_1;
3960
+ const cloudLink = link;
3961
+ const cloudDev = dev$1;
3576
3962
  const {
3577
3963
  fail,
3578
3964
  info: info$1
@@ -3588,10 +3974,10 @@ const {
3588
3974
  getModulesByModuleNames
3589
3975
  } = tmsMpconfig.exports;
3590
3976
 
3591
- const handleModuleArg = cmd => {
3977
+ const handleModuleArg = cmdOptions => {
3592
3978
  // 单模块或多模块开发-用户通过脚手架参数指定的模块
3593
- if (typeof cmd.module === 'string') {
3594
- return cmd.module.split(',');
3979
+ if (typeof cmdOptions.module === 'string') {
3980
+ return cmdOptions.module.split(',');
3595
3981
  }
3596
3982
 
3597
3983
  return [];
@@ -3631,26 +4017,34 @@ const getSpecificModuleNames = (moduleArg, modules) => {
3631
4017
  return all.map(item => item.moduleName);
3632
4018
  };
3633
4019
 
3634
- async function run(commandName, cmd) {
4020
+ async function run(commandName, cmdOptions) {
3635
4021
  // 用户本地的配置
3636
4022
  const tmsConfig = getTmsConfig$1();
3637
4023
 
3638
4024
  try {
3639
4025
  // 缓存数据
3640
4026
  global.setData({
3641
- cmd,
4027
+ cmdOptions,
3642
4028
  tmsConfig
3643
4029
  });
3644
4030
 
3645
- if (commandName === 'cloud') {
3646
- cloud(tmsConfig);
3647
- report$1('run:cloud', {
4031
+ if (commandName === 'cloud-link') {
4032
+ cloudLink(tmsConfig, cmdOptions);
4033
+ report$1('run:cloud-link', {
4034
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
4035
+ });
4036
+ return;
4037
+ }
4038
+
4039
+ if (commandName === 'cloud-dev') {
4040
+ cloudDev(tmsConfig, cmdOptions);
4041
+ report$1('run:cloud-dev', {
3648
4042
  appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
3649
4043
  });
3650
4044
  return;
3651
4045
  }
3652
4046
 
3653
- otherCommands(tmsConfig, commandName, cmd);
4047
+ otherCommands(tmsConfig, commandName, cmdOptions);
3654
4048
  } catch (error) {
3655
4049
  const errMsg = typeof error === 'object' ? error.message : error;
3656
4050
  report$1('run', {
@@ -3663,9 +4057,9 @@ async function run(commandName, cmd) {
3663
4057
  }
3664
4058
  }
3665
4059
 
3666
- function otherCommands(tmsConfig, commandName, cmd) {
4060
+ function otherCommands(tmsConfig, commandName, cmdOptions) {
3667
4061
  // 处理module参数
3668
- const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmd), tmsConfig.modules); // moduleNames => ['home', 'car']
4062
+ const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmdOptions), tmsConfig.modules); // moduleNames => ['home', 'car']
3669
4063
 
3670
4064
  const moduleNames = [...new Set([...specificModuleNames])];
3671
4065
  const modules = getModulesByModuleNames(tmsConfig, moduleNames, false); // 获取所有模块,合并模块依赖的模块
@@ -3678,7 +4072,7 @@ function otherCommands(tmsConfig, commandName, cmd) {
3678
4072
  case 'init':
3679
4073
  init(tmsConfig, newModules);
3680
4074
  report$1('run:init', {
3681
- appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
4075
+ appName: tmsConfig.appName
3682
4076
  });
3683
4077
  return;
3684
4078
 
@@ -3686,14 +4080,14 @@ function otherCommands(tmsConfig, commandName, cmd) {
3686
4080
  global.setData('isDev', true);
3687
4081
  dev(tmsConfig, newModules);
3688
4082
  report$1('run:dev', {
3689
- appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
4083
+ appName: tmsConfig.appName
3690
4084
  });
3691
4085
  return;
3692
4086
 
3693
4087
  case 'install':
3694
4088
  install(tmsConfig, subPackages, false);
3695
4089
  report$1('run:install', {
3696
- appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
4090
+ appName: tmsConfig.appName
3697
4091
  });
3698
4092
  return;
3699
4093
 
@@ -3701,7 +4095,21 @@ function otherCommands(tmsConfig, commandName, cmd) {
3701
4095
  global.setData('isDev', false);
3702
4096
  build(tmsConfig, newModules);
3703
4097
  report$1('run:build', {
3704
- appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
4098
+ appName: tmsConfig.appName
4099
+ });
4100
+ return;
4101
+
4102
+ case 'preview':
4103
+ preview(tmsConfig, cmdOptions);
4104
+ report$1('run:preview', {
4105
+ appName: tmsConfig.appName
4106
+ });
4107
+ return;
4108
+
4109
+ case 'upload':
4110
+ upload(tmsConfig, cmdOptions);
4111
+ report$1('run:upload', {
4112
+ appName: tmsConfig.appName
3705
4113
  });
3706
4114
  return;
3707
4115
 
@@ -3722,9 +4130,9 @@ var entry = [{
3722
4130
  command: 'install-cmd <npm-name>',
3723
4131
  description: '安装扩展命令',
3724
4132
  options: [['--registry [registry]', 'npm源']],
3725
- action: (npmName, cmd) => {
4133
+ action: (npmName, cmdOptions) => {
3726
4134
  const res = extendCmd;
3727
- res.installCmd(npmName, cmd);
4135
+ res.installCmd(npmName, cmdOptions);
3728
4136
  }
3729
4137
  }, {
3730
4138
  name: 'run',
@@ -3734,33 +4142,143 @@ var entry = [{
3734
4142
  command: 'install',
3735
4143
  description: '安装依赖',
3736
4144
  options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
3737
- action: cmd => {
3738
- run_1('install', cmd);
4145
+ action: cmdOptions => {
4146
+ run_1('install', cmdOptions);
3739
4147
  }
3740
4148
  }, {
3741
4149
  command: 'dev',
3742
4150
  description: 'dev 打包编译',
3743
4151
  options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-noCache, --noCache', '不使用缓存功能']],
3744
- action: cmd => {
3745
- run_1('dev', cmd);
3746
- }
3747
- }, {
3748
- command: 'cloud',
3749
- description: '云函数开发',
3750
- options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
3751
- action: cmd => {
3752
- run_1('cloud', cmd);
4152
+ action: cmdOptions => {
4153
+ run_1('dev', cmdOptions);
3753
4154
  }
3754
4155
  }, {
3755
4156
  command: 'build',
3756
4157
  description: 'prod 打包编译',
3757
4158
  options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
3758
- action: cmd => {
3759
- run_1('build', cmd);
4159
+ action: cmdOptions => {
4160
+ run_1('build', cmdOptions);
3760
4161
  }
3761
- }]
4162
+ }, {
4163
+ command: 'preview',
4164
+ description: '小程序预览',
4165
+ options: [['-f, --qrcodeFormat [qrcodeFormat]', '二维码的格式,选项terminal, image, base64。默认terminal'], ['-o, --qrcodeOutputDest [qrcodeOutputDest]', '二维码会被输出到给定路径'], ['-i, --info-output [infoOutput]', '相关信息会被输出到给定路径']],
4166
+ action: cmdOptions => {
4167
+ run_1('preview', cmdOptions);
4168
+ }
4169
+ }, {
4170
+ command: 'upload',
4171
+ description: '小程序上传',
4172
+ options: [['--version [version]', '上传代码版本,version 指定版本号'], ['-d, --desc [desc]', '上传代码时的备注'], ['-i, --info-output [infoOutput]', '相关信息会被输出到给定路径'], ['-r, --robot [robot]', '指定使用哪一个 ci 机器人,可选值:1 ~ 30']],
4173
+ action: cmdOptions => {
4174
+ run_1('upload', cmdOptions);
4175
+ }
4176
+ }, {
4177
+ command: 'cloud-dev',
4178
+ description: '云函数开发',
4179
+ options: [['--cloud [cloud]', '模块名称']],
4180
+ action: cmdOptions => {
4181
+ run_1('cloud-dev', cmdOptions);
4182
+ }
4183
+ } // {
4184
+ // command: 'cloud-link',
4185
+ // description: '云函数开发',
4186
+ // options: [
4187
+ // ['--cloud [cloud]', '模块名称'],
4188
+ // ],
4189
+ // action: (cmdOptions) => {
4190
+ // require('./scripts/run/index')('cloud-link', cmdOptions);
4191
+ // },
4192
+ // },
4193
+ ]
3762
4194
  }];
3763
4195
 
4196
+ var require$$12 = {
4197
+ name: "@tmsfe/tmskit",
4198
+ version: "0.0.27",
4199
+ description: "tmskit",
4200
+ main: "dist/index.cjs",
4201
+ bin: {
4202
+ tmskit: "main.js"
4203
+ },
4204
+ files: [
4205
+ "build",
4206
+ "src",
4207
+ "dist",
4208
+ "main.js",
4209
+ "package.json"
4210
+ ],
4211
+ scripts: {
4212
+ dev: "rollup -wc --environment TARGET:tmskit",
4213
+ build: "rollup -c --environment TARGET:tmskit",
4214
+ "pub:patch": "sh build/publish.sh patch",
4215
+ "pub:minor": "sh build/publish.sh minor",
4216
+ "pub:major": "sh build/publish.sh major"
4217
+ },
4218
+ author: "tms·web",
4219
+ license: "ISC",
4220
+ buildOptions: {
4221
+ formats: [
4222
+ "cjs"
4223
+ ]
4224
+ },
4225
+ devDependencies: {
4226
+ "@rollup/plugin-babel": "^5.0.2",
4227
+ "@rollup/plugin-commonjs": "^19.0.0",
4228
+ "@rollup/plugin-json": "^4.0.3",
4229
+ rollup: "^2.6.1"
4230
+ },
4231
+ whiteDependencies: {
4232
+ },
4233
+ dependencies: {
4234
+ "ansi-colors": "1.1.0",
4235
+ anymatch: "^1.3.0",
4236
+ async: "^3.2.2",
4237
+ chalk: "^4.1.0",
4238
+ chokidar: "^3.5.3",
4239
+ commander: "^8.3.0",
4240
+ ejs: "^3.1.5",
4241
+ "fancy-log": "1.3.2",
4242
+ "fs-extra": "^10.0.1",
4243
+ "glob-ignore": "^1.0.2",
4244
+ "glob-parent": "^3.0.1",
4245
+ gulp: "^4.0.2",
4246
+ "gulp-if": "^3.0.0",
4247
+ "gulp-watch": "^5.0.1",
4248
+ htmlparser2: "^7.2.0",
4249
+ inquirer: "^7.3.3",
4250
+ leven: "3.1.0",
4251
+ lodash: "^4.17.21",
4252
+ metalsmith: "^2.3.0",
4253
+ minimatch: "^5.1.0",
4254
+ "miniprogram-ci": "1.8.25",
4255
+ moment: "^2.29.2",
4256
+ "object-assign": "^4.0.1",
4257
+ ora: "^5.4.1",
4258
+ "path-is-absolute": "^1.0.1",
4259
+ "plugin-error": "^1.0.0",
4260
+ postcss: "^8.4.6",
4261
+ precinct: "^8.3.1",
4262
+ "readable-stream": "^2.2.2",
4263
+ "replace-ext": "^2.0.0",
4264
+ request: "^2.88.2",
4265
+ shelljs: "^0.8.5",
4266
+ slash: "^1.0.0",
4267
+ "strip-comments": "^2.0.1",
4268
+ through2: "^4.0.2",
4269
+ unzipper: "^0.10.11",
4270
+ vinyl: "^2.1.0",
4271
+ "vinyl-file": "^2.0.0",
4272
+ "vinyl-sourcemaps-apply": "^0.2.0"
4273
+ },
4274
+ engines: {
4275
+ node: "^12.17.0 || >= 14.13.1"
4276
+ },
4277
+ jest: {
4278
+ testEnvironment: "jest-environment-node"
4279
+ }
4280
+ };
4281
+
3764
4282
  const semver = require$$1__default$7;
3765
4283
  const packageJson = require$$12;
3766
4284
  const chalk$1 = require$$3__default;
@@ -3905,6 +4423,6 @@ if (!process.argv.slice(2).length) {
3905
4423
  }
3906
4424
 
3907
4425
  program.parse(process.argv);
3908
- var src = src$2;
4426
+ var src = src$3;
3909
4427
 
3910
4428
  module.exports = src;