Skip to content

Commit

Permalink
Merge pull request #11014 from keymanapp/feat/developer/kmc-generate
Browse files Browse the repository at this point in the history
feat(developer): kmc generate
  • Loading branch information
mcdurdin authored Nov 8, 2024
2 parents e27ebd1 + 89e58fb commit b80c124
Show file tree
Hide file tree
Showing 105 changed files with 3,624 additions and 32 deletions.
1 change: 0 additions & 1 deletion common/web/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"restructure": "3.0.1"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.7",
"@types/node": "^20.4.1",
"ajv": "^8.12.0",
Expand Down
4 changes: 4 additions & 0 deletions developer/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ node-based next generation compiler, hosts kmc, (and legacy kmlmc, kmlmp)

File analysis tools for Keyman files.

### kmc-generate - Generation tools

Project generation tools for Keyman.

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

Builds .keyboard_info files for use on the Keyman Cloud keyboard repository
Expand Down
1 change: 1 addition & 0 deletions developer/src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ builder_describe \
":help Online documentation" \
":kmcmplib Compiler - .kmn compiler" \
":kmc-analyze Compiler - Analysis Tools" \
":kmc-generate Compiler - Generation Tools" \
":kmc-keyboard-info Compiler - .keyboard_info Module" \
":kmc-kmn Compiler - .kmn to .kmx and .js Keyboard Module" \
":kmc-ldml Compiler - LDML Keyboard Module" \
Expand Down
5 changes: 5 additions & 0 deletions developer/src/common/web/test-helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import { CompilerEvent, CompilerCallbacks, CompilerPathCallbacks, CompilerFileSystemCallbacks, CompilerError } from '@keymanapp/developer-utils';
import { fileURLToPath } from 'url';
export { verifyCompilerMessagesObject } from './verifyCompilerMessagesObject.js';

