From 2b1f180320077a1153b474cb3d7a6bfd74ad636b Mon Sep 17 00:00:00 2001 From: Luca Steeb Date: Thu, 26 Mar 2020 01:40:08 +0700 Subject: [PATCH 1/2] feat(prisma2/cli): allow arbitrary generator commands with flags only show the JS example when generator is prisma-client-js fix #1101 --- cli/generator-helper/src/GeneratorProcess.ts | 20 ++++++++++++++++---- cli/prisma2/src/Generate.ts | 12 +++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cli/generator-helper/src/GeneratorProcess.ts b/cli/generator-helper/src/GeneratorProcess.ts index d973ec00165f..cda898cf51f2 100644 --- a/cli/generator-helper/src/GeneratorProcess.ts +++ b/cli/generator-helper/src/GeneratorProcess.ts @@ -26,7 +26,7 @@ export class GeneratorProcess { private initPromise?: Promise private initialized: boolean = false constructor(private executablePath: string) { - if (!fs.existsSync(executablePath)) { + if (!executablePath.includes(' ') && !fs.existsSync(executablePath)) { throw new Error( `Error in generator: Can't find executable ${executablePath}`, ) @@ -40,10 +40,22 @@ export class GeneratorProcess { } initSingleton(): Promise { 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'], }, diff --git a/cli/prisma2/src/Generate.ts b/cli/prisma2/src/Generate.ts index dcab6ea9081d..44c2706d8d20 100644 --- a/cli/prisma2/src/Generate.ts +++ b/cli/prisma2/src/Generate.ts @@ -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: \`\`\` @@ -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 : ''), ) } From 8bc3d0ff9e0b302551aa07a8cefc19cc1634e7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Galeran?= Date: Thu, 26 Mar 2020 10:05:45 +0100 Subject: [PATCH 2/2] Add comments --- cli/generator-helper/src/GeneratorProcess.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/generator-helper/src/GeneratorProcess.ts b/cli/generator-helper/src/GeneratorProcess.ts index cda898cf51f2..b0894474ebe3 100644 --- a/cli/generator-helper/src/GeneratorProcess.ts +++ b/cli/generator-helper/src/GeneratorProcess.ts @@ -26,6 +26,9 @@ export class GeneratorProcess { private initPromise?: Promise private initialized: boolean = false constructor(private executablePath: string) { + // 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}`,