Skip to content

Commit ab7c5a2

Browse files
committed
add nail version script
1 parent 0077c2b commit ab7c5a2

3 files changed

Lines changed: 67 additions & 5 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ jobs:
5252
- run: git config user.name "$(git log -n 1 --pretty=format:%an)"
5353
- run: git config user.email "$(git log -n 1 --pretty=format:%ae)"
5454

55-
- run: npm version ${{ github.event.inputs.release_type }}
56-
working-directory: packages/react-native-device-activity
57-
5855
- run: bun install
5956

57+
- run: bun run nail-workspace-dependency-versions
58+
59+
- run: echo "versionTag=$(npm version ${{ github.event.inputs.release_type }} -m "%s ${{ github.event.inputs.description }}")" >> $GITHUB_ENV
60+
working-directory: packages/react-native-device-activity
61+
6062
- name: Setup NPM Authentication
6163
run: |
6264
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
@@ -66,4 +68,11 @@ jobs:
6668

6769
- run: git push --follow-tags
6870
env:
69-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
71+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
72+
73+
- name: Release
74+
uses: softprops/action-gh-release@v1
75+
with:
76+
name: ${{ env.versionTag }} ${{ github.event.inputs.description }}
77+
tag_name: ${{ env.versionTag }}
78+
generate_release_notes: true

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"lint": "eslint .",
88
"pre-push": "bun run typecheck && bun run lint && apps/example/ios/Pods/SwiftLint/swiftlint lint --strict",
99
"typecheck": "cd packages/react-native-device-activity && bun run typecheck && cd ../../apps/example && bun run typecheck",
10-
"prepare": "husky"
10+
"prepare": "husky",
11+
"nail-workspace-dependency-versions": "bun run scripts/nail-workspace-dependency-versions.ts"
1112
},
1213
"workspaces": ["packages/*", "apps/*"],
1314
"keywords": [
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Glob } from 'bun'
2+
import fs from 'fs'
3+
4+
// Find all package.json files (excluding node_modules)
5+
const packageFilesUnfiltered = new Glob('./**/package.json').scanSync()
6+
7+
const packageFiles = new Array(...packageFilesUnfiltered).filter((filePath) => !filePath.includes('node_modules'))
8+
9+
// Create a map of package names to their versions
10+
const packageVersions: Record<string, string> = {}
11+
packageFiles.forEach((filePath) => {
12+
const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'))
13+
if (pkg.name && pkg.version) {
14+
packageVersions[pkg.name] = pkg.version
15+
}
16+
})
17+
18+
// Process each package.json
19+
packageFiles.forEach((filePath) => {
20+
const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'))
21+
let modified = false
22+
23+
// Helper function to process dependencies
24+
const processDeps = (deps: Record<string, string>) => {
25+
if (!deps) return deps
26+
const newDeps = { ...deps }
27+
28+
Object.entries(deps).forEach(([name, version]) => {
29+
if (version.startsWith('workspace:')) {
30+
const actualVersion = version === 'workspace:*'
31+
? packageVersions[name]
32+
: version.replace('workspace:', '')
33+
34+
if (actualVersion) {
35+
newDeps[name] = actualVersion
36+
modified = true
37+
}
38+
}
39+
})
40+
return newDeps
41+
}
42+
43+
// Process all dependency types
44+
pkg.dependencies = processDeps(pkg.dependencies)
45+
pkg.devDependencies = processDeps(pkg.devDependencies)
46+
pkg.peerDependencies = processDeps(pkg.peerDependencies)
47+
48+
// Save if modified
49+
if (modified) {
50+
fs.writeFileSync(filePath, `${JSON.stringify(pkg, null, 2)}\n`)
51+
}
52+
})

0 commit comments

Comments
 (0)