/**
Expand All @@ -25,6 +26,10 @@ export class TestCompilerCallbacks implements CompilerCallbacks {
return this.messages.find((item) => item.code == code) === undefined ? false : true;
}

fileURLToPath(url: string | URL): string {
return fileURLToPath(url);
}

/** true of at least one error */
hasError(): boolean {
return CompilerError.hasError(this.messages);
Expand Down
11 changes: 11 additions & 0 deletions developer/src/common/web/utils/src/compiler-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ export enum CompilerErrorNamespace {
* kmc-keyboard-info 0x9000…0x9FFF
*/
KeyboardInfoCompiler = 0x9000,
/**
* kmc-generate 0xA000…0xAFFF
*/
Generator = 0xA000,
};

/**
Expand Down Expand Up @@ -290,6 +294,7 @@ export interface CompilerFileSystemCallbacks {
readFileSync(path: string, options: { encoding: string; flag?: string; } | string): string;
readFileSync(path: string, options?: { encoding?: string | null; flag?: string; } | string | null): string | Uint8Array;
writeFileSync(path: string, data: Uint8Array): void;
mkdirSync(path: string, options?: {recursive?: boolean}): string;

existsSync(name: string): boolean;
}
Expand Down Expand Up @@ -375,6 +380,8 @@ export interface CompilerCallbacks {
reportMessage(event: CompilerEvent): void;

debug(msg: string): void;

fileURLToPath(url: string | URL): string;
};

/**
Expand Down Expand Up @@ -471,6 +478,10 @@ export class CompilerFileCallbacks implements CompilerCallbacks {
debug(msg: string): void {
return this.parent.debug(msg);
}

fileURLToPath(url: string | URL): string {
return this.parent.fileURLToPath(url);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion developer/src/common/web/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ export { defaultCompilerOptions, CompilerBaseOptions, CompilerCallbacks, Compile
} from './compiler-interfaces.js';

export { CommonTypesMessages } from './common-messages.js';

export * as SourceFilenamePatterns from './source-filename-patterns.js';
export { KeymanXMLType, KeymanXMLWriter, KeymanXMLReader } from './xml-utils.js';
45 changes: 45 additions & 0 deletions developer/src/common/web/utils/src/source-filename-patterns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Keyman is copyright (C) SIL International. MIT License.
*
* Keyman Developer source filename regular expressions
*/

/**
* A keyboard package filename SHOULD adhere to this pattern (including file
* extension), lower case alphanumeric and underscore only allowed (a-z, _ only
* for first letter).
*/
export const KEYBOARD_ID_PATTERN_PACKAGE = /^[a-z_][a-z0-9_]*\.(kps|kmp)$/;

/**
* A lexical model package filename SHOULD adhere to this pattern (including
* file extension). There are three components to the filename: author, bcp47,
* and uniq, separated by period. The filename ends in .model.kps or .model.kmp.
* Each of the author, bcp47, and uniq sections may contain lowercase
* alphanumeric, underscore characters, and the bcp47 section additionally may
* contain hyphen. Digits are not permitted as first letter of each section.
*
* Despite including a bcp47 tag as part of the filename, it is informative only,
* and is not regarded as part of the metadata for the lexical model.
*/
// author .bcp47 .uniq
export const MODEL_ID_PATTERN_PACKAGE = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*\.model\.(kps|kmp)$/;

// const MODEL_ID_PATTERN_JS = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*\.model\.js$/;
// const MODEL_ID_PATTERN_TS = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*\.model\.ts$/;
// const MODEL_ID_PATTERN_PROJECT = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*\.model\.kpj$/;

/**
* Filenames of files contained in a package MAY adhere to this pattern for
* optimum cross-platform compatibility. This is the basename portion of the
* filename, and is case-insensitive.
*/
export const CONTENT_FILE_BASENAME_PATTERN = /^[a-z0-9_+.-]+$/i; // base names can be case insensitive

/**
* Extensions of files contained in a package MAY adhere to this pattern for optimum
* cross-platform compatibility. This is the extension portion of the filename,
* and should be lower case, and may be empty.
*/
export const CONTENT_FILE_EXTENSION_PATTERN = /^(\.[a-z0-9_-]+)?$/; // extensions should be lower-case or empty

5 changes: 5 additions & 0 deletions developer/src/common/web/utils/test/TestCompilerCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { loadFile, resolveFilename } from './helpers/index.js';
import { CompilerCallbacks, CompilerError, CompilerEvent, CompilerFileSystemCallbacks, CompilerPathCallbacks } from '../src/compiler-interfaces.js';
import { fileURLToPath } from 'url';

// This is related to developer/src/common/web/test-helpers/index.ts but has a slightly different API surface
// as this runs at a lower level than the compiler.
Expand Down Expand Up @@ -34,6 +35,10 @@ export class TestCompilerCallbacks implements CompilerCallbacks {
return resolveFilename(baseFilename, filename);
}

fileURLToPath(url: string | URL): string {
return fileURLToPath(url);
}

loadFile(filename: string): Uint8Array {
// TODO: error management, does it belong here?
try {
Expand Down
21 changes: 21 additions & 0 deletions developer/src/kmc-generate/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Keyman is copyright (C) SIL International. MIT License.
*
* tslint options for kmc-generate
*/

module.exports = {
parserOptions: {
project: ["./tsconfig.json", "./test/tsconfig.json"],
},
ignorePatterns: ["test/fixtures/**/*", "src/template/**/*"],
overrides: [
{
files:"src/**/*.ts",
extends: ["../../../common/tools/eslint/eslintNoNodeImports.js"],
}
],
rules: {
"prefer-const": 1,
},
};
51 changes: 51 additions & 0 deletions developer/src/kmc-generate/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
#
# Keyman is copyright (C) SIL International. MIT License.
#
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
. "${THIS_SCRIPT%/*}/../../../resources/build/builder.inc.sh"
## END STANDARD BUILD SCRIPT INCLUDE

. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
. "$KEYMAN_ROOT/resources/build/build-utils-ci.inc.sh"

builder_describe "Build Keyman kmc-generate module" \
"@/common/web/keyman-version" \
"@/common/web/types" \
"@/developer/src/common/web/test-helpers" \
clean configure build api test publish \
"--npm-publish+ For publish, do a npm publish, not npm pack (only for CI)" \
"--dry-run,-n don't actually publish, just dry run"

builder_describe_outputs \
configure /node_modules \
build /developer/src/kmc-generate/build/src/main.js \
api /developer/build/api/kmc-generate.api.json

builder_parse "$@"

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

do_build() {
tsc --build
rm -rf ./build/src/template
mkdir -p ./build/src/template
cp -R ./src/template/ ./build/src/
}

do_test() {
eslint .
cd test
tsc --build
cd ..
c8 --reporter=lcov --reporter=text mocha "${builder_extra_params[@]}"
}

builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_run_action configure verify_npm_setup
builder_run_action build do_build
builder_run_action api api-extractor run --local --verbose
builder_run_action test do_test
builder_run_action publish builder_publish_npm
12 changes: 12 additions & 0 deletions developer/src/kmc-generate/config/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Config file for API Extractor. For more info, please visit: https://api-extractor.com
*/
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "../../../config/api-extractor.base.json",
"mainEntryPointFilePath": "<projectFolder>/build/src/main.d.ts",
"docModel": {
"enabled": true,
"projectFolderUrl": "http://github.com/keymanapp/keyman/tree/master/developer/src/kmc-generate"
}
}
64 changes: 64 additions & 0 deletions developer/src/kmc-generate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@keymanapp/kmc-generate",
"description": "Keyman Developer generate module",
"keywords": [
"keyboard",
"keyman",
"ldml",
"unicode"
],
"type": "module",
"exports": {
".": "./build/src/main.js"
},
"files": [
"/build/src/"
],
"scripts": {
"build": "gosh ./build.sh build",
"lint": "eslint .",
"test": "gosh ./build.sh test"
},
"author": "Marc Durdin <[email protected]> (https://github.com/mcdurdin)",
"license": "MIT",
"bugs": {
"url": "https://github.com/keymanapp/keyman/issues"
},
"dependencies": {
"@keymanapp/common-types": "*",
"@keymanapp/developer-utils": "*",
"@keymanapp/keyman-version": "*"
},
"devDependencies": {
"@keymanapp/developer-test-helpers": "*",
"@keymanapp/resources-gosh": "*",
"@types/mocha": "^10.0.0",
"@types/node": "^20.4.1",
"@types/semver": "^7.3.12",
"c8": "^7.12.0",
"chalk": "^2.4.2",
"mocha": "^10.0.0",
"typescript": "^5.4.5"
},
"mocha": {
"spec": "build/test/**/test-*.js",
"require": [
"source-map-support/register"
]
},
"c8": {
"all": true,
"src": [
"src/"
],
"exclude-after-remap": true,
"exclude": [
"test/",
"src/template/"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/keymanapp/keyman.git"
}
}
Loading

0 comments on commit b80c124

Please sign in to comment.