UNPKG

2.22 kBapplication/x-shView Raw
1#!/bin/bash
2
3#
4# Run this script to publish a new version of the library to npm. This requires
5# that you have a clean working directory and have created a tag that matches
6# the version number in package.json.
7#
8set -o errexit
9
10#
11# All profiles to be built. Must correspond to .json files in the config
12# directory.
13#
14PROFILES="ol ol-debug"
15
16#
17# Destination directory for builds.
18#
19BUILDS=dist
20
21#
22# URL for canonical repo.
23#
24REMOTE=https://github.com/openlayers/openlayers.git
25
26#
27# Display usage and exit.
28#
29display_usage() {
30 cat <<-EOF
31
32 Usage: ${1} <version>
33
34 To publish a new release, update the version number in package.json and
35 create a tag for the release.
36
37 The tag name must match the version number prefixed by a "v" (for example,
38 version 3.2.1 would be tagged v3.2.1).
39
40 The tag must be pushed to ${REMOTE} before the release can be published.
41
42EOF
43}
44
45#
46# Exit if the current working tree is not clean.
47#
48assert_clean() {
49 source `git --exec-path`/git-sh-setup && \
50 require_clean_work_tree "publish" "Please commit or stash them."
51}
52
53#
54# Exit if the requested version doesn't match package.json.
55#
56assert_version_match() {
57 v=`grep -o '"version":.*' package.json | sed 's/"version": *"\(.*\)",/\1/'`
58 if test "${1}" != "${v}"; then
59 echo "Version mismatch: requested '${1}', but package.json specifies '${v}'"
60 exit 1
61 fi
62}
63
64#
65# Build all of the distribution profiles.
66#
67build_js() {
68 for p in ${@}; do
69 echo building ${BUILDS}/${p}.js
70 node ./tasks/build.js config/${p}.json ${BUILDS}/${p}.js
71 done
72}
73
74build_css() {
75 ./node_modules/.bin/cleancss css/ol.css -o ${BUILDS}/ol.css
76 cp css/ol.css ${BUILDS}/ol-debug.css
77}
78
79#
80# Check out the provided tag. This ensures that the tag has been pushed to
81# the canonical remote.
82#
83checkout_tag() {
84 git fetch ${REMOTE} refs/tags/v${1}:refs/tags/v${1}
85 git checkout refs/tags/v${1}
86}
87
88#
89# Build all profiles and publish.
90#
91main() {
92 root=$(cd -P -- "$(dirname -- "${0}")" && pwd -P)/..
93 cd ${root}
94 assert_clean
95 checkout_tag ${1}
96 assert_version_match ${1}
97 rm -rf ${BUILDS}
98 npm install
99 build_js ${PROFILES}
100 build_css
101 npm publish
102}
103
104if test ${#} -ne 1; then
105 display_usage ${0}
106 exit 1
107else
108 main ${1}
109fi