mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 16:35:33 +00:00
53 lines
No EOL
1.2 KiB
JavaScript
53 lines
No EOL
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* kmlmc - Keyman Lexical Model Compiler
|
|
*/
|
|
/// <reference path="lexical-model-compiler/lexical-model.ts" />
|
|
|
|
import * as fs from 'fs';
|
|
import * as program from 'commander';
|
|
|
|
import { compileModel } from './util';
|
|
|
|
/**
|
|
* Exit codes defined in <sysexits.h>:
|
|
* https://www.freebsd.org/cgi/man.cgi?query=sysexits&apropos=0&sektion=0&manpath=FreeBSD+4.3-RELEASE&format=html
|
|
*/
|
|
export const enum SysExits {
|
|
EX_USAGE = 64,
|
|
EX_DATAERR = 65,
|
|
};
|
|
|
|
let inputFilename: string;
|
|
|
|
/* Arguments */
|
|
program
|
|
.description('Compiles Keyman lexical models')
|
|
.version(require('../package.json').version)
|
|
.arguments('<infile>')
|
|
.action(infile => inputFilename = infile)
|
|
.option('-o, --outFile <filename>', 'where to save the resultant file');
|
|
|
|
program.parse(process.argv);
|
|
|
|
// Deal with input arguments:
|
|
if (!inputFilename) {
|
|
exitDueToUsageError('Must provide a lexical model source file.');
|
|
}
|
|
|
|
// Compile:
|
|
let code = compileModel(inputFilename);
|
|
|
|
// Output:
|
|
if (program.outFile) {
|
|
fs.writeFileSync(program.outFile, code, 'utf8');
|
|
} else {
|
|
console.log(code);
|
|
}
|
|
|
|
function exitDueToUsageError(message: string): never {
|
|
console.error(`${program._name}: ${message}`);
|
|
console.error();
|
|
program.outputHelp();
|
|
return process.exit(SysExits.EX_USAGE);
|
|
} |