UNPKG

@keymanapp/kmc

Version:

Keyman Developer compiler command line tools

62 lines (60 loc) 2.15 kB
#!/usr/bin/env node /** * kmlmc - Keyman Lexical Model Compiler */ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="21503a91-4908-5cd1-8ccb-7a4d25cbc88b")}catch(e){}}(); import { Command } from 'commander'; import { LexicalModelCompiler } from '@keymanapp/kmc-model'; import KEYMAN_VERSION from "@keymanapp/keyman-version"; import { NodeCompilerCallbacks } from './util/NodeCompilerCallbacks.js'; let inputFilename; const program = new Command(); /* Arguments */ program .description('Compiles Keyman lexical models') .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 source file.'); } const callbacks = new NodeCompilerCallbacks({ logLevel: 'info' }); const compiler = new LexicalModelCompiler(); if (!await compiler.init(callbacks, null)) { console.error('Initialization failed.'); process.exit(65 /* SysExits.EX_DATAERR */); } let code = null; // Compile: try { code = await compiler.run(inputFilename, program.opts().outFile); } catch (e) { console.error(e); process.exit(65 /* SysExits.EX_DATAERR */); } if (!code) { console.error('Compilation failed.'); process.exit(65 /* SysExits.EX_DATAERR */); } // Output: if (program.opts().outFile) { compiler.write(code.artifacts); } else { // TODO(lowpri): if writing to console then log messages should all be to stderr? const decoder = new TextDecoder(); const text = decoder.decode(code.artifacts.js.data); console.log(text); } function exitDueToUsageError(message) { console.error(`${program.name()}: ${message}`); console.error(); program.outputHelp(); return process.exit(64 /* SysExits.EX_USAGE */); } //# sourceMappingURL=kmlmc.js.map //# debugId=21503a91-4908-5cd1-8ccb-7a4d25cbc88b