mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-13 12:19:25 +00:00
Improves build script performance by: * using built-ins wherever possible (e.g. string splitting) * eliminating redundant code * using absolute (to $KEYMAN_ROOT) rather than relative paths to avoid realpath * removing unnecessary `npm run` calls BEFORE | AFTER -------------------------------|---------------------- time ./core/build.sh --help | real 0m2.116s | real 0m0.874s user 0m0.578s | user 0m0.198s sys 0m0.984s | sys 0m0.289s -------------------------------|---------------------- time ./web/build.sh --help | real 0m3.523s | real 0m0.757s user 0m1.166s | user 0m0.320s sys 0m2.273s | sys 0m0.455s -------------------------------|---------------------- time ./web/build.sh -d | real 1m34.750s | real 0m59.974s user 0m9.721s | user 0m6.284s sys 0m19.652s | sys 0m13.202s @keymanapp-test-bot skip
101 lines
2.8 KiB
Bash
Executable file
101 lines
2.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# Compiles the Language Modeling Layer for common use in predictive text and autocorrective applications.
|
|
# Designed for optimal compatibility with the Keyman Suite.
|
|
#
|
|
|
|
# Exit on command failure and when using unset variables:
|
|
set -eu
|
|
|
|
# Include some helper functions from resources
|
|
|
|
## START STANDARD BUILD SCRIPT INCLUDE
|
|
# adjust relative paths as necessary
|
|
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
|
|
. "${THIS_SCRIPT%/*}/../../resources/build/build-utils.sh"
|
|
## END STANDARD BUILD SCRIPT INCLUDE
|
|
|
|
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
|
|
|
|
# This script runs from its own folder
|
|
cd "$(dirname "$THIS_SCRIPT")"
|
|
|
|
################################ Main script ################################
|
|
|
|
# TODO: once these modules are builder-based, reference here too:
|
|
# "@../models/templates" \
|
|
# "@../models/types" \
|
|
# "@../models/wordbreakers"
|
|
|
|
builder_describe "Builds the lm-layer module" \
|
|
"@/common/web/keyman-version" \
|
|
"@/common/web/lm-worker" \
|
|
"clean" \
|
|
"configure" \
|
|
"build" \
|
|
"test" \
|
|
":headless A headless, Node-oriented version of the module useful for unit tests" \
|
|
":browser The standard version of the module for in-browser use" \
|
|
"--ci Sets $(builder_term test) action to use CI-based test configurations & reporting"
|
|
|
|
builder_describe_outputs \
|
|
configure /node_modules \
|
|
configure:headless /node_modules \
|
|
configure:browser /node_modules \
|
|
build:headless /common/predictive-text/build/headless.js \
|
|
build:browser /common/predictive-text/build/index.js
|
|
|
|
builder_parse "$@"
|
|
|
|
### CONFIGURE ACTIONS
|
|
|
|
if builder_start_action configure; then
|
|
verify_npm_setup
|
|
builder_finish_action success configure
|
|
fi
|
|
|
|
### CLEAN ACTIONS
|
|
|
|
if builder_start_action clean; then
|
|
rm -rf build/
|
|
builder_finish_action success clean
|
|
fi
|
|
|
|
### BUILD ACTIONS
|
|
|
|
# Builds the top-level JavaScript file for use in browsers
|
|
if builder_start_action build:browser; then
|
|
npm run tsc -- -b ./browser.tsconfig.json
|
|
|
|
builder_finish_action success build:browser
|
|
fi
|
|
|
|
# Builds the top-level JavaScript file for use on Node
|
|
if builder_start_action build:headless; then
|
|
npm run tsc -- -b ./tsconfig.json
|
|
|
|
builder_finish_action success build:headless
|
|
fi
|
|
|
|
### TEST ACTIONS
|
|
# Note - the actual test setup is done in a separate test script, but it's easy
|
|
# enough to route the calls through.
|
|
|
|
TEST_OPTIONS=
|
|
if builder_has_option --ci; then
|
|
TEST_OPTIONS=--ci
|
|
fi
|
|
|
|
if builder_start_action test:headless; then
|
|
# We'll test the included libraries here for now, at least until we have
|
|
# converted their builds to builder scripts
|
|
./unit_tests/test.sh test:libraries test:headless $TEST_OPTIONS
|
|
|
|
builder_finish_action success test:headless
|
|
fi
|
|
|
|
if builder_start_action test:browser; then
|
|
./unit_tests/test.sh test:browser $TEST_OPTIONS
|
|
|
|
builder_finish_action success test:browser
|
|
fi
|