UNPKG

1.7 kBapplication/x-shView Raw
1#!/bin/bash -e
2export RELEASE=1
3
4update_version() {
5 echo "$(node -p "p=require('./${1}');p.version='${2}';JSON.stringify(p,null,2)")" > $1
6 echo "${1} 的版本号升级到 ${2}"
7}
8
9validate_semver() {
10 if ! [[ $1 =~ ^[0-9]\.[0-9]+\.[0-9](-.+)? ]]; then
11 echo >&2 "版本号 $1 不合法!正确的版本号格式应该形如 1.0.2 或 2.3.0-beta.1"
12 exit 1
13 fi
14}
15
16unpublish_current_version() {
17 npm unpublish $1@$2 --registry=http://registry.npm.corp.qunar.com/
18}
19
20current_version=$(node -p "require('./package').version")
21package_name=$(node -p "require('./package').name")
22
23printf "输入下一个版本号(当前版本是 $current_version, 直接回车为当前版本号): "
24read next_version
25
26if [ "$next_version" = "" ]; then
27 next_version="$current_version"
28else
29 validate_semver $next_version
30fi
31
32# 表明可能需要发 rc-tag
33if [[ "$next_version" =~ ^[0-9]\.[0-9]+\.[0-9]-.+ ]]; then
34 printf "请输入 npm 需要发布的 tag (如 rc tag, 与正常 install 版本相区分): "
35 read tag_name
36fi
37
38next_ref="v$next_version"
39
40# npm test
41
42update_version 'package.json' $next_version
43
44if [ "$next_version" = "$current_version" ]; then
45 unpublish_current_version $package_name $current_version
46 git tag -d $next_ref || echo "本地不存在 $next_ref tag"
47 git push origin -d tag $next_ref || echo "线上不存在 $next_ref tag"
48else
49 git commit -am "Version $next_version"
50fi
51
52# push first to make sure we're up-to-date
53git push origin master
54
55git tag $next_ref
56
57git push origin $next_ref
58
59if [ "$tag_name" = "" ]; then
60 npm publish --registry=http://registry.npm.corp.qunar.com/
61else
62 npm publish --registry=http://registry.npm.corp.qunar.com/ --tag $tag_name
63fi