feat: migrate workbench to React

This commit is contained in:
que01 committed 2026-08-26 15:01:07 +08:00
1 parent f15e69c868
commit 3ddb33e321
48 files changed
+16748 -1509

No files matched your search

+27 -22
View File
@@ -1,49 +1,54 @@
"use strict";
'use strict';
const fs = require("fs");
const path = require("path");
const { zipSync } = require("fflate");
const { LAYER_REGISTRY, validatePublishedLayers } = require("../compile/layer-manifest");
const fs = require('fs');
const path = require('path');
const { zipSync } = require('fflate');
const { LAYER_REGISTRY, validatePublishedLayers } = require('../compile/layer-manifest');
const ROOT_FILES = [
"manifest.json",
"compiled.json",
"diagnostics.json",
"comparison.json",
"traffic-signal-assemblies.json",
"traffic-signals.json",
'manifest.json',
'compiled.json',
'diagnostics.json',
'comparison.json',
'traffic-signal-assemblies.json',
'traffic-signals.json',
];
const GENERATOR = Object.freeze({ name: "road-compiler", version: "0.3.0" });
const GENERATOR = Object.freeze({ name: 'road-compiler', version: '0.3.0' });
function packageEntries(directory) {
const manifestPath = path.join(directory, "manifest.json");
const manifestPath = path.join(directory, 'manifest.json');
if (!fs.existsSync(manifestPath)) throw new Error(`Native road package manifest is missing: ${manifestPath}`);
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
if (manifest.contract !== "native-road-package/v1.1") throw new Error("Native road package requires native-road-package/v1.1.");
if (!manifest.areaId || typeof manifest.areaId !== "string") throw new Error("Native road package manifest areaId is required.");
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
if (manifest.contract !== 'native-road-package/v1.1')
throw new Error('Native road package requires native-road-package/v1.1.');
if (!manifest.areaId || typeof manifest.areaId !== 'string')
throw new Error('Native road package manifest areaId is required.');
validatePublishedLayers(directory, manifest);
const files = [];
for (const relative of ROOT_FILES) files.push(relative);
for (const layer of LAYER_REGISTRY) files.push(`layers/${layer.source}.geojson`);
for (const relative of files) {
const file = path.join(directory, relative);
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new Error(`Native road package file is missing: ${relative}`);
if (!fs.existsSync(file) || !fs.statSync(file).isFile())
throw new Error(`Native road package file is missing: ${relative}`);
}
return { manifest, files: [...new Set(files)].sort() };
}
function exportNativeRoadPackage(directory, destination = null) {
const { manifest, files } = packageEntries(directory);
const entries = Object.fromEntries(files.map((relative) => [relative, fs.readFileSync(path.join(directory, relative))]));
const entries = Object.fromEntries(
files.map((relative) => [relative, fs.readFileSync(path.join(directory, relative))]),
);
// The model/movements remain needed by host preview generation, but absolute
// compiler-workspace paths are not part of the exported package contract.
const compiled = JSON.parse(entries["compiled.json"].toString("utf8"));
const compiled = JSON.parse(entries['compiled.json'].toString('utf8'));
delete compiled.source;
entries["compiled.json"] = Buffer.from(`${JSON.stringify(compiled, null, 2)}\n`);
entries["manifest.json"] = Buffer.from(`${JSON.stringify({ ...manifest, generator: GENERATOR }, null, 2)}\n`);
entries['compiled.json'] = Buffer.from(`${JSON.stringify(compiled, null, 2)}\n`);
entries['manifest.json'] = Buffer.from(`${JSON.stringify({ ...manifest, generator: GENERATOR }, null, 2)}\n`);
// ZIP timestamps start at 1980; a fixed value keeps repeated exports byte-stable.
const bytes = zipSync(entries, { level: 6, mtime: new Date("1980-01-01T00:00:00Z") });
const bytes = zipSync(entries, { level: 6, mtime: new Date('1980-01-01T00:00:00Z') });
if (destination) {
fs.mkdirSync(path.dirname(destination), { recursive: true });
const temporary = `${destination}.tmp-${process.pid}`;