@playcraft/build 0.2.15-test-a → 0.2.16-test
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/base-builder.js +2 -41
- package/dist/engines/engine-detector.js +0 -4
- package/dist/engines/generic-adapter.js +19 -14
- package/dist/engines/playable-scripts-adapter.js +5 -2
- package/dist/index.d.ts +4 -21
- package/dist/index.js +2 -12
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.d.ts +0 -4
- package/dist/platforms/base.js +6 -25
- package/dist/platforms/bigo.js +0 -1
- package/dist/platforms/facebook.js +0 -1
- package/dist/platforms/google.js +0 -1
- package/dist/platforms/inmobi.js +0 -1
- package/dist/platforms/ironsource.js +0 -1
- package/dist/platforms/liftoff.js +0 -1
- package/dist/platforms/mintegral.js +0 -1
- package/dist/platforms/moloco.js +0 -1
- package/dist/platforms/playcraft.js +0 -1
- package/dist/platforms/remerge.js +0 -1
- package/dist/platforms/snapchat.js +0 -1
- package/dist/platforms/tiktok.js +0 -1
- package/dist/platforms/unity.js +0 -1
- package/dist/types.d.ts +2 -10
- package/dist/validation/html-validator.d.ts +0 -5
- package/dist/validation/html-validator.js +17 -19
- package/dist/validation/index.d.ts +0 -5
- package/dist/validation/index.js +0 -5
- package/dist/validation/package-validator.d.ts +0 -2
- package/dist/validation/package-validator.js +64 -25
- package/dist/validation/profiles.d.ts +1 -13
- package/dist/validation/profiles.js +0 -27
- package/dist/validation/source-scanner.d.ts +0 -11
- package/dist/validation/source-scanner.js +2 -32
- package/dist/validation/types.d.ts +2 -201
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +2 -22
- package/dist/validation/validation-runner.js +3 -64
- package/dist/validation/zip-reader.d.ts +0 -7
- package/dist/validation/zip-reader.js +26 -159
- package/dist/vite/config-builder-generic.d.ts +1 -3
- package/dist/vite/config-builder-generic.js +7 -9
- package/dist/vite/config-builder.js +1 -1
- package/dist/vite/plugin-platform.js +30 -16
- package/dist/vite/plugin-source-builder.d.ts +14 -2
- package/dist/vite/plugin-source-builder.js +997 -61
- package/dist/vite-builder.d.ts +5 -4
- package/dist/vite-builder.js +34 -33
- package/package.json +4 -30
- package/dist/audio-source-files.d.ts +0 -5
- package/dist/audio-source-files.js +0 -135
- package/dist/delivery/agent-build-runner.d.ts +0 -44
- package/dist/delivery/agent-build-runner.js +0 -365
- package/dist/delivery/agent-build-source.d.ts +0 -8
- package/dist/delivery/agent-build-source.js +0 -25
- package/dist/delivery/artifact-descriptor.d.ts +0 -31
- package/dist/delivery/artifact-descriptor.js +0 -237
- package/dist/delivery/artifact-package.d.ts +0 -43
- package/dist/delivery/artifact-package.js +0 -283
- package/dist/delivery/build-plan.d.ts +0 -4
- package/dist/delivery/build-plan.js +0 -189
- package/dist/delivery/build-plan.types.d.ts +0 -51
- package/dist/delivery/build-plan.types.js +0 -1
- package/dist/delivery/command-isolation.d.ts +0 -21
- package/dist/delivery/command-isolation.js +0 -327
- package/dist/delivery/commands.d.ts +0 -5
- package/dist/delivery/commands.js +0 -146
- package/dist/delivery/files.d.ts +0 -9
- package/dist/delivery/files.js +0 -144
- package/dist/delivery/git-source-fingerprint.d.ts +0 -2
- package/dist/delivery/git-source-fingerprint.js +0 -58
- package/dist/delivery/isolated-source.d.ts +0 -5
- package/dist/delivery/isolated-source.js +0 -131
- package/dist/delivery/output-publication.d.ts +0 -21
- package/dist/delivery/output-publication.js +0 -444
- package/dist/delivery/project-delivery.d.ts +0 -6
- package/dist/delivery/project-delivery.js +0 -287
- package/dist/delivery/recipe-build-plan.d.ts +0 -4
- package/dist/delivery/recipe-build-plan.js +0 -53
- package/dist/delivery/recipe.d.ts +0 -20
- package/dist/delivery/recipe.js +0 -211
- package/dist/delivery/safe-path.d.ts +0 -2
- package/dist/delivery/safe-path.js +0 -18
- package/dist/delivery/types.d.ts +0 -76
- package/dist/delivery/types.js +0 -1
- package/dist/production-animation-presence.d.ts +0 -2
- package/dist/production-animation-presence.js +0 -146
- package/dist/production-inputs.d.ts +0 -30
- package/dist/production-inputs.js +0 -262
- package/dist/production-source-paths.d.ts +0 -5
- package/dist/production-source-paths.js +0 -27
- package/dist/redirect-policy.d.ts +0 -23
- package/dist/redirect-policy.js +0 -25
- package/dist/validation/artifact-qa.d.ts +0 -36
- package/dist/validation/artifact-qa.js +0 -263
- package/dist/validation/artifact-rules.d.ts +0 -39
- package/dist/validation/artifact-rules.js +0 -451
- package/dist/validation/artifact.d.ts +0 -14
- package/dist/validation/artifact.js +0 -188
- package/dist/validation/playwright-driver.d.ts +0 -37
- package/dist/validation/playwright-driver.js +0 -302
- package/dist/validation/runtime-cover.d.ts +0 -32
- package/dist/validation/runtime-cover.js +0 -120
- package/dist/validation/runtime-load.d.ts +0 -141
- package/dist/validation/runtime-load.js +0 -812
- package/dist/vite/source-builder-asset-paths.d.ts +0 -25
- package/dist/vite/source-builder-asset-paths.js +0 -154
- package/dist/vite/source-builder-esm.d.ts +0 -7
- package/dist/vite/source-builder-esm.js +0 -877
- package/dist/vite/source-builder-types.d.ts +0 -14
- package/dist/vite/source-builder-types.js +0 -1
- package/dist/vite/workspace.d.ts +0 -6
- package/dist/vite/workspace.js +0 -41
- package/dist/workspace-css-imports.d.ts +0 -2
- package/dist/workspace-css-imports.js +0 -139
- package/dist/workspace-model-source.d.ts +0 -14
- package/dist/workspace-model-source.js +0 -184
- package/dist/workspace-public-imports.d.ts +0 -11
- package/dist/workspace-public-imports.js +0 -232
- package/dist/workspace-public-source.d.ts +0 -15
- package/dist/workspace-public-source.js +0 -564
- package/templates/patches/playcraft-redirect-policy.js +0 -115
package/dist/base-builder.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter
|
|
2
|
-
import { writeFile } from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { executeProjectDelivery } from './delivery/project-delivery.js';
|
|
1
|
+
import { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter } from './engines/index.js';
|
|
5
2
|
import { formatValidationSummary, hasBlockingValidationErrors, runPlayableValidation, saveValidationReport, } from './validation/index.js';
|
|
6
3
|
/**
|
|
7
4
|
* 基础构建器 - 路由到不同构建工具适配器
|
|
@@ -35,40 +32,6 @@ export class BaseBuilder {
|
|
|
35
32
|
* 根据构建工具路由到对应适配器
|
|
36
33
|
*/
|
|
37
34
|
async build() {
|
|
38
|
-
const explicit = await executeProjectDelivery(this.projectDir, {
|
|
39
|
-
outputDir: this.options.outputDir,
|
|
40
|
-
channel: this.options.validation?.channel,
|
|
41
|
-
format: this.options.format,
|
|
42
|
-
expectedPreparation: this.options.deliveryPreparation,
|
|
43
|
-
});
|
|
44
|
-
if (explicit) {
|
|
45
|
-
const metadata = {
|
|
46
|
-
mode: 'classic',
|
|
47
|
-
engine: 'generic',
|
|
48
|
-
buildTool: 'generic',
|
|
49
|
-
buildOutputDir: explicit.directory,
|
|
50
|
-
deliveryRecipeDigest: explicit.recipeDigest,
|
|
51
|
-
...(explicit.kind === 'channel-package'
|
|
52
|
-
? { skipChannelBuild: true, deliveryArtifact: explicit.entry }
|
|
53
|
-
: {}),
|
|
54
|
-
};
|
|
55
|
-
await writeFile(path.join(explicit.directory, '.build-metadata.json'), JSON.stringify(metadata, null, 2));
|
|
56
|
-
this._metadata = metadata;
|
|
57
|
-
return {
|
|
58
|
-
outputDir: explicit.directory,
|
|
59
|
-
metadata,
|
|
60
|
-
files: {
|
|
61
|
-
html: explicit.entry,
|
|
62
|
-
engine: null,
|
|
63
|
-
config: '',
|
|
64
|
-
settings: null,
|
|
65
|
-
modules: null,
|
|
66
|
-
start: '',
|
|
67
|
-
scenes: [],
|
|
68
|
-
assets: [],
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
35
|
// 1. 确定引擎类型和构建工具
|
|
73
36
|
const { engine, buildTool } = await this.resolveDetection();
|
|
74
37
|
console.log(`[BaseBuilder] 使用引擎: ${engine}, 构建工具: ${buildTool}`);
|
|
@@ -99,9 +62,7 @@ export class BaseBuilder {
|
|
|
99
62
|
}
|
|
100
63
|
async runPrebuildValidation(engine, buildTool) {
|
|
101
64
|
const validationOptions = this.options.validation;
|
|
102
|
-
if (validationOptions?.enabled === false ||
|
|
103
|
-
validationOptions?.sourcePrechecked ||
|
|
104
|
-
!validationOptions?.channel) {
|
|
65
|
+
if (validationOptions?.enabled === false || validationOptions?.sourcePrechecked || !validationOptions?.channel) {
|
|
105
66
|
return;
|
|
106
67
|
}
|
|
107
68
|
if (!this.isPhaserValidationTarget(engine, buildTool)) {
|
|
@@ -309,10 +309,6 @@ export class EngineDetector {
|
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
if (matches.length === 0) {
|
|
312
|
-
// Creator projects carry their editor version here; Node's engine version is unrelated.
|
|
313
|
-
if (isRecord(pkg.creator) && typeof pkg.creator.version === 'string' &&
|
|
314
|
-
/^\d+\.\d+\.\d+(?:[-+][a-zA-Z0-9.-]+)?$/.test(pkg.creator.version))
|
|
315
|
-
return 'cocos';
|
|
316
312
|
return null;
|
|
317
313
|
}
|
|
318
314
|
// 按优先级排序,返回最高优先级的引擎
|
|
@@ -30,25 +30,31 @@ export class GenericAdapter {
|
|
|
30
30
|
// 1. 检测包管理器
|
|
31
31
|
const packageManager = await this.detectPackageManager();
|
|
32
32
|
console.log(`[GenericAdapter] 检测到包管理器: ${packageManager}`);
|
|
33
|
-
// 2.
|
|
34
|
-
// 必须先构建、再取产物,不允许复用残留的 dist/ 或 public/。
|
|
35
|
-
const buildScript = await this.detectBuildScript();
|
|
36
|
-
if (!buildScript) {
|
|
37
|
-
throw new Error(`[GenericAdapter] 未找到可用的构建命令,拒绝复用工程内现成的目录。\n` +
|
|
38
|
-
`项目目录: ${this.projectDir}\n` +
|
|
39
|
-
`请在 package.json 的 scripts 中声明 build(支持 build / build:prod / ` +
|
|
40
|
-
`build:production / dist / compile 之一)。`);
|
|
41
|
-
}
|
|
42
|
-
console.log(`[GenericAdapter] 检测到构建命令: ${buildScript}`);
|
|
43
|
-
// 3. 检查 node_modules 是否存在
|
|
33
|
+
// 2. 检查 node_modules 是否存在
|
|
44
34
|
const hasNodeModules = await this.checkNodeModules();
|
|
45
35
|
if (hasNodeModules) {
|
|
46
36
|
console.log('[GenericAdapter] node_modules 已存在,跳过依赖安装');
|
|
47
37
|
}
|
|
48
38
|
else {
|
|
39
|
+
// 3. 执行安装
|
|
49
40
|
console.log('[GenericAdapter] 执行依赖安装...');
|
|
50
41
|
await this.runNpmInstall(packageManager);
|
|
51
42
|
}
|
|
43
|
+
// 4. 检测构建命令。**必须先构建、再取产物**,不允许因为「找不到脚本」就
|
|
44
|
+
// 复用工程里现成的目录:那会把残留的 `dist/` 或 Vite 的 `public/` 当成
|
|
45
|
+
// 构建结果,用户拿到的是过期或完全不对的内容。
|
|
46
|
+
//
|
|
47
|
+
// 平台导入的工程都带 `builds.config.js`,由 playable-scripts 构建链负责
|
|
48
|
+
// 产出产物,正常路径下这里必然能拿到 build 脚本;拿不到就是工程本身有问题,
|
|
49
|
+
// 应当明确报错而不是静默降级。
|
|
50
|
+
const buildScript = await this.detectBuildScript();
|
|
51
|
+
if (!buildScript) {
|
|
52
|
+
throw new Error(`[GenericAdapter] 未找到可用的构建命令,拒绝复用工程内现成的目录。\n` +
|
|
53
|
+
`项目目录: ${this.projectDir}\n` +
|
|
54
|
+
`请在 package.json 的 scripts 中声明 build(支持 build / build:prod / ` +
|
|
55
|
+
`build:production / dist / compile 之一)。`);
|
|
56
|
+
}
|
|
57
|
+
console.log(`[GenericAdapter] 检测到构建命令: ${buildScript}`);
|
|
52
58
|
// 5. 执行构建
|
|
53
59
|
console.log('[GenericAdapter] 执行项目构建...');
|
|
54
60
|
const originalBuildDir = await this.runNpmBuild(packageManager, buildScript);
|
|
@@ -340,9 +346,7 @@ export class GenericAdapter {
|
|
|
340
346
|
*/
|
|
341
347
|
getNestedValue(obj, path) {
|
|
342
348
|
return path.split('.').reduce((current, key) => {
|
|
343
|
-
|
|
344
|
-
return undefined;
|
|
345
|
-
return current[key];
|
|
349
|
+
return current && current[key] !== undefined ? current[key] : undefined;
|
|
346
350
|
}, obj);
|
|
347
351
|
}
|
|
348
352
|
/**
|
|
@@ -417,6 +421,7 @@ export class GenericAdapter {
|
|
|
417
421
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
418
422
|
for (const entry of entries) {
|
|
419
423
|
const fullPath = path.join(dir, entry.name);
|
|
424
|
+
const relativePath = path.relative(basePath, fullPath);
|
|
420
425
|
if (entry.isDirectory()) {
|
|
421
426
|
await scanDir(fullPath, basePath);
|
|
422
427
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { spawn } from 'child_process';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
4
5
|
import { createRequire } from 'module';
|
|
5
6
|
import { strFromU8, strToU8, unzipSync, zipSync } from 'fflate';
|
|
6
7
|
import { injectBigoLifecycleBridge } from '../platforms/bigo-lifecycle.js';
|
|
7
8
|
import { formatValidationSummary, hasBlockingValidationErrors, runPlayableValidation, saveValidationReport, } from '../validation/index.js';
|
|
9
|
+
// ESM 兼容:获取当前模块的目录路径
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
8
12
|
// ESM 兼容:创建 require 函数用于动态加载 JSON
|
|
9
13
|
const require = createRequire(import.meta.url);
|
|
10
14
|
/**
|
|
@@ -451,7 +455,7 @@ export class PlayableScriptsAdapter {
|
|
|
451
455
|
hasMigration = true;
|
|
452
456
|
}
|
|
453
457
|
}
|
|
454
|
-
catch {
|
|
458
|
+
catch (error) {
|
|
455
459
|
// 读取或写入失败,跳过
|
|
456
460
|
console.log(`[PlayableScriptsAdapter] ⚠️ 无法处理文件: ${filePath}`);
|
|
457
461
|
}
|
|
@@ -1535,7 +1539,6 @@ export class PlayableScriptsAdapter {
|
|
|
1535
1539
|
return path.join(parsed.dir, `${parsed.name}.${channel}${parsed.ext || '.json'}`);
|
|
1536
1540
|
}
|
|
1537
1541
|
async saveBuildMetadata(metadata) {
|
|
1538
|
-
void metadata;
|
|
1539
1542
|
// 不再保存 .build-metadata.json 文件,元数据通过返回值传递
|
|
1540
1543
|
console.log(`[PlayableScriptsAdapter] 构建完成(buildTool: playable-scripts, skipChannelBuild: true)`);
|
|
1541
1544
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
export { BaseBuilder } from './base-builder.js';
|
|
2
2
|
export type { BaseBuildOptions, BaseBuildOutput } from './base-builder.js';
|
|
3
|
-
export { inspectProjectDelivery, prepareProjectDelivery, executeProjectDelivery, } from './delivery/project-delivery.js';
|
|
4
|
-
export { parseProjectDeliveryRecipe, readProjectDeliveryRecipe, recipeDigest, ProjectDeliveryError, } from './delivery/recipe.js';
|
|
5
|
-
export type { DeliveryCommand, ProjectDeliveryRecipe, DeliveryPreparationStamp, ProjectDeliveryIssue, ProjectDeliveryInspection, ProjectDeliveryOptions, ExecuteProjectDeliveryOptions, ProjectDeliveryOutput, } from './delivery/types.js';
|
|
6
|
-
export { parseBuildPlan, buildPlanDigest } from './delivery/build-plan.js';
|
|
7
|
-
export { createRecipeBuildPlan } from './delivery/recipe-build-plan.js';
|
|
8
|
-
export type { BuildPlan, BuildPackageManager, RecipeBuildPlanOptions } from './delivery/build-plan.types.js';
|
|
9
|
-
export { parseArtifactDescriptor, assertArtifactDescriptorDigest, artifactBytesDigest, artifactFileDescriptor, } from './delivery/artifact-descriptor.js';
|
|
10
|
-
export type { ArtifactDescriptor, ArtifactFileDescriptor, ArtifactIdentity, } from './delivery/artifact-descriptor.js';
|
|
11
|
-
export { ARTIFACT_LIMITS, normalizeArtifactPath, validateArtifactFiles, readArtifactDirectory, createNormalizedZip, readZipArtifact, packageChannelArtifact, describeChannelArtifact, verifyChannelArtifactDescriptor, } from './delivery/artifact-package.js';
|
|
12
|
-
export type { ArtifactInputFile, PackageChannelArtifactOptions, DescribeChannelArtifactOptions, } from './delivery/artifact-package.js';
|
|
13
|
-
export type { ViteWorkspace } from './vite/workspace.js';
|
|
14
|
-
export { readProductionSourceSnapshot, readProductionSourceFile, verifyProductionSourceSnapshot, productionSourcePathAllowed, productionAuxiliaryPathAllowed, ProductionSourceError, PRODUCTION_SOURCE_RULES_VERSION, SUPPORTED_PRODUCTION_SOURCE_RULES_VERSIONS } from './production-inputs.js';
|
|
15
|
-
export type { ProductionSourceSnapshot, ProductionSourceFile } from './production-inputs.js';
|
|
16
|
-
export { readWorkspacePublicSourceClosure } from './workspace-public-source.js';
|
|
17
|
-
export { assertNoUnanchoredFrameAnimationSources } from './production-animation-presence.js';
|
|
18
3
|
export { ViteBuilder } from './vite-builder.js';
|
|
19
4
|
export type { ViteBuildOutput } from './vite-builder.js';
|
|
20
|
-
export { normalizePlayableRedirect, PLAYABLE_REDIRECT_LIMITS } from './redirect-policy.js';
|
|
21
|
-
export type { PlayableRedirectRule } from './redirect-policy.js';
|
|
22
5
|
export { PlayableBuilder } from './playable-builder.js';
|
|
23
6
|
export type { PlayableBuildOutput } from './playable-builder.js';
|
|
24
7
|
export { OnePageConverter } from './converter.js';
|
|
25
|
-
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter
|
|
8
|
+
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter } from './engines/index.js';
|
|
26
9
|
export { BuildStateManager, BUILD_STATE_VERSION } from './state/index.js';
|
|
27
10
|
export type { AssetType, ProcessingStage, OptimizationType, AssetProcessingInfo, AssetState, BuildStageInfo, BuildState, } from './state/index.js';
|
|
28
11
|
export { StateToReportConverter } from './state/index.js';
|
|
@@ -30,8 +13,8 @@ export type { UnifiedReportData, ReportAsset, ProcessingStep, TypeStatistics, Ca
|
|
|
30
13
|
export { BuildAnalyzer } from './analyzers/build-analyzer.js';
|
|
31
14
|
export type { BuildAnalysisReport, FileAnalysis } from './analyzers/build-analyzer.js';
|
|
32
15
|
export { PlayableAnalyzer } from './analyzers/playable-analyzer.js';
|
|
33
|
-
export type { PlayableAnalysisReport, PlayableAssetAnalysis
|
|
34
|
-
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies
|
|
16
|
+
export type { PlayableAnalysisReport, PlayableAssetAnalysis } from './analyzers/playable-analyzer.js';
|
|
17
|
+
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies } from './analyzers/scene-asset-collector.js';
|
|
35
18
|
export type { SceneDependencies } from './analyzers/scene-asset-collector.js';
|
|
36
19
|
export { detectAmmoUsage } from './utils/ammo-detector.js';
|
|
37
20
|
export { createPlatformAdapter, PlatformAdapter } from './platforms/index.js';
|
|
@@ -41,6 +24,6 @@ export { ViteConfigBuilder } from './vite/config-builder.js';
|
|
|
41
24
|
export { PLATFORM_CONFIGS } from './vite/platform-configs.js';
|
|
42
25
|
export type { PlatformViteConfig } from './vite/platform-configs.js';
|
|
43
26
|
export { AudioOptimizer } from './audio-optimizer.js';
|
|
44
|
-
export type { AudioAssetInfo, AudioOptimizationReport, AudioOptimizerOptions
|
|
27
|
+
export type { AudioAssetInfo, AudioOptimizationReport, AudioOptimizerOptions } from './audio-optimizer.js';
|
|
45
28
|
export * from './validation/index.js';
|
|
46
29
|
export * from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
// 导出构建器
|
|
2
2
|
export { BaseBuilder } from './base-builder.js';
|
|
3
|
-
export { inspectProjectDelivery, prepareProjectDelivery, executeProjectDelivery, } from './delivery/project-delivery.js';
|
|
4
|
-
export { parseProjectDeliveryRecipe, readProjectDeliveryRecipe, recipeDigest, ProjectDeliveryError, } from './delivery/recipe.js';
|
|
5
|
-
export { parseBuildPlan, buildPlanDigest } from './delivery/build-plan.js';
|
|
6
|
-
export { createRecipeBuildPlan } from './delivery/recipe-build-plan.js';
|
|
7
|
-
export { parseArtifactDescriptor, assertArtifactDescriptorDigest, artifactBytesDigest, artifactFileDescriptor, } from './delivery/artifact-descriptor.js';
|
|
8
|
-
export { ARTIFACT_LIMITS, normalizeArtifactPath, validateArtifactFiles, readArtifactDirectory, createNormalizedZip, readZipArtifact, packageChannelArtifact, describeChannelArtifact, verifyChannelArtifactDescriptor, } from './delivery/artifact-package.js';
|
|
9
|
-
export { readProductionSourceSnapshot, readProductionSourceFile, verifyProductionSourceSnapshot, productionSourcePathAllowed, productionAuxiliaryPathAllowed, ProductionSourceError, PRODUCTION_SOURCE_RULES_VERSION, SUPPORTED_PRODUCTION_SOURCE_RULES_VERSIONS } from './production-inputs.js';
|
|
10
|
-
export { readWorkspacePublicSourceClosure } from './workspace-public-source.js';
|
|
11
|
-
export { assertNoUnanchoredFrameAnimationSources } from './production-animation-presence.js';
|
|
12
3
|
export { ViteBuilder } from './vite-builder.js';
|
|
13
|
-
export { normalizePlayableRedirect, PLAYABLE_REDIRECT_LIMITS } from './redirect-policy.js';
|
|
14
4
|
export { PlayableBuilder } from './playable-builder.js';
|
|
15
5
|
export { OnePageConverter } from './converter.js';
|
|
16
6
|
// 导出引擎检测器和适配器
|
|
17
|
-
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter
|
|
7
|
+
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter } from './engines/index.js';
|
|
18
8
|
// 导出状态管理器
|
|
19
9
|
export { BuildStateManager, BUILD_STATE_VERSION } from './state/index.js';
|
|
20
10
|
export { StateToReportConverter } from './state/index.js';
|
|
21
11
|
// 导出分析器
|
|
22
12
|
export { BuildAnalyzer } from './analyzers/build-analyzer.js';
|
|
23
13
|
export { PlayableAnalyzer } from './analyzers/playable-analyzer.js';
|
|
24
|
-
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies
|
|
14
|
+
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies } from './analyzers/scene-asset-collector.js';
|
|
25
15
|
export { detectAmmoUsage } from './utils/ammo-detector.js';
|
|
26
16
|
// 导出平台适配器
|
|
27
17
|
export { createPlatformAdapter, PlatformAdapter } from './platforms/index.js';
|
package/dist/platforms/base.d.ts
CHANGED
|
@@ -55,10 +55,6 @@ export declare abstract class PlatformAdapter {
|
|
|
55
55
|
* 在 HTML 中注入 CTA 适配器(异步版本)
|
|
56
56
|
*/
|
|
57
57
|
protected injectCTAAdapterAsync(html: string): Promise<string>;
|
|
58
|
-
/**
|
|
59
|
-
* 跳转版本规则脚本:未配置有效 `redirect` 时返回空串,普通构建的产物保持不变。
|
|
60
|
-
*/
|
|
61
|
-
protected getRedirectPolicyScriptAsync(): Promise<string>;
|
|
62
58
|
/**
|
|
63
59
|
* 在 HTML 中注入 CTA 适配器(同步版本)
|
|
64
60
|
* @deprecated 推荐使用 injectCTAAdapterAsync
|
package/dist/platforms/base.js
CHANGED
|
@@ -2,11 +2,8 @@ import fs from 'fs/promises';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { minifyPatchCode } from '../utils/minify.js';
|
|
5
|
-
import { normalizePlayableRedirect } from '../redirect-policy.js';
|
|
6
5
|
// 缓存压缩后的 CTA 适配器代码
|
|
7
6
|
let cachedMinifiedCTAAdapter = null;
|
|
8
|
-
// 缓存压缩后的跳转版本规则代码
|
|
9
|
-
let cachedMinifiedRedirectPolicy = null;
|
|
10
7
|
// 缓存压缩后的 Tracking 适配器代码
|
|
11
8
|
let cachedMinifiedTrackingAdapter = null;
|
|
12
9
|
// 缓存从 @playcraft/ads-tracking 提取的 tracking 实现代码
|
|
@@ -90,34 +87,18 @@ export class PlatformAdapter {
|
|
|
90
87
|
async injectCTAAdapterAsync(html) {
|
|
91
88
|
const storeUrlsScript = this.getStoreUrlsScript();
|
|
92
89
|
const ctaScript = await this.getCTAAdapterScriptAsync();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const combined = storeUrlsScript + ctaScript + redirectScript;
|
|
96
|
-
// 在 </head> 之前或 </body> 之前注入(函数替换:脚本内容里的 `$` 不会被当成替换模式)
|
|
90
|
+
const combined = storeUrlsScript + ctaScript;
|
|
91
|
+
// 在 </head> 之前或 </body> 之前注入
|
|
97
92
|
if (html.includes('</head>')) {
|
|
98
|
-
return html.replace('</head>',
|
|
93
|
+
return html.replace('</head>', `${combined}\n</head>`);
|
|
99
94
|
}
|
|
100
95
|
else if (html.includes('</body>')) {
|
|
101
|
-
return html.replace('</body>',
|
|
96
|
+
return html.replace('</body>', `${combined}\n</body>`);
|
|
102
97
|
}
|
|
103
98
|
else {
|
|
104
99
|
return combined + '\n' + html;
|
|
105
100
|
}
|
|
106
101
|
}
|
|
107
|
-
/**
|
|
108
|
-
* 跳转版本规则脚本:未配置有效 `redirect` 时返回空串,普通构建的产物保持不变。
|
|
109
|
-
*/
|
|
110
|
-
async getRedirectPolicyScriptAsync() {
|
|
111
|
-
const rule = normalizePlayableRedirect(this.options.redirect);
|
|
112
|
-
if (!rule)
|
|
113
|
-
return '';
|
|
114
|
-
if (!cachedMinifiedRedirectPolicy) {
|
|
115
|
-
const code = await this.readTemplateFile('playcraft-redirect-policy.js');
|
|
116
|
-
cachedMinifiedRedirectPolicy = await minifyPatchCode(code, 'playcraft-redirect-policy.js');
|
|
117
|
-
}
|
|
118
|
-
return (`<script>window.__PLAYCRAFT_REDIRECT__=${JSON.stringify(rule)};</script>` +
|
|
119
|
-
`<script>${cachedMinifiedRedirectPolicy}</script>`);
|
|
120
|
-
}
|
|
121
102
|
/**
|
|
122
103
|
* 在 HTML 中注入 CTA 适配器(同步版本)
|
|
123
104
|
* @deprecated 推荐使用 injectCTAAdapterAsync
|
|
@@ -207,8 +188,8 @@ export class PlatformAdapter {
|
|
|
207
188
|
cachedAdsTrackingScript = minified;
|
|
208
189
|
return `<script>${minified}</script>`;
|
|
209
190
|
}
|
|
210
|
-
catch (
|
|
211
|
-
console.warn('[Tracking] 无法加载 @playcraft/ads-tracking:',
|
|
191
|
+
catch (e) {
|
|
192
|
+
console.warn('[Tracking] 无法加载 @playcraft/ads-tracking:', e.message);
|
|
212
193
|
return '';
|
|
213
194
|
}
|
|
214
195
|
}
|
package/dist/platforms/bigo.js
CHANGED
package/dist/platforms/google.js
CHANGED
package/dist/platforms/inmobi.js
CHANGED
|
@@ -11,7 +11,6 @@ export class MintegralAdapter extends PlatformAdapter {
|
|
|
11
11
|
return 'html';
|
|
12
12
|
}
|
|
13
13
|
async modifyHTML(html, assets) {
|
|
14
|
-
void assets;
|
|
15
14
|
// Mintegral 要求 charset 为 utf-8,确保存在
|
|
16
15
|
if (!html.includes('charset') && html.includes('<head>')) {
|
|
17
16
|
html = html.replace('<head>', '<head>\n<meta charset="utf-8">');
|
package/dist/platforms/moloco.js
CHANGED
|
@@ -32,7 +32,6 @@ export class PlayCraftAdapter extends PlatformAdapter {
|
|
|
32
32
|
* PlayCraft 构建注入 CTA 适配器
|
|
33
33
|
*/
|
|
34
34
|
async modifyHTML(html, _assets) {
|
|
35
|
-
void _assets;
|
|
36
35
|
html = await this.injectCTAAdapterAsync(html);
|
|
37
36
|
html = await this.injectTrackingAdapterAsync(html);
|
|
38
37
|
return html;
|
|
@@ -13,7 +13,6 @@ export class RemergeAdapter extends PlatformAdapter {
|
|
|
13
13
|
return 'zip';
|
|
14
14
|
}
|
|
15
15
|
async modifyHTML(html, assets) {
|
|
16
|
-
void assets;
|
|
17
16
|
// Remerge 使用 FbPlayableAd API(与 Facebook/Moloco 相同)
|
|
18
17
|
const remergeScriptCode = `
|
|
19
18
|
window.FbPlayableAd = window.FbPlayableAd || {
|
package/dist/platforms/tiktok.js
CHANGED
package/dist/platforms/unity.js
CHANGED
|
@@ -42,7 +42,6 @@ export class UnityAdapter extends PlatformAdapter {
|
|
|
42
42
|
return 'html';
|
|
43
43
|
}
|
|
44
44
|
async modifyHTML(html, assets) {
|
|
45
|
-
void assets;
|
|
46
45
|
const unityScript = await this.minifyPlatformScript(this.getPlatformScript(), 'unity-mraid');
|
|
47
46
|
const comment = `<!-- Unity Ads: MRAID 2.0, 等待viewableChange, 使用mraid.open() -->`;
|
|
48
47
|
// 保留 charset 在文档开头,同时确保可见性门控早于首个业务脚本。
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { PlayableRedirectRule } from './redirect-policy.js';
|
|
2
1
|
export type Platform = 'playcraft' | 'facebook' | 'snapchat' | 'ironsource' | 'applovin' | 'google' | 'tiktok' | 'unity' | 'liftoff' | 'moloco' | 'bigo' | 'inmobi' | 'adikteev' | 'remerge' | 'mintegral';
|
|
3
2
|
export type OutputFormat = 'html' | 'zip';
|
|
4
3
|
/**
|
|
@@ -21,7 +20,6 @@ export interface ComplianceValidationOptions {
|
|
|
21
20
|
export type BuildMode = 'classic' | 'esm';
|
|
22
21
|
export type ESMMode = 'auto' | 'enabled' | 'disabled';
|
|
23
22
|
export interface BuildOptions {
|
|
24
|
-
deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
|
|
25
23
|
platform: Platform;
|
|
26
24
|
format?: OutputFormat;
|
|
27
25
|
outputDir?: string;
|
|
@@ -66,8 +64,6 @@ export interface BuildOptions {
|
|
|
66
64
|
adNetwork?: string;
|
|
67
65
|
totalInteractions?: number;
|
|
68
66
|
};
|
|
69
|
-
/** 跳转版本规则(点击次数 / 游玩时长);仅在有效时随 CTA 适配器注入 */
|
|
70
|
-
redirect?: PlayableRedirectRule;
|
|
71
67
|
}
|
|
72
68
|
export interface BaseBuildMetadata {
|
|
73
69
|
mode: BuildMode;
|
|
@@ -80,9 +76,6 @@ export interface BaseBuildMetadata {
|
|
|
80
76
|
buildTool?: BuildTool;
|
|
81
77
|
skipChannelBuild?: boolean;
|
|
82
78
|
buildOutputDir?: string;
|
|
83
|
-
/** Explicit output from the project's delivery recipe; never selected by filename scanning. */
|
|
84
|
-
deliveryArtifact?: string;
|
|
85
|
-
deliveryRecipeDigest?: string;
|
|
86
79
|
}
|
|
87
80
|
export interface LocalBuildOptions {
|
|
88
81
|
scriptsConcatenate?: boolean;
|
|
@@ -123,8 +116,8 @@ export interface ProjectManifest {
|
|
|
123
116
|
path: string;
|
|
124
117
|
preload?: boolean;
|
|
125
118
|
tags?: string[];
|
|
126
|
-
i18n?: Record<string,
|
|
127
|
-
data?:
|
|
119
|
+
i18n?: Record<string, any>;
|
|
120
|
+
data?: any;
|
|
128
121
|
file?: {
|
|
129
122
|
filename: string;
|
|
130
123
|
size: number;
|
|
@@ -232,7 +225,6 @@ export interface BaseBuildOptions {
|
|
|
232
225
|
/** 渠道产物格式(playable-scripts 阶段;与 Vite 阶段 format 对齐) */
|
|
233
226
|
format?: OutputFormat;
|
|
234
227
|
validation?: ComplianceValidationOptions;
|
|
235
|
-
deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
|
|
236
228
|
}
|
|
237
229
|
/**
|
|
238
230
|
* 基础构建输出
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
import type { ChannelRuleProfile, ValidationContext, ValidationResult } from './types.js';
|
|
2
2
|
export declare function validateHtmlArtifact(context: ValidationContext, profile?: ChannelRuleProfile): Promise<ValidationResult[]>;
|
|
3
|
-
/** Validates the exact final bytes, including objects downloaded by Business. */
|
|
4
|
-
export declare function validateHtmlArtifactContent(context: ValidationContext, content: string | Uint8Array, displayPath?: string, profile?: ChannelRuleProfile): ValidationResult[];
|
|
5
|
-
export declare function collectExternalResources(html: string): string[];
|
|
6
|
-
export declare function collectLocalResourceReferences(html: string): string[];
|
|
7
|
-
export declare function isAllowedExternalResource(url: string, allowedPatterns?: string[]): boolean;
|
|
@@ -3,33 +3,31 @@ import { getRulesForStage } from './profiles.js';
|
|
|
3
3
|
const RESOURCE_ATTR_RE = /\b(?:src|href|data)\s*=\s*["']([^"']+)["']/gi;
|
|
4
4
|
const CSS_URL_RE = /url\(\s*["']?([^"')]+)["']?\s*\)/gi;
|
|
5
5
|
export async function validateHtmlArtifact(context, profile) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
6
|
+
const rules = profile?.rules.filter((rule) => rule.stage === 'html-artifact')
|
|
7
|
+
?? getRulesForStage(context.channel, 'html-artifact');
|
|
9
8
|
if (!context.htmlPath) {
|
|
10
9
|
return [missingHtmlResult(context.channel)];
|
|
11
10
|
}
|
|
11
|
+
let artifact;
|
|
12
12
|
try {
|
|
13
|
-
const content = await
|
|
14
|
-
|
|
13
|
+
const [content, stat] = await Promise.all([
|
|
14
|
+
fs.readFile(context.htmlPath, 'utf-8'),
|
|
15
|
+
fs.stat(context.htmlPath),
|
|
16
|
+
]);
|
|
17
|
+
artifact = {
|
|
18
|
+
path: context.htmlPath,
|
|
19
|
+
content,
|
|
20
|
+
size: stat.size,
|
|
21
|
+
};
|
|
15
22
|
}
|
|
16
23
|
catch (error) {
|
|
17
24
|
return [missingHtmlResult(context.channel, context.htmlPath, error)];
|
|
18
25
|
}
|
|
19
|
-
}
|
|
20
|
-
/** Validates the exact final bytes, including objects downloaded by Business. */
|
|
21
|
-
export function validateHtmlArtifactContent(context, content, displayPath = 'index.html', profile) {
|
|
22
|
-
const rules = profile?.rules.filter((rule) => rule.stage === 'html-artifact')
|
|
23
|
-
?? getRulesForStage(context.channel, 'html-artifact');
|
|
24
|
-
const artifact = {
|
|
25
|
-
path: displayPath,
|
|
26
|
-
content: typeof content === 'string' ? content : Buffer.from(content).toString('utf-8'),
|
|
27
|
-
size: typeof content === 'string' ? Buffer.byteLength(content) : content.byteLength,
|
|
28
|
-
};
|
|
29
26
|
const results = [];
|
|
30
27
|
for (const rule of rules) {
|
|
31
|
-
if (!rule.detectable || !rule.check)
|
|
28
|
+
if (!rule.detectable || !rule.check) {
|
|
32
29
|
continue;
|
|
30
|
+
}
|
|
33
31
|
results.push(evaluateHtmlRule(rule, artifact));
|
|
34
32
|
}
|
|
35
33
|
return results;
|
|
@@ -89,10 +87,10 @@ function resultFromBoolean(rule, passed, file, evidence) {
|
|
|
89
87
|
confidence: rule.confidence,
|
|
90
88
|
};
|
|
91
89
|
}
|
|
92
|
-
|
|
90
|
+
function collectExternalResources(html) {
|
|
93
91
|
return collectUrls(html).filter((url) => /^https?:\/\//i.test(url) || /^\/\//.test(url));
|
|
94
92
|
}
|
|
95
|
-
|
|
93
|
+
function collectLocalResourceReferences(html) {
|
|
96
94
|
return collectUrls(html).filter((url) => {
|
|
97
95
|
if (isInlineOrSpecialUrl(url))
|
|
98
96
|
return false;
|
|
@@ -116,7 +114,7 @@ function collectUrls(html) {
|
|
|
116
114
|
function isInlineOrSpecialUrl(url) {
|
|
117
115
|
return /^(data:|blob:|javascript:|mailto:|tel:|about:)/i.test(url);
|
|
118
116
|
}
|
|
119
|
-
|
|
117
|
+
function isAllowedExternalResource(url, allowedPatterns) {
|
|
120
118
|
if (!allowedPatterns || allowedPatterns.length === 0) {
|
|
121
119
|
return false;
|
|
122
120
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
-
export * from './artifact.js';
|
|
3
|
-
export * from './artifact-rules.js';
|
|
4
|
-
export * from './artifact-qa.js';
|
|
5
|
-
export * from './runtime-load.js';
|
|
6
2
|
export * from './profiles.js';
|
|
7
3
|
export * from './html-validator.js';
|
|
8
4
|
export * from './package-validator.js';
|
|
@@ -10,4 +6,3 @@ export * from './reporter.js';
|
|
|
10
6
|
export * from './source-scanner.js';
|
|
11
7
|
export * from './validation-runner.js';
|
|
12
8
|
export * from './zip-reader.js';
|
|
13
|
-
export * from './runtime-cover.js';
|
package/dist/validation/index.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
-
export * from './artifact.js';
|
|
3
|
-
export * from './artifact-rules.js';
|
|
4
|
-
export * from './artifact-qa.js';
|
|
5
|
-
export * from './runtime-load.js';
|
|
6
2
|
export * from './profiles.js';
|
|
7
3
|
export * from './html-validator.js';
|
|
8
4
|
export * from './package-validator.js';
|
|
@@ -10,4 +6,3 @@ export * from './reporter.js';
|
|
|
10
6
|
export * from './source-scanner.js';
|
|
11
7
|
export * from './validation-runner.js';
|
|
12
8
|
export * from './zip-reader.js';
|
|
13
|
-
export * from './runtime-cover.js';
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import type { Platform } from '../types.js';
|
|
2
1
|
import type { ChannelRuleProfile, ValidationContext, ValidationResult } from './types.js';
|
|
3
2
|
export declare function validateDeliveryPackage(context: ValidationContext, profile?: ChannelRuleProfile): Promise<ValidationResult[]>;
|
|
4
|
-
export declare function validateSingleHtmlPackage(channel: Platform, bytes: Uint8Array, artifactName?: string): ValidationResult[];
|