feat: migrate workbench to React

This commit is contained in:
2026-08-26 15:01:07 +08:00
parent f15e69c868
commit 3ddb33e321
48 changed files with 16748 additions and 1509 deletions

View File

@@ -101,8 +101,5 @@
"bytes": 15491
}
},
"volatileExcluded": [
"absolute paths -> <repo> or <external>",
"native-road-* staging directory -> <staging>"
]
"volatileExcluded": ["absolute paths -> <repo> or <external>", "native-road-* staging directory -> <staging>"]
}

View File

@@ -101,8 +101,5 @@
"bytes": 74151
}
},
"volatileExcluded": [
"absolute paths -> <repo> or <external>",
"native-road-* staging directory -> <staging>"
]
"volatileExcluded": ["absolute paths -> <repo> or <external>", "native-road-* staging directory -> <staging>"]
}

View File

@@ -1,49 +1,61 @@
"use strict";
'use strict';
const assert = require("assert/strict");
const crypto = require("crypto");
const { execFileSync } = require("child_process");
const fs = require("fs");
const path = require("path");
const { unzipSync, strFromU8 } = require("fflate");
const { compiler } = require("../src");
const { exportNativeRoadPackage } = require("../src/export/native-road-package");
const assert = require('assert/strict');
const crypto = require('crypto');
const { execFileSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const { unzipSync, strFromU8 } = require('fflate');
const { compiler } = require('../src');
const { exportNativeRoadPackage } = require('../src/export/native-road-package');
const root = path.resolve(__dirname, "..");
for (const areaId of ["fengshu-er-road", "nantaizi-lake-innovation-valley"]) {
const isFengshu = areaId === "fengshu-er-road";
const outputRoot = path.join(root, "outputs", areaId);
const root = path.resolve(__dirname, '..');
for (const areaId of ['fengshu-er-road', 'nantaizi-lake-innovation-valley']) {
const isFengshu = areaId === 'fengshu-er-road';
const outputRoot = path.join(root, 'outputs', areaId);
const input = {
areaId,
osmFile: path.join(root, "inputs", "osm", isFengshu ? "枫树二路.osm" : "南台子湖创新谷OSM.osm"),
outDir: path.join(outputRoot, "native-road"),
stagingDir: path.join(outputRoot, "_pipeline"),
overridesFile: path.join(outputRoot, "native-road-overrides.json"),
trafficSignalsFile: path.join(outputRoot, "native-traffic-signals.json"),
comparisonDir: path.join(outputRoot, "osm2streets_web_out"),
osmFile: path.join(root, 'inputs', 'osm', isFengshu ? '枫树二路.osm' : '南台子湖创新谷OSM.osm'),
outDir: path.join(outputRoot, 'native-road'),
stagingDir: path.join(outputRoot, '_pipeline'),
overridesFile: path.join(outputRoot, 'native-road-overrides.json'),
trafficSignalsFile: path.join(outputRoot, 'native-traffic-signals.json'),
comparisonDir: path.join(outputRoot, 'osm2streets_web_out'),
options: { edgeLines: false, junctionTemplates: { enabled: false, references: [] } },
};
assert.ok(fs.existsSync(path.join(root, "test", "baseline", `${areaId}.json`)));
assert.ok(fs.existsSync(path.join(root, 'test', 'baseline', `${areaId}.json`)));
const { result } = compiler.compileInput(input);
assert.equal(result.areaId, areaId);
assert.ok(fs.existsSync(path.join(input.outDir, "compiled.json")));
assert.ok(fs.existsSync(path.join(input.outDir, 'compiled.json')));
const first = exportNativeRoadPackage(input.outDir);
const second = exportNativeRoadPackage(input.outDir);
assert.equal(crypto.createHash("sha256").update(first.bytes).digest("hex"), crypto.createHash("sha256").update(second.bytes).digest("hex"));
assert.equal(
crypto.createHash('sha256').update(first.bytes).digest('hex'),
crypto.createHash('sha256').update(second.bytes).digest('hex'),
);
const entries = unzipSync(first.bytes);
const manifest = JSON.parse(strFromU8(entries["manifest.json"]));
const manifest = JSON.parse(strFromU8(entries['manifest.json']));
assert.equal(manifest.areaId, areaId);
assert.equal(manifest.contract, "native-road-package/v1.1");
assert.deepEqual(manifest.generator, { name: "road-compiler", version: "0.3.0" });
assert.equal("source" in JSON.parse(strFromU8(entries["compiled.json"])), false);
assert.equal(Object.keys(entries).some((entry) => entry.includes("override") || entry.endsWith(".osm")), false);
assert.equal(manifest.contract, 'native-road-package/v1.1');
assert.deepEqual(manifest.generator, { name: 'road-compiler', version: '0.3.0' });
assert.equal('source' in JSON.parse(strFromU8(entries['compiled.json'])), false);
assert.equal(
Object.keys(entries).some((entry) => entry.includes('override') || entry.endsWith('.osm')),
false,
);
assert.equal(Object.keys(entries).length, 18);
if (isFengshu) {
const inputFile = path.join(outputRoot, "road-compiler-input.json");
const archive = path.join(outputRoot, "export.zip");
const inputFile = path.join(outputRoot, 'road-compiler-input.json');
const archive = path.join(outputRoot, 'export.zip');
fs.writeFileSync(inputFile, `${JSON.stringify(input)}\n`);
execFileSync(process.execPath, [path.join(root, "bin", "road-compiler.js"), "--input", inputFile, "--export-zip", archive]);
execFileSync(process.execPath, [
path.join(root, 'bin', 'road-compiler.js'),
'--input',
inputFile,
'--export-zip',
archive,
]);
assert.ok(fs.existsSync(archive));
}
}
console.log("road compiler fixture tests passed");
console.log('road compiler fixture tests passed');

File diff suppressed because one or more lines are too long

View File

@@ -1,25 +1,31 @@
"use strict";
'use strict';
const assert = require("assert/strict");
const fs = require("fs");
const path = require("path");
const compiler = require("../src");
const assert = require('assert/strict');
const fs = require('fs');
const path = require('path');
const compiler = require('../src');
assert.equal(typeof compiler.laneGeometry.laneCenterline, "function");
assert.equal(typeof compiler.gaodeReference.convertGeoJson, "function");
assert.equal(typeof compiler.turnLaneArrows.buildCustomTurnLaneArrows, "function");
assert.equal(typeof compiler.complexJunction.buildComplexJunctionGeometry, "function");
assert.equal(typeof compiler.nativeRoad.compileRoadModel, "function");
assert.equal(typeof compiler.check.checkOutput, "function");
assert.equal(typeof compiler.layerManifest.manifestForArea, "function");
const manifest = compiler.layerManifest.manifestForArea("fixture");
assert.equal(manifest.contract, "native-road-package/v1.1");
assert.equal(typeof compiler.laneGeometry.laneCenterline, 'function');
assert.equal(typeof compiler.gaodeReference.convertGeoJson, 'function');
assert.equal(typeof compiler.turnLaneArrows.buildCustomTurnLaneArrows, 'function');
assert.equal(typeof compiler.complexJunction.buildComplexJunctionGeometry, 'function');
assert.equal(typeof compiler.nativeRoad.compileRoadModel, 'function');
assert.equal(typeof compiler.check.checkOutput, 'function');
assert.equal(typeof compiler.layerManifest.manifestForArea, 'function');
const manifest = compiler.layerManifest.manifestForArea('fixture');
assert.equal(manifest.contract, 'native-road-package/v1.1');
assert.equal(manifest.layers.length, 12);
assert.deepEqual(manifest.layers.filter((layer) => layer.role === "semantic").map((layer) => layer.source), ["lane_centerlines", "connectors"]);
assert.equal(manifest.layers.find((layer) => layer.source === "center_lines").splitBy.cases[0].match, "white");
const fixture = path.join(__dirname, "fixtures", "fengshu-er-road.osm");
assert.deepEqual(
manifest.layers.filter((layer) => layer.role === 'semantic').map((layer) => layer.source),
['lane_centerlines', 'connectors'],
);
assert.equal(manifest.layers.find((layer) => layer.source === 'center_lines').splitBy.cases[0].match, 'white');
const fixture = path.join(__dirname, 'fixtures', 'fengshu-er-road.osm');
assert.ok(fs.existsSync(fixture));
assert.throws(() => compiler.compiler.validateInput({ id: "area" }), /RoadCompilerInput/);
const model = compiler.nativeRoad.compileRoadModel(fs.readFileSync(fixture, "utf8"), { schema: "native-road-overrides/v1", overrides: [] });
assert.throws(() => compiler.compiler.validateInput({ id: 'area' }), /RoadCompilerInput/);
const model = compiler.nativeRoad.compileRoadModel(fs.readFileSync(fixture, 'utf8'), {
schema: 'native-road-overrides/v1',
overrides: [],
});
assert.equal(model.roads.length, 24);
console.log("road compiler package tests passed");
console.log('road compiler package tests passed');