@tmsfe/tmskit 0.0.24 → 0.0.25

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
@@ -79,7 +79,7 @@ var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
79
79
  var src$2 = {};
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
  */
@@ -97,7 +97,7 @@ const fail$9 = (message = '') => {
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,10 +121,10 @@ 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$g = (...args) => console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
128
128
 
129
129
  const infoNoTime$2 = (...args) => console.log(...args);
130
130
 
@@ -132,17 +132,17 @@ var log$1 = {
132
132
  fail: fail$9,
133
133
  succeed: succeed$2,
134
134
  warn: warn$2,
135
- info: info$d,
135
+ info: info$g,
136
136
  infoNoTime: infoNoTime$2
137
137
  };
138
138
 
139
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;
140
+ const path$g = require$$1__default$1;
141
+ const fs$i = require$$0__default$1;
142
+ const shelljs$8 = require$$2__default;
143
143
  const glob = require$$4__default;
144
144
  const {
145
- info: info$c
145
+ info: info$f
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$g(...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$i.existsSync(dest)) {
190
+ shelljs$8.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$8.mkdir('-p', dest);
194
+ shelljs$8.cd(dest);
195
+ shelljs$8.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$8.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$8.cd(dest);
219
+ shelljs$8.exec('git config pull.rebase false', shelljsOptions);
220
+ shelljs$8.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$8.cd(cwd);
228
228
  resolve();
229
229
  });
230
230
  });
