@playcraft/build 0.1.95-test-a → 0.1.97
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/index.d.ts +4 -19
- package/dist/index.js +2 -11
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.js +2 -2
- 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 +0 -5
- package/dist/validation/html-validator.d.ts +0 -5
- package/dist/validation/html-validator.js +17 -19
- package/dist/validation/index.d.ts +0 -4
- package/dist/validation/index.js +0 -4
- 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 -155
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +2 -22
- package/dist/validation/validation-runner.js +3 -68
- 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 +54 -30
- 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 -16
- 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 -20
- package/dist/delivery/command-isolation.js +0 -324
- 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 -126
- 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/validation/artifact-qa.d.ts +0 -44
- package/dist/validation/artifact-qa.js +0 -170
- package/dist/validation/artifact-rules.d.ts +0 -28
- package/dist/validation/artifact-rules.js +0 -440
- package/dist/validation/artifact.d.ts +0 -14
- package/dist/validation/artifact.js +0 -188
- package/dist/validation/runtime-load.d.ts +0 -89
- package/dist/validation/runtime-load.js +0 -654
- 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
|
* 基础构建器 - 路由到不同构建工具适配器
|
|
@@ -34,40 +31,6 @@ export class BaseBuilder {
|
|
|
34
31
|
* 根据构建工具路由到对应适配器
|
|
35
32
|
*/
|
|
36
33
|
async build() {
|
|
37
|
-
const explicit = await executeProjectDelivery(this.projectDir, {
|
|
38
|
-
outputDir: this.options.outputDir,
|
|
39
|
-
channel: this.options.validation?.channel,
|
|
40
|
-
format: this.options.format,
|
|
41
|
-
expectedPreparation: this.options.deliveryPreparation,
|
|
42
|
-
});
|
|
43
|
-
if (explicit) {
|
|
44
|
-
const metadata = {
|
|
45
|
-
mode: 'classic',
|
|
46
|
-
engine: 'generic',
|
|
47
|
-
buildTool: 'generic',
|
|
48
|
-
buildOutputDir: explicit.directory,
|
|
49
|
-
deliveryRecipeDigest: explicit.recipeDigest,
|
|
50
|
-
...(explicit.kind === 'channel-package'
|
|
51
|
-
? { skipChannelBuild: true, deliveryArtifact: explicit.entry }
|
|
52
|
-
: {}),
|
|
53
|
-
};
|
|
54
|
-
await writeFile(path.join(explicit.directory, '.build-metadata.json'), JSON.stringify(metadata, null, 2));
|
|
55
|
-
this._metadata = metadata;
|
|
56
|
-
return {
|
|
57
|
-
outputDir: explicit.directory,
|
|
58
|
-
metadata,
|
|
59
|
-
files: {
|
|
60
|
-
html: explicit.entry,
|
|
61
|
-
engine: null,
|
|
62
|
-
config: '',
|
|
63
|
-
settings: null,
|
|
64
|
-
modules: null,
|
|
65
|
-
start: '',
|
|
66
|
-
scenes: [],
|
|
67
|
-
assets: [],
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
34
|
// 1. 确定引擎类型和构建工具
|
|
72
35
|
const { engine, buildTool } = await this.resolveDetection();
|
|
73
36
|
console.log(`[BaseBuilder] 使用引擎: ${engine}, 构建工具: ${buildTool}`);
|
|
@@ -98,9 +61,7 @@ export class BaseBuilder {
|
|
|
98
61
|
}
|
|
99
62
|
async runPrebuildValidation(engine, buildTool) {
|
|
100
63
|
const validationOptions = this.options.validation;
|
|
101
|
-
if (validationOptions?.enabled === false ||
|
|
102
|
-
validationOptions?.sourcePrechecked ||
|
|
103
|
-
!validationOptions?.channel) {
|
|
64
|
+
if (validationOptions?.enabled === false || validationOptions?.sourcePrechecked || !validationOptions?.channel) {
|
|
104
65
|
return;
|
|
105
66
|
}
|
|
106
67
|
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
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +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
5
|
export { PlayableBuilder } from './playable-builder.js';
|
|
21
6
|
export type { PlayableBuildOutput } from './playable-builder.js';
|
|
22
7
|
export { OnePageConverter } from './converter.js';
|
|
23
|
-
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter
|
|
8
|
+
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter } from './engines/index.js';
|
|
24
9
|
export { BuildStateManager, BUILD_STATE_VERSION } from './state/index.js';
|
|
25
10
|
export type { AssetType, ProcessingStage, OptimizationType, AssetProcessingInfo, AssetState, BuildStageInfo, BuildState, } from './state/index.js';
|
|
26
11
|
export { StateToReportConverter } from './state/index.js';
|
|
@@ -28,8 +13,8 @@ export type { UnifiedReportData, ReportAsset, ProcessingStep, TypeStatistics, Ca
|
|
|
28
13
|
export { BuildAnalyzer } from './analyzers/build-analyzer.js';
|
|
29
14
|
export type { BuildAnalysisReport, FileAnalysis } from './analyzers/build-analyzer.js';
|
|
30
15
|
export { PlayableAnalyzer } from './analyzers/playable-analyzer.js';
|
|
31
|
-
export type { PlayableAnalysisReport, PlayableAssetAnalysis
|
|
32
|
-
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';
|
|
33
18
|
export type { SceneDependencies } from './analyzers/scene-asset-collector.js';
|
|
34
19
|
export { detectAmmoUsage } from './utils/ammo-detector.js';
|
|
35
20
|
export { createPlatformAdapter, PlatformAdapter } from './platforms/index.js';
|
|
@@ -39,6 +24,6 @@ export { ViteConfigBuilder } from './vite/config-builder.js';
|
|
|
39
24
|
export { PLATFORM_CONFIGS } from './vite/platform-configs.js';
|
|
40
25
|
export type { PlatformViteConfig } from './vite/platform-configs.js';
|
|
41
26
|
export { AudioOptimizer } from './audio-optimizer.js';
|
|
42
|
-
export type { AudioAssetInfo, AudioOptimizationReport, AudioOptimizerOptions
|
|
27
|
+
export type { AudioAssetInfo, AudioOptimizationReport, AudioOptimizerOptions } from './audio-optimizer.js';
|
|
43
28
|
export * from './validation/index.js';
|
|
44
29
|
export * from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,26 +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
4
|
export { PlayableBuilder } from './playable-builder.js';
|
|
14
5
|
export { OnePageConverter } from './converter.js';
|
|
15
6
|
// 导出引擎检测器和适配器
|
|
16
|
-
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter
|
|
7
|
+
export { EngineDetector, PlayCanvasAdapter, GenericAdapter, PlayableScriptsAdapter } from './engines/index.js';
|
|
17
8
|
// 导出状态管理器
|
|
18
9
|
export { BuildStateManager, BUILD_STATE_VERSION } from './state/index.js';
|
|
19
10
|
export { StateToReportConverter } from './state/index.js';
|
|
20
11
|
// 导出分析器
|
|
21
12
|
export { BuildAnalyzer } from './analyzers/build-analyzer.js';
|
|
22
13
|
export { PlayableAnalyzer } from './analyzers/playable-analyzer.js';
|
|
23
|
-
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies
|
|
14
|
+
export { analyzeSceneDependencies, collectScenesAssets, printSceneDependencies } from './analyzers/scene-asset-collector.js';
|
|
24
15
|
export { detectAmmoUsage } from './utils/ammo-detector.js';
|
|
25
16
|
// 导出平台适配器
|
|
26
17
|
export { createPlatformAdapter, PlatformAdapter } from './platforms/index.js';
|
package/dist/platforms/base.js
CHANGED
|
@@ -188,8 +188,8 @@ export class PlatformAdapter {
|
|
|
188
188
|
cachedAdsTrackingScript = minified;
|
|
189
189
|
return `<script>${minified}</script>`;
|
|
190
190
|
}
|
|
191
|
-
catch (
|
|
192
|
-
console.warn('[Tracking] 无法加载 @playcraft/ads-tracking:',
|
|
191
|
+
catch (e) {
|
|
192
|
+
console.warn('[Tracking] 无法加载 @playcraft/ads-tracking:', e.message);
|
|
193
193
|
return '';
|
|
194
194
|
}
|
|
195
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
|
@@ -20,7 +20,6 @@ export interface ComplianceValidationOptions {
|
|
|
20
20
|
export type BuildMode = 'classic' | 'esm';
|
|
21
21
|
export type ESMMode = 'auto' | 'enabled' | 'disabled';
|
|
22
22
|
export interface BuildOptions {
|
|
23
|
-
deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
|
|
24
23
|
platform: Platform;
|
|
25
24
|
format?: OutputFormat;
|
|
26
25
|
outputDir?: string;
|
|
@@ -77,9 +76,6 @@ export interface BaseBuildMetadata {
|
|
|
77
76
|
buildTool?: BuildTool;
|
|
78
77
|
skipChannelBuild?: boolean;
|
|
79
78
|
buildOutputDir?: string;
|
|
80
|
-
/** Explicit output from the project's delivery recipe; never selected by filename scanning. */
|
|
81
|
-
deliveryArtifact?: string;
|
|
82
|
-
deliveryRecipeDigest?: string;
|
|
83
79
|
}
|
|
84
80
|
export interface LocalBuildOptions {
|
|
85
81
|
scriptsConcatenate?: boolean;
|
|
@@ -224,7 +220,6 @@ export interface BaseBuildOptions {
|
|
|
224
220
|
/** 渠道产物格式(playable-scripts 阶段;与 Vite 阶段 format 对齐) */
|
|
225
221
|
format?: OutputFormat;
|
|
226
222
|
validation?: ComplianceValidationOptions;
|
|
227
|
-
deliveryPreparation?: import('./delivery/types.js').DeliveryPreparationStamp;
|
|
228
223
|
}
|
|
229
224
|
/**
|
|
230
225
|
* 基础构建输出
|
|
@@ -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';
|
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';
|
|
@@ -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[];
|
|
@@ -2,11 +2,10 @@ import fs from 'fs/promises';
|
|
|
2
2
|
import fsSync from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { getChannelRuleProfile } from './profiles.js';
|
|
5
|
-
import { directorySize, listDirectoryEntries } from './artifact.js';
|
|
6
5
|
import { SimpleZipReader } from './zip-reader.js';
|
|
7
6
|
const FIVE_MB = 5 * 1024 * 1024;
|
|
8
7
|
export async function validateDeliveryPackage(context, profile = getChannelRuleProfile(context.channel)) {
|
|
9
|
-
if (!context.packagePath
|
|
8
|
+
if (!context.packagePath) {
|
|
10
9
|
return [{
|
|
11
10
|
ruleId: `${context.channel}.package.path.required`,
|
|
12
11
|
channel: context.channel,
|
|
@@ -19,10 +18,9 @@ export async function validateDeliveryPackage(context, profile = getChannelRuleP
|
|
|
19
18
|
confidence: 'high',
|
|
20
19
|
}];
|
|
21
20
|
}
|
|
22
|
-
const packagePath = context.packagePath ?? 'delivery.zip';
|
|
23
21
|
let inventory;
|
|
24
22
|
try {
|
|
25
|
-
inventory = await readPackageInventory(
|
|
23
|
+
inventory = await readPackageInventory(context.packagePath);
|
|
26
24
|
}
|
|
27
25
|
catch (error) {
|
|
28
26
|
return [{
|
|
@@ -31,9 +29,9 @@ export async function validateDeliveryPackage(context, profile = getChannelRuleP
|
|
|
31
29
|
stage: 'delivery-package',
|
|
32
30
|
severity: 'error',
|
|
33
31
|
status: 'fail',
|
|
34
|
-
message: `Delivery package is not readable: ${packagePath}`,
|
|
32
|
+
message: `Delivery package is not readable: ${context.packagePath}`,
|
|
35
33
|
recommendation: 'Verify the generated ZIP or delivery directory exists and is readable.',
|
|
36
|
-
file: packagePath,
|
|
34
|
+
file: context.packagePath,
|
|
37
35
|
evidence: error instanceof Error ? error.message : String(error),
|
|
38
36
|
owner: 'playcraft-delivery',
|
|
39
37
|
confidence: 'high',
|
|
@@ -64,26 +62,18 @@ export async function validateDeliveryPackage(context, profile = getChannelRuleP
|
|
|
64
62
|
}
|
|
65
63
|
return results;
|
|
66
64
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const entries = await listDirectoryEntries(packagePath);
|
|
78
|
-
return {
|
|
79
|
-
packagePath,
|
|
80
|
-
entries,
|
|
81
|
-
readText: (entryPath) => readTextFromDirectorySyncUnsupported(packagePath, entryPath),
|
|
82
|
-
size: await directorySize(packagePath),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
65
|
+
async function readPackageInventory(packagePath) {
|
|
66
|
+
const stat = await fs.stat(packagePath);
|
|
67
|
+
if (stat.isDirectory()) {
|
|
68
|
+
const entries = await readDirectoryEntries(packagePath);
|
|
69
|
+
return {
|
|
70
|
+
packagePath,
|
|
71
|
+
entries,
|
|
72
|
+
readText: (entryPath) => readTextFromDirectorySyncUnsupported(packagePath, entryPath),
|
|
73
|
+
size: await calculateDirectorySize(packagePath),
|
|
74
|
+
};
|
|
85
75
|
}
|
|
86
|
-
const buffer =
|
|
76
|
+
const buffer = await fs.readFile(packagePath);
|
|
87
77
|
const zip = new SimpleZipReader(buffer);
|
|
88
78
|
return {
|
|
89
79
|
packagePath,
|
|
@@ -92,6 +82,38 @@ async function readPackageInventory(packagePath, packageBytes) {
|
|
|
92
82
|
size: buffer.length,
|
|
93
83
|
};
|
|
94
84
|
}
|
|
85
|
+
async function readDirectoryEntries(dir) {
|
|
86
|
+
const entries = [];
|
|
87
|
+
const walk = async (current) => {
|
|
88
|
+
const dirEntries = await fs.readdir(current, { withFileTypes: true });
|
|
89
|
+
for (const entry of dirEntries) {
|
|
90
|
+
const fullPath = path.join(current, entry.name);
|
|
91
|
+
const relative = path.relative(dir, fullPath).replace(/\\/g, '/');
|
|
92
|
+
if (entry.isDirectory()) {
|
|
93
|
+
entries.push({
|
|
94
|
+
path: `${relative}/`,
|
|
95
|
+
compressedSize: 0,
|
|
96
|
+
uncompressedSize: 0,
|
|
97
|
+
compressionMethod: 0,
|
|
98
|
+
isDirectory: true,
|
|
99
|
+
});
|
|
100
|
+
await walk(fullPath);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const stat = await fs.stat(fullPath);
|
|
104
|
+
entries.push({
|
|
105
|
+
path: relative,
|
|
106
|
+
compressedSize: stat.size,
|
|
107
|
+
uncompressedSize: stat.size,
|
|
108
|
+
compressionMethod: 0,
|
|
109
|
+
isDirectory: false,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
await walk(dir);
|
|
115
|
+
return entries;
|
|
116
|
+
}
|
|
95
117
|
function readTextFromDirectorySyncUnsupported(_packagePath, _entryPath) {
|
|
96
118
|
const filePath = path.join(_packagePath, _entryPath);
|
|
97
119
|
try {
|
|
@@ -101,6 +123,23 @@ function readTextFromDirectorySyncUnsupported(_packagePath, _entryPath) {
|
|
|
101
123
|
return null;
|
|
102
124
|
}
|
|
103
125
|
}
|
|
126
|
+
async function calculateDirectorySize(dir) {
|
|
127
|
+
let total = 0;
|
|
128
|
+
const walk = async (current) => {
|
|
129
|
+
const entries = await fs.readdir(current, { withFileTypes: true });
|
|
130
|
+
for (const entry of entries) {
|
|
131
|
+
const fullPath = path.join(current, entry.name);
|
|
132
|
+
if (entry.isDirectory()) {
|
|
133
|
+
await walk(fullPath);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
total += (await fs.stat(fullPath)).size;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
await walk(dir);
|
|
141
|
+
return total;
|
|
142
|
+
}
|
|
104
143
|
function validateZipLikePackage(channel, inventory) {
|
|
105
144
|
const paths = new Set(inventory.entries.map((entry) => entry.path));
|
|
106
145
|
return [
|