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:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"create-medusa-app": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(create-medusa-app): add `stable` option + add URI encoding to database string
|
||||||
@@ -30,9 +30,15 @@ export type CreateOptions = {
|
|||||||
seed?: boolean
|
seed?: boolean
|
||||||
// commander passed --no-boilerplate as boilerplate
|
// commander passed --no-boilerplate as boilerplate
|
||||||
boilerplate?: boolean
|
boilerplate?: boolean
|
||||||
|
stable?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
|
export default async ({
|
||||||
|
repoUrl = "",
|
||||||
|
seed,
|
||||||
|
boilerplate,
|
||||||
|
stable,
|
||||||
|
}: CreateOptions) => {
|
||||||
track("CREATE_CLI")
|
track("CREATE_CLI")
|
||||||
if (repoUrl) {
|
if (repoUrl) {
|
||||||
track("STARTER_SELECTED", { starter: repoUrl })
|
track("STARTER_SELECTED", { starter: repoUrl })
|
||||||
@@ -111,6 +117,7 @@ export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
|
|||||||
repoUrl,
|
repoUrl,
|
||||||
abortController,
|
abortController,
|
||||||
spinner,
|
spinner,
|
||||||
|
stable,
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
return
|
return
|
||||||
@@ -192,7 +199,9 @@ export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
|
|||||||
resources: ["http://localhost:9000/health"],
|
resources: ["http://localhost:9000/health"],
|
||||||
}).then(async () =>
|
}).then(async () =>
|
||||||
open(
|
open(
|
||||||
inviteToken
|
stable
|
||||||
|
? "http://localhost:9000/store/products"
|
||||||
|
: inviteToken
|
||||||
? `http://localhost:7001/invite?token=${inviteToken}&first_run=true`
|
? `http://localhost:7001/invite?token=${inviteToken}&first_run=true`
|
||||||
: "http://localhost:7001"
|
: "http://localhost:7001"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ program
|
|||||||
"--no-boilerplate",
|
"--no-boilerplate",
|
||||||
"Install a Medusa project without the boilerplate and demo files."
|
"Install a Medusa project without the boilerplate and demo files."
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
"--stable",
|
||||||
|
"Install the latest stable version. This removes all onboarding features"
|
||||||
|
)
|
||||||
.parse()
|
.parse()
|
||||||
|
|
||||||
void create(program.opts())
|
void create(program.opts())
|
||||||
|
|||||||
@@ -9,19 +9,23 @@ type CloneRepoOptions = {
|
|||||||
directoryName?: string
|
directoryName?: string
|
||||||
repoUrl?: string
|
repoUrl?: string
|
||||||
abortController?: AbortController
|
abortController?: AbortController
|
||||||
|
stable?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_REPO =
|
const DEFAULT_REPO = "https://github.com/medusajs/medusa-starter-default"
|
||||||
"https://github.com/medusajs/medusa-starter-default -b feat/onboarding"
|
|
||||||
|
|
||||||
export default async function cloneRepo({
|
export default async function cloneRepo({
|
||||||
directoryName = "",
|
directoryName = "",
|
||||||
repoUrl,
|
repoUrl,
|
||||||
abortController,
|
abortController,
|
||||||
|
stable = false,
|
||||||
}: CloneRepoOptions) {
|
}: CloneRepoOptions) {
|
||||||
await promiseExec(`git clone ${repoUrl || DEFAULT_REPO} ${directoryName}`, {
|
await promiseExec(
|
||||||
signal: abortController?.signal,
|
`git clone ${repoUrl || getRepoUrl(stable)} ${directoryName}`,
|
||||||
})
|
{
|
||||||
|
signal: abortController?.signal,
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runCloneRepo({
|
export async function runCloneRepo({
|
||||||
@@ -29,17 +33,20 @@ export async function runCloneRepo({
|
|||||||
repoUrl,
|
repoUrl,
|
||||||
abortController,
|
abortController,
|
||||||
spinner,
|
spinner,
|
||||||
|
stable = false,
|
||||||
}: {
|
}: {
|
||||||
projectName: string
|
projectName: string
|
||||||
repoUrl: string
|
repoUrl: string
|
||||||
abortController: AbortController
|
abortController: AbortController
|
||||||
spinner: Ora
|
spinner: Ora
|
||||||
|
stable?: boolean
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
await cloneRepo({
|
await cloneRepo({
|
||||||
directoryName: projectName,
|
directoryName: projectName,
|
||||||
repoUrl,
|
repoUrl,
|
||||||
abortController,
|
abortController,
|
||||||
|
stable,
|
||||||
})
|
})
|
||||||
|
|
||||||
deleteGitDirectory(projectName)
|
deleteGitDirectory(projectName)
|
||||||
@@ -62,3 +69,7 @@ function deleteGitDirectory(projectDirectory: string) {
|
|||||||
force: true,
|
force: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRepoUrl(stable?: boolean) {
|
||||||
|
return !stable ? `${DEFAULT_REPO} -b feat/onboarding` : DEFAULT_REPO
|
||||||
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ export async function getDbClientAndCredentials(dbName: string): Promise<{
|
|||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logMessage({
|
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",
|
type: "error",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,18 @@ type ConnectionStringOptions = {
|
|||||||
db: string
|
db: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function encodeDbValue(value: string): string {
|
||||||
|
return encodeURIComponent(value)
|
||||||
|
}
|
||||||
|
|
||||||
export default ({ user, password, host, db }: ConnectionStringOptions) => {
|
export default ({ user, password, host, db }: ConnectionStringOptions) => {
|
||||||
let connection = `postgres://`
|
let connection = `postgres://`
|
||||||
if (user) {
|
if (user) {
|
||||||
connection += user
|
connection += encodeDbValue(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (password) {
|
if (password) {
|
||||||
connection += `:${password}`
|
connection += `:${encodeDbValue(password)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user || password) {
|
if (user || password) {
|
||||||
|
|||||||
Reference in New Issue
Block a user