@@ -4,8 +4,7 @@ set -euo pipefail
4
4
5
5
# Release script for jquery-micro-utils
6
6
# - Creates a GitHub release for the current version
7
- # - Bumps patch version in package.json
8
- # - Syncs runtime version in src/jquery-micro-utils.js
7
+ # - Bumps patch version in package.json, src file, and README CDN link
9
8
# - Commits and pushes the bump
10
9
11
10
REPO_ROOT=" $( cd " $( dirname " $0 " ) /.." && pwd) "
@@ -16,7 +15,7 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
16
15
exit 1
17
16
fi
18
17
19
- # Ensure working tree is clean to avoid accidental releases of uncommitted code
18
+ # Ensure working tree is clean
20
19
if ! git diff-index --quiet HEAD --; then
21
20
echo " Error: working tree has uncommitted changes. Please commit or stash before releasing." >&2
22
21
exit 1
25
24
BRANCH=" $( git rev-parse --abbrev-ref HEAD) "
26
25
HEAD_SHA=" $( git rev-parse HEAD) "
27
26
28
- PKG_JSON=" package.json"
29
- SRC_FILE=" src/jquery-micro-utils.js"
30
-
31
- if [[ ! -f " $PKG_JSON " ]]; then
32
- echo " Error: $PKG_JSON not found." >&2
33
- exit 1
34
- fi
35
-
36
- # Read version from package.json; initialize if missing
37
- CURRENT_VERSION=" $( node -e " try{const v=require('./package.json').version||'';process.stdout.write(String(v||''))}catch(e){process.stdout.write('')}" ) "
38
-
39
- init_if_missing () {
40
- local init_ver=" $1 "
41
- echo " Initializing package version to $init_ver "
42
- npm version " $init_ver " --no-git-tag-version > /dev/null
43
-
44
- # Sync runtime version in source file if present
45
- if [[ -f " $SRC_FILE " ]]; then
46
- node - << 'NODE ' "$init_ver" "$SRC_FILE"
47
- const fs = require('fs');
48
- const path = process.argv[3];
49
- const ver = process.argv[2];
50
- let s = fs.readFileSync(path, 'utf8');
51
- s = s.replace(/(jQuery\s+Micro\s+Utils\s+v)(\d+\.\d+\.\d+)/, `$1${ver}`);
52
- s = s.replace(/(\$\.microUtils\s*=\s*\{\s*version:\s*['"])([^'"]+)(['"]\s*\})/, `$1${ver}$3`);
53
- fs.writeFileSync(path, s);
54
- NODE
55
- git add " $PKG_JSON " " $SRC_FILE "
56
- else
57
- git add " $PKG_JSON "
58
- fi
59
- git commit -m " chore(version): initialize to v$init_ver " > /dev/null
60
- }
27
+ # Read current version from package.json
28
+ CURRENT_VERSION=" $( perl -ne ' print $1 if /"version":\s*"([^"]+)"/' package.json) "
61
29
62
30
if [[ -z " $CURRENT_VERSION " ]]; then
63
- # Default initial version
64
- init_if_missing " 0.1.0"
31
+ echo " Initializing package version to 0.1.0"
32
+ npm version " 0.1.0" --no-git-tag-version > /dev/null
33
+ update_version " 0.1.0"
34
+ git add package.json src/jquery-micro-utils.js README.md
35
+ git commit -m " chore(version): initialize to v0.1.0" > /dev/null
65
36
CURRENT_VERSION=" 0.1.0"
66
- # Update HEAD SHA after the init commit
67
37
HEAD_SHA=" $( git rev-parse HEAD) "
68
38
fi
69
39
70
40
TAG=" v$CURRENT_VERSION "
71
41
72
- # Ensure the tag doesn't already exist remotely as a release
42
+ # Ensure the tag doesn't already exist remotely
73
43
if gh release view " $TAG " > /dev/null 2>&1 ; then
74
44
echo " Error: release $TAG already exists on GitHub." >&2
75
45
exit 1
78
48
echo " Creating GitHub release $TAG from $BRANCH @$HEAD_SHA "
79
49
gh release create " $TAG " --title " $TAG " --generate-notes --target " $HEAD_SHA "
80
50
81
- # Bump patch version in package.json without creating a git tag
51
+ # Bump patch version
82
52
echo " Bumping patch version"
83
53
npm version patch --no-git-tag-version > /dev/null
84
54
85
- NEW_VERSION=" $( node -p " require('./package.json').version" ) "
86
-
87
- # Sync runtime version in source file
88
- if [[ -f " $SRC_FILE " ]]; then
89
- node - << 'NODE ' "$NEW_VERSION" "$SRC_FILE"
90
- const fs = require('fs');
91
- const path = process.argv[3];
92
- const ver = process.argv[2];
93
- let s = fs.readFileSync(path, 'utf8');
94
- s = s.replace(/(jQuery\s+Micro\s+Utils\s+v)(\d+\.\d+\.\d+)/, `$1${ver}`);
95
- s = s.replace(/(\$\.microUtils\s*=\s*\{\s*version:\s*['"])([^'"]+)(['"]\s*\})/, `$1${ver}$3`);
96
- fs.writeFileSync(path, s);
97
- NODE
98
- git add " $PKG_JSON " " $SRC_FILE "
99
- else
100
- git add " $PKG_JSON "
101
- fi
55
+ NEW_VERSION=" $( perl -ne ' print $1 if /"version":\s*"([^"]+)"/' package.json) "
56
+
57
+ update_version () {
58
+ local ver=" $1 "
59
+ # Update source file version
60
+ perl -pi -e " s/(jQuery\\ s+Micro\\ s+Utils\\ s+v)\\ d+\\ .\\ d+\\ .\\ d+/\$ 1$ver /g" src/jquery-micro-utils.js
61
+ perl -pi -e " s/(\\\$\\ .microUtils\\ s*=\\ s*\\ {\\ s*version:\\ s*['\" ])([^'\" ]+)(['\" ]\\ s*\\ })/\$ 1$ver \$ 3/g" src/jquery-micro-utils.js
62
+ # Update README CDN link
63
+ perl -pi -e " s/(cdn\\ .jsdelivr\\ .net\\ /gh\\ /AnswerDotAI\\ /jquery-micro-utils\\ @)\\ d+\\ .\\ d+\\ .\\ d+/\$ 1$ver /g" README.md
64
+ }
102
65
66
+ update_version " $NEW_VERSION "
67
+ git add package.json src/jquery-micro-utils.js README.md
103
68
git commit -m " chore(version): bump to v$NEW_VERSION " > /dev/null
104
69
105
70
echo " Pushing changes to origin/$BRANCH "
0 commit comments