28 lines
915 B
TypeScript
28 lines
915 B
TypeScript
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import type { TechLogServingContract } from "./tech-log-serving-contract.ts";
|
|
|
|
type ServingArtifactOptions = Readonly<{
|
|
distRoot: string;
|
|
contract: TechLogServingContract;
|
|
serverSourcePath?: string;
|
|
}>;
|
|
|
|
export async function writeTechLogServingArtifact({
|
|
distRoot,
|
|
contract,
|
|
serverSourcePath = "scripts/lib/tech-log-production-server.ts",
|
|
}: ServingArtifactOptions): Promise<void> {
|
|
const absoluteDistRoot = path.resolve(distRoot);
|
|
const serverSource = await readFile(path.resolve(serverSourcePath), "utf8");
|
|
await mkdir(absoluteDistRoot, { recursive: true });
|
|
await Promise.all([
|
|
writeFile(
|
|
path.join(absoluteDistRoot, "tech-log-serving-contract.json"),
|
|
`${JSON.stringify(contract, null, 2)}\n`,
|
|
),
|
|
writeFile(path.join(absoluteDistRoot, "server.mjs"), serverSource),
|
|
]);
|
|
}
|