Skip to content

Commit

Permalink
fix: rewrite compatibility_date for cloudflare-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed Jul 21, 2024
1 parent 53df74d commit 8a4285d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/hooks/after-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ afterCreateHook.addHook(
)

const COMPATIBILITY_DATE = /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')
// Get current date in YYYY-MM-DD format
const currentDate = new Date().toISOString().split('T')[0]
const rewritten = wrangler.replace(
COMPATIBILITY_DATE,
`compatibility_date = "${currentDate}"`,
)
writeFileSync(wranglerPath, rewritten)
})
afterCreateHook.addHook(
['cloudflare-workers', 'cloudflare-pages'],
({ directoryPath }) => {
const wranglerPath = path.join(directoryPath, 'wrangler.toml')
const wrangler = readFileSync(wranglerPath, 'utf-8')
// Get current date in YYYY-MM-DD format
const currentDate = new Date().toISOString().split('T')[0]
const rewritten = wrangler.replace(
COMPATIBILITY_DATE,
`compatibility_date = "${currentDate}"`,
)
writeFileSync(wranglerPath, rewritten)
},
)

export { afterCreateHook }

0 comments on commit 8a4285d

Please sign in to comment.