Skip to content

Commit 6e8cc16

Browse files
authored
Merge pull request #9474 from keymanapp/feat/developer/compile-without-source-keyboard-info
feat(developer): support building .keyboard_info without source version 🎺
2 parents 0913770 + e751a25 commit 6e8cc16

35 files changed

+525
-243
lines changed

common/schemas/kpj/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ always '1.0'. It will be required for version 2.0 and later of the format.
66
**Note:** An additional schema file, kpj-9.0.schema.json, for supporting legacy
77
versions of .kpj, from Keyman Developer 9.0 and earlier, is now available.
88

9+
## 2023-08-07 2.0.1
10+
* Add Options/SkipMetadataFiles, defaults to True for 1.0 projects.
11+
912
## 2023-02-27 2.0
1013
* Version 2.0 makes 'Files' optional (internally, Files/File will be ignored,
1114
deleted on load and populated from folder structure). Adds Options/SourcePath,

common/schemas/kpj/kpj.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
"type": "string",
4646
"pattern": "^(True|False)$"
4747
},
48+
"SkipMetadataFiles": {
49+
"type": "string",
50+
"pattern": "^(True|False)$"
51+
},
4852
"ProjectType": {
4953
"type": "string",
5054
"pattern": "^(keyboard|lexicalmodel)$"

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ export class KeymanDeveloperProjectOptions {
108108
compilerWarningsAsErrors: boolean = false;
109109
warnDeprecatedCode: boolean = true;
110110
checkFilenameConventions: boolean = false; // missing option defaults to False
111+
/**
112+
* Skip building .keyboard_info and .model_info files, for example in
113+
* unit tests or for legacy keyboards
114+
*/
115+
skipMetadataFiles: boolean;
111116
projectType: KeymanDeveloperProjectType = KeymanDeveloperProjectType.Keyboard;
112117
readonly version: KeymanDeveloperProjectVersion;
113118
constructor(version: KeymanDeveloperProjectVersion) {
@@ -116,10 +121,12 @@ export class KeymanDeveloperProjectOptions {
116121
case "1.0":
117122
this.buildPath = '';
118123
this.sourcePath = '';
124+
this.skipMetadataFiles = true;
119125
break;
120126
case "2.0":
121127
this.buildPath = '$PROJECTPATH/build';
122128
this.sourcePath = '$PROJECTPATH/source';
129+
this.skipMetadataFiles = false;
123130
break;
124131
default:
125132
throw new Error('Invalid version');

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ export class KPJFileReader {
6262
if(result.options.version == '2.0') {
6363
result.options.buildPath = (project.Options?.BuildPath || result.options.buildPath).replace(/\\/g, '/');
6464
result.options.sourcePath = (project.Options?.SourcePath || result.options.sourcePath).replace(/\\/g, '/');
65+
result.options.skipMetadataFiles = this.boolFromString(project.Options?.SkipMetadataFiles, false);
6566
} else {
6667
result.options.buildPath = (project.Options?.BuildPath || '').replace(/\\/g, '/');
68+
result.options.skipMetadataFiles = this.boolFromString(project.Options?.SkipMetadataFiles, true);
6769
}
6870
result.options.checkFilenameConventions = this.boolFromString(project.Options?.CheckFilenameConventions, false);
6971
result.options.compilerWarningsAsErrors = this.boolFromString(project.Options?.CompilerWarningsAsErrors, false);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface KPJFileOptions {
2020
SourcePath?: string; // default '' in 1.0, '$PROJECTPATH/source' in 2.0
2121
CompilerWarningsAsErrors?: string; // default False
2222
WarnDeprecatedCode?: string; // default True
23+
SkipMetadataFiles?: string; // default True for 1.0, False for 2.0
2324
CheckFilenameConventions?: string; // default False
2425
ProjectType?: 'keyboard' | 'lexicalmodel'; // default 'keyboard'
2526
Version?: '1.0' | '2.0'; // default 1.0

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ export function filenameIs(filename: string, fileType: Source | Binary) {
146146
return filename.toLowerCase().endsWith(fileType);
147147
}
148148

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+
149159
/**
150160
* Replaces a filename extension with the new extension. Returns `null` if the
151161
* filename does not end with oldExtension.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('kpj-file-reader', function () {
2323
assert.equal(kpj.KeymanDeveloperProject.Options.CompilerWarningsAsErrors, 'True');
2424
assert.equal(kpj.KeymanDeveloperProject.Options.ProjectType, 'keyboard');
2525
assert.equal(kpj.KeymanDeveloperProject.Options.WarnDeprecatedCode, 'True');
26+
assert.isUndefined(kpj.KeymanDeveloperProject.Options.SkipMetadataFiles); // because this is a 1.0 version file
2627
assert.isUndefined(kpj.KeymanDeveloperProject.Options.Version);
2728

2829
assert.lengthOf(kpj.KeymanDeveloperProject.Files.File, 21);
@@ -73,6 +74,7 @@ describe('kpj-file-reader', function () {
7374
assert.isTrue(project.options.compilerWarningsAsErrors);
7475
assert.equal(project.options.projectType, KeymanDeveloperProjectType.Keyboard);
7576
assert.isTrue(project.options.warnDeprecatedCode);
77+
assert.isTrue(project.options.skipMetadataFiles);
7678
assert.equal(project.options.version, '1.0');
7779

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

developer/src/kmc-analyze/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function do_test() {
2929
# TODO: enable tests
3030
# cd test && tsc --build && cd .. && mocha
3131
# TODO: enable c8 (disabled because no coverage at present)
32-
# c8 --reporter=lcov --reporter=text mocha
32+
# c8 --reporter=lcov --reporter=text --exclude-after-remap mocha
3333
}
3434

3535
builder_run_action clean rm -rf ./build/

developer/src/kmc-keyboard-info/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ builder_run_action build tsc --build
4343
if builder_start_action test; then
4444
eslint .
4545
tsc --build test
46-
c8 --reporter=lcov --reporter=text mocha
46+
c8 --reporter=lcov --reporter=text --exclude-after-remap mocha
4747
builder_finish_action success test
4848
fi
4949

developer/src/kmc-keyboard-info/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"url": "https://github.com/keymanapp/keyman/issues"
2525
},
2626
"dependencies": {
27-
"@keymanapp/common-types": "*"
27+
"@keymanapp/common-types": "*",
28+
"@keymanapp/kmc-package": "*"
2829
},
2930
"devDependencies": {
3031
"@types/chai": "^4.1.7",

0 commit comments

Comments
 (0)