From 0e1edb281eb3e77e73c8dbbd79ee283e0e3f8cd1 Mon Sep 17 00:00:00 2001 From: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com> Date: Fri, 12 Jul 2024 07:47:54 +0530 Subject: [PATCH] feat(workers): set compatibility date to current date --- src/hooks/after-create.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hooks/after-create.ts b/src/hooks/after-create.ts index 5efc32a..67d4c60 100644 --- a/src/hooks/after-create.ts +++ b/src/hooks/after-create.ts @@ -17,4 +17,19 @@ afterCreateHook.addHook( }, ) +const regex = /compatibility_date\s*=\s*"\d{4}-\d{2}-\d{2}"/ +afterCreateHook.addHook(['cloudflare-workers'], ({ directoryPath }) => { + const wranglerPath = path.join(directoryPath, 'wrangler.toml') + const wrangler = readFileSync(wranglerPath, 'utf-8') + + const currentDate = new Date().toISOString().split('T')[0] // Get current date in YYYY-MM-DD format + + const rewritten = wrangler.replace( + regex, + `compatibility_date = "${currentDate}"`, + ) + + writeFileSync(wranglerPath, rewritten) +}) + export { afterCreateHook }