@playcraft/build 0.2.19-test-a → 0.2.21
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 -42
- 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 +6 -19
- package/dist/index.js +3 -11
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.js +6 -33
- 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/redirect-artifact.d.ts +30 -0
- package/dist/redirect-artifact.js +83 -0
- package/dist/types.d.ts +2 -9
- 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/templates/patches/one-page-mraid-resize-canvas.js +2 -0
- package/templates/patches/playcraft-redirect-policy.js +17 -1
- 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 -148
- 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 -81
- 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/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/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,41 +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
|
-
trustedDependencyRoot: this.options.trustedDependencyRoot,
|
|
44
|
-
});
|
|
45
|
-
if (explicit) {
|
|
46
|
-
const metadata = {
|
|
47
|
-
mode: 'classic',
|
|
48
|
-
engine: 'generic',
|
|
49
|
-
buildTool: 'generic',
|
|
50
|
-
buildOutputDir: explicit.directory,
|
|
51
|
-
deliveryRecipeDigest: explicit.recipeDigest,
|
|
52
|
-
...(explicit.kind === 'channel-package'
|
|
53
|
-
? { skipChannelBuild: true, deliveryArtifact: explicit.entry }
|
|
54
|
-
: {}),
|
|
55
|
-
};
|
|
56
|
-
await writeFile(path.join(explicit.directory, '.build-metadata.json'), JSON.stringify(metadata, null, 2));
|
|
57
|
-
this._metadata = metadata;
|
|
58
|
-
return {
|
|
59
|
-
outputDir: explicit.directory,
|
|
60
|
-
metadata,
|
|
61
|
-
files: {
|
|
62
|
-
html: explicit.entry,
|
|
63
|
-
engine: null,
|
|
64
|
-
config: '',
|
|
65
|
-
settings: null,
|
|
66
|
-
modules: null,
|
|
67
|
-
start: '',
|
|
68
|
-
scenes: [],
|
|
69
|
-
assets: [],
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
35
|
// 1. 确定引擎类型和构建工具
|
|
74
36
|
const { engine, buildTool } = await this.resolveDetection();
|
|
75
37
|
console.log(`[BaseBuilder] 使用引擎: ${engine}, 构建工具: ${buildTool}`);
|
|
@@ -100,9 +62,7 @@ export class BaseBuilder {
|
|
|
100
62
|
}
|
|
101
63
|
async runPrebuildValidation(engine, buildTool) {
|
|
102
64
|
const validationOptions = this.options.validation;
|
|
103
|
-
if (validationOptions?.enabled === false ||
|
|
104
|
-
validationOptions?.sourcePrechecked ||
|
|
105
|
-
!validationOptions?.channel) {
|
|
65
|
+
if (validationOptions?.enabled === false || validationOptions?.sourcePrechecked || !validationOptions?.channel) {
|
|
106
66
|
return;
|
|
107
67
|
}
|
|
108
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,15 @@
|
|
|
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
5
|
export { normalizePlayableRedirect, PLAYABLE_REDIRECT_LIMITS } from './redirect-policy.js';
|
|
6
|
+
export { injectRedirectPolicyIntoArtifact } from './redirect-artifact.js';
|
|
7
|
+
export type { PlayableStoreUrls } from './redirect-artifact.js';
|
|
21
8
|
export type { PlayableRedirectRule } from './redirect-policy.js';
|
|
22
9
|
export { PlayableBuilder } from './playable-builder.js';
|
|
23
10
|
export type { PlayableBuildOutput } from './playable-builder.js';
|
|
24
11
|
export { OnePageConverter } from './converter.js';
|
|
25
|
-
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter
|
|
12
|
+
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter } from './engines/index.js';
|
|
26
13
|
export { BuildStateManager, BUILD_STATE_VERSION } from './state/index.js';
|
|
27
14
|
export type { AssetType, ProcessingStage, OptimizationType, AssetProcessingInfo, AssetState, BuildStageInfo, BuildState, } from './state/index.js';
|
|
28
15
|
export { StateToReportConverter } from './state/index.js';
|
|
@@ -30,8 +17,8 @@ export type { UnifiedReportData, ReportAsset, ProcessingStep, TypeStatistics, Ca
|
|
|
30
17
|
export { BuildAnalyzer } from './analyzers/build-analyzer.js';
|
|
31
18
|
export type { BuildAnalysisReport, FileAnalysis } from './analyzers/build-analyzer.js';
|
|
32
19
|
export { PlayableAnalyzer } from './analyzers/playable-analyzer.js';
|
|
33
|
-
export type { PlayableAnalysisReport, PlayableAssetAnalysis
|
|
34
|
-
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies
|
|
20
|
+
export type { PlayableAnalysisReport, PlayableAssetAnalysis } from './analyzers/playable-analyzer.js';
|
|
21
|
+
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies } from './analyzers/scene-asset-collector.js';
|
|
35
22
|
export type { SceneDependencies } from './analyzers/scene-asset-collector.js';
|
|
36
23
|
export { detectAmmoUsage } from './utils/ammo-detector.js';
|
|
37
24
|
export { createPlatformAdapter, PlatformAdapter } from './platforms/index.js';
|
|
@@ -41,6 +28,6 @@ export { ViteConfigBuilder } from './vite/config-builder.js';
|
|
|
41
28
|
export { PLATFORM_CONFIGS } from './vite/platform-configs.js';
|
|
42
29
|
export type { PlatformViteConfig } from './vite/platform-configs.js';
|
|
43
30
|
export { AudioOptimizer } from './audio-optimizer.js';
|
|
44
|
-
export type { AudioAssetInfo, AudioOptimizationReport, AudioOptimizerOptions
|
|
31
|
+
export type { AudioAssetInfo, AudioOptimizationReport, AudioOptimizerOptions } from './audio-optimizer.js';
|
|
45
32
|
export * from './validation/index.js';
|
|
46
33
|
export * from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
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
4
|
export { normalizePlayableRedirect, PLAYABLE_REDIRECT_LIMITS } from './redirect-policy.js';
|
|
5
|
+
export { injectRedirectPolicyIntoArtifact } from './redirect-artifact.js';
|
|
14
6
|
export { PlayableBuilder } from './playable-builder.js';
|
|
15
7
|
export { OnePageConverter } from './converter.js';
|
|
16
8
|
// 导出引擎检测器和适配器
|
|
17
|
-
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter
|
|
9
|
+
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter } from './engines/index.js';
|
|
18
10
|
// 导出状态管理器
|
|
19
11
|
export { BuildStateManager, BUILD_STATE_VERSION } from './state/index.js';
|
|
20
12
|
export { StateToReportConverter } from './state/index.js';
|
|
21
13
|
// 导出分析器
|
|
22
14
|
export { BuildAnalyzer } from './analyzers/build-analyzer.js';
|
|
23
15
|
export { PlayableAnalyzer } from './analyzers/playable-analyzer.js';
|
|
24
|
-
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies
|
|
16
|
+
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies } from './analyzers/scene-asset-collector.js';
|
|
25
17
|
export { detectAmmoUsage } from './utils/ammo-detector.js';
|
|
26
18
|
// 导出平台适配器
|
|
27
19
|
export { createPlatformAdapter, PlatformAdapter } from './platforms/index.js';
|
package/dist/platforms/base.js
CHANGED
|
@@ -2,11 +2,7 @@ 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 {
|
|
6
|
-
// 缓存压缩后的 CTA 适配器代码
|
|
7
|
-
let cachedMinifiedCTAAdapter = null;
|
|
8
|
-
// 缓存压缩后的跳转版本规则代码
|
|
9
|
-
let cachedMinifiedRedirectPolicy = null;
|
|
5
|
+
import { ctaAdapterScript, redirectPolicyScript, storeUrlsScript } from '../redirect-artifact.js';
|
|
10
6
|
// 缓存压缩后的 Tracking 适配器代码
|
|
11
7
|
let cachedMinifiedTrackingAdapter = null;
|
|
12
8
|
// 缓存从 @playcraft/ads-tracking 提取的 tracking 实现代码
|
|
@@ -50,29 +46,14 @@ export class PlatformAdapter {
|
|
|
50
46
|
* 获取 CTA 适配器脚本(异步版本,带压缩)
|
|
51
47
|
*/
|
|
52
48
|
async getCTAAdapterScriptAsync() {
|
|
53
|
-
|
|
54
|
-
return `<script>${cachedMinifiedCTAAdapter}</script>`;
|
|
55
|
-
}
|
|
56
|
-
const ctaCode = await this.readTemplateFile('playcraft-cta-adapter.js');
|
|
57
|
-
const minified = await minifyPatchCode(ctaCode, 'playcraft-cta-adapter.js');
|
|
58
|
-
cachedMinifiedCTAAdapter = minified;
|
|
59
|
-
return `<script>${minified}</script>`;
|
|
49
|
+
return ctaAdapterScript();
|
|
60
50
|
}
|
|
61
51
|
/**
|
|
62
52
|
* 生成 Store URLs 注入脚本
|
|
63
53
|
* 将 storeUrls 以全局变量写入 HTML,供 CTA 适配器读取
|
|
64
54
|
*/
|
|
65
55
|
getStoreUrlsScript() {
|
|
66
|
-
|
|
67
|
-
// 只有存在有效 URL 时才注入
|
|
68
|
-
if (!urls.ios && !urls.android) {
|
|
69
|
-
return '';
|
|
70
|
-
}
|
|
71
|
-
const safeUrls = {
|
|
72
|
-
...(urls.ios ? { ios: urls.ios } : {}),
|
|
73
|
-
...(urls.android ? { android: urls.android } : {}),
|
|
74
|
-
};
|
|
75
|
-
return `<script>window.__PLAYCRAFT_STORE_URLS__=${JSON.stringify(safeUrls)};</script>`;
|
|
56
|
+
return storeUrlsScript(this.options.storeUrls);
|
|
76
57
|
}
|
|
77
58
|
/**
|
|
78
59
|
* 获取 CTA 适配器脚本(同步版本,使用预压缩代码)
|
|
@@ -108,15 +89,7 @@ export class PlatformAdapter {
|
|
|
108
89
|
* 跳转版本规则脚本:未配置有效 `redirect` 时返回空串,普通构建的产物保持不变。
|
|
109
90
|
*/
|
|
110
91
|
async getRedirectPolicyScriptAsync() {
|
|
111
|
-
|
|
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>`);
|
|
92
|
+
return redirectPolicyScript(this.options.redirect);
|
|
120
93
|
}
|
|
121
94
|
/**
|
|
122
95
|
* 在 HTML 中注入 CTA 适配器(同步版本)
|
|
@@ -207,8 +180,8 @@ export class PlatformAdapter {
|
|
|
207
180
|
cachedAdsTrackingScript = minified;
|
|
208
181
|
return `<script>${minified}</script>`;
|
|
209
182
|
}
|
|
210
|
-
catch (
|
|
211
|
-
console.warn('[Tracking] 无法加载 @playcraft/ads-tracking:',
|
|
183
|
+
catch (e) {
|
|
184
|
+
console.warn('[Tracking] 无法加载 @playcraft/ads-tracking:', e.message);
|
|
212
185
|
return '';
|
|
213
186
|
}
|
|
214
187
|
}
|
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 在文档开头,同时确保可见性门控早于首个业务脚本。
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 跳转版本的注入脚本:商店链接、CTA 适配器、跳转规则。渠道适配器(`PlatformAdapter`)在打渠道包时
|
|
3
|
+
* 注入它们;不经过渠道适配、自己产出渠道包的工程(如 devkit / playable-scripts)由
|
|
4
|
+
* `injectRedirectPolicyIntoArtifact` 在拿到最终产物后补上同样的脚本。
|
|
5
|
+
*/
|
|
6
|
+
export type PlayableStoreUrls = {
|
|
7
|
+
ios?: string;
|
|
8
|
+
android?: string;
|
|
9
|
+
};
|
|
10
|
+
/** 商店链接全局变量,供 CTA 适配器读取;没有有效链接时返回空串。 */
|
|
11
|
+
export declare function storeUrlsScript(urls?: PlayableStoreUrls): string;
|
|
12
|
+
/** CTA 适配器:运行时识别渠道并提供 `window.PlayCraftCTA.jump()`。 */
|
|
13
|
+
export declare function ctaAdapterScript(): Promise<string>;
|
|
14
|
+
/** 跳转规则脚本:未配置有效 `redirect` 时返回空串,普通构建的产物保持不变。 */
|
|
15
|
+
export declare function redirectPolicyScript(redirect: unknown): Promise<string>;
|
|
16
|
+
/** 在 `</head>` 之前(没有时 `</body>` 之前,再没有时开头)插入脚本;函数替换避免 `$` 被当成替换模式。 */
|
|
17
|
+
export declare function insertScripts(html: string, scripts: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* 给已打好的渠道产物(单 HTML 或 ZIP)补上跳转版本脚本,原地改写。脚本与渠道适配器注入的相同:
|
|
20
|
+
* CTA 适配器在运行时识别渠道,跳转规则包装它的 `jump()` 并旁听点击计数。没有有效规则时不改动产物;
|
|
21
|
+
* 产物里找不到可注入的 HTML 时报错,避免导出名义上带跳转、实际没有的版本。
|
|
22
|
+
*
|
|
23
|
+
* `adapter: false` 用于渠道适配器已打好的产物:其中已有商店链接和 CTA 适配器,只补跳转规则,
|
|
24
|
+
* 插在它们之后。
|
|
25
|
+
*/
|
|
26
|
+
export declare function injectRedirectPolicyIntoArtifact(filePath: string, options: {
|
|
27
|
+
redirect?: unknown;
|
|
28
|
+
storeUrls?: PlayableStoreUrls;
|
|
29
|
+
adapter?: boolean;
|
|
30
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { strFromU8, strToU8, unzipSync, zipSync } from 'fflate';
|
|
5
|
+
import { minifyPatchCode } from './utils/minify.js';
|
|
6
|
+
import { normalizePlayableRedirect } from './redirect-policy.js';
|
|
7
|
+
async function patchScript(filename) {
|
|
8
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const code = await fs.readFile(path.resolve(currentDir, '../templates/patches', filename), 'utf-8');
|
|
10
|
+
return minifyPatchCode(code, filename);
|
|
11
|
+
}
|
|
12
|
+
/** 商店链接全局变量,供 CTA 适配器读取;没有有效链接时返回空串。 */
|
|
13
|
+
export function storeUrlsScript(urls) {
|
|
14
|
+
const value = urls || {};
|
|
15
|
+
if (!value.ios && !value.android)
|
|
16
|
+
return '';
|
|
17
|
+
const safeUrls = {
|
|
18
|
+
...(value.ios ? { ios: value.ios } : {}),
|
|
19
|
+
...(value.android ? { android: value.android } : {}),
|
|
20
|
+
};
|
|
21
|
+
return `<script>window.__PLAYCRAFT_STORE_URLS__=${JSON.stringify(safeUrls)};</script>`;
|
|
22
|
+
}
|
|
23
|
+
/** CTA 适配器:运行时识别渠道并提供 `window.PlayCraftCTA.jump()`。 */
|
|
24
|
+
export async function ctaAdapterScript() {
|
|
25
|
+
return `<script>${await patchScript('playcraft-cta-adapter.js')}</script>`;
|
|
26
|
+
}
|
|
27
|
+
/** 跳转规则脚本:未配置有效 `redirect` 时返回空串,普通构建的产物保持不变。 */
|
|
28
|
+
export async function redirectPolicyScript(redirect) {
|
|
29
|
+
const rule = normalizePlayableRedirect(redirect);
|
|
30
|
+
if (!rule)
|
|
31
|
+
return '';
|
|
32
|
+
return (`<script>window.__PLAYCRAFT_REDIRECT__=${JSON.stringify(rule)};</script>` +
|
|
33
|
+
`<script>${await patchScript('playcraft-redirect-policy.js')}</script>`);
|
|
34
|
+
}
|
|
35
|
+
/** 在 `</head>` 之前(没有时 `</body>` 之前,再没有时开头)插入脚本;函数替换避免 `$` 被当成替换模式。 */
|
|
36
|
+
export function insertScripts(html, scripts) {
|
|
37
|
+
if (!scripts)
|
|
38
|
+
return html;
|
|
39
|
+
if (html.includes('</head>'))
|
|
40
|
+
return html.replace('</head>', () => `${scripts}\n</head>`);
|
|
41
|
+
if (html.includes('</body>'))
|
|
42
|
+
return html.replace('</body>', () => `${scripts}\n</body>`);
|
|
43
|
+
return `${scripts}\n${html}`;
|
|
44
|
+
}
|
|
45
|
+
const UNSUPPORTED = 'redirect_versions_unsupported';
|
|
46
|
+
/** ZIP 渠道包里的入口 HTML:优先根目录 index.html,否则层级最浅的 HTML。 */
|
|
47
|
+
function zipEntryHtml(names) {
|
|
48
|
+
const html = names.filter((name) => /\.html?$/i.test(name) && !name.endsWith('/'));
|
|
49
|
+
return (html.find((name) => name.toLowerCase() === 'index.html') ??
|
|
50
|
+
html.sort((a, b) => a.split('/').length - b.split('/').length || a.length - b.length)[0]);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 给已打好的渠道产物(单 HTML 或 ZIP)补上跳转版本脚本,原地改写。脚本与渠道适配器注入的相同:
|
|
54
|
+
* CTA 适配器在运行时识别渠道,跳转规则包装它的 `jump()` 并旁听点击计数。没有有效规则时不改动产物;
|
|
55
|
+
* 产物里找不到可注入的 HTML 时报错,避免导出名义上带跳转、实际没有的版本。
|
|
56
|
+
*
|
|
57
|
+
* `adapter: false` 用于渠道适配器已打好的产物:其中已有商店链接和 CTA 适配器,只补跳转规则,
|
|
58
|
+
* 插在它们之后。
|
|
59
|
+
*/
|
|
60
|
+
export async function injectRedirectPolicyIntoArtifact(filePath, options) {
|
|
61
|
+
const policy = await redirectPolicyScript(options.redirect);
|
|
62
|
+
if (!policy)
|
|
63
|
+
return false;
|
|
64
|
+
const scripts = options.adapter === false
|
|
65
|
+
? policy
|
|
66
|
+
: storeUrlsScript(options.storeUrls) + (await ctaAdapterScript()) + policy;
|
|
67
|
+
const lower = filePath.toLowerCase();
|
|
68
|
+
if (/\.html?$/.test(lower)) {
|
|
69
|
+
const html = await fs.readFile(filePath, 'utf-8');
|
|
70
|
+
await fs.writeFile(filePath, insertScripts(html, scripts));
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (lower.endsWith('.zip')) {
|
|
74
|
+
const entries = unzipSync(new Uint8Array(await fs.readFile(filePath)));
|
|
75
|
+
const entry = zipEntryHtml(Object.keys(entries));
|
|
76
|
+
if (!entry)
|
|
77
|
+
throw new Error(`${UNSUPPORTED}: the channel package has no HTML entry`);
|
|
78
|
+
entries[entry] = strToU8(insertScripts(strFromU8(entries[entry]), scripts));
|
|
79
|
+
await fs.writeFile(filePath, zipSync(entries, { level: 9 }));
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
throw new Error(`${UNSUPPORTED}: unsupported artifact ${path.basename(filePath)}`);
|
|
83
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ export interface ComplianceValidationOptions {
|
|
|
21
21
|
export type BuildMode = 'classic' | 'esm';
|
|
22
22
|
export type ESMMode = 'auto' | 'enabled' | 'disabled';
|
|
23
23
|
export interface BuildOptions {
|
|
24
|
-
deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
|
|
25
24
|
platform: Platform;
|
|
26
25
|
format?: OutputFormat;
|
|
27
26
|
outputDir?: string;
|
|
@@ -80,9 +79,6 @@ export interface BaseBuildMetadata {
|
|
|
80
79
|
buildTool?: BuildTool;
|
|
81
80
|
skipChannelBuild?: boolean;
|
|
82
81
|
buildOutputDir?: string;
|
|
83
|
-
/** Explicit output from the project's delivery recipe; never selected by filename scanning. */
|
|
84
|
-
deliveryArtifact?: string;
|
|
85
|
-
deliveryRecipeDigest?: string;
|
|
86
82
|
}
|
|
87
83
|
export interface LocalBuildOptions {
|
|
88
84
|
scriptsConcatenate?: boolean;
|
|
@@ -123,8 +119,8 @@ export interface ProjectManifest {
|
|
|
123
119
|
path: string;
|
|
124
120
|
preload?: boolean;
|
|
125
121
|
tags?: string[];
|
|
126
|
-
i18n?: Record<string,
|
|
127
|
-
data?:
|
|
122
|
+
i18n?: Record<string, any>;
|
|
123
|
+
data?: any;
|
|
128
124
|
file?: {
|
|
129
125
|
filename: string;
|
|
130
126
|
size: number;
|
|
@@ -232,9 +228,6 @@ export interface BaseBuildOptions {
|
|
|
232
228
|
/** 渠道产物格式(playable-scripts 阶段;与 Vite 阶段 format 对齐) */
|
|
233
229
|
format?: OutputFormat;
|
|
234
230
|
validation?: ComplianceValidationOptions;
|
|
235
|
-
deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
|
|
236
|
-
/** See `ProjectDeliveryOptions.trustedDependencyRoot`. */
|
|
237
|
-
trustedDependencyRoot?: string;
|
|
238
231
|
}
|
|
239
232
|
/**
|
|
240
233
|
* 基础构建输出
|
|
@@ -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;
|