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:
Oliver Windall Juhl authored and GitHub committed 2023-05-31 12:38:44 +02:00
1 parent f3920730dc
commit 260dc55b6f
3 files changed
+20 -44

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
---
"@medusajs/medusa-cli": patch
"@medusajs/medusa": patch
---
chore(medusa,medusa-cli): Clean up new command + fix CI
+1 -16
View File
@@ -8,11 +8,6 @@ jobs:
NODE_ENV: CI NODE_ENV: CI
REDIS_URL: redis://localhost:6379 REDIS_URL: redis://localhost:6379
DATABASE_URL: "postgres://postgres:postgres@localhost/cli-test" DATABASE_URL: "postgres://postgres:postgres@localhost/cli-test"
strategy:
matrix:
db: [postgres]
services: services:
redis: redis:
image: redis image: redis
@@ -56,7 +51,7 @@ jobs:
- name: Create Medusa project - name: Create Medusa project
run: | run: |
medusa new cli-test 'https://github.com/medusajs/medusa-starter-default/tree/ci-test' medusa new cli-test --skip-db
working-directory: .. working-directory: ..
- name: run medusa dev - name: run medusa dev
@@ -64,28 +59,20 @@ jobs:
working-directory: ../cli-test working-directory: ../cli-test
- name: Run migrations - name: Run migrations
env:
DATABASE_TYPE: ${{ matrix.db }}
run: medusa migrations run run: medusa migrations run
working-directory: ../cli-test working-directory: ../cli-test
- name: Seed db - name: Seed db
env:
DATABASE_TYPE: ${{ matrix.db }}
run: yarn seed run: yarn seed
working-directory: ../cli-test working-directory: ../cli-test
- name: Create admin user - name: Create admin user
env:
DATABASE_TYPE: ${{ matrix.db }}
run: medusa user -e test@test.com -p password -i admin_123 run: medusa user -e test@test.com -p password -i admin_123
working-directory: ../cli-test working-directory: ../cli-test
########################## Test medusa develop ############################### ########################## Test medusa develop ###############################
- name: Run development server - name: Run development server
env:
DATABASE_TYPE: ${{ matrix.db }}
run: medusa develop & run: medusa develop &
working-directory: ../cli-test working-directory: ../cli-test
@@ -95,8 +82,6 @@ jobs:
########################### Test medusa start ################################ ########################### Test medusa start ################################
- name: Starting medusa - name: Starting medusa
env:
DATABASE_TYPE: ${{ matrix.db }}
run: medusa start & run: medusa start &
working-directory: ../cli-test working-directory: ../cli-test
+13 -28
View File
@@ -300,7 +300,9 @@ const verifyPgCreds = async (creds) => {
const interactiveDbCreds = async (dbName, dbCreds = {}) => { const interactiveDbCreds = async (dbName, dbCreds = {}) => {
const credentials = Object.assign({}, defaultDBCreds, dbCreds) const credentials = Object.assign({}, defaultDBCreds, dbCreds)
let collecting = true
const collecting = true
while (collecting) { while (collecting) {
const result = await inquirer const result = await inquirer
.prompt([ .prompt([
@@ -309,10 +311,9 @@ const interactiveDbCreds = async (dbName, dbCreds = {}) => {
name: "continueWithDefault", name: "continueWithDefault",
message: ` message: `
Will attempt to setup database "${dbName}" with credentials: Will attempt to setup Postgres database "${dbName}" with credentials:
user: ${credentials.user} user: ${credentials.user}
password: *** password: ***
database: ${credentials.database}
port: ${credentials.port} port: ${credentials.port}
host: ${credentials.host} host: ${credentials.host}
Do you wish to continue with these credentials? Do you wish to continue with these credentials?
@@ -352,14 +353,6 @@ Do you wish to continue with these credentials?
default: credentials.host, default: credentials.host,
message: `DB host`, message: `DB host`,
}, },
{
type: "input",
when: ({ continueWithDefault }) =>
continueWithDefault === `Change credentials`,
name: "database",
default: credentials.database,
message: `DB database`,
},
]) ])
.then(async (answers) => { .then(async (answers) => {
const collectedCreds = Object.assign({}, credentials, { const collectedCreds = Object.assign({}, credentials, {
@@ -367,7 +360,6 @@ Do you wish to continue with these credentials?
password: answers.password, password: answers.password,
host: answers.host, host: answers.host,
port: answers.port, port: answers.port,
database: answers.database,
}) })
switch (answers.continueWithDefault) { switch (answers.continueWithDefault) {
@@ -428,19 +420,13 @@ const setupDB = async (dbName, dbCreds = {}) => {
}) })
} }
const setupEnvVars = async ( const setupEnvVars = async (rootPath, dbName, dbCreds = {}) => {
rootPath,
dbName,
dbCreds = {},
isPostgres = true
) => {
const templatePath = sysPath.join(rootPath, ".env.template") const templatePath = sysPath.join(rootPath, ".env.template")
const destination = sysPath.join(rootPath, ".env") const destination = sysPath.join(rootPath, ".env")
if (existsSync(templatePath)) { if (existsSync(templatePath)) {
fs.renameSync(templatePath, destination) fs.renameSync(templatePath, destination)
} }
if (isPostgres) {
const credentials = Object.assign({}, defaultDBCreds, dbCreds) const credentials = Object.assign({}, defaultDBCreds, dbCreds)
let dbUrl = "" let dbUrl = ""
if ( if (
@@ -454,7 +440,6 @@ const setupEnvVars = async (
fs.appendFileSync(destination, `DATABASE_URL=${dbUrl}\n`) fs.appendFileSync(destination, `DATABASE_URL=${dbUrl}\n`)
} }
}
const runMigrations = async (rootPath) => { const runMigrations = async (rootPath) => {
const migrationActivity = reporter.activity("Applying database migrations...") const migrationActivity = reporter.activity("Applying database migrations...")
@@ -611,29 +596,29 @@ medusa new ${rootPath} [url-to-starter]
await copy(starterPath, rootPath) await copy(starterPath, rootPath)
} }
const medusaConfig = getMedusaConfig(rootPath)
let isPostgres = false
track("CLI_NEW_LAYOUT_COMPLETED") track("CLI_NEW_LAYOUT_COMPLETED")
let creds = dbCredentials let creds = dbCredentials
const dbName = `medusa-db-${Math.random().toString(36).substring(2, 7)}` // generate random 5 character string
if (!useDefaults && !skipDb && !skipEnv) { if (!useDefaults && !skipDb && !skipEnv) {
creds = await interactiveDbCreds(rootPath, dbCredentials) creds = await interactiveDbCreds(dbName, dbCredentials)
} }
if (creds === null) { 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 { } else {
if (!skipDb) { if (!skipDb) {
track("CLI_NEW_SETUP_DB") track("CLI_NEW_SETUP_DB")
await setupDB(rootPath, creds) await setupDB(dbName, creds)
} }
if (!skipEnv) { if (!skipEnv) {
track("CLI_NEW_SETUP_ENV") track("CLI_NEW_SETUP_ENV")
await setupEnvVars(rootPath, rootPath, creds) await setupEnvVars(rootPath, dbName, creds)
} }
if (!skipMigrations) { if (!skipMigrations) {