spiegel-keyman/web/common.inc.sh
Marc Durdin fa3980f598 feat(developer): deploy kmc as ES module
Deploy kmc as an ES module, forced now by top-level await that we use in
the sentry load.

Moved NodeCompilerCallbacks to same util folder as schemas are found in,
to avoid rewriting schema loading with imports in this PR. It belongs
better there than messages/ anyway.

Distributed files are now .mjs. Removed --enable-source-maps from
launchers as logging will be managed with sentry anyway.
2023-07-12 10:20:35 +07:00

100 lines
No EOL
2.9 KiB
Bash

#!/usr/bin/env bash
#
# Compiles all build products corresponding to the specified target.
# This should be called from the working directory of a child project's
# build script.
#
# ### Parameters
#
# * 1: `product` the product's source path under src/
#
# ### Example
#
# ```bash
# compile engine/main
# ```
function compile() {
if [ $# -lt 1 ]; then
builder_die "Scripting error: insufficient argument count!"
fi
local COMPILE_TARGET="$1"
local BUNDLE_FLAG="${2:-}"
tsc -b "${KEYMAN_ROOT}/web/src/$COMPILE_TARGET"
if [ -f "./build-bundler.js" ]; then
node "./build-bundler.js" "$BUNDLE_FLAG"
# So... tsc does declaration-bundling on its own pretty well, at least for local development.
tsc --emitDeclarationOnly --outFile "${KEYMAN_ROOT}/web/build/$COMPILE_TARGET/lib/index.d.ts" -p "${KEYMAN_ROOT}/web/src/$COMPILE_TARGET"
fi
}
function _copy_dir_if_exists() {
local SRC=$1
local DST=$2
if [ -d "$SRC" ]; then
cp -rf "$SRC/." "$DST"
fi
}
# Copies top-level build artifacts into common 'debug' and 'release' config folders
# for use in publishing and does a normalization pass on the sourcemaps.
function prepare() {
local CHILD_BUILD_ROOT="$KEYMAN_ROOT/web/build/app"
local PUBLISH_BUILD_ROOT="$KEYMAN_ROOT/web/build/publish"
mkdir -p "$PUBLISH_BUILD_ROOT/debug"
mkdir -p "$PUBLISH_BUILD_ROOT/release"
_copy_dir_if_exists "$CHILD_BUILD_ROOT/browser/debug" "$PUBLISH_BUILD_ROOT/debug"
_copy_dir_if_exists "$CHILD_BUILD_ROOT/browser/release" "$PUBLISH_BUILD_ROOT/release"
_copy_dir_if_exists "$CHILD_BUILD_ROOT/resources" "$PUBLISH_BUILD_ROOT/debug"
_copy_dir_if_exists "$CHILD_BUILD_ROOT/resources" "$PUBLISH_BUILD_ROOT/release"
_copy_dir_if_exists "$CHILD_BUILD_ROOT/ui/debug" "$PUBLISH_BUILD_ROOT/debug"
_copy_dir_if_exists "$CHILD_BUILD_ROOT/ui/release" "$PUBLISH_BUILD_ROOT/release"
# Normalize paths in the sourcemaps
for sourcemap in "$PUBLISH_BUILD_ROOT/debug/"*.map; do
node "$KEYMAN_ROOT/web/build/tools/building/sourcemap-root/index.js" null "$sourcemap" --clean
done
for sourcemap in "$PUBLISH_BUILD_ROOT/release/"*.map; do
node "$KEYMAN_ROOT/web/build/tools/building/sourcemap-root/index.js" null "$sourcemap" --clean
done
}
# Runs all headless tests corresponding to the specified target.
# This should be called from the working directory of a child project's
# build script.
#
# ### Parameters
#
# * 1: `product` the folder under src/test/auto/headless containing the
# child project's tests
#
# ### Example
#
# ```bash
# # from engine/osk
# test-headless osk
# ```
function test-headless() {
TEST_FOLDER=$1
TEST_OPTS=
if builder_has_option --ci; then
TEST_OPTS="--reporter mocha-teamcity-reporter"
fi
if [ -e .c8rc.json ]; then
c8 mocha --recursive "${KEYMAN_ROOT}/web/src/test/auto/headless/$TEST_FOLDER" $TEST_OPTS
else
mocha --recursive "${KEYMAN_ROOT}/web/src/test/auto/headless/$TEST_FOLDER" $TEST_OPTS
fi
}