spiegel-keyman/developer/kmdev-server/build.sh
Marc Durdin 44b0335fed feat(developer): Keyman Developer Server
Initial commit for Keyman Developer Server, running on Node.

Supports web debugger only at this point.

Extensive rewrite of web debugger, much of it more modern standards,
significantly improved UX:

1. Drop keyboards, packages, fonts, models onto debug page to load them
2. Websocket for instant reload of recompiled keyboards, packages,
   models.
3. API for interacting with debug server.
4. Cache of recently used items.
5. Integration with ngrok for public access as desired.
6. Tray icon (currently default icon) for control of server.
7. Server can live after TIKE closes, supports multiple TIKE instances.
8. UI of debug host page rewritten with Bootstrap.
9. Packages downloads integrated into main page, and download link for
   Keyman supports all platforms (Linux is just a link to
   instructions...)
10. Avoids file locking and contention by managing all files internally.
11. Not yet tested, but should run cross-platform.
2021-12-21 09:06:16 +11:00

137 lines
3.5 KiB
Bash

#!/bin/bash
#
# Compiles kmdev-server for deployment
#
# 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
pushd "$(dirname "$THIS_SCRIPT")"
# Build the main script.
build () {
npm run build || fail "Could not build top-level JavaScript file."
}
display_usage ( ) {
echo "Usage: $0 [--production|--watch] [--test|--tdd]"
echo " $0 --help"
echo
echo " --help displays this screen and exits"
echo " --production, -p builds production release in build/"
echo " --skip-package-install, -S don't run npm install (not valid with --production)"
echo " --test, -t runs unit tests after building"
#echo " --watch, -w builds dev server in watch mode"
echo " --tdd runs unit tests WITHOUT building"
echo " --no-build-kmw don't build KeymanWeb"
echo " --no-copy-kmw don't copy KeymanWeb"
}
################################ Main script ################################
run_tests=0
production=0
build=1
install_dependencies=1
build_keymanweb=1
copy_keymanweb=1
# Process command-line arguments
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
--help|-h|-?)
display_usage
exit
;;
--production|-p)
production=1
;;
-skip-package-install|-S)
install_dependencies=0
;;
--no-build-kmw)
build_keymanweb=0
;;
--no-copy-kmw)
copy_keymanweb=0
;;
--test)
run_tests=1
;;
--tdd)
run_tests=1
build=0
install_dependencies=0
;;
*)
echo "$0: invalid option: $key"
display_usage
exit $EX_USAGE
esac
shift # past the processed argument
done
# 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
npm install --production=false
# See https://github.com/bubenshchykov/ngrok/issues/254, https://github.com/bubenshchykov/ngrok/pull/255
rm -f node_modules/ngrok/bin/ngrok.exe
fi
# TODO
##if [ -n "$publish_version" ]; then
# set_npm_version "$publish_version" || fail "Setting version failed."
#fi
# TODO: build kmw (unless skipped)
if (( build_keymanweb )); then
pushd "$KEYMAN_ROOT/web/source"
./build.sh -no_minify
popd
fi
if (( copy_keymanweb )); then
SRC="$KEYMAN_ROOT/web/release/unminified"
DST="$(dirname "$THIS_SCRIPT")/src/site/resource"
rm -rf "$DST"
mkdir -p "$DST/osk"
mkdir -p "$DST/ui"
cp "$SRC/web/"*.js "$SRC/web/"*.js.map "$DST/"
cp -R "$SRC/web/osk/"* "$DST/osk/"
cp -R "$SRC/web/ui/"* "$DST/ui/"
cp "$KEYMAN_ROOT/web/LICENSE" "$DST/"
cp "$KEYMAN_ROOT/web/README.md" "$DST/"
fi
npm run build || fail "Compilation failed."
echo "Typescript compilation successful."
if (( run_tests )); then
npm test || fail "Tests failed"
fi
if (( production )) ; then
# We'll build in the build/ folder
rm -rf build/
mkdir build/
cp -R dist/ package.json package-lock.json build/
cd build/
npm install --production
# See https://github.com/bubenshchykov/ngrok/issues/254, https://github.com/bubenshchykov/ngrok/pull/255
rm -f node_modules/ngrok/bin/ngrok.exe
cd ..
fi