ttmg-pack 0.2.7-requirePlugin.7 → 0.2.8-beta.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,312 @@
1
+ ## 0.0.1
2
+
3
+ 发布第一个版本,将分包逻辑单独维护
4
+
5
+ ## 0.0.3
6
+
7
+ - 增加类型导出
8
+ - 修改入参格式
9
+
10
+ ## 0.0.4
11
+
12
+ - 支持自定义输出 log
13
+ - 打包产物支持 banner 注释
14
+
15
+ ## 0.0.5
16
+
17
+ - 调整包大小校验限制,主包 30MB,子包 4MB
18
+
19
+ ## 0.0.6
20
+
21
+ 优化入口接口
22
+
23
+ ```
24
+ export interface BuildConfig {
25
+ entry: string;
26
+ output: string;
27
+ rules?: {
28
+ mainPackageSizeLimit: number;
29
+ projectSizeLimit: number;
30
+ subpackageSizeLimit?: number;
31
+ };
32
+ enableDev?: boolean;
33
+ enableCheck?: boolean;
34
+ enableLog?: boolean;
35
+ }
36
+
37
+ ```
38
+
39
+ ## 0.0.7
40
+
41
+ 支持类型文件导出
42
+
43
+ ## 0.0.8
44
+
45
+ ODR 相关功能
46
+
47
+ - 支持 ODR 打包
48
+ - 支持 ODR 下载
49
+ - 支持 ODR 配置写入
50
+
51
+ ## 0.0.9
52
+
53
+ 拆分 debug 功能 和 build 功能
54
+
55
+ ## 0.0.10
56
+
57
+ fix buildPkgs 日志输出问题
58
+
59
+ ## 0.0.11
60
+
61
+ 移除 console.log 日志
62
+
63
+ ## 0.0.12
64
+
65
+ 支持校验 project.config.json,appid 不能为空,开发调试环节强依赖
66
+
67
+ ## 0.0.13
68
+
69
+ 移除无效 log
70
+
71
+ ## 0.0.14
72
+
73
+ 导出 packageConfig.json,调试环节使用
74
+
75
+ ## 0.0.15
76
+
77
+ fix: 修复 生成 projectConfig.json
78
+
79
+ ## 0.0.16
80
+
81
+ 调试模式不做大小校验,只做警告
82
+
83
+ ## 0.0.17
84
+
85
+ 支持 sourcemap
86
+
87
+ ## 0.0.18
88
+
89
+ 支持 sourcemap 配置
90
+
91
+ ## 0.0.19
92
+
93
+ 支持自定义 sourcemap 文件名
94
+
95
+ ## 0.0.20
96
+
97
+ 1. 支持多种 sourcemap 输出方案
98
+ 2. 优化打包配置接口
99
+
100
+ ## 0.0.21
101
+
102
+ 1. 优化生产 sourcemap 生成逻辑
103
+
104
+ ## 0.0.22
105
+
106
+ 修复 sourcemap
107
+
108
+ ## 0.0.23
109
+
110
+ 优化 pack 逻辑,降低耗时
111
+
112
+ ## 0.0.24
113
+
114
+ 优化 buildPkgs 逻辑
115
+
116
+ ## 0.0.25
117
+
118
+ fix: odr 下载逻辑,Array buffer 读写
119
+
120
+ ## 0.0.26
121
+
122
+ 1. fix: source map 写入 bug
123
+ 2. 支持 esmodule 打包
124
+
125
+ ## 0.0.27
126
+
127
+ 1. 修复循环依赖问题
128
+
129
+ ## 0.0.28
130
+
131
+ 回滚 支持 esmodule 打包,止损加密后解密失败的问题
132
+
133
+ ## 0.0.29
134
+
135
+ 支持 es module 打包
136
+
137
+ ## 0.0.30
138
+
139
+ 修改类型定义文件
140
+
141
+ ## 0.0.31
142
+
143
+ 1. 修复 打包逻辑,移除 subpackages 逻辑,基于 root 进行分包拆解
144
+ 2. 修复 debugPkgs 逻辑,合并代码出问题,导致 wasmcode 代码丢失
145
+
146
+ ## 0.0.32
147
+
148
+ 1. 移除日志
149
+ 2. 移除 subpackages 常量
150
+
151
+ ## 0.0.33
152
+
153
+ 修复打包 BUG
154
+
155
+ ## 0.0.34
156
+
157
+ 1. pack remove file not work
158
+ 2. merge remove file not work
159
+
160
+ ## 0.0.35
161
+
162
+ fix main path error
163
+
164
+ ## 0.0.36
165
+
166
+ remove useless log
167
+
168
+ ## 0.0.37
169
+
170
+ 支持调试模式校验日志导出
171
+
172
+ ## 0.0.38
173
+
174
+ 导出 checkPkgs 函数
175
+
176
+ ## 0.0.39
177
+
178
+ 1. 导出 getPkgs 函数
179
+ 2. 修复校验主包大小 BUG
180
+
181
+ ## 0.0.40
182
+
183
+ 1. 导出 GAME_MAIN_PACKAGE_NAME 常量
184
+ 2. 修复校验主包大小 BUG
185
+
186
+ ## 0.0.41/42
187
+
188
+ 优化校验逻辑提示文案
189
+
190
+ ## 0.0.43
191
+
192
+ 调整 log 结构
193
+
194
+ ## 0.0.44
195
+
196
+ 移除日志空格
197
+
198
+ ## 0.0.45
199
+
200
+ 优化打包类型
201
+
202
+ ## 0.0.46
203
+
204
+ 包大小限制提示大小显示问题优化,避免 0MB 展示效果
205
+
206
+ ## 0.0.47
207
+
208
+ 修复校验主包大小 BUG
209
+
210
+ ## 0.0.48
211
+
212
+ 优化校验逻辑提示文案
213
+
214
+ ## 0.0.49
215
+
216
+ 优化校验逻辑提示文案
217
+
218
+ ## 0.0.50
219
+
220
+ 优化校验逻辑提示文案,移除废弃 log
221
+
222
+ ## 0.0.51
223
+
224
+ 支持 fyf packages 导出
225
+
226
+ ## 0.0.52
227
+
228
+ 支持必接 API 预检查,校验必接 API 是否被调用,但是否生效不在检查范畴内
229
+
230
+ ## 0.0.53
231
+
232
+ 移除非必要日志
233
+
234
+ ## 0.0.54
235
+
236
+ 修复 require 路径解析问题
237
+
238
+ ## 0.0.55
239
+
240
+ 支持 unity 游戏引擎,对于 unity 游戏引擎的游戏,不限制主包和独立分包大小
241
+
242
+ ## 0.0.56
243
+
244
+ 补充必接 API 校验范围
245
+
246
+ ## 0.1.0
247
+
248
+ 发布 0.1.0 版本,更新后续平台升级
249
+
250
+ ## 0.1.1
251
+
252
+ 移除 project.config.json 校验
253
+
254
+ ## 0.1.2-0.1.5
255
+
256
+ 开发 unity 相关
257
+
258
+ ## 0.1.6
259
+
260
+ 修复 esbuild 构建编码问题,导致部分 JS 语法不符合预期
261
+
262
+ ## 0.1.7
263
+
264
+ 调整 esbuild 构建目标为 esnext,避免部分语法不符合预期
265
+
266
+ ## 0.1.8
267
+
268
+ 调整 esbuild 构建目标为 es2015,避免部分语法不符合预期
269
+
270
+ ## 0.1.9
271
+
272
+ 支持开放数据域
273
+
274
+ ## 0.2.0
275
+
276
+ fix: 修复 esbuild 构建编码问题
277
+
278
+ ## 0.2.0-beta.1
279
+
280
+ 切换成 esbuild 更稳定的 build
281
+
282
+ ## 0.2.1
283
+
284
+ 完善编译, 修复 open data context 编译问题
285
+
286
+ ## 0.2.2
287
+
288
+ 补充对 分包名称名称为中文类型字符的校验支持,避免打包失败
289
+
290
+ ## 0.2.3
291
+
292
+ esbuild 构建目标调整为 es2020,避免部分语法不符合预期,和安卓 vmsdk 支持最低版本保持一致
293
+
294
+ ## 0.2.4
295
+
296
+ 修复 open data context 编译问题
297
+
298
+ ## 0.2.5
299
+
300
+ 修复 open data context 编译问题
301
+
302
+ ## 0.2.6
303
+
304
+ 修复 build 失败丢失 open data context 代码问题
305
+
306
+ ## 0.2.7
307
+
308
+ 修复 open data context 代码丢失问题,彻底修复
309
+
310
+ ## 0.2.8-beta.1
311
+
312
+ 升级打包脚本,支持 cocos 2.x 版本排行版榜单问题
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * ==========================================
3
3
  * @Description: ttmg pack
