Skip to content

Commit 5056bc0

Browse files
committed
release.sh
1 parent 731b792 commit 5056bc0

File tree

1 file changed

+23
-58
lines changed

1 file changed

+23
-58
lines changed

scripts/release.sh

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ set -euo pipefail
44

55
# Release script for jquery-micro-utils
66
# - 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
98
# - Commits and pushes the bump
109

1110
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
@@ -16,7 +15,7 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
1615
exit 1
1716
fi
1817

19-
# Ensure working tree is clean to avoid accidental releases of uncommitted code
18+
# Ensure working tree is clean
2019
if ! git diff-index --quiet HEAD --; then
2120
echo "Error: working tree has uncommitted changes. Please commit or stash before releasing." >&2
2221
exit 1
@@ -25,51 +24,22 @@ fi
2524
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
2625
HEAD_SHA="$(git rev-parse HEAD)"
2726

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)"
6129

6230
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
6536
CURRENT_VERSION="0.1.0"
66-
# Update HEAD SHA after the init commit
6737
HEAD_SHA="$(git rev-parse HEAD)"
6838
fi
6939

7040
TAG="v$CURRENT_VERSION"
7141

72-
# Ensure the tag doesn't already exist remotely as a release
42+
# Ensure the tag doesn't already exist remotely
7343
if gh release view "$TAG" >/dev/null 2>&1; then
7444
echo "Error: release $TAG already exists on GitHub." >&2
7545
exit 1
@@ -78,28 +48,23 @@ fi
7848
echo "Creating GitHub release $TAG from $BRANCH@$HEAD_SHA"
7949
gh release create "$TAG" --title "$TAG" --generate-notes --target "$HEAD_SHA"
8050

81-
# Bump patch version in package.json without creating a git tag
51+
# Bump patch version
8252
echo "Bumping patch version"
8353
npm version patch --no-git-tag-version >/dev/null
8454

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+
}
10265

66+
update_version "$NEW_VERSION"
67+
git add package.json src/jquery-micro-utils.js README.md
10368
git commit -m "chore(version): bump to v$NEW_VERSION" >/dev/null
10469

10570
echo "Pushing changes to origin/$BRANCH"

0 commit comments

Comments
 (0)