1 |
|
2 | export RELEASE=1
|
3 |
|
4 | update_version() {
|
5 | echo "$(node -p "p=require('./${1}');p.version='${2}';JSON.stringify(p,null,2)")" > $1
|
6 | echo "将 ${1} 的版本号升级到 ${2}"
|
7 | }
|
8 |
|
9 | validate_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 |
|
16 | unpublish_current_version() {
|
17 | npm unpublish $1@$2 --registry=http://registry.npm.corp.qunar.com/
|
18 | }
|
19 |
|
20 | current_version=$(node -p "require('./package').version")
|
21 | package_name=$(node -p "require('./package').name")
|
22 |
|
23 | printf "输入下一个版本号(当前版本是 $current_version, 直接回车为当前版本号): "
|
24 | read next_version
|
25 |
|
26 | if [ "$next_version" = "" ]; then
|
27 | next_version="$current_version"
|
28 | else
|
29 | validate_semver $next_version
|
30 | fi
|
31 |
|
32 |
|
33 | if [[ "$next_version" =~ ^[0-9]\.[0-9]+\.[0-9]-.+ ]]; then
|
34 | printf "请输入 npm 需要发布的 tag (如 rc tag, 与正常 install 版本相区分): "
|
35 | read tag_name
|
36 | fi
|
37 |
|
38 | next_ref="v$next_version"
|
39 |
|
40 |
|
41 |
|
42 | update_version 'package.json' $next_version
|
43 |
|
44 | if [ "$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"
|
48 | else
|
49 | git commit -am "Version $next_version"
|
50 | fi
|
51 |
|
52 |
|
53 | git push origin master
|
54 |
|
55 | git tag $next_ref
|
56 |
|
57 | git push origin $next_ref
|
58 |
|
59 | if [ "$tag_name" = "" ]; then
|
60 | npm publish --registry=http://registry.npm.corp.qunar.com/
|
61 | else
|
62 | npm publish --registry=http://registry.npm.corp.qunar.com/ --tag $tag_name
|
63 | fi
|