Skip to content

Commit

Permalink
Merge pull request #11531 from keymanapp/refactor/common/9665-move-pr…
Browse files Browse the repository at this point in the history
…oject-file-type-to-developer

refactor(common): move kpj-related files into developer-utils 🐉
  • Loading branch information
mcdurdin authored Aug 7, 2024
2 parents 1d27a10 + 42698eb commit 7849b77
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 44 deletions.
5 changes: 4 additions & 1 deletion common/web/types/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ function do_build() {
function do_test() {
eslint .
tsc --build test
c8 --skip-full --reporter=lcov --reporter=text mocha "${builder_extra_params[@]}"
readonly C8_THRESHOLD=75
c8 --skip-full --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha "${builder_extra_params[@]}"
builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal."
builder_echo warning "Please increase threshold in build.sh as test coverage improves."
}

#-------------------------------------------------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions common/web/types/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export * as TouchLayout from './keyman-touch-layout/keyman-touch-layout-file.js'
export { TouchLayoutFileReader } from './keyman-touch-layout/keyman-touch-layout-file-reader.js';
export { TouchLayoutFileWriter, TouchLayoutFileWriterOptions } from './keyman-touch-layout/keyman-touch-layout-file-writer.js';

export * as KPJ from './kpj/kpj-file.js';
export { KPJFileReader } from './kpj/kpj-file-reader.js';
export { KeymanDeveloperProject, KeymanDeveloperProjectFile, KeymanDeveloperProjectType, } from './kpj/keyman-developer-project.js';

export * as KpsFile from './package/kps-file.js';
export * as KmpJsonFile from './package/kmp-json-file.js';

Expand Down
7 changes: 5 additions & 2 deletions developer/src/common/web/utils/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ builder_describe "Build Keyman Developer web utility module" \

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

builder_parse "$@"

Expand All @@ -34,7 +34,10 @@ 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
readonly C8_THRESHOLD=60
c8 --reporter=lcov --reporter=text --exclude-after-remap --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha
builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal."
builder_echo warning "Please increase threshold in build.sh as test coverage improves."
builder_finish_action success test
fi

Expand Down
6 changes: 0 additions & 6 deletions developer/src/common/web/utils/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion developer/src/common/web/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Keyman Developer utilities",
"type": "module",
"exports": {
".": "./build/index.js"
".": "./build/src/index.js"
},
"files": [
"/build/"
Expand Down
10 changes: 10 additions & 0 deletions developer/src/common/web/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export { validateMITLicense } from './utils/validate-mit-license.js';
export { KeymanSentry, SentryNodeOptions } from './utils/KeymanSentry.js';
export { getOption, loadOptions, clearOptions } from './utils/options.js';
export { escapeMarkdownChar } from './utils/markdown.js';
export { KeymanUrls } from './utils/keyman-urls.js';

export * as KPJ from './types/kpj/kpj-file.js';
export { KPJFileReader } from './types/kpj/kpj-file-reader.js';
export { KeymanDeveloperProject, KeymanDeveloperProjectFile, KeymanDeveloperProjectType, } from './types/kpj/keyman-developer-project.js';
export { isValidEmail } from './is-valid-email.js';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Version 1.0 and 2.0 of Keyman Developer Project .kpj file
//

import { KeymanFileTypes } from '../main.js';
import { CompilerCallbacks } from '../util/compiler-interfaces.js';
import { CompilerCallbacks, KeymanFileTypes } from '@keymanapp/common-types';

export class KeymanDeveloperProject {
options: KeymanDeveloperProjectOptions;
Expand All @@ -29,13 +28,13 @@ export class KeymanDeveloperProject {
if(this.options.version != '2.0') {
throw new Error('populateFiles can only be called on a v2.0 project');
}
let sourcePath = this.resolveProjectPath(this.options.sourcePath);
const sourcePath = this.resolveProjectPath(this.options.sourcePath);
if(!this.callbacks.fs.existsSync(sourcePath)) {
return false;
}
let files = this.callbacks.fs.readdirSync(sourcePath);
for(let filename of files) {
let fullPath = this.callbacks.path.join(sourcePath, filename);
const files = this.callbacks.fs.readdirSync(sourcePath);
for(const filename of files) {
const fullPath = this.callbacks.path.join(sourcePath, filename);
if(KeymanFileTypes.filenameIs(filename, KeymanFileTypes.Source.LdmlKeyboard)) {
try {
const data = this.callbacks.loadFile(fullPath);
Expand All @@ -51,7 +50,7 @@ export class KeymanDeveloperProject {
}
}
if(KeymanFileTypes.sourceTypeFromFilename(filename) !== null) {
let file = new KeymanDeveloperProjectFile20(fullPath, this.callbacks);
const file = new KeymanDeveloperProjectFile20(fullPath, this.callbacks);
this.files.push(file);
}
}
Expand Down Expand Up @@ -109,7 +108,7 @@ export class KeymanDeveloperProject {

p = this.resolveProjectPath(p);

let f = file.filename.replace(new RegExp(`\\${sourceExt}$`, 'i'), targetExt);
const f = file.filename.replace(new RegExp(`\\${sourceExt}$`, 'i'), targetExt);
return this.callbacks.path.normalize(this.callbacks.path.join(p, f));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as xml2js from '../deps/xml2js/xml2js.js';
import { xml2js } from '@keymanapp/common-types';
import { KPJFile, KPJFileProject } from './kpj-file.js';
import { boxXmlArray } from '../util/util.js';
import { util } from '@keymanapp/common-types';
import { KeymanDeveloperProject, KeymanDeveloperProjectFile10, KeymanDeveloperProjectType } from './keyman-developer-project.js';
import { CompilerCallbacks } from '../util/compiler-interfaces.js';
import SchemaValidators from '../schema-validators.js';
import { CompilerCallbacks, SchemaValidators } from '@keymanapp/common-types';

export class KPJFileReader {
constructor(private callbacks: CompilerCallbacks) {
Expand All @@ -29,7 +28,7 @@ export class KPJFileReader {
});
data = this.boxArrays(data);
if(data.KeymanDeveloperProject?.Files?.File?.length) {
for(let file of data.KeymanDeveloperProject?.Files?.File) {
for(const file of data.KeymanDeveloperProject?.Files?.File) {
// xml2js imports <Details/> as '' so we will just delete the empty string
if(typeof file.Details == 'string') {
delete file.Details;
Expand All @@ -40,11 +39,11 @@ export class KPJFileReader {
}

public validate(source: KPJFile): void {
if(!SchemaValidators.kpj(source)) {
if(!SchemaValidators.kpj90(source)) {
if(!SchemaValidators.default.kpj(source)) {
if(!SchemaValidators.default.kpj90(source)) {
// If the legacy schema also does not validate, then we will only report
// the errors against the modern schema
throw new Error(JSON.stringify((<any>SchemaValidators.kpj).errors));
throw new Error(JSON.stringify((<any>SchemaValidators.default.kpj).errors));
}
}
}
Expand All @@ -60,8 +59,8 @@ export class KPJFileReader {
// NOTE: at this point, the xml should have been validated
// and matched the schema result so we can assume the source
// is a valid shape
let project = source.KeymanDeveloperProject;
let result: KeymanDeveloperProject = new KeymanDeveloperProject(projectFilename, project.Options?.Version || "1.0", this.callbacks);
const project = source.KeymanDeveloperProject;
const result: KeymanDeveloperProject = new KeymanDeveloperProject(projectFilename, project.Options?.Version || "1.0", this.callbacks);
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, '/');
Expand All @@ -88,9 +87,9 @@ export class KPJFileReader {
}

private transformFilesVersion10(project: KPJFileProject, result: KeymanDeveloperProject) {
let ids: { [id: string]: KeymanDeveloperProjectFile10; } = {};
for (let sourceFile of project.Files?.File) {
let file: KeymanDeveloperProjectFile10 = new KeymanDeveloperProjectFile10(
const ids: { [id: string]: KeymanDeveloperProjectFile10; } = {};
for (const sourceFile of project.Files?.File) {
const file: KeymanDeveloperProjectFile10 = new KeymanDeveloperProjectFile10(
sourceFile.ID || '',
(sourceFile.Filepath || '').replace(/\\/g, '/'),
sourceFile.FileVersion || '',
Expand Down Expand Up @@ -123,7 +122,7 @@ export class KPJFileReader {
if(!source.KeymanDeveloperProject.Files || typeof source.KeymanDeveloperProject.Files == 'string') {
source.KeymanDeveloperProject.Files = {File:[]};
}
boxXmlArray(source.KeymanDeveloperProject.Files, 'File');
util.boxXmlArray(source.KeymanDeveloperProject.Files, 'File');
return source;
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as fs from 'fs';
import 'mocha';
import {assert} from 'chai';
import { makePathToFixture } from '../helpers/index.js';
import { KPJFileReader } from "../../src/kpj/kpj-file-reader.js";
import { KeymanDeveloperProjectFile10, KeymanDeveloperProjectType } from '../../src/kpj/keyman-developer-project.js';
import { TestCompilerCallbacks } from '../helpers/TestCompilerCallbacks.js';
import { KPJFileReader } from "../../src/types/kpj/kpj-file-reader.js";
import { KeymanDeveloperProjectFile10, KeymanDeveloperProjectType } from '../../src/types/kpj/keyman-developer-project.js';
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';

const callbacks = new TestCompilerCallbacks();

Expand Down
2 changes: 1 addition & 1 deletion developer/src/common/web/utils/test/test-license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import { assert } from 'chai';
import 'mocha';
import { makePathToFixture } from './helpers/index.js';
import { validateMITLicense } from '../src/validate-mit-license.js';
import { validateMITLicense } from '../src/utils/validate-mit-license.js';

function verifyLicenseFile(filename: string) {
return validateMITLicense(fs.readFileSync(makePathToFixture('license', filename), 'utf-8'));
Expand Down
1 change: 0 additions & 1 deletion developer/src/common/web/utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"baseUrl": ".",
},
"include": [
"index.ts",
"src/**/*.ts",
],
}
3 changes: 2 additions & 1 deletion developer/src/kmc/src/commands/buildClasses/BuildProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';
import * as fs from 'fs';
import { CompilerCallbacks, CompilerFileCallbacks, KeymanDeveloperProject, KeymanDeveloperProjectFile, KeymanDeveloperProjectType, KeymanFileTypes } from '@keymanapp/common-types';
import { CompilerCallbacks, CompilerFileCallbacks, KeymanFileTypes } from '@keymanapp/common-types';
import { KeymanDeveloperProject, KeymanDeveloperProjectFile, KeymanDeveloperProjectType } from '@keymanapp/developer-utils';
import { BuildActivity } from './BuildActivity.js';
import { buildActivities, buildKeyboardInfoActivity, buildModelInfoActivity } from './buildActivities.js';
import { InfrastructureMessages } from '../../messages/infrastructureMessages.js';
Expand Down
3 changes: 2 additions & 1 deletion developer/src/kmc/src/util/projectLoader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import * as path from 'path';
import * as fs from 'fs';
import { CompilerCallbacks, KeymanDeveloperProject, KeymanFileTypes, KPJFileReader } from "@keymanapp/common-types";
import { CompilerCallbacks, KeymanFileTypes } from "@keymanapp/common-types";
import { KeymanDeveloperProject, KPJFileReader } from "@keymanapp/developer-utils";
import { InfrastructureMessages } from "../messages/infrastructureMessages.js";

export const isProject = (filename: string): boolean =>
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc/test/test-getLastGitCommitDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ describe('getLastGitCommitDate', function () {
// The expected date was manually extracted using the following command, with msec appended:
// TZ=UTC git log --date=iso-strict-local -- fixtures/get-last-git-commit-date/README.md
// If the fixture modified, then this will also need to be updated.
assert.equal(date, '2024-06-17T20:43:48.000Z');
assert.equal(date, '2024-08-01T00:07:07.000Z');
});
});

0 comments on commit 7849b77

Please sign in to comment.