Skip to content

Commit c1c12bc

Browse files
authored
feat(cpa): add website template to CPA (#7079)
- Adds website to cpa list - Reworks .env handling
1 parent 5a76d6d commit c1c12bc

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

packages/create-payload-app/src/lib/templates.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export function getValidTemplates(): ProjectTemplate[] {
2020
description: 'Blank 3.0 Template',
2121
url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',
2222
},
23+
{
24+
name: 'website',
25+
type: 'starter',
26+
description: 'Website Template',
27+
url: 'https://github.com/payloadcms/payload/templates/website#beta',
28+
},
2329

2430
// Remove these until they have been updated for 3.0
2531

@@ -30,12 +36,6 @@ export function getValidTemplates(): ProjectTemplate[] {
3036
// url: 'https://github.com/payloadcms/payload/templates/blank',
3137
// },
3238
// {
33-
// name: 'website',
34-
// type: 'starter',
35-
// description: 'Website Template',
36-
// url: 'https://github.com/payloadcms/payload/templates/website',
37-
// },
38-
// {
3939
// name: 'ecommerce',
4040
// type: 'starter',
4141
// description: 'E-commerce Template',

packages/create-payload-app/src/lib/write-env-file.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ export async function writeEnvFile(args: {
2323
const envOutputPath = path.join(projectDir, '.env')
2424

2525
try {
26-
if (fs.existsSync(envOutputPath)) {
27-
if (template?.type === 'starter') {
28-
// Parse .env file into key/value pairs
29-
const envFile = await fs.readFile(path.join(projectDir, '.env.example'), 'utf8')
30-
const envWithValues: string[] = envFile
26+
let fileContents: string
27+
28+
if (template?.type === 'starter') {
29+
// Parse .env file into key/value pairs
30+
const envExample = path.join(projectDir, '.env.example')
31+
const envFile = await fs.readFile(envExample, 'utf8')
32+
33+
fileContents =
34+
`# Added by Payload\n` +
35+
envFile
3136
.split('\n')
3237
.filter((e) => e)
3338
.map((line) => {
@@ -46,18 +51,17 @@ export async function writeEnvFile(args: {
4651

4752
return `${key}=${value}`
4853
})
54+
.join('\n')
55+
} else {
56+
fileContents = `# Added by Payload\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`
57+
}
4958

50-
// Write new .env file
51-
await fs.writeFile(envOutputPath, envWithValues.join('\n'))
52-
} else {
53-
const existingEnv = await fs.readFile(envOutputPath, 'utf8')
54-
const newEnv =
55-
existingEnv + `\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`
56-
await fs.writeFile(envOutputPath, newEnv)
57-
}
59+
if (fs.existsSync(envOutputPath)) {
60+
const existingEnv = await fs.readFile(envOutputPath, 'utf8')
61+
const newEnv = existingEnv + '\n# Added by Payload' + fileContents
62+
await fs.writeFile(envOutputPath, newEnv)
5863
} else {
59-
const content = `DATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}`
60-
await fs.outputFile(`${projectDir}/.env`, content)
64+
await fs.writeFile(envOutputPath, fileContents)
6165
}
6266
} catch (err: unknown) {
6367
error('Unable to write .env file')

0 commit comments

Comments
 (0)