Skip to content

Commit

Permalink
fix: Convert project name with the same rules as wrangler (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmemoto authored Oct 22, 2023
1 parent 6aa68a3 commit 6c15448
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/hooks/after-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ name = "%%PROJECT_NAME%%-staging"
})
const { readFileSync, writeFileSync } = await import('fs')

const projectName = 'test-project'
const projectName = 'test-projectNAME+123'
const directoryPath = './tmp'
const wranglerPath = join(directoryPath, 'wrangler.toml')
const replaced = `
name = "${projectName}"
name = "test-projectname-123"
[env.staging]
name = "${projectName}-staging"
name = "test-projectname-123-staging"
`.trim()
afterCreateHook.applyHook('cloudflare-workers', {
projectName,
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/after-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ afterCreateHook.addHook(
({ projectName, directoryPath }) => {
const wranglerPath = path.join(directoryPath, 'wrangler.toml')
const wrangler = readFileSync(wranglerPath, 'utf-8')
const rewritten = wrangler.replaceAll(PROJECT_NAME, projectName)
const convertProjectName = projectName.toLowerCase().replaceAll(/[^a-z0-9\-_]/gm, "-")
const rewritten = wrangler.replaceAll(PROJECT_NAME, convertProjectName)
writeFileSync(wranglerPath, rewritten)
}
)
Expand Down

0 comments on commit 6c15448

Please sign in to comment.