fix(cpa): ensures .env & .env.example file modifications occur before git initialization (#10312)
### What? Previously, `.env` & `.env.example` modifications during `cpa` occurred after a project was initialized. ### Why? As a result, these modifications would be seen as uncommitted modifications in the project repo. ### How? Now, we make these modifications in the `createProject` script before the project is initialized. Also, updates the **template** `.env.example` files to use the generic db name `your-database-name` for better alignment & clarity. Fixes #10232
This commit is contained in:
@@ -19,6 +19,8 @@ import { configurePayloadConfig } from './configure-payload-config.js'
|
|||||||
import { configurePluginProject } from './configure-plugin-project.js'
|
import { configurePluginProject } from './configure-plugin-project.js'
|
||||||
import { downloadExample } from './download-example.js'
|
import { downloadExample } from './download-example.js'
|
||||||
import { downloadTemplate } from './download-template.js'
|
import { downloadTemplate } from './download-template.js'
|
||||||
|
import { generateSecret } from './generate-secret.js'
|
||||||
|
import { manageEnvFiles } from './manage-env-files.js'
|
||||||
|
|
||||||
const filename = fileURLToPath(import.meta.url)
|
const filename = fileURLToPath(import.meta.url)
|
||||||
const dirname = path.dirname(filename)
|
const dirname = path.dirname(filename)
|
||||||
@@ -142,6 +144,18 @@ export async function createProject(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call manageEnvFiles before initializing Git
|
||||||
|
if (dbDetails) {
|
||||||
|
await manageEnvFiles({
|
||||||
|
cliArgs,
|
||||||
|
databaseType: dbDetails.type,
|
||||||
|
databaseUri: dbDetails.dbUri,
|
||||||
|
payloadSecret: generateSecret(),
|
||||||
|
projectDir,
|
||||||
|
template: 'template' in args ? args.template : undefined,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Remove yarn.lock file. This is only desired in Payload Cloud.
|
// Remove yarn.lock file. This is only desired in Payload Cloud.
|
||||||
const lockPath = path.resolve(projectDir, 'pnpm-lock.yaml')
|
const lockPath = path.resolve(projectDir, 'pnpm-lock.yaml')
|
||||||
if (fse.existsSync(lockPath)) {
|
if (fse.existsSync(lockPath)) {
|
||||||
|
|||||||
@@ -255,7 +255,6 @@ export class Main {
|
|||||||
}
|
}
|
||||||
case 'starter': {
|
case 'starter': {
|
||||||
const dbDetails = await selectDb(this.args, projectName)
|
const dbDetails = await selectDb(this.args, projectName)
|
||||||
const payloadSecret = generateSecret()
|
|
||||||
|
|
||||||
await createProject({
|
await createProject({
|
||||||
cliArgs: this.args,
|
cliArgs: this.args,
|
||||||
@@ -266,15 +265,6 @@ export class Main {
|
|||||||
template,
|
template,
|
||||||
})
|
})
|
||||||
|
|
||||||
await manageEnvFiles({
|
|
||||||
cliArgs: this.args,
|
|
||||||
databaseType: dbDetails.type,
|
|
||||||
databaseUri: dbDetails.dbUri,
|
|
||||||
payloadSecret,
|
|
||||||
projectDir,
|
|
||||||
template,
|
|
||||||
})
|
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
DATABASE_URI=mongodb://127.0.0.1/payload-template-blank-3-0
|
DATABASE_URI=mongodb://127.0.0.1/your-database-name
|
||||||
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
DATABASE_URI=mongodb://127.0.0.1/payload-template-blank-3-0
|
DATABASE_URI=mongodb://127.0.0.1/your-database-name
|
||||||
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# Database connection string
|
# Database connection string
|
||||||
DATABASE_URI=mongodb://127.0.0.1/payload-template-website
|
DATABASE_URI=mongodb://127.0.0.1/your-database-name
|
||||||
|
|
||||||
# Or use a PG connection string
|
# Or use a PG connection string
|
||||||
#DATABASE_URI=postgresql://127.0.0.1:5432/payload-template-website
|
#DATABASE_URI=postgresql://127.0.0.1:5432/your-database-name
|
||||||
|
|
||||||
# Used to encrypt JWT tokens
|
# Used to encrypt JWT tokens
|
||||||
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
DATABASE_URI=mongodb://127.0.0.1/payload-template-blank-3-0
|
DATABASE_URI=mongodb://127.0.0.1/your-database-name
|
||||||
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
||||||
|
|||||||
Reference in New Issue
Block a user