UNPKG

2.01 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4const CliProc = require("@chlorophytum/cli-proc");
5const program = require("commander");
6const fs = require("fs");
7const json5 = require("json5");
8const _ = require("lodash");
9const path = require("path");
10const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json"), "utf8"));
11program.version(packageJson.version);
12function readProcOptions(from) {
13 if (!from)
14 throw new TypeError("Configuration file is mandatory");
15 const ho = json5.parse(fs.readFileSync(from, "utf-8"));
16 return ho;
17}
18program
19 .command("hint <font> <toHint> [others...]")
20 .option("-c, --config <json>", "Configuration file")
21 .option("-h, --cache <cache.gz>", "Hint cache file")
22 .option("-j, --jobs <jobs>", "Jobs in parallel")
23 .action(WithErrors(async (font, toHint, rest, options) => {
24 const ho = readProcOptions(options.config);
25 if (options.jobs)
26 ho.jobs = options.jobs || 0;
27 const jobFiles = [font, toHint, ...(rest || [])];
28 await CliProc.doHint(Object.assign(Object.assign({}, ho), { cacheFilePath: options.cache }), _.chunk(jobFiles, 2));
29}));
30program
31 .command("instruct <font> <hints> <font-output> [others...]")
32 .option("-c, --config <json>", "Configuration file")
33 .action(WithErrors(async (font, hints, fontOut, rest, options) => {
34 const ho = readProcOptions(options.config);
35 const jobFiles = [font, hints, fontOut, ...(rest || [])];
36 await CliProc.doInstruct(ho, _.chunk(jobFiles, 3));
37}));
38program.parse(process.argv);
39///////////////////////////////////////////////////////////////////////////////////////////////////
40function WithErrors(command) {
41 return async (...args) => {
42 try {
43 await command(...args);
44 }
45 catch (e) {
46 console.error(e);
47 process.exitCode = 1;
48 }
49 };
50}
51//# sourceMappingURL=index.js.map
\No newline at end of file