Format authored monorepo code with pinned language formatters
This commit is contained in:
@@ -3,10 +3,7 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import process from "node:process";
|
||||
import { bindingSchema } from "../bindings/index.js";
|
||||
import {
|
||||
compileCapabilityResourceRepository,
|
||||
type ResolvedCapabilityResource,
|
||||
} from "./assembly.js";
|
||||
import { compileCapabilityResourceRepository, type ResolvedCapabilityResource } from "./assembly.js";
|
||||
import { createGitCapabilityResolver } from "./git-resolver.js";
|
||||
|
||||
const usage = `usage: quixos-resource-compile --root DIRECTORY --kind interface|package
|
||||
@@ -22,7 +19,21 @@ const parseArgs = (args: string[]) => {
|
||||
const key = args[index];
|
||||
const value = args[index + 1];
|
||||
if (!key?.startsWith("--") || !value) throw new Error(usage);
|
||||
if (!["--root", "--kind", "--repository", "--commit", "--checkout-root", "--snapshot-map", "--snapshot-only", "--graph-out", "--schema-out"].includes(key) || values.has(key)) throw new Error(usage);
|
||||
if (
|
||||
![
|
||||
"--root",
|
||||
"--kind",
|
||||
"--repository",
|
||||
"--commit",
|
||||
"--checkout-root",
|
||||
"--snapshot-map",
|
||||
"--snapshot-only",
|
||||
"--graph-out",
|
||||
"--schema-out",
|
||||
].includes(key) ||
|
||||
values.has(key)
|
||||
)
|
||||
throw new Error(usage);
|
||||
values.set(key, value);
|
||||
}
|
||||
const rootDirectory = values.get("--root");
|
||||
@@ -30,14 +41,14 @@ const parseArgs = (args: string[]) => {
|
||||
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")) {
|
||||
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");
|
||||
}
|
||||
if (values.has("--snapshot-only") && values.get("--snapshot-only") !== "true") throw new Error("--snapshot-only accepts true");
|
||||
if (values.has("--snapshot-only") && values.get("--snapshot-only") !== "true")
|
||||
throw new Error("--snapshot-only accepts true");
|
||||
return {
|
||||
rootDirectory,
|
||||
kind,
|
||||
@@ -56,9 +67,8 @@ const graphEntry = (node: ResolvedCapabilityResource) => ({
|
||||
kind: node.kind,
|
||||
source: node.source,
|
||||
directory: node.directory,
|
||||
resourceId: node.resource.kind === "interface"
|
||||
? node.resource.revision.interfaceId
|
||||
: node.resource.revision.packageId,
|
||||
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,
|
||||
@@ -88,21 +98,32 @@ const main = async () => {
|
||||
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`);
|
||||
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`,
|
||||
);
|
||||
}
|
||||
if (options.schemaOut) await writeFile(options.schemaOut, `${JSON.stringify(bindingSchema(compiled), 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.stderr.write(`${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user