feat(create-medusa-app,medusa-cli): Allow clearing project (#4273)

- Added build step
- Added `--no-boilerplate` option to `create-medusa-app` to allow clearing onboarding files
- Clear project files by default in medusa-cli
This commit is contained in:
Shahed Nasser
2023-06-15 17:31:30 +00:00
committed by GitHub
parent f8643361cd
commit f98ba5bde8
18 changed files with 582 additions and 87 deletions
@@ -0,0 +1,60 @@
type ProcessOptions = {
process: Function
ignoreERESOLVE?: boolean
}
export default class ProcessManager {
intervals: NodeJS.Timer[] = []
static MAX_RETRIES = 3
constructor() {
this.onTerminated(() => {
this.intervals.forEach((interval) => {
clearInterval(interval)
})
})
}
onTerminated(fn: Function) {
process.on("SIGTERM", () => fn())
process.on("SIGINT", () => fn())
}
addInterval(interval: NodeJS.Timer) {
this.intervals.push(interval)
}
// when running commands with npx or npm sometimes they
// terminate with EAGAIN error unexpectedly
// this utility function allows retrying the process if
// EAGAIN occurs, or otherwise throw the error that occurs
async runProcess({ process, ignoreERESOLVE }: ProcessOptions) {
let processError = false
let retries = 0
do {
retries++
try {
await process()
} catch (error) {
if (
typeof error === "object" &&
error !== null &&
"code" in error &&
error?.code === "EAGAIN"
) {
processError = true
} else if (
ignoreERESOLVE &&
typeof error === "object" &&
error !== null &&
"code" in error &&
error?.code === "ERESOLVE"
) {
// ignore error
} else {
throw error
}
}
} while (processError && retries <= ProcessManager.MAX_RETRIES)
}
}