Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(developer): kmc generate #11014

Merged
merged 30 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1ab9574
feat(developer): kmc-generate module
mcdurdin Mar 17, 2024
9003dbb
feat(developer): kmc-generate docs and tests started
mcdurdin Mar 20, 2024
125cfe6
feat(developer): kmc generate cleanup
mcdurdin Apr 12, 2024
a45abe4
feat(developer): unit tests for kmc-generate
mcdurdin Apr 12, 2024
413ae60
chore(developer): fixup tests and scripts for kmc-generate
mcdurdin Jun 25, 2024
8011c25
feat(developer): comments for kmc-generate
mcdurdin Jul 2, 2024
939134a
feat(developer): kmc-generate module
mcdurdin Mar 17, 2024
2994fe2
feat(developer): kmc-generate docs and tests started
mcdurdin Mar 20, 2024
8274d30
feat(developer): kmc generate cleanup
mcdurdin Apr 12, 2024
db90411
feat(developer): unit tests for kmc-generate
mcdurdin Apr 12, 2024
1ab1ca5
chore(developer): fixup tests and scripts for kmc-generate
mcdurdin Jun 25, 2024
113b4f7
feat(developer): comments for kmc-generate
mcdurdin Jul 2, 2024
beb4c2c
chore(developer): Merge branch 'feat/developer/kmc-generate' of https…
mcdurdin Sep 8, 2024
64c8bce
Merge branch 'master' into feat/developer/kmc-generate
mcdurdin Sep 8, 2024
d2f99f6
chore(developer): refactor imports after merge
mcdurdin Sep 8, 2024
09e97ce
chore(developer): fixup imports
mcdurdin Sep 9, 2024
95d169f
chore(developer): add developer-utils dep for kmc-generate
mcdurdin Sep 9, 2024
4a2e6fd
test(developer): add unit test for generate module
mcdurdin Sep 10, 2024
021d434
chore(developer): generate no longer needs to generate .model_info
mcdurdin Sep 10, 2024
edc5c93
chore(developer): add api-extractor for kmc-generate
mcdurdin Sep 10, 2024
178325c
chore(developer): use new npm publish for kmc-generate
mcdurdin Sep 10, 2024
8424cb9
Merge branch 'master' into feat/developer/kmc-generate
mcdurdin Sep 12, 2024
48d4e65
fix(developer): copy templates into bundle
mcdurdin Sep 17, 2024
ec6c26c
feat(developer): add .gitignore to kmc generate templates
mcdurdin Sep 17, 2024
10e4bba
Merge branch 'master' into feat/developer/kmc-generate
mcdurdin Sep 26, 2024
025b9ed
chore(developer): update eslint config path
mcdurdin Sep 26, 2024
5886847
chore(developer): cleanup targets and generated files in kmc-generate
mcdurdin Sep 27, 2024
0997986
chore(developer): fix kmc-generate test fixtures
mcdurdin Sep 27, 2024
0d96884
Merge branch 'master' into feat/developer/kmc-generate
mcdurdin Oct 11, 2024
89e58fb
Merge branch 'master' into feat/developer/kmc-generate
mcdurdin Oct 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -43,5 +43,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

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
Loading