@tmsfe/tmskit 0.0.41 → 0.0.43

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
@@ -120,13 +120,13 @@ const succeed$2 = (message = '') => {
120
120
  const warn$2 = message => {
121
121
  console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, chalk$5.yellow(message));
122
122
  };
123
- const info$j = (...args) => console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
123
+ const info$k = (...args) => console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
124
124
  const infoNoTime$1 = (...args) => console.log(...args);
125
125
  var log$1 = {
126
126
  fail: fail$a,
127
127
  succeed: succeed$2,
128
128
  warn: warn$2,
129
- info: info$j,
129
+ info: info$k,
130
130
  infoNoTime: infoNoTime$1
131
131
  };
132
132
 
@@ -136,7 +136,7 @@ const fs$j = require$$0__default$1;
136
136
  const shelljs$7 = require$$0__default$2;
137
137
  const glob = require$$4__default;
138
138
  const {
139
- info: info$i
139
+ info: info$j
140
140
  } = log$1;
141
141
  const shelljsOptions = {
142
142
  slient: true,
@@ -145,7 +145,7 @@ const shelljsOptions = {
145
145
 
146
146
  // 获取当前目录
147
147
  const cwd = process.cwd();
148
- function resolve$j(...args) {
148
+ function resolve$k(...args) {
149
149
  return path$h.resolve(cwd, ...args);
150
150
  }
151
151
 
@@ -274,11 +274,11 @@ const cost = start => Date.now() - start;
274
274
  * @param {String} endText 任务结束后提示语
275
275
  * @returns {Undefined} 无需返回值
276
276
  */
277
- function createTask$6(task, startText, endText) {
277
+ function createTask$7(task, startText, endText) {
278
278
  return async (...args) => {
279
279
  const start = Date.now();
280
280
  const spinner = ora$2();
281
- info$i(startText);
281
+ info$j(startText);
282
282
  spinner.start();
283
283
  const result = await task(...args);
284
284
  endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
@@ -336,7 +336,7 @@ function findFiles(globPath, filter = []) {
336
336
  // 获取绝对路径
337
337
  function getAbsolutePath$6(pathDir, cwd = '') {
338
338
  let newPath = pathDir;
339
- newPath = newPath.startsWith('/') ? newPath : resolve$j(cwd, newPath);
339
+ newPath = newPath.startsWith('/') ? newPath : resolve$k(cwd, newPath);
340
340
  newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
341
341
  return newPath;
342
342
  }
@@ -367,10 +367,10 @@ function getGitUser$2() {
367
367
  return res.stdout;
368
368
  }
369
369
  var widgets = {
370
- resolve: resolve$j,
370
+ resolve: resolve$k,
371
371
  isObject,
372
372
  isArray,
373
- createTask: createTask$6,
373
+ createTask: createTask$7,
374
374
  downloadRepoForGit: downloadRepoForGit$1,
375
375
  pullRepoForGit: pullRepoForGit$1,
376
376
  camelize,
@@ -505,6 +505,8 @@ var defaultTmsConfig = {
505
505
  dependencies: {},
506
506
  /** 编译输出文件夹位置 */
507
507
  outputDir: 'dist',
508
+ /** 是否在编译前清空输出目录 */
509
+ cleanOutputDirBeforeCompile: true,
508
510
  /** 源码监听路径 */
509
511
  sourceDir: './',
510
512
  /** 静态资源目录 */
@@ -842,7 +844,7 @@ var defaultTmsConfig = {
842
844
  const fs$i = require$$0__default$1;
843
845
  const path$f = require$$1__default$1;
844
846
  const {
845
- info: info$h
847
+ info: info$i
846
848
  } = log$1;
847
849
  const {
848
850
  relativeCwdPath
@@ -892,11 +894,11 @@ function diffContentCopyFile(originFile, destFile) {
892
894
  const depDestContent = fs$i.readFileSync(destFile, 'utf8');
893
895
  const depOriginContent = fs$i.readFileSync(originFile, 'utf8');
894
896
  if (depDestContent !== depOriginContent) {
895
- info$h(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
897
+ info$i(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
896
898
  copyFile(originFile, destFile);
897
899
  }
898
900
  } else {
899
- info$h(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
901
+ info$i(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
900
902
  copyFile(originFile, destFile);
901
903
  }
902
904
  }
@@ -989,7 +991,7 @@ var render_1 = render$1;
989
991
  const fs$h = require$$0__default$1;
990
992
  const inquirer$1 = require$$1__default$5;
991
993
  const {
992
- resolve: resolve$i
994
+ resolve: resolve$j
993
995
  } = widgets;
994
996
  const {
995
997
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
@@ -1031,7 +1033,7 @@ const isQuestionType = result => {
1031
1033
  return true;
1032
1034
  };
1033
1035
  const ask$1 = templateDir => (files, metalsmith, next) => {
1034
- const prompts = parseTemplateQuestions(resolve$i(templateDir, TEMPLATE_TKIT_DIR$1));
1036
+ const prompts = parseTemplateQuestions(resolve$j(templateDir, TEMPLATE_TKIT_DIR$1));
1035
1037
  const metadata = metalsmith.metadata();
1036
1038
  const filteredPrompts = prompts.filter(prompt => {
1037
1039
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -1074,7 +1076,7 @@ const {
1074
1076
  getGitUser: getGitUser$1
1075
1077
  } = widgets;
1076
1078
  const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
1077
- const report$a = (name, attrs = {}) => {
1079
+ const report$b = (name, attrs = {}) => {
1078
1080
  try {
1079
1081
  const param = [];
1080
1082
  param[27] = name;
@@ -1096,7 +1098,7 @@ const report$a = (name, attrs = {}) => {
1096
1098
  // }
1097
1099
  } catch (e) {}
1098
1100
  };
1099
- var report_1 = report$a;
1101
+ var report_1 = report$b;
1100
1102
 
1101
1103
  const path$e = require$$1__default$1;
1102
1104
  const fs$g = require$$0__default$1;
@@ -1110,18 +1112,18 @@ const {
1110
1112
  CREATE_TEMPLATE_QUESTION
1111
1113
  } = constant;
1112
1114
  const {
1113
- resolve: resolve$h
1115
+ resolve: resolve$i
1114
1116
  } = widgets;
1115
1117
  const io$2 = io$3;
1116
1118
  const {
1117
1119
  fail: fail$9,
1118
1120
  succeed: succeed$1,
1119
- info: info$g
1121
+ info: info$h
1120
1122
  } = log$1;
1121
1123
  const generator = generator_1;
1122
1124
  const request = require$$0__default$6;
1123
1125
  const unzip = require$$10__default;
1124
- const report$9 = report_1;
1126
+ const report$a = report_1;
1125
1127
 
1126
1128
  /**
1127
1129
  * 如果该目录下面存在文件,换个名字
@@ -1180,7 +1182,7 @@ async function create(projectName) {
1180
1182
  const {
1181
1183
  projectType
1182
1184
  } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
1183
- report$9('create-start', {
1185
+ report$a('create-start', {
1184
1186
  projectType
1185
1187
  });
1186
1188
 
@@ -1201,7 +1203,7 @@ async function create(projectName) {
1201
1203
  // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
1202
1204
  generator(path$e.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1203
1205
  shelljs$6.cd(projectName);
1204
- const hookFilePath = resolve$h(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1206
+ const hookFilePath = resolve$i(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1205
1207
  if (fs$g.existsSync(hookFilePath)) {
1206
1208
  const hooks = require(hookFilePath);
1207
1209
  if (hooks.afterCreate) {
@@ -1215,15 +1217,15 @@ async function create(projectName) {
1215
1217
  }
1216
1218
  });
1217
1219
  }
1218
- shelljs$6.rm('-rf', resolve$h(projectName, TEMPLATE_TKIT_DIR));
1220
+ shelljs$6.rm('-rf', resolve$i(projectName, TEMPLATE_TKIT_DIR));
1219
1221
  }
1220
- report$9('create-success', {
1222
+ report$a('create-success', {
1221
1223
  projectType
1222
1224
  });
1223
1225
  succeed$1('项目创建完成.');
1224
1226
  }).catch(err => {
1225
1227
  fail$9(err.message);
1226
- info$g('详细的错误信息:', err);
1228
+ info$h('详细的错误信息:', err);
1227
1229
  });
1228
1230
  }
1229
1231
  var create_1 = create;
@@ -1238,10 +1240,10 @@ const {
1238
1240
  EXTEND_CMD
1239
1241
  } = constant;
1240
1242
  const {
1241
- createTask: createTask$5
1243
+ createTask: createTask$6
1242
1244
  } = widgets;
1243
1245
  const {
1244
- info: info$f,
1246
+ info: info$g,
1245
1247
  fail: fail$8
1246
1248
  } = log$1;
1247
1249
 
@@ -1260,7 +1262,7 @@ async function installCmd(npmName, cmd) {
1260
1262
  }, null, 2));
1261
1263
  }
1262
1264
  shellJs$3.cd(EXTEND_CMD);
1263
- await createTask$5(npmName => new Promise((resolve, reject) => {
1265
+ await createTask$6(npmName => new Promise((resolve, reject) => {
1264
1266
  const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
1265
1267
  shellJs$3.exec(`npm install --save ${npmName} ${registry}`, {
1266
1268
  cwd: EXTEND_CMD,
@@ -1274,7 +1276,7 @@ async function installCmd(npmName, cmd) {
1274
1276
  }), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
1275
1277
  } catch (e) {
1276
1278
  fail$8('构建出现错误:');
1277
- info$f(e);
1279
+ info$g(e);
1278
1280
  process.exit(1);
1279
1281
  }
1280
1282
  }
@@ -1336,7 +1338,7 @@ const {
1336
1338
  const {
1337
1339
  global: global$b
1338
1340
  } = global_1;
1339
- function handleError$8(error, isQuit = false) {
1341
+ function handleError$9(error, isQuit = false) {
1340
1342
  const errMsg = typeof error === 'object' ? error.message : error;
1341
1343
  if (isQuit) {
1342
1344
  fail$7(errMsg);
@@ -1351,7 +1353,7 @@ function handleError$8(error, isQuit = false) {
1351
1353
  }
1352
1354
  }
1353
1355
  var handleError_1 = {
1354
- handleError: handleError$8
1356
+ handleError: handleError$9
1355
1357
  };
1356
1358
 
1357
1359
  /**
@@ -1367,19 +1369,19 @@ const {
1367
1369
  } = tmsMpconfig.exports;
1368
1370
  const {
1369
1371
  fail: fail$6,
1370
- info: info$e
1372
+ info: info$f
1371
1373
  } = log$1;
1372
1374
  const {
1373
- resolve: resolve$g,
1375
+ resolve: resolve$h,
1374
1376
  filterField: filterField$7
1375
1377
  } = widgets;
1376
1378
  const {
1377
- handleError: handleError$7
1379
+ handleError: handleError$8
1378
1380
  } = handleError_1;
1379
1381
  const {
1380
1382
  global: global$a
1381
1383
  } = global_1;
1382
- const report$8 = report_1;
1384
+ const report$9 = report_1;
1383
1385
 
1384
1386
  /**
1385
1387
  * 更新appJson里面的主包配置
@@ -1440,23 +1442,35 @@ const fixAppJson = appJson => {
1440
1442
  const {
1441
1443
  subpackages
1442
1444
  } = appJson;
1445
+ // 创建插件映射,用于检测插件配置冲突
1443
1446
  const pluginsMap = {};
1447
+ // 记录app.json顶层的插件配置
1444
1448
  Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
1449
+
1450
+ // 处理每个分包的配置
1445
1451
  const subps = subpackages.map(subp => {
1452
+ // 需要从分包提取到app.json顶层的数组类型字段
1446
1453
  const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList'];
1454
+ // 需要从分包提取到app.json顶层的对象类型字段
1447
1455
  const objOfFileType = ['preloadRule'];
1456
+
1457
+ // 遍历分包中的每个配置项
1448
1458
  Object.keys(subp).forEach(key => {
1459
+ // 处理插件配置,检查是否有重复配置的插件
1449
1460
  if (key === 'plugins') {
1450
1461
  Object.keys(subp.plugins).forEach(pk => {
1462
+ // 记录每个插件被哪些地方配置
1451
1463
  pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
1452
1464
  });
1453
1465
  }
1454
- // 分包里数组类型字段,提到appjson最上层
1466
+
1467
+ // 处理数组类型字段(如requiredBackgroundModes),合并到app.json顶层并去重
1455
1468
  if (arrOfFileType.indexOf(key) > -1) {
1456
1469
  const preVal = appJson[key];
1457
1470
  preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
1458
1471
  }
1459
- // 分包里对象类型字段,提到appjson最上层
1472
+
1473
+ // 处理对象类型字段(如preloadRule),合并到app.json顶层,已存在的键值不覆盖
1460
1474
  if (objOfFileType.indexOf(key) > -1) {
1461
1475
  const preloadRuleMap = appJson[key] || {};
1462
1476
  subp[key] && Object.keys(subp[key]).forEach(page => {
@@ -1467,9 +1481,12 @@ const fixAppJson = appJson => {
1467
1481
  appJson[key] = preloadRuleMap;
1468
1482
  }
1469
1483
  });
1484
+
1485
+ // 从分包配置中移除已提取到顶层的字段以及一些构建相关的内部字段
1470
1486
  return filterField$7(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1471
1487
  });
1472
- // 如果plugins重复,则错误提示
1488
+
1489
+ // 检查插件配置冲突,如果同一个插件在多处配置则报错
1473
1490
  const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
1474
1491
  if (pluginsMap[pk].length > 1) {
1475
1492
  return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
@@ -1479,9 +1496,44 @@ const fixAppJson = appJson => {
1479
1496
  if (pluginsErrMsg) {
1480
1497
  throw new Error(`plugins配置出现错误:${pluginsErrMsg}`);
1481
1498
  }
1499
+
1500
+ // 用处理后的分包配置更新app.json的subpackages字段
1482
1501
  appJson.subpackages = subps;
1483
1502
  };
1484
1503
 
1504
+ /**
1505
+ * 合并分包配置,保留已有分包,添加新分包
1506
+ * @param {Array} existingPackages 现有的分包配置
1507
+ * @param {Array} newPackages 新的分包配置
1508
+ * @returns {Array} 合并后的分包配置
1509
+ */
1510
+ function mergeSubPackages(existingPackages, newPackages) {
1511
+ // 创建结果数组和root到索引的映射
1512
+ const resultPackages = [...existingPackages];
1513
+ const rootMap = {};
1514
+
1515
+ // 建立现有分包的root映射
1516
+ existingPackages.forEach((pkg, index) => {
1517
+ if (pkg.root) {
1518
+ rootMap[pkg.root] = index;
1519
+ }
1520
+ });
1521
+
1522
+ // 合并新分包
1523
+ newPackages.forEach(newPkg => {
1524
+ if (!newPkg.root) return; // 忽略没有root的分包
1525
+
1526
+ if (rootMap[newPkg.root] !== undefined) {
1527
+ // 如果已存在相同root的分包,则不覆盖保留原有配置
1528
+ info$f(`保留已有分包配置, root: ${newPkg.root}, name: ${newPkg.name || '未命名'}`);
1529
+ } else {
1530
+ // 如果不存在,则添加新分包
1531
+ resultPackages.push(newPkg);
1532
+ }
1533
+ });
1534
+ return resultPackages;
1535
+ }
1536
+
1485
1537
  /**
1486
1538
  * 动态生成编译后的app.json
1487
1539
  * @param {object} tmsConfig
@@ -1494,13 +1546,14 @@ async function buildOutputAppJson$3(tmsConfig, modules) {
1494
1546
  // 获取所有模块,合并模块依赖的模块
1495
1547
  const modulesConfig = getModulesConfig(modules, tmsConfig, false);
1496
1548
  // 获取所有的分包
1497
- const subPackages = getSubPackages$3(modulesConfig);
1549
+ const newSubPackages = getSubPackages$3(modulesConfig);
1498
1550
  // 获取app.json的配置
1499
- let appJson = getAppJsonContent(resolve$g('./app.json'));
1551
+ let appJson = getAppJsonContent(resolve$h('./app.json'));
1500
1552
 
1501
- // 更新app.json中的subpackages
1502
- appJson.subpackages = subPackages;
1503
- appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
1553
+ // 保留已有分包配置,合并新的分包配置
1554
+ const existingSubpackages = appJson.subpackages || [];
1555
+ appJson.subpackages = mergeSubPackages(existingSubpackages, newSubPackages);
1556
+ appJson.subpackages.sort((item1, item2) => item1.root.localeCompare(item2.root));
1504
1557
 
1505
1558
  // 处理appJson中重复||冲突的地方
1506
1559
  fixAppJson(appJson);
@@ -1510,7 +1563,7 @@ async function buildOutputAppJson$3(tmsConfig, modules) {
1510
1563
  // 模板渲染:先将 app.json 转为字符串,然后通过 preprocess 渲染
1511
1564
  const appJsonStr = JSON.stringify(appJson, null, 2);
1512
1565
  const preprocessedStr = pp$1.preprocess(appJsonStr, tmsConfig.templateVars || {}, 'json');
1513
- fs$e.writeFileSync(resolve$g(`${tmsConfig.outputDir}/app.json`), preprocessedStr, 'utf8');
1566
+ fs$e.writeFileSync(resolve$h(`${tmsConfig.outputDir}/app.json`), preprocessedStr, 'utf8');
1514
1567
  appJson = JSON.parse(preprocessedStr);
1515
1568
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
1516
1569
  var _tmsConfig$hooks2;
@@ -1521,12 +1574,12 @@ async function buildOutputAppJson$3(tmsConfig, modules) {
1521
1574
  appJson,
1522
1575
  isDev: global$a.getData('isDev')
1523
1576
  }));
1524
- report$8('hooks:updateAppJson');
1577
+ report$9('hooks:updateAppJson');
1525
1578
  }
1526
1579
  return appJson;
1527
1580
  } catch (e) {
1528
- handleError$7(`生成app.json出现错误: ${e}`);
1529
- info$e(e);
1581
+ handleError$8(`生成app.json出现错误: ${e}`);
1582
+ info$f(e);
1530
1583
  }
1531
1584
  }
1532
1585
  var buildAppJson = {
@@ -1541,16 +1594,16 @@ const crypto$2 = require$$1__default$6;
1541
1594
  const {
1542
1595
  downloadRepoForGit,
1543
1596
  pullRepoForGit,
1544
- resolve: resolve$f
1597
+ resolve: resolve$g
1545
1598
  } = widgets;
1546
1599
  const {
1547
1600
  fail: fail$5,
1548
- info: info$d
1601
+ info: info$e
1549
1602
  } = log$1;
1550
1603
  const fs$d = require$$0__default$1;
1551
1604
  const shelljs$5 = require$$0__default$2;
1552
1605
  const {
1553
- handleError: handleError$6
1606
+ handleError: handleError$7
1554
1607
  } = handleError_1;
1555
1608
  const {
1556
1609
  global: global$9
@@ -1642,7 +1695,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1642
1695
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
1643
1696
  return Promise.all(callArr);
1644
1697
  }).catch(e => {
1645
- handleError$6(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1698
+ handleError$7(`下载代码${params.httpRepoUrl}出现错误:${e}`);
1646
1699
  }));
1647
1700
  });
1648
1701
  await Promise.all(arrPromises);
@@ -1686,9 +1739,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1686
1739
  // 根据gitUrl与branch计算md5
1687
1740
  const md5Key = md5ByGitUrlBranch(gitUrl, branch);
1688
1741
  // git源码临时存在的源目录
1689
- const sourcePath = resolve$f(sourceDir, md5Key);
1742
+ const sourcePath = resolve$g(sourceDir, md5Key);
1690
1743
  // 模块源码要放到目标目录
1691
- const targetPath = resolve$f(targetDir, path);
1744
+ const targetPath = resolve$g(targetDir, path);
1692
1745
  // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1693
1746
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath;
1694
1747
 
@@ -1713,15 +1766,15 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1713
1766
  let promiseTask;
1714
1767
  if (fs$d.existsSync(sourcePath) && fs$d.existsSync(`${sourcePath}/.git`)) {
1715
1768
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1716
- info$d(`git pull:${httpRepoUrl} --branch: ${branch}`);
1769
+ info$e(`git pull:${httpRepoUrl} --branch: ${branch}`);
1717
1770
  return pullRepoForGit(sourcePath, branch).catch(e => {
1718
- info$d(`pull代码失败:${e}, 开始git clone: ${httpRepoUrl}:${branch}`);
1771
+ info$e(`pull代码失败:${e}, 开始git clone: ${httpRepoUrl}:${branch}`);
1719
1772
  return downloadRepoForGit(gitUrl, sourcePath, branch);
1720
1773
  });
1721
1774
  };
1722
1775
  } else {
1723
1776
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1724
- info$d(`git clone: ${httpRepoUrl}`);
1777
+ info$e(`git clone: ${httpRepoUrl}`);
1725
1778
  return downloadRepoForGit(gitUrl, sourcePath, branch);
1726
1779
  };
1727
1780
  }
@@ -1895,10 +1948,30 @@ const uploadMp = async (params = {}) => {
1895
1948
  onProgressUpdate: () => {}
1896
1949
  });
1897
1950
  };
1898
- var mpCi$2 = {
1951
+ const getDevSourceMap = async (params = {}) => {
1952
+ const {
1953
+ appId,
1954
+ projectPath,
1955
+ privateKey,
1956
+ robot,
1957
+ sourceMapSavePath
1958
+ } = params;
1959
+ const project = await getMpCi({
1960
+ appId,
1961
+ projectPath,
1962
+ privateKey
1963
+ });
1964
+ return await ci.getDevSourceMap({
1965
+ project,
1966
+ robot,
1967
+ sourceMapSavePath
1968
+ });
1969
+ };
1970
+ var mpCi$3 = {
1899
1971
  buildMpNpm: buildMpNpm$1,
1900
1972
  previewMp,
1901
- uploadMp
1973
+ uploadMp,
1974
+ getDevSourceMap
1902
1975
  };
1903
1976
 
1904
1977
  const fs$c = require$$0__default$1;
@@ -1952,7 +2025,7 @@ const {
1952
2025
  npmInstall: npmInstall$2
1953
2026
  } = widgets;
1954
2027
  const {
1955
- handleError: handleError$5
2028
+ handleError: handleError$6
1956
2029
  } = handleError_1;
1957
2030
  const {
1958
2031
  global: global$8
@@ -2074,7 +2147,7 @@ const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
2074
2147
  }) => fn(...Object.keys(cParams).map(key => cParams[key])));
2075
2148
  return Promise.all(callArr);
2076
2149
  }).catch(e => {
2077
- handleError$5(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
2150
+ handleError$6(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
2078
2151
  }));
2079
2152
  });
2080
2153
  await Promise.all(arrPromises);
@@ -2175,13 +2248,13 @@ var md5 = {
2175
2248
  const fs$9 = require$$0__default$1;
2176
2249
  const semver$1 = require$$1__default$8;
2177
2250
  const {
2178
- resolve: resolve$e,
2251
+ resolve: resolve$f,
2179
2252
  getAbsolutePath: getAbsolutePath$5
2180
2253
  } = widgets;
2181
2254
  const path$9 = require$$1__default$1;
2182
2255
  const shelljs$4 = require$$0__default$2;
2183
2256
  const {
2184
- handleError: handleError$4
2257
+ handleError: handleError$5
2185
2258
  } = handleError_1;
2186
2259
  const getLatestVersion = npmName => {
2187
2260
  const data = shelljs$4.exec(`npm view ${npmName} version`);
@@ -2197,7 +2270,7 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2197
2270
  // 1.1根目录的package.json
2198
2271
  const packageArr = [{
2199
2272
  srcPackageDir: path$9.join(cwd, packageJsonName),
2200
- destNpmDir: resolve$e(outputDir, 'node_modules')
2273
+ destNpmDir: resolve$f(outputDir, 'node_modules')
2201
2274
  }];
2202
2275
  // 1.2模块的package.json
2203
2276
  subPackages.forEach(item => {
@@ -2205,7 +2278,7 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2205
2278
  if (fs$9.existsSync(srcPackageDir)) {
2206
2279
  packageArr.push({
2207
2280
  srcPackageDir,
2208
- destNpmDir: resolve$e(outputDir, item.root, 'node_modules')
2281
+ destNpmDir: resolve$f(outputDir, item.root, 'node_modules')
2209
2282
  });
2210
2283
  }
2211
2284
  });
@@ -2220,7 +2293,7 @@ function readPackageDependencies(srcPackageDir) {
2220
2293
  const json = packageJson ? JSON.parse(packageJson) : {};
2221
2294
  dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
2222
2295
  } catch (e) {
2223
- handleError$4(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2296
+ handleError$5(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
2224
2297
  }
2225
2298
  return dependencies;
2226
2299
  }
@@ -2276,14 +2349,14 @@ const fs$8 = require$$0__default$1;
2276
2349
  const path$8 = require$$1__default$1;
2277
2350
  const io$1 = io$3;
2278
2351
  const {
2279
- createTask: createTask$4,
2280
- resolve: resolve$d,
2352
+ createTask: createTask$5,
2353
+ resolve: resolve$e,
2281
2354
  getAbsolutePath: getAbsolutePath$4,
2282
2355
  filterField: filterField$6
2283
2356
  } = widgets;
2284
2357
  const {
2285
2358
  buildMpNpm
2286
- } = mpCi$2;
2359
+ } = mpCi$3;
2287
2360
  const {
2288
2361
  global: global$7
2289
2362
  } = global_1;
@@ -2298,7 +2371,7 @@ const {
2298
2371
  npmInstallAll
2299
2372
  } = npm;
2300
2373
  const {
2301
- info: info$c
2374
+ info: info$d
2302
2375
  } = log$1;
2303
2376
  const {
2304
2377
  fileMd5
@@ -2312,41 +2385,41 @@ async function install$3(tmsConfig, subPackages, useCache = true) {
2312
2385
  // 加npm install之前的钩子
2313
2386
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeNpmInstall) === 'function') {
2314
2387
  var _tmsConfig$hooks2;
2315
- info$c('—————— 执行beforeNpmInstall ————');
2388
+ info$d('—————— 执行beforeNpmInstall ————');
2316
2389
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeNpmInstall({
2317
2390
  tmsConfig: filterField$6(tmsConfig, ['gitAccount']),
2318
2391
  cmdOptions: global$7.getData('cmdOptions')
2319
2392
  }));
2320
- info$c('—————— 执行beforeNpmInstall 完成 ————');
2393
+ info$d('—————— 执行beforeNpmInstall 完成 ————');
2321
2394
  }
2322
- const npmInstallRes = await createTask$4(npmInstall$1, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache);
2395
+ const npmInstallRes = await createTask$5(npmInstall$1, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache);
2323
2396
 
2324
2397
  // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2325
2398
  if (!npmInstallRes.isCache) {
2326
2399
  // 构建miniprogram_npm, 不使用缓存
2327
- await createTask$4(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
2400
+ await createTask$5(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
2328
2401
  } else {
2329
2402
  // 构建miniprogram_npm
2330
- await createTask$4(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2403
+ await createTask$5(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2331
2404
  }
2332
2405
  shelljs$3.cd(cwd);
2333
2406
  }
2334
2407
  async function npmInstall$1(tmsConfig, subPackages, useCache) {
2335
2408
  // 如果依赖没有更新和使用缓存数据(则命中缓存)
2336
- if (!isDependenciesUpdate(subPackages, resolve$d('./'), tmsConfig.outputDir) && useCache) {
2337
- info$c('node_modules命中缓存');
2409
+ if (!isDependenciesUpdate(subPackages, resolve$e('./'), tmsConfig.outputDir) && useCache) {
2410
+ info$d('node_modules命中缓存');
2338
2411
  return {
2339
2412
  isCache: true
2340
2413
  };
2341
2414
  }
2342
2415
  // 拷贝模块的package.json到编译输出目录
2343
2416
  subPackages.forEach(item => {
2344
- const outputModuleDir = resolve$d(`${tmsConfig.outputDir}/${item.root}`);
2417
+ const outputModuleDir = resolve$e(`${tmsConfig.outputDir}/${item.root}`);
2345
2418
  io$1.ensureDirExist(outputModuleDir);
2346
2419
  const modulePackagePath = `${getAbsolutePath$4(item.path)}/package.json`;
2347
2420
  if (fs$8.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
2348
2421
  });
2349
- await npmInstallAll(subPackages, resolve$d(tmsConfig.outputDir), NODE_MODULES_DIR$1);
2422
+ await npmInstallAll(subPackages, resolve$e(tmsConfig.outputDir), NODE_MODULES_DIR$1);
2350
2423
  return {
2351
2424
  isCache: false
2352
2425
  };
@@ -2355,12 +2428,12 @@ async function npmInstall$1(tmsConfig, subPackages, useCache) {
2355
2428
  // 构建miniprogram_npm
2356
2429
  async function mpCiInstall(tmsConfig, subPackages, useCache) {
2357
2430
  const packageJsonFiles = [];
2358
- const rootPackFile = resolve$d(`${tmsConfig.outputDir}/package.json`);
2431
+ const rootPackFile = resolve$e(`${tmsConfig.outputDir}/package.json`);
2359
2432
  if (fs$8.existsSync(rootPackFile)) {
2360
2433
  packageJsonFiles.push(rootPackFile);
2361
2434
  }
2362
2435
  subPackages.forEach(item => {
2363
- const packageJsonFile = resolve$d(`${tmsConfig.outputDir}/${item.root}/package.json`);
2436
+ const packageJsonFile = resolve$e(`${tmsConfig.outputDir}/${item.root}/package.json`);
2364
2437
  if (fs$8.existsSync(packageJsonFile)) {
2365
2438
  packageJsonFiles.push(packageJsonFile);
2366
2439
  }
@@ -2374,7 +2447,7 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2374
2447
  let flag = true;
2375
2448
  await Promise.all(packageJsonFiles.map(async item => {
2376
2449
  const packageDir = path$8.dirname(item);
2377
- const mpDir = resolve$d(`${packageDir}/miniprogram_npm`);
2450
+ const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
2378
2451
  const md5Value = await getMNPMd5(packageDir);
2379
2452
  const preCache = getCache(mpDir, 'miniprogram_npm');
2380
2453
  // console.log('miniprogram_npm', preCache, md5Value);
@@ -2386,14 +2459,14 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2386
2459
  isCache = flag;
2387
2460
  }
2388
2461
  if (isCache) {
2389
- info$c('miniprogram_npm命中缓存');
2462
+ info$d('miniprogram_npm命中缓存');
2390
2463
  return;
2391
2464
  }
2392
2465
 
2393
2466
  // 即将构建,在cache中标记开始
2394
2467
  await Promise.all(packageJsonFiles.map(async item => {
2395
2468
  const packageDir = path$8.dirname(item);
2396
- const mpDir = resolve$d(`${packageDir}/miniprogram_npm`);
2469
+ const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
2397
2470
  setCache(mpDir, 'miniprogram_npm', {
2398
2471
  md5: '',
2399
2472
  status: statusMap.doing
@@ -2401,14 +2474,14 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2401
2474
  }));
2402
2475
  await buildMpNpm({
2403
2476
  appId: tmsConfig.appId,
2404
- projectPath: resolve$d('./'),
2477
+ projectPath: resolve$e('./'),
2405
2478
  privateKey: tmsConfig.privateKey
2406
2479
  });
2407
2480
 
2408
2481
  // 构建成功后,计算md5写入cache
2409
2482
  await Promise.all(packageJsonFiles.map(async item => {
2410
2483
  const packageDir = path$8.dirname(item);
2411
- const mpDir = resolve$d(`${packageDir}/miniprogram_npm`);
2484
+ const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
2412
2485
  const md5Value = await getMNPMd5(packageDir);
2413
2486
  setCache(mpDir, 'miniprogram_npm', {
2414
2487
  md5: md5Value,
@@ -2442,8 +2515,8 @@ const shelljs$2 = require$$0__default$2;
2442
2515
  const fs$7 = require$$0__default$1;
2443
2516
  const io = io$3;
2444
2517
  const {
2445
- resolve: resolve$c,
2446
- createTask: createTask$3
2518
+ resolve: resolve$d,
2519
+ createTask: createTask$4
2447
2520
  } = widgets;
2448
2521
  const {
2449
2522
  buildOutputAppJson: buildOutputAppJson$2
@@ -2461,7 +2534,7 @@ const {
2461
2534
  } = tmsMpconfig.exports;
2462
2535
  const {
2463
2536
  fail: fail$4,
2464
- info: info$b
2537
+ info: info$c
2465
2538
  } = log$1;
2466
2539
  const install$2 = install_1;
2467
2540
 
@@ -2473,17 +2546,17 @@ const install$2 = install_1;
2473
2546
  * @returns
2474
2547
  */
2475
2548
  const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2476
- const outputDir = resolve$c(tmsConfig.outputDir);
2549
+ const outputDir = resolve$d(tmsConfig.outputDir);
2477
2550
  io.ensureDirExist(outputDir);
2478
2551
  defaultFiles.forEach(item => {
2479
- if (fs$7.existsSync(resolve$c(item))) {
2480
- shelljs$2.cp('-rf', resolve$c(item), resolve$c(tmsConfig.outputDir, item));
2552
+ if (fs$7.existsSync(resolve$d(item))) {
2553
+ shelljs$2.cp('-rf', resolve$d(item), resolve$d(tmsConfig.outputDir, item));
2481
2554
  }
2482
2555
  });
2483
2556
  };
2484
2557
  async function task(tmsConfig, targetModules) {
2485
2558
  // 下载和移动代码
2486
- await createTask$3(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$c('./'), targetModules);
2559
+ await createTask$4(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$d('./'), targetModules);
2487
2560
 
2488
2561
  // 获取所有模块,合并模块依赖的模块
2489
2562
  const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true);
@@ -2491,13 +2564,13 @@ async function task(tmsConfig, targetModules) {
2491
2564
  const newSubPackages = getSubPackages$2(newModules);
2492
2565
 
2493
2566
  // 拷贝相关配置文件到输出目录
2494
- await createTask$3(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1);
2567
+ await createTask$4(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1);
2495
2568
 
2496
2569
  // install
2497
2570
  await install$2(tmsConfig, newSubPackages, true);
2498
2571
 
2499
2572
  // 动态生成编译后的app.json;
2500
- await createTask$3(buildOutputAppJson$2, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2573
+ await createTask$4(buildOutputAppJson$2, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
2501
2574
  return {
2502
2575
  modules: newModules,
2503
2576
  subPackages: newSubPackages
@@ -2510,7 +2583,7 @@ async function init$3(tmsConfig, targetModules) {
2510
2583
  } catch (error) {
2511
2584
  const errMsg = typeof error === 'object' ? error.message : error;
2512
2585
  fail$4(`初始化流程出现错误: ${errMsg}`);
2513
- info$b('详细的错误信息', error);
2586
+ info$c('详细的错误信息', error);
2514
2587
  process.exit(1);
2515
2588
  }
2516
2589
  }
@@ -2636,15 +2709,15 @@ const minimatch = require$$2__default;
2636
2709
  const gulpif = require$$3__default$1;
2637
2710
  const mpProjectJson = mpProjectJson_1;
2638
2711
  const {
2639
- resolve: resolve$b
2712
+ resolve: resolve$c
2640
2713
  } = widgets;
2641
2714
  const through = require$$0__default$8;
2642
2715
  const {
2643
2716
  fail: fail$3
2644
2717
  } = log$1;
2645
2718
  const getTargetFile$2 = (sourceFile, module, outputDir) => {
2646
- const sourceFileRelativeModule = path$6.relative(resolve$b(module.from), sourceFile);
2647
- const targetFile = resolve$b(outputDir, module.to, sourceFileRelativeModule);
2719
+ const sourceFileRelativeModule = path$6.relative(resolve$c(module.from), sourceFile);
2720
+ const targetFile = resolve$c(outputDir, module.to, sourceFileRelativeModule);
2648
2721
  return targetFile;
2649
2722
  };
2650
2723
  const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
@@ -2854,12 +2927,12 @@ const {
2854
2927
  series: series$2
2855
2928
  } = require$$0__default$9;
2856
2929
  const {
2857
- info: info$a,
2930
+ info: info$b,
2858
2931
  warn: warn$1,
2859
2932
  fail: fail$2
2860
2933
  } = log$1;
2861
2934
  const {
2862
- resolve: resolve$a,
2935
+ resolve: resolve$b,
2863
2936
  filterField: filterField$5
2864
2937
  } = widgets;
2865
2938
  const {
@@ -2868,7 +2941,7 @@ const {
2868
2941
  const {
2869
2942
  checkPackageVersion
2870
2943
  } = checkDependencies;
2871
- const report$7 = report_1;
2944
+ const report$8 = report_1;
2872
2945
  const TIP_MAP = {
2873
2946
  'package.json': {
2874
2947
  tip: '依赖版本有变动,请重新执行tmskit run dev',
@@ -2895,14 +2968,14 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
2895
2968
  return;
2896
2969
  }
2897
2970
  }
2898
- info$a(`${fileName}有更新`);
2971
+ info$b(`${fileName}有更新`);
2899
2972
  } catch (e) {
2900
2973
  fail$2(`${sourceFile}文件更新提示出现错误: ${e.message}`);
2901
2974
  }
2902
2975
  };
2903
2976
  const getTargetFile$1 = (sourceFile, module, outputDir) => {
2904
- const sourceFileRelativeModule = path$4.relative(resolve$a(module.from), sourceFile);
2905
- return resolve$a(outputDir, module.to, sourceFileRelativeModule);
2977
+ const sourceFileRelativeModule = path$4.relative(resolve$b(module.from), sourceFile);
2978
+ return resolve$b(outputDir, module.to, sourceFileRelativeModule);
2906
2979
  };
2907
2980
  var watch_1 = function (globValue, watchOptions, callback, module) {
2908
2981
  watch$2(globValue, {
@@ -2919,7 +2992,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
2919
2992
  targetFile = path$4.join(module.to, filePath);
2920
2993
  }
2921
2994
  if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
2922
- info$a(`删除${sourceFileName}`);
2995
+ info$b(`删除${sourceFileName}`);
2923
2996
  shellJs$2.rm('-rf', targetFile);
2924
2997
  updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
2925
2998
  return;
@@ -2968,7 +3041,7 @@ async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
2968
3041
  targetFile,
2969
3042
  type
2970
3043
  });
2971
- report$7('hooks:updateFile');
3044
+ report$8('hooks:updateFile');
2972
3045
  }
2973
3046
  }
2974
3047
 
@@ -2981,7 +3054,7 @@ const {
2981
3054
  series: series$1
2982
3055
  } = require$$0__default$9;
2983
3056
  const {
2984
- resolve: resolve$9,
3057
+ resolve: resolve$a,
2985
3058
  mergeMap,
2986
3059
  filterField: filterField$4,
2987
3060
  getAbsolutePath: getAbsolutePath$3
@@ -2995,9 +3068,9 @@ const {
2995
3068
  const compile = compile$1;
2996
3069
  const watch$1 = watch_1;
2997
3070
  const {
2998
- info: info$9
3071
+ info: info$a
2999
3072
  } = log$1;
3000
- const report$6 = report_1;
3073
+ const report$7 = report_1;
3001
3074
  const {
3002
3075
  global: global$5
3003
3076
  } = global_1;
@@ -3007,12 +3080,12 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3007
3080
 
3008
3081
  // 监听根目录的文件
3009
3082
  mergeMap(compileTasksMap, compile(tmsConfig, {
3010
- glob: DEFAULT_COPY_CONFIG.map(item => resolve$9(item)),
3083
+ glob: DEFAULT_COPY_CONFIG.map(item => resolve$a(item)),
3011
3084
  module: {
3012
- from: resolve$9(),
3013
- to: resolve$9(tmsConfig.outputDir)
3085
+ from: resolve$a(),
3086
+ to: resolve$a(tmsConfig.outputDir)
3014
3087
  },
3015
- destPath: resolve$9(tmsConfig.outputDir),
3088
+ destPath: resolve$a(tmsConfig.outputDir),
3016
3089
  srcOption: {
3017
3090
  allowEmpty: true
3018
3091
  },
@@ -3048,7 +3121,7 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3048
3121
  ...moduleItem
3049
3122
  };
3050
3123
  const srcModulePath = getAbsolutePath$3(moduleItem.path);
3051
- const buildModulePath = resolve$9(tmsConfig.outputDir, moduleItem.modulePath);
3124
+ const buildModulePath = resolve$a(tmsConfig.outputDir, moduleItem.modulePath);
3052
3125
  if (isDev) {
3053
3126
  // 监听模块配置文件
3054
3127
  watch$1([`${srcModulePath}/**/module.config.json`], {
@@ -3062,9 +3135,9 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3062
3135
  const newPath = getAbsolutePath$3(ePath, srcModulePath);
3063
3136
  const ext = path$3.extname(ePath).slice(1);
3064
3137
  if (ext) {
3065
- return `!${resolve$9(srcModulePath, newPath)}`;
3138
+ return `!${resolve$a(srcModulePath, newPath)}`;
3066
3139
  }
3067
- return `!${resolve$9(srcModulePath, newPath)}/**/*`;
3140
+ return `!${resolve$a(srcModulePath, newPath)}/**/*`;
3068
3141
  });
3069
3142
  const moduleConfigPath = `${srcModulePath}/**/module.config.json`;
3070
3143
  const moduleConfigGlob = tmsConfig.isKeepModuleConfig ? `${moduleConfigPath}` : `!${moduleConfigPath}`;
@@ -3113,7 +3186,7 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3113
3186
  let eTime;
3114
3187
  const spinner = ora$1();
3115
3188
  function start(cb) {
3116
- info$9('启动编译...');
3189
+ info$a('启动编译...');
3117
3190
  spinner.start();
3118
3191
  sTime = new Date().getTime();
3119
3192
  cb();
@@ -3122,12 +3195,12 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3122
3195
  var _tmsConfig$hooks;
3123
3196
  if (isDev) {
3124
3197
  // 监听app.json
3125
- watch$1([resolve$9('app.json')], {
3198
+ watch$1([resolve$a('app.json')], {
3126
3199
  ignoreInitial: false,
3127
3200
  events: watchEvents
3128
3201
  }, async () => await buildOutputAppJson$1(tmsConfig, modules, isDev), {
3129
- from: resolve$9(),
3130
- to: resolve$9(tmsConfig.outputDir)
3202
+ from: resolve$a(),
3203
+ to: resolve$a(tmsConfig.outputDir)
3131
3204
  });
3132
3205
  // 监听其他文件
3133
3206
  compileTasksMap.forEach(({
@@ -3151,7 +3224,7 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3151
3224
  modules,
3152
3225
  cmdOptions: global$5.getData('cmdOptions')
3153
3226
  }));
3154
- report$6('hooks:afterCompile');
3227
+ report$7('hooks:afterCompile');
3155
3228
  }
3156
3229
  spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
3157
3230
  spinner.stop();
@@ -3170,7 +3243,7 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3170
3243
  const shelljs$1 = require$$0__default$2;
3171
3244
  const compileDev = dev$4;
3172
3245
  const {
3173
- resolve: resolve$8,
3246
+ resolve: resolve$9,
3174
3247
  filterField: filterField$3
3175
3248
  } = widgets;
3176
3249
  const init$2 = init_1;
@@ -3182,7 +3255,7 @@ const {
3182
3255
  getSubPackages: getSubPackages$1
3183
3256
  } = tmsMpconfig.exports;
3184
3257
  const {
3185
- info: info$8
3258
+ info: info$9
3186
3259
  } = log$1;
3187
3260
  const {
3188
3261
  global: global$4
@@ -3191,7 +3264,7 @@ const {
3191
3264
  MODULE_CODE_DIR,
3192
3265
  NODE_MODULES_DIR
3193
3266
  } = constant;
3194
- const report$5 = report_1;
3267
+ const report$6 = report_1;
3195
3268
  // const { recommendVersion } = require('../../../core/recommendVersion');
3196
3269
 
3197
3270
  // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
@@ -3203,7 +3276,7 @@ function delOtherPackages(tmsConfig, targetSubPackages) {
3203
3276
  const targetSubPackagesName = targetSubPackages.map(item => item.name);
3204
3277
  allSubPackages.forEach(item => {
3205
3278
  if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
3206
- const moduleRootDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
3279
+ const moduleRootDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
3207
3280
  shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
3208
3281
  silent: true
3209
3282
  });
@@ -3218,7 +3291,9 @@ async function dev$3(tmsConfig, targetModules) {
3218
3291
  noCache
3219
3292
  } = global$4.getData('cmdOptions');
3220
3293
  if (noCache) {
3221
- shelljs$1.rm('-rf', resolve$8(tmsConfig.outputDir));
3294
+ if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
3295
+ shelljs$1.rm('-rf', resolve$9(tmsConfig.outputDir));
3296
+ }
3222
3297
  shelljs$1.rm('-rf', MODULE_CODE_DIR);
3223
3298
  shelljs$1.rm('-rf', NODE_MODULES_DIR);
3224
3299
  }
@@ -3233,7 +3308,7 @@ async function dev$3(tmsConfig, targetModules) {
3233
3308
 
3234
3309
  // 在启动开发环境前主动执行生成 app.json
3235
3310
  await buildOutputAppJson(tmsConfig, newModules);
3236
- info$8('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3311
+ info$9('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3237
3312
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
3238
3313
  var _tmsConfig$hooks2;
3239
3314
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
@@ -3242,7 +3317,7 @@ async function dev$3(tmsConfig, targetModules) {
3242
3317
  modules: newModules,
3243
3318
  cmdOptions: global$4.getData('cmdOptions')
3244
3319
  }));
3245
- report$5('hooks:beforeCompile');
3320
+ report$6('hooks:beforeCompile');
3246
3321
  }
3247
3322
  delOtherPackages(tmsConfig, subPackages);
3248
3323
  compileDev(tmsConfig, newModules, true);
@@ -3256,26 +3331,28 @@ var build$2 = async (tmsConfig, newModules, isDev) => {
3256
3331
 
3257
3332
  const shelljs = require$$0__default$2;
3258
3333
  const {
3259
- resolve: resolve$7,
3334
+ resolve: resolve$8,
3260
3335
  filterField: filterField$2
3261
3336
  } = widgets;
3262
3337
  const init$1 = init_1;
3263
3338
  const {
3264
- info: info$7
3339
+ info: info$8
3265
3340
  } = log$1;
3266
3341
  const compileBuild = build$2;
3267
- const report$4 = report_1;
3342
+ const report$5 = report_1;
3268
3343
  const {
3269
3344
  global: global$3
3270
3345
  } = global_1;
3271
3346
  async function build$1(tmsConfig, targetModules) {
3272
3347
  var _tmsConfig$hooks;
3273
3348
  // 开始构建前,清理输出目录
3274
- await shelljs.rm('-rf', resolve$7(tmsConfig.outputDir));
3349
+ if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
3350
+ await shelljs.rm('-rf', resolve$8(tmsConfig.outputDir));
3351
+ }
3275
3352
  const {
3276
3353
  modules: newModules
3277
3354
  } = await init$1(tmsConfig, targetModules);
3278
- info$7('当前build有效模块', newModules.map(item => item.moduleName).sort());
3355
+ info$8('当前build有效模块', newModules.map(item => item.moduleName).sort());
3279
3356
  const isDev = false;
3280
3357
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
3281
3358
  var _tmsConfig$hooks2;
@@ -3285,7 +3362,7 @@ async function build$1(tmsConfig, targetModules) {
3285
3362
  modules: newModules,
3286
3363
  cmdOptions: global$3.getData('cmdOptions')
3287
3364
  }));
3288
- report$4('hooks:beforeCompile');
3365
+ report$5('hooks:beforeCompile');
3289
3366
  }
3290
3367
  compileBuild(tmsConfig, newModules, isDev);
3291
3368
  }
@@ -3311,7 +3388,7 @@ function getAllSize$2(data = {}) {
3311
3388
  }
3312
3389
  return allSize;
3313
3390
  }
3314
- const getDesc$2 = (desc = '') => {
3391
+ const getDesc$3 = (desc = '') => {
3315
3392
  const user = getGitUser();
3316
3393
  const date = moment().format('YYYY-MM-DD HH:mm:ss');
3317
3394
  return `构建描述:${desc}; 构建人: ${user}; 构建时间:${date}`;
@@ -3329,24 +3406,24 @@ const getDetaultVersion = () => {
3329
3406
  };
3330
3407
  var utils = {
3331
3408
  getAllSize: getAllSize$2,
3332
- getDesc: getDesc$2,
3409
+ getDesc: getDesc$3,
3333
3410
  outputInfo: outputInfo$2,
3334
3411
  getDetaultVersion
3335
3412
  };
3336
3413
 
3337
- const mpCi$1 = mpCi$2;
3414
+ const mpCi$2 = mpCi$3;
3338
3415
  const fs$4 = require$$0__default$1;
3339
3416
  const {
3340
- resolve: resolve$6,
3341
- createTask: createTask$2,
3417
+ resolve: resolve$7,
3418
+ createTask: createTask$3,
3342
3419
  getAbsolutePath: getAbsolutePath$1,
3343
3420
  filterField: filterField$1
3344
3421
  } = widgets;
3345
3422
  const {
3346
- handleError: handleError$3
3423
+ handleError: handleError$4
3347
3424
  } = handleError_1;
3348
3425
  const {
3349
- info: info$6
3426
+ info: info$7
3350
3427
  } = log$1;
3351
3428
  const {
3352
3429
  global: global$2
@@ -3354,10 +3431,10 @@ const {
3354
3431
  const {
3355
3432
  getAllSize: getAllSize$1,
3356
3433
  outputInfo: outputInfo$1,
3357
- getDesc: getDesc$1
3434
+ getDesc: getDesc$2
3358
3435
  } = utils;
3359
- const report$3 = report_1;
3360
- const handleParams$1 = (tmsConfig, cmdOptions) => {
3436
+ const report$4 = report_1;
3437
+ const handleParams$2 = (tmsConfig, cmdOptions) => {
3361
3438
  const params = {
3362
3439
  ...(tmsConfig.preview ? tmsConfig.preview : {}),
3363
3440
  ...cmdOptions
@@ -3365,10 +3442,10 @@ const handleParams$1 = (tmsConfig, cmdOptions) => {
3365
3442
  return {
3366
3443
  ...params,
3367
3444
  appId: params.appId || tmsConfig.appId,
3368
- projectPath: resolve$6(tmsConfig.outputDir),
3445
+ projectPath: resolve$7(tmsConfig.outputDir),
3369
3446
  privateKey: params.privateKey || tmsConfig.privateKey,
3370
3447
  robot: params.robot || 30,
3371
- desc: params.desc || getDesc$1(params.desc),
3448
+ desc: params.desc || getDesc$2(params.desc),
3372
3449
  qrcodeOutputDest: getAbsolutePath$1(params.qrcodeOutputDest || '')
3373
3450
  };
3374
3451
  };
@@ -3381,7 +3458,7 @@ const handleParams$1 = (tmsConfig, cmdOptions) => {
3381
3458
  async function preview$1(tmsConfig, cmdOptions) {
3382
3459
  try {
3383
3460
  var _tmsConfig$hooks;
3384
- const params = handleParams$1(tmsConfig, cmdOptions);
3461
+ const params = handleParams$2(tmsConfig, cmdOptions);
3385
3462
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforePreview) === 'function') {
3386
3463
  var _tmsConfig$hooks2;
3387
3464
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforePreview({
@@ -3389,10 +3466,10 @@ async function preview$1(tmsConfig, cmdOptions) {
3389
3466
  cmdOptions: global$2.getData('cmdOptions'),
3390
3467
  params
3391
3468
  }));
3392
- report$3('hooks:beforePreview');
3469
+ report$4('hooks:beforePreview');
3393
3470
  }
3394
3471
  ;
3395
- const previewRes = await createTask$2(mpCi$1.previewMp, '正在构建预览码', '构建预览码完成')({
3472
+ const previewRes = await createTask$3(mpCi$2.previewMp, '正在构建预览码', '构建预览码完成')({
3396
3473
  ...params
3397
3474
  });
3398
3475
  const allSize = getAllSize$1(previewRes);
@@ -3407,25 +3484,25 @@ async function preview$1(tmsConfig, cmdOptions) {
3407
3484
  ...previewRes
3408
3485
  });
3409
3486
  }
3410
- info$6('预览包大小:', `${allSize}k`);
3487
+ info$7('预览包大小:', `${allSize}k`);
3411
3488
  } catch (e) {
3412
3489
  console.log('详细错误:', e);
3413
- handleError$3(`预览错误: ${e.message}`, true);
3490
+ handleError$4(`预览错误: ${e.message}`, true);
3414
3491
  }
3415
3492
  }
3416
3493
  var preview_1 = preview$1;
3417
3494
 
3418
- const mpCi = mpCi$2;
3495
+ const mpCi$1 = mpCi$3;
3419
3496
  const {
3420
- resolve: resolve$5,
3421
- createTask: createTask$1,
3497
+ resolve: resolve$6,
3498
+ createTask: createTask$2,
3422
3499
  filterField
3423
3500
  } = widgets;
3424
3501
  const {
3425
- handleError: handleError$2
3502
+ handleError: handleError$3
3426
3503
  } = handleError_1;
3427
3504
  const {
3428
- info: info$5
3505
+ info: info$6
3429
3506
  } = log$1;
3430
3507
  const {
3431
3508
  global: global$1
@@ -3433,10 +3510,10 @@ const {
3433
3510
  const {
3434
3511
  getAllSize,
3435
3512
  outputInfo,
3436
- getDesc
3513
+ getDesc: getDesc$1
3437
3514
  } = utils;
3438
- const report$2 = report_1;
3439
- const handleParams = (tmsConfig, cmdOptions) => {
3515
+ const report$3 = report_1;
3516
+ const handleParams$1 = (tmsConfig, cmdOptions) => {
3440
3517
  const params = {
3441
3518
  ...(tmsConfig.upload ? tmsConfig.upload : {}),
3442
3519
  ...cmdOptions
@@ -3447,10 +3524,10 @@ const handleParams = (tmsConfig, cmdOptions) => {
3447
3524
  return {
3448
3525
  ...params,
3449
3526
  appId: params.appId || tmsConfig.appId,
3450
- projectPath: resolve$5(tmsConfig.outputDir),
3527
+ projectPath: resolve$6(tmsConfig.outputDir),
3451
3528
  privateKey: params.privateKey || tmsConfig.privateKey,
3452
3529
  robot: params.robot || 30,
3453
- desc: params.desc || getDesc(params.desc)
3530
+ desc: params.desc || getDesc$1(params.desc)
3454
3531
  };
3455
3532
  };
3456
3533
 
@@ -3462,7 +3539,7 @@ const handleParams = (tmsConfig, cmdOptions) => {
3462
3539
  async function upload$1(tmsConfig, cmdOptions) {
3463
3540
  try {
3464
3541
  var _tmsConfig$hooks;
3465
- const params = handleParams(tmsConfig, cmdOptions);
3542
+ const params = handleParams$1(tmsConfig, cmdOptions);
3466
3543
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeUpload) === 'function') {
3467
3544
  var _tmsConfig$hooks2;
3468
3545
  await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeUpload({
@@ -3470,10 +3547,10 @@ async function upload$1(tmsConfig, cmdOptions) {
3470
3547
  cmdOptions: global$1.getData('cmdOptions'),
3471
3548
  params
3472
3549
  }));
3473
- report$2('hooks:beforeUpload');
3550
+ report$3('hooks:beforeUpload');
3474
3551
  }
3475
3552
  ;
3476
- const uploadRes = await createTask$1(mpCi.uploadMp, '正在上传小程序代码', '上传小程序代码完成')({
3553
+ const uploadRes = await createTask$2(mpCi$1.uploadMp, '正在上传小程序代码', '上传小程序代码完成')({
3477
3554
  ...params
3478
3555
  });
3479
3556
  const allSize = getAllSize(uploadRes);
@@ -3483,14 +3560,65 @@ async function upload$1(tmsConfig, cmdOptions) {
3483
3560
  ...uploadRes
3484
3561
  });
3485
3562
  }
3486
- info$5(`上传包大小: ${allSize}k; 上传包版本: ${params.version}`);
3563
+ info$6(`上传包大小: ${allSize}k; 上传包版本: ${params.version}`);
3487
3564
  } catch (e) {
3488
3565
  console.log('详细错误:', e);
3489
- handleError$2(`上传错误: ${e.message}`, true);
3566
+ handleError$3(`上传错误: ${e.message}`, true);
3490
3567
  }
3491
3568
  }
3492
3569
  var upload_1 = upload$1;
3493
3570
 
3571
+ const mpCi = mpCi$3;
3572
+ const {
3573
+ resolve: resolve$5,
3574
+ createTask: createTask$1
3575
+ } = widgets;
3576
+ const {
3577
+ handleError: handleError$2
3578
+ } = handleError_1;
3579
+ const {
3580
+ info: info$5
3581
+ } = log$1;
3582
+ const {
3583
+ getDesc
3584
+ } = utils;
3585
+ const report$2 = report_1;
3586
+ const handleParams = (tmsConfig, cmdOptions) => {
3587
+ const params = {
3588
+ ...(tmsConfig.upload ? tmsConfig.upload : {}),
3589
+ ...cmdOptions
3590
+ };
3591
+ return {
3592
+ sourceMapSavePath: './sourcemap.zip',
3593
+ ...params,
3594
+ appId: params.appId || tmsConfig.appId,
3595
+ projectPath: resolve$5(tmsConfig.outputDir),
3596
+ privateKey: params.privateKey || tmsConfig.privateKey,
3597
+ robot: params.robot || 30,
3598
+ desc: params.desc || getDesc(params.desc)
3599
+ };
3600
+ };
3601
+
3602
+ /**
3603
+ * 获取sourcemap
3604
+ * @param {object} tmsConfig
3605
+ * @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
3606
+ */
3607
+ async function sourcemap$1(tmsConfig, cmdOptions) {
3608
+ try {
3609
+ const params = handleParams(tmsConfig, cmdOptions);
3610
+ report$2('sourcemap');
3611
+ await createTask$1(mpCi.getDevSourceMap, '正在获取小程序代码sourcemap', '获取小程序代码sourcemap完成')({
3612
+ ...params
3613
+ });
3614
+ info$5(`sourcemap文件已保存到${params.sourceMapSavePath}`);
3615
+ } catch (e) {
3616
+ console.log('详细错误:', e);
3617
+ handleError$2(`获取sourcemap错误: ${e.message}`, true);
3618
+ }
3619
+ }
3620
+ var sourcemap_1 = sourcemap$1;
3621
+
3494
3622
  const {
3495
3623
  resolve: resolve$4,
3496
3624
  getAbsolutePath
@@ -3824,6 +3952,7 @@ const build = build_1;
3824
3952
  const install = install_1;
3825
3953
  const preview = preview_1;
3826
3954
  const upload = upload_1;
3955
+ const sourcemap = sourcemap_1;
3827
3956
  const cloudLink = link;
3828
3957
  const cloudDev = dev$1;
3829
3958
  const {
@@ -3961,6 +4090,12 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
3961
4090
  appName: tmsConfig.appName
3962
4091
  });
3963
4092
  return;
4093
+ case 'sourcemap':
4094
+ sourcemap(tmsConfig);
4095
+ report$1('run:sourcemap', {
4096
+ appName: tmsConfig.appName
4097
+ });
4098
+ return;
3964
4099
  default:
3965
4100
  return;
3966
4101
  }
@@ -4020,6 +4155,13 @@ var entry = [{
4020
4155
  action: cmdOptions => {
4021
4156
  run_1('upload', cmdOptions);
4022
4157
  }
4158
+ }, {
4159
+ command: 'sourcemap',
4160
+ description: '获取sourcemap',
4161
+ options: [],
4162
+ action: cmdOptions => {
4163
+ run_1('sourcemap', cmdOptions);
4164
+ }
4023
4165
  }, {
4024
4166
  command: 'cloud-dev',
4025
4167
  description: '云函数开发',
@@ -4043,7 +4185,7 @@ var entry = [{
4043
4185
 
4044
4186
  var require$$12 = {
4045
4187
  name: "@tmsfe/tmskit",
4046
- version: "0.0.41",
4188
+ version: "0.0.43",
4047
4189
  description: "tmskit",
4048
4190
  main: "dist/index.cjs",
4049
4191
  bin: {
@@ -4102,7 +4244,7 @@ var require$$12 = {
4102
4244
  lodash: "^4.17.21",
4103
4245
  metalsmith: "^2.3.0",
4104
4246
  minimatch: "^5.1.0",
4105
- "miniprogram-ci": "1.8.25",
4247
+ "miniprogram-ci": "2.1.14",
4106
4248
  moment: "^2.29.2",
4107
4249
  "object-assign": "^4.0.1",
4108
4250
  ora: "^5.4.1",