Skip to content

Commit

Permalink
Merge pull request #3130 from keymanapp/refactor/web/engine/web-utils…
Browse files Browse the repository at this point in the history
…-package

refactor(web/engine): Moves common utility functions into separate `web-utils` package
  • Loading branch information
jahorton authored May 19, 2020
2 parents 091f606 + e416269 commit 026be0d
Show file tree
Hide file tree
Showing 38 changed files with 198 additions and 34 deletions.
1 change: 1 addition & 0 deletions common/core/web/input-processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@keymanapp/keyboard-processor": "^14.0.77",
"@keymanapp/lexical-model-layer": "^14.0.77",
"@keymanapp/lexical-model-types": "^14.0.77",
"@keymanapp/web-utils": "^14.0.77",
"@types/node": "^11.9.4",
"eventemitter3": "^4.0.0",
"ts-node": "^8.0.2"
Expand Down
1 change: 1 addition & 0 deletions common/core/web/input-processor/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"outFile": "../dist/index.js"
},
"files": [
"../node_modules/@keymanapp/web-utils/src/index.ts",
"../node_modules/@keymanapp/lexical-model-layer/node-defaultWorker.ts",
"text/inputProcessor.ts"
]
Expand Down
1 change: 1 addition & 0 deletions common/core/web/keyboard-processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"mocha": "mocha"
},
"dependencies": {
"@keymanapp/web-utils": "^14.0.77",
"@keymanapp/lexical-model-types": "^14.0.77",
"@types/node": "^11.9.4",
"ts-node": "^8.0.2"
Expand Down
5 changes: 5 additions & 0 deletions common/core/web/keyboard-processor/src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ fi
# Generates a linkable TS file; defined in resources/build-utils.sh.
exportEnvironmentDefinitionTS

pushd ../../utils/src
./build.sh -skip-package-install || fail "Failed to compile Keyman utility function package"
echo ""
popd

# Compile web's `keyboard-processor` module.
npm run tsc -- -p src/tsconfig.json || fail "Failed to compile the core/web/keyboard-processor module."
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
Copyright 2017 SIL International
***/

///<reference path="../utils/version.ts"/>
///<reference path="../utils/deepCopy.ts"/>
// Relies on web-utils for version and deep-copy functionality.

namespace com.keyman.keyboards {
let Codes = com.keyman.text.Codes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Includes KMW string extension declarations.
/// <reference path="kmwstring.ts" />
// Establishes key-code definitions.
/// <reference path="codes.ts" />
// Defines our generalized "KeyEvent" class.
Expand All @@ -14,8 +12,8 @@
/// <reference path="keyMapping.ts" />
// Defines a core-compatible 'Device' analogue for use in keyEvent processing
/// <reference path="engineDeviceSpec.ts" />
// Defines the getGlobalObject() utility method.
/// <reference path="../utils/globalObject.ts" />

// Also relies on @keymanapp/web-utils, which is included via tsconfig.json.

namespace com.keyman.text {
export type BeepHandler = (outputTarget: OutputTarget) => void;
Expand Down
4 changes: 2 additions & 2 deletions common/core/web/keyboard-processor/src/text/outputTarget.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Defines KMW's string extension functions.
///<reference path="../text/kmwstring.ts" />
// Defines deadkey management in a manner attachable to each element interface.
///<reference path="../text/deadkeys.ts" />
// Defines the KeyEvent type.
///<reference path="keyEvent.ts" />

// Also relies on string-extensions provided by the web-utils package.

namespace com.keyman.text {
export class TextTransform implements Transform {
readonly insert: string;
Expand Down
1 change: 1 addition & 0 deletions common/core/web/keyboard-processor/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"files": [
"../node_modules/@keymanapp/lexical-model-types/index.d.ts",
"../node_modules/@keymanapp/web-utils/src/index.ts",
"text/keyboardProcessor.ts"
]
}
1 change: 1 addition & 0 deletions common/core/web/tools/recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"homepage": "https://github.com/keymanapp/keyman#readme",
"dependencies": {
"@keymanapp/keyboard-processor": "^14.0.77",
"@keymanapp/web-utils": "^14.0.77",
"@keymanapp/lexical-model-types": "^14.0.77"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions common/core/web/tools/recorder/src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ PATH="../node_modules/.bin:$PATH"
compiler="npm run tsc --"
compilecmd="$compiler"

pushd ../../../utils/src
./build.sh -skip-package-install

if [ $? -ne 0 ]; then
fail "KeymanWeb utility function library compilation failed."
fi
popd

$compilecmd -p "$SCRIPT_DIR/tsconfig.json"
if [ $? -ne 0 ]; then
fail "KeymanWeb recorder-core compilation failed."
Expand Down
1 change: 0 additions & 1 deletion common/core/web/tools/recorder/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference path="../node_modules/@keymanapp/keyboard-processor/src/text/engineDeviceSpec.ts" />
/// <reference path="../node_modules/@keymanapp/keyboard-processor/src/utils/version.ts" />
/// <reference path="../node_modules/@keymanapp/keyboard-processor/src/text/keyEvent.ts" />
/// <reference path="proctor.ts" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"files": [
"../node_modules/@keymanapp/lexical-model-types/index.d.ts",
"../node_modules/@keymanapp/web-utils/src/index.ts",
"nodeProctor.ts"
]
}
1 change: 1 addition & 0 deletions common/core/web/tools/recorder/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"files": [
"../node_modules/@keymanapp/lexical-model-types/index.d.ts",
"../node_modules/@keymanapp/web-utils/src/index.ts",
"index.ts"
]
}
18 changes: 18 additions & 0 deletions common/core/web/utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Build products
src/environment.inc.ts

# Legacy build folders.
output/
build/
embedded/

# Current build output folder (matches standard node publish location).
dist/

# Other local files.
node_modules/
unit_tests/modernizr.js
source/environment.inc.ts
**/.idea/**/*.xml
**/*.iml
**/*.kpj.user
14 changes: 14 additions & 0 deletions common/core/web/utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions common/core/web/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@keymanapp/web-utils",
"version": "14.0.76",
"description": "Common utility functions used throughout other Keyman packages",
"main": "index.js",
"scripts": {
"tsc": "tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/keymanapp/keyman.git"
},
"author": "SIL International",
"license": "MIT",
"bugs": {
"url": "https://github.com/keymanapp/keyman/issues"
},
"homepage": "https://github.com/keymanapp/keyman#readme",
"devDependencies": {
"typescript": "^3.7.2"
}
}
64 changes: 64 additions & 0 deletions common/core/web/utils/src/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#! /bin/bash
#
# Compiles common TS-based utility functions for use among Keyman's codebase

## 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]}")"
SCRIPT_DIR="$(dirname "$THIS_SCRIPT")"
KEYMAN_ROOT="$(dirname "$THIS_SCRIPT")/../../../../.."
. "$KEYMAN_ROOT/resources/build/build-utils.sh"
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
## END STANDARD BUILD SCRIPT INCLUDE

display_usage ( ) {
echo "build.sh [-skip-dependency-install]"
echo
echo " -skip-dependency-install skips the `lerna bootstrap` dependency check."
echo " (or -S) Intended for use when this script is called by another build script."
echo ""
echo " If more than one target is specified, the last one will take precedence."
exit 1
}

# Establish default build parameters
set_default_vars ( ) {
FETCH_DEPS=true
}

set_default_vars

# Generates a linkable TS file; defined in resources/build-utils.sh.
exportEnvironmentDefinitionTS

# Parse args
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-skip-package-install|-S)
set_default_vars
FETCH_DEPS=false
;;
esac
shift # past argument
done

