ttmg-pack 0.3.5 → 0.3.7

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.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * ==========================================
3
3
  * @Description: ttmg pack
4
- * @Version: 0.3.5
4
+ * @Version: 0.3.7
5
5
  * @Author: zhanghongyang.mocha
6
- * @Date: 2026-02-11 17:10:39
6
+ * @Date: 2026-02-28 17:14:10
7
7
  * ==========================================
8
8
  */
9
9
  'use strict';
@@ -390,18 +390,22 @@ function getIndependentPackagesConfig(entryDir) {
390
390
  }
391
391
 
392
392
  function getMainPkgSize({ entryDir }) {
393
+ // 先获取分包根目录,这样如果有 subPackages 配置错误,会在这里抛出
394
+ const subpackagesRoots = getSubpackagesRoots(entryDir);
393
395
  return getDirSizeSync({
394
396
  rootDir: entryDir,
395
397
  entryDir,
396
- filterDirs: [...getSubpackagesRoots(entryDir), ...USELESS_DIRS],
398
+ filterDirs: [...subpackagesRoots, ...USELESS_DIRS],
397
399
  });
398
400
  }
399
401
  function getSubpackagesRoots(entryDir) {
400
- var _a;
402
+ var _a, _b;
401
403
  const originConfigPath = path.join(entryDir, GAME_ORIGIN_CONFIG_FILE_NAME);
402
404
  try {
403
405
  const originConfig = JSON.parse(fs.readFileSync(originConfigPath, 'utf8'));
406
+ // 优先使用小写的 subpackages,如果没有,再使用小驼峰的 subPackages
404
407
  const roots = ((_a = originConfig.subpackages) === null || _a === void 0 ? void 0 : _a.map((item) => item.root)) ||
408
+ ((_b = originConfig.subPackages) === null || _b === void 0 ? void 0 : _b.map((item) => item.root)) ||
405
409
  [];
406
410
  /**
407
411
  * 移除掉头和尾的 /
@@ -629,40 +633,6 @@ function getCheckConfig(config) {
629
633
  }
630
634
  }
631
635
 
632
- function copyDirectory(src, dest) {
633
- try {
634
- if (!fs.existsSync(dest)) {
635
- fs.mkdirSync(dest, { recursive: true });
636
- }
637
- const items = fs.readdirSync(src);
638
- const normalizedDest = path.resolve(dest) + path.sep;
639
- items.forEach(item => {
640
- const srcPath = path.join(src, item);
641
- const destPath = path.join(dest, item);
642
- // 检查当前要处理的源路径是否就是目标路径
643
- // 这可以防止将目标目录本身复制到自身中
644
- if (path.resolve(srcPath) === path.resolve(dest)) {
645
- return; // 跳过目标目录本身
646
- }
647
- // 获取文件状态
648
- const stat = fs.statSync(srcPath);
649
- if (stat.isFile()) {
650
- // 复制文件
651
- fs.copyFileSync(srcPath, destPath);
652
- }
653
- else if (stat.isDirectory()) {
654
- const childNormalizedSrc = path.resolve(srcPath) + path.sep;
655
- if (!normalizedDest.startsWith(childNormalizedSrc)) {
656
- copyDirectory(srcPath, destPath);
657
- }
658
- }
659
- });
660
- }
661
- catch (error) {
662
- logger.error(`copyDirectory error: ${error}`);
663
- }
664
- }
665
-
666
636
  /**
667
637
  * 将 packageConfig packages 中 分拆的包 配置迁移到 odr_packages 中
668
638
  */
@@ -918,40 +888,50 @@ const defaultCheckConfig$3 = {
918
888
  name: 'project',
919
889
  dimension: CHECK_DIMENSION.Project,
920
890
  };
921
- function checkProject(entryDir, config) {
891
+ function checkProject(config) {
922
892
  logger.info('start check project');
923
- const checkSizeResult = checkProjectSize(entryDir, config);
924
- const gameJsonCheckResult = checkGameJson(entryDir, config);
925
- // const projectConfigCheckResult = checkProjectConfig(entryDir, config);
893
+ const gameJsonCheckResult = checkGameJson(config);
894
+ const checkSizeResult = checkProjectSize(config);
926
895
  const result = [
927
- checkSizeResult,
928
896
  gameJsonCheckResult,
929
- // projectConfigCheckResult,
897
+ checkSizeResult,
930
898
  ];
931
899
  if (result.every(item => item.passed)) {
932
900
  logger.info('check project successfully');
933
901
  }
934
902
  return result;
935
903
  }
936
- function checkGameJson(entryDir, config) {
937
- var _a;
904
+ function checkGameJson(config) {
905
+ var _a, _b;
938
906
  logger.info('start check config');
939
- const gameJsonPath = path.join(entryDir, GAME_ORIGIN_CONFIG_FILE_NAME);
907
+ const gameJsonPath = path.join(config.entry, GAME_ORIGIN_CONFIG_FILE_NAME);
940
908
  if (!fs.existsSync(gameJsonPath)) {
941
909
  const errMsg = 'Can not find game.json in game source code, please check it';
942
910
  logger.error(errMsg);
943
911
  if ((_a = config === null || config === void 0 ? void 0 : config.dev) === null || _a === void 0 ? void 0 : _a.enable) {
944
912
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️ ${errMsg}`);
945
- return Object.assign({ passed: false, msg: errMsg, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$3);
913
+ return Object.assign({ passed: false, msg: errMsg, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME, name: 'project' }, defaultCheckConfig$3);
946
914
  }
947
915
  else {
948
916
  throw new Error(errMsg);
949
917
  }
950
918
  }
951
919
  else {
920
+ const gameJson = JSON.parse(fs.readFileSync(gameJsonPath, 'utf-8'));
921
+ if (gameJson.subPackages) {
922
+ const errMsg = `'subPackages' is found in ${GAME_ORIGIN_CONFIG_FILE_NAME}. Please use 'subpackages' (all lowercase) instead.`;
923
+ logger.error(errMsg);
924
+ if ((_b = config === null || config === void 0 ? void 0 : config.dev) === null || _b === void 0 ? void 0 : _b.enable) {
925
+ console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️ ${errMsg}`);
926
+ return Object.assign({ passed: false, msg: errMsg, type: 'config', name: 'project', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$3);
927
+ }
928
+ else {
929
+ throw new Error(errMsg);
930
+ }
931
+ }
952
932
  const msg = 'Check game.json config successfully';
953
933
  logger.info(msg);
954
- return Object.assign({ passed: true, msg, file: GAME_ORIGIN_CONFIG_FILE_NAME, type: 'config' }, defaultCheckConfig$3);
934
+ return Object.assign({ passed: true, msg, type: 'config', level: 'info', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$3);
955
935
  }
956
936
  }
957
937
  /**
@@ -959,9 +939,9 @@ function checkGameJson(entryDir, config) {
959
939
  * @param param0
960
940
  * @returns
961
941
  */
962
- function checkProjectSize(entryDir, config) {
942
+ function checkProjectSize(config) {
963
943
  logger.info('start check project size');
964
- const { dev } = config;
944
+ const { entry: entryDir, dev } = config;
965
945
  const { pkgSizeLimit } = getCheckConfig(config);
966
946
  const enableDev = dev === null || dev === void 0 ? void 0 : dev.enable;
967
947
  const gameSize = getProjectSize({ entryDir });
@@ -972,7 +952,7 @@ function checkProjectSize(entryDir, config) {
972
952
  logger.error(errMsg);
973
953
  if (enableDev) {
974
954
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', errMsg);
975
- return Object.assign({ passed: false, msg: errMsg, type: 'size', size: gameSize }, defaultCheckConfig$3);
955
+ return Object.assign({ passed: false, name: 'project', msg: errMsg, type: 'size', level: 'warning', size: gameSize }, defaultCheckConfig$3);
976
956
  }
977
957
  else {
978
958
  throw new Error(errMsg);
@@ -984,7 +964,7 @@ function checkProjectSize(entryDir, config) {
984
964
  */
985
965
  const logMsg = `Check project size successfully, size: ${gameSizeMB}MB`;
986
966
  logger.info(logMsg);
987
- return Object.assign({ passed: true, msg: logMsg, name: 'project', type: 'size', size: gameSize }, defaultCheckConfig$3);
967
+ return Object.assign({ passed: true, msg: logMsg, name: 'project', type: 'size', level: 'info', size: gameSize }, defaultCheckConfig$3);
988
968
  }
989
969
  }
990
970
 
@@ -997,9 +977,9 @@ const defaultCheckConfig$2 = {
997
977
  * @param param0
998
978
  * @returns
999
979
  */
1000
- function checkMainPackageSize({ entryDir, config, }) {
980
+ function checkMainPackageSize(config) {
1001
981
  logger.info('start check main package size');
1002
- const { dev } = config;
982
+ const { entry: entryDir, dev } = config;
1003
983
  const { mainPkgSizeLimit } = getCheckConfig(config);
1004
984
  const mainPkgSize = getMainPkgSize({ entryDir });
1005
985
  const mainPkgSizeMB = (mainPkgSize / (1024 * 1024)).toFixed(2);
@@ -1009,47 +989,42 @@ function checkMainPackageSize({ entryDir, config, }) {
1009
989
  logger.error(errMsg);
1010
990
  if (dev === null || dev === void 0 ? void 0 : dev.enable) {
1011
991
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️ ${errMsg}`);
1012
- return Object.assign({ passed: false, msg: errMsg, size: mainPkgSize, type: 'size' }, defaultCheckConfig$2);
992
+ return Object.assign({ passed: false, msg: errMsg, size: mainPkgSize, type: 'size', level: 'warning' }, defaultCheckConfig$2);
1013
993
  }
1014
994
  else {
1015
995
  throw new Error(errMsg);
1016
996
  }
1017
997
  }
1018
998
  else {
1019
- return Object.assign({ passed: true, msg: `Check main package size successfully, size: ${mainPkgSizeMB}MB`, size: mainPkgSize, type: 'size' }, defaultCheckConfig$2);
999
+ return Object.assign({ passed: true, msg: `Check main package size successfully, size: ${mainPkgSizeMB}MB`, size: mainPkgSize, type: 'size', level: 'info' }, defaultCheckConfig$2);
1020
1000
  }
1021
1001
  }
1022
- function checkMainPackageEntry({ entryDir, config, }) {
1002
+ function checkMainPackageEntry(config) {
1023
1003
  var _a;
1024
1004
  logger.info('start check main package entry');
1005
+ const { entry: entryDir } = config;
1025
1006
  const gameJsPath = path__namespace.join(entryDir, 'game.js');
1026
1007
  if (!fs__namespace.existsSync(gameJsPath)) {
1027
1008
  const errMsg = 'Check main package entry failed, game.js must exist in main package!';
1028
1009
  logger.error(errMsg);
1029
1010
  if ((_a = config.dev) === null || _a === void 0 ? void 0 : _a.enable) {
1030
1011
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', errMsg);
1031
- return Object.assign({ passed: false, msg: errMsg, type: 'config', file: 'game.js' }, defaultCheckConfig$2);
1012
+ return Object.assign({ passed: false, msg: errMsg, type: 'config', level: 'error', file: 'game.js' }, defaultCheckConfig$2);
1032
1013
  }
1033
1014
  }
1034
1015
  logger.info('check game.js successfully');
1035
- return Object.assign({ passed: true, msg: 'Check main package entry successfully, game.js must exist in main package!', type: 'config', file: 'game.js' }, defaultCheckConfig$2);
1016
+ return Object.assign({ passed: true, msg: 'Check main package entry successfully, game.js must exist in main package!', type: 'config', level: 'info', file: 'game.js' }, defaultCheckConfig$2);
1036
1017
  }
1037
- function checkMainPackage(entryDir, config) {
1018
+ function checkMainPackage(config) {
1038
1019
  var _a;
1039
1020
  const checkResults = [];
1040
1021
  logger.info('start check main package');
1041
1022
  /**
1042
1023
  * 检查 game.js 是否存在
1043
1024
  */
1044
- checkResults.push(checkMainPackageEntry({
1045
- entryDir,
1046
- config,
1047
- }));
1025
+ checkResults.push(checkMainPackageEntry(config));
1048
1026
  if ((_a = getCheckConfig(config)) === null || _a === void 0 ? void 0 : _a.mainPkgSizeLimit) {
1049
- checkResults.push(checkMainPackageSize({
1050
- entryDir,
1051
- config,
1052
- }));
1027
+ checkResults.push(checkMainPackageSize(config));
1053
1028
  }
1054
1029
  if (checkResults.every(item => item.passed)) {
1055
1030
  logger.info('Check main package successfully');
@@ -1067,13 +1042,31 @@ const defaultCheckConfig$1 = {
1067
1042
  name: 'subpackage',
1068
1043
  dimension: 'subpackage',
1069
1044
  };
1070
- function checkSubpackages(entryDir, config) {
1045
+ function checkSubpackages(config) {
1046
+ var _a;
1047
+ const { entry: entryDir } = config;
1071
1048
  const checkResults = [];
1072
1049
  /**
1073
1050
  * 校验 subpackage 大小
1074
1051
  * 开始校验 subpackages 配置是否有效
1075
1052
  */
1076
1053
  logger.info('start check subpackages in game.json');
1054
+ // 检查是否使用了小驼峰命名的 subPackages
1055
+ try {
1056
+ const gameOriginConfigPath = path.join(entryDir, GAME_ORIGIN_CONFIG_FILE_NAME);
1057
+ const gameOriginConfig = JSON.parse(fs.readFileSync(gameOriginConfigPath, 'utf-8'));
1058
+ if (gameOriginConfig.subPackages) {
1059
+ const errMsg = 'Error: \'subPackages\' is found in game.json. Please use \'subpackages\' (all lowercase) instead.';
1060
+ logger.error(errMsg);
1061
+ if ((_a = config === null || config === void 0 ? void 0 : config.dev) === null || _a === void 0 ? void 0 : _a.enable) {
1062
+ console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️ ${errMsg}`);
1063
+ }
1064
+ checkResults.push(Object.assign({ passed: false, msg: errMsg, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1065
+ }
1066
+ }
1067
+ catch (e) {
1068
+ // 忽略读取配置文件的错误,继续检查其他配置
1069
+ }
1077
1070
  const subpackages = getSubpackagesConfig(entryDir);
1078
1071
  subpackages.forEach(sub => {
1079
1072
  var _a, _b, _c;
@@ -1085,7 +1078,7 @@ function checkSubpackages(entryDir, config) {
1085
1078
  logger.error(errMsg);
1086
1079
  if ((_a = config === null || config === void 0 ? void 0 : config.dev) === null || _a === void 0 ? void 0 : _a.enable) {
1087
1080
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️ ${errMsg}`);
1088
- checkResults.push(Object.assign({ passed: false, msg: errMsg, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1081
+ checkResults.push(Object.assign({ passed: false, msg: errMsg, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1089
1082
  }
1090
1083
  else {
1091
1084
  throw new Error(errMsg);
@@ -1096,14 +1089,14 @@ function checkSubpackages(entryDir, config) {
1096
1089
  logger.error(errMsg);
1097
1090
  if ((_b = config === null || config === void 0 ? void 0 : config.dev) === null || _b === void 0 ? void 0 : _b.enable) {
1098
1091
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️ ${errMsg}`);
1099
- checkResults.push(Object.assign({ passed: false, msg: errMsg, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1092
+ checkResults.push(Object.assign({ passed: false, msg: errMsg, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1100
1093
  }
1101
1094
  else {
1102
1095
  throw new Error(errMsg);
1103
1096
  }
1104
1097
  }
1105
1098
  else {
1106
- checkResults.push(Object.assign({ passed: true, msg: `Check subpackage<${sub.name}> config successfully`, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1099
+ checkResults.push(Object.assign({ passed: true, msg: `Check subpackage<${sub.name}> config successfully`, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1107
1100
  }
1108
1101
  /**
1109
1102
  * 校验 subpackage 配置是否有效
@@ -1115,14 +1108,14 @@ function checkSubpackages(entryDir, config) {
1115
1108
  logger.error(errMsg);
1116
1109
  if ((_c = config === null || config === void 0 ? void 0 : config.dev) === null || _c === void 0 ? void 0 : _c.enable) {
1117
1110
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️ ${errMsg}`);
1118
- checkResults.push(Object.assign({ passed: false, msg: errMsg, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1111
+ checkResults.push(Object.assign({ passed: false, msg: errMsg, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1119
1112
  }
1120
1113
  else {
1121
1114
  throw new Error(errMsg);
1122
1115
  }
1123
1116
  }
1124
1117
  else {
1125
- checkResults.push(Object.assign({ passed: true, msg: `Check subpackage<${sub.name}> config successfully`, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1118
+ checkResults.push(Object.assign({ passed: true, msg: `Check subpackage<${sub.name}> config successfully`, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME }, defaultCheckConfig$1));
1126
1119
  }
1127
1120
  });
1128
1121
  if (checkResults.length && checkResults.every(item => item.passed)) {
@@ -1134,8 +1127,9 @@ function checkSubpackages(entryDir, config) {
1134
1127
  const defaultCheckConfig = {
1135
1128
  dimension: CHECK_DIMENSION.IndependentPackage,
1136
1129
  };
1137
- function checkIndependentPackages(entryDir, config) {
1130
+ function checkIndependentPackages(config) {
1138
1131
  var _a;
1132
+ const { entry: entryDir } = config;
1139
1133
  const isEnableDev = (_a = config === null || config === void 0 ? void 0 : config.dev) === null || _a === void 0 ? void 0 : _a.enable;
1140
1134
  const checkResults = [];
1141
1135
  /**
@@ -1152,14 +1146,14 @@ function checkIndependentPackages(entryDir, config) {
1152
1146
  logger.error(errMsg);
1153
1147
  if (isEnableDev) {
1154
1148
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️${errMsg}`);
1155
- checkResults.push(Object.assign(Object.assign({}, defaultCheckConfig), { passed: false, msg: errMsg, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME, name: sub.name }));
1149
+ checkResults.push(Object.assign(Object.assign({}, defaultCheckConfig), { passed: false, msg: errMsg, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME, name: sub.name }));
1156
1150
  }
1157
1151
  else {
1158
1152
  throw new Error(errMsg);
1159
1153
  }
1160
1154
  }
1161
1155
  else {
1162
- checkResults.push(Object.assign(Object.assign({}, defaultCheckConfig), { passed: true, msg: `Check independent package<${sub.name}> config successfully`, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME, name: sub.name }));
1156
+ checkResults.push(Object.assign(Object.assign({}, defaultCheckConfig), { passed: true, msg: `Check independent package<${sub.name}> config successfully`, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME, name: sub.name }));
1163
1157
  }
1164
1158
  /**
1165
1159
  * 校验 independent subpackage 配置是否有效
@@ -1171,7 +1165,7 @@ function checkIndependentPackages(entryDir, config) {
1171
1165
  logger.error(errMsg);
1172
1166
  if (isEnableDev) {
1173
1167
  console.log('\x1b[1m\x1b[33m%s\x1b[0m', `❗️ ${errMsg}`);
1174
- checkResults.push(Object.assign(Object.assign({}, defaultCheckConfig), { passed: false, msg: errMsg, type: 'config', file: GAME_ORIGIN_CONFIG_FILE_NAME, name: sub.name }));
1168
+ checkResults.push(Object.assign(Object.assign({}, defaultCheckConfig), { passed: false, msg: errMsg, type: 'config', level: 'error', file: GAME_ORIGIN_CONFIG_FILE_NAME, name: sub.name }));
1175
1169
  }
1176
1170
  else {
1177
1171
  throw new Error(errMsg);
@@ -1182,6 +1176,7 @@ function checkIndependentPackages(entryDir, config) {
1182
1176
  passed: true,
1183
1177
  msg: `Check independent package<${sub.name}> config successfully`,
1184
1178
  type: 'config',
1179
+ level: 'error',
1185
1180
  file: GAME_ORIGIN_CONFIG_FILE_NAME,
1186
1181
  dimension: CHECK_DIMENSION.IndependentPackage,
1187
1182
  name: sub.name,
@@ -1197,6 +1192,7 @@ function checkIndependentPackages(entryDir, config) {
1197
1192
  pkgName: sub.name,
1198
1193
  limit: independentSubPkgSizeLimit,
1199
1194
  dimension: CHECK_DIMENSION.IndependentPackage,
1195
+ level: isEnableDev ? 'warning' : 'error',
1200
1196
  });
1201
1197
  checkResults.push(checkSizeResult);
1202
1198
  logger.info(checkSizeResult.msg);
@@ -1215,7 +1211,7 @@ function checkIndependentPackages(entryDir, config) {
1215
1211
  }
1216
1212
  return checkResults;
1217
1213
  }
1218
- function checkPkgSize({ entryDir, limit, pkgName, dimension, }) {
1214
+ function checkPkgSize({ entryDir, limit, pkgName, dimension, level, }) {
1219
1215
  const size = getDirSizeSync({
1220
1216
  rootDir: entryDir,
1221
1217
  entryDir,
@@ -1229,6 +1225,7 @@ function checkPkgSize({ entryDir, limit, pkgName, dimension, }) {
1229
1225
  ? `Check package ${pkgName} size ${sizeMB.toFixed(2)}MB check successfully`
1230
1226
  : `Check package ${pkgName} size ${sizeMB.toFixed(2)}MB exceeds limit ${limitMB.toFixed(2)}MB`,
1231
1227
  type: 'size',
1228
+ level,
1232
1229
  size,
1233
1230
  dimension,
1234
1231
  name: pkgName,
@@ -1264,7 +1261,7 @@ const API_LIST = [
1264
1261
  desc: "Get entrance mission reward"
1265
1262
  }
1266
1263
  ];
1267
- function checkAPI({ entryDir, config, }) {
1264
+ function checkAPI(config) {
1268
1265
  var _a;
1269
1266
  if (!((_a = config === null || config === void 0 ? void 0 : config.build) === null || _a === void 0 ? void 0 : _a.enableAPICheck)) {
1270
1267
  return [];
@@ -1289,7 +1286,7 @@ function checkAPI({ entryDir, config, }) {
1289
1286
  hitFilesMap.set(name, new Set());
1290
1287
  }
1291
1288
  // 深度优先遍历
1292
- const stack = [entryDir];
1289
+ const stack = [config.entry];
1293
1290
  while (stack.length) {
1294
1291
  const current = stack.pop();
1295
1292
  const stat = fs.statSync(current);
@@ -1338,6 +1335,7 @@ function checkAPI({ entryDir, config, }) {
1338
1335
  passed: files.length > 0,
1339
1336
  files,
1340
1337
  type: 'api',
1338
+ level: 'warning',
1341
1339
  required: false,
1342
1340
  dimension: 'project',
1343
1341
  };
@@ -1351,28 +1349,28 @@ function escapeRegex(s) {
1351
1349
  return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1352
1350
  }
1353
1351
 
1354
- async function checkPkgs({ entryDir, config, }) {
1352
+ async function checkPkgs(config) {
1355
1353
  logger.info('开始校验项目');
1356
1354
  /**
1357
1355
  * 1. 校验项目
1358
1356
  */
1359
- const projectCheckResult = checkProject(entryDir, config);
1357
+ const projectCheckResult = checkProject(config);
1360
1358
  /**
1361
- * 2. 校验主包
1359
+ * 2. 如果有,校验分包
1362
1360
  */
1363
- const mainPackageCheckResult = checkMainPackage(entryDir, config);
1361
+ const subpackagesCheckResult = checkSubpackages(config);
1364
1362
  /**
1365
- * 3. 如果有,校验分包
1363
+ * 3. 校验主包
1366
1364
  */
1367
- const subpackagesCheckResult = checkSubpackages(entryDir, config);
1365
+ const mainPackageCheckResult = checkMainPackage(config);
1368
1366
  /**
1369
1367
  * 校验独立分包
1370
1368
  */
1371
- const independentPackagesCheckResult = checkIndependentPackages(entryDir, config);
1369
+ const independentPackagesCheckResult = checkIndependentPackages(config);
1372
1370
  /**
1373
1371
  * 校验 API 调用
1374
1372
  */
1375
- const apiCheckResult = checkAPI({ entryDir, config });
1373
+ const apiCheckResult = checkAPI(config);
1376
1374
  return [
1377
1375
  ...projectCheckResult,
1378
1376
  ...mainPackageCheckResult,
@@ -1382,7 +1380,8 @@ async function checkPkgs({ entryDir, config, }) {
1382
1380
  ];
1383
1381
  }
1384
1382
 
1385
- async function setup(entryDir, outputDir) {
1383
+ async function setup(config) {
1384
+ const { entry: entryDir, output: outputDir } = config;
1386
1385
  logger.info('开始基于源代码中的 game.json 生成 packageConfig.json');
1387
1386
  const gameJsonPath = path.join(entryDir, GAME_ORIGIN_CONFIG_FILE_NAME);
1388
1387
  const gameJson = JSON.parse(fs.readFileSync(gameJsonPath, 'utf-8'));
@@ -1510,7 +1509,8 @@ function collectPkgJsFiles({ entry, root, exts = ['.js', '.ts', '.jsx', '.tsx'],
1510
1509
  return files;
1511
1510
  }
1512
1511
  // 构建每个包的 map
1513
- function collectMaps(entryDir, packages) {
1512
+ function collectMaps(config, packages) {
1513
+ const { entry: entryDir } = config;
1514
1514
  logger.info('开始基于游戏源代码收集分包中的 JS 文件');
1515
1515
  const result = {};
1516
1516
  // 1. 先收集所有分包根目录名(如 subpackages/level1、subpackages/level2)
@@ -1563,29 +1563,95 @@ function collectMaps(entryDir, packages) {
1563
1563
  logger.info('基于游戏源代码收集分包中的 JS 文件完成');
1564
1564
  return result;
1565
1565
  }
1566
- function collectPluginMaps(gameDir, entryDir, name) {
1567
- logger.info('开始基于插件源代码收集分包中的 JS 文件');
1568
- const result = {};
1569
- let jsFiles;
1570
- jsFiles = collectPkgJsFiles({
1571
- entry: entryDir,
1572
- root: entryDir,
1573
- exts: ['.js', '.ts', '.jsx', '.tsx'],
1574
- excludeDirs: [],
1575
- });
1576
- const list = [];
1577
- jsFiles.forEach(absPath => {
1578
- list.push(path.relative(gameDir, absPath).replace(/\\/g, '/'));
1566
+
1567
+ /**
1568
+ * 根据 TikTok DevPortal 接口获取插件包信息(url + md5)
1569
+ *
1570
+ * 对应 curl:
1571
+ * POST https://developers.tiktok.com/tiktok/v4/devportal/minigame/plugin_meta/get
1572
+ * body: { plugin_name, plugin_version }
1573
+ */
1574
+ async function getPluginInfo(params) {
1575
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1576
+ const baseUrl = (_a = params.baseUrl) !== null && _a !== void 0 ? _a : 'https://developers.tiktok.com';
1577
+ const url = `${baseUrl}/tiktok/v4/devportal/minigame/plugin_meta/get`;
1578
+ const res = await fetch(url, {
1579
+ method: 'POST',
1580
+ headers: Object.assign({ 'Content-Type': 'application/json' }, ((_b = params.headers) !== null && _b !== void 0 ? _b : {})),
1581
+ body: JSON.stringify({
1582
+ plugin_name: params.plugin_name,
1583
+ plugin_version: params.plugin_version,
1584
+ }),
1579
1585
  });
1580
- const packNameRoot = name;
1581
- result[name] = {
1582
- [`${packNameRoot}/game.pack.js`]: list,
1583
- };
1584
- logger.info('基于插件源代码收集分包中的 JS 文件完成');
1585
- return result;
1586
+ const json = await res.json();
1587
+ const meta = (_g = (_e = (_c = json === null || json === void 0 ? void 0 : json.PluginMeta) !== null && _c !== void 0 ? _c : (_d = json === null || json === void 0 ? void 0 : json.data) === null || _d === void 0 ? void 0 : _d.PluginMeta) !== null && _e !== void 0 ? _e : (_f = json === null || json === void 0 ? void 0 : json.result) === null || _f === void 0 ? void 0 : _f.PluginMeta) !== null && _g !== void 0 ? _g : (_j = (_h = json === null || json === void 0 ? void 0 : json.data) === null || _h === void 0 ? void 0 : _h.result) === null || _j === void 0 ? void 0 : _j.PluginMeta;
1588
+ if (!(meta === null || meta === void 0 ? void 0 : meta.PackageCDNURL) || !(meta === null || meta === void 0 ? void 0 : meta.PackageMD5)) {
1589
+ throw new Error(`[ttmg-pack]: The current game plugin version does not exist. plugin_name: ${params.plugin_name}, plugin_version: ${params.plugin_version}, error: ${JSON.stringify(json)}`);
1590
+ }
1591
+ return { url: meta.PackageCDNURL, md5: meta.PackageMD5 };
1592
+ }
1593
+ async function addDepsToPackages(gameEntry, outputDir, allDeps) {
1594
+ var _a;
1595
+ const gamePackConfigPath = path.join(outputDir, GAME_PACK_CONFIG_FILE_NAME);
1596
+ const gameJsonPath = path.join(gameEntry, GAME_ORIGIN_CONFIG_FILE_NAME);
1597
+ let gamePackConfig;
1598
+ let gameJson;
1599
+ let pluginConfig;
1600
+ try {
1601
+ gamePackConfig = JSON.parse(fs.readFileSync(gamePackConfigPath, 'utf-8'));
1602
+ gameJson = JSON.parse(fs.readFileSync(gameJsonPath, 'utf-8'));
1603
+ pluginConfig = gameJson.plugins;
1604
+ }
1605
+ catch (error) {
1606
+ throw new Error('[ttmg-pack] Failed to read package file game.json or packageConfig.json');
1607
+ }
1608
+ const unityDeps = ['data-package', 'StreamingAssets', 'wasmcode', 'wasmcode-android', 'wasmcode-ios'];
1609
+ for (const dep of unityDeps) {
1610
+ // 如果 game.json 的 subpackages 里有这个包,则添加进 __GAME__ 的 dependencies
1611
+ if (((_a = gameJson.subpackages) !== null && _a !== void 0 ? _a : []).some(pkg => pkg.name === dep)) {
1612
+ gamePackConfig.packages[GAME_MAIN_PACKAGE_NAME].dependencies.push(dep);
1613
+ }
1614
+ }
1615
+ for (const [pkgName, plugins] of Object.entries(allDeps)) {
1616
+ for (const pluginName of plugins) {
1617
+ if (!(pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig[pluginName]))
1618
+ continue;
1619
+ const version = pluginConfig[pluginName].version;
1620
+ const pluginPkgName = `${pluginName}_${version}`;
1621
+ const { url, md5 } = await getPluginInfo({
1622
+ plugin_name: pluginName.toLowerCase(),
1623
+ plugin_version: version
1624
+ });
1625
+ gamePackConfig.packages[pkgName].dependencies.push(pluginPkgName);
1626
+ if (!gamePackConfig.packages[pluginPkgName]) {
1627
+ gamePackConfig.packages[pluginPkgName] = {
1628
+ url,
1629
+ md5,
1630
+ root: pluginPkgName,
1631
+ main: `${pluginPkgName}/index.js`,
1632
+ output: `${pluginPkgName}${STTPKG_EXT}`,
1633
+ independent: false,
1634
+ type: 'plugin',
1635
+ dependencies: [],
1636
+ };
1637
+ }
1638
+ else {
1639
+ // 如果已存在,也覆盖 url/md5,保证最新
1640
+ gamePackConfig.packages[pluginPkgName].url = url;
1641
+ gamePackConfig.packages[pluginPkgName].md5 = md5;
1642
+ }
1643
+ }
1644
+ }
1645
+ try {
1646
+ fs.writeFileSync(gamePackConfigPath, JSON.stringify(gamePackConfig, null, 2));
1647
+ }
1648
+ catch (error) {
1649
+ throw new Error(`[ttmg-pack] Failed to write package file packageConfig.json: ${error.message} path: ${gamePackConfigPath}`);
1650
+ }
1586
1651
  }
1587
1652
 
1588
- function collectDeps(gameEntry, packages) {
1653
+ async function collectDeps(config, packages) {
1654
+ const { entry: gameEntry, output: gameOutput } = config;
1589
1655
  // 自动扫描 game 目录下的一级文件夹作为根前缀
1590
1656
  const rootPrefixes = getRootPrefixes(gameEntry);
1591
1657
  // 查找所有 JS 文件
@@ -1708,6 +1774,7 @@ function collectDeps(gameEntry, packages) {
1708
1774
  packageDeps: {},
1709
1775
  pluginDeps: {},
1710
1776
  });
1777
+ await addDepsToPackages(gameEntry, gameOutput, result.pluginDeps);
1711
1778
  return result;
1712
1779
  }
1713
1780
  function getRootPrefixes(gameEntry) {
@@ -1804,8 +1871,7 @@ async function pack({ gameEntry, pkgName, allDeps, allMaps, pkgConfig, destRoot,
1804
1871
  // });
1805
1872
  // const code = fs.readFileSync(absPath, 'utf-8');
1806
1873
  const fileId = relPath.replace(/\\/g, '/');
1807
- const schema = config.build.type === 'plugin' ? 'plugin' : 'game';
1808
- const defineHeader = `define("${schema}:${fileId}", ["require", "requireAsync", "module", "exports", "sandboxGlobal"], function(require, requireAsync, module, exports, sandboxGlobal){\nwith(sandboxGlobal){\n`;
1874
+ const defineHeader = `define("game:${fileId}", ["require", "requireAsync", "module", "exports", "sandboxGlobal"], function(require, requireAsync, module, exports, sandboxGlobal){\nwith(sandboxGlobal){\n`;
1809
1875
  const defineFooter = `\n}\n});\n`;
1810
1876
  const fileMagic = new MagicString(code, { filename: fileId });
1811
1877
  fileMagic.prepend(defineHeader);
@@ -1892,106 +1958,19 @@ async function partition({ pkgRoot, destRoot, packedFiles, gameEntry, gameOutput
1892
1958
  }
1893
1959
  }
1894
1960
 
1895
- /**
1896
- * 根据 TikTok DevPortal 接口获取插件包信息(url + md5)
1897
- *
1898
- * 对应 curl:
1899
- * POST https://developers.tiktok.com/tiktok/v4/devportal/minigame/plugin_meta/get
1900
- * body: { plugin_name, plugin_version }
1901
- */
1902
- async function getPluginInfo(params) {
1903
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1904
- const baseUrl = (_a = params.baseUrl) !== null && _a !== void 0 ? _a : 'https://developers.tiktok.com';
1905
- const url = `${baseUrl}/tiktok/v4/devportal/minigame/plugin_meta/get`;
1906
- const res = await fetch(url, {
1907
- method: 'POST',
1908
- headers: Object.assign({ 'Content-Type': 'application/json' }, ((_b = params.headers) !== null && _b !== void 0 ? _b : {})),
1909
- body: JSON.stringify({
1910
- plugin_name: params.plugin_name,
1911
- plugin_version: params.plugin_version,
1912
- }),
1913
- });
1914
- const json = await res.json();
1915
- const meta = (_g = (_e = (_c = json === null || json === void 0 ? void 0 : json.PluginMeta) !== null && _c !== void 0 ? _c : (_d = json === null || json === void 0 ? void 0 : json.data) === null || _d === void 0 ? void 0 : _d.PluginMeta) !== null && _e !== void 0 ? _e : (_f = json === null || json === void 0 ? void 0 : json.result) === null || _f === void 0 ? void 0 : _f.PluginMeta) !== null && _g !== void 0 ? _g : (_j = (_h = json === null || json === void 0 ? void 0 : json.data) === null || _h === void 0 ? void 0 : _h.result) === null || _j === void 0 ? void 0 : _j.PluginMeta;
1916
- if (!(meta === null || meta === void 0 ? void 0 : meta.PackageCDNURL) || !(meta === null || meta === void 0 ? void 0 : meta.PackageMD5)) {
1917
- throw new Error(`[ttmg-pack]: The current game plugin version does not exist. plugin_name: ${params.plugin_name}, plugin_version: ${params.plugin_version}, error: ${JSON.stringify(json)}`);
1918
- }
1919
- return { url: meta.PackageCDNURL, md5: meta.PackageMD5 };
1920
- }
1921
- async function addDepsToPackages(gameEntry, outputDir, allDeps) {
1922
- var _a;
1923
- const gamePackConfigPath = path.join(outputDir, GAME_PACK_CONFIG_FILE_NAME);
1924
- const gameJsonPath = path.join(gameEntry, GAME_ORIGIN_CONFIG_FILE_NAME);
1925
- let gamePackConfig;
1926
- let gameJson;
1927
- let pluginConfig;
1928
- try {
1929
- gamePackConfig = JSON.parse(fs.readFileSync(gamePackConfigPath, 'utf-8'));
1930
- gameJson = JSON.parse(fs.readFileSync(gameJsonPath, 'utf-8'));
1931
- pluginConfig = gameJson.plugins;
1932
- }
1933
- catch (error) {
1934
- throw new Error('[ttmg-pack] Failed to read package file game.json or packageConfig.json');
1935
- }
1936
- const unityDeps = ['data-package', 'StreamingAssets', 'wasmcode', 'wasmcode-android', 'wasmcode-ios'];
1937
- for (const dep of unityDeps) {
1938
- // 如果 game.json 的 subpackages 里有这个包,则添加进 __GAME__ 的 dependencies
1939
- if (((_a = gameJson.subpackages) !== null && _a !== void 0 ? _a : []).some(pkg => pkg.name === dep)) {
1940
- gamePackConfig.packages[GAME_MAIN_PACKAGE_NAME].dependencies.push(dep);
1941
- }
1942
- }
1943
- for (const [pkgName, plugins] of Object.entries(allDeps)) {
1944
- for (const pluginName of plugins) {
1945
- if (!(pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig[pluginName]))
1946
- continue;
1947
- const version = pluginConfig[pluginName].version;
1948
- const pluginPkgName = `${pluginName}_${version}`;
1949
- const { url, md5 } = await getPluginInfo({
1950
- plugin_name: pluginName.toLowerCase(),
1951
- plugin_version: version
1952
- });
1953
- gamePackConfig.packages[pkgName].dependencies.push(pluginPkgName);
1954
- if (!gamePackConfig.packages[pluginPkgName]) {
1955
- gamePackConfig.packages[pluginPkgName] = {
1956
- url,
1957
- md5,
1958
- root: pluginPkgName,
1959
- main: `${pluginPkgName}/index.js`,
1960
- output: `${pluginPkgName}${STTPKG_EXT}`,
1961
- independent: false,
1962
- type: 'plugin',
1963
- dependencies: [],
1964
- };
1965
- }
1966
- else {
1967
- // 如果已存在,也覆盖 url/md5,保证最新
1968
- gamePackConfig.packages[pluginPkgName].url = url;
1969
- gamePackConfig.packages[pluginPkgName].md5 = md5;
1970
- }
1971
- }
1972
- }
1973
- fs.writeFileSync(gamePackConfigPath, JSON.stringify(gamePackConfig, null, 2));
1974
- }
1975
-
1976
- function getSkipDirs({ packages, entryDir, }) {
1977
- const skipDirs = [];
1978
- if (packages) {
1979
- skipDirs.push(...Object.values(packages).map(item => item.root));
1980
- }
1981
- return skipDirs;
1982
- }
1983
- async function makePkgs({ gameEntry, gameOutput, config, }) {
1961
+ async function makePkgs(config) {
1962
+ const { entry: gameEntry, output: gameOutput } = config;
1984
1963
  let startTime = Date.now();
1985
1964
  logger.info(`pack start,startTime:${startTime}`);
1986
- const { packages } = await setup(gameEntry, gameOutput);
1987
- const allDeps = collectDeps(gameEntry, packages);
1988
- await addDepsToPackages(gameEntry, gameOutput, allDeps.pluginDeps);
1989
- const allMaps = collectMaps(gameEntry, packages);
1965
+ const { packages } = await setup(config);
1966
+ const allDeps = await collectDeps(config, packages);
1967
+ const allMaps = collectMaps(config, packages);
1990
1968
  const pkgOutput = {};
1991
1969
  /**
1992
1970
  * 基于 asyncPool 并发打包
1993
1971
  */
1994
1972
  await asyncPool$1(10, Object.keys(allMaps), async (pkgName) => {
1973
+ var _a;
1995
1974
  logger.info(`开始基于游戏源代码打包,包名:${pkgName}`);
1996
1975
  let startTime = Date.now();
1997
1976
  const pkgConfig = packages[pkgName];
@@ -2018,7 +1997,7 @@ async function makePkgs({ gameEntry, gameOutput, config, }) {
2018
1997
  pkgRoot,
2019
1998
  destRoot,
2020
1999
  packedFiles: flattenMaps(allMaps),
2021
- skipDirs: getSkipDirs({ packages, entryDir: gameEntry }),
2000
+ skipDirs: ((_a = Object.values(packages)) === null || _a === void 0 ? void 0 : _a.map(item => item.root)) || [],
2022
2001
  });
2023
2002
  const pkgRootDir = path.join(gameOutput, pkgName);
2024
2003
  removeEmptyDir(pkgRootDir);
@@ -2035,46 +2014,6 @@ async function makePkgs({ gameEntry, gameOutput, config, }) {
2035
2014
  logger.info(`pack end,duration:${Date.now() - startTime}ms`);
2036
2015
  return pkgOutput;
2037
2016
  }
2038
- async function makePlugin({ gameEntry, gameOutput, config, }) {
2039
- try {
2040
- const pluginConfig = fs.readFileSync(path.join(gameEntry, 'plugin.json'), 'utf-8');
2041
- const { name, main, version } = JSON.parse(pluginConfig);
2042
- const pluginName = `${name}_${version}`;
2043
- // 把 entryDir 下的所有文件复制到 entryDir/plugin
2044
- const pluginDir = path.join(gameEntry, pluginName);
2045
- copyDirectory(gameEntry, pluginDir);
2046
- const packages = {
2047
- [pluginName]: {
2048
- url: '',
2049
- md5: '',
2050
- root: pluginName,
2051
- main,
2052
- output: `${pluginName}${STTPKG_EXT}`,
2053
- type: 'game',
2054
- dependencies: []
2055
- }
2056
- };
2057
- fs.writeFileSync(path.join(gameOutput, GAME_PACK_CONFIG_FILE_NAME), JSON.stringify({ packages }, null, 2));
2058
- const pluginEntry = path.join(gameEntry, pluginName);
2059
- const allMaps = collectPluginMaps(gameEntry, pluginEntry, pluginName);
2060
- await pack({
2061
- gameEntry,
2062
- allDeps: {
2063
- packageDeps: {},
2064
- pluginDeps: {},
2065
- },
2066
- allMaps,
2067
- pkgName: pluginName,
2068
- pkgConfig: packages[pluginName],
2069
- destRoot: path.join(gameOutput, pluginName, packages[pluginName].root),
2070
- config,
2071
- });
2072
- }
2073
- catch (error) {
2074
- logger.error('plugin.json 不存在');
2075
- return;
2076
- }
2077
- }
2078
2017
 
2079
2018
  /**
2080
2019
  * 将 packages 中的每个 package 下的文件内容合并到 outputDir 下,不保留 package name
@@ -2146,33 +2085,40 @@ async function mergePkgs(outputDir) {
2146
2085
  logger.info('mergePkgs 完成');
2147
2086
  }
2148
2087
 
2149
- async function clearPkgs(entryDir, uselessDirs = ['node_modules', '__MACOSX']) {
2150
- removeSystemUseless(entryDir, uselessDirs);
2088
+ async function clearPkgs(config, uselessDirs = ['node_modules', '__MACOSX']) {
2089
+ removeSystemUseless(config.entry, uselessDirs);
2151
2090
  }
2152
2091
 
2153
2092
  async function debugPkgs(config) {
2154
- const { entry: entryDir, output: outputDir, dev: { enableLog }, } = config;
2093
+ const { output: outputDir, dev: { enableLog }, } = config;
2155
2094
  logger.init(outputDir, enableLog);
2156
2095
  try {
2157
2096
  /**
2158
2097
  * 清理
2159
2098
  */
2160
- clearPkgs(entryDir);
2099
+ clearPkgs(config);
2161
2100
  /**
2162
2101
  * 校验
2163
2102
  */
2164
- const checkResults = await checkPkgs({
2165
- entryDir,
2166
- config,
2167
- });
2103
+ const checkResults = await checkPkgs(config);
2104
+ /**
2105
+ * 如果有任何 error 类型的校验项失败,则不再继续后续流程,直接返回错误
2106
+ */
2107
+ const errorResults = checkResults.filter(item => !item.passed && item.level === 'error');
2108
+ if (errorResults.length > 0) {
2109
+ const errorMsg = errorResults
2110
+ .map(item => `[${item.name || item.type}] ${item.msg}`)
2111
+ .join('\n');
2112
+ return {
2113
+ isSuccess: false,
2114
+ errorMsg: `Project validation failed (Errors):\n${errorMsg}`,
2115
+ checkResults,
2116
+ };
2117
+ }
2168
2118
  /**
2169
2119
  * 打包
2170
2120
  */
2171
- await makePkgs({
2172
- gameEntry: entryDir,
2173
- gameOutput: outputDir,
2174
- config,
2175
- });
2121
+ await makePkgs(config);
2176
2122
  /**
2177
2123
  * 合并
2178
2124
  */
@@ -2197,60 +2143,23 @@ async function debugPkgs(config) {
2197
2143
  }
2198
2144
 
2199
2145
  async function buildPkgs(config) {
2200
- var _a;
2201
- if (((_a = config === null || config === void 0 ? void 0 : config.build) === null || _a === void 0 ? void 0 : _a.type) === 'plugin') {
2202
- await buildPlugin(config);
2203
- return;
2204
- }
2205
- const { entry: entryDir, output: outputDir, build } = config;
2146
+ const { output: outputDir, build } = config;
2206
2147
  let startTime = Date.now();
2207
2148
  logger.init(outputDir, true);
2208
- logger.info(`TTMG_PACK_VERSION: ${"0.3.5"}`);
2149
+ logger.info(`TTMG_PACK_VERSION: ${"0.3.7"}`);
2209
2150
  logger.info(`pack start, startTime:${startTime}`);
2210
2151
  /**
2211
2152
  * 清理
2212
2153
  */
2213
- clearPkgs(entryDir, ['node_modules', '__MACOSX', TTMG_TEMP_DIR]);
2154
+ await clearPkgs(config, ['node_modules', '__MACOSX', TTMG_TEMP_DIR]);
2214
2155
  /**
2215
2156
  * 校验
2216
2157
  */
2217
- await checkPkgs({
2218
- entryDir,
2219
- config,
2220
- });
2221
- /**
2222
- * 打包
2223
- */
2224
- await makePkgs({
2225
- config,
2226
- gameEntry: entryDir,
2227
- gameOutput: outputDir,
2228
- });
2229
- if (build === null || build === void 0 ? void 0 : build.enableOdr) {
2230
- /**
2231
- * 等待文件全部读写完成后
2232
- */
2233
- await makeOdrPkgs(outputDir);
2234
- /**
2235
- * 分拆 odr 包
2236
- */
2237
- }
2238
- logger.info(`pack end:${Date.now() - startTime}ms`);
2239
- }
2240
- async function buildPlugin(originConfig) {
2241
- const { entry: entryDir, output: outputDir, build } = originConfig;
2242
- let startTime = Date.now();
2243
- logger.init(outputDir, true);
2244
- logger.info(`TTMG_PACK_VERSION: ${"0.3.5"}`);
2245
- logger.info(`pack start, startTime:${startTime}`);
2158
+ await checkPkgs(config);
2246
2159
  /**
2247
2160
  * 打包
2248
2161
  */
2249
- await makePlugin({
2250
- config: originConfig,
2251
- gameEntry: entryDir,
2252
- gameOutput: outputDir,
2253
- });
2162
+ await makePkgs(config);
2254
2163
  if (build === null || build === void 0 ? void 0 : build.enableOdr) {
2255
2164
  /**
2256
2165
  * 等待文件全部读写完成后