Graduate TUI runtime from Eve
This commit is contained in:
parent
294b3ec5b4
commit
afdbbc4375
23 changed files with 9 additions and 2168 deletions
|
|
@ -1,118 +0,0 @@
|
|||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { EveTuiShell } from "../../runtimes/incubating/eve-tui/src/eve-tui-shell.mjs";
|
||||
import { buildTuiCaptureRequest, loadJsonFile, writeCaptureRequest } from "./evetui-capture-contract.mjs";
|
||||
|
||||
export function buildTuiCaptureArtifact({
|
||||
advertisement,
|
||||
capabilityManifest,
|
||||
surfaceDocument,
|
||||
advertisementPath = "",
|
||||
capabilityManifestPath = "",
|
||||
captureSurfaceId = "",
|
||||
stamp = "latest",
|
||||
width = 80,
|
||||
} = {}) {
|
||||
const request = buildTuiCaptureRequest({
|
||||
advertisement,
|
||||
capabilityManifest,
|
||||
advertisementPath,
|
||||
capabilityManifestPath,
|
||||
captureSurfaceId,
|
||||
stamp,
|
||||
});
|
||||
const shell = new EveTuiShell({ width });
|
||||
const grid = shell.lowerSurface(surfaceDocument, advertisement, request.surfaceId);
|
||||
validateGridArtifact(grid, request);
|
||||
|
||||
return {
|
||||
request,
|
||||
grid: {
|
||||
...grid,
|
||||
artifactKind: request.artifactKind,
|
||||
captureKind: request.captureKind,
|
||||
sourceAdvertisementPath: request.sourceAdvertisementPath,
|
||||
sourceCapabilityManifestPath: request.sourceCapabilityManifestPath,
|
||||
issuedAtUtc: request.issuedAtUtc,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function writeTuiCaptureArtifact({ request, grid }, { outputPath, requestOutputPath = "" } = {}) {
|
||||
if (!outputPath) throw new Error("outputPath is required");
|
||||
mkdirSync(path.dirname(outputPath), { recursive: true });
|
||||
writeFileSync(outputPath, `${JSON.stringify(grid, null, 2)}\n`, "utf8");
|
||||
if (requestOutputPath) {
|
||||
writeCaptureRequest(request, requestOutputPath);
|
||||
}
|
||||
}
|
||||
|
||||
function validateGridArtifact(grid, request) {
|
||||
if (grid.schema !== "gamecult.eve.tui_grid.v1") {
|
||||
throw new Error(`Unexpected TUI grid schema: ${grid.schema || ""}`);
|
||||
}
|
||||
for (const [field, expected] of [
|
||||
["runtimeId", request.runtimeId],
|
||||
["providerId", request.providerId],
|
||||
["surfaceId", request.surfaceId],
|
||||
["projectionKind", request.projectionKind],
|
||||
["commandBoundary", request.commandBoundary],
|
||||
["receiptSchema", request.receiptSchema],
|
||||
]) {
|
||||
if ((grid[field] || "") !== (expected || "")) {
|
||||
throw new Error(`TUI grid ${field} expected ${expected || ""} got ${grid[field] || ""}`);
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(grid.lines) || !grid.lines.length) {
|
||||
throw new Error("TUI grid artifact must contain at least one line");
|
||||
}
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
const args = {};
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const value = argv[index];
|
||||
if (!value.startsWith("--")) continue;
|
||||
const key = value.slice(2);
|
||||
const next = argv[index + 1];
|
||||
if (!next || next.startsWith("--")) {
|
||||
args[key] = true;
|
||||
} else {
|
||||
args[key] = next;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function runCli() {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
for (const required of ["advertisement", "capability", "surface", "output"]) {
|
||||
if (!args[required]) {
|
||||
throw new Error(`missing required --${required}`);
|
||||
}
|
||||
}
|
||||
const stamp = args.stamp || "latest";
|
||||
const artifact = buildTuiCaptureArtifact({
|
||||
advertisement: loadJsonFile(args.advertisement),
|
||||
capabilityManifest: loadJsonFile(args.capability),
|
||||
surfaceDocument: loadJsonFile(args.surface),
|
||||
advertisementPath: args.advertisement,
|
||||
capabilityManifestPath: args.capability,
|
||||
captureSurfaceId: args["surface-id"] || "",
|
||||
stamp,
|
||||
width: Number(args.width || 80),
|
||||
});
|
||||
writeTuiCaptureArtifact(artifact, {
|
||||
outputPath: args.output,
|
||||
requestOutputPath: args["request-output"] || "",
|
||||
});
|
||||
process.stdout.write(`${args.output}\n`);
|
||||
}
|
||||
|
||||
const invokedPath = process.argv[1] ? path.resolve(process.argv[1]) : "";
|
||||
const modulePath = fileURLToPath(import.meta.url);
|
||||
if (invokedPath === modulePath) {
|
||||
runCli();
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import { buildTuiCaptureArtifact } from "./evetui-capture-artifact.mjs";
|
||||
|
||||
const advertisement = JSON.parse(readFileSync(new URL("../../../Aetheria/conformance/eve/aetheria.provider-advertisement.json", import.meta.url), "utf8"));
|
||||
const capabilityManifest = JSON.parse(readFileSync(new URL("../../runtimes/incubating/eve-tui/eve-runtime-capability.json", import.meta.url), "utf8"));
|
||||
const surfaceDocument = JSON.parse(readFileSync(new URL("../../../Aetheria/conformance/eve/aetheria-world-surface.json", import.meta.url), "utf8"));
|
||||
const worldSmokeAdvertisement = JSON.parse(readFileSync(new URL("../../web/fixtures/eve-world-smoke.provider-advertisement.json", import.meta.url), "utf8"));
|
||||
const worldSmokeSurfaceDocument = JSON.parse(readFileSync(new URL("../../web/fixtures/eve-world-smoke-surface.json", import.meta.url), "utf8"));
|
||||
|
||||
test("builds TUI JSON grid capture artifact from provider advertisement and surface", () => {
|
||||
const { request, grid } = buildTuiCaptureArtifact({
|
||||
advertisement,
|
||||
capabilityManifest,
|
||||
surfaceDocument,
|
||||
advertisementPath: "conformance/eve/aetheria.provider-advertisement.json",
|
||||
capabilityManifestPath: "runtimes/incubating/eve-tui/eve-runtime-capability.json",
|
||||
stamp: "smoke",
|
||||
width: 72,
|
||||
});
|
||||
|
||||
assert.equal(request.artifactKind, "json-grid");
|
||||
assert.equal(request.artifactPath, "artifacts/evetui-capture/smoke/tui-grid.json");
|
||||
assert.equal(grid.schema, "gamecult.eve.tui_grid.v1");
|
||||
assert.equal(grid.runtimeId, "tui");
|
||||
assert.equal(grid.providerId, "aetheria");
|
||||
assert.equal(grid.surfaceId, "aetheria.daemon.game");
|
||||
assert.equal(grid.commandBoundary, "aetheria.daemon.commands");
|
||||
assert.equal(grid.receiptSchema, "aetheria.eve_command_acceptance_status.v1");
|
||||
assert.equal(grid.artifactKind, "json-grid");
|
||||
assert.equal(grid.captureKind, "terminal-cell-grid");
|
||||
assert.equal(grid.width, 72);
|
||||
assert.ok(grid.lines.some(line => line.includes("aetheria.daemon.game")));
|
||||
});
|
||||
|
||||
test("builds TUI JSON grid capture artifact from a generic world provider", () => {
|
||||
const { grid } = buildTuiCaptureArtifact({
|
||||
advertisement: worldSmokeAdvertisement,
|
||||
capabilityManifest,
|
||||
surfaceDocument: worldSmokeSurfaceDocument,
|
||||
advertisementPath: "web/fixtures/eve-world-smoke.provider-advertisement.json",
|
||||
capabilityManifestPath: "runtimes/incubating/eve-tui/eve-runtime-capability.json",
|
||||
stamp: "smoke",
|
||||
width: 72,
|
||||
});
|
||||
|
||||
assert.equal(grid.schema, "gamecult.eve.tui_grid.v1");
|
||||
assert.equal(grid.runtimeId, "tui");
|
||||
assert.equal(grid.providerId, "eve.world-smoke");
|
||||
assert.equal(grid.surfaceId, "eve.world-smoke.surface");
|
||||
assert.equal(grid.commandBoundary, "eve.world-smoke.commands");
|
||||
assert.equal(grid.receiptSchema, "eve.world_smoke.command_receipt.v1");
|
||||
assert.equal(grid.artifactKind, "json-grid");
|
||||
assert.equal(grid.captureKind, "terminal-cell-grid");
|
||||
assert.ok(grid.lines.some(line => line.includes("eve.world-smoke.surface")));
|
||||
});
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
export function buildTuiCaptureRequest({
|
||||
advertisement,
|
||||
capabilityManifest,
|
||||
advertisementPath = "",
|
||||
capabilityManifestPath = "",
|
||||
captureSurfaceId = "",
|
||||
stamp = new Date().toISOString().replace(/[:.]/g, "-"),
|
||||
} = {}) {
|
||||
if (!advertisement || typeof advertisement !== "object") {
|
||||
throw new Error("advertisement is required");
|
||||
}
|
||||
if (!capabilityManifest || typeof capabilityManifest !== "object") {
|
||||
throw new Error("capabilityManifest is required");
|
||||
}
|
||||
|
||||
const captureContract = capabilityManifest.lifecycle?.capture?.captureContract;
|
||||
if (!captureContract) {
|
||||
throw new Error("capability manifest is missing lifecycle.capture.captureContract");
|
||||
}
|
||||
|
||||
const captureSurface = selectCaptureSurface(captureContract, advertisement.providerId, captureSurfaceId);
|
||||
if (!captureSurface) {
|
||||
if (captureSurfaceId) {
|
||||
throw new Error(
|
||||
`capture surface mismatch: expected ${captureSurfaceList(captureContract)} got ${advertisement.providerId || "missing"}:${captureSurfaceId}`,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`capture provider mismatch: expected ${captureProviderList(captureContract)} got ${advertisement.providerId || "missing"}`,
|
||||
);
|
||||
}
|
||||
|
||||
const targetId = captureContract.targetId || captureContract.runtimeId;
|
||||
const surface = (advertisement.surfaces || []).find(candidate => candidate.surfaceId === captureSurface.surfaceId);
|
||||
if (!surface) {
|
||||
throw new Error(`capture surface not advertised: ${captureSurface.surfaceId}`);
|
||||
}
|
||||
|
||||
const loweringTargets = surface.worldInteraction?.loweringTargets || [];
|
||||
if (!loweringTargets.includes(targetId)) {
|
||||
throw new Error(`surface ${surface.surfaceId} does not advertise lowering target ${targetId}`);
|
||||
}
|
||||
|
||||
const artifactPath = replaceStamp(captureContract.artifactPattern, stamp);
|
||||
|
||||
return {
|
||||
schema: captureContract.requestSchema || "gamecult.eve.runtime_capture_request.v1",
|
||||
runtimeId: capabilityManifest.runtimeId,
|
||||
ownerRepo: captureContract.ownerRepo,
|
||||
providerId: advertisement.providerId,
|
||||
surfaceId: surface.surfaceId,
|
||||
surfaceKind: surface.surfaceKind || "",
|
||||
targetId,
|
||||
projectionKind: surface.worldInteraction?.projectionKind || "",
|
||||
commandBoundary: surface.worldInteraction?.commandBoundary || "",
|
||||
receiptSchema: surface.worldInteraction?.receiptSchema || "",
|
||||
captureKind: captureContract.captureKind,
|
||||
artifactKind: captureContract.artifactKind,
|
||||
artifactPath,
|
||||
conformanceAttachment: captureContract.conformanceAttachment,
|
||||
authority: captureContract.authority,
|
||||
sourceAdvertisementPath: advertisementPath,
|
||||
sourceCapabilityManifestPath: capabilityManifestPath,
|
||||
issuedAtUtc: stamp,
|
||||
};
|
||||
}
|
||||
|
||||
export function loadJsonFile(filePath) {
|
||||
return JSON.parse(readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
export function writeCaptureRequest(request, outputPath) {
|
||||
mkdirSync(path.dirname(outputPath), { recursive: true });
|
||||
writeFileSync(outputPath, `${JSON.stringify(request, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
function replaceStamp(pattern, stamp) {
|
||||
if (!pattern || !pattern.includes("{stamp}")) {
|
||||
throw new Error(`capture artifact pattern must include {stamp}: ${pattern || "missing"}`);
|
||||
}
|
||||
return pattern.replace("{stamp}", stamp);
|
||||
}
|
||||
|
||||
function selectCaptureSurface(captureContract, providerId, surfaceId = "") {
|
||||
const claims = captureSurfaceClaims(captureContract).filter(claim => claim.providerId === providerId);
|
||||
if (surfaceId) return claims.find(claim => claim.surfaceId === surfaceId) || null;
|
||||
return claims[0] || null;
|
||||
}
|
||||
|
||||
function captureProviderList(captureContract) {
|
||||
return captureSurfaceClaims(captureContract).map(claim => claim.providerId).filter(Boolean).join(", ") || "missing";
|
||||
}
|
||||
|
||||
function captureSurfaceList(captureContract) {
|
||||
return captureSurfaceClaims(captureContract).map(claim => `${claim.providerId}:${claim.surfaceId}`).join(", ") || "missing";
|
||||
}
|
||||
|
||||
function captureSurfaceClaims(captureContract) {
|
||||
return [
|
||||
{
|
||||
providerId: captureContract.requiredProvider || "",
|
||||
surfaceId: captureContract.requiredSurface || "",
|
||||
},
|
||||
...(Array.isArray(captureContract.additionalProviderSurfaces) ? captureContract.additionalProviderSurfaces : []),
|
||||
]
|
||||
.filter(claim => claim && typeof claim === "object")
|
||||
.map(claim => ({
|
||||
providerId: String(claim.providerId || ""),
|
||||
surfaceId: String(claim.surfaceId || ""),
|
||||
}))
|
||||
.filter(claim => claim.providerId && claim.surfaceId);
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
const args = {};
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const value = argv[index];
|
||||
if (!value.startsWith("--")) continue;
|
||||
const key = value.slice(2);
|
||||
const next = argv[index + 1];
|
||||
if (!next || next.startsWith("--")) {
|
||||
args[key] = true;
|
||||
} else {
|
||||
args[key] = next;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function runCli() {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
for (const required of ["advertisement", "capability", "output"]) {
|
||||
if (!args[required]) {
|
||||
throw new Error(`missing required --${required}`);
|
||||
}
|
||||
}
|
||||
|
||||
const stamp = args.stamp || new Date().toISOString().replace(/[:.]/g, "-");
|
||||
const request = buildTuiCaptureRequest({
|
||||
advertisement: loadJsonFile(args.advertisement),
|
||||
capabilityManifest: loadJsonFile(args.capability),
|
||||
advertisementPath: args.advertisement,
|
||||
capabilityManifestPath: args.capability,
|
||||
captureSurfaceId: args["surface-id"] || "",
|
||||
stamp,
|
||||
});
|
||||
writeCaptureRequest(request, args.output);
|
||||
process.stdout.write(`${args.output}\n`);
|
||||
}
|
||||
|
||||
const invokedPath = process.argv[1] ? path.resolve(process.argv[1]) : "";
|
||||
const modulePath = fileURLToPath(import.meta.url);
|
||||
if (invokedPath === modulePath) {
|
||||
runCli();
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import { buildTuiCaptureRequest } from "./evetui-capture-contract.mjs";
|
||||
|
||||
const advertisement = JSON.parse(readFileSync(new URL("../../../Aetheria/conformance/eve/aetheria.provider-advertisement.json", import.meta.url), "utf8"));
|
||||
const worldSmokeAdvertisement = JSON.parse(readFileSync(new URL("../../web/fixtures/eve-world-smoke.provider-advertisement.json", import.meta.url), "utf8"));
|
||||
const capabilityManifest = JSON.parse(readFileSync(new URL("../../runtimes/incubating/eve-tui/eve-runtime-capability.json", import.meta.url), "utf8"));
|
||||
|
||||
test("builds TUI capture request from provider advertisement", () => {
|
||||
const request = buildTuiCaptureRequest({
|
||||
advertisement,
|
||||
capabilityManifest,
|
||||
advertisementPath: "conformance/eve/aetheria.provider-advertisement.json",
|
||||
capabilityManifestPath: "runtimes/incubating/eve-tui/eve-runtime-capability.json",
|
||||
stamp: "smoke",
|
||||
});
|
||||
|
||||
assert.equal(request.schema, "gamecult.eve.runtime_capture_request.v1");
|
||||
assert.equal(request.runtimeId, "tui");
|
||||
assert.equal(request.ownerRepo, "EveTui");
|
||||
assert.equal(request.providerId, "aetheria");
|
||||
assert.equal(request.surfaceId, "aetheria.daemon.game");
|
||||
assert.equal(request.targetId, "tui");
|
||||
assert.equal(request.projectionKind, "provider-authored-world-surface");
|
||||
assert.equal(request.commandBoundary, "aetheria.daemon.commands");
|
||||
assert.equal(request.receiptSchema, "aetheria.eve_command_acceptance_status.v1");
|
||||
assert.equal(request.captureKind, "terminal-cell-grid");
|
||||
assert.equal(request.artifactKind, "json-grid");
|
||||
assert.equal(request.artifactPath, "artifacts/evetui-capture/smoke/tui-grid.json");
|
||||
assert.match(request.authority, /provider state/);
|
||||
});
|
||||
|
||||
test("builds TUI capture request for Aetheria editor surface", () => {
|
||||
const request = buildTuiCaptureRequest({
|
||||
advertisement,
|
||||
capabilityManifest,
|
||||
captureSurfaceId: "aetheria.daemon.editor",
|
||||
advertisementPath: "conformance/eve/aetheria.provider-advertisement.json",
|
||||
capabilityManifestPath: "runtimes/incubating/eve-tui/eve-runtime-capability.json",
|
||||
stamp: "smoke",
|
||||
});
|
||||
|
||||
assert.equal(request.runtimeId, "tui");
|
||||
assert.equal(request.providerId, "aetheria");
|
||||
assert.equal(request.surfaceId, "aetheria.daemon.editor");
|
||||
assert.equal(request.surfaceKind, "interactive-world-editor");
|
||||
assert.equal(request.projectionKind, "provider-authored-world-editor-surface");
|
||||
assert.equal(request.commandBoundary, "aetheria.daemon.commands");
|
||||
assert.equal(request.receiptSchema, "aetheria.eve_command_acceptance_status.v1");
|
||||
});
|
||||
|
||||
test("builds TUI capture request from a declared generic world provider", () => {
|
||||
const request = buildTuiCaptureRequest({
|
||||
advertisement: worldSmokeAdvertisement,
|
||||
capabilityManifest,
|
||||
advertisementPath: "web/fixtures/eve-world-smoke.provider-advertisement.json",
|
||||
capabilityManifestPath: "runtimes/incubating/eve-tui/eve-runtime-capability.json",
|
||||
stamp: "smoke",
|
||||
});
|
||||
|
||||
assert.equal(request.runtimeId, "tui");
|
||||
assert.equal(request.providerId, "eve.world-smoke");
|
||||
assert.equal(request.surfaceId, "eve.world-smoke.surface");
|
||||
assert.equal(request.commandBoundary, "eve.world-smoke.commands");
|
||||
assert.equal(request.receiptSchema, "eve.world_smoke.command_receipt.v1");
|
||||
});
|
||||
|
||||
test("rejects capture request when the surface does not advertise TUI", () => {
|
||||
const withoutTarget = structuredClone(advertisement);
|
||||
const surface = withoutTarget.surfaces.find(candidate => candidate.surfaceId === "aetheria.daemon.game");
|
||||
surface.worldInteraction.loweringTargets = surface.worldInteraction.loweringTargets.filter(target => target !== "tui");
|
||||
|
||||
assert.throws(
|
||||
() => buildTuiCaptureRequest({ advertisement: withoutTarget, capabilityManifest, stamp: "smoke" }),
|
||||
/does not advertise lowering target tui/,
|
||||
);
|
||||
});
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
export function buildTuiReleaseRequest({
|
||||
capabilityManifest,
|
||||
packageManifest,
|
||||
capabilityManifestPath = "",
|
||||
packageManifestPath = "",
|
||||
repository = "GameCult/EveTui",
|
||||
} = {}) {
|
||||
if (!capabilityManifest || typeof capabilityManifest !== "object") {
|
||||
throw new Error("capabilityManifest is required");
|
||||
}
|
||||
if (!packageManifest || typeof packageManifest !== "object") {
|
||||
throw new Error("packageManifest is required");
|
||||
}
|
||||
|
||||
const releaseContract = capabilityManifest.lifecycle?.release?.releaseContract;
|
||||
if (!releaseContract) {
|
||||
throw new Error("capability manifest is missing lifecycle.release.releaseContract");
|
||||
}
|
||||
|
||||
if (packageManifest.name !== releaseContract.packageName) {
|
||||
throw new Error(`package name mismatch: expected ${releaseContract.packageName} got ${packageManifest.name || "missing"}`);
|
||||
}
|
||||
if (!packageManifest.version || !/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(packageManifest.version)) {
|
||||
throw new Error(`package version is not a SemVer-compatible release version: ${packageManifest.version || "missing"}`);
|
||||
}
|
||||
|
||||
const tagName = replaceVersion(releaseContract.tagPattern, packageManifest.version);
|
||||
const artifactPath = replaceVersion(
|
||||
releaseContract.artifactPattern || `artifacts/evetui-release/{version}/${releaseContract.packageName}-{version}.tgz`,
|
||||
packageManifest.version,
|
||||
);
|
||||
|
||||
return {
|
||||
schema: releaseContract.requestSchema || "gamecult.eve.runtime_release_request.v1",
|
||||
ownerRepo: releaseContract.ownerRepo,
|
||||
repository,
|
||||
packageName: releaseContract.packageName,
|
||||
version: packageManifest.version,
|
||||
packageRoot: releaseContract.packageRoot,
|
||||
versionSource: releaseContract.versionSource,
|
||||
tagName,
|
||||
artifactKind: releaseContract.artifactKind,
|
||||
artifactPath,
|
||||
publishProof: releaseContract.publishProof,
|
||||
sourceCapabilityManifestPath: capabilityManifestPath,
|
||||
sourcePackageManifestPath: packageManifestPath,
|
||||
main: packageManifest.main || "",
|
||||
scripts: packageManifest.scripts || {},
|
||||
dependencies: packageManifest.dependencies || {},
|
||||
devDependencies: packageManifest.devDependencies || {},
|
||||
};
|
||||
}
|
||||
|
||||
export function loadJsonFile(filePath) {
|
||||
return JSON.parse(readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
export function writeReleaseRequest(request, outputPath) {
|
||||
mkdirSync(path.dirname(outputPath), { recursive: true });
|
||||
writeFileSync(outputPath, `${JSON.stringify(request, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
function replaceVersion(pattern, version) {
|
||||
if (!pattern || !pattern.includes("{version}")) {
|
||||
throw new Error(`release pattern must include {version}: ${pattern || "missing"}`);
|
||||
}
|
||||
return pattern.replaceAll("{version}", version);
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
const args = {};
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const value = argv[index];
|
||||
if (!value.startsWith("--")) continue;
|
||||
const key = value.slice(2);
|
||||
const next = argv[index + 1];
|
||||
if (!next || next.startsWith("--")) {
|
||||
args[key] = true;
|
||||
} else {
|
||||
args[key] = next;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function runCli() {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
for (const required of ["capability", "package", "output"]) {
|
||||
if (!args[required]) {
|
||||
throw new Error(`missing required --${required}`);
|
||||
}
|
||||
}
|
||||
|
||||
const request = buildTuiReleaseRequest({
|
||||
capabilityManifest: loadJsonFile(args.capability),
|
||||
packageManifest: loadJsonFile(args.package),
|
||||
capabilityManifestPath: args.capability,
|
||||
packageManifestPath: args.package,
|
||||
repository: args.repository || "GameCult/EveTui",
|
||||
});
|
||||
writeReleaseRequest(request, args.output);
|
||||
process.stdout.write(`${args.output}\n`);
|
||||
}
|
||||
|
||||
const invokedPath = process.argv[1] ? path.resolve(process.argv[1]) : "";
|
||||
const modulePath = fileURLToPath(import.meta.url);
|
||||
if (invokedPath === modulePath) {
|
||||
runCli();
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import { buildTuiReleaseRequest } from "./evetui-release-contract.mjs";
|
||||
|
||||
const capabilityManifest = JSON.parse(readFileSync(new URL("../../runtimes/incubating/eve-tui/eve-runtime-capability.json", import.meta.url), "utf8"));
|
||||
const packageManifest = JSON.parse(readFileSync(new URL("../../runtimes/incubating/eve-tui/package.json", import.meta.url), "utf8"));
|
||||
|
||||
test("builds EveTui release request from package manifest", () => {
|
||||
const request = buildTuiReleaseRequest({
|
||||
capabilityManifest,
|
||||
packageManifest,
|
||||
capabilityManifestPath: "runtimes/incubating/eve-tui/eve-runtime-capability.json",
|
||||
packageManifestPath: "runtimes/incubating/eve-tui/package.json",
|
||||
});
|
||||
|
||||
assert.equal(request.schema, "gamecult.eve.runtime_release_request.v1");
|
||||
assert.equal(request.ownerRepo, "EveTui");
|
||||
assert.equal(request.repository, "GameCult/EveTui");
|
||||
assert.equal(request.packageName, "eve-tui");
|
||||
assert.equal(request.version, "0.1.0");
|
||||
assert.equal(request.packageRoot, "runtimes/incubating/eve-tui");
|
||||
assert.equal(request.versionSource, "runtimes/incubating/eve-tui/package.json");
|
||||
assert.equal(request.tagName, "evetui-v0.1.0");
|
||||
assert.equal(request.artifactKind, "terminal-runtime");
|
||||
assert.equal(request.artifactPath, "artifacts/evetui-release/0.1.0/eve-tui-0.1.0.tgz");
|
||||
assert.equal(request.main, "src/eve-tui-shell.mjs");
|
||||
});
|
||||
|
||||
test("rejects package manifests that do not match the TUI release contract", () => {
|
||||
const wrongPackage = { ...packageManifest, name: "eve-wrong" };
|
||||
|
||||
assert.throws(
|
||||
() => buildTuiReleaseRequest({ capabilityManifest, packageManifest: wrongPackage }),
|
||||
/package name mismatch/,
|
||||
);
|
||||
});
|
||||
Loading…
Reference in a new issue