-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-version.sh
More file actions
executable file
·70 lines (60 loc) · 2.44 KB
/
sync-version.sh
File metadata and controls
executable file
·70 lines (60 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# filepath: /Users/ariss/Developer/github.com/riipandi/vitto/sync-version.sh
set -euo pipefail
ROOT_DIR=$(dirname "$0")
# Get current version from ROOT_DIR/package.json
CURRENT_VERSION=$(jq -r '.version' "$ROOT_DIR/package.json")
echo "Current version: $CURRENT_VERSION"
# Check if version is provided as argument
if [ $# -eq 1 ]; then
NEW_VERSION="$1"
echo "Using provided version: $NEW_VERSION"
else
# Get new version from user
printf "%-20s: " "Enter new version (e.g. 1.2.3)"
read NEW_VERSION
fi
# Validate version format (semantic versioning: X.Y.Z or X.Y.Z-suffix)
if [[ ! "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\.\-]+)?$ ]]; then
echo "Error: Version must follow semantic versioning format (e.g., 0.0.0 or 1.2.3-beta.1)"
exit 1
fi
# Check if version is different from current
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
echo "Warning: New version is the same as current version"
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 0
fi
fi
# Update version in ROOT_DIR/package.json
jq --arg v "$NEW_VERSION" '.version = $v' "$ROOT_DIR/package.json" > "$ROOT_DIR/package.json.tmp"
mv "$ROOT_DIR/package.json.tmp" "$ROOT_DIR/package.json"
# Update version in all package.json in packages/**/** (exclude template-* folders)
find "$ROOT_DIR/packages" -type f -name package.json | grep -v '/template-' | while read -r pkg; do
jq --arg v "$NEW_VERSION" '.version = $v' "$pkg" > "$pkg.tmp"
mv "$pkg.tmp" "$pkg"
echo "Updated version in: $pkg"
done
# Update vitto devDependencies in all template-* folders
find "$ROOT_DIR/packages/create-vitto" -type f -name package.json | grep '/template-' | while read -r pkg; do
# Check if vitto exists in devDependencies
if jq -e '.devDependencies.vitto' "$pkg" >/dev/null 2>&1; then
jq --arg v "^$NEW_VERSION" '.devDependencies.vitto = $v' "$pkg" > "$pkg.tmp"
mv "$pkg.tmp" "$pkg"
echo "Updated vitto version in: $pkg"
fi
done
# Running code formatting after version update
if command -v pnpm >/dev/null 2>&1; then
echo "Running code formatting..."
pnpm run --silent format
else
echo "pnpm is not installed. Please run code formatting manually."
fi
echo ""
echo "✓ Version updated from $CURRENT_VERSION to $NEW_VERSION"
echo "✓ All package.json files have been updated"
echo "✓ Template vitto devDependencies have been updated"