-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublish.sh
More file actions
43 lines (32 loc) · 1011 Bytes
/
publish.sh
File metadata and controls
43 lines (32 loc) · 1011 Bytes
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
#!/bin/bash
# 停止脚本如果有错误
set -e
# 检查npm是否已登录
if ! npm whoami > /dev/null 2>&1; then
echo "You are not logged in to npm. Please run 'npm login' first."
exit 1
fi
# 构建TypeScript项目
echo "Building the project..."
npm run build
# 获取当前版本号
CURRENT_VERSION=$(node -p "require('./package.json').version")
# 提示用户输入新的版本号
read -p "Enter the new version (current version is $CURRENT_VERSION): " NEW_VERSION
# 如果用户没有输入新版本号,保持当前版本号
if [ -z "$NEW_VERSION" ]; then
NEW_VERSION=$CURRENT_VERSION
fi
# 更新版本号
echo "Updating version to $NEW_VERSION..."
npm version $NEW_VERSION --no-git-tag-version
# 发布到NPM
echo "Publishing to npm..."
npm publish
# 提交更改并推送到git仓库(如果需要)
# git add .
# git commit -m "Release version $NEW_VERSION"
# git push origin main
echo "Published version $NEW_VERSION to npm."
# 确保脚本有可执行权限
# chmod +x publish.sh