Skip to content

Commit 65d95d3

Browse files
authored
Merge pull request #9535 from keymanapp/feat/developer/eliminate-source-info-files
feat(developer): eliminate source .model_info and .keyboard_info files 🎺
2 parents 640f04c + a0bdb61 commit 65d95d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+705
-407
lines changed

common/web/types/src/kpj/keyman-developer-project.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Version 1.0 of Keyman Developer Project .kpj file
2+
// Version 1.0 and 2.0 of Keyman Developer Project .kpj file
33
//
44

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

13-
constructor(private projectFilename: string, version: KeymanDeveloperProjectVersion, private callbacks: CompilerCallbacks) {
14-
this.projectPath = this.callbacks.path.dirname(this.projectFilename);
14+
get projectFilename() {
15+
return this._projectFilename;
16+
}
17+
18+
constructor(private _projectFilename: string, version: KeymanDeveloperProjectVersion, private callbacks: CompilerCallbacks) {
19+
this.projectPath = this.callbacks.path.dirname(this._projectFilename);
1520
this.options = new KeymanDeveloperProjectOptions(version);
1621
this.files = [];
22+
this.projectFile = new KeymanDeveloperProjectFile20(_projectFilename, callbacks);
1723
}
1824
/**
1925
* Adds .kmn, .xml, .kps to project based on options.sourcePath
@@ -38,8 +44,6 @@ export class KeymanDeveloperProject {
3844
this.files.push(file);
3945
}
4046
}
41-
42-
this.addMetadataFile();
4347
}
4448

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

53-
public addMetadataFile() {
54-
const ext = this.isLexicalModelProject() ? KeymanFileTypes.Source.ModelInfo : KeymanFileTypes.Source.KeyboardInfo;
57+
private resolveProjectPath(p: string): string {
58+
// Replace placeholders in the target path
59+
return p.replace('$PROJECTPATH', this.projectPath);
60+
}
61+
62+
getOutputFilePath(type: KeymanFileTypes.Binary) {
63+
// Roughly corresponds to Delphi TProject.GetTargetFileName
64+
let p = this.options.version == '1.0' ?
65+
this.options.buildPath || '$SOURCEPATH' :
66+
this.options.buildPath;
5567

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

60-
const infoFile =
61-
this.callbacks.path.join(this.projectPath,
62-
this.callbacks.path.basename(this.projectFilename, KeymanFileTypes.Source.Project) + ext);
63-
this.files.push(new KeymanDeveloperProjectFile20(infoFile, this.callbacks));
64-
}
75+
p = this.resolveProjectPath(p);
6576

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

7181
resolveInputFilePath(file: KeymanDeveloperProjectFile): string {
72-
return this.callbacks.resolveFilename(this.projectFilename, file.filePath);
82+
return this.callbacks.resolveFilename(this._projectFilename, file.filePath);
7383
}
7484

7585
resolveOutputFilePath(file: KeymanDeveloperProjectFile, sourceExt: string, targetExt: string): string {

common/web/types/src/kpj/kpj-file-reader.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export class KPJFileReader {
7777

7878
if(result.options.version == '1.0') {
7979
this.transformFilesVersion10(project, result);
80-
result.addMetadataFile();
8180
} else {
8281
result.populateFiles();
8382
}

common/web/types/src/util/file-types.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ export const enum Source {
1010
LdmlKeyboard = '.xml', // Warning, also other possible uses
1111
Package = '.kps',
1212
VisualKeyboard = '.kvks',
13-
TouchLayout = '.keyman-touch-layout',
14-
KeyboardInfo = '.keyboard_info',
15-
ModelInfo = '.model_info',
13+
TouchLayout = '.keyman-touch-layout'
1614
};
1715

1816
/**
@@ -26,9 +24,7 @@ export const ALL_SOURCE: ReadonlyArray<Source> = [
2624
Source.LdmlKeyboard,
2725
Source.Package,
2826
Source.VisualKeyboard,
29-
Source.TouchLayout,
30-
Source.KeyboardInfo,
31-
Source.ModelInfo,
27+
Source.TouchLayout
3228
] as const;
3329

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

149-
/**
150-
* Returns true if the file is either a .keyboard_info file or a .model_info
151-
* file
152-
* @param filename
153-
* @returns
154-
*/
155-
export function filenameIsMetadata(filename: string) {
156-
return filenameIs(filename, Source.KeyboardInfo) || filenameIs(filename, Source.ModelInfo);
157-
}
158-
159145
/**
160146
* Replaces a filename extension with the new extension. Returns `null` if the
161147
* filename does not end with oldExtension.

common/web/types/test/kpj/test-kpj-file-reader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('kpj-file-reader', function () {
7777
assert.isTrue(project.options.skipMetadataFiles);
7878
assert.equal(project.options.version, '1.0');
7979

80-
assert.lengthOf(project.files, 3);
80+
assert.lengthOf(project.files, 2);
8181

8282
let f: KeymanDeveloperProjectFile10 = <KeymanDeveloperProjectFile10>project.files[0];
8383
assert.equal(f.id, 'id_f347675c33d2e6b1c705c787fad4941a');

developer/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ builder_describe \
2727
configure \
2828
build \
2929
test \
30+
":utils=src/common/web/utils Developer utils" \
3031
":kmcmplib=src/kmcmplib Compiler - .kmn compiler" \
3132
":kmc-analyze=src/kmc-analyze Compiler - Analysis Tools" \
3233
":kmc-keyboard-info=src/kmc-keyboard-info Compiler - .keyboard_info Module" \

developer/src/README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,40 @@ details.
7070

7171
## src/kmc
7272

73-
node-based next generation compiler, hosts kmc, kmlmi, kmlmc, kmlmp
73+
node-based next generation compiler, hosts kmc, (and legacy kmlmc, kmlmp)
74+
75+
### src/kmc-analyze - Analysis tools
76+
77+
File analysis tools for Keyman files.
78+
79+
### src/kmc-keyboard-info - Keyboard Info Compiler
80+
81+
Builds .keyboard_info files for use on the Keyman Cloud keyboard repository
82+
at https://github.com/keymanapp/keyboards. Command line access through kmc.
83+
84+
### src/kmc-kmn - Keyboard Compiler
85+
86+
Builds .kmx files from .kmn. Command line access through kmc.
7487

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

77-
Next Generation keyboard compiler package - LDML keyboards only at present.
78-
Command line access through kmc.
90+
Next Generation keyboard compiler - LDML keyboards. Command line access through
91+
kmc.
7992

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

82-
The Lexical Model Compiler, kmlmc, runs on nodeJS on all supported desktop
83-
platforms. Command line access through kmc/kmlmc.
95+
The Lexical Model Compiler, runs on nodeJS on all supported desktop platforms.
96+
Command line access through kmc.
8497

85-
### src/kmc-package - Package Compiler
98+
### src/kmc-model-info - Model Info Compiler
8699

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

93-
### src/kmc-model-info - Model Info Compiler
103+
### src/kmc-package - Package Compiler
94104

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

99108
## src/samples
100109

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
## START STANDARD BUILD SCRIPT INCLUDE
3+
# adjust relative paths as necessary
4+
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
5+
. "${THIS_SCRIPT%/*}/../../../../../resources/build/build-utils.sh"
6+
## END STANDARD BUILD SCRIPT INCLUDE
7+
8+
cd "$THIS_SCRIPT_PATH"
9+
10+
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
11+
12+
builder_describe "Build Keyman Developer web utility module" \
13+
"@/common/web/types" \
14+
"clean" \
15+
"configure" \
16+
"build" \
17+
"test"
18+
19+
builder_describe_outputs \
20+
configure /node_modules \
21+
build /developer/src/common/web/utils/build/index.js
22+
23+
builder_parse "$@"
24+
25+
#-------------------------------------------------------------------------------------------------------------------
26+
27+
builder_run_action clean rm -rf ./build/
28+
builder_run_action configure verify_npm_setup
29+
builder_run_action build tsc --build
30+
31+
if builder_start_action test; then
32+
eslint .
33+
tsc --build test
34+
c8 --reporter=lcov --reporter=text --exclude-after-remap mocha
35+
builder_finish_action success test
36+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { validateMITLicense } from './src/validate-mit-license.js';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@keymanapp/developer-utils",
3+
"private": true,
4+
"description": "Keyman Developer utilities",
5+
"type": "module",
6+
"exports": {
7+
".": "./build/index.js"
8+
},
9+
"files": [
10+
"/build/"
11+
],
12+
"devDependencies": {
13+
"@types/node": "^20.4.1",
14+
"ts-node": "^9.1.1",
15+
"typescript": "^4.9.5",
16+
"c8": "^7.12.0",
17+
"chai": "^4.3.4",
18+
"mocha": "^8.4.0"
19+
},
20+
"scripts": {
21+
"build": "tsc -b"
22+
},
23+
"dependencies": {
24+
"@keymanapp/common-types": "*"
25+
},
26+
"mocha": {
27+
"spec": "build/test/**/test-*.js",
28+
"require": [
29+
"source-map-support/register"
30+
]
31+
}
32+
}

0 commit comments

Comments
 (0)