fix(create-medusa-app): improved error messages (#4543)
* fix error messages * format docs url based on current OS * added changeset
This commit is contained in:
1 parent
221f62dc4c
commit
f325881227
4 files changed
+23
-4
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"create-medusa-app": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(create-medusa-app): improved error messages
|
||||||
@@ -53,11 +53,14 @@ export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
|
|||||||
}
|
}
|
||||||
const dbName = `medusa-${nanoid(4)}`
|
const dbName = `medusa-${nanoid(4)}`
|
||||||
let isProjectCreated = false
|
let isProjectCreated = false
|
||||||
|
let isDbInitialized = false
|
||||||
let printedMessage = false
|
let printedMessage = false
|
||||||
|
|
||||||
processManager.onTerminated(async () => {
|
processManager.onTerminated(async () => {
|
||||||
spinner.stop()
|
spinner.stop()
|
||||||
if (client) {
|
// prevent an error from occurring if
|
||||||
|
// client hasn't been declared yet
|
||||||
|
if (isDbInitialized && client) {
|
||||||
await client.end()
|
await client.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +89,7 @@ export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
|
|||||||
|
|
||||||
const projectName = await askForProjectName()
|
const projectName = await askForProjectName()
|
||||||
const { client, dbConnectionString } = await getDbClientAndCredentials(dbName)
|
const { client, dbConnectionString } = await getDbClientAndCredentials(dbName)
|
||||||
|
isDbInitialized = true
|
||||||
const adminEmail = await askForAdminEmail(seed, boilerplate)
|
const adminEmail = await askForAdminEmail(seed, boilerplate)
|
||||||
|
|
||||||
logMessage({
|
logMessage({
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import { EOL } from "os"
|
||||||
import pg from "pg"
|
import pg from "pg"
|
||||||
import postgresClient from "./postgres-client.js"
|
import postgresClient from "./postgres-client.js"
|
||||||
import inquirer from "inquirer"
|
import inquirer from "inquirer"
|
||||||
import logMessage from "./log-message.js"
|
import logMessage from "./log-message.js"
|
||||||
import formatConnectionString from "./format-connection-string.js"
|
import formatConnectionString from "./format-connection-string.js"
|
||||||
import { Ora } from "ora"
|
import { Ora } from "ora"
|
||||||
|
import { getCurrentOs } from "./get-current-os.js"
|
||||||
|
|
||||||
type CreateDbOptions = {
|
type CreateDbOptions = {
|
||||||
client: pg.Client
|
client: pg.Client
|
||||||
@@ -80,9 +82,7 @@ export async function getDbClientAndCredentials(dbName: string): Promise<{
|
|||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logMessage({
|
logMessage({
|
||||||
message:
|
message: `Couldn't connect to PostgreSQL. Make sure you have PostgreSQL installed and the credentials you provided are correct.${EOL}${EOL}You can learn how to install PostgreSQL here: https://docs.medusajs.com/development/backend/prepare-environment?os=${getCurrentOs()}#postgresql`,
|
||||||
"Couldn't connect to PostgreSQL. Make sure you have PostgreSQL installed and the credentials you provided are correct.${EOL}${EOL}" +
|
|
||||||
"You can learn how to install PostgreSQL here: https://docs.medusajs.com/development/backend/prepare-environment#postgresql",
|
|
||||||
type: "error",
|
type: "error",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export const getCurrentOs = (): string => {
|
||||||
|
switch (process.platform) {
|
||||||
|
case "darwin":
|
||||||
|
return "macos"
|
||||||
|
case "linux":
|
||||||
|
return "linux"
|
||||||
|
default:
|
||||||
|
return "windows"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user