Skip to content

Commit

Permalink
chore(publish): write commit to package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jun 9, 2020
1 parent d967a74 commit 5d14aef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"prisma2": "build/index.js"
},
"prisma": {
"version": "41f8d9863f1e0f6bfdb24def858e520f99bc2479"
"version": "41f8d9863f1e0f6bfdb24def858e520f99bc2479",
"prismaCommit": "d967a745e99bd1d7487e1d5a235455a88f6f700e"
},
"devDependencies": {
"@apexearth/copy": "1.4.5",
Expand Down
20 changes: 20 additions & 0 deletions src/scripts/ci/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,14 @@ async function publishPackages(
}

await writeVersion(pkgDir, newVersion, dryRun)

if (pkgName === '@prisma/cli') {
const latestCommit = await getLatestCommit('.')
await writeToPkgJson(pkgDir, (pkg) => {
pkg.prisma.prismaCommit = latestCommit
})
}

if (process.env.BUILDKITE) {
await run(pkgDir, `pnpm run build`, dryRun)
}
Expand Down Expand Up @@ -874,6 +882,18 @@ async function acquireLock(): Promise<() => void> {
}
}

async function writeToPkgJson(pkgDir, cb: (pkg: any) => any, dryRun?: boolean) {
const pkgJsonPath = path.join(pkgDir, 'package.json')
const file = await fs.readFile(pkgJsonPath, 'utf-8')
let packageJson = JSON.parse(file)
if (dryRun) {
console.log(`Would write to ${pkgJsonPath} from ${packageJson.version} now`)
} else {
packageJson = cb(packageJson)
await fs.writeFile(pkgJsonPath, JSON.stringify(packageJson, null, 2))
}
}

async function writeVersion(pkgDir: string, version: string, dryRun?: boolean) {
const pkgJsonPath = path.join(pkgDir, 'package.json')
const file = await fs.readFile(pkgJsonPath, 'utf-8')
Expand Down

0 comments on commit 5d14aef

Please sign in to comment.