feat(create-medusa-app): add stable option + add URI encoding to database string (#4567)

* feat(create-medusa-app): added stable option

* add new function

* changed open url

* switch condition

* fix open url for stable

* add URI encoding

* modified db error message
This commit is contained in:
Shahed Nasser
2023-07-24 13:33:14 +03:00
committed by GitHub
parent c9989529ed
commit 15e87a8100
6 changed files with 43 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
---
"create-medusa-app": patch
---
feat(create-medusa-app): add `stable` option + add URI encoding to database string

View File

@@ -30,9 +30,15 @@ export type CreateOptions = {
seed?: boolean
// commander passed --no-boilerplate as boilerplate
boilerplate?: boolean
stable?: boolean
}
export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
export default async ({
repoUrl = "",
seed,
boilerplate,
stable,
}: CreateOptions) => {
track("CREATE_CLI")
if (repoUrl) {
track("STARTER_SELECTED", { starter: repoUrl })
@@ -111,6 +117,7 @@ export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
repoUrl,
abortController,
spinner,
stable,
})
} catch {
return
@@ -192,7 +199,9 @@ export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
resources: ["http://localhost:9000/health"],
}).then(async () =>
open(
inviteToken
stable
? "http://localhost:9000/store/products"
: inviteToken
? `http://localhost:7001/invite?token=${inviteToken}&first_run=true`
: "http://localhost:7001"
)

View File

@@ -10,6 +10,10 @@ program
"--no-boilerplate",
"Install a Medusa project without the boilerplate and demo files."
)
.option(
"--stable",
"Install the latest stable version. This removes all onboarding features"
)
.parse()
void create(program.opts())

View File

@@ -9,19 +9,23 @@ type CloneRepoOptions = {
directoryName?: string
repoUrl?: string
abortController?: AbortController
stable?: boolean
}
const DEFAULT_REPO =
"https://github.com/medusajs/medusa-starter-default -b feat/onboarding"
const DEFAULT_REPO = "https://github.com/medusajs/medusa-starter-default"
export default async function cloneRepo({
directoryName = "",
repoUrl,
abortController,
stable = false,
}: CloneRepoOptions) {
await promiseExec(`git clone ${repoUrl || DEFAULT_REPO} ${directoryName}`, {
signal: abortController?.signal,
})
await promiseExec(
`git clone ${repoUrl || getRepoUrl(stable)} ${directoryName}`,
{
signal: abortController?.signal,
}
)
}
export async function runCloneRepo({
@@ -29,17 +33,20 @@ export async function runCloneRepo({
repoUrl,
abortController,
spinner,
stable = false,
}: {
projectName: string
repoUrl: string
abortController: AbortController
spinner: Ora
stable?: boolean
}) {
try {
await cloneRepo({
directoryName: projectName,
repoUrl,
abortController,
stable,
})
deleteGitDirectory(projectName)
@@ -62,3 +69,7 @@ function deleteGitDirectory(projectDirectory: string) {
force: true,
})
}
function getRepoUrl(stable?: boolean) {
return !stable ? `${DEFAULT_REPO} -b feat/onboarding` : DEFAULT_REPO
}

View File

@@ -82,7 +82,7 @@ export async function getDbClientAndCredentials(dbName: string): Promise<{
})
} catch (e) {
logMessage({
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`,
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${EOL}${EOL}If you keep running into this issue despite having PostgreSQL installed, please check out our troubleshooting guidelines: https://docs.medusajs.com/troubleshooting/database-error`,
type: "error",
})
}

View File

@@ -5,14 +5,18 @@ type ConnectionStringOptions = {
db: string
}
export function encodeDbValue(value: string): string {
return encodeURIComponent(value)
}
export default ({ user, password, host, db }: ConnectionStringOptions) => {
let connection = `postgres://`
if (user) {
connection += user
connection += encodeDbValue(user)
}
if (password) {
connection += `:${password}`
connection += `:${encodeDbValue(password)}`
}
if (user || password) {