Skip to content

Commit

Permalink
Merge pull request #9474 from keymanapp/feat/developer/compile-withou…
Browse files Browse the repository at this point in the history
…t-source-keyboard-info

feat(developer): support building .keyboard_info without source version 🎺
  • Loading branch information
mcdurdin authored Sep 1, 2023
2 parents 0913770 + e751a25 commit 6e8cc16
Show file tree
Hide file tree
Showing 35 changed files with 525 additions and 243 deletions.
3 changes: 3 additions & 0 deletions common/schemas/kpj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ always '1.0'. It will be required for version 2.0 and later of the format.
**Note:** An additional schema file, kpj-9.0.schema.json, for supporting legacy
versions of .kpj, from Keyman Developer 9.0 and earlier, is now available.

## 2023-08-07 2.0.1
* Add Options/SkipMetadataFiles, defaults to True for 1.0 projects.

## 2023-02-27 2.0
* Version 2.0 makes 'Files' optional (internally, Files/File will be ignored,
deleted on load and populated from folder structure). Adds Options/SourcePath,
Expand Down
4 changes: 4 additions & 0 deletions common/schemas/kpj/kpj.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"type": "string",
"pattern": "^(True|False)$"
},
"SkipMetadataFiles": {
"type": "string",
"pattern": "^(True|False)$"
},
"ProjectType": {
"type": "string",
"pattern": "^(keyboard|lexicalmodel)$"
Expand Down
7 changes: 7 additions & 0 deletions common/web/types/src/kpj/keyman-developer-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ export class KeymanDeveloperProjectOptions {
compilerWarningsAsErrors: boolean = false;
warnDeprecatedCode: boolean = true;
checkFilenameConventions: boolean = false; // missing option defaults to False
/**
* Skip building .keyboard_info and .model_info files, for example in
* unit tests or for legacy keyboards
*/
skipMetadataFiles: boolean;
projectType: KeymanDeveloperProjectType = KeymanDeveloperProjectType.Keyboard;
readonly version: KeymanDeveloperProjectVersion;
constructor(version: KeymanDeveloperProjectVersion) {
Expand All @@ -116,10 +121,12 @@ export class KeymanDeveloperProjectOptions {
case "1.0":
this.buildPath = '';
this.sourcePath = '';
this.skipMetadataFiles = true;
break;
case "2.0":
this.buildPath = '$PROJECTPATH/build';
this.sourcePath = '$PROJECTPATH/source';
this.skipMetadataFiles = false;
break;
default:
throw new Error('Invalid version');
Expand Down
2 changes: 2 additions & 0 deletions common/web/types/src/kpj/kpj-file-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export class KPJFileReader {
if(result.options.version == '2.0') {
result.options.buildPath = (project.Options?.BuildPath || result.options.buildPath).replace(/\\/g, '/');
result.options.sourcePath = (project.Options?.SourcePath || result.options.sourcePath).replace(/\\/g, '/');
result.options.skipMetadataFiles = this.boolFromString(project.Options?.SkipMetadataFiles, false);
} else {
result.options.buildPath = (project.Options?.BuildPath || '').replace(/\\/g, '/');
result.options.skipMetadataFiles = this.boolFromString(project.Options?.SkipMetadataFiles, true);
}
result.options.checkFilenameConventions = this.boolFromString(project.Options?.CheckFilenameConventions, false);
result.options.compilerWarningsAsErrors = this.boolFromString(project.Options?.CompilerWarningsAsErrors, false);
Expand Down
1 change: 1 addition & 0 deletions common/web/types/src/kpj/kpj-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface KPJFileOptions {
SourcePath?: string; // default '' in 1.0, '$PROJECTPATH/source' in 2.0
CompilerWarningsAsErrors?: string; // default False
WarnDeprecatedCode?: string; // default True
SkipMetadataFiles?: string; // default True for 1.0, False for 2.0
CheckFilenameConventions?: string; // default False
ProjectType?: 'keyboard' | 'lexicalmodel'; // default 'keyboard'
Version?: '1.0' | '2.0'; // default 1.0
Expand Down
10 changes: 10 additions & 0 deletions common/web/types/src/util/file-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ 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
2 changes: 2 additions & 0 deletions common/web/types/test/kpj/test-kpj-file-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +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.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 @@ -73,6 +74,7 @@ describe('kpj-file-reader', function () {
assert.isTrue(project.options.compilerWarningsAsErrors);
assert.equal(project.options.projectType, KeymanDeveloperProjectType.Keyboard);
assert.isTrue(project.options.warnDeprecatedCode);
assert.isTrue(project.options.skipMetadataFiles);
assert.equal(project.options.version, '1.0');

assert.lengthOf(project.files, 3);
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc-analyze/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function do_test() {
# TODO: enable tests
# cd test && tsc --build && cd .. && mocha
# TODO: enable c8 (disabled because no coverage at present)
# c8 --reporter=lcov --reporter=text mocha
# c8 --reporter=lcov --reporter=text --exclude-after-remap mocha
}

builder_run_action clean rm -rf ./build/
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc-keyboard-info/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ builder_run_action build tsc --build
if builder_start_action test; then
eslint .
tsc --build test
c8 --reporter=lcov --reporter=text mocha
c8 --reporter=lcov --reporter=text --exclude-after-remap mocha
builder_finish_action success test
fi

Expand Down
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 @@ -24,7 +24,8 @@
"url": "https://github.com/keymanapp/keyman/issues"
},
"dependencies": {
"@keymanapp/common-types": "*"
"@keymanapp/common-types": "*",
"@keymanapp/kmc-package": "*"
},
"devDependencies": {
"@types/chai": "^4.1.7",
Expand Down
Loading

0 comments on commit 6e8cc16

Please sign in to comment.