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',
|
description: 'Blank 3.0 Template',
|
||||||
url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',
|
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
|
// 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',
|
// 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',
|
// name: 'ecommerce',
|
||||||
// type: 'starter',
|
// type: 'starter',
|
||||||
// description: 'E-commerce Template',
|
// description: 'E-commerce Template',
|
||||||
|
|||||||
@@ -23,11 +23,16 @@ export async function writeEnvFile(args: {
|
|||||||
const envOutputPath = path.join(projectDir, '.env')
|
const envOutputPath = path.join(projectDir, '.env')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(envOutputPath)) {
|
let fileContents: string
|
||||||
if (template?.type === 'starter') {
|
|
||||||
// Parse .env file into key/value pairs
|
if (template?.type === 'starter') {
|
||||||
const envFile = await fs.readFile(path.join(projectDir, '.env.example'), 'utf8')
|
// Parse .env file into key/value pairs
|
||||||
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')
|
.split('\n')
|
||||||
.filter((e) => e)
|
.filter((e) => e)
|
||||||
.map((line) => {
|
.map((line) => {
|
||||||
@@ -46,18 +51,17 @@ export async function writeEnvFile(args: {
|
|||||||
|
|
||||||
return `${key}=${value}`
|
return `${key}=${value}`
|
||||||
})
|
})
|
||||||
|
.join('\n')
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const content = `DATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}`
|
fileContents = `# Added by Payload\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`
|
||||||
await fs.outputFile(`${projectDir}/.env`, content)
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch (err: unknown) {
|
||||||
error('Unable to write .env file')
|
error('Unable to write .env file')
|
||||||
|
|||||||
Reference in New Issue
Block a user