-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
build.sh
executable file
·151 lines (131 loc) · 3.86 KB
/
build.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
#
# Compiles the developer tools, including the language model compilers.
#
# Exit on command failure and when using unset variables:
set -eu
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/../../resources/build/build-utils.sh"
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
## END STANDARD BUILD SCRIPT INCLUDE
EX_USAGE=64
# Where to find lexical model types.
LEXICAL_MODELS_TYPES=../../common/models/types
# Build the main script.
build () {
npm run build || fail "Could not build top-level JavaScript file."
}
display_usage ( ) {
echo "Usage: $0 [-test] [-publish-to-npm]"
echo " $0 -help"
echo
echo " -help displays this screen and exits"
echo " -test runs unit tests after building"
echo " -tdd runs unit tests WITHOUT building"
echo " -publish-to-npm publishes the current version to the npm package index"
echo " -dry-run do build, etc, but don't actually publish"
}
################################ Main script ################################
run_tests=0
install_dependencies=1
should_publish=0
npm_dist_tag=
should_dry_run=0
# Process command-line arguments
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-help|-h)
display_usage
exit
;;
-dry-run)
should_dry_run=1
;;
-skip-package-install|-S)
install_dependencies=0
;;
-test)
run_tests=1
;;
-tdd)
run_tests=1
install_dependencies=0
;;
-version)
echo "Warning: -version is now ignored"
;;
-tier)
echo "Warning: -tier is now ignored"
;;
-publish-to-npm)
should_publish=1
;;
*)
echo "$0: invalid option: $key"
display_usage
exit $EX_USAGE
esac
shift # past the processed argument
done
# Dry run settings
if (( should_dry_run )); then
DRY_RUN=--dry-run
else
DRY_RUN=
fi
publish_version=`cat "$KEYMAN_ROOT/VERSION.md"`
publish_tier=`cat "$KEYMAN_ROOT/TIER.md"`
# Validate the publish_version
if [ ! -z "$publish_version" ]; then
# Remove final component if more than 3 components passed
publish_version=` echo "$publish_version" | cut -d "." -f1,2,3 -`
[[ $publish_version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] || fail "-version must be dotted numeric string, e.g. 1.2.3."
fi
if [ -n "$publish_tier" ]; then
# Make sure we're either setting the version or publishing:
if [ -z "$publish_version" ] && (( !should_publish )) ; then
fail "-tier cannot be specified without -version or -publish-to-npm"
fi
case "$publish_tier" in
alpha)
publish_tier=-alpha
npm_dist_tag=alpha
;;
beta)
publish_tier=-beta
npm_dist_tag=beta
;;
stable)
# Stable releases intentionally have a blank publish tier:
publish_tier=
npm_dist_tag=latest
;;
*)
fail "-tier must be one of alpha, beta or stable"
esac
publish_version=$publish_version$publish_tier
fi
# Check if Node.JS/npm is installed.
type npm >/dev/null ||\
fail "Build environment setup error detected! Please ensure Node.js is installed!"
if (( install_dependencies )) ; then
verify_npm_setup
fi
if [ -n "$publish_version" ]; then
set_npm_version "$publish_version" || fail "Setting version failed."
fi
build || fail "Compilation failed."
echo "Typescript compilation successful."
if (( run_tests )); then
npm test || fail "Tests failed"
fi
if (( should_publish )); then
# Note: In either case, npm publish MUST be given --access public to publish
# a package in the @keymanapp scope on the public npm package index.
#
# See `npm help publish` for more details.
npm publish $DRY_RUN --access public --tag "${npm_dist_tag:=latest}" || fail "Could not publish ${npm_dist_tag} release."
fi