diff --git a/web/samples/uncompiled.html b/web/samples/uncompiled.html
index 1797823c18..6e370f3b47 100644
--- a/web/samples/uncompiled.html
+++ b/web/samples/uncompiled.html
@@ -23,15 +23,7 @@
-
-
-
-
-
-
-
-
-
+
-
+
diff --git a/web/source/build.bat b/web/source/build.bat
index d3c6bbdf9c..5e31ad4bd2 100644
--- a/web/source/build.bat
+++ b/web/source/build.bat
@@ -98,21 +98,58 @@ rem Credit to https://stackoverflow.com/questions/23075953/batch-script-to-find-
rem It's not the most efficient thing ever, but it gets the job done. The shell script's version is WAY faster due to available tools.
:replace_in_file
@echo off
- setlocal enableextensions disabledelayedexpansion
+ setlocal enableextensions disabledelayedexpansion
- set "search=%1"
- set "replace=%2"
+ set "search=%1"
+ set "replace=%2"
- set "textFile=%3"
+ set "textFile=%3"
- for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
- set "line=%%i"
- setlocal enabledelayedexpansion
- >>"%textFile%" echo(!line:%search%=%replace%!
- endlocal
- )
+ for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
+ set "line=%%i"
+ setlocal enabledelayedexpansion
+ >>"%textFile%" echo(!line:%search%=%replace%!
+ endlocal
+ )
- EXIT /B 0
+ EXIT /B 0
+
+:copy_resources
+ echo
+ echo Copy resources to %1/ui, .../osk
+
+ rem Create our entire compilation results path. Can't one-line them due to shell-script parsing errors.
+
+ rem Extended mkdir functionality - can recursively create directories as long as command extensions are enabled.
+ rem They usually are, but... just in case.
+
+ @echo off
+ setlocal enableextensions
+ if not exist %1 mkdir %1
+ if not exist %1\ui mkdir %1\ui
+ if not exist %1\osk mkdir %1\osk
+ if not exist %1\src mkdir %1\src
+ if not exist %1\src\ui mkdir %1\src\ui
+ if not exist %1\src\osk mkdir %1\src\osk
+ endlocal
+
+ echo Copy resources to %1\ui, ...\osk
+ xcopy %SOURCE%\resources\ui\* %1\ui /E /Y >nul
+ xcopy %SOURCE%\resources\osk\* %1\osk /E /Y >nul
+
+ echo Copy source to %1/src
+ xcopy %SOURCE%\*.js %1\src /Y
+ xcopy %SOURCE%\*.ts %1\src /Y
+ echo %BUILD% > %1\src\version.txt
+
+ xcopy %SOURCE%\resources\ui\* %1\src\ui /E /Y >nul
+ xcopy %SOURCE%\resources\osk\* %1\src\osk /E /Y >nul
+
+ rem Update build number if successful
+ echo
+ echo KeymanWeb resources saved under %1
+ echo
+ EXIT /B 0
:main
@@ -145,6 +182,8 @@ endlocal
del %EMBED_OUTPUT%\keyman.js 2>nul
CALL %compilecmd% -p %NODE_SOURCE%\tsconfig.embedded.json
+echo Typescript compiled.
+
CALL :minify "keyman.js" %EMBED_OUTPUT% SIMPLE_OPTIMIZATIONS "keyman.__BUILD__=%BUILD%"
if not exist %EMBED_OUTPUT%\keyman.js goto fail
@@ -164,23 +203,16 @@ if "%1" == "-embed" goto done
:web
-rem Extended mkdir functionality - can recursively create directories as long as command extensions are enabled.
-rem They usually are, but... just in case.
-@echo off
-setlocal enableextensions
-if not exist %WEB_OUTPUT% mkdir %WEB_OUTPUT%
-if not exist %WEB_OUTPUT%\ui mkdir %WEB_OUTPUT%\ui
-if not exist %WEB_OUTPUT%\osk mkdir %WEB_OUTPUT%\osk
-if not exist %WEB_OUTPUT%\src mkdir %WEB_OUTPUT%\src
-if not exist %WEB_OUTPUT%\src\ui mkdir %WEB_OUTPUT%\src\ui
-if not exist %WEB_OUTPUT%\src\osk mkdir %WEB_OUTPUT%\src\osk
-endlocal
-
rem Compile KeymanWeb code modules for native keymanweb use, stubbing out and removing references to debug functions
-echo Compile Keymanweb
+echo Compile Keymanweb...
del %WEB_OUTPUT%\keymanweb.js 2>nul
CALL %compilecmd% -p %NODE_SOURCE%\tsconfig.web.json || true
+echo Typescript compiled.
+
+call :copy_resources %INTERMEDIATE%
+
+echo Minifying KeymanWeb...
CALL :minify "keymanweb.js" %WEB_OUTPUT% SIMPLE_OPTIMIZATIONS "keyman.__BUILD__=%BUILD%"
if not exist %WEB_OUTPUT%\keymanweb.js goto fail
@@ -188,16 +220,7 @@ if "%1" == "-test" goto done
rem Update any changed resources
-echo Copy resources to %WEB_OUTPUT%\ui, ...\osk
-xcopy %SOURCE%\resources\ui\* %WEB_OUTPUT%\ui /E /Y >nul
-xcopy %SOURCE%\resources\osk\* %WEB_OUTPUT%\osk /E /Y >nul
-
-echo Copy source to %WEB_OUTPUT%\src
-xcopy %SOURCE%\*.js %WEB_OUTPUT%\src /Y
-xcopy %SOURCE%\*.ts %WEB_OUTPUT%\src /Y
-echo %BUILD% > %WEB_OUTPUT%\src\version.txt
-xcopy %SOURCE%\resources\ui\* %WEB_OUTPUT%\src\ui /E /Y >nul
-xcopy %SOURCE%\resources\osk\* %WEB_OUTPUT%\src\osk /E /Y >nul
+call :copy_resources %WEB_OUTPUT%
rem Update build number if successful
echo.
@@ -210,24 +233,25 @@ rem Compile UI code modules (TODO: add date testing, only recompile if needed)
:ui
+echo Compile UI Modules...
CALL %compilecmd% -p %NODE_SOURCE%\tsconfig.ui.json
-echo Compile ToolBar UI
+echo Minify ToolBar UI
del %WEB_OUTPUT%\kmuitoolbar.js 2>nul
CALL :minify "kmwuitoolbar.js" %WEB_OUTPUT% ADVANCED_OPTIMIZATIONS "" "(function() {%%%%output%%%%}());"
if not exist %WEB_OUTPUT%\kmwuitoolbar.js goto fail
-echo Compile Toggle UI
+echo Minify Toggle UI
del %WEB_OUTPUT%\kmuitoggle.js 2>nul
CALL :minify "kmwuitoggle.js" %WEB_OUTPUT% SIMPLE_OPTIMIZATIONS "" "(function() {%%%%output%%%%}());"
if not exist %WEB_OUTPUT%\kmwuitoggle.js goto fail
-echo Compile Float UI
+echo Minify Float UI
del %WEB_OUTPUT%\kmuifloat.js 2>nul
CALL :minify "kmwuifloat.js" %WEB_OUTPUT% ADVANCED_OPTIMIZATIONS "" "(function() {%%%%output%%%%}());"
if not exist %WEB_OUTPUT%\kmwuifloat.js goto fail
-echo Compile Button UI
+echo Minify Button UI
del %WEB_OUTPUT%\kmuibutton.js 2>nul
CALL :minify "kmwuibutton.js" %WEB_OUTPUT% ADVANCED_OPTIMIZATIONS "" "(function() {%%%%output%%%%}());"
if not exist %WEB_OUTPUT%\kmwuibutton.js goto fail
diff --git a/web/source/build.sh b/web/source/build.sh
index 6b2e76759f..84b54cc666 100755
--- a/web/source/build.sh
+++ b/web/source/build.sh
@@ -33,8 +33,10 @@ npm install
: ${JAVA:=java}
minifier="$CLOSURECOMPILERPATH/compiler.jar"
+# We'd love to add the argument --source_map_include_content for distribution in the future,
+# but Closure doesn't include the TS sources properly at this time.
minifier_warnings="--jscomp_error=* --jscomp_off=lintChecks --jscomp_off=unusedLocalVariables"
-minifycmd="$JAVA -jar $minifier $minifier_warnings"
+minifycmd="$JAVA -jar $minifier $minifier_warnings --generate_exports"
if ! [ -f $minifier ];
then
@@ -69,6 +71,41 @@ minify ( ) {
//# sourceMappingURL=$1.map"
}
+copy_resources ( ) {
+ echo
+ echo Copy resources to $1/ui, .../osk
+
+ # Create our entire compilation results path. Can't one-line them due to shell-script parsing errors.
+ if ! [ -d $1/ui ]; then
+ mkdir -p "$1/ui"
+ fi
+ if ! [ -d $1/osk ]; then
+ mkdir -p "$1/osk"
+ fi
+ if ! [ -d $1/src/ui ]; then
+ mkdir -p "$1/src/ui"
+ fi
+ if ! [ -d $1/src/osk ]; then
+ mkdir -p "$1/src/osk"
+ fi
+
+ cp -Rf $SOURCE/resources/ui $1/ >/dev/null
+ cp -Rf $SOURCE/resources/osk $1/ >/dev/null
+
+ echo Copy source to $1/src
+ cp -Rf $SOURCE/*.js $1/src
+ cp -Rf $SOURCE/*.ts $1/src
+ echo $BUILD > $1/src/version.txt
+
+ cp -Rf $SOURCE/resources/ui $1/src/ >/dev/null
+ cp -Rf $SOURCE/resources/osk $1/src/ >/dev/null
+
+ # Update build number if successful
+ echo
+ echo KeymanWeb resources saved under $1
+ echo
+}
+
if [ $? -ne 0 ]; then
fail "Build environment setup error detected! Please ensure Node.js is installed!"
fi
@@ -170,6 +207,8 @@ if [ $BUILD_EMBED = true ]; then
rm $EMBED_OUTPUT/keyman.js 2>/dev/null
$compilecmd -p $NODE_SOURCE/tsconfig.embedded.json
+ echo Typescript compiled.
+
minify keyman.js $EMBED_OUTPUT SIMPLE_OPTIMIZATIONS "keyman.__BUILD__=$BUILD"
assert $EMBED_OUTPUT/keyman.js
@@ -188,24 +227,15 @@ if [ $BUILD_EMBED = true ]; then
fi
if [ $BUILD_COREWEB = true ]; then
- # Create our entire compilation results path. Can't one-line them due to shell-script parsing errors.
- if ! [ -d $WEB_OUTPUT/ui ]; then
- mkdir -p "$WEB_OUTPUT/ui"
- fi
- if ! [ -d $WEB_OUTPUT/osk ]; then
- mkdir -p "$WEB_OUTPUT/osk"
- fi
- if ! [ -d $WEB_OUTPUT/src/ui ]; then
- mkdir -p "$WEB_OUTPUT/src/ui"
- fi
- if ! [ -d $WEB_OUTPUT/src/osk ]; then
- mkdir -p "$WEB_OUTPUT/src/osk"
- fi
-
# Compile KeymanWeb code modules for native keymanweb use, stubbing out and removing references to debug functions
- echo Compile Keymanweb
+ echo Compile Keymanweb...
rm $WEB_OUTPUT/keymanweb.js 2>/dev/null
$compilecmd -p $NODE_SOURCE/tsconfig.web.json
+ echo Typescript compiled.
+
+ copy_resources "$INTERMEDIATE"
+
+ echo Minifying KeymanWeb...
minify keymanweb.js $WEB_OUTPUT SIMPLE_OPTIMIZATIONS "keyman.__BUILD__=$BUILD"
assert $WEB_OUTPUT/keymanweb.js
@@ -213,20 +243,7 @@ if [ $BUILD_COREWEB = true ]; then
fi
if [ $BUILD_FULLWEB = true ]; then
- echo
- echo Copy resources to $WEB_OUTPUT/ui, .../osk
-
- cp -Rf $SOURCE/resources/ui $WEB_OUTPUT/ >/dev/null
- cp -Rf $SOURCE/resources/osk $WEB_OUTPUT/ >/dev/null
-
- echo Copy source to $WEB_OUTPUT/src
- cp -Rf $SOURCE/*.js $WEB_OUTPUT/src
- cp -Rf $SOURCE/*.ts $WEB_OUTPUT/src
- echo $BUILD > $WEB_OUTPUT/src/version.txt
-
- cp -Rf $SOURCE/resources/ui $WEB_OUTPUT/src/ >/dev/null
- cp -Rf $SOURCE/resources/osk $WEB_OUTPUT/src/ >/dev/null
-
+ copy_resources "$WEB_OUTPUT"
# Update build number if successful
echo
echo KeymanWeb 2 build $BUILD compiled and saved under $WEB_OUTPUT
@@ -234,7 +251,7 @@ if [ $BUILD_FULLWEB = true ]; then
fi
if [ $BUILD_UI = true ]; then
- echo Compile UI Modules
+ echo Compile UI Modules...
$compilecmd -p $NODE_SOURCE/tsconfig.ui.json
echo Minify ToolBar UI