forked from openlayers/openlayers
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublish.sh
executable file
·90 lines (75 loc) · 1.87 KB
/
publish.sh
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
#!/bin/bash
#
# Run this script to publish a new version of the library to npm. This requires
# that you have a clean working directory and have created a tag that matches
# the version number in package.json.
#
set -o errexit
#
# Destination directory for the package.
#
BUILT_PACKAGE=build/ol
#
# URL for canonical repo.
#
REMOTE=https://github.com/openlayers/openlayers.git
#
# Display usage and exit.
#
display_usage() {
cat <<-EOF
Usage: ${1} <version> [options]
To publish a new release, update the version number in package.json and
create a tag for the release.
The tag name must match the version number prefixed by a "v" (for example,
version 3.2.1 would be tagged v3.2.1).
The tag must be pushed to ${REMOTE} before the release can be published.
Additional args after <version> will be passed to "npm publish" (e.g. "--tag beta").
EOF
}
#
# Exit if the current working tree is not clean.
#
assert_clean() {
source `git --exec-path`/git-sh-setup && \
require_clean_work_tree "publish" "Please commit or stash them."
}
#
# Exit if the requested version doesn't match package.json.
#
assert_version_match() {
v=`grep -o '"version":.*' package.json | sed 's/"version": *"\(.*\)",/\1/'`
if test "${1}" != "${v}"; then
echo "Version mismatch: requested '${1}', but package.json specifies '${v}'"
exit 1
fi
}
#
# Check out the provided tag. This ensures that the tag has been pushed to
# the canonical remote.
#
checkout_tag() {
git fetch ${REMOTE} refs/tags/v${1}:refs/tags/v${1}
git checkout refs/tags/v${1}
}
#
# Build the package and publish.
#
main() {
root=$(cd -P -- "$(dirname -- "${0}")" && pwd -P)/..
cd ${root}
assert_clean
checkout_tag ${1}
assert_version_match ${1}
npm install
npm run build-package
cd ${BUILT_PACKAGE}
shift
npm publish ${@}
}
if test ${#} -lt 1; then
display_usage ${0}
exit 1
else
main ${@}
fi