4
- * @Version: 0.2.7-requirePlugin.7
4
+ * @Version: 0.2.8-beta.1
5
5
  * @Author: zhanghongyang.mocha
6
- * @Date: 2025-12-17 21:24:44
6
+ * @Date: 2025-12-18 11:49:49
7
7
  * ==========================================
8
8
  */
9
9
  'use strict';
@@ -478,6 +478,17 @@ const getOpenDataContextEntry = ({ entryDir }) => {
478
478
  };
479
479
  }
480
480
  };
481
+ const bareToRelativePlugin = {
482
+ name: 'bare-to-relative',
483
+ setup(build) {
484
+ // 匹配不以 . 或 / 开头的 .js 文件路径
485
+ build.onResolve({ filter: /^[^./].*\.js$/ }, args => {
486
+ return {
487
+ path: path.resolve(args.resolveDir, args.path),
488
+ };
489
+ });
490
+ },
491
+ };
481
492
  async function genOpenDataContext(entryPath) {
482
493
  var _a, _b;
483
494
  const result = await safeBuild({
@@ -495,45 +506,12 @@ async function genOpenDataContext(entryPath) {
495
506
  '.svg': 'dataurl',
496
507
  '.webp': 'dataurl',
497
508
  },
509
+ plugins: [bareToRelativePlugin]
498
510
  });
499
511
  const jsCode = ((_b = (_a = result === null || result === void 0 ? void 0 : result.outputFiles) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text) || '';
500
512
  return jsCode;
501
513
  }
502
514
 
503
- function copyDirectory(src, dest) {
504
- try {
505
- if (!fs.existsSync(dest)) {
506
- fs.mkdirSync(dest, { recursive: true });
507
- }
508
- const items = fs.readdirSync(src);
509
- const normalizedDest = path.resolve(dest) + path.sep;
510
- items.forEach(item => {
511
- const srcPath = path.join(src, item);
512
- const destPath = path.join(dest, item);
513
- // 检查当前要处理的源路径是否就是目标路径
514
- // 这可以防止将目标目录本身复制到自身中
515
- if (path.resolve(srcPath) === path.resolve(dest)) {
516
- return; // 跳过目标目录本身
517
- }
518
- // 获取文件状态
519
- const stat = fs.statSync(srcPath);
520
- if (stat.isFile()) {
521
- // 复制文件
522
- fs.copyFileSync(srcPath, destPath);
523
- }
524
- else if (stat.isDirectory()) {
525
- const childNormalizedSrc = path.resolve(srcPath) + path.sep;
526
- if (!normalizedDest.startsWith(childNormalizedSrc)) {
527
- copyDirectory(srcPath, destPath);
528
- }
529
- }
530
- });
531
- }
532
- catch (error) {
533
- logger.error(`copyDirectory error: ${error}`);
534
- }
535
- }
536
-
537
515
  /**
538
516
  * 将 packageConfig packages 中 分拆的包 配置迁移到 odr_packages 中
539
517
  */
@@ -553,7 +531,7 @@ async function writeOdrConfig(outputDir) {
553
531
  if (!odrPackages[relatedPkgName]) {
554
532
  odrPackages[relatedPkgName] = {};
555
533
  }
556
- odrPackages[relatedPkgName] = Object.assign(Object.assign({}, odrPackages[relatedPkgName]), { root: pkgConfig.root, code_output: pkgConfig.output, code_md5: pkgConfig.md5, main: pkgConfig.main, dependencies: pkgConfig.dependencies, type: pkgConfig.type });
534
+ odrPackages[relatedPkgName] = Object.assign(Object.assign({}, odrPackages[relatedPkgName]), { root: pkgConfig.root, code_output: pkgConfig.output, code_md5: pkgConfig.md5, main: pkgConfig.main });
557
535
  delete packages[pkgName];
558
536
  }
559
537
  if (pkgName.endsWith(ODR_ASSET_DIR_SUFFIX)) {
@@ -582,14 +560,12 @@ async function makeOdrPkgs(outputDir) {
582
560
  const pkgOutput = path.join(outputDir, pkgName);
583
561
  const codeOutput = path.join(outputDir, `${pkgName}${ODR_CODE_DIR_SUFFIX}`);
584
562
  const assetOutput = path.join(outputDir, `${pkgName}${ODR_ASSET_DIR_SUFFIX}`);
585
- if (packages[pkgName].type === 'game') {
586
- ensureDirSync(codeOutput);
587
- ensureDirSync(assetOutput);
588
- fs.cpSync(pkgOutput, codeOutput, { recursive: true });
589
- fs.cpSync(pkgOutput, assetOutput, { recursive: true });
590
- deleteNoJsFilesSync(codeOutput);
591
- deleteJsFilesSync(assetOutput);
592
- }
563
+ ensureDirSync(codeOutput);
564
+ ensureDirSync(assetOutput);
565
+ fs.cpSync(pkgOutput, codeOutput, { recursive: true });
566
+ fs.cpSync(pkgOutput, assetOutput, { recursive: true });
567
+ deleteNoJsFilesSync(codeOutput);
568
+ deleteJsFilesSync(assetOutput);
593
569
  /**
594
570
  * 写入配置
595
571
  */
@@ -1276,8 +1252,6 @@ async function setup(entryDir, outputDir) {
1276
1252
  root: '',
1277
1253
  main: 'game.js',
1278
1254
  output: `${GAME_MAIN_PACKAGE_NAME}${STTPKG_EXT}`,
1279
- type: 'game',
1280
- dependencies: []
1281
1255
  };
1282
1256
  transformSubPackages(gameJson.subpackages).forEach(({ name, root, main, independent }) => {
1283
1257
  // root 是目录
@@ -1288,8 +1262,6 @@ async function setup(entryDir, outputDir) {
1288
1262
  main,
1289
1263
  output: `${name}${STTPKG_EXT}`,
1290
1264
  independent,
1291
- type: 'game',
1292
- dependencies: []
1293
1265
  };
1294
1266
  if (independent) {
1295
1267
  fyfPackages.push({
@@ -1437,27 +1409,6 @@ function collectMaps(entryDir, packages) {
1437
1409
  logger.info('基于游戏源代码收集分包中的 JS 文件完成');
1438
1410
  return result;
1439
1411
  }
1440
- function collectPluginMaps(gameDir, entryDir, name) {
1441
- logger.info('开始基于插件源代码收集分包中的 JS 文件');
1442
- const result = {};
1443
- let jsFiles;
1444
- jsFiles = collectPkgJsFiles({
1445
- entry: entryDir,
1446
- root: entryDir,
1447
- exts: ['.js', '.ts', '.jsx', '.tsx'],
1448
- excludeDirs: [],
1449
- });
1450
- const list = [];
1451
- jsFiles.forEach(absPath => {
1452
- list.push(path.relative(gameDir, absPath).replace(/\\/g, '/'));
1453
- });
1454
- const packNameRoot = name;
1455
- result[name] = {
1456
- [`${packNameRoot}/game.pack.js`]: list,
1457
- };
1458
- logger.info('基于插件源代码收集分包中的 JS 文件完成');
1459
- return result;
1460
- }
1461
1412
 
1462
1413
  function collectDeps(gameEntry, packages) {
1463
1414
  // 自动扫描 game 目录下的一级文件夹作为根前缀
@@ -1510,7 +1461,6 @@ function collectDeps(gameEntry, packages) {
1510
1461
  }
1511
1462
  requireCalls.push({
1512
1463
  file: path.relative(gameEntry, fullPath),
1513
- type: 'game',
1514
1464
  callee: node.callee.name,
1515
1465
  requirePath,
1516
1466
  resolvedPath: resolvedPath
@@ -1518,20 +1468,6 @@ function collectDeps(gameEntry, packages) {
1518
1468
  : '',
1519
1469
  });
1520
1470
  }
1521
- else if (node.type === 'CallExpression' &&
1522
- node.callee.type === 'Identifier' &&
1523
- node.callee.name === 'requirePlugin' &&
1524
- node.arguments.length > 0 &&
1525
- node.arguments[0].type === 'Literal') {
1526
- const requirePath = node.arguments[0].value;
1527
- requireCalls.push({
1528
- file: path.relative(gameEntry, fullPath),
1529
- type: 'plugin',
1530
- callee: node.callee.name,
1531
- requirePath,
1532
- resolvedPath: requirePath,
1533
- });
1534
- }
1535
1471
  });
1536
1472
  });
1537
1473
  const newRequireCalls = requireCalls.map(i => {
@@ -1539,16 +1475,11 @@ function collectDeps(gameEntry, packages) {
1539
1475
  * 基于 packages 来判断
1540
1476
  */
1541
1477
  let depModule = '';
1542
- if (i.type === 'plugin') {
1543
- depModule = i.requirePath.split('/')[0];
1544
- }
1545
- else if (i.type === 'game') {
1546
- Object.keys(packages).forEach(pkg => {
1547
- if (i.resolvedPath && i.resolvedPath.startsWith(packages[pkg].root)) {
1548
- depModule = pkg;
1549
- }
1550
- });
1551
- }
1478
+ Object.keys(packages).forEach(pkg => {
1479
+ if (i.resolvedPath && i.resolvedPath.startsWith(packages[pkg].root)) {
1480
+ depModule = pkg;
1481
+ }
1482
+ });
1552
1483
  let curModule = '';
1553
1484
  Object.keys(packages).forEach(pkg => {
1554
1485
  if (i.file.startsWith(packages[pkg].root)) {
@@ -1562,26 +1493,17 @@ function collectDeps(gameEntry, packages) {
1562
1493
  const exts = ['.js', '.ts', '.jsx', '.tsx'];
1563
1494
  const isJsLike = f => exts.some(ext => f.endsWith(ext));
1564
1495
  const result = newRequireCalls.reduce((acc, cur) => {
1565
- if (!acc.packageDeps[cur.curModule]) {
1566
- acc.packageDeps[cur.curModule] = {};
1567
- }
1568
- if (!acc.pluginDeps[cur.curModule]) {
1569
- acc.pluginDeps[cur.curModule] = [];
1496
+ if (!acc[cur.curModule]) {
1497
+ acc[cur.curModule] = {};
1570
1498
  }
1571
1499
  if (cur.curModule === cur.depModule) {
1572
1500
  return acc;
1573
1501
  }
1574
- if (cur.resolvedPath && isJsLike(cur.resolvedPath) && cur.type === 'game') {
1575
- acc.packageDeps[cur.curModule][cur.resolvedPath] = cur.depModule;
1576
- }
1577
- else if (cur.type === 'plugin') {
1578
- acc.pluginDeps[cur.curModule].push(cur.depModule);
1502
+ if (cur.resolvedPath && isJsLike(cur.resolvedPath)) {
1503
+ acc[cur.curModule] = Object.assign(Object.assign({}, acc[cur.curModule]), { [cur.resolvedPath]: cur.depModule });
1579
1504
  }
1580
1505
  return acc;
1581
- }, {
1582
- packageDeps: {},
1583
- pluginDeps: {},
1584
- });
1506
+ }, {});
1585
1507
  return result;
1586
1508
  }
1587
1509
  function getRootPrefixes(gameEntry) {
@@ -1627,7 +1549,7 @@ async function pack({ gameEntry, pkgName, allDeps, allMaps, pkgConfig, destRoot,
1627
1549
  const packMap = allMaps[pkgName];
1628
1550
  const moduleConfig = {
1629
1551
  main: pkgConfig.main,
1630
- deps: allDeps.packageDeps[pkgName] || {},
1552
+ deps: allDeps[pkgName] || {},
1631
1553
  map: allMaps[pkgName],
1632
1554
  };
1633
1555
  ensureDirSync(destRoot);
@@ -1678,8 +1600,7 @@ async function pack({ gameEntry, pkgName, allDeps, allMaps, pkgConfig, destRoot,
1678
1600
  // });
1679
1601
  // const code = fs.readFileSync(absPath, 'utf-8');
1680
1602
  const fileId = relPath.replace(/\\/g, '/');
1681
- const schema = config.build.type === 'plugin' ? 'plugin' : 'game';
1682
- const defineHeader = `define("${schema}:${fileId}", ["require", "requireAsync", "module", "exports", "sandboxGlobal"], function(require, requireAsync, module, exports, sandboxGlobal){\nwith(sandboxGlobal){\n`;
1603
+ const defineHeader = `define("game:${fileId}", ["require", "requireAsync", "module", "exports", "sandboxGlobal"], function(require, requireAsync, module, exports, sandboxGlobal){\nwith(sandboxGlobal){\n`;
1683
1604
  const defineFooter = `\n}\n});\n`;
1684
1605
  const fileMagic = new MagicString(code, { filename: fileId });
1685
1606
  fileMagic.prepend(defineHeader);
@@ -1766,35 +1687,6 @@ async function partition({ pkgRoot, destRoot, packedFiles, gameEntry, gameOutput
1766
1687
  }
1767
1688
  }
1768
1689
 
1769
- async function addDepsToPackages(gameEntry, outputDir, allDeps) {
1770
- const gamePackConfigPath = path.join(outputDir, GAME_PACK_CONFIG_FILE_NAME);
1771
- const gameJsonPath = path.join(gameEntry, GAME_ORIGIN_CONFIG_FILE_NAME);
1772
- const gamePackConfig = JSON.parse(fs.readFileSync(gamePackConfigPath, 'utf-8'));
1773
- const gameJson = JSON.parse(fs.readFileSync(gameJsonPath, 'utf-8'));
1774
- const pluginConfig = gameJson.plugins;
1775
- Object.entries(allDeps).forEach(([pkgName, plugins]) => {
1776
- plugins.forEach(pluginName => {
1777
- if (pluginConfig[pluginName]) {
1778
- const version = pluginConfig[pluginName].version;
1779
- gamePackConfig.packages[pkgName].dependencies.push(`${pluginName}_${version}`);
1780
- if (!gamePackConfig.packages[`${pluginName}_${version}`]) {
1781
- gamePackConfig.packages[`${pluginName}_${version}`] = {
1782
- url: `https://connect.tiktok-minis.com/test/${pluginName}_${version}.txt`,
1783
- md5: '1230b603dd35b502b66fe204c4b613ff',
1784
- root: `${pluginName}_${version}`,
1785
- main: '',
1786
- output: `${pluginName}_${version}${STTPKG_EXT}`,
1787
- independent: false,
1788
- type: 'plugin',
1789
- dependencies: []
1790
- };
1791
- }
1792
- }
1793
- });
1794
- });
1795
- fs.writeFileSync(gamePackConfigPath, JSON.stringify(gamePackConfig, null, 2));
1796
- }
1797
-
1798
1690
  function getSkipDirs({ packages, entryDir, }) {
1799
1691
  const skipDirs = [];
1800
1692
  if (packages) {
@@ -1812,7 +1704,6 @@ async function makePkgs({ gameEntry, gameOutput, config, }) {
1812
1704
  logger.info(`pack start,startTime:${startTime}`);
1813
1705
  const { packages } = await setup(gameEntry, gameOutput);
1814
1706
  const allDeps = collectDeps(gameEntry, packages);
1815
- await addDepsToPackages(gameEntry, gameOutput, allDeps.pluginDeps);
1816
1707
  const allMaps = collectMaps(gameEntry, packages);
1817
1708
  const pkgOutput = {};
1818
1709
  /**
@@ -1862,46 +1753,6 @@ async function makePkgs({ gameEntry, gameOutput, config, }) {
1862
1753
  logger.info(`pack end,duration:${Date.now() - startTime}ms`);
1863
1754
  return pkgOutput;
1864
1755
  }
1865
- async function makePlugin({ gameEntry, gameOutput, config, }) {
1866
- try {
1867
- const pluginConfig = fs.readFileSync(path.join(gameEntry, 'plugin.json'), 'utf-8');
1868
- const { name, main, version } = JSON.parse(pluginConfig);
1869
- const pluginName = `${name}_${version}`;
1870
- // 把 entryDir 下的所有文件复制到 entryDir/plugin
1871
- const pluginDir = path.join(gameEntry, pluginName);
1872
- copyDirectory(gameEntry, pluginDir);
1873
- const packages = {
1874
- [pluginName]: {
1875
- url: '',
1876
- md5: '',
1877
- root: pluginName,
1878
- main,
1879
- output: `${pluginName}${STTPKG_EXT}`,
1880
- type: 'game',
1881
- dependencies: []
1882
- }
1883
- };
1884
- fs.writeFileSync(path.join(gameOutput, GAME_PACK_CONFIG_FILE_NAME), JSON.stringify({ packages }, null, 2));
1885
- const pluginEntry = path.join(gameEntry, pluginName);
1886
- const allMaps = collectPluginMaps(gameEntry, pluginEntry, pluginName);
1887
- await pack({
1888
- gameEntry,
1889
- allDeps: {
1890
- packageDeps: {},
1891
- pluginDeps: {},
1892
- },
1893
- allMaps,
1894
- pkgName: pluginName,
1895
- pkgConfig: packages[pluginName],
1896
- destRoot: path.join(gameOutput, pluginName, packages[pluginName].root),
1897
- config,
1898
- });
1899
- }
1900
- catch (error) {
1901
- logger.error('plugin.json 不存在');
1902
- return;
1903
- }
1904
- }
1905
1756
 
1906
1757
  /**
1907
1758
  * 将 packages 中的每个 package 下的文件内容合并到 outputDir 下,不保留 package name
@@ -2017,15 +1868,10 @@ async function debugPkgs(originConfig) {
2017
1868
  }
2018
1869
 
2019
1870
  async function buildPkgs(originConfig) {
2020
- var _a;
2021
- if (((_a = originConfig === null || originConfig === void 0 ? void 0 : originConfig.build) === null || _a === void 0 ? void 0 : _a.type) === 'plugin') {
2022
- await buildPlugin(originConfig);
2023
- return;
2024
- }
2025
1871
  const { entry: entryDir, output: outputDir, build } = originConfig;
2026
1872
  let startTime = Date.now();
2027
1873
  logger.init(outputDir, true);
2028
- logger.info(`TTMG_PACK_VERSION: ${"0.2.7-requirePlugin.7"}`);
1874
+ logger.info(`TTMG_PACK_VERSION: ${"0.2.8-beta.1"}`);
2029
1875
  logger.info(`pack start, startTime:${startTime}`);
2030
1876
  const config = overrideConfig(entryDir, originConfig);
2031
1877
  /**
@@ -2054,31 +1900,6 @@ async function buildPkgs(originConfig) {
2054
1900
  }
2055
1901
  logger.info(`pack end:${Date.now() - startTime}ms`);
2056
1902
  }
2057
- async function buildPlugin(originConfig) {
2058
- const { entry: entryDir, output: outputDir, build } = originConfig;
2059
- let startTime = Date.now();
2060
- logger.init(outputDir, true);
2061
- logger.info(`TTMG_PACK_VERSION: ${"0.2.7-requirePlugin.7"}`);
2062
- logger.info(`pack start, startTime:${startTime}`);
2063
- /**
2064
- * 打包
2065
- */
2066
- await makePlugin({
2067
- config: originConfig,
2068
- gameEntry: entryDir,
2069
- gameOutput: outputDir,
2070
- });
2071
- if (build === null || build === void 0 ? void 0 : build.enableOdr) {
2072
- /**
2073
- * 等待文件全部读写完成后
2074
- */
2075
- await makeOdrPkgs(outputDir);
2076
- /**
2077
- * 分拆 odr 包
2078
- */
2079
- }
2080
- logger.info(`pack end:${Date.now() - startTime}ms`);
2081
- }
2082
1903
 
2083
1904
  async function getPkgs({ entryDir, }) {
2084
1905
  const independentPackages = getIndependentPackagesConfig(entryDir);