if [ $FETCH_DEPS = true ]; then
verify_npm_setup
fi

# Definition of global compile constants
OUTPUT_DIR="dist"
OUTPUT="index.js"

# Ensures that we rely first upon the local npm-based install of Typescript.
# (Facilitates automated setup for build agents.)
PATH="../node_modules/.bin:$PATH"

compiler="npm run tsc --"
compilecmd="$compiler"

$compilecmd -p "$SCRIPT_DIR/tsconfig.json"
if [ $? -ne 0 ]; then
fail "Utility-function package compilation failed."
fi
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions common/core/web/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// References all utility includes from a single file, making import/export simple.
///<reference path="deepCopy.ts" />
///<reference path="globalObject.ts" />
///<reference path="version.ts" />
///<reference path="kmwstring.ts" />
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/***
KeymanWeb 11.0
Copyright 2019 SIL International
KeymanWeb 14.0
Copyright 2020 SIL International
***/

/*
* TODO: Remove this file as part of addressing https://github.com/keymanapp/keyman/issues/2492.
*/

interface StringConstructor {
kmwFromCharCode(cp0: number): string,
_kmwFromCharCode(cp0: number): string,
Expand Down
16 changes: 16 additions & 0 deletions common/core/web/utils/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"allowJs": true,
"module": "none",
"outDir": "../dist/",
"inlineSources": true,
"sourceMap": true,
"target": "es5",
"types": ["node"],
"lib": ["es6"],
"outFile": "../dist/index.js"
},
"files": [
"index.ts"
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Defines build-environment variables, as used for versioning.
/// <reference path="../environment.inc.ts" />
/// <reference path="environment.inc.ts" />

// Ensure that this class contains no reference into core KMW code - it is referenced
// by components intended to be modular and possible to separate from core KMW.
Expand Down
3 changes: 3 additions & 0 deletions common/predictive-text/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ done
# Check if Node.JS/npm is installed.
verify_npm_setup $fetch_deps

pushd ../core/web/utils/src
./build.sh -skip-package-install || fail "Utility library package compilation failed."
popd

# Ensure that the build-product destination for any generated include .d.ts files exists.
if ! [ -d $INCLUDES_OUTPUT ]; then
Expand Down
12 changes: 6 additions & 6 deletions common/predictive-text/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions common/predictive-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"homepage": "https://github.com/keymanapp/keyman#readme",
"devDependencies": {
"@types/node": "^10.12.11",
"@types/node": "^10.17.21",
"chai": "^4.2.0",
"karma": "^4.2.0",
"karma-browserstack-launcher": "^1.5.1",
Expand All @@ -41,10 +41,10 @@
"mocha-teamcity-reporter": "^2.5.1",
"sinon": "^7.1.1",
"ts-node": "^7.0.1",
"typescript": "^3.2.1"
"typescript": "^3.7.2"
},
"dependencies": {
"@keymanapp/keyboard-processor": "^14.0.77",
"@keymanapp/web-utils": "^14.0.77",
"@keymanapp/lexical-model-types": "^14.0.77",
"es6-shim": "^0.35.5",
"string.prototype.codepointat": "^0.2.1",
Expand Down
1 change: 0 additions & 1 deletion common/predictive-text/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/

/// <reference path="../message.d.ts" />
/// <reference path="../node_modules/@keymanapp/keyboard-processor/src/text/kmwstring.ts" />
/// <reference path="models/dummy-model.ts" />
/// <reference path="word_breaking/ascii-word-breaker.ts" />
/// <reference path="./model-compositor.ts" />
Expand Down
6 changes: 5 additions & 1 deletion common/predictive-text/worker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
"sourceMap": true,
"lib": ["webworker", "es6"],
"target": "es5"
}
},
"include": [
"../node_modules/@keymanapp/web-utils/src/index.ts",
"./**/*.ts",
]
}
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"common/core/web/input-processor",
"common/core/web/keyboard-processor",
"common/core/web/tools/recorder",
"common/core/web/utils",
"common/lexical-model-types",
"common/predictive-text",
"web"
Expand Down
2 changes: 1 addition & 1 deletion web/bulk_rendering/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"target": "es5"
},
"files": [
"../node_modules/@keymanapp/keyboard-processor/src/utils/version.ts",
"../node_modules/@keymanapp/web-utils/src/index.ts",
"../node_modules/@keymanapp/keyboard-processor/src/text/engineDeviceSpec.ts",
"../node_modules/@keymanapp/lexical-model-layer/message.d.ts",
"renderer_core.ts"
Expand Down
Loading

0 comments on commit 026be0d

Please sign in to comment.