@playcraft/build 0.0.48 → 0.0.49
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.
|
@@ -15,8 +15,12 @@ export declare class PlayableScriptsAdapter {
|
|
|
15
15
|
private projectDir;
|
|
16
16
|
private options;
|
|
17
17
|
private config?;
|
|
18
|
+
private projectBuildsConfig?;
|
|
18
19
|
private static readonly DEFAULTS;
|
|
19
20
|
constructor(projectDir: string, options: BaseBuildOptions, config?: PlayableScriptsConfig);
|
|
21
|
+
private loadProjectBuildsConfig;
|
|
22
|
+
private resolveObfuscateLevel;
|
|
23
|
+
private resolveFflateCompression;
|
|
20
24
|
/**
|
|
21
25
|
* 执行 playable-scripts 构建
|
|
22
26
|
*
|
|
@@ -49,6 +49,42 @@ export class PlayableScriptsAdapter {
|
|
|
49
49
|
console.log(`[PlayableScriptsAdapter] 目标渠道: ${config.channels.join(', ')}`);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
loadProjectBuildsConfig(configPath) {
|
|
53
|
+
try {
|
|
54
|
+
const resolvedPath = require.resolve(configPath);
|
|
55
|
+
delete require.cache[resolvedPath];
|
|
56
|
+
const loaded = require(resolvedPath);
|
|
57
|
+
if (loaded && typeof loaded === 'object' && !Array.isArray(loaded)) {
|
|
58
|
+
return loaded;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.warn(`[PlayableScriptsAdapter] Failed to read builds.config.js build params, using PlayCraft defaults: ${error instanceof Error ? error.message : String(error)}`);
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
resolveObfuscateLevel() {
|
|
67
|
+
const explicitValue = this.config?.obfuscateLevel;
|
|
68
|
+
if (typeof explicitValue === 'number' && Number.isFinite(explicitValue)) {
|
|
69
|
+
return explicitValue;
|
|
70
|
+
}
|
|
71
|
+
const projectValue = this.projectBuildsConfig?.obfuscateLevel;
|
|
72
|
+
if (typeof projectValue === 'number' && Number.isFinite(projectValue)) {
|
|
73
|
+
return projectValue;
|
|
74
|
+
}
|
|
75
|
+
return PlayableScriptsAdapter.DEFAULTS.obfuscateLevel;
|
|
76
|
+
}
|
|
77
|
+
resolveFflateCompression() {
|
|
78
|
+
const explicitValue = this.config?.fflateCompression;
|
|
79
|
+
if (typeof explicitValue === 'boolean') {
|
|
80
|
+
return explicitValue;
|
|
81
|
+
}
|
|
82
|
+
const projectValue = this.projectBuildsConfig?.fflateCompression;
|
|
83
|
+
if (typeof projectValue === 'boolean') {
|
|
84
|
+
return projectValue;
|
|
85
|
+
}
|
|
86
|
+
return PlayableScriptsAdapter.DEFAULTS.fflateCompression;
|
|
87
|
+
}
|
|
52
88
|
/**
|
|
53
89
|
* 执行 playable-scripts 构建
|
|
54
90
|
*
|
|
@@ -149,10 +185,12 @@ export class PlayableScriptsAdapter {
|
|
|
149
185
|
let configContent;
|
|
150
186
|
try {
|
|
151
187
|
configContent = await fs.readFile(configPath, 'utf-8');
|
|
188
|
+
this.projectBuildsConfig = this.loadProjectBuildsConfig(configPath);
|
|
152
189
|
console.log('[PlayableScriptsAdapter] 读取现有 builds.config.js');
|
|
153
190
|
}
|
|
154
191
|
catch {
|
|
155
192
|
configContent = 'module.exports = {};';
|
|
193
|
+
this.projectBuildsConfig = undefined;
|
|
156
194
|
console.log('[PlayableScriptsAdapter] builds.config.js 不存在,将创建');
|
|
157
195
|
}
|
|
158
196
|
// 构建注入内容
|
|
@@ -225,11 +263,11 @@ export class PlayableScriptsAdapter {
|
|
|
225
263
|
buildCLIArgs() {
|
|
226
264
|
const config = this.config ?? {};
|
|
227
265
|
const args = [];
|
|
228
|
-
// 混淆等级:config 指定 > PlayCraft
|
|
229
|
-
const obfuscateLevel =
|
|
266
|
+
// 混淆等级:config 指定 > 项目 builds.config.js > PlayCraft 默认 4
|
|
267
|
+
const obfuscateLevel = this.resolveObfuscateLevel();
|
|
230
268
|
args.push('--obfuscate-level', `${obfuscateLevel}`);
|
|
231
|
-
// fflate 压缩:config 指定 > PlayCraft
|
|
232
|
-
const fflate =
|
|
269
|
+
// fflate 压缩:config 指定 > 项目 builds.config.js > PlayCraft 默认 true
|
|
270
|
+
const fflate = this.resolveFflateCompression();
|
|
233
271
|
args.push('--fflate-compression', `${fflate}`);
|
|
234
272
|
// 渠道列表
|
|
235
273
|
if (config.channels && config.channels.length > 0) {
|
|
@@ -280,8 +318,8 @@ export class PlayableScriptsAdapter {
|
|
|
280
318
|
// ==================== 3. 日志输出 ====================
|
|
281
319
|
logBuildParams() {
|
|
282
320
|
const config = this.config ?? {};
|
|
283
|
-
const obfuscateLevel =
|
|
284
|
-
const fflate =
|
|
321
|
+
const obfuscateLevel = this.resolveObfuscateLevel();
|
|
322
|
+
const fflate = this.resolveFflateCompression();
|
|
285
323
|
const levelLabels = {
|
|
286
324
|
1: 'minimum - 基础',
|
|
287
325
|
2: 'medium - 中等',
|