Build workspace agent, capability graph, and versioned cutovers
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import process from "node:process";
|
||||
import {
|
||||
compileCapabilityResourceRepository,
|
||||
type ResolvedCapabilityResource,
|
||||
} from "./assembly.js";
|
||||
import { createGitCapabilityResolver } from "./git-resolver.js";
|
||||
|
||||
const usage = `usage: quixos-resource-compile --root DIRECTORY --kind interface|package
|
||||
--repository URL --commit GIT_REV --checkout-root DIRECTORY
|
||||
[--snapshot-map PATH] [--graph-out PATH]
|
||||
|
||||
Resolves a standalone resource's recursive dependency-lock graph, validates
|
||||
its interface.qx or package.qx manifest, and emits the checked resource as JSON.`;
|
||||
|
||||
const parseArgs = (args: string[]) => {
|
||||
const values = new Map<string, string>();
|
||||
for (let index = 0; index < args.length; index += 2) {
|
||||
const key = args[index];
|
||||
const value = args[index + 1];
|
||||
if (!key?.startsWith("--") || !value) throw new Error(usage);
|
||||
values.set(key, value);
|
||||
}
|
||||
const rootDirectory = values.get("--root");
|
||||
const kind = values.get("--kind");
|
||||
const repository = values.get("--repository");
|
||||
const commit = values.get("--commit")?.toLowerCase();
|
||||
const checkoutRoot = values.get("--checkout-root");
|
||||
if (!rootDirectory || !repository || !commit || !checkoutRoot ||
|
||||
(kind !== "interface" && kind !== "package")) {
|
||||
throw new Error(usage);
|
||||
}
|
||||
if (!/^([0-9a-f]{40}|[0-9a-f]{64})$/.test(commit)) {
|
||||
throw new Error("--commit must be a full Git object ID");
|
||||
}
|
||||
return {
|
||||
rootDirectory,
|
||||
kind,
|
||||
repository,
|
||||
commit,
|
||||
checkoutRoot,
|
||||
snapshotMap: values.get("--snapshot-map"),
|
||||
graphOut: values.get("--graph-out"),
|
||||
} as const;
|
||||
};
|
||||
|
||||
const graphEntry = (node: ResolvedCapabilityResource) => ({
|
||||
key: node.key,
|
||||
kind: node.kind,
|
||||
source: node.source,
|
||||
directory: node.directory,
|
||||
resourceId: node.resource.kind === "interface"
|
||||
? node.resource.revision.interfaceId
|
||||
: node.resource.revision.packageId,
|
||||
revisionId: node.resource.revision.revisionId,
|
||||
dependencies: [...node.dependencies.entries()].map(([binding, dependency]) => ({
|
||||
binding,
|
||||
resourceKey: dependency.key,
|
||||
})),
|
||||
});
|
||||
|
||||
const main = async () => {
|
||||
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
||||
process.stdout.write(`${usage}\n`);
|
||||
return;
|
||||
}
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
const resolveResource = await createGitCapabilityResolver({
|
||||
checkoutRoot: options.checkoutRoot,
|
||||
snapshotMap: options.snapshotMap,
|
||||
});
|
||||
const compiled = await compileCapabilityResourceRepository({
|
||||
rootDirectory: options.rootDirectory,
|
||||
kind: options.kind,
|
||||
source: {
|
||||
resolver: "git",
|
||||
repository: options.repository,
|
||||
commit: options.commit,
|
||||
},
|
||||
resolveResource,
|
||||
});
|
||||
if (options.graphOut) {
|
||||
await writeFile(options.graphOut, `${JSON.stringify({
|
||||
formatVersion: 1,
|
||||
quixos: compiled.lock.quixos,
|
||||
root: graphEntry(compiled.resources.find((node) =>
|
||||
node.source.repository === options.repository &&
|
||||
node.source.commit === options.commit &&
|
||||
node.kind === options.kind)!),
|
||||
resources: compiled.resources.map(graphEntry),
|
||||
}, null, 2)}\n`);
|
||||
}
|
||||
process.stdout.write(`${JSON.stringify(compiled.resource, null, 2)}\n`);
|
||||
};
|
||||
|
||||
main().catch((error: unknown) => {
|
||||
process.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user