Files
legion_kk/scripts/generate-app-version.ts
self f8698fa3bc feat: prepare production Legion CLI
Build the CLI as a production artifact, expose a package bin, generate shared app version metadata, rename the local state file to legion-state.json, and include readable appVersion metadata in the encrypted state envelope.

Also updates README feature/setup documentation and commits all current repository changes requested for this Legion patch.
2026-06-28 16:34:05 +02:00

37 lines
1.3 KiB
TypeScript

import { readFile, writeFile, mkdir } from "node:fs/promises"
import { resolve } from "node:path"
import { pathToFileURL } from "node:url"
import { fileURLToPath } from "node:url"
interface PackageMetadata {
version?: unknown
}
export function renderGeneratedAppVersion(version: string): string {
return `// Generated by scripts/generate-app-version.ts
// Source: package.json
export const PACKAGE_VERSION = ${JSON.stringify(version)}
`
}
async function main(): Promise<void> {
const repoRoot = resolve(fileURLToPath(new URL(".", import.meta.url)), "..")
const packageJsonPath = resolve(repoRoot, "package.json")
const outputDir = resolve(repoRoot, "src/shared/generated")
const outputPath = resolve(outputDir, "app-version.ts")
const packageMetadata = JSON.parse(await readFile(packageJsonPath, "utf8")) as PackageMetadata
if (typeof packageMetadata.version !== "string" || !packageMetadata.version.trim()) {
throw new Error("package.json is missing a valid version string")
}
await mkdir(outputDir, { recursive: true })
await writeFile(outputPath, renderGeneratedAppVersion(packageMetadata.version), "utf8")
process.stdout.write(`${outputPath}\n`)
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
void main()
}