-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·151 lines (131 loc) · 4.02 KB
/
publish.sh
File metadata and controls
executable file
·151 lines (131 loc) · 4.02 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# publish.sh - Script for updating version and publishing to npm
# Ensure script fails on any error
set -e
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}Starting publication process...${NC}"
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check requirements
if ! command_exists npm; then
echo -e "${RED}Error: npm is not installed${NC}"
exit 1
fi
if ! command_exists git; then
echo -e "${RED}Error: git is not installed${NC}"
exit 1
fi
# Check if we're in a clean git state
if [[ -n $(git status -s) ]]; then
echo -e "${YELLOW}Warning: Git working directory is not clean${NC}"
echo "You may want to commit your changes first"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Publication aborted${NC}"
exit 1
fi
fi
# Get current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo -e "${BLUE}Current version: ${YELLOW}$CURRENT_VERSION${NC}"
# Check if version type is specified as argument
VERSION_TYPE="patch" # Default to patch
if [ "$1" != "" ]; then
case $1 in
patch|minor|major)
VERSION_TYPE="$1"
;;
--version=*)
SPECIFIC_VERSION="${1#*=}"
VERSION_ARGS="--version=$SPECIFIC_VERSION"
;;
*)
echo -e "${RED}Invalid version type: $1${NC}"
echo "Valid options are: patch, minor, major, or --version=X.Y.Z"
exit 1
;;
esac
else
# Ask for version type if not provided as argument
echo -e "${BLUE}What kind of version update is this?${NC}"
echo "1) patch (bug fixes) [DEFAULT]"
echo "2) minor (new features)"
echo "3) major (breaking changes)"
echo "4) custom (specify version)"
read -p "Enter your choice [1-4] or press Enter for patch: " VERSION_CHOICE
# Default to patch if no input
VERSION_CHOICE=${VERSION_CHOICE:-1}
case $VERSION_CHOICE in
1|"")
VERSION_TYPE="patch"
VERSION_ARGS="--patch"
;;
2)
VERSION_TYPE="minor"
VERSION_ARGS="--minor"
;;
3)
VERSION_TYPE="major"
VERSION_ARGS="--major"
;;
4)
read -p "Enter custom version (e.g., 1.2.3): " CUSTOM_VERSION
VERSION_ARGS="--version=$CUSTOM_VERSION"
;;
*)
echo -e "${RED}Invalid choice${NC}"
exit 1
;;
esac
fi
# Run version.sh to increment version and update changelog
echo -e "${BLUE}Running version script...${NC}"
./version.sh $VERSION_ARGS
# Get new version from package.json
NEW_VERSION=$(node -p "require('./package.json').version")
echo -e "${GREEN}Updated version: ${YELLOW}$NEW_VERSION${NC}"
# Run linting
echo -e "${BLUE}Running linting...${NC}"
npm run lint || {
echo -e "${YELLOW}Linting found issues.${NC}"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Publication aborted${NC}"
exit 1
fi
}
# Run tests if available
echo -e "${BLUE}Running tests...${NC}"
npm test || {
echo -e "${YELLOW}Tests failed.${NC}"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Publication aborted${NC}"
exit 1
fi
}
# Commit changes
echo -e "${BLUE}Committing version update...${NC}"
git add package.json package-lock.json CHANGELOG.md
git commit -m "Version bump to $NEW_VERSION"
# Create git tag
echo -e "${BLUE}Creating git tag v$NEW_VERSION...${NC}"
git tag -a "v$NEW_VERSION" -m "Version $NEW_VERSION"
# Push to GitHub
echo -e "${BLUE}Pushing changes and tags to GitHub...${NC}"
git push origin main
git push origin --tags
# Publish to npm
echo -e "${BLUE}Publishing to npm...${NC}"
npm publish --access=public
echo -e "${GREEN}Successfully published version $NEW_VERSION${NC}"