Skip to content

Commit 4b58511

Browse files
committed
build: add an auto increment version script using husky
1 parent c9a11ba commit 4b58511

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

.husky/pre-commit

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
# Bump version
5+
bun run version:bump
6+
7+
# Add the package.json to include version change
8+
git add package.json
9+
10+
# Run build to ensure everything works
111
bun run build

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "job-conciergerie",
3-
"version": "1.457",
3+
"version": "1.459",
44
"private": true,
55
"scripts": {
66
"dev": "next dev --turbopack",
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"prepare": "husky"
10+
"prepare": "husky",
11+
"version:bump": "bun scripts/increment-version.js"
1112
},
1213
"dependencies": {
1314
"@neondatabase/serverless": "latest",

scripts/increment-version.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Script to increment the minor version in package.json
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
const packageJsonPath = path.join(process.cwd(), 'package.json');
6+
7+
try {
8+
// Read package.json
9+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
10+
11+
// Parse current version
12+
const currentVersion = packageJson.version;
13+
const versionParts = currentVersion.split('.');
14+
15+
// Increment minor version
16+
if (versionParts.length >= 2) {
17+
const majorVersion = versionParts[0];
18+
const minorVersion = parseInt(versionParts[1], 10) + 1;
19+
20+
// Create new version string
21+
const newVersion = `${majorVersion}.${minorVersion}`;
22+
23+
// Update package.json
24+
packageJson.version = newVersion;
25+
26+
// Write updated package.json
27+
fs.writeFileSync(
28+
packageJsonPath,
29+
JSON.stringify(packageJson, null, 2) + '\n',
30+
'utf8'
31+
);
32+
33+
console.log(`📦 Version bumped: ${currentVersion}${newVersion}`);
34+
} else {
35+
console.error('❌ Invalid version format in package.json');
36+
process.exit(1);
37+
}
38+
} catch (error) {
39+
console.error('❌ Error updating version:', error);
40+
process.exit(1);
41+
}

0 commit comments

Comments
 (0)