Skip to content

Commit

Permalink
chore: up format script
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Dec 4, 2024
1 parent becba9f commit 48a6002
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scripts/formatPackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { execSync } from 'node:child_process'
import path from 'node:path'
import { glob } from 'glob'

Expand All @@ -15,6 +16,7 @@ for (const packagePath of packagePaths) {
type Package = Record<string, unknown> & {
name?: string | undefined
private?: boolean | undefined
version?: string | undefined
}
const file = Bun.file(packagePath)
const packageJson = (await file.json()) as Package
Expand All @@ -31,6 +33,14 @@ for (const packagePath of packagePaths) {
)

const { devDependencies: _dD, scripts: _s, type: _t, ...rest } = packageJson
if (Bun.env.PKG_PR_NEW) {
const gitHash = execSync('git rev-parse --short HEAD').toString().trim()
const branch = execSync('git branch --show-current')
.toString()
.trim()
.replace(/[^a-zA-Z0-9]/g, '_')
rest.version = `0.0.0-${branch}.${gitHash}`
}
await Bun.write(packagePath, `${JSON.stringify(rest, undefined, 2)}\n`)
}

Expand Down

0 comments on commit 48a6002

Please sign in to comment.