mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-18 05:37:40 +00:00
feat(developer): kmc compile .model.ts file
Adds basic support for compiling .model.ts files using kmc-model to kmc.
This commit is contained in:
parent
f6a3364c56
commit
12a6e404af
2 changed files with 30 additions and 2 deletions
28
developer/src/kmc/src/activities/buildModel.ts
Normal file
28
developer/src/kmc/src/activities/buildModel.ts
Normal file
|
|
@ -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<boolean> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -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<bool
|
|||
return buildPackage(infile, options);
|
||||
}
|
||||
|
||||
/*
|
||||
if(infile.endsWith('.model.ts')) {
|
||||
return buildModel(infile, options);
|
||||
}
|
||||
|
||||
/*
|
||||
if(infile.endsWith('.kpj')) {
|
||||
return buildProject(infile, options);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue