Skip to content

Commit

Permalink
Fix / improve generate and --watch output and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 committed Jan 17, 2020
1 parent 4c94875 commit c19c69e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 9 additions & 0 deletions cli/prisma2/fixtures/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ if [[ ${VERSION} != *"prisma2@"* ]]; then
exit 1
fi

# Test generate output command
cd fixtures/project/subdir
GENERATE=$(node ../../../build/index.js generate)
if [[ ${GENERATE} != *"Generated "* ]]; then
echo "prisma2 generate is broken"
exit 1
fi
cd ../../..


# Test generation in npm script
rm -rf fixtures/project/subdir/@prisma
Expand Down
10 changes: 6 additions & 4 deletions cli/prisma2/src/Generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Generate implements Command {

private runGenerate = simpleDebounce(
async ({generators, watchMode}) => {
const message: string[] = ['']
const message: string[] = []

for (const generator of generators) {
const toStr = generator.options!.generator.output!
Expand Down Expand Up @@ -89,20 +89,22 @@ export class Generate implements Command {
console.error(missingGeneratorMessage)
}

const watchingText = `\n${chalk.green('Watching...')} ${chalk.dim(datamodelPath)}\n`

if (watchMode) {
const watchingText = `\n${chalk.green('Watching...')} ${chalk.dim(datamodelPath)}\n`
logUpdate(watchingText)

fs.watch(datamodelPath, async (eventType) => {
if (eventType === 'change') {
logUpdate(`\n${chalk.green('Building...')}\n${this.logText}`)
await this.runGenerate({generators, watchMode})
logUpdate(watchingText + this.logText)
logUpdate(watchingText + '\n' + this.logText)
}
})
}

this.runGenerate({generators, watchMode})
await this.runGenerate({generators, watchMode})
watchMode ? logUpdate(watchingText + '\n' + this.logText) : logUpdate(this.logText)

if (watchMode) await new Promise(r => null)

Expand Down

0 comments on commit c19c69e

Please sign in to comment.