feat(cpa): add website template to CPA (#7079)

- Adds website to cpa list
- Reworks .env handling
This commit is contained in:
Paul
2024-07-10 09:44:07 -04:00
committed by GitHub
parent 5a76d6db8b
commit c1c12bc60d
2 changed files with 26 additions and 22 deletions

View File

@@ -20,6 +20,12 @@ export function getValidTemplates(): ProjectTemplate[] {
description: 'Blank 3.0 Template',
url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',
},
{
name: 'website',
type: 'starter',
description: 'Website Template',
url: 'https://github.com/payloadcms/payload/templates/website#beta',
},
// Remove these until they have been updated for 3.0
@@ -30,12 +36,6 @@ export function getValidTemplates(): ProjectTemplate[] {
// url: 'https://github.com/payloadcms/payload/templates/blank',
// },
// {
// name: 'website',
// type: 'starter',
// description: 'Website Template',
// url: 'https://github.com/payloadcms/payload/templates/website',
// },
// {
// name: 'ecommerce',
// type: 'starter',
// description: 'E-commerce Template',

View File

@@ -23,11 +23,16 @@ export async function writeEnvFile(args: {
const envOutputPath = path.join(projectDir, '.env')
try {
if (fs.existsSync(envOutputPath)) {
let fileContents: string
if (template?.type === 'starter') {
// Parse .env file into key/value pairs
const envFile = await fs.readFile(path.join(projectDir, '.env.example'), 'utf8')
const envWithValues: string[] = envFile
const envExample = path.join(projectDir, '.env.example')
const envFile = await fs.readFile(envExample, 'utf8')
fileContents =
`# Added by Payload\n` +
envFile
.split('\n')
.filter((e) => e)
.map((line) => {
@@ -46,18 +51,17 @@ export async function writeEnvFile(args: {
return `${key}=${value}`
})
// Write new .env file
await fs.writeFile(envOutputPath, envWithValues.join('\n'))
.join('\n')
} else {
const existingEnv = await fs.readFile(envOutputPath, 'utf8')
const newEnv =
existingEnv + `\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`
await fs.writeFile(envOutputPath, newEnv)
fileContents = `# Added by Payload\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`
}
if (fs.existsSync(envOutputPath)) {
const existingEnv = await fs.readFile(envOutputPath, 'utf8')
const newEnv = existingEnv + '\n# Added by Payload' + fileContents
await fs.writeFile(envOutputPath, newEnv)
} else {
const content = `DATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}`
await fs.outputFile(`${projectDir}/.env`, content)
await fs.writeFile(envOutputPath, fileContents)
}
} catch (err: unknown) {
error('Unable to write .env file')