@@ -240,7 +240,7 @@ function pullRepoForGit$1(dest, branch) {
240
240
  function npmInstall$2(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$8.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$5(task, startText, endText) {
297
297
  return async (...args) => {
298
298
  const start = Date.now();
299
299
  const spinner = ora$1();
300
- info$c(startText);
300
+ info$f(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,9 +357,9 @@ function findFiles(globPath, filter = []) {
357
357
  } // 获取绝对路径
358
358
 
359
359
 
360
- function getAbsolutePath$3(pathDir, cwd = '') {
360
+ function getAbsolutePath$5(pathDir, cwd = '') {
361
361
  let newPath = pathDir;
362
- newPath = newPath.startsWith('/') ? newPath : resolve$e(cwd, newPath);
362
+ newPath = newPath.startsWith('/') ? newPath : resolve$g(cwd, newPath);
363
363
  newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
364
364
  return newPath;
365
365
  } // 版本比较 => 1(大于), 0(等于), -1(小于)
@@ -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$8.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$g,
390
398
  isObject,
391
399
  isArray,
392
- createTask: createTask$3,
400
+ createTask: createTask$5,
393
401
  downloadRepoForGit: downloadRepoForGit$1,
394
402
  pullRepoForGit: pullRepoForGit$1,
395
403
  camelize,
396
404
  npmInstall: npmInstall$2,
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$5,
402
410
  getNpmRegistry,
403
- versionCompare: versionCompare$1
411
+ versionCompare: versionCompare$1,
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
424
  const VERSION_URL$1 = '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$1 = 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'];
@@ -510,7 +519,33 @@ 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
+ }
514
549
  };
515
550
 
516
551
  /**
@@ -659,18 +694,10 @@ var defaultTmsConfig = {
659
694
  return content;
660
695
  }
661
696
 
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
697
  const adaptSubPackages = function (moduleConfig, appName) {
673
- const subPackages = isObject(moduleConfig) && moduleConfig.subPackages ? moduleConfig.subPackages : isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
698
+ const {
699
+ subPackages
700
+ } = moduleConfig;
674
701
  return adaptMpCgContent(subPackages, appName);
675
702
  };
676
703
  /**
@@ -694,10 +721,8 @@ var defaultTmsConfig = {
694
721
 
695
722
 
696
723
  const subPackages = adaptSubPackages(moduleConfig, appName);
697
- const dependencies = adaptDependencies(moduleConfig.dependencies, subPackages);
698
724
  moduleConfig = { ...(isObject(moduleConfig) ? moduleConfig : {}),
699
- subPackages,
700
- dependencies
725
+ subPackages
701
726
  }; // 兼容逻辑--- end
702
727
 
703
728
  modulesConfig.push(moduleConfig);
@@ -747,10 +772,7 @@ var defaultTmsConfig = {
747
772
  const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
748
773
  const newModuleItem = { ...tmsModuleItem,
749
774
  ...moduleConfig
750
- }; // 兼容逻辑
751
-
752
- if (!newModuleItem.moduleName) newModuleItem.moduleName = newModuleItem.name;
753
- delete newModuleItem.name; // 参数校验-模块源码路径
775
+ }; // 参数校验-模块源码路径
754
776
 
755
777
  if (!newModuleItem.path) {
756
778
  throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
@@ -793,6 +815,10 @@ var defaultTmsConfig = {
793
815
 
794
816
  function dfs(tmsConfig, modules) {
795
817
  modules.forEach(moduleItem => {
818
+ if (!moduleItem.path) {
819
+ throw new Error(`${moduleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
820
+ }
821
+
796
822
  const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
797
823
 
798
824
  if (!fs.existsSync(moduleConfigPath)) {
@@ -841,10 +867,10 @@ var defaultTmsConfig = {
841
867
  };
842
868
  })(tmsMpconfig);
843
869
 
844
- const fs$f = require$$0__default$1;
845
- const path$d = require$$1__default$1;
870
+ const fs$h = require$$0__default$1;
871
+ const path$e = require$$1__default$1;
846
872
  const {
847
- info: info$b
873
+ info: info$e
848
874
  } = log$1;
849
875
  const {
850
876
  relativeCwdPath
@@ -855,12 +881,12 @@ const {
855
881
  * @returns
856
882
  */
857
883
 
858
- const isDirEmpty = dirname => fs$f.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
884
+ const isDirEmpty = dirname => fs$h.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
859
885
 
860
886
 
861
887
  const isFile = pathName => {
862
888
  try {
863
- const stat = fs$f.lstatSync(pathName);
889
+ const stat = fs$h.lstatSync(pathName);
864
890
  return stat.isFile();
865
891
  } catch {
866
892
  return false;
@@ -872,9 +898,9 @@ const isFile = pathName => {
872
898
  */
873
899
 
874
900
 
875
- const ensureDirExist$4 = dirname => {
876
- if (!fs$f.existsSync(dirname)) {
877
- fs$f.mkdirSync(dirname, {
901
+ const ensureDirExist$5 = dirname => {
902
+ if (!fs$h.existsSync(dirname)) {
903
+ fs$h.mkdirSync(dirname, {
878
904
  recursive: true
879
905
  });
880
906
  }
@@ -882,27 +908,27 @@ const ensureDirExist$4 = dirname => {
882
908
 
883
909
 
884
910
  const copyFile = function (src, dest) {
885
- if (fs$f.existsSync(dest)) {
886
- fs$f.unlinkSync(dest);
911
+ if (fs$h.existsSync(dest)) {
912
+ fs$h.unlinkSync(dest);
887
913
  }
888
914
 
889
- const dir = path$d.dirname(dest);
890
- ensureDirExist$4(dir);
891
- fs$f.copyFileSync(src, dest);
915
+ const dir = path$e.dirname(dest);
916
+ ensureDirExist$5(dir);
917
+ fs$h.copyFileSync(src, dest);
892
918
  }; // 判断文件内容是否一致,不一致再进行拷贝
893
919
 
894
920
 
895
921
  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');
922
+ if (fs$h.existsSync(destFile)) {
923
+ const depDestContent = fs$h.readFileSync(destFile, 'utf8');
924
+ const depOriginContent = fs$h.readFileSync(originFile, 'utf8');
899
925
 
900
926
  if (depDestContent !== depOriginContent) {
901
- info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
927
+ info$e(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
902
928
  copyFile(originFile, destFile);
903
929
  }
904
930
  } else {
905
- info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
931
+ info$e(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
906
932
  copyFile(originFile, destFile);
907
933
  }
908
934
  } // 添加后缀
@@ -913,7 +939,7 @@ function ext(filePath, extensions) {
913
939
  let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
914
940
 
915
941
  try {
916
- const stat = fs$f.lstatSync(newFilePath);
942
+ const stat = fs$h.lstatSync(newFilePath);
917
943
 
918
944
  if (stat.isDirectory()) {
919
945
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
@@ -924,7 +950,7 @@ function ext(filePath, extensions) {
924
950
  for (const ext of extensions) {
925
951
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
926
952
 
927
- if (fs$f.existsSync(file)) {
953
+ if (fs$h.existsSync(file)) {
928
954
  return {
929
955
  ext,
930
956
  extPath: extPath + ext,
@@ -942,11 +968,11 @@ function ext(filePath, extensions) {
942
968
 
943
969
 
944
970
  const fileInDir = (dir, file) => {
945
- if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
971
+ if (!fs$h.existsSync(dir) || !fs$h.existsSync(file)) {
946
972
  return false;
947
973
  }
948
974
 
949
- const relativePath = path$d.relative(dir, file);
975
+ const relativePath = path$e.relative(dir, file);
950
976
 
951
977
  if (relativePath.startsWith('..')) {
952
978
  return false;
@@ -959,10 +985,10 @@ function findAllFilesOfDir(dir) {
959
985
  const list = [];
960
986
 
961
987
  function listFile(dir) {
962
- const arr = fs$f.readdirSync(dir);
988
+ const arr = fs$h.readdirSync(dir);
963
989
  arr.forEach(item => {
964
- const fullPath = path$d.join(dir, item);
965
- const stats = fs$f.statSync(fullPath);
990
+ const fullPath = path$e.join(dir, item);
991
+ const stats = fs$h.statSync(fullPath);
966
992
 
967
993
  if (stats.isDirectory()) {
968
994
  listFile(fullPath);
@@ -981,7 +1007,7 @@ var io$3 = {
981
1007
  isDirEmpty,
982
1008
  copyFile,
983
1009
  diffContentCopyFile,
984
- ensureDirExist: ensureDirExist$4,
1010
+ ensureDirExist: ensureDirExist$5,
985
1011
  ext,
986
1012
  fileInDir,
987
1013
  isFile,
@@ -1008,10 +1034,10 @@ const render$1 = (files, metalsmith, next) => {
1008
1034
 
1009
1035
  var render_1 = render$1;
1010
1036
 
1011
- const fs$e = require$$0__default$1;
1037
+ const fs$g = require$$0__default$1;
1012
1038
  const inquirer$2 = require$$1__default$4;
1013
1039
  const {
1014
- resolve: resolve$d
1040
+ resolve: resolve$f
1015
1041
  } = widgets;
1016
1042
  const {
1017
1043
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -1025,12 +1051,12 @@ const {
1025
1051
  const parseTemplateQuestions = dir => {
1026
1052
  let prompts = [];
1027
1053
 
1028
- if (!fs$e.existsSync(`${dir}/questions.json`)) {
1054
+ if (!fs$g.existsSync(`${dir}/questions.json`)) {
1029
1055
  return prompts;
1030
1056
  }
1031
1057
 
1032
1058
  try {
1033
- const json = JSON.parse(fs$e.readFileSync(`${dir}/questions.json`));
1059
+ const json = JSON.parse(fs$g.readFileSync(`${dir}/questions.json`));
1034
1060
 
1035
1061
  if (Array.isArray(json) && json.length > 0) {
1036
1062
  json.forEach((item, index) => {
@@ -1063,7 +1089,7 @@ const isQuestionType = result => {
1063
1089
  };
1064
1090
 
1065
1091
  const ask$1 = templateDir => (files, metalsmith, next) => {
1066
- const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
1092
+ const prompts = parseTemplateQuestions(resolve$f(templateDir, TEMPLATE_TKIT_DIR$1));
1067
1093
  const metadata = metalsmith.metadata();
1068
1094
  const filteredPrompts = prompts.filter(prompt => {
1069
1095
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -1106,23 +1132,17 @@ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolv
1106
1132
  var generator_1 = generator$1;
1107
1133
 
1108
1134
  const request$2 = require$$0__default$5;
1109
- const shelljs$8 = require$$2__default;
1135
+ const {
1136
+ getGitUser: getGitUser$1
1137
+ } = widgets;
1110
1138
  const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
1111
1139
 
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 = {}) => {
1140
+ const report$a = (name, attrs = {}) => {
1121
1141
  try {
1122
1142
  const param = [];
1123
1143
  param[27] = name;
1124
1144
  param[28] = 'tmskit';
1125
- param[29] = getGitUser();
1145
+ param[29] = getGitUser$1();
1126
1146
  param[30] = JSON.stringify(attrs);
1127
1147
 
1128
1148
  for (let i = 0; i < 40; i++) {
@@ -1135,16 +1155,16 @@ const report$8 = (name, attrs = {}) => {
1135
1155
  json: {
1136
1156
  param
1137
1157
  }
1138
- }); // (error, response, body) => {
1158
+ }, () => {}); // (error, response, body) => {
1139
1159
  // console.log('body:', body);
1140
1160
  // }
1141
1161
  } catch (e) {}
1142
1162
  };
1143
1163
 
1144
- var report_1 = report$8;
1164
+ var report_1 = report$a;
1145
1165
 
1146
- const path$c = require$$1__default$1;
1147
- const fs$d = require$$0__default$1;
1166
+ const path$d = require$$1__default$1;
1167
+ const fs$f = require$$0__default$1;
1148
1168
  const shelljs$7 = require$$2__default;
1149
1169
  const inquirer$1 = require$$1__default$4;
1150
1170
  const {
@@ -1155,18 +1175,18 @@ const {
1155
1175
  CREATE_TEMPLATE_QUESTION
1156
1176
  } = constant;
1157
1177
  const {
1158
- resolve: resolve$c
1178
+ resolve: resolve$e
1159
1179
  } = widgets;
1160
1180
  const io$2 = io$3;
1161
1181
  const {
1162
1182
  fail: fail$8,
1163
1183
  succeed: succeed$1,
1164
- info: info$a
1184
+ info: info$d
1165
1185
  } = log$1;
1166
1186
  const generator = generator_1;
1167
1187
  const request$1 = require$$0__default$5;
1168
1188
  const unzip = require$$10__default;
1169
- const report$7 = report_1;
1189
+ const report$9 = report_1;
1170
1190
  /**
1171
1191
  * 如果该目录下面存在文件,换个名字
1172
1192
  * @param { string } targetDir 当前文件夹
@@ -1175,7 +1195,7 @@ const report$7 = report_1;
1175
1195
 
1176
1196
  async function createProjectDir(targetDir) {
1177
1197
  // 如果目录非空或者已经存在,提示用户,做选择
1178
- if (fs$d.existsSync(targetDir)) {
1198
+ if (fs$f.existsSync(targetDir)) {
1179
1199
  if (!(await io$2.isDirEmpty(targetDir))) {
1180
1200
  fail$8('该目录名已经存在,换个项目名字吧~');
1181
1201
  process.exit(1);
@@ -1196,14 +1216,14 @@ async function createProjectDir(targetDir) {
1196
1216
  function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1197
1217
  return new Promise((resolve, reject) => {
1198
1218
  const localZipPath = `${templateDir}/${templateName}.zip`;
1199
- const stream = fs$d.createWriteStream(localZipPath);
1219
+ const stream = fs$f.createWriteStream(localZipPath);
1200
1220
  request$1(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
1201
1221
  if (err) {
1202
1222
  reject(err);
1203
1223
  return;
1204
1224
  }
1205
1225
 
1206
- fs$d.createReadStream(localZipPath).pipe(unzip.Extract({
1226
+ fs$f.createReadStream(localZipPath).pipe(unzip.Extract({
1207
1227
  path: templateDir
1208
1228
  })).on('close', err => {
1209
1229
  if (err) {
@@ -1225,31 +1245,31 @@ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1225
1245
 
1226
1246
  async function create(projectName) {
1227
1247
  const cwd = process.cwd();
1228
- const targetDir = path$c.resolve(cwd, projectName);
1248
+ const targetDir = path$d.resolve(cwd, projectName);
1229
1249
  const {
1230
1250
  projectType
1231
1251
  } = await inquirer$1.prompt(CREATE_TEMPLATE_QUESTION);
1232
- report$7('create-start', {
1252
+ report$9('create-start', {
1233
1253
  projectType
1234
1254
  }); // 创建项目目录
1235
1255
 
1236
1256
  await createProjectDir(targetDir); // 新创建缓存目录
1237
1257
 
1238
- if (fs$d.existsSync(TEMPLATE_DIR)) {
1258
+ if (fs$f.existsSync(TEMPLATE_DIR)) {
1239
1259
  shelljs$7.rm('-rf', TEMPLATE_DIR);
1240
1260
  }
1241
1261
 
1242
- fs$d.mkdirSync(TEMPLATE_DIR, {
1262
+ fs$f.mkdirSync(TEMPLATE_DIR, {
1243
1263
  recursive: true
1244
1264
  }); // 下载和解压模板
1245
1265
 
1246
1266
  await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
1247
1267
 
1248
- generator(path$c.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1268
+ generator(path$d.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1249
1269
  shelljs$7.cd(projectName);
1250
- const hookFilePath = resolve$c(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1270
+ const hookFilePath = resolve$e(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1251
1271
 
1252
- if (fs$d.existsSync(hookFilePath)) {
1272
+ if (fs$f.existsSync(hookFilePath)) {
1253
1273
  const hooks = require(hookFilePath);
1254
1274
 
1255
1275
  if (hooks.afterCreate) {
@@ -1264,35 +1284,35 @@ async function create(projectName) {
1264
1284
  });
1265
1285
  }
1266
1286
 
1267
- shelljs$7.rm('-rf', resolve$c(projectName, TEMPLATE_TKIT_DIR));
1287
+ shelljs$7.rm('-rf', resolve$e(projectName, TEMPLATE_TKIT_DIR));
1268
1288
  }
1269
1289
 
1270
- report$7('create-success', {
1290
+ report$9('create-success', {
1271
1291
  projectType
1272
1292
  });
1273
1293
  succeed$1('项目创建完成.');
1274
1294
  }).catch(err => {
1275
1295
  fail$8(err.message);
1276
- info$a('详细的错误信息:', err);
1296
+ info$d('详细的错误信息:', err);
1277
1297
  });
1278
1298
  }
1279
1299
 
1280
1300
  var create_1 = create;
1281
1301
 
1282
- const fs$c = require$$0__default$1;
1283
- const path$b = require$$1__default$1;
1302
+ const fs$e = require$$0__default$1;
1303
+ const path$c = require$$1__default$1;
1284
1304
  const shellJs$1 = require$$2__default;
1285
1305
  const {
1286
- ensureDirExist: ensureDirExist$3
1306
+ ensureDirExist: ensureDirExist$4
1287
1307
  } = io$3;
1288
1308
  const {
1289
1309
  EXTEND_CMD
1290
1310
  } = constant;
1291
1311
  const {
1292
- createTask: createTask$2
1312
+ createTask: createTask$4
1293
1313
  } = widgets;
1294
1314
  const {
1295
- info: info$9,
1315
+ info: info$c,
1296
1316
  fail: fail$7
1297
1317
  } = log$1;
1298
1318
  /**
@@ -1305,15 +1325,15 @@ async function installCmd(npmName, cmd) {
1305
1325
  try {
1306
1326
  const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1307
1327
 
1308
- if (!fs$c.existsSync(cmdPackageJson)) {
1309
- ensureDirExist$3(EXTEND_CMD);
1310
- fs$c.writeFileSync(cmdPackageJson, JSON.stringify({
1328
+ if (!fs$e.existsSync(cmdPackageJson)) {
1329
+ ensureDirExist$4(EXTEND_CMD);
1330
+ fs$e.writeFileSync(cmdPackageJson, JSON.stringify({
1311
1331
  dependencies: {}
1312
1332
  }, null, 2));
1313
1333
  }
1314
1334
 
1315
1335
  shellJs$1.cd(EXTEND_CMD);
1316
- await createTask$2(npmName => new Promise((resolve, reject) => {
1336
+ await createTask$4(npmName => new Promise((resolve, reject) => {
1317
1337
  const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
1318
1338
  shellJs$1.exec(`npm install --save ${npmName} ${registry}`, {
1319
1339
  cwd: EXTEND_CMD,
@@ -1328,7 +1348,7 @@ async function installCmd(npmName, cmd) {
1328
1348
  }), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
1329
1349
  } catch (e) {
1330
1350
  fail$7('构建出现错误:');
1331
- info$9(e);
1351
+ info$c(e);
1332
1352
  process.exit(1);
1333
1353
  }
1334
1354
  }
@@ -1342,17 +1362,17 @@ function loadExtendCmd$1() {
1342
1362
  const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1343
1363
  const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
1344
1364
 
1345
- if (fs$c.existsSync(cmdPackageJson)) {
1346
- const content = fs$c.readFileSync(cmdPackageJson, 'utf8');
1365
+ if (fs$e.existsSync(cmdPackageJson)) {
1366
+ const content = fs$e.readFileSync(cmdPackageJson, 'utf8');
1347
1367
  const json = JSON.parse(content);
1348
1368
  const deps = json.dependencies || {};
1349
1369
  const cmdConfigs = [];
1350
1370
  Object.keys(deps).forEach(name => {
1351
1371
  // 检索cmd的npm包
1352
1372
  if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
1353
- const cmdConfig = path$b.join(cmdNpmDir, name, 'tms.config.js');
1373
+ const cmdConfig = path$c.join(cmdNpmDir, name, 'tms.config.js');
1354
1374
 
1355
- if (fs$c.existsSync(cmdConfig)) {
1375
+ if (fs$e.existsSync(cmdConfig)) {
1356
1376
  cmdConfigs.push(cmdConfig);
1357
1377
  }
1358
1378
  });
@@ -1367,7 +1387,7 @@ var extendCmd = {
1367
1387
  loadExtendCmd: loadExtendCmd$1
1368
1388
  };
1369
1389
 
1370
- const global$7 = {
1390
+ const global$b = {
1371
1391
  data: {},
1372
1392
 
1373
1393
  setData(...args) {
@@ -1389,17 +1409,17 @@ const global$7 = {
1389
1409
 
1390
1410
  };
1391
1411
  var global_1 = {
1392
- global: global$7
1412
+ global: global$b
1393
1413
  };
1394
1414
 
1395
1415
  const {
1396
1416
  fail: fail$6
1397
1417
  } = log$1;
1398
1418
  const {
1399
- global: global$6
1419
+ global: global$a
1400
1420
  } = global_1;
1401
1421
 
1402
- function handleError$5(error, isQuit = false) {
1422
+ function handleError$7(error, isQuit = false) {
1403
1423
  const errMsg = typeof error === 'object' ? error.message : error;
1404
1424
 
1405
1425
  if (isQuit) {
@@ -1407,7 +1427,7 @@ function handleError$5(error, isQuit = false) {
1407
1427
  process.exit(1);
1408
1428
  }
1409
1429
 
1410
- const isDev = global$6.getData('isDev');
1430
+ const isDev = global$a.getData('isDev');
1411
1431
 
1412
1432
  if (isDev) {
1413
1433
  fail$6(errMsg);
@@ -1418,7 +1438,7 @@ function handleError$5(error, isQuit = false) {
1418
1438
  }
1419
1439
 
1420
1440
  var handleError_1 = {
1421
- handleError: handleError$5
1441
+ handleError: handleError$7
1422
1442
  };
1423
1443
 
1424
1444
  /**
@@ -1426,26 +1446,26 @@ var handleError_1 = {
1426
1446
  */
1427
1447
  /* eslint-disable no-param-reassign */
1428
1448
 
1429
- const fs$b = require$$0__default$1;
1449
+ const fs$d = require$$0__default$1;
1430
1450
  const {
1431
1451
  getSubPackages: getSubPackages$3,
1432
1452
  getModulesConfig
1433
1453
  } = tmsMpconfig.exports;
1434
1454
  const {
1435
1455
  fail: fail$5,
1436
- info: info$8
1456
+ info: info$b
1437
1457
  } = log$1;
1438
1458
  const {
1439
- resolve: resolve$b,
1440
- filterField: filterField$4
1459
+ resolve: resolve$d,
1460
+ filterField: filterField$6
1441
1461
  } = widgets;
1442
1462
  const {
1443
- handleError: handleError$4
1463
+ handleError: handleError$6
1444
1464
  } = handleError_1;
1445
1465
  const {
1446
- global: global$5
1466
+ global: global$9
1447
1467
  } = global_1;
1448
- const report$6 = report_1;
1468
+ const report$8 = report_1;
1449
1469
  /**
1450
1470
  * 更新appJson里面的主包配置
1451
1471
  * @param { object } appJson appJson信息
@@ -1453,7 +1473,7 @@ const report$6 = report_1;
1453
1473
  * @returns { object } appJson小程序主页配置信息
1454
1474
  */
1455
1475
 
1456
- function updateMainPackages(appJson, mainPackages) {
1476
+ function updateMainPackages(appJson, mainPackages = []) {
1457
1477
  let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
1458
1478
 
1459
1479
  if (foundMainPackages.length === 0) {
@@ -1489,12 +1509,12 @@ function updateMainPackages(appJson, mainPackages) {
1489
1509
 
1490
1510
 
1491
1511
  const getAppJsonContent = sourceAppJsonPath => {
1492
- if (!fs$b.existsSync(sourceAppJsonPath)) {
1512
+ if (!fs$d.existsSync(sourceAppJsonPath)) {
1493
1513
  fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1494
1514
  process.exit(1);
1495
1515
  }
1496
1516
 
1497
- const appJson = JSON.parse(fs$b.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1517
+ const appJson = JSON.parse(fs$d.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1498
1518
 
1499
1519
  appJson.subpackages = [];
1500
1520
  appJson.pages = [];
@@ -1539,7 +1559,7 @@ const fixAppJson = appJson => {
1539
1559
  appJson[key] = preloadRuleMap;
1540
1560
  }
1541
1561
  });
1542
- return filterField$4(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1562
+ return filterField$6(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1543
1563
  }); // 如果plugins重复,则错误提示
1544
1564
 
1545
1565
  const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
@@ -1573,7 +1593,7 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1573
1593
 
1574
1594
  const subPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
1575
1595
 
1576
- const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
1596
+ const appJson = getAppJsonContent(resolve$d('./app.json')); // 更新app.json中的subpackages
1577
1597
 
1578
1598
  appJson.subpackages = subPackages;
1579
1599
  appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name)); // 处理appJson中重复||冲突的地方
@@ -1581,24 +1601,25 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1581
1601
  fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1582
1602
 
1583
1603
  updateMainPackages(appJson, tmsConfig.mainPackages);
1584
- fs$b.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1604
+ fs$d.writeFileSync(resolve$d(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1585
1605
 
1586
1606
  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
1607
  var _tmsConfig$hooks2;
1588
1608
 
1589
1609
  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']),
1610
+ tmsConfig: filterField$6(tmsConfig, ['gitAccount']),
1611
+ cmdOptions: global$9.getData('cmdOptions'),
1591
1612
  modules,
1592
1613
  appJson,
1593
- isDev: global$5.getData('isDev')
1614
+ isDev: global$9.getData('isDev')
1594
1615
  });
1595
- report$6('hooks:updateAppJson');
1616
+ report$8('hooks:updateAppJson');
1596
1617
  }
1597
1618
 
1598
1619
  return appJson;
1599
1620
  } catch (e) {
1600
- handleError$4(`生成app.json出现错误: ${e}`);
1601
- info$8(e);
1621
+ handleError$6(`生成app.json出现错误: ${e}`);
1622
+ info$b(e);
1602
1623
  }
1603
1624
  }
1604
1625
 
@@ -1614,19 +1635,19 @@ const crypto$2 = require$$1__default$5;
1614
1635
  const {
1615
1636
  downloadRepoForGit,
1616
1637
  pullRepoForGit,
1617
- resolve: resolve$a
1638
+ resolve: resolve$c
1618
1639
  } = widgets;
1619
1640
  const {
1620
1641
  fail: fail$4,
1621
- info: info$7
1642
+ info: info$a
1622
1643
  } = log$1;
1623
- const fs$a = require$$0__default$1;
1644
+ const fs$c = require$$0__default$1;
1624
1645
  const shelljs$6 = require$$2__default;
1625
1646
  const {
1626
- handleError: handleError$3
1647
+ handleError: handleError$5
1627
1648
  } = handleError_1;
1628
1649
  const {
1629
- global: global$4
1650
+ global: global$8
1630
1651
  } = global_1;
1631
1652
  /**
1632
1653
  * 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
@@ -1636,15 +1657,15 @@ const {
1636
1657
  */
1637
1658
 
1638
1659
  function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1639
- var _tmsConfig$gitAccount;
1660
+ var _tmsConfig$gitAccount, _tmsConfig$gitAccount2;
1640
1661
 
1641
1662
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1642
- const tmsConfig = global$4.getData('tmsConfig');
1663
+ const tmsConfig = global$8.getData('tmsConfig');
1643
1664
  let gitUrl = httpRepoUrl;
1644
1665
  const {
1645
1666
  username = '',
1646
1667
  pass = ''
1647
- } = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
1668
+ } = (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
1669
  const urlPrefixReg = /http(s)?:\/\//;
1649
1670
 
1650
1671
  if (username && pass && urlPrefixReg.test(gitUrl)) {
@@ -1662,8 +1683,8 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1662
1683
  */
1663
1684
 
1664
1685
 
1665
- function moveFile(sourceDir, targetDir, ignore) {
1666
- if (fs$a.existsSync(targetDir)) {
1686
+ function moveFile(sourceDir, targetDir, ignore = []) {
1687
+ if (fs$c.existsSync(targetDir)) {
1667
1688
  shelljs$6.rm('-rf', targetDir);
1668
1689
  } // 删除不是文件夹的文件
1669
1690
 
@@ -1720,7 +1741,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1720
1741
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1721
1742
  return Promise.all(callArr);
1722
1743
  }).catch(e => {
1723
- handleError$3(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1744
+ handleError$5(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1724
1745
  }));
1725
1746
  });
1726
1747
  await Promise.all(arrPromises);
@@ -1765,9 +1786,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1765
1786
 
1766
1787
  const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1767
1788
 
1768
- const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
1789
+ const sourcePath = resolve$c(sourceDir, md5Key); // 模块源码要放到目标目录
1769
1790
 
1770
- const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1791
+ const targetPath = resolve$c(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1771
1792
 
1772
1793
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1773
1794
 
@@ -1777,7 +1798,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1777
1798
  targetPath
1778
1799
  },
1779
1800
  fn: async (sourceModulePath, targetPath) => {
1780
- if (fs$a.existsSync(targetPath)) {
1801
+ if (fs$c.existsSync(targetPath)) {
1781
1802
  shelljs$6.rm('-rf', `${targetPath}/*`);
1782
1803
  }
1783
1804
 
@@ -1792,14 +1813,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1792
1813
  } else {
1793
1814
  let promiseTask;
1794
1815
 
1795
- if (fs$a.existsSync(sourcePath) && fs$a.existsSync(`${sourcePath}/.git`)) {
1816
+ if (fs$c.existsSync(sourcePath) && fs$c.existsSync(`${sourcePath}/.git`)) {
1796
1817
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1797
- info$7(`git pull:${httpRepoUrl}`);
1818
+ info$a(`git pull:${httpRepoUrl} --branch: ${branch}`);
1798
1819
  return pullRepoForGit(sourcePath, branch);
1799
1820
  };
1800
1821
  } else {
1801
1822
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1802
- info$7(`git clone: ${httpRepoUrl}`);
1823
+ info$a(`git clone: ${httpRepoUrl}`);
1803
1824
  return downloadRepoForGit(gitUrl, sourcePath, branch);
1804
1825
  };
1805
1826
  }
@@ -1840,7 +1861,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
1840
1861
  const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
1841
1862
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
1842
1863
 
1843
- if (!fs$a.existsSync(`${sourceDir}/${md5Key}`)) {
1864
+ if (!fs$c.existsSync(`${sourceDir}/${md5Key}`)) {
1844
1865
  return true;
1845
1866
  }
1846
1867
  }
@@ -1854,7 +1875,7 @@ var cloneModules_1 = {
1854
1875
  };
1855
1876
 
1856
1877
  const ci = require$$0__default$6;
1857
- const path$a = require$$1__default$1;
1878
+ const path$b = require$$1__default$1;
1858
1879
  /**
1859
1880
  * 获取小程序ci的Project对象
1860
1881
  * @returns {Object} 小程序ci对象
@@ -1866,11 +1887,11 @@ const getMpCi = ({
1866
1887
  type = 'miniProgram',
1867
1888
  privateKey = 'TODO'
1868
1889
  }) => {
1869
- var _cfgJsonContent$packO;
1890
+ var _projectCg$packOption, _projectCg$packOption2;
1870
1891
 
1871
- const cfgJsonContent = require(path$a.join(projectPath, 'project.config.json'));
1892
+ const projectCg = require(path$b.join(projectPath, 'project.config.json'));
1872
1893
 
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(({
1894
+ 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
1895
  value
1875
1896
  }) => value)) || [];
1876
1897
  return new ci.Project({
@@ -1880,13 +1901,6 @@ const getMpCi = ({
1880
1901
  projectPath,
1881
1902
  ignores: ['node_modules/**/*', 'cloud/**/*', ...ignores]
1882
1903
  });
1883
- }; // 用小程序ci工具构建小程序
1884
-
1885
-
1886
- const packMpProject = async project => {
1887
- await ci.packNpm(project, {
1888
- ignores: ['cloud/**/*']
1889
- });
1890
1904
  };
1891
1905
  /**
1892
1906
  * 格式化构建npm结果信息
@@ -1905,8 +1919,12 @@ const formatPackNpmWarning = warning => {
1905
1919
  return result;
1906
1920
  };
1907
1921
  /**
1908
- * 构建miniprogram_npm
1909
- * @returns {Object} 小程序ci对象
1922
+ * 构建miniprogram_npm https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E6%9E%84%E5%BB%BAnpm
1923
+ * * @param {object} {
1924
+ * appId,
1925
+ * peojectPath,
1926
+ * privateKey,
1927
+ * }
1910
1928
  */
1911
1929
 
1912
1930
 
@@ -1915,12 +1933,14 @@ const buildMpNpm$1 = async ({
1915
1933
  projectPath,
1916
1934
  privateKey
1917
1935
  }) => {
1918
- const mpCi = await getMpCi({
1936
+ const mpCi = getMpCi({
1919
1937
  appId,
1920
1938
  projectPath,
1921
1939
  privateKey
1922
1940
  });
1923
- const packNpmWarning = await packMpProject(mpCi);
1941
+ const packNpmWarning = await ci.packNpm(mpCi, {
1942
+ ignores: ['cloud/**/*']
1943
+ });
1924
1944
  const packNpmMsg = formatPackNpmWarning(packNpmWarning);
1925
1945
 
1926
1946
  if (packNpmMsg) {
@@ -1929,18 +1949,80 @@ const buildMpNpm$1 = async ({
1929
1949
 
1930
1950
  return Promise.resolve();
1931
1951
  };
1952
+ /**
1953
+ * 预览小程序码 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88
1954
+ * @param {object} {
1955
+ * appId,
1956
+ * peojectPath,
1957
+ * privateKey,
1958
+ * desc
1959
+ * robot
1960
+ * }
1961
+ */
1962
+
1963
+
1964
+ const previewMp = async (params = {}) => {
1965
+ const {
1966
+ appId,
1967
+ projectPath,
1968
+ privateKey,
1969
+ ...resetParams
1970
+ } = params;
1971
+ const mpCi = await getMpCi({
1972
+ appId,
1973
+ projectPath,
1974
+ privateKey
1975
+ });
1976
+ return await ci.preview({
1977
+ project: mpCi,
1978
+ ...resetParams,
1979
+ onProgressUpdate: () => {}
1980
+ });
1981
+ };
1982
+ /**
1983
+ * 上传小程序 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E4%B8%8A%E4%BC%A0
1984
+ * @param {object} {
1985
+ * appId,
1986
+ * peojectPath,
1987
+ * privateKey,
1988
+ * version,
1989
+ * desc
1990
+ * }
1991
+ */
1992
+
1932
1993
 
1933
- var mpCi = {
1934
- buildMpNpm: buildMpNpm$1
1994
+ const uploadMp = async (params = {}) => {
1995
+ const {
1996
+ appId,
1997
+ projectPath,
1998
+ privateKey,
1999
+ ...resetParams
2000
+ } = params;
2001
+ const mpCi = await getMpCi({
2002
+ appId,
2003
+ projectPath,
2004
+ privateKey
2005
+ });
2006
+ return await ci.upload({
2007
+ project: mpCi,
2008
+ ...resetParams,
2009
+ onProgressUpdate: () => {}
2010
+ });
1935
2011
  };
1936
2012
 
1937
- const fs$9 = require$$0__default$1;
1938
- const path$9 = require$$1__default$1;
2013
+ var mpCi$2 = {
2014
+ buildMpNpm: buildMpNpm$1,
2015
+ previewMp,
2016
+ uploadMp
2017
+ };
2018
+
2019
+ const fs$b = require$$0__default$1;
2020
+ const path$a = require$$1__default$1;
1939
2021
  const {
1940
2022
  NPM_CACHE_FILE
1941
2023
  } = constant;
1942
2024
  const {
1943
- ensureDirExist: ensureDirExist$2
2025
+ ensureDirExist: ensureDirExist$3
1944
2026
  } = io$3;
1945
2027
 
1946
2028
  function getCache$1(projectDir, type) {
@@ -1948,7 +2030,7 @@ function getCache$1(projectDir, type) {
1948
2030
 
1949
2031
  const filePath = NPM_CACHE_FILE;
1950
2032
 
1951
- if (!fs$9.existsSync(filePath)) {
2033
+ if (!fs$b.existsSync(filePath)) {
1952
2034
  return null;
1953
2035
  }
1954
2036
 
@@ -1960,10 +2042,10 @@ function getCache$1(projectDir, type) {
1960
2042
  function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1961
2043
  const filePath = NPM_CACHE_FILE;
1962
2044
 
1963
- if (!fs$9.existsSync(filePath)) {
1964
- const dir = path$9.dirname(filePath);
1965
- ensureDirExist$2(dir);
1966
- fs$9.writeFileSync(filePath, '{}');
2045
+ if (!fs$b.existsSync(filePath)) {
2046
+ const dir = path$a.dirname(filePath);
2047
+ ensureDirExist$3(dir);
2048
+ fs$b.writeFileSync(filePath, '{}');
1967
2049
  }
1968
2050
 
1969
2051
  const content = require(filePath);
@@ -1975,7 +2057,7 @@ function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1975
2057
  content[projectDir] = {
1976
2058
  [type]: data
1977
2059
  };
1978
- fs$9.writeFileSync(filePath, JSON.stringify(content, null, 2));
2060
+ fs$b.writeFileSync(filePath, JSON.stringify(content, null, 2));
1979
2061
  }
1980
2062
 
1981
2063
  var cache = {
@@ -1986,20 +2068,20 @@ var cache = {
1986
2068
  /**
1987
2069
  * 本文件主要负责项目或者分包依赖的npm的安装
1988
2070
  */
1989
- const fs$8 = require$$0__default$1;
2071
+ const fs$a = require$$0__default$1;
1990
2072
  const fsExtra = require$$1__default$6;
1991
2073
  const crypto$1 = require$$1__default$5;
1992
- const path$8 = require$$1__default$1;
2074
+ const path$9 = require$$1__default$1;
1993
2075
  const shell = require$$2__default;
1994
2076
  const log = log$1;
1995
2077
  const {
1996
2078
  npmInstall: npmInstall$1
1997
2079
  } = widgets;
1998
2080
  const {
1999
- handleError: handleError$2
2081
+ handleError: handleError$4
2000
2082
  } = handleError_1;
2001
2083
  const {
2002
- global: global$3
2084
+ global: global$7
2003
2085
  } = global_1;
2004
2086
  const shellJsOption = {
2005
2087
  async: false,
@@ -2023,7 +2105,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2023
2105
  const npmTasksMap = new Map();
2024
2106
 
2025
2107
  for (const packageJsonPath of packageJsonFiles) {
2026
- const packageContent = fs$8.readFileSync(packageJsonPath);
2108
+ const packageContent = fs$a.readFileSync(packageJsonPath);
2027
2109
  let packageJson;
2028
2110
 
2029
2111
  try {
@@ -2038,14 +2120,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2038
2120
 
2039
2121
  if (Object.keys(md5Obj.dependencies).length !== 0) {
2040
2122
  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到编译目录并解压)
2123
+ const cacheNMPath = path$9.join(cacheDir, md5Key);
2124
+ const cacheNMTarFile = path$9.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
2043
2125
 
2044
2126
  const callback = {
2045
2127
  params: {
2046
2128
  cacheNMPath,
2047
2129
  cacheNMTarFile,
2048
- packageJsonDir: path$8.dirname(packageJsonPath),
2130
+ packageJsonDir: path$9.dirname(packageJsonPath),
2049
2131
  shell
2050
2132
  },
2051
2133
  fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
@@ -2074,7 +2156,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
2074
2156
  fsExtra.emptydirSync(cacheNMPath);
2075
2157
  shell.cp('-f', packageJsonPath, cacheNMPath);
2076
2158
  log.info(`npm install: ${packageJsonPath}`);
2077
- const tmsConfig = global$3.getData('tmsConfig');
2159
+ const tmsConfig = global$7.getData('tmsConfig');
2078
2160
  return npmInstall$1(cacheNMPath, tmsConfig.npm).then(() => {
2079
2161
  const newShellJsOption = { ...shellJsOption,
2080
2162
  cwd: cacheNMPath
@@ -2122,7 +2204,7 @@ const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
2122
2204
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
2123
2205
  return Promise.all(callArr);
2124
2206
  }).catch(e => {
2125
- handleError$2(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
2207
+ handleError$4(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
2126
2208
  }));
2127
2209
  });
2128
2210
  await Promise.all(arrPromises);
@@ -2148,7 +2230,7 @@ const findFilesByFilter = (startPath, filter) => {
2148
2230
 
2149
2231
  const find = (startPath, filter) => {
2150
2232
  // 目录不存在
2151
- if (!fs$8.existsSync(startPath)) {
2233
+ if (!fs$a.existsSync(startPath)) {
2152
2234
  log.fail(`${startPath}目录不存在`);
2153
2235
  process.exit(-1);
2154
2236
  return;
@@ -2161,10 +2243,10 @@ const findFilesByFilter = (startPath, filter) => {
2161
2243
  return;
2162
2244
  }
2163
2245
 
2164
- const files = fs$8.readdirSync(startPath);
2246
+ const files = fs$a.readdirSync(startPath);
2165
2247
  files.forEach(file => {
2166
- const filename = path$8.join(startPath, file);
2167
- const stat = fs$8.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2248
+ const filename = path$9.join(startPath, file);
2249
+ const stat = fs$a.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2168
2250
 
2169
2251
  if (stat.isDirectory()) {
2170
2252
  find(filename, filter);
@@ -2190,10 +2272,10 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
2190
2272
  const packageJsonName = 'package.json'; // 查找文件名
2191
2273
 
2192
2274
  const cwd = contextDir || dirPath;
2193
- const result = [path$8.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
2275
+ const result = [path$9.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
2194
2276
 
2195
2277
  subRoots.forEach(subRoot => {
2196
- const toppath = path$8.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
2278
+ const toppath = path$9.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
2197
2279
 
2198
2280
  const list = findFilesByFilter(toppath, packageJsonName);
2199
2281
  result.push(...list);
@@ -2208,12 +2290,12 @@ var npm = {
2208
2290
  };
2209
2291
 
2210
2292
  const crypto = require$$1__default$5;
2211
- const fs$7 = require$$0__default$1;
2293
+ const fs$9 = require$$0__default$1;
2212
2294
 
2213
2295
  function fileMd5$1(filePath) {
2214
2296
  return new Promise((resolve, reject) => {
2215
2297
  const md5sum = crypto.createHash('md5');
2216
- const stream = fs$7.ReadStream(filePath);
2298
+ const stream = fs$9.ReadStream(filePath);
2217
2299
  stream.on('data', d => {
2218
2300
  md5sum.update(d);
2219
2301
  });
@@ -2231,16 +2313,16 @@ var md5 = {
2231
2313
  fileMd5: fileMd5$1
2232
2314
  };
2233
2315
 
2234
- const fs$6 = require$$0__default$1;
2316
+ const fs$8 = require$$0__default$1;
2235
2317
  const semver$1 = require$$1__default$7;
2236
2318
  const {
2237
- resolve: resolve$9,
2238
- getAbsolutePath: getAbsolutePath$2
2319
+ resolve: resolve$b,
2320
+ getAbsolutePath: getAbsolutePath$4
2239
2321
  } = widgets;
2240
- const path$7 = require$$1__default$1;
2322
+ const path$8 = require$$1__default$1;
2241
2323
  const shelljs$5 = require$$2__default;
2242
2324
  const {
2243
- handleError: handleError$1
2325
+ handleError: handleError$3
2244
2326
  } = handleError_1;
2245
2327
 
2246
2328
  const getLatestVersion = npmName => {
@@ -2259,17 +2341,17 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2259
2341
  // 1.1根目录的package.json
2260
2342
 
2261
2343
  const packageArr = [{
2262
- srcPackageDir: path$7.join(cwd, packageJsonName),
2263
- destNpmDir: resolve$9(outputDir, 'node_modules')
2344
+ srcPackageDir: path$8.join(cwd, packageJsonName),
2345
+ destNpmDir: resolve$b(outputDir, 'node_modules')
2264
2346
  }]; // 1.2模块的package.json
2265
2347
 
2266
2348
  subPackages.forEach(item => {
2267
- const srcPackageDir = `${getAbsolutePath$2(item.path)}/package.json`;
2349
+ const srcPackageDir = `${getAbsolutePath$4(item.path)}/package.json`;
2268
2350
 
2269
- if (fs$6.existsSync(srcPackageDir)) {
2351
+ if (fs$8.existsSync(srcPackageDir)) {
2270
2352
  packageArr.push({
2271
2353
  srcPackageDir,
2272
- destNpmDir: resolve$9(outputDir, item.root, 'node_modules')
2354
+ destNpmDir: resolve$b(outputDir, item.root, 'node_modules')
2273
2355
  });
2274
2356
  }
2275
2357
  });
@@ -2278,14 +2360,14 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2278
2360
 
2279
2361
 
2280
2362
  function readPackageDependencies(srcPackageDir) {
2281
- const packageJson = fs$6.readFileSync(srcPackageDir, 'utf-8');
2363
+ const packageJson = fs$8.readFileSync(srcPackageDir, 'utf-8');
2282
2364
  let dependencies = {};
2283
2365
 
2284
2366
  try {
2285
2367
  const json = packageJson ? JSON.parse(packageJson) : {};
2286
2368
  dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
2287
2369
  } catch (e) {
2288
- handleError$1(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2370
+ handleError$3(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2289
2371
  }
2290
2372
 
2291
2373
  return dependencies;
@@ -2313,15 +2395,15 @@ const checkPackageVersion$1 = packageArr => {
2313
2395
  const dependenciesKeys = Object.keys(dependencies);
2314
2396
 
2315
2397
  for (const key of dependenciesKeys) {
2316
- const depPath = path$7.join(item.destNpmDir, key);
2398
+ const depPath = path$8.join(item.destNpmDir, key);
2317
2399
 
2318
- if (!fs$6.existsSync(depPath)) {
2400
+ if (!fs$8.existsSync(depPath)) {
2319
2401
  return true;
2320
2402
  }
2321
2403
 
2322
- const depPackagePath = path$7.join(depPath, 'package.json');
2404
+ const depPackagePath = path$8.join(depPath, 'package.json');
2323
2405
 
2324
- if (fs$6.existsSync(depPackagePath)) {
2406
+ if (fs$8.existsSync(depPackagePath)) {
2325
2407
  const packageData = require(depPackagePath);
2326
2408
 
2327
2409
  if (dependencies[key] === 'latest') {
@@ -2348,17 +2430,17 @@ var checkDependencies = {
2348
2430
  };
2349
2431
 
2350
2432
  const shelljs$4 = require$$2__default;
2351
- const fs$5 = require$$0__default$1;
2352
- const path$6 = require$$1__default$1;
2433
+ const fs$7 = require$$0__default$1;
2434
+ const path$7 = require$$1__default$1;
2353
2435
  const io$1 = io$3;
2354
2436
  const {
2355
- createTask: createTask$1,
2356
- resolve: resolve$8,
2357
- getAbsolutePath: getAbsolutePath$1
2437
+ createTask: createTask$3,
2438
+ resolve: resolve$a,
2439
+ getAbsolutePath: getAbsolutePath$3
2358
2440
  } = widgets;
2359
2441
  const {
2360
2442
  buildMpNpm
2361
- } = mpCi;
2443
+ } = mpCi$2;
2362
2444
  const {
2363
2445
  setCache,
2364
2446
  getCache
@@ -2370,7 +2452,7 @@ const {
2370
2452
  npmInstallAll
2371
2453
  } = npm;
2372
2454
  const {
2373
- info: info$6
2455
+ info: info$9
2374
2456
  } = log$1;
2375
2457
  const {
2376
2458
  fileMd5
@@ -2379,16 +2461,16 @@ const {
2379
2461
  isDependenciesUpdate
2380
2462
  } = checkDependencies;
2381
2463
 
2382
- async function install$2(tmsConfig, subPackages, useCache) {
2464
+ async function install$2(tmsConfig, subPackages, useCache = true) {
2383
2465
  const cwd = process.cwd();
2384
- const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2466
+ const npmInstallRes = await createTask$3(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2385
2467
 
2386
2468
  if (!npmInstallRes.isCache) {
2387
2469
  // 构建miniprogram_npm, 不使用缓存
2388
- await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
2470
+ await createTask$3(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
2389
2471
  } else {
2390
2472
  // 构建miniprogram_npm
2391
- await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2473
+ await createTask$3(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2392
2474
  }
2393
2475
 
2394
2476
  shelljs$4.cd(cwd);
@@ -2396,8 +2478,8 @@ async function install$2(tmsConfig, subPackages, useCache) {
2396
2478
 
2397
2479
  async function npmInstall(tmsConfig, subPackages, useCache) {
2398
2480
  // 如果依赖没有更新和使用缓存数据(则命中缓存)
2399
- if (!isDependenciesUpdate(subPackages, resolve$8('./'), tmsConfig.outputDir) && useCache) {
2400
- info$6('node_modules命中缓存');
2481
+ if (!isDependenciesUpdate(subPackages, resolve$a('./'), tmsConfig.outputDir) && useCache) {
2482
+ info$9('node_modules命中缓存');
2401
2483
  return {
2402
2484
  isCache: true
2403
2485
  };
@@ -2405,12 +2487,12 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
2405
2487
 
2406
2488
 
2407
2489
  subPackages.forEach(item => {
2408
- const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
2490
+ const outputModuleDir = resolve$a(`${tmsConfig.outputDir}/${item.root}`);
2409
2491
  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);
2492
+ const modulePackagePath = `${getAbsolutePath$3(item.path)}/package.json`;
2493
+ if (fs$7.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
2412
2494
  });
2413
- await npmInstallAll(subPackages, resolve$8(tmsConfig.outputDir), NODE_MODULES_DIR$1);
2495
+ await npmInstallAll(subPackages, resolve$a(tmsConfig.outputDir), NODE_MODULES_DIR$1);
2414
2496
  return {
2415
2497
  isCache: false
2416
2498
  };
@@ -2419,16 +2501,16 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
2419
2501
 
2420
2502
  async function mpCiInstall(tmsConfig, subPackages, useCache) {
2421
2503
  const packageJsonFiles = [];
2422
- const rootPackFile = resolve$8(`${tmsConfig.outputDir}/package.json`);
2504
+ const rootPackFile = resolve$a(`${tmsConfig.outputDir}/package.json`);
2423
2505
 
2424
- if (fs$5.existsSync(rootPackFile)) {
2506
+ if (fs$7.existsSync(rootPackFile)) {
2425
2507
  packageJsonFiles.push(rootPackFile);
2426
2508
  }
2427
2509
 
2428
2510
  subPackages.forEach(item => {
2429
- const packageJsonFile = resolve$8(`${tmsConfig.outputDir}/${item.root}/package.json`);
2511
+ const packageJsonFile = resolve$a(`${tmsConfig.outputDir}/${item.root}/package.json`);
2430
2512
 
2431
- if (fs$5.existsSync(packageJsonFile)) {
2513
+ if (fs$7.existsSync(packageJsonFile)) {
2432
2514
  packageJsonFiles.push(packageJsonFile);
2433
2515
  }
2434
2516
  });
@@ -2441,8 +2523,8 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2441
2523
  if (useCache) {
2442
2524
  let flag = true;
2443
2525
  await Promise.all(packageJsonFiles.map(async item => {
2444
- const packageDir = path$6.dirname(item);
2445
- const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2526
+ const packageDir = path$7.dirname(item);
2527
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2446
2528
  const md5Value = await getMNPMd5(packageDir);
2447
2529
  const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
2448
2530
  // 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
@@ -2455,14 +2537,14 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2455
2537
  }
2456
2538
 
2457
2539
  if (isCache) {
2458
- info$6('miniprogram_npm命中缓存');
2540
+ info$9('miniprogram_npm命中缓存');
2459
2541
  return;
2460
2542
  } // 即将构建,在cache中标记开始
2461
2543
 
2462
2544
 
2463
2545
  await Promise.all(packageJsonFiles.map(async item => {
2464
- const packageDir = path$6.dirname(item);
2465
- const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2546
+ const packageDir = path$7.dirname(item);
2547
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2466
2548
  setCache(mpDir, 'miniprogram_npm', {
2467
2549
  md5: '',
2468
2550
  status: statusMap.doing
@@ -2470,13 +2552,13 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2470
2552
  }));
2471
2553
  await buildMpNpm({
2472
2554
  appId: tmsConfig.appId,
2473
- projectPath: resolve$8('./'),
2555
+ projectPath: resolve$a('./'),
2474
2556
  privateKey: tmsConfig.privateKey
2475
2557
  }); // 构建成功后,计算md5写入cache
2476
2558
 
2477
2559
  await Promise.all(packageJsonFiles.map(async item => {
2478
- const packageDir = path$6.dirname(item);
2479
- const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2560
+ const packageDir = path$7.dirname(item);
2561
+ const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2480
2562
  const md5Value = await getMNPMd5(packageDir);
2481
2563
  setCache(mpDir, 'miniprogram_npm', {
2482
2564
  md5: md5Value,
@@ -2493,12 +2575,12 @@ async function getMNPMd5(cwd) {
2493
2575
  };
2494
2576
  shelljs$4.cd(cwd);
2495
2577
 
2496
- if (fs$5.existsSync('miniprogram_npm')) {
2578
+ if (fs$7.existsSync('miniprogram_npm')) {
2497
2579
  shelljs$4.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2498
2580
  cwd,
2499
2581
  ...shellJsOption
2500
2582
  });
2501
- const tarDir = path$6.join(cwd, './miniprogram_npm.tar.gz');
2583
+ const tarDir = path$7.join(cwd, './miniprogram_npm.tar.gz');
2502
2584
  const md5Value = await fileMd5(tarDir);
2503
2585
  shelljs$4.rm('-rf', tarDir);
2504
2586
  return md5Value;
@@ -2510,11 +2592,11 @@ async function getMNPMd5(cwd) {
2510
2592
  var install_1 = install$2;
2511
2593
 
2512
2594
  const shelljs$3 = require$$2__default;
2513
- const fs$4 = require$$0__default$1;
2595
+ const fs$6 = require$$0__default$1;
2514
2596
  const io = io$3;
2515
2597
  const {
2516
- resolve: resolve$7,
2517
- createTask
2598
+ resolve: resolve$9,
2599
+ createTask: createTask$2
2518
2600
  } = widgets;
2519
2601
  const {
2520
2602
  buildOutputAppJson: buildOutputAppJson$1
@@ -2532,7 +2614,7 @@ const {
2532
2614
  } = tmsMpconfig.exports;
2533
2615
  const {
2534
2616
  fail: fail$3,
2535
- info: info$5
2617
+ info: info$8
2536
2618
  } = log$1;
2537
2619
  const install$1 = install_1;
2538
2620
  /**
@@ -2544,28 +2626,28 @@ const install$1 = install_1;
2544
2626
  */
2545
2627
 
2546
2628
  const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2547
- const outputDir = resolve$7(tmsConfig.outputDir);
2629
+ const outputDir = resolve$9(tmsConfig.outputDir);
2548
2630
  io.ensureDirExist(outputDir);
2549
2631
  defaultFiles.forEach(item => {
2550
- if (fs$4.existsSync(resolve$7(item))) {
2551
- shelljs$3.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
2632
+ if (fs$6.existsSync(resolve$9(item))) {
2633
+ shelljs$3.cp('-rf', resolve$9(item), resolve$9(tmsConfig.outputDir, item));
2552
2634
  }
2553
2635
  });
2554
2636
  };
2555
2637
 
2556
2638
  async function task(tmsConfig, targetModules) {
2557
2639
  // 下载和移动代码
2558
- await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$7('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2640
+ await createTask$2(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$9('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2559
2641
 
2560
2642
  const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
2561
2643
 
2562
2644
  const newSubPackages = getSubPackages$2(newModules); // 拷贝相关配置文件到输出目录
2563
2645
 
2564
- await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
2646
+ await createTask$2(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
2565
2647
 
2566
2648
  await install$1(tmsConfig, newSubPackages, true); // 动态生成编译后的app.json;
2567
2649
 
2568
- await createTask(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2650
+ await createTask$2(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2569
2651
  return {
2570
2652
  modules: newModules,
2571
2653
  subPackages: newSubPackages
@@ -2579,7 +2661,7 @@ async function init$3(tmsConfig, targetModules) {
2579
2661
  } catch (error) {
2580
2662
  const errMsg = typeof error === 'object' ? error.message : error;
2581
2663
  fail$3(`初始化流程出现错误: ${errMsg}`);
2582
- info$5('详细的错误信息', error);
2664
+ info$8('详细的错误信息', error);
2583
2665
  process.exit(1);
2584
2666
  }
2585
2667
  }
@@ -2609,12 +2691,12 @@ const {
2609
2691
  src: src$1,
2610
2692
  dest
2611
2693
  } = require$$0__default$7;
2612
- const path$5 = require$$1__default$1;
2694
+ const path$6 = require$$1__default$1;
2613
2695
  const minimatch = require$$2__default$1;
2614
2696
  const gulpif = require$$3__default$1;
2615
2697
  const mpProjectJson = mpProjectJson_1;
2616
2698
  const {
2617
- resolve: resolve$6
2699
+ resolve: resolve$8
2618
2700
  } = widgets;
2619
2701
  const through = require$$6__default;
2620
2702
  const {
@@ -2622,8 +2704,8 @@ const {
2622
2704
  } = log$1;
2623
2705
 
2624
2706
  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);
2707
+ const sourceFileRelativeModule = path$6.relative(resolve$8(module.from), sourceFile);
2708
+ const targetFile = resolve$8(outputDir, module.to, sourceFileRelativeModule);
2627
2709
  return targetFile;
2628
2710
  };
2629
2711
 
@@ -2681,7 +2763,7 @@ var compile$1 = function (tmsConfig, {
2681
2763
  // 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
2682
2764
 
2683
2765
  const assign = require$$0__default$8;
2684
- const path$4 = require$$1__default$1;
2766
+ const path$5 = require$$1__default$1;
2685
2767
  const PluginError = require$$2__default$2;
2686
2768
  const fancyLog = require$$3__default$2;
2687
2769
  const colors = require$$4__default$1;
@@ -2726,10 +2808,10 @@ function watch$2(globs, opts, cb) {
2726
2808
 
2727
2809
  function resolveFilepath(filepath) {
2728
2810
  if (pathIsAbsolute(filepath)) {
2729
- return path$4.normalize(filepath);
2811
+ return path$5.normalize(filepath);
2730
2812
  }
2731
2813
 
2732
- return path$4.resolve(opts.cwd || process.cwd(), filepath);
2814
+ return path$5.resolve(opts.cwd || process.cwd(), filepath);
2733
2815
  }
2734
2816
 
2735
2817
  function resolveGlob(glob) {
@@ -2785,7 +2867,7 @@ function watch$2(globs, opts, cb) {
2785
2867
  let glob;
2786
2868
  let currentFilepath = filepath;
2787
2869
 
2788
- while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$4.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
2870
+ while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$5.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
2789
2871
 
2790
2872
 
2791
2873
  if (!glob) {
@@ -2794,7 +2876,7 @@ function watch$2(globs, opts, cb) {
2794
2876
  }
2795
2877
 
2796
2878
  if (!baseForced) {
2797
- fileOpts.base = path$4.normalize(globParent(glob));
2879
+ fileOpts.base = path$5.normalize(globParent(glob));
2798
2880
  } // Do not stat deleted files
2799
2881
 
2800
2882
 
@@ -2854,27 +2936,27 @@ var gulpWatch = watch$2;
2854
2936
 
2855
2937
  /* eslint-disable no-restricted-syntax */
2856
2938
  const watch$1 = gulpWatch;
2857
- const path$3 = require$$1__default$1;
2939
+ const path$4 = require$$1__default$1;
2858
2940
  const shellJs = require$$2__default;
2859
2941
  const {
2860
2942
  series: series$1
2861
2943
  } = require$$0__default$7;
2862
2944
  const {
2863
- info: info$4,
2945
+ info: info$7,
2864
2946
  warn: warn$1,
2865
2947
  fail: fail$1
2866
2948
  } = log$1;
2867
2949
  const {
2868
- resolve: resolve$5,
2869
- filterField: filterField$3
2950
+ resolve: resolve$7,
2951
+ filterField: filterField$5
2870
2952
  } = widgets;
2871
2953
  const {
2872
- global: global$2
2954
+ global: global$6
2873
2955
  } = global_1;
2874
2956
  const {
2875
2957
  checkPackageVersion
2876
2958
  } = checkDependencies;
2877
- const report$5 = report_1;
2959
+ const report$7 = report_1;
2878
2960
  const TIP_MAP = {
2879
2961
  'package.json': {
2880
2962
  tip: '依赖版本有变动,请重新执行tmskit run dev',
@@ -2903,15 +2985,15 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
2903
2985
  }
2904
2986
  }
2905
2987
 
2906
- info$4(`${fileName}有更新`);
2988
+ info$7(`${fileName}有更新`);
2907
2989
  } catch (e) {
2908
2990
  fail$1(`${sourceFile}文件更新提示出现错误: ${e.message}`);
2909
2991
  }
2910
2992
  };
2911
2993
 
2912
2994
  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);
2995
+ const sourceFileRelativeModule = path$4.relative(resolve$7(module.from), sourceFile);
2996
+ const targetFile = resolve$7(outputDir, module.to, sourceFileRelativeModule);
2915
2997
  return targetFile;
2916
2998
  };
2917
2999
 
@@ -2922,11 +3004,11 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
2922
3004
  const sourceFile = vinyl.history[0];
2923
3005
  const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
2924
3006
  const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
2925
- const tmsConfig = global$2.getData('tmsConfig');
3007
+ const tmsConfig = global$6.getData('tmsConfig');
2926
3008
  const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
2927
3009
 
2928
3010
  if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
2929
- info$4(`删除${sourceFileName}`);
3011
+ info$7(`删除${sourceFileName}`);
2930
3012
  shellJs.rm('-rf', targetFile);
2931
3013
  updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
2932
3014
  return;
@@ -2954,13 +3036,13 @@ async function runCallback({
2954
3036
  // callbacl.name === taskFn 代表进入gulp编译流程
2955
3037
  // series为gulp编译串行执行,callback执行完毕后,执行updateFileHooks钩子
2956
3038
  if (callback.name === 'taskFn') {
2957
- series$1(callback.bind(null, [sourceFile], path$3.dirname(targetFile)), cb => {
3039
+ series$1(callback.bind(null, [sourceFile], path$4.dirname(targetFile)), cb => {
2958
3040
  cb();
2959
3041
  updateFileHook(tmsConfig, sourceFile, targetFile, type);
2960
3042
  })();
2961
3043
  } else {
2962
3044
  // 普通的callback函数
2963
- await callback([sourceFile], path$3.dirname(targetFile));
3045
+ await callback([sourceFile], path$4.dirname(targetFile));
2964
3046
  await updateFileHook(tmsConfig, sourceFile, targetFile, type);
2965
3047
  }
2966
3048
  } // 执行源码文件更新的钩子
@@ -2971,17 +3053,18 @@ async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
2971
3053
 
2972
3054
  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
3055
  await tmsConfig.hooks.updateFile({
2974
- tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
3056
+ tmsConfig: filterField$5(tmsConfig, ['gitAccount']),
3057
+ cmdOptions: global$6.getData('cmdOptions'),
2975
3058
  sourceFile,
2976
3059
  targetFile,
2977
3060
  type
2978
3061
  });
2979
- report$5('hooks:updateFile');
3062
+ report$7('hooks:updateFile');
2980
3063
  }
2981
3064
  }
2982
3065
 
2983
- const path$2 = require$$1__default$1;
2984
- const fs$3 = require$$0__default$1;
3066
+ const path$3 = require$$1__default$1;
3067
+ const fs$5 = require$$0__default$1;
2985
3068
  const ora = require$$0__default;
2986
3069
  const chalk$3 = require$$3__default;
2987
3070
  const {
@@ -2989,10 +3072,10 @@ const {
2989
3072
  series
2990
3073
  } = require$$0__default$7;
2991
3074
  const {
2992
- resolve: resolve$4,
3075
+ resolve: resolve$6,
2993
3076
  mergeMap,
2994
- filterField: filterField$2,
2995
- getAbsolutePath
3077
+ filterField: filterField$4,
3078
+ getAbsolutePath: getAbsolutePath$2
2996
3079
  } = widgets;
2997
3080
  const {
2998
3081
  buildOutputAppJson
@@ -3003,21 +3086,24 @@ const {
3003
3086
  const compile = compile$1;
3004
3087
  const watch = watch_1;
3005
3088
  const {
3006
- info: info$3
3089
+ info: info$6
3007
3090
  } = log$1;
3008
- const report$4 = report_1;
3091
+ const report$6 = report_1;
3092
+ const {
3093
+ global: global$5
3094
+ } = global_1;
3009
3095
  const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
3010
3096
 
3011
3097
  var dev$3 = async (tmsConfig, modules, isDev = true) => {
3012
3098
  const compileTasksMap = new Map(); // 监听根目录的文件
3013
3099
 
3014
3100
  mergeMap(compileTasksMap, compile(tmsConfig, {
3015
- glob: DEFAULT_COPY_CONFIG.map(item => resolve$4(item)),
3101
+ glob: DEFAULT_COPY_CONFIG.map(item => resolve$6(item)),
3016
3102
  module: {
3017
- from: resolve$4(),
3018
- to: resolve$4(tmsConfig.outputDir)
3103
+ from: resolve$6(),
3104
+ to: resolve$6(tmsConfig.outputDir)
3019
3105
  },
3020
- destPath: resolve$4(tmsConfig.outputDir),
3106
+ destPath: resolve$6(tmsConfig.outputDir),
3021
3107
  srcOption: {
3022
3108
  allowEmpty: true
3023
3109
  },
@@ -3031,8 +3117,8 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3031
3117
  },
3032
3118
  ...moduleItem
3033
3119
  };
3034
- const srcModulePath = getAbsolutePath(moduleItem.path);
3035
- const buildModulePath = resolve$4(tmsConfig.outputDir, moduleItem.modulePath);
3120
+ const srcModulePath = getAbsolutePath$2(moduleItem.path);
3121
+ const buildModulePath = resolve$6(tmsConfig.outputDir, moduleItem.modulePath);
3036
3122
 
3037
3123
  if (isDev) {
3038
3124
  // 监听模块配置文件
@@ -3045,14 +3131,14 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3045
3131
  }
3046
3132
 
3047
3133
  const excludes = moduleItem.exclude.map(ePath => {
3048
- const newPath = getAbsolutePath(ePath, srcModulePath);
3049
- const ext = path$2.extname(ePath).slice(1);
3134
+ const newPath = getAbsolutePath$2(ePath, srcModulePath);
3135
+ const ext = path$3.extname(ePath).slice(1);
3050
3136
 
3051
3137
  if (ext) {
3052
- return `!${resolve$4(srcModulePath, newPath)}`;
3138
+ return `!${resolve$6(srcModulePath, newPath)}`;
3053
3139
  }
3054
3140
 
3055
- return `!${resolve$4(srcModulePath, newPath)}/**/*`;
3141
+ return `!${resolve$6(srcModulePath, newPath)}/**/*`;
3056
3142
  });
3057
3143
  mergeMap(compileTasksMap, compile(tmsConfig, {
3058
3144
  glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
@@ -3071,10 +3157,10 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3071
3157
 
3072
3158
  if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
3073
3159
  for (const item of tmsConfig.static) {
3074
- item.from = getAbsolutePath(item.from);
3075
- item.to = getAbsolutePath(item.to);
3160
+ item.from = getAbsolutePath$2(item.from);
3161
+ item.to = getAbsolutePath$2(item.to);
3076
3162
  let glob = {};
3077
- const ext = path$2.extname(item.from).slice(1);
3163
+ const ext = path$3.extname(item.from).slice(1);
3078
3164
 
3079
3165
  if (ext) {
3080
3166
  glob = [item.from];
@@ -3082,7 +3168,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3082
3168
  glob = [`${item.from}/**/*`];
3083
3169
  }
3084
3170
 
3085
- const from = fs$3.lstatSync(item.from).isFile() ? path$2.dirname(item.from) : item.from;
3171
+ const from = fs$5.lstatSync(item.from).isFile() ? path$3.dirname(item.from) : item.from;
3086
3172
  mergeMap(compileTasksMap, compile(tmsConfig, {
3087
3173
  glob,
3088
3174
  destPath: item.to,
@@ -3103,7 +3189,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3103
3189
  const spinner = ora();
3104
3190
 
3105
3191
  function start(cb) {
3106
- info$3('启动编译...');
3192
+ info$6('启动编译...');
3107
3193
  spinner.start();
3108
3194
  sTime = new Date().getTime();
3109
3195
  cb();
@@ -3114,12 +3200,12 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3114
3200
 
3115
3201
  if (isDev) {
3116
3202
  // 监听app.json
3117
- watch([resolve$4('app.json')], {
3203
+ watch([resolve$6('app.json')], {
3118
3204
  ignoreInitial: false,
3119
3205
  events: watchEvents
3120
3206
  }, () => buildOutputAppJson(tmsConfig, modules, isDev), {
3121
- from: resolve$4(),
3122
- to: resolve$4(tmsConfig.outputDir)
3207
+ from: resolve$6(),
3208
+ to: resolve$6(tmsConfig.outputDir)
3123
3209
  }); // 监听其他文件
3124
3210
 
3125
3211
  compileTasksMap.forEach(({
@@ -3142,10 +3228,11 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3142
3228
 
3143
3229
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterFirstCompile({
3144
3230
  isDev,
3145
- tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
3146
- modules
3231
+ tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
3232
+ modules,
3233
+ cmdOptions: global$5.getData('cmdOptions')
3147
3234
  }));
3148
- report$4('hooks:afterCompile');
3235
+ report$6('hooks:afterCompile');
3149
3236
  }
3150
3237
 
3151
3238
  spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
@@ -3165,7 +3252,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3165
3252
 
3166
3253
  var require$$12 = {
3167
3254
  name: "@tmsfe/tmskit",
3168
- version: "0.0.24",
3255
+ version: "0.0.25",
3169
3256
  description: "tmskit",
3170
3257
  main: "dist/index.cjs",
3171
3258
  bin: {
@@ -3198,6 +3285,11 @@ var require$$12 = {
3198
3285
  "@rollup/plugin-json": "^4.0.3",
3199
3286
  rollup: "^2.6.1"
3200
3287
  },
3288
+ whiteDependencies: {
3289
+ "miniprogram-ci": "ignore",
3290
+ ora: "ignore",
3291
+ shelljs: "ignore"
3292
+ },
3201
3293
  dependencies: {
3202
3294
  "ansi-colors": "1.1.0",
3203
3295
  anymatch: "^1.3.0",
@@ -3220,7 +3312,7 @@ var require$$12 = {
3220
3312
  lodash: "^4.17.21",
3221
3313
  metalsmith: "^2.3.0",
3222
3314
  minimatch: "^5.1.0",
3223
- "miniprogram-ci": "1.4.13",
3315
+ "miniprogram-ci": "1.8.25",
3224
3316
  moment: "^2.29.2",
3225
3317
  "object-assign": "^4.0.1",
3226
3318
  ora: "^5.1.0",
@@ -3248,8 +3340,8 @@ var require$$12 = {
3248
3340
  }
3249
3341
  };
3250
3342
 
3251
- const fs$2 = require$$0__default$1;
3252
- const path$1 = require$$1__default$1;
3343
+ const fs$4 = require$$0__default$1;
3344
+ const path$2 = require$$1__default$1;
3253
3345
  const shelljs$2 = require$$2__default;
3254
3346
  const chalk$2 = require$$3__default;
3255
3347
  const request = require$$0__default$5;
@@ -3263,7 +3355,7 @@ const {
3263
3355
  VERSION_URL
3264
3356
  } = constant;
3265
3357
  const {
3266
- ensureDirExist: ensureDirExist$1
3358
+ ensureDirExist: ensureDirExist$2
3267
3359
  } = io$3;
3268
3360
  const {
3269
3361
  versionCompare
@@ -3316,7 +3408,7 @@ function isInstallLatestVersion() {
3316
3408
  function getVersionIsRecommend(version) {
3317
3409
  const filePath = VERSION_CACHE_FILE;
3318
3410
 
3319
- if (!fs$2.existsSync(filePath)) {
3411
+ if (!fs$4.existsSync(filePath)) {
3320
3412
  return false;
3321
3413
  }
3322
3414
 
@@ -3329,20 +3421,20 @@ function getVersionIsRecommend(version) {
3329
3421
  function setVersionRecommend(version, isRecommend) {
3330
3422
  const filePath = VERSION_CACHE_FILE;
3331
3423
 
3332
- if (!fs$2.existsSync(filePath)) {
3333
- const dir = path$1.dirname(filePath);
3334
- ensureDirExist$1(dir);
3335
- fs$2.writeFileSync(filePath, '{}');
3424
+ if (!fs$4.existsSync(filePath)) {
3425
+ const dir = path$2.dirname(filePath);
3426
+ ensureDirExist$2(dir);
3427
+ fs$4.writeFileSync(filePath, '{}');
3336
3428
  }
3337
3429
 
3338
3430
  const content = require(filePath);
3339
3431
 
3340
3432
  content[version] = isRecommend;
3341
- fs$2.writeFileSync(filePath, JSON.stringify(content, null, 2));
3433
+ fs$4.writeFileSync(filePath, JSON.stringify(content, null, 2));
3342
3434
  } // 推荐理由
3343
3435
 
3344
3436
 
3345
- function displayRecommends(arr) {
3437
+ function displayRecommends(arr = []) {
3346
3438
  infoNoTime$1(chalk$2.green('构建工具有新的版本~~:'));
3347
3439
  arr.forEach(item => {
3348
3440
  infoNoTime$1(chalk$2.green(item));
@@ -3391,8 +3483,8 @@ var recommendVersion_1 = {
3391
3483
  const shelljs$1 = require$$2__default;
3392
3484
  const compileDev = dev$3;
3393
3485
  const {
3394
- resolve: resolve$3,
3395
- filterField: filterField$1
3486
+ resolve: resolve$5,
3487
+ filterField: filterField$3
3396
3488
  } = widgets;
3397
3489
  const init$2 = init_1;
3398
3490
  const {
@@ -3400,16 +3492,16 @@ const {
3400
3492
  getSubPackages: getSubPackages$1
3401
3493
  } = tmsMpconfig.exports;
3402
3494
  const {
3403
- info: info$2
3495
+ info: info$5
3404
3496
  } = log$1;
3405
3497
  const {
3406
- global: global$1
3498
+ global: global$4
3407
3499
  } = global_1;
3408
3500
  const {
3409
3501
  MODULE_CODE_DIR,
3410
3502
  NODE_MODULES_DIR
3411
3503
  } = constant;
3412
- const report$3 = report_1;
3504
+ const report$5 = report_1;
3413
3505
  const {
3414
3506
  recommendVersion
3415
3507
  } = recommendVersion_1; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
@@ -3422,7 +3514,7 @@ function delOtherPackages(tmsConfig, targetSubPackages) {
3422
3514
  const targetSubPackagesName = targetSubPackages.map(item => item.name);
3423
3515
  allSubPackages.forEach(item => {
3424
3516
  if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
3425
- const moduleRootDir = resolve$3(`${tmsConfig.outputDir}/${item.root}`);
3517
+ const moduleRootDir = resolve$5(`${tmsConfig.outputDir}/${item.root}`);
3426
3518
  shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
3427
3519
  silent: true
3428
3520
  }); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
@@ -3436,10 +3528,10 @@ async function dev$2(tmsConfig, targetModules) {
3436
3528
 
3437
3529
  const {
3438
3530
  noCache
3439
- } = global$1.getData('cmd');
3531
+ } = global$4.getData('cmdOptions');
3440
3532
 
3441
3533
  if (noCache) {
3442
- shelljs$1.rm('-rf', resolve$3(tmsConfig.outputDir));
3534
+ shelljs$1.rm('-rf', resolve$5(tmsConfig.outputDir));
3443
3535
  shelljs$1.rm('-rf', MODULE_CODE_DIR);
3444
3536
  shelljs$1.rm('-rf', NODE_MODULES_DIR);
3445
3537
  } // 推荐tmskit的版本
@@ -3451,17 +3543,18 @@ async function dev$2(tmsConfig, targetModules) {
3451
3543
  subPackages,
3452
3544
  modules: newModules
3453
3545
  } = await init$2(tmsConfig, targetModules);
3454
- info$2('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3546
+ info$5('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3455
3547
 
3456
3548
  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
3549
  var _tmsConfig$hooks2;
3458
3550
 
3459
3551
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
3460
3552
  isDev: true,
3461
- tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
3462
- modules: newModules
3553
+ tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
3554
+ modules: newModules,
3555
+ cmdOptions: global$4.getData('cmdOptions')
3463
3556
  }));
3464
- report$3('hooks:beforeCompile');
3557
+ report$5('hooks:beforeCompile');
3465
3558
  }
3466
3559
  delOtherPackages(tmsConfig, subPackages);
3467
3560
  compileDev(tmsConfig, newModules, true);
@@ -3477,21 +3570,28 @@ var build$2 = async (tmsConfig, newModules, isDev) => {
3477
3570
 
3478
3571
  const shelljs = require$$2__default;
3479
3572
  const {
3480
- resolve: resolve$2,
3481
- filterField
3573
+ resolve: resolve$4,
3574
+ filterField: filterField$2
3482
3575
  } = widgets;
3483
3576
  const init$1 = init_1;
3577
+ const {
3578
+ info: info$4
3579
+ } = log$1;
3484
3580
  const compileBuild = build$2;
3485
- const report$2 = report_1;
3581
+ const report$4 = report_1;
3582
+ const {
3583
+ global: global$3
3584
+ } = global_1;
3486
3585
 
3487
3586
  async function build$1(tmsConfig, targetModules) {
3488
3587
  var _tmsConfig$hooks;
3489
3588
 
3490
3589
  // 开始构建前,清理输出目录
3491
- await shelljs.rm('-rf', resolve$2(tmsConfig.outputDir));
3590
+ await shelljs.rm('-rf', resolve$4(tmsConfig.outputDir));
3492
3591
  const {
3493
3592
  modules: newModules
3494
3593
  } = await init$1(tmsConfig, targetModules);
3594
+ info$4('当前build有效模块', newModules.map(item => item.moduleName).sort());
3495
3595
  const isDev = false;
3496
3596
 
3497
3597
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
@@ -3499,16 +3599,240 @@ async function build$1(tmsConfig, targetModules) {
3499
3599
 
3500
3600
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
3501
3601
  isDev,
3502
- tmsConfig: filterField(tmsConfig, ['gitAccount']),
3503
- modules: newModules
3602
+ tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
3603
+ modules: newModules,
3604
+ cmdOptions: global$3.getData('cmdOptions')
3504
3605
  }));
3505
- report$2('hooks:beforeCompile');
3606
+ report$4('hooks:beforeCompile');
3506
3607
  }
3507
3608
  compileBuild(tmsConfig, newModules, isDev);
3508
3609
  }
3509
3610
 
3510
3611
  var build_1 = build$1;
3511
3612
 
3613
+ const moment = require$$1__default;
3614
+ const path$1 = require$$1__default$1;
3615
+ const fs$3 = require$$0__default$1;
3616
+ const {
3617
+ getGitUser,
3618
+ getAbsolutePath: getAbsolutePath$1
3619
+ } = widgets;
3620
+ const {
3621
+ ensureDirExist: ensureDirExist$1
3622
+ } = io$3;
3623
+
3624
+ function getAllSize$2(data = {}) {
3625
+ let allSize;
3626
+
3627
+ for (const item of data === null || data === void 0 ? void 0 : data.subPackageInfo) {
3628
+ if (item.name === '__FULL__') {
3629
+ allSize = item.size;
3630
+ break;
3631
+ }
3632
+ }
3633
+
3634
+ return allSize;
3635
+ }
3636
+
3637
+ const getDesc$2 = (desc = '') => {
3638
+ const user = getGitUser();
3639
+ const date = moment().format('YYYY-MM-DD HH:mm:ss');
3640
+ return `构建描述:${desc}; 构建人: ${user}; 构建时间:${date}`;
3641
+ };
3642
+
3643
+ const outputInfo$2 = (infoOutput, data) => {
3644
+ const outPath = getAbsolutePath$1(infoOutput);
3645
+ const dir = path$1.dirname(outPath);
3646
+ ensureDirExist$1(dir);
3647
+ fs$3.writeFileSync(outPath, JSON.stringify(data, null, 2));
3648
+ };
3649
+
3650
+ const getDetaultVersion = () => {
3651
+ const version = moment().format('gggg,mm').split(',');
3652
+ version.push('0');
3653
+ return version.join('.');
3654
+ };
3655
+
3656
+ var utils = {
3657
+ getAllSize: getAllSize$2,
3658
+ getDesc: getDesc$2,
3659
+ outputInfo: outputInfo$2,
3660
+ getDetaultVersion
3661
+ };
3662
+
3663
+ const mpCi$1 = mpCi$2;
3664
+ const fs$2 = require$$0__default$1;
3665
+ const {
3666
+ resolve: resolve$3,
3667
+ createTask: createTask$1,
3668
+ getAbsolutePath,
3669
+ filterField: filterField$1
3670
+ } = widgets;
3671
+ const {
3672
+ handleError: handleError$2
3673
+ } = handleError_1;
3674
+ const {
3675
+ info: info$3
3676
+ } = log$1;
3677
+ const {
3678
+ global: global$2
3679
+ } = global_1;
3680
+ const {
3681
+ getAllSize: getAllSize$1,
3682
+ outputInfo: outputInfo$1,
3683
+ getDesc: getDesc$1
3684
+ } = utils;
3685
+ const report$3 = report_1;
3686
+
3687
+ const handleParams$1 = (tmsConfig, cmdOptions) => {
3688
+ const params = { ...(tmsConfig.preview ? tmsConfig.preview : {}),
3689
+ ...cmdOptions
3690
+ };
3691
+ return { ...params,
3692
+ appId: params.appId || tmsConfig.appId,
3693
+ projectPath: resolve$3(tmsConfig.outputDir),
3694
+ privateKey: params.privateKey || tmsConfig.privateKey,
3695
+ robot: params.robot || 30,
3696
+ desc: params.desc || getDesc$1(params.desc),
3697
+ qrcodeOutputDest: getAbsolutePath(params.qrcodeOutputDest || '')
3698
+ };
3699
+ };
3700
+ /**
3701
+ * 预览
3702
+ * @params {object} tmsConfig
3703
+ * @param {object} cmdOptions {qrcodeFormat: 'base64', qrcodeOutputDest: './a.txt', robot: 2, infoOutput: './a.txt' }
3704
+ */
3705
+
3706
+
3707
+ async function preview$1(tmsConfig, cmdOptions) {
3708
+ try {
3709
+ var _tmsConfig$hooks;
3710
+
3711
+ const params = handleParams$1(tmsConfig, cmdOptions);
3712
+
3713
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforePreview) === 'function') {
3714
+ var _tmsConfig$hooks2;
3715
+
3716
+ await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforePreview({
3717
+ tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
3718
+ cmdOptions: global$2.getData('cmdOptions'),
3719
+ params
3720
+ }));
3721
+ report$3('hooks:beforePreview');
3722
+ }
3723
+
3724
+ ;
3725
+ const previewRes = await createTask$1(mpCi$1.previewMp, '正在构建预览码', '构建预览码完成')({ ...params
3726
+ });
3727
+ const allSize = getAllSize$1(previewRes);
3728
+
3729
+ if (params.infoOutput) {
3730
+ let qrcodeBase64 = '';
3731
+
3732
+ if (params.qrcodeFormat === 'base64' && fs$2.existsSync(params.qrcodeOutputDest)) {
3733
+ qrcodeBase64 = fs$2.readFileSync(params.qrcodeOutputDest, 'utf8');
3734
+ }
3735
+
3736
+ outputInfo$1(params.infoOutput, {
3737
+ sourceCode: params.projectPath,
3738
+ qrcodeBase64,
3739
+ ...previewRes
3740
+ });
3741
+ }
3742
+
3743
+ info$3('预览包大小:', `${allSize}k`);
3744
+ } catch (e) {
3745
+ console.log('详细错误:', e);
3746
+ handleError$2(`预览错误: ${e.message}`, true);
3747
+ }
3748
+ }
3749
+
3750
+ var preview_1 = preview$1;
3751
+
3752
+ const mpCi = mpCi$2;
3753
+ const {
3754
+ resolve: resolve$2,
3755
+ createTask,
3756
+ filterField
3757
+ } = widgets;
3758
+ const {
3759
+ handleError: handleError$1
3760
+ } = handleError_1;
3761
+ const {
3762
+ info: info$2
3763
+ } = log$1;
3764
+ const {
3765
+ global: global$1
3766
+ } = global_1;
3767
+ const {
3768
+ getAllSize,
3769
+ outputInfo,
3770
+ getDesc
3771
+ } = utils;
3772
+ const report$2 = report_1;
3773
+
3774
+ const handleParams = (tmsConfig, cmdOptions) => {
3775
+ const params = { ...(tmsConfig.upload ? tmsConfig.upload : {}),
3776
+ ...cmdOptions
3777
+ };
3778
+
3779
+ if (!params.version) {
3780
+ throw new Error('请指定传入版本号 eg: tmskit run upload --version 2022.28.5');
3781
+ }
3782
+
3783
+ return { ...params,
3784
+ appId: params.appId || tmsConfig.appId,
3785
+ projectPath: resolve$2(tmsConfig.outputDir),
3786
+ privateKey: params.privateKey || tmsConfig.privateKey,
3787
+ robot: params.robot || 30,
3788
+ desc: params.desc || getDesc(params.desc)
3789
+ };
3790
+ };
3791
+ /**
3792
+ * 上传
3793
+ * @param {object} tmsConfig
3794
+ * @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
3795
+ */
3796
+
3797
+
3798
+ async function upload$1(tmsConfig, cmdOptions) {
3799
+ try {
3800
+ var _tmsConfig$hooks;
3801
+
3802
+ const params = handleParams(tmsConfig, cmdOptions);
3803
+
3804
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeUpload) === 'function') {
3805
+ var _tmsConfig$hooks2;
3806
+
3807
+ await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeUpload({
3808
+ tmsConfig: filterField(tmsConfig, ['gitAccount']),
3809
+ cmdOptions: global$1.getData('cmdOptions'),
3810
+ params
3811
+ }));
3812
+ report$2('hooks:beforeUpload');
3813
+ }
3814
+
3815
+ ;
3816
+ const uploadRes = await createTask(mpCi.uploadMp, '正在上传小程序代码', '上传小程序代码完成')({ ...params
3817
+ });
3818
+ const allSize = getAllSize(uploadRes);
3819
+
3820
+ if (params.infoOutput) {
3821
+ outputInfo(params.infoOutput, {
3822
+ sourceCode: params.projectPath,
3823
+ ...uploadRes
3824
+ });
3825
+ }
3826
+
3827
+ info$2(`上传包大小: ${allSize}k; 上传包版本: ${params.version}`);
3828
+ } catch (e) {
3829
+ console.log('详细错误:', e);
3830
+ handleError$1(`上传错误: ${e.message}`, true);
3831
+ }
3832
+ }
3833
+
3834
+ var upload_1 = upload$1;
3835
+
3512
3836
  const fs$1 = require$$0__default$1;
3513
3837
  const {
3514
3838
  resolve: resolve$1
@@ -3563,7 +3887,7 @@ var cloud$1 = async tmsConfig => {
3563
3887
  try {
3564
3888
  await symLink(tmsConfig);
3565
3889
  } catch (e) {
3566
- handleError(`创建软链错误: ${e}`);
3890
+ handleError(`创建软链错误: ${e}`, true);
3567
3891
  }
3568
3892
  };
3569
3893
 
@@ -3572,6 +3896,8 @@ const init = init_1;
3572
3896
  const dev = dev_1;
3573
3897
  const build = build_1;
3574
3898
  const install = install_1;
3899
+ const preview = preview_1;
3900
+ const upload = upload_1;
3575
3901
  const cloud = cloud$1;
3576
3902
  const {
3577
3903
  fail,
@@ -3588,10 +3914,10 @@ const {
3588
3914
  getModulesByModuleNames
3589
3915
  } = tmsMpconfig.exports;
3590
3916
 
3591
- const handleModuleArg = cmd => {
3917
+ const handleModuleArg = cmdOptions => {
3592
3918
  // 单模块或多模块开发-用户通过脚手架参数指定的模块
3593
- if (typeof cmd.module === 'string') {
3594
- return cmd.module.split(',');
3919
+ if (typeof cmdOptions.module === 'string') {
3920
+ return cmdOptions.module.split(',');
3595
3921
  }
3596
3922
 
3597
3923
  return [];
@@ -3631,14 +3957,14 @@ const getSpecificModuleNames = (moduleArg, modules) => {
3631
3957
  return all.map(item => item.moduleName);
3632
3958
  };
3633
3959
 
3634
- async function run(commandName, cmd) {
3960
+ async function run(commandName, cmdOptions) {
3635
3961
  // 用户本地的配置
3636
3962
  const tmsConfig = getTmsConfig$1();
3637
3963
 
3638
3964
  try {
3639
3965
  // 缓存数据
3640
3966
  global.setData({
3641
- cmd,
3967
+ cmdOptions,
3642
3968
  tmsConfig
3643
3969
  });
3644
3970
 
@@ -3650,7 +3976,7 @@ async function run(commandName, cmd) {
3650
3976
  return;
3651
3977
  }
3652
3978
 
3653
- otherCommands(tmsConfig, commandName, cmd);
3979
+ otherCommands(tmsConfig, commandName, cmdOptions);
3654
3980
  } catch (error) {
3655
3981
  const errMsg = typeof error === 'object' ? error.message : error;
3656
3982
  report$1('run', {
@@ -3663,9 +3989,9 @@ async function run(commandName, cmd) {
3663
3989
  }
3664
3990
  }
3665
3991
 
3666
- function otherCommands(tmsConfig, commandName, cmd) {
3992
+ function otherCommands(tmsConfig, commandName, cmdOptions) {
3667
3993
  // 处理module参数
3668
- const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmd), tmsConfig.modules); // moduleNames => ['home', 'car']
3994
+ const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmdOptions), tmsConfig.modules); // moduleNames => ['home', 'car']
3669
3995
 
3670
3996
  const moduleNames = [...new Set([...specificModuleNames])];
3671
3997
  const modules = getModulesByModuleNames(tmsConfig, moduleNames, false); // 获取所有模块,合并模块依赖的模块
@@ -3705,6 +4031,20 @@ function otherCommands(tmsConfig, commandName, cmd) {
3705
4031
  });
3706
4032
  return;
3707
4033
 
4034
+ case 'preview':
4035
+ preview(tmsConfig, cmdOptions);
4036
+ report$1('run:preview', {
4037
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
4038
+ });
4039
+ return;
4040
+
4041
+ case 'upload':
4042
+ upload(tmsConfig, cmdOptions);
4043
+ report$1('run:upload', {
4044
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
4045
+ });
4046
+ return;
4047
+
3708
4048
  default:
3709
4049
  return;
3710
4050
  }
@@ -3722,9 +4062,9 @@ var entry = [{
3722
4062
  command: 'install-cmd <npm-name>',
3723
4063
  description: '安装扩展命令',
3724
4064
  options: [['--registry [registry]', 'npm源']],
3725
- action: (npmName, cmd) => {
4065
+ action: (npmName, cmdOptions) => {
3726
4066
  const res = extendCmd;
3727
- res.installCmd(npmName, cmd);
4067
+ res.installCmd(npmName, cmdOptions);
3728
4068
  }
3729
4069
  }, {
3730
4070
  name: 'run',
@@ -3734,29 +4074,43 @@ var entry = [{
3734
4074
  command: 'install',
3735
4075
  description: '安装依赖',
3736
4076
  options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
3737
- action: cmd => {
3738
- run_1('install', cmd);
4077
+ action: cmdOptions => {
4078
+ run_1('install', cmdOptions);
3739
4079
  }
3740
4080
  }, {
3741
4081
  command: 'dev',
3742
4082
  description: 'dev 打包编译',
3743
4083
  options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-noCache, --noCache', '不使用缓存功能']],
3744
- action: cmd => {
3745
- run_1('dev', cmd);
4084
+ action: cmdOptions => {
4085
+ run_1('dev', cmdOptions);
3746
4086
  }
3747
4087
  }, {
3748
4088
  command: 'cloud',
3749
4089
  description: '云函数开发',
3750
4090
  options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
3751
- action: cmd => {
3752
- run_1('cloud', cmd);
4091
+ action: cmdOptions => {
4092
+ run_1('cloud', cmdOptions);
3753
4093
  }
3754
4094
  }, {
3755
4095
  command: 'build',
3756
4096
  description: 'prod 打包编译',
3757
4097
  options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
3758
- action: cmd => {
3759
- run_1('build', cmd);
4098
+ action: cmdOptions => {
4099
+ run_1('build', cmdOptions);
4100
+ }
4101
+ }, {
4102
+ command: 'preview',
4103
+ description: '小程序预览',
4104
+ options: [['-f, --qrcodeFormat [qrcodeFormat]', '二维码的格式,选项terminal, image, base64。默认terminal'], ['-o, --qrcodeOutputDest [qrcodeOutputDest]', '二维码会被输出到给定路径'], ['-i, --info-output [infoOutput]', '相关信息会被输出到给定路径']],
4105
+ action: cmdOptions => {
4106
+ run_1('preview', cmdOptions);
4107
+ }
4108
+ }, {
4109
+ command: 'upload',
4110
+ description: '小程序上传',
4111
+ options: [['--version [version]', '上传代码版本,version 指定版本号'], ['-d, --desc [desc]', '上传代码时的备注'], ['-i, --info-output [infoOutput]', '相关信息会被输出到给定路径'], ['-r, --robot [robot]', '指定使用哪一个 ci 机器人,可选值:1 ~ 30']],
4112
+ action: cmdOptions => {
4113
+ run_1('upload', cmdOptions);
3760
4114
  }
3761
4115
  }]
3762
4116
  }];