Skip to content

Commit 9e4f12e

Browse files
committed
Changed by script: version 1.0.4
1 parent e6c6463 commit 9e4f12e

File tree

2 files changed

+164
-1
lines changed

2 files changed

+164
-1
lines changed

generate-package.sh

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#!/bin/bash
2+
3+
# Version bump and package generation script
4+
# Usage: ./generate-package.sh [fix|patch|version]
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
# Function to print colored output
15+
print_info() {
16+
echo -e "${GREEN}[INFO]${NC} $1"
17+
}
18+
19+
print_warning() {
20+
echo -e "${YELLOW}[WARNING]${NC} $1"
21+
}
22+
23+
print_error() {
24+
echo -e "${RED}[ERROR]${NC} $1"
25+
}
26+
27+
# Check if argument is provided
28+
if [ $# -eq 0 ]; then
29+
print_error "No argument provided. Usage: $0 [fix|patch|version]"
30+
exit 1
31+
fi
32+
33+
BUMP_TYPE=$1
34+
35+
# Validate argument
36+
if [[ "$BUMP_TYPE" != "fix" && "$BUMP_TYPE" != "patch" && "$BUMP_TYPE" != "version" ]]; then
37+
print_error "Invalid argument. Use: fix, patch, or version"
38+
exit 1
39+
fi
40+
41+
# Check if package.json exists
42+
if [ ! -f "package.json" ]; then
43+
print_error "package.json not found in current directory"
44+
exit 1
45+
fi
46+
47+
# Check if we're in a git repository
48+
if [ ! -d ".git" ]; then
49+
print_error "Not in a git repository"
50+
exit 1
51+
fi
52+
53+
# Check if vsce is installed
54+
if ! command -v vsce &> /dev/null; then
55+
print_error "vsce is not installed. Please install it with: npm install -g vsce"
56+
exit 1
57+
fi
58+
59+
print_info "Reading current version from package.json..."
60+
61+
# Extract current version from package.json
62+
CURRENT_VERSION=$(grep '"version"' package.json | sed 's/.*"version": *"\([^"]*\)".*/\1/')
63+
64+
if [ -z "$CURRENT_VERSION" ]; then
65+
print_error "Could not extract version from package.json"
66+
exit 1
67+
fi
68+
69+
print_info "Current version: $CURRENT_VERSION"
70+
71+
# Split version into components
72+
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
73+
74+
if [ ${#VERSION_PARTS[@]} -ne 3 ]; then
75+
print_error "Version format is invalid. Expected format: x.y.z"
76+
exit 1
77+
fi
78+
79+
MAJOR=${VERSION_PARTS[0]}
80+
MINOR=${VERSION_PARTS[1]}
81+
PATCH=${VERSION_PARTS[2]}
82+
83+
print_info "Current version components: Major=$MAJOR, Minor=$MINOR, Patch=$PATCH"
84+
85+
# Calculate new version based on bump type
86+
case $BUMP_TYPE in
87+
"fix")
88+
NEW_PATCH=$((PATCH + 1))
89+
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
90+
;;
91+
"patch")
92+
NEW_MINOR=$((MINOR + 1))
93+
NEW_VERSION="$MAJOR.$NEW_MINOR.0"
94+
;;
95+
"version")
96+
NEW_MAJOR=$((MAJOR + 1))
97+
NEW_VERSION="$NEW_MAJOR.0.0"
98+
;;
99+
esac
100+
101+
print_info "New version will be: $NEW_VERSION"
102+
103+
# Update package.json
104+
print_info "Updating package.json with new version..."
105+
106+
# Create backup
107+
cp package.json package.json.backup
108+
109+
# Update version in package.json using sed
110+
if [[ "$OSTYPE" == "darwin"* ]]; then
111+
# macOS version of sed
112+
sed -i '' "s/\"version\": \"$CURRENT_VERSION\"/\"version\": \"$NEW_VERSION\"/" package.json
113+
else
114+
# Linux version of sed
115+
sed -i "s/\"version\": \"$CURRENT_VERSION\"/\"version\": \"$NEW_VERSION\"/" package.json
116+
fi
117+
118+
# Verify the change was made
119+
UPDATED_VERSION=$(grep '"version"' package.json | sed 's/.*"version": *"\([^"]*\)".*/\1/')
120+
121+
if [ "$UPDATED_VERSION" != "$NEW_VERSION" ]; then
122+
print_error "Failed to update version in package.json"
123+
# Restore backup
124+
mv package.json.backup package.json
125+
exit 1
126+
fi
127+
128+
# Remove backup
129+
rm package.json.backup
130+
131+
print_info "Successfully updated package.json to version $NEW_VERSION"
132+
133+
# Git operations
134+
print_info "Adding all changes to git..."
135+
git add .
136+
137+
print_info "Creating commit..."
138+
COMMIT_MESSAGE="Changed by script: version $NEW_VERSION"
139+
git commit -m "$COMMIT_MESSAGE"
140+
141+
print_info "Pushing to main branch..."
142+
git push origin main
143+
144+
print_info "Creating tag v$NEW_VERSION..."
145+
git tag "v$NEW_VERSION"
146+
147+
print_info "Pushing tag to origin..."
148+
git push origin "v$NEW_VERSION"
149+
150+
print_info "Creating package with vsce..."
151+
vsce package
152+
153+
print_info "✅ Successfully completed all operations!"
154+
print_info " - Updated version from $CURRENT_VERSION to $NEW_VERSION"
155+
print_info " - Committed and pushed changes"
156+
print_info " - Created and pushed tag v$NEW_VERSION"
157+
print_info " - Generated package file"
158+
159+
# List generated package files
160+
PACKAGE_FILES=$(ls *.vsix 2>/dev/null | tail -1)
161+
if [ -n "$PACKAGE_FILES" ]; then
162+
print_info " - Package file: $PACKAGE_FILES"
163+
fi

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "turnstyle",
33
"displayName": "Turnstyle",
44
"description": "Turnstile theme based on never enough colors",
5-
"version": "1.0.3",
5+
"version": "1.0.4",
66
"publisher": "oxechicao",
77
"repository": {
88
"type": "git",

0 commit comments

Comments
 (0)