Skip to content

Commit

Permalink
fix: Now deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Dec 12, 2019
1 parent 4ced387 commit 7ed49eb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cli/prisma2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"scripts": {
"test": "./fixtures/test.sh && ./node_modules/.bin/mocha src/__tests__/integrate.test.ts --require ts-mocha src/__tests__/integrate.test.ts --timeout 10s",
"test:debug": "./node_modules/.bin/mocha --inspect-brk src/__tests__/integrate.test.ts --require ts-mocha src/__tests__/integrate.test.ts --timeout 10s",
"install": "node download-build/index.js || echo \"\"",
"install": "node download-build/index.js || echo \"Have fun with prisma2!\"",
"download": "node scripts/updateTag.js && node download-build/index.js || echo \"\"",
"tsc": "tsc -d && cp src/capture-worker.js dist/capture-worker.js && scripts/copy-runtime-dist.sh",
"ncc": "ncc build dist/bin.js -o build",
Expand Down
40 changes: 40 additions & 0 deletions cli/prisma2/scripts/download.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const { download } = require('@prisma/fetch-engine')
const pkg = require('../package.json')
const fs = require('fs')
const path = require('path')
const pkgUp = require('pkg-up')
const Debug = require('debug')
const debug = Debug('prisma2:download')

const binaryPath = eval(`require('path').join(__dirname, '../')`)

Expand All @@ -14,3 +19,38 @@ download({
showProgress: true,
version,
})

// if we are in a Now context, ensure that `prisma2 generate` is in the postinstall hook
if (process.env.INIT_CWD && process.env.NOW_BUILDER) {
ensurePostInstall().catch(e => {
debug(e)
})
}

async function ensurePostInstall() {
const appPkg = path.resolve(process.env.INIT_CWD, 'package.json')
if (fs.existsSync(appPkg)) {
ensurePostInstallPackage(appPkg)
} else {
const pkgPath = await pkgUp({
cwd: path.join(process.cwd(), '..'),
})
if (pkgPath) {
ensurePostInstallPackage(pkgPath)
}
}
}

function ensurePostInstallPackage(pkgPath) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))

pkg.scripts = pkg.scripts || {}

if (!pkg.scripts.postinstall) {
pkg.scripts.postinstall = 'prisma2 generate'
} else {
pkg.scripts.postinstall = `prisma2 generate && ${pkg.scripts.postinstall}`
}

fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
}

0 comments on commit 7ed49eb

Please sign in to comment.