@anrans001/ttmg-cli 0.3.6-beta.wasmcode.split.3
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/README.md +47 -0
- package/dist/index.js +11850 -0
- package/dist/index.js.map +1 -0
- package/dist/openDataContext/template/open_context.html.hbs +29 -0
- package/dist/openDataContext/template/open_context_sdk.js.hbs +16 -0
- package/dist/package.json +88 -0
- package/dist/public/assets/baseForm-BlSwM0cZ.js +10 -0
- package/dist/public/assets/baseForm-BlSwM0cZ.js.br +0 -0
- package/dist/public/assets/baseForm-DzWBZ1nI.css +1 -0
- package/dist/public/assets/baseForm-DzWBZ1nI.css.br +0 -0
- package/dist/public/assets/icon-DcfeE9nw.svg +8 -0
- package/dist/public/assets/index-4ojiQYTH.js +1 -0
- package/dist/public/assets/index-9LGhLiO-.js +1 -0
- package/dist/public/assets/index-9LGhLiO-.js.br +0 -0
- package/dist/public/assets/index-B0rEQNzZ.js +1 -0
- package/dist/public/assets/index-B6DYsrdP.js +1 -0
- package/dist/public/assets/index-BFPQPvSA.css +1 -0
- package/dist/public/assets/index-BLfeu5YF.css +1 -0
- package/dist/public/assets/index-BPf4cmgA.css +1 -0
- package/dist/public/assets/index-BSpAncbU.css +1 -0
- package/dist/public/assets/index-BqGAmMye.css +1 -0
- package/dist/public/assets/index-C1wJuGuX.js +1 -0
- package/dist/public/assets/index-C1wJuGuX.js.br +0 -0
- package/dist/public/assets/index-C7C5ulLg.css +1 -0
- package/dist/public/assets/index-C7TANh6s.js +1 -0
- package/dist/public/assets/index-CFcABxBe.css +1 -0
- package/dist/public/assets/index-CK_U0Hdx.js +1 -0
- package/dist/public/assets/index-CKw1GdOh.js +1 -0
- package/dist/public/assets/index-CMVdacE6.js +1 -0
- package/dist/public/assets/index-CkUQlQ6l.js +1 -0
- package/dist/public/assets/index-Cr-wghsi.css +1 -0
- package/dist/public/assets/index-Cr-wghsi.css.br +0 -0
- package/dist/public/assets/index-CtaSaIq7.css +1 -0
- package/dist/public/assets/index-D-vT04G4.js +1 -0
- package/dist/public/assets/index-D1Hppiwz.js +1 -0
- package/dist/public/assets/index-DOmSn_x5.js +59 -0
- package/dist/public/assets/index-DOmSn_x5.js.br +0 -0
- package/dist/public/assets/index-DXFg6tGR.css +1 -0
- package/dist/public/assets/index-D_31QZCr.js +1 -0
- package/dist/public/assets/index-D_31QZCr.js.br +0 -0
- package/dist/public/assets/index-Dcdc0Lzb.css +1 -0
- package/dist/public/assets/index-DeQT3JAU.css +1 -0
- package/dist/public/assets/index-DqFmR7Qk.css +1 -0
- package/dist/public/assets/index-DsIb6ZUl.css +1 -0
- package/dist/public/assets/index-DsyAl3FY.js +1 -0
- package/dist/public/assets/index-DsyAl3FY.js.br +0 -0
- package/dist/public/assets/index-G1jifyp4.js +1 -0
- package/dist/public/assets/index-GaMxCcrF.js +1 -0
- package/dist/public/assets/index-Rm6ShNzz.css +1 -0
- package/dist/public/assets/index-Rm6ShNzz.css.br +0 -0
- package/dist/public/assets/index-Wj_kzecB.js +1 -0
- package/dist/public/assets/index-XY8Gg_WJ.css +1 -0
- package/dist/public/assets/index-XY8Gg_WJ.css.br +0 -0
- package/dist/public/assets/index-e6cINrNl.js +1 -0
- package/dist/public/assets/index-e6cINrNl.js.br +0 -0
- package/dist/public/assets/index-gJcsWhoa.css +1 -0
- package/dist/public/assets/index-tReoEVof.css +1 -0
- package/dist/public/assets/isPlainObject-Bjx6qRk8.js +1 -0
- package/dist/public/assets/times-G9laB4vc.js +1 -0
- package/dist/public/icon.svg +8 -0
- package/dist/public/index.html +68 -0
- package/dist/public/scripts/krypton.js +11 -0
- package/dist/public/scripts/ttmg-core.js +24 -0
- package/dist/scripts/build.js +23 -0
- package/dist/scripts/dev-debug.js +191 -0
- package/dist/scripts/resetLocalState.js +48 -0
- package/dist/scripts/setup.js +30 -0
- package/dist/scripts/test-protocol.js +29 -0
- package/dist/scripts/test-regression.js +94 -0
- package/dist/scripts/test-regression.ts +93 -0
- package/dist/scripts/worker.js +263 -0
- package/package.json +88 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
3
|
+
const url = require('url');
|
|
4
|
+
|
|
5
|
+
console.log('--- Protocol Compatibility Test ---');
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
// Test 1: SOCKS5 URI (Should technically fail with HttpsProxyAgent if it doesn't support socks under the hood,
|
|
9
|
+
// but HttpsProxyAgent v5 *might* only support http/https. Let's verify.)
|
|
10
|
+
// Actually, `https-proxy-agent` is specifically for HTTP CONNECT tunneling.
|
|
11
|
+
// If user passes `socks5://...`, does it throw or just fail at runtime?
|
|
12
|
+
const socksProxy = 'socks5://127.0.0.1:1080';
|
|
13
|
+
console.log(`Trying to create HttpsProxyAgent with: ${socksProxy}`);
|
|
14
|
+
|
|
15
|
+
// NOTE: HttpsProxyAgent v5 constructor parses the URL.
|
|
16
|
+
// If protocol is not supported, it might behavior unexpectedly.
|
|
17
|
+
const agent = new HttpsProxyAgent(socksProxy);
|
|
18
|
+
console.log('✅ Agent created successfully (Constructor did not throw).');
|
|
19
|
+
console.log(' Agent protocol:', agent.proxy.protocol);
|
|
20
|
+
|
|
21
|
+
if (agent.proxy.protocol !== 'http:' && agent.proxy.protocol !== 'https:') {
|
|
22
|
+
console.log('⚠️ Warning: Protocol is not http/https. Runtime connection might fail if library doesn\'t support it.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.log('❌ Constructor threw error for SOCKS5:', err.message);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log('--- Test End ---');
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
6
|
+
|
|
7
|
+
const MOCK_CONFIG_PATH = path.join(process.cwd(), '.ttmgrc_test_regression');
|
|
8
|
+
|
|
9
|
+
function getTTMGRC() {
|
|
10
|
+
if (!fs.existsSync(MOCK_CONFIG_PATH)) return null;
|
|
11
|
+
return JSON.parse(fs.readFileSync(MOCK_CONFIG_PATH, 'utf8'));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function setTTMGRC(config) {
|
|
15
|
+
const origin = getTTMGRC() || {};
|
|
16
|
+
// Simulate CLI logic: merging new config into old
|
|
17
|
+
const merged = { ...origin, ...config };
|
|
18
|
+
// If config value is undefined, it won't remove key in JSON.stringify unless we manipulate it
|
|
19
|
+
// In `config.ts`: `setTTMGRC({ proxy: undefined })` -> JSON.stringify will OMIT the key if value is strictly undefined
|
|
20
|
+
fs.writeFileSync(MOCK_CONFIG_PATH, JSON.stringify(merged));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getAxiosProxyConfig() {
|
|
24
|
+
const config = getTTMGRC();
|
|
25
|
+
const proxyUrl = config ? config.proxy : undefined;
|
|
26
|
+
if (proxyUrl) {
|
|
27
|
+
return {
|
|
28
|
+
httpsAgent: new HttpsProxyAgent(proxyUrl),
|
|
29
|
+
httpAgent: new HttpsProxyAgent(proxyUrl),
|
|
30
|
+
proxy: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {}; // Important: return empty object means "use axios defaults"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function testRegression() {
|
|
37
|
+
console.log('--- Starting Regression Test (JS) ---');
|
|
38
|
+
|
|
39
|
+
if (fs.existsSync(MOCK_CONFIG_PATH)) fs.unlinkSync(MOCK_CONFIG_PATH);
|
|
40
|
+
|
|
41
|
+
// 1. Default (No Config)
|
|
42
|
+
console.log('Testing default state (no proxy config)...');
|
|
43
|
+
const defaultConfig = getAxiosProxyConfig();
|
|
44
|
+
if (Object.keys(defaultConfig).length === 0) {
|
|
45
|
+
console.log('✅ Default config is empty (Axios defaults apply).');
|
|
46
|
+
} else {
|
|
47
|
+
console.error('❌ Default config is NOT empty.');
|
|
48
|
+
console.log(defaultConfig);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 2. Set Proxy
|
|
53
|
+
const testProxy = 'http://127.0.0.1:7890';
|
|
54
|
+
console.log(`Setting proxy to ${testProxy}...`);
|
|
55
|
+
setTTMGRC({ proxy: testProxy });
|
|
56
|
+
|
|
57
|
+
const activeConfig = getAxiosProxyConfig();
|
|
58
|
+
if (activeConfig.proxy === false) {
|
|
59
|
+
console.log('✅ Proxy configured correctly.');
|
|
60
|
+
} else {
|
|
61
|
+
console.error('❌ Proxy config failed.');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 3. Delete Proxy
|
|
66
|
+
console.log('Deleting proxy config...');
|
|
67
|
+
setTTMGRC({ proxy: undefined });
|
|
68
|
+
|
|
69
|
+
// Verify file content
|
|
70
|
+
const fileContent = fs.readFileSync(MOCK_CONFIG_PATH, 'utf8');
|
|
71
|
+
if (!fileContent.includes('"proxy"')) {
|
|
72
|
+
console.log('✅ Proxy key removed from JSON file.');
|
|
73
|
+
} else {
|
|
74
|
+
console.log('⚠️ Proxy key still present in JSON (might be null or undefined value).');
|
|
75
|
+
console.log(' File content:', fileContent);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const revertedConfig = getAxiosProxyConfig();
|
|
79
|
+
if (Object.keys(revertedConfig).length === 0) {
|
|
80
|
+
console.log('✅ Reverted to default state successfully (Axios defaults apply).');
|
|
81
|
+
} else {
|
|
82
|
+
console.error('❌ Revert failed. Config still active:');
|
|
83
|
+
console.log(revertedConfig);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (fs.existsSync(MOCK_CONFIG_PATH)) fs.unlinkSync(MOCK_CONFIG_PATH);
|
|
88
|
+
console.log('--- Regression Test Passed ---');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
testRegression().catch(err => {
|
|
92
|
+
console.error(err);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
6
|
+
|
|
7
|
+
// Mock TTMGRC logic
|
|
8
|
+
const MOCK_CONFIG_PATH = path.join(process.cwd(), '.ttmgrc_test_regression');
|
|
9
|
+
|
|
10
|
+
function getTTMGRC() {
|
|
11
|
+
if (!fs.existsSync(MOCK_CONFIG_PATH)) return null;
|
|
12
|
+
return JSON.parse(fs.readFileSync(MOCK_CONFIG_PATH, 'utf8'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function setTTMGRC(config: any) {
|
|
16
|
+
const origin = getTTMGRC() || {};
|
|
17
|
+
fs.writeFileSync(MOCK_CONFIG_PATH, JSON.stringify({ ...origin, ...config }));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Replicate request.ts logic
|
|
21
|
+
function getAxiosProxyConfig() {
|
|
22
|
+
const config = getTTMGRC();
|
|
23
|
+
const proxyUrl = config?.proxy;
|
|
24
|
+
if (proxyUrl) {
|
|
25
|
+
return {
|
|
26
|
+
httpsAgent: new HttpsProxyAgent(proxyUrl),
|
|
27
|
+
httpAgent: new HttpsProxyAgent(proxyUrl),
|
|
28
|
+
proxy: false as const,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function testRegression() {
|
|
35
|
+
console.log('--- Starting Regression Test ---');
|
|
36
|
+
|
|
37
|
+
// 1. Cleanup
|
|
38
|
+
if (fs.existsSync(MOCK_CONFIG_PATH)) fs.unlinkSync(MOCK_CONFIG_PATH);
|
|
39
|
+
|
|
40
|
+
// 2. Default State (No Config)
|
|
41
|
+
console.log('Testing default state (no proxy config)...');
|
|
42
|
+
const defaultConfig = getAxiosProxyConfig();
|
|
43
|
+
if (Object.keys(defaultConfig).length === 0) {
|
|
44
|
+
console.log('✅ Default config is empty (Axios will use env vars by default).');
|
|
45
|
+
} else {
|
|
46
|
+
console.error('❌ Default config is NOT empty.');
|
|
47
|
+
console.log(defaultConfig);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 3. Set Proxy
|
|
52
|
+
const testProxy = 'http://127.0.0.1:7890';
|
|
53
|
+
console.log(`Setting proxy to ${testProxy}...`);
|
|
54
|
+
setTTMGRC({ proxy: testProxy });
|
|
55
|
+
const activeConfig = getAxiosProxyConfig();
|
|
56
|
+
if (activeConfig.proxy === false) {
|
|
57
|
+
console.log('✅ Proxy configured correctly.');
|
|
58
|
+
} else {
|
|
59
|
+
console.error('❌ Proxy config failed.');
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 4. Delete Proxy (Simulate `ttmg config delete proxy` which sets it to undefined/null)
|
|
64
|
+
console.log('Deleting proxy config...');
|
|
65
|
+
setTTMGRC({ proxy: undefined }); // In JSON.stringify, undefined fields are omitted
|
|
66
|
+
|
|
67
|
+
// Verify file content actually lacks "proxy"
|
|
68
|
+
const fileContent = fs.readFileSync(MOCK_CONFIG_PATH, 'utf8');
|
|
69
|
+
if (fileContent.includes('"proxy"')) {
|
|
70
|
+
// If setTTMGRC implementation merges, we might need to explicitly set to null or check merge logic
|
|
71
|
+
// In the mock above: { ...origin, ...config }. If config has {proxy: undefined}, it overrides?
|
|
72
|
+
// JSON.stringify({a:1, b:undefined}) -> "{\"a\":1}"
|
|
73
|
+
console.log(' (Proxy key removed from JSON)');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const revertedConfig = getAxiosProxyConfig();
|
|
77
|
+
if (Object.keys(revertedConfig).length === 0) {
|
|
78
|
+
console.log('✅ Reverted to default state successfully.');
|
|
79
|
+
} else {
|
|
80
|
+
console.error('❌ Revert failed. Config still active:');
|
|
81
|
+
console.log(revertedConfig);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 5. Cleanup
|
|
86
|
+
if (fs.existsSync(MOCK_CONFIG_PATH)) fs.unlinkSync(MOCK_CONFIG_PATH);
|
|
87
|
+
console.log('--- Regression Test Passed ---');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
testRegression().catch(err => {
|
|
91
|
+
console.error(err);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
});
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子线程进行编译(Worker)
|
|
3
|
+
*/
|
|
4
|
+
const { debugPkgs } = require('ttmg-pack');
|
|
5
|
+
const https = require('https');
|
|
6
|
+
const chalk = require('chalk');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const semver = require('semver');
|
|
10
|
+
const { parentPort } = require('worker_threads');
|
|
11
|
+
const { execSync } = require('child_process');
|
|
12
|
+
|
|
13
|
+
const messages = {
|
|
14
|
+
'en-US': {
|
|
15
|
+
'worker.compile.missingClientKey': 'Missing clientKey',
|
|
16
|
+
'worker.compile.tempDir': 'Game local debug assets temp directory: {dir}',
|
|
17
|
+
'worker.compile.initOutputFailed':
|
|
18
|
+
'Failed to initialize output directory: {error}',
|
|
19
|
+
'worker.compile.buildFailed': 'Build failed',
|
|
20
|
+
'worker.update.noGlobalInstall': 'Global install of {pkgName} was not detected',
|
|
21
|
+
'worker.update.available': 'Update available!',
|
|
22
|
+
'worker.update.changelog': 'Changelog:',
|
|
23
|
+
'worker.update.toUpdate': 'To update, run:',
|
|
24
|
+
},
|
|
25
|
+
'zh-CN': {
|
|
26
|
+
'worker.compile.missingClientKey': '缺少 clientKey',
|
|
27
|
+
'worker.compile.tempDir': '游戏本地调试资源临时目录:{dir}',
|
|
28
|
+
'worker.compile.initOutputFailed': '初始化输出目录失败:{error}',
|
|
29
|
+
'worker.compile.buildFailed': '构建失败',
|
|
30
|
+
'worker.update.noGlobalInstall': '未检测到全局安装的 {pkgName}',
|
|
31
|
+
'worker.update.available': '检测到可用更新!',
|
|
32
|
+
'worker.update.changelog': '更新日志:',
|
|
33
|
+
'worker.update.toUpdate': '执行以下命令升级:',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
let currentLang = 'en-US';
|
|
38
|
+
|
|
39
|
+
function setWorkerLanguage(lang) {
|
|
40
|
+
currentLang = lang === 'zh-CN' ? 'zh-CN' : 'en-US';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function t(key, params = {}) {
|
|
44
|
+
const template =
|
|
45
|
+
(messages[currentLang] && messages[currentLang][key]) ||
|
|
46
|
+
messages['en-US'][key] ||
|
|
47
|
+
key;
|
|
48
|
+
return template.replace(/\{(\w+)\}/g, (_, token) => {
|
|
49
|
+
if (params[token] === undefined) return `{${token}}`;
|
|
50
|
+
return String(params[token]);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 获取 npm 最新版本
|
|
56
|
+
*/
|
|
57
|
+
function getLatestVersion(pkgName) {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const req = https.get(
|
|
60
|
+
`https://registry.npmjs.org/${encodeURIComponent(pkgName)}/latest`,
|
|
61
|
+
res => {
|
|
62
|
+
if (res.statusCode && res.statusCode >= 400) {
|
|
63
|
+
// 非 2xx 状态码直接返回 null(不阻断主流程)
|
|
64
|
+
res.resume(); // 消耗流避免 socket 泄漏
|
|
65
|
+
return resolve(null);
|
|
66
|
+
}
|
|
67
|
+
let data = '';
|
|
68
|
+
res.setEncoding('utf8');
|
|
69
|
+
res.on('data', chunk => (data += chunk));
|
|
70
|
+
res.on('end', () => {
|
|
71
|
+
try {
|
|
72
|
+
const info = JSON.parse(data);
|
|
73
|
+
resolve(info?.version ?? null);
|
|
74
|
+
} catch {
|
|
75
|
+
resolve(null);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
res.on('error', () => resolve(null));
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
req.on('error', () => resolve(null));
|
|
82
|
+
req.setTimeout(8000, () => {
|
|
83
|
+
req.destroy();
|
|
84
|
+
resolve(null);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 获取全局已安装版本
|
|
91
|
+
* 显式设置 stdio,避免在 worker/CI/守护环境中继承到非法 fd 触发 EBADF
|
|
92
|
+
*/
|
|
93
|
+
function getGlobalVersion(pkgName) {
|
|
94
|
+
try {
|
|
95
|
+
const output = execSync(`npm ls -g ${pkgName} --depth=0 --json`, {
|
|
96
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
97
|
+
});
|
|
98
|
+
const json = JSON.parse(output);
|
|
99
|
+
return json?.dependencies?.[pkgName]?.version ?? null;
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function compile(context = {}) {
|
|
106
|
+
try {
|
|
107
|
+
const { clientKey, outputDir, entryDir, devPort, mode, lang } = context;
|
|
108
|
+
setWorkerLanguage(lang);
|
|
109
|
+
|
|
110
|
+
// 参数校验
|
|
111
|
+
if (!clientKey) {
|
|
112
|
+
const message = t('worker.compile.missingClientKey');
|
|
113
|
+
if (mode !== 'watch') {
|
|
114
|
+
parentPort?.postMessage({ type: 'error', error: message });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
throw new Error(message);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 输出目录重建
|
|
121
|
+
try {
|
|
122
|
+
console.log(
|
|
123
|
+
chalk(
|
|
124
|
+
`🔍 ${t('worker.compile.tempDir', {
|
|
125
|
+
dir: chalk.yellow.underline(outputDir),
|
|
126
|
+
})}`,
|
|
127
|
+
),
|
|
128
|
+
);
|
|
129
|
+
if (fs.existsSync(outputDir)) {
|
|
130
|
+
fs.rmSync(outputDir, { recursive: true, force: true });
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
// 目录操作失败也上报
|
|
134
|
+
parentPort?.postMessage({
|
|
135
|
+
type: 'error',
|
|
136
|
+
error: t('worker.compile.initOutputFailed', {
|
|
137
|
+
error: e?.message || e,
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
parentPort?.postMessage({ type: 'status', status: 'start' });
|
|
144
|
+
|
|
145
|
+
// 调用打包
|
|
146
|
+
const { isSuccess, errorMsg, packages } = await debugPkgs({
|
|
147
|
+
entry: entryDir,
|
|
148
|
+
output: outputDir,
|
|
149
|
+
dev: {
|
|
150
|
+
enable: true,
|
|
151
|
+
port: devPort,
|
|
152
|
+
host: 'localhost',
|
|
153
|
+
enableSourcemap: true,
|
|
154
|
+
enableLog: false,
|
|
155
|
+
},
|
|
156
|
+
build: {
|
|
157
|
+
enableAPICheck: true,
|
|
158
|
+
enableOdr: false,
|
|
159
|
+
pkgSizeLimit: 30 * 1024 * 1024,
|
|
160
|
+
mainPkgSizeLimit: 4 * 1024 * 1024,
|
|
161
|
+
independentSubPkgSizeLimit: 4 * 1024 * 1024,
|
|
162
|
+
},
|
|
163
|
+
// 如果 ttmg-pack 支持透传选项,可考虑加上 stdio/并发等设置:
|
|
164
|
+
// spawnOptions: { stdio: ['ignore', 'pipe', 'pipe'] },
|
|
165
|
+
// concurrency: 4,
|
|
166
|
+
}, {
|
|
167
|
+
lang,
|
|
168
|
+
});
|
|
169
|
+
if (fs.existsSync(path.join(outputDir, '__TTMG_TEMP__'))) {
|
|
170
|
+
fs.rmSync(path.join(outputDir, '__TTMG_TEMP__'), {
|
|
171
|
+
recursive: true,
|
|
172
|
+
force: true,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (!isSuccess) {
|
|
177
|
+
parentPort?.postMessage({
|
|
178
|
+
type: 'status',
|
|
179
|
+
status: 'end',
|
|
180
|
+
isSuccess: false,
|
|
181
|
+
errorMsg: errorMsg || t('worker.compile.buildFailed'),
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
parentPort?.postMessage({
|
|
185
|
+
type: 'status',
|
|
186
|
+
status: 'end',
|
|
187
|
+
isSuccess: true,
|
|
188
|
+
packages,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
} catch (err) {
|
|
192
|
+
parentPort?.postMessage({
|
|
193
|
+
type: 'error',
|
|
194
|
+
error: err?.message || String(err),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function checkUpdate(context = {}) {
|
|
200
|
+
try {
|
|
201
|
+
setWorkerLanguage(context?.lang);
|
|
202
|
+
const pkgName = '@anrans001/ttmg-cli';
|
|
203
|
+
const [oldVersion, newVersion] = await Promise.all([
|
|
204
|
+
getGlobalVersion(pkgName),
|
|
205
|
+
getLatestVersion(pkgName),
|
|
206
|
+
]);
|
|
207
|
+
|
|
208
|
+
if (!newVersion) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!oldVersion) {
|
|
213
|
+
console.log(
|
|
214
|
+
chalk.yellow(t('worker.update.noGlobalInstall', { pkgName })),
|
|
215
|
+
);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (oldVersion === newVersion) return;
|
|
220
|
+
|
|
221
|
+
const oldVersionIsBeta = oldVersion.includes('beta');
|
|
222
|
+
const newVersionIsBeta = newVersion.includes('beta');
|
|
223
|
+
if (oldVersionIsBeta && newVersionIsBeta) return;
|
|
224
|
+
|
|
225
|
+
const oldVersionMajor = semver.major(oldVersion);
|
|
226
|
+
const newVersionMajor = semver.major(newVersion);
|
|
227
|
+
if (oldVersionIsBeta && oldVersionMajor >= newVersionMajor) return;
|
|
228
|
+
|
|
229
|
+
const message = `
|
|
230
|
+
${chalk.bold(t('worker.update.available'))} ${chalk.red(oldVersion)} ${chalk.white('→')} ${chalk.green(newVersion)}.
|
|
231
|
+
${chalk.magenta(t('worker.update.changelog'))} ${chalk.cyan(`https://npmjs.com/package/${pkgName}/v/${newVersion}`)}
|
|
232
|
+
${t('worker.update.toUpdate')} ${chalk.magenta(`npm i -g ${pkgName}`)}
|
|
233
|
+
`.trim();
|
|
234
|
+
|
|
235
|
+
// 动态引入 boxen,避免主线程初始化时不必要的 require
|
|
236
|
+
const boxen = require('boxen').default;
|
|
237
|
+
console.log(
|
|
238
|
+
boxen(message, {
|
|
239
|
+
padding: 1,
|
|
240
|
+
margin: 1,
|
|
241
|
+
borderStyle: 'round',
|
|
242
|
+
borderColor: 'yellowBright',
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
} catch (e) {
|
|
246
|
+
// 更新检查失败不影响主流程
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// worker 入口
|
|
251
|
+
if (parentPort) {
|
|
252
|
+
parentPort.on('message', async msg => {
|
|
253
|
+
try {
|
|
254
|
+
if (msg?.type === 'compile') {
|
|
255
|
+
await compile(msg.context);
|
|
256
|
+
} else if (msg?.type === 'checkUpdate') {
|
|
257
|
+
await checkUpdate({ lang: msg?.lang });
|
|
258
|
+
}
|
|
259
|
+
} catch (e) {
|
|
260
|
+
parentPort.postMessage({ type: 'error', error: e?.message || String(e) });
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@anrans001/ttmg-cli",
|
|
3
|
+
"version": "0.3.6-beta.wasmcode.split.3",
|
|
4
|
+
"description": "TikTok Mini Game Command Line Tool (anrans001 fork for testing)",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ttmg": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"prepublish": "npm run build",
|
|
17
|
+
"build": "node scripts/build.js",
|
|
18
|
+
"setup": "node scripts/setup.js",
|
|
19
|
+
"reset:local-state": "node scripts/resetLocalState.js",
|
|
20
|
+
"dev:link": "npm run build && npm link",
|
|
21
|
+
"dev:debug": "node scripts/dev-debug.js"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"TTMG",
|
|
25
|
+
"Mini Games"
|
|
26
|
+
],
|
|
27
|
+
"author": "zhanghongyang.mocha",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"acorn": "^8.15.0",
|
|
30
|
+
"archiver": "^7.0.1",
|
|
31
|
+
"axios": "^1.11.0",
|
|
32
|
+
"boxen": "^6.2.1",
|
|
33
|
+
"chalk": "^4.1.2",
|
|
34
|
+
"cheerio": "^1.1.1",
|
|
35
|
+
"chokidar": "^4.0.3",
|
|
36
|
+
"chrome-launcher": "^1.2.0",
|
|
37
|
+
"chrome-remote-interface": "^0.33.3",
|
|
38
|
+
"commander": "^11.1.0",
|
|
39
|
+
"esbuild": "^0.25.9",
|
|
40
|
+
"estraverse": "^5.3.0",
|
|
41
|
+
"express": "4.18.2",
|
|
42
|
+
"express-fileupload": "1.5.2",
|
|
43
|
+
"express-static-gzip": "^3.0.0",
|
|
44
|
+
"form-data": "^4.0.4",
|
|
45
|
+
"glob": "^11.0.3",
|
|
46
|
+
"got": "^11.8.5",
|
|
47
|
+
"handlebars": "4.7.8",
|
|
48
|
+
"https-proxy-agent": "^5.0.1",
|
|
49
|
+
"inquirer": "^12.7.0",
|
|
50
|
+
"jsdom": "^26.1.0",
|
|
51
|
+
"mime-types": "^3.0.1",
|
|
52
|
+
"multer": "^2.0.2",
|
|
53
|
+
"open": "^10.2.0",
|
|
54
|
+
"ora": "^9.0.0",
|
|
55
|
+
"p-limit": "5.0.0",
|
|
56
|
+
"prettier": "^3.6.2",
|
|
57
|
+
"qs": "6.12.1",
|
|
58
|
+
"semver": "^7.7.2",
|
|
59
|
+
"socks-proxy-agent": "^9.0.0",
|
|
60
|
+
"ttmg-pack": "0.4.8",
|
|
61
|
+
"ws": "^8.18.3",
|
|
62
|
+
"@anrans001/ttmg-wasmtool": "^0.3.2"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@babel/core": "^7.28.3",
|
|
66
|
+
"@babel/preset-env": "^7.28.3",
|
|
67
|
+
"@rollup/plugin-alias": "^5.1.1",
|
|
68
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
69
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
70
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
71
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
72
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
73
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
74
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
75
|
+
"@types/node": "^24.2.0",
|
|
76
|
+
"compression": "^1.8.1",
|
|
77
|
+
"eslint": "^9.31.0",
|
|
78
|
+
"rollup": "^4.46.4",
|
|
79
|
+
"rollup-plugin-copy": "3.5.0",
|
|
80
|
+
"rollup-plugin-visualizer": "^6.0.3",
|
|
81
|
+
"ts-node": "^10.9.2",
|
|
82
|
+
"tsconfig-paths": "^4.2.0",
|
|
83
|
+
"typescript": "^5.9.2"
|
|
84
|
+
},
|
|
85
|
+
"engines": {
|
|
86
|
+
"node": ">=20.19.1 <21 || >=22"
|
|
87
|
+
}
|
|
88
|
+
}
|