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

feat(prisma2/cli): allow arbitrary generator commands with flags #1933

Merged
merged 2 commits into from Mar 26, 2020
Merged
Show file tree
Hide file tree
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
23 changes: 19 additions & 4 deletions cli/generator-helper/src/GeneratorProcess.ts
Expand Up @@ -26,7 +26,10 @@ export class GeneratorProcess {
private initPromise?: Promise<void>
private initialized: boolean = false
constructor(private executablePath: string) {
if (!fs.existsSync(executablePath)) {
// executablePath can be passed like this
// "/Users/prisma/go/bin/photongo" as a path to the executable (no options)
// "go run prisma/photongo/generator" as a command
if (!executablePath.includes(' ') && !fs.existsSync(executablePath)) {
throw new Error(
`Error in generator: Can't find executable ${executablePath}`,
)
Expand All @@ -40,10 +43,22 @@ export class GeneratorProcess {
}
initSingleton(): Promise<void> {
return new Promise(async (resolve, reject) => {
const isBinary = await isBinaryFile(this.executablePath)
let isBinary = true

let command = this.executablePath
let args: string[] = []

if (this.executablePath.includes(' ')) {
const arr = this.executablePath.split(' ')
command = arr.shift()!
args = arr
} else {
isBinary = await isBinaryFile(this.executablePath)
}

this.child = spawn(
isBinary ? this.executablePath : process.execPath,
isBinary ? [] : ['--max-old-space-size=8096', this.executablePath],
isBinary ? command : process.execPath,
isBinary ? args : ['--max-old-space-size=8096', command],
{
stdio: ['pipe', 'inherit', 'pipe'],
},
Expand Down
12 changes: 7 additions & 5 deletions cli/prisma2/src/Generate.ts
Expand Up @@ -120,13 +120,13 @@ export class Generate implements Command {

await this.runGenerate({ generators, watchMode })

const isJSClient = generators.find((g) => g.options && g.options.generator.provider === 'prisma-client-js')

if (watchMode) {
logUpdate(watchingText + '\n' + this.logText)
await new Promise(r => null)
} else {
logUpdate(
this.logText +
`
const hint = `
You can now start using Prisma Client in your code:

\`\`\`
Expand All @@ -135,9 +135,11 @@ import { PrismaClient } from '@prisma/client'
// or const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()`)}
\`\`\`
\`\`\`

Explore the full API: ${link('http://pris.ly/d/client')}`,
Explore the full API: ${link('http://pris.ly/d/client')}`
logUpdate(
this.logText + (isJSClient ? hint : ''),
)
}

Expand Down