chore(medusa,medusa-cli): Clean up new command + fix CI (#4214)
* chore(workflows): Use default starter template in action * Use postgres by default in new * Add skip DB flag * Create thirty-tomatoes-hug.md * address PR comments
This commit is contained in:
@@ -300,7 +300,9 @@ const verifyPgCreds = async (creds) => {
|
||||
|
||||
const interactiveDbCreds = async (dbName, dbCreds = {}) => {
|
||||
const credentials = Object.assign({}, defaultDBCreds, dbCreds)
|
||||
let collecting = true
|
||||
|
||||
const collecting = true
|
||||
|
||||
while (collecting) {
|
||||
const result = await inquirer
|
||||
.prompt([
|
||||
@@ -309,10 +311,9 @@ const interactiveDbCreds = async (dbName, dbCreds = {}) => {
|
||||
name: "continueWithDefault",
|
||||
message: `
|
||||
|
||||
Will attempt to setup database "${dbName}" with credentials:
|
||||
Will attempt to setup Postgres database "${dbName}" with credentials:
|
||||
user: ${credentials.user}
|
||||
password: ***
|
||||
database: ${credentials.database}
|
||||
port: ${credentials.port}
|
||||
host: ${credentials.host}
|
||||
Do you wish to continue with these credentials?
|
||||
@@ -352,14 +353,6 @@ Do you wish to continue with these credentials?
|
||||
default: credentials.host,
|
||||
message: `DB host`,
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
when: ({ continueWithDefault }) =>
|
||||
continueWithDefault === `Change credentials`,
|
||||
name: "database",
|
||||
default: credentials.database,
|
||||
message: `DB database`,
|
||||
},
|
||||
])
|
||||
.then(async (answers) => {
|
||||
const collectedCreds = Object.assign({}, credentials, {
|
||||
@@ -367,7 +360,6 @@ Do you wish to continue with these credentials?
|
||||
password: answers.password,
|
||||
host: answers.host,
|
||||
port: answers.port,
|
||||
database: answers.database,
|
||||
})
|
||||
|
||||
switch (answers.continueWithDefault) {
|
||||
@@ -428,32 +420,25 @@ const setupDB = async (dbName, dbCreds = {}) => {
|
||||
})
|
||||
}
|
||||
|
||||
const setupEnvVars = async (
|
||||
rootPath,
|
||||
dbName,
|
||||
dbCreds = {},
|
||||
isPostgres = true
|
||||
) => {
|
||||
const setupEnvVars = async (rootPath, dbName, dbCreds = {}) => {
|
||||
const templatePath = sysPath.join(rootPath, ".env.template")
|
||||
const destination = sysPath.join(rootPath, ".env")
|
||||
if (existsSync(templatePath)) {
|
||||
fs.renameSync(templatePath, destination)
|
||||
}
|
||||
|
||||
if (isPostgres) {
|
||||
const credentials = Object.assign({}, defaultDBCreds, dbCreds)
|
||||
let dbUrl = ""
|
||||
if (
|
||||
credentials.user !== defaultDBCreds.user ||
|
||||
credentials.password !== defaultDBCreds.password
|
||||
) {
|
||||
dbUrl = `postgres://${credentials.user}:${credentials.password}@${credentials.host}:${credentials.port}/${dbName}`
|
||||
} else {
|
||||
dbUrl = `postgres://${credentials.host}:${credentials.port}/${dbName}`
|
||||
}
|
||||
|
||||
fs.appendFileSync(destination, `DATABASE_URL=${dbUrl}\n`)
|
||||
const credentials = Object.assign({}, defaultDBCreds, dbCreds)
|
||||
let dbUrl = ""
|
||||
if (
|
||||
credentials.user !== defaultDBCreds.user ||
|
||||
credentials.password !== defaultDBCreds.password
|
||||
) {
|
||||
dbUrl = `postgres://${credentials.user}:${credentials.password}@${credentials.host}:${credentials.port}/${dbName}`
|
||||
} else {
|
||||
dbUrl = `postgres://${credentials.host}:${credentials.port}/${dbName}`
|
||||
}
|
||||
|
||||
fs.appendFileSync(destination, `DATABASE_URL=${dbUrl}\n`)
|
||||
}
|
||||
|
||||
const runMigrations = async (rootPath) => {
|
||||
@@ -611,29 +596,29 @@ medusa new ${rootPath} [url-to-starter]
|
||||
await copy(starterPath, rootPath)
|
||||
}
|
||||
|
||||
const medusaConfig = getMedusaConfig(rootPath)
|
||||
|
||||
let isPostgres = false
|
||||
|
||||
track("CLI_NEW_LAYOUT_COMPLETED")
|
||||
|
||||
let creds = dbCredentials
|
||||
|
||||
const dbName = `medusa-db-${Math.random().toString(36).substring(2, 7)}` // generate random 5 character string
|
||||
|
||||
if (!useDefaults && !skipDb && !skipEnv) {
|
||||
creds = await interactiveDbCreds(rootPath, dbCredentials)
|
||||
creds = await interactiveDbCreds(dbName, dbCredentials)
|
||||
}
|
||||
|
||||
if (creds === null) {
|
||||
reporter.info("Skipping automatic database setup")
|
||||
reporter.info(
|
||||
"Skipping automatic database setup. Please note that you need to create a database and run migrations before you can run your Medusa backend"
|
||||
)
|
||||
} else {
|
||||
if (!skipDb) {
|
||||
track("CLI_NEW_SETUP_DB")
|
||||
await setupDB(rootPath, creds)
|
||||
await setupDB(dbName, creds)
|
||||
}
|
||||
|
||||
if (!skipEnv) {
|
||||
track("CLI_NEW_SETUP_ENV")
|
||||
await setupEnvVars(rootPath, rootPath, creds)
|
||||
await setupEnvVars(rootPath, dbName, creds)
|
||||
}
|
||||
|
||||
if (!skipMigrations) {
|
||||
|
||||
Reference in New Issue
Block a user