Created
May 2, 2025 20:51
-
-
Save danew/3151e1eca14e8417b42b26eadd55d244 to your computer and use it in GitHub Desktop.
Extend WrangleJson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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