From 12a6e404aff2cc7587e5a66f0547f8cab2002bb1 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 24 Feb 2023 14:44:57 +0700 Subject: [PATCH] feat(developer): kmc compile .model.ts file Adds basic support for compiling .model.ts files using kmc-model to kmc. --- .../src/kmc/src/activities/buildModel.ts | 28 +++++++++++++++++++ developer/src/kmc/src/commands/build.ts | 4 +-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 developer/src/kmc/src/activities/buildModel.ts diff --git a/developer/src/kmc/src/activities/buildModel.ts b/developer/src/kmc/src/activities/buildModel.ts new file mode 100644 index 0000000000..dc0ddf6e9b --- /dev/null +++ b/developer/src/kmc/src/activities/buildModel.ts @@ -0,0 +1,28 @@ +import * as fs from 'fs'; +import { BuildCommandOptions } from '../commands/build.js'; +import { compileModel } from '@keymanapp/kmc-model'; + +export async function buildModel(infile: string, options: BuildCommandOptions): Promise { + + let outputFilename: string = options.outFile ? options.outFile : infile.replace(/\.ts$/i, ".js"); + + let code = null; + + // Compile: + try { + code = compileModel(infile); + } catch(e) { + console.error(e); + return false; + } + + if(!code) { + console.error('Compilation failed.') + return false; + } + + // Output: + fs.writeFileSync(outputFilename, code, 'utf8'); + + return true; +} \ No newline at end of file diff --git a/developer/src/kmc/src/commands/build.ts b/developer/src/kmc/src/commands/build.ts index 6d3106296d..4161e2251c 100644 --- a/developer/src/kmc/src/commands/build.ts +++ b/developer/src/kmc/src/commands/build.ts @@ -2,6 +2,7 @@ import { Command } from 'commander'; import { buildPackage } from '../activities/buildPackage.js'; import { buildKmnKeyboard } from '../activities/buildKmnKeyboard.js'; import { buildLdmlKeyboard } from '../activities/buildLdmlKeyboard.js'; +import { buildModel } from '../activities/buildModel.js'; export interface BuildCommandOptions { debug?: boolean; @@ -44,11 +45,10 @@ async function build(infile: string, options: BuildCommandOptions): Promise