Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(developer): eliminate source .model_info and .keyboard_info files 🎺 #9535

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions common/web/types/src/kpj/keyman-developer-project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Version 1.0 of Keyman Developer Project .kpj file
// Version 1.0 and 2.0 of Keyman Developer Project .kpj file
//

import { KeymanFileTypes } from '../main.js';
Expand All @@ -9,11 +9,17 @@ export class KeymanDeveloperProject {
options: KeymanDeveloperProjectOptions;
files: KeymanDeveloperProjectFile[];
projectPath: string = '';
readonly projectFile: KeymanDeveloperProjectFile;

constructor(private projectFilename: string, version: KeymanDeveloperProjectVersion, private callbacks: CompilerCallbacks) {
this.projectPath = this.callbacks.path.dirname(this.projectFilename);
get projectFilename() {
return this._projectFilename;
}

constructor(private _projectFilename: string, version: KeymanDeveloperProjectVersion, private callbacks: CompilerCallbacks) {
this.projectPath = this.callbacks.path.dirname(this._projectFilename);
this.options = new KeymanDeveloperProjectOptions(version);
this.files = [];
this.projectFile = new KeymanDeveloperProjectFile20(_projectFilename, callbacks);
}
/**
* Adds .kmn, .xml, .kps to project based on options.sourcePath
Expand All @@ -38,8 +44,6 @@ export class KeymanDeveloperProject {
this.files.push(file);
}
}

this.addMetadataFile();
}

public isKeyboardProject() {
Expand All @@ -50,26 +54,32 @@ export class KeymanDeveloperProject {
return !!this.files.find(file => file.fileType == KeymanFileTypes.Source.Model);
}

public addMetadataFile() {
const ext = this.isLexicalModelProject() ? KeymanFileTypes.Source.ModelInfo : KeymanFileTypes.Source.KeyboardInfo;
private resolveProjectPath(p: string): string {
// Replace placeholders in the target path
return p.replace('$PROJECTPATH', this.projectPath);
}

getOutputFilePath(type: KeymanFileTypes.Binary) {
// Roughly corresponds to Delphi TProject.GetTargetFileName
let p = this.options.version == '1.0' ?
this.options.buildPath || '$SOURCEPATH' :
this.options.buildPath;

if(this.files.find(file => KeymanFileTypes.filenameIs(file.filename, ext))) {
return;
// Replace placeholders in the target path
if(this.options.version == '1.0') {
// TODO: do we need to support $VERSION?
// $SOURCEPATH only supported in 1.0 projects
p = p.replace('$SOURCEPATH', this.callbacks.path.dirname(this._projectFilename));
}

const infoFile =
this.callbacks.path.join(this.projectPath,
this.callbacks.path.basename(this.projectFilename, KeymanFileTypes.Source.Project) + ext);
this.files.push(new KeymanDeveloperProjectFile20(infoFile, this.callbacks));
}
p = this.resolveProjectPath(p);

private resolveProjectPath(p: string): string {
// Replace placeholders in the target path
return p.replace('$PROJECTPATH', this.projectPath);
const f = this.callbacks.path.basename(this._projectFilename, KeymanFileTypes.Source.Project) + type;
return this.callbacks.path.normalize(this.callbacks.path.join(p, f));
}

resolveInputFilePath(file: KeymanDeveloperProjectFile): string {
return this.callbacks.resolveFilename(this.projectFilename, file.filePath);
return this.callbacks.resolveFilename(this._projectFilename, file.filePath);
}

resolveOutputFilePath(file: KeymanDeveloperProjectFile, sourceExt: string, targetExt: string): string {
Expand Down
1 change: 0 additions & 1 deletion common/web/types/src/kpj/kpj-file-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class KPJFileReader {

if(result.options.version == '1.0') {
this.transformFilesVersion10(project, result);
result.addMetadataFile();
} else {
result.populateFiles();
}
Expand Down
18 changes: 2 additions & 16 deletions common/web/types/src/util/file-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export const enum Source {
LdmlKeyboard = '.xml', // Warning, also other possible uses
Package = '.kps',
VisualKeyboard = '.kvks',
TouchLayout = '.keyman-touch-layout',
KeyboardInfo = '.keyboard_info',
ModelInfo = '.model_info',
TouchLayout = '.keyman-touch-layout'
};

/**
Expand All @@ -26,9 +24,7 @@ export const ALL_SOURCE: ReadonlyArray<Source> = [
Source.LdmlKeyboard,
Source.Package,
Source.VisualKeyboard,
Source.TouchLayout,
Source.KeyboardInfo,
Source.ModelInfo,
Source.TouchLayout
] as const;

/**
Expand Down Expand Up @@ -146,16 +142,6 @@ export function filenameIs(filename: string, fileType: Source | Binary) {
return filename.toLowerCase().endsWith(fileType);
}

/**
* Returns true if the file is either a .keyboard_info file or a .model_info
* file
* @param filename
* @returns
*/
export function filenameIsMetadata(filename: string) {
return filenameIs(filename, Source.KeyboardInfo) || filenameIs(filename, Source.ModelInfo);
}

/**
* Replaces a filename extension with the new extension. Returns `null` if the
* filename does not end with oldExtension.
Expand Down
4 changes: 2 additions & 2 deletions common/web/types/test/kpj/test-kpj-file-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('kpj-file-reader', function () {
assert.equal(kpj.KeymanDeveloperProject.Options.CompilerWarningsAsErrors, 'True');
assert.equal(kpj.KeymanDeveloperProject.Options.ProjectType, 'keyboard');
assert.equal(kpj.KeymanDeveloperProject.Options.WarnDeprecatedCode, 'True');
assert.equal(kpj.KeymanDeveloperProject.Options.SkipMetadataFiles, 'True'); // because this is a 1.0 version file
assert.isUndefined(kpj.KeymanDeveloperProject.Options.SkipMetadataFiles); // because this is a 1.0 version file
assert.isUndefined(kpj.KeymanDeveloperProject.Options.Version);

assert.lengthOf(kpj.KeymanDeveloperProject.Files.File, 21);
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('kpj-file-reader', function () {
assert.isTrue(project.options.skipMetadataFiles);
assert.equal(project.options.version, '1.0');

assert.lengthOf(project.files, 3);
assert.lengthOf(project.files, 2);

let f: KeymanDeveloperProjectFile10 = <KeymanDeveloperProjectFile10>project.files[0];
assert.equal(f.id, 'id_f347675c33d2e6b1c705c787fad4941a');
Expand Down
1 change: 1 addition & 0 deletions developer/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ builder_describe \
configure \
build \
test \
":utils=src/common/web/utils Developer utils" \
":kmcmplib=src/kmcmplib Compiler - .kmn compiler" \
":kmc-analyze=src/kmc-analyze Compiler - Analysis Tools" \
":kmc-keyboard-info=src/kmc-keyboard-info Compiler - .keyboard_info Module" \
Expand Down
39 changes: 24 additions & 15 deletions developer/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,40 @@ details.

## src/kmc

node-based next generation compiler, hosts kmc, kmlmi, kmlmc, kmlmp
node-based next generation compiler, hosts kmc, (and legacy kmlmc, kmlmp)

### src/kmc-analyze - Analysis tools

File analysis tools for Keyman files.

### src/kmc-keyboard-info - Keyboard Info Compiler

Builds .keyboard_info files for use on the Keyman Cloud keyboard repository
at https://github.com/keymanapp/keyboards. Command line access through kmc.

### src/kmc-kmn - Keyboard Compiler

Builds .kmx files from .kmn. Command line access through kmc.

### src/kmc-ldml - LDML Keyboard Compiler

Next Generation keyboard compiler package - LDML keyboards only at present.
Command line access through kmc.
Next Generation keyboard compiler - LDML keyboards. Command line access through
kmc.

### src/kmc-model - Lexical Model Compiler

The Lexical Model Compiler, kmlmc, runs on nodeJS on all supported desktop
platforms. Command line access through kmc/kmlmc.
The Lexical Model Compiler, runs on nodeJS on all supported desktop platforms.
Command line access through kmc.

### src/kmc-package - Package Compiler
### src/kmc-model-info - Model Info Compiler

The package compiler is broadly compatible with the kmcomp .kps package
compiler. However at this stage it is only tested with lexical models, and use
with keyboards (either .js or .kmx) is not tested or supported. It is likely in
the future that the kmcomp .kps compiler will be deprecated in favour of this
one. Command line access through kmc/kmlmp.
Builds .model_info files for use on the Keyman Cloud lexical model repository at
https://github.com/keymanapp/lexical-models. Command line access through kmc.

### src/kmc-model-info - Model Info Compiler
### src/kmc-package - Package Compiler

Merges .model_info files for use on the Keyman Cloud lexical model repository at
https://github.com/keymanapp/lexical-models. Command line access through
kmc/kmlmi.
Compiles .kps packages into .kmp files. Works with both lexical model packages
and keyboard packages. Command line access through kmc.

## src/samples

Expand Down
1 change: 1 addition & 0 deletions developer/src/common/web/utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
36 changes: 36 additions & 0 deletions developer/src/common/web/utils/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
## 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

cd "$THIS_SCRIPT_PATH"

. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"

builder_describe "Build Keyman Developer web utility module" \
"@/common/web/types" \
"clean" \
"configure" \
"build" \
"test"

builder_describe_outputs \
configure /node_modules \
build /developer/src/common/web/utils/build/index.js

builder_parse "$@"

#-------------------------------------------------------------------------------------------------------------------

builder_run_action clean rm -rf ./build/
builder_run_action configure verify_npm_setup
builder_run_action build tsc --build

if builder_start_action test; then
eslint .
tsc --build test
c8 --reporter=lcov --reporter=text --exclude-after-remap mocha
builder_finish_action success test
fi
1 change: 1 addition & 0 deletions developer/src/common/web/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { validateMITLicense } from './src/validate-mit-license.js';
32 changes: 32 additions & 0 deletions developer/src/common/web/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@keymanapp/developer-utils",
"description": "Keyman Developer utilities",
"type": "module",
"exports": {
".": "./build/index.js"
},
"files": [
"/build/"
],
"devDependencies": {
"@types/node": "^20.4.1",
"ts-node": "^9.1.1",
"typescript": "^4.9.5",
"c8": "^7.12.0",
"chai": "^4.3.4",
"mocha": "^8.4.0"
},
"scripts": {
"build": "tsc -b"
},
"license": "MIT",
"dependencies": {
"@keymanapp/common-types": "*"
},
"mocha": {
"spec": "build/test/**/test-*.js",
"require": [
"source-map-support/register"
]
}
}
18 changes: 18 additions & 0 deletions developer/src/common/web/utils/test/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Helpers and utilities for the Mocha tests.
*/
import * as path from 'path';
import { fileURLToPath } from 'url';

/**
* Builds a path to the fixture with the given path components.
*
* e.g., makePathToFixture('example.qaa.trivial')
* e.g., makePathToFixture('example.qaa.trivial', 'model.ts')
*
* @param components One or more path components.
*/
export function makePathToFixture(...components: string[]): string {
return fileURLToPath(new URL(path.join('..', '..', '..', 'test', 'fixtures', ...components), import.meta.url));
}

24 changes: 24 additions & 0 deletions developer/src/common/web/utils/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "../../../../kmc/tsconfig.kmc-base.json",

"compilerOptions": {
"rootDir": ".",
"rootDirs": ["./", "../src/"],
"outDir": "../build/test",
"esModuleInterop": true,
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"@keymanapp/developer-test-helpers": ["../../test-helpers/index"],
},
},
"include": [
"**/test-*.ts",
"helpers/*.ts",
],
"references": [
{ "path": "../" },
{ "path": "../../test-helpers/" },
]
}
18 changes: 18 additions & 0 deletions developer/src/common/web/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../../../../tsconfig.esm-base.json",

"compilerOptions": {
"rootDir": ".",
"outDir": "./build/",
"baseUrl": ".",
"paths": {
"@keymanapp/common-types": ["../../../../../common/web/types/src/main"],
},
},
"include": [
"./*.ts", "src/validate-mit-license.ts",
],
"references": [
{ "path": "../../../../../common/web/types/" },
]
}
4 changes: 0 additions & 4 deletions developer/src/inst/kmdev.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,6 @@
<File Name='kmlmc.cmd' KeyPath="yes" Source="node\kmlmc.cmd" />
</Component>

<Component Directory="INSTALLDIR">
<File Name='kmlmi.cmd' KeyPath="yes" Source="node\kmlmi.cmd" />
</Component>

<Component Directory="INSTALLDIR">
<File Name='kmlmp.cmd' KeyPath="yes" Source="node\kmlmp.cmd" />
</Component>
Expand Down
4 changes: 0 additions & 4 deletions developer/src/inst/node/kmlmi.cmd

This file was deleted.

3 changes: 2 additions & 1 deletion developer/src/kmc-keyboard-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"dependencies": {
"@keymanapp/common-types": "*",
"@keymanapp/kmc-package": "*"
"@keymanapp/kmc-package": "*",
"@keymanapp/developer-utils": "*"
},
"devDependencies": {
"@types/chai": "^4.3.5",
Expand Down
Loading