-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublish.sh
More file actions
212 lines (186 loc) · 5.89 KB
/
publish.sh
File metadata and controls
212 lines (186 loc) · 5.89 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
# publish.sh - Quick publish script for vite-plugin-component-debugger
set -e # Exit on error
echo "🚀 Vite Plugin Component Debugger - Quick Publish"
echo "================================================"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if npm is installed
if ! command -v npm &> /dev/null; then
echo -e "${RED}❌ npm is not installed${NC}"
exit 1
fi
# Check if logged in to npm
echo -n "Checking npm login... "
NPM_USER=$(npm whoami 2>/dev/null || echo "")
if [ -z "$NPM_USER" ]; then
echo -e "${RED}❌ Not logged in${NC}"
echo ""
echo "Please login to npm first:"
echo " npm login"
exit 1
else
echo -e "${GREEN}✅ Logged in as: $NPM_USER${NC}"
fi
# Check package name availability
PACKAGE_NAME=$(node -p "require('./package.json').name" 2>/dev/null || echo "")
if [ -z "$PACKAGE_NAME" ]; then
echo -e "${RED}❌ Could not read package.json${NC}"
exit 1
fi
echo -n "Checking package name availability... "
if npm view "$PACKAGE_NAME" version &>/dev/null; then
CURRENT_VERSION=$(npm view "$PACKAGE_NAME" version)
echo -e "${YELLOW}⚠️ Package exists (v$CURRENT_VERSION)${NC}"
echo ""
echo "This will update the existing package."
read -p "Continue? (y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 0
fi
else
echo -e "${GREEN}✅ Package name available${NC}"
fi
# Clean and install
echo ""
echo "📦 Preparing package..."
echo "----------------------"
echo "Cleaning previous builds..."
rm -rf dist node_modules package-lock.json
echo "Installing dependencies..."
npm install
echo "Running tests..."
if npm test; then
echo -e "${GREEN}✅ Tests passed${NC}"
else
echo -e "${RED}❌ Tests failed${NC}"
exit 1
fi
echo "Building package..."
if npm run build; then
echo -e "${GREEN}✅ Build successful${NC}"
else
echo -e "${RED}❌ Build failed${NC}"
exit 1
fi
# Check git status
echo ""
echo "📋 Git Status"
echo "-------------"
if [ -d .git ]; then
if [ -n "$(git status --porcelain)" ]; then
echo -e "${YELLOW}⚠️ You have uncommitted changes${NC}"
git status --short
echo ""
read -p "Commit these changes first? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Commit message: " COMMIT_MSG
git add .
git commit -m "$COMMIT_MSG"
echo -e "${GREEN}✅ Changes committed${NC}"
fi
else
echo -e "${GREEN}✅ Working directory clean${NC}"
fi
else
echo "Not a git repository (optional)"
fi
# Show what will be published
echo ""
echo "📄 Files to be published:"
echo "------------------------"
npm pack --dry-run 2>&1 | grep -A 100 "Tarball Contents" | grep -B 100 "Tarball Details" | grep "📦" || npm pack --dry-run
# Get current version
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo ""
echo "📌 Current version: $CURRENT_VERSION"
# Ask for version bump
echo ""
echo "Choose version bump:"
echo " 1) Patch (bug fixes) - $CURRENT_VERSION → $(npm version patch --no-git-tag-version --silent && node -p "require('./package.json').version" && git checkout package.json)"
echo " 2) Minor (new features) - $CURRENT_VERSION → $(npm version minor --no-git-tag-version --silent && node -p "require('./package.json').version" && git checkout package.json)"
echo " 3) Major (breaking changes) - $CURRENT_VERSION → $(npm version major --no-git-tag-version --silent && node -p "require('./package.json').version" && git checkout package.json)"
echo " 4) Keep current version"
echo ""
read -p "Select (1-4): " VERSION_CHOICE
case $VERSION_CHOICE in
1)
npm version patch
echo -e "${GREEN}✅ Version bumped to $(node -p "require('./package.json').version")${NC}"
;;
2)
npm version minor
echo -e "${GREEN}✅ Version bumped to $(node -p "require('./package.json').version")${NC}"
;;
3)
npm version major
echo -e "${GREEN}✅ Version bumped to $(node -p "require('./package.json').version")${NC}"
;;
4)
echo "Keeping current version"
;;
*)
echo -e "${RED}Invalid choice${NC}"
exit 1
;;
esac
NEW_VERSION=$(node -p "require('./package.json').version")
# Final confirmation
echo ""
echo "======================================"
echo "Ready to publish:"
echo " Package: $PACKAGE_NAME"
echo " Version: $NEW_VERSION"
echo " User: $NPM_USER"
echo "======================================"
echo ""
# Check if it's a scoped package
if [[ "$PACKAGE_NAME" == @* ]]; then
echo -e "${YELLOW}Note: This is a scoped package${NC}"
echo "It will be published with --access public"
echo ""
fi
read -p "🚀 Publish now? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
echo "Publishing to npm..."
if [[ "$PACKAGE_NAME" == @* ]]; then
npm publish --access public
else
npm publish
fi
if [ $? -eq 0 ]; then
echo ""
echo -e "${GREEN}✅ Successfully published $PACKAGE_NAME@$NEW_VERSION${NC}"
echo ""
echo "View your package at:"
echo " https://www.npmjs.com/package/$PACKAGE_NAME"
echo ""
# Push to git if it exists
if [ -d .git ]; then
echo "Pushing to git..."
git push 2>/dev/null || echo "Could not push to git (no remote?)"
git push --tags 2>/dev/null || echo "Could not push tags"
fi
echo ""
echo "🎉 Congratulations! Your package is now live!"
echo ""
echo "Next steps:"
echo " - Share on social media"
echo " - Create a demo repository"
echo " - Add badges to your README"
echo ""
else
echo -e "${RED}❌ Publishing failed${NC}"
exit 1
fi
else
echo "Publishing cancelled"
fi