Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[legacy-framework] Fix CLI crash when prisma is not installed #438

Merged
merged 1 commit into from May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 16 additions & 11 deletions packages/cli/src/commands/db.ts
Expand Up @@ -15,19 +15,24 @@ const getPrismaBin = () => resolveBinAsync('@prisma/cli', 'prisma')
// Prisma client generation will fail if no model is defined in the schema.
// So the silent option is here to ignore that failure
export const runPrismaGeneration = async ({silent = false} = {}) => {
const prismaBin = await getPrismaBin()
try {
const prismaBin = await getPrismaBin()

return new Promise((resolve) => {
spawn(prismaBin, ['generate', schemaArg], {stdio: silent ? 'ignore' : 'inherit'}).on('exit', (code) => {
if (code === 0) {
resolve()
} else if (silent) {
resolve()
} else {
process.exit(1)
}
return new Promise((resolve) => {
spawn(prismaBin, ['generate', schemaArg], {stdio: silent ? 'ignore' : 'inherit'}).on('exit', (code) => {
if (code === 0) {
resolve()
} else if (silent) {
resolve()
} else {
process.exit(1)
}
})
})
})
} catch (error) {
if (silent) return
throw new Error("Oops, we can't find Prisma Client. Please make sure it's installed in your project")
}
}

export const runMigrate = async () => {
Expand Down