-
Notifications
You must be signed in to change notification settings - Fork 31
/
convert.sh
executable file
·28 lines (21 loc) · 1.19 KB
/
convert.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
#!/usr/bin/env bash
# set -x # verbose debugging
IN_FILE='index.js'
OUT_FILE='index-compat.js'
BABEL_PATH='./node_modules/babel-cli/bin/babel.js'
# Get script location, resolve if a link.
export SCRIPT_ROOT_ENV_SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SCRIPT_ROOT_ENV_SOURCE" ]; do
export SCRIPT_ROOT_DIR="$( cd -P "$( dirname "$SCRIPT_ROOT_ENV_SOURCE" )" && pwd )"
export SCRIPT_ROOT_ENV_SOURCE="$(readlink "$SCRIPT_ROOT_ENV_SOURCE")"
[[ ${SCRIPT_ROOT_ENV_SOURCE} != /* ]] && SCRIPT_ROOT_ENV_SOURCE="$SCRIPT_ROOT_DIR/$SCRIPT_ROOT_ENV_SOURCE"
done
export SCRIPT_ROOT_DIR="$( cd -P "$( dirname "$SCRIPT_ROOT_ENV_SOURCE" )" && pwd )"
pushd "$SCRIPT_ROOT_DIR" || { echo 'Could not enter primary directory.' ; exit 1; }
if [ ! -f "$BABEL_PATH" ]; then
npm i || { echo 'NPM Installation Failed.' ; exit 1; }
fi
echo "/* The following JavaScript file was preprocessed from $IN_FILE via Babel for support on older Node installations. */" > "$OUT_FILE.tmp"
"$BABEL_PATH" "$IN_FILE" --presets es2017,es2016,es2015 | sed '1d' >> "$OUT_FILE.tmp" || { echo 'Babel Processing Failed.' ; rm "$OUT_FILE.tmp"; exit 1; }
mv "$OUT_FILE.tmp" "$OUT_FILE"
popd || { echo 'Could not return from primary directory.' ; exit 1; }