import { readFile } from 'node:fs/promises'; import path from 'node:path'; import { loadPocProfile } from '../packages/runtime/src/poc-profile.js'; import { PocDeploymentAdapter, pocReleaseSchema } from '../packages/runtime/src/poc-release.js'; import { buildPocRelease } from '../packages/runtime/src/poc-build.js'; const [operation, profileFile, stateDirectory, workspaceOrRelease, sourceCommit, releaseId] = process.argv.slice(2); if (!operation || !profileFile || !stateDirectory) throw Error( 'Usage: tsx scripts/poc-release.ts inspect|build|deploy|reconcile PROFILE STATE_DIRECTORY [WORKSPACE SOURCE_SHA RELEASE_ID | RELEASE_FILE | RELEASE_ID]', ); const profile = await loadPocProfile(profileFile); const adapter = new PocDeploymentAdapter(profile, path.join(stateDirectory, 'deployments')); switch (operation) { case 'inspect': console.log(JSON.stringify(await adapter.snapshot(), null, 2)); break; case 'build': { if (!workspaceOrRelease || !sourceCommit || !releaseId) throw Error('build requires workspace, full source SHA and release ID'); const result = await buildPocRelease({ profile, stateDirectory, workspace: workspaceOrRelease, sourceCommit, releaseId, onProgress: message => console.error(message), }); console.log(JSON.stringify(result, null, 2)); break; } case 'deploy': { if (!workspaceOrRelease) throw Error('deploy requires a release JSON file'); const journal = await adapter.deploy( pocReleaseSchema.parse(JSON.parse(await readFile(workspaceOrRelease, 'utf8'))), ); console.log(JSON.stringify(journal, null, 2)); if (journal.state !== 'succeeded') process.exitCode = 1; break; } case 'reconcile': { if (!workspaceOrRelease) throw Error('reconcile requires release ID'); console.log(JSON.stringify(await adapter.reconcile(workspaceOrRelease), null, 2)); break; } default: throw Error('Unknown POC operation'); }