feat(cli): migrate api entries into the apis block
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,7 @@ import { pathToFileURL } from "node:url";
|
||||
import { formatWrn, parse } from "@wrnexus/syntax";
|
||||
import { AI_GUIDE, CLAUDE_MD } from "./ai-guide.ts";
|
||||
import { inspectProject, type DoctorCheck } from "./doctor.ts";
|
||||
import { migrateApisBlock } from "./migrations/apis-block.ts";
|
||||
import { generateApplicationTypes } from "./types.ts";
|
||||
|
||||
/** The version of the CLI currently running (its own package.json). */
|
||||
@@ -868,6 +869,41 @@ const MIGRATIONS: Migration[] = [
|
||||
if (!ctx.dryRun) writeFileSync(file, after, "utf8");
|
||||
},
|
||||
},
|
||||
{
|
||||
version: "0.9.0",
|
||||
id: "move-api-blocks",
|
||||
description:
|
||||
"Move api entries out of legacy ssr/client data blocks into a page-level apis block",
|
||||
apply(ctx) {
|
||||
const appDirectory = join(ctx.appRoot, "app");
|
||||
if (!existsSync(appDirectory)) return;
|
||||
|
||||
for (const file of walkProjectFiles(appDirectory, ".wrn")) {
|
||||
const relativeFile = relative(ctx.appRoot, file).replace(/\\/g, "/");
|
||||
const before = readFileSync(file, "utf8");
|
||||
|
||||
let result: ReturnType<typeof migrateApisBlock>;
|
||||
try {
|
||||
result = migrateApisBlock(before);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message.split("\n", 1)[0] : String(error);
|
||||
ctx.report.parseFailures.push(`${relativeFile}: ${message}`);
|
||||
ctx.log(`! ${relativeFile}: left unchanged because the apis-block migration failed`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("skip" in result) {
|
||||
ctx.report.needsReview.push(`${relativeFile}: ${result.skip}`);
|
||||
continue;
|
||||
}
|
||||
if (!result.changed) continue;
|
||||
|
||||
ctx.report.changedAutomatically.push(`${relativeFile}: moved api entries into apis { }`);
|
||||
ctx.log(`~ ${relativeFile}: moved api entries into apis { }`);
|
||||
if (!ctx.dryRun) writeFileSync(file, result.source, "utf8");
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
/** Release tooling uses this to require an explicit migration entry per version. */
|
||||
|
||||
Reference in New Issue
Block a user