mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-06 00:45:32 +00:00
As KEYMAN-VERSION changed from being a type to a class, this broke the bundling and referencing strategies in Developer/Server and Developer/kmlmc. This updates the bundling process and fixes the references in both projects. Note that keyman-version no longer depends on gosh. Given we are currently manually calling the build for this in all projects (or should be!), it's better that we keep the build of this explicit for now. If we want to restore the postinstall/postci steps in the future, the gosh dependency would need to be manually removed from package.json in order for the bundling builds to work for Developer/Server and Developer/kmlmc.
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* kmlmp - Keyman Lexical Model Package Compiler
|
|
*/
|
|
|
|
import * as program from 'commander';
|
|
import * as fs from 'fs';
|
|
import KmpCompiler from './package-compiler/kmp-compiler';
|
|
import { SysExits } from './util/sysexits';
|
|
const KEYMAN_VERSION = require("@keymanapp/keyman-version").KEYMAN_VERSION;
|
|
|
|
let inputFilename: string;
|
|
|
|
/* Arguments */
|
|
program
|
|
.description('Compiles Keyman lexical model packages')
|
|
.version(KEYMAN_VERSION.VERSION_WITH_TAG)
|
|
.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 package source file.');
|
|
}
|
|
|
|
let outputFilename: string = program.outFile ? program.outFile : inputFilename.replace(/\.kps$/, ".kmp");
|
|
|
|
//
|
|
// Load .kps source data
|
|
//
|
|
|
|
let kpsString: string = fs.readFileSync(inputFilename, 'utf8');
|
|
let kmpCompiler = new KmpCompiler();
|
|
let kmpJsonData = kmpCompiler.transformKpsToKmpObject(kpsString);
|
|
|
|
//
|
|
// Build the .kmp package file
|
|
//
|
|
|
|
let promise = kmpCompiler.buildKmpFile(kmpJsonData);
|
|
promise.then(data => {
|
|
fs.writeFileSync(outputFilename, data, 'binary');
|
|
}).catch(error => {
|
|
// Consumer decides how to handle errors
|
|
console.error('Failed to write kmp file');
|
|
});
|
|
|
|
function exitDueToUsageError(message: string): never {
|
|
console.error(`${program._name}: ${message}`);
|
|
console.error();
|
|
program.outputHelp();
|
|
return process.exit(SysExits.EX_USAGE);
|
|
}
|