Skip to content

Instantly share code, notes, and snippets.

@danew
Created May 2, 2025 20:51
Show Gist options
  • Save danew/3151e1eca14e8417b42b26eadd55d244 to your computer and use it in GitHub Desktop.
Save danew/3151e1eca14e8417b42b26eadd55d244 to your computer and use it in GitHub Desktop.
Extend WrangleJson
import { WranglerJson, WranglerJsonSpec } from "alchemy/cloudflare";
import { writeFile } from "fs/promises";
import prettier from "prettier";
interface ExtendedWranglerJsonSpec extends WranglerJsonSpec {
migrations: {
tag: string;
new_sqlite_classes: string[];
}[];
}
export async function addDurableObjectMigration(
wranglerJson: WranglerJson,
className: string,
tag = "v1"
) {
const updatedWranglerJsonc: ExtendedWranglerJsonSpec = {
...wranglerJson.spec,
migrations: [
{
tag: tag,
new_sqlite_classes: [className],
},
],
};
const contents = await prettier.format(JSON.stringify(updatedWranglerJsonc), {
parser: "json",
editor: {
tabWidth: 2,
indentWidth: 2,
},
});
await writeFile(wranglerJson.path, contents);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment