@threenative/runtime-native 0.2.0
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/LICENSE +21 -0
- package/NOTICE +10 -0
- package/android/README.md +155 -0
- package/android/app/build.gradle.kts +298 -0
- package/android/app/proguard-rules.pro +12 -0
- package/android/app/src/main/AndroidManifest.xml +45 -0
- package/android/app/src/main/java/com/mystral/engine/MystralActivity.java +88 -0
- package/android/app/src/main/res/values/strings.xml +5 -0
- package/android/app/src/main/res/values/themes.xml +8 -0
- package/android/build.gradle.kts +5 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/android/gradle.properties +13 -0
- package/android/gradlew +185 -0
- package/android/settings.gradle.kts +17 -0
- package/package.json +56 -0
- package/scripts/bundle.mjs +343 -0
- package/scripts/install-prebuilt.mjs +102 -0
- package/scripts/package-android.mjs +412 -0
- package/scripts/package-desktop.mjs +123 -0
- package/scripts/package-ios.mjs +385 -0
- package/scripts/production-evidence.mjs +286 -0
- package/scripts/profile-production.mjs +1525 -0
- package/scripts/verify-starter-desktop.mjs +103 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { basename, join, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
|
+
import { PNG } from 'pngjs';
|
|
9
|
+
|
|
10
|
+
const workspaceRoot = resolve(fileURLToPath(import.meta.url), '..', '..', '..', '..');
|
|
11
|
+
const READY_MARKER = 'TN_NATIVE_SMOKE_READY:webgpu';
|
|
12
|
+
const ASSET_MARKER = 'TN_NATIVE_STARTER_ASSETS_LOADED:texture,glb';
|
|
13
|
+
|
|
14
|
+
export function inspectStarterScreenshot(path) {
|
|
15
|
+
if (!existsSync(path)) throw new Error(`TN_NATIVE_STARTER_SCREENSHOT_MISSING: ${path}`);
|
|
16
|
+
const png = PNG.sync.read(readFileSync(path));
|
|
17
|
+
const colors = new Set();
|
|
18
|
+
let cyanAssetPixels = 0;
|
|
19
|
+
for (let index = 0; index < png.data.length; index += 4) {
|
|
20
|
+
const red = png.data[index];
|
|
21
|
+
const green = png.data[index + 1];
|
|
22
|
+
const blue = png.data[index + 2];
|
|
23
|
+
const alpha = png.data[index + 3];
|
|
24
|
+
colors.add(`${red},${green},${blue},${alpha}`);
|
|
25
|
+
if (alpha > 0 && blue > 150 && green > 140 && blue > red * 1.4) cyanAssetPixels += 1;
|
|
26
|
+
}
|
|
27
|
+
if (colors.size < 2) throw new Error('TN_NATIVE_STARTER_SCREENSHOT_BLANK: one-color frame.');
|
|
28
|
+
if (cyanAssetPixels < 100) {
|
|
29
|
+
throw new Error(`TN_NATIVE_STARTER_ASSET_NOT_VISIBLE: found ${cyanAssetPixels} cyan proof pixels.`);
|
|
30
|
+
}
|
|
31
|
+
return { colors: colors.size, cyanAssetPixels, height: png.height, width: png.width };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function analyzeStarterLog(log, frames = 300) {
|
|
35
|
+
const failures = [];
|
|
36
|
+
for (const marker of [READY_MARKER, ASSET_MARKER, `TN_NATIVE_SMOKE_${frames}_FRAMES:${frames}`]) {
|
|
37
|
+
if (!log.includes(marker)) failures.push(`missing ${marker}`);
|
|
38
|
+
}
|
|
39
|
+
if (!new RegExp(`Rendered ${frames} frames in \\d+ms`, 'u').test(log)) {
|
|
40
|
+
failures.push(`missing exact ${frames}-frame completion`);
|
|
41
|
+
}
|
|
42
|
+
for (const pattern of [/TN_NATIVE_START_FAILED/u, /validation error/iu, /TypeError:/u]) {
|
|
43
|
+
if (pattern.test(log)) failures.push(`runtime log matched ${pattern}`);
|
|
44
|
+
}
|
|
45
|
+
return failures;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function verifyStarterDesktop({ frames = 300, project = process.cwd() } = {}) {
|
|
49
|
+
const projectRoot = resolve(project);
|
|
50
|
+
const manifest = JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8'));
|
|
51
|
+
const projectName = basename(String(manifest.name ?? 'starter').replace(/^@[^/]+\//u, ''));
|
|
52
|
+
const executableName = process.platform === 'win32' ? `${projectName}.exe` : projectName;
|
|
53
|
+
const artifact = join(projectRoot, 'dist-native', executableName);
|
|
54
|
+
if (!existsSync(artifact)) {
|
|
55
|
+
throw new Error(`TN_NATIVE_STARTER_ARTIFACT_MISSING: run pnpm build:desktop first (${artifact}).`);
|
|
56
|
+
}
|
|
57
|
+
const artifactDirectory = join(projectRoot, 'artifacts', 'native');
|
|
58
|
+
const screenshot = join(artifactDirectory, 'starter-desktop.png');
|
|
59
|
+
const logPath = join(artifactDirectory, 'starter-desktop.log');
|
|
60
|
+
const reportPath = join(artifactDirectory, 'starter-desktop-report.json');
|
|
61
|
+
mkdirSync(artifactDirectory, { recursive: true });
|
|
62
|
+
const runtimeArgs = ['--screenshot', screenshot, '--frames', String(frames)];
|
|
63
|
+
// See verify-desktop-core.mjs: `xvfb-run` hands back its own failing cleanup kill's status.
|
|
64
|
+
const command = process.platform === 'linux' ? 'sh' : artifact;
|
|
65
|
+
const args = process.platform === 'linux'
|
|
66
|
+
? [join(workspaceRoot, 'scripts', 'xvfb.sh'), artifact, ...runtimeArgs]
|
|
67
|
+
: runtimeArgs;
|
|
68
|
+
const result = spawnSync(command, args, {
|
|
69
|
+
cwd: projectRoot,
|
|
70
|
+
encoding: 'utf8',
|
|
71
|
+
env: process.platform === 'linux' ? { ...process.env, SDL_VIDEODRIVER: 'x11' } : process.env,
|
|
72
|
+
timeout: 120_000,
|
|
73
|
+
});
|
|
74
|
+
if (result.error) throw result.error;
|
|
75
|
+
const log = `${result.stdout ?? ''}\n${result.stderr ?? ''}`;
|
|
76
|
+
writeFileSync(logPath, log);
|
|
77
|
+
if (result.status !== 0) throw new Error(`TN_NATIVE_STARTER_EXIT_${result.status}:\n${log}`);
|
|
78
|
+
const failures = analyzeStarterLog(log, frames);
|
|
79
|
+
if (failures.length > 0) throw new Error(`TN_NATIVE_STARTER_LOG_FAILED:\n${failures.join('\n')}`);
|
|
80
|
+
const image = inspectStarterScreenshot(screenshot);
|
|
81
|
+
const report = {
|
|
82
|
+
artifact,
|
|
83
|
+
completedAt: new Date().toISOString(),
|
|
84
|
+
frames,
|
|
85
|
+
image,
|
|
86
|
+
log: logPath,
|
|
87
|
+
pass: true,
|
|
88
|
+
screenshot,
|
|
89
|
+
screenshotSha256: createHash('sha256').update(readFileSync(screenshot)).digest('hex'),
|
|
90
|
+
};
|
|
91
|
+
writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`);
|
|
92
|
+
return report;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
96
|
+
try {
|
|
97
|
+
const report = verifyStarterDesktop();
|
|
98
|
+
console.log(`starter desktop gate passed: ${report.frames} frames, ${report.image.colors} colors, ${report.image.cyanAssetPixels} asset pixels`);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
101
|
+
process.exitCode = 1;
|
|
102
|
+
}
|
|
103
|
+
}
|