feat(cpa): add website template to CPA (#7079)
- Adds website to cpa list - Reworks .env handling
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -23,11 +23,16 @@ export async function writeEnvFile(args: {
|
||||
const envOutputPath = path.join(projectDir, '.env')
|
||||
|
||||
try {
|
||||
if (fs.existsSync(envOutputPath)) {
|
||||
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
|
||||
let fileContents: string
|
||||
|
||||
if (template?.type === 'starter') {
|
||||
// Parse .env file into key/value pairs
|
||||
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'))
|
||||
} else {
|
||||
const existingEnv = await fs.readFile(envOutputPath, 'utf8')
|
||||
const newEnv =
|
||||
existingEnv + `\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`
|
||||
await fs.writeFile(envOutputPath, newEnv)
|
||||
}
|
||||
.join('\n')
|
||||
} else {
|
||||
const content = `DATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}`
|
||||
await fs.outputFile(`${projectDir}/.env`, content)
|
||||
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 {
|
||||
await fs.writeFile(envOutputPath, fileContents)
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
error('Unable to write .env file')
|
||||
|
||||
Reference in New Issue
Block a user