1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | const CliProc = require("@chlorophytum/cli-proc");
|
5 | const program = require("commander");
|
6 | const fs = require("fs");
|
7 | const json5 = require("json5");
|
8 | const _ = require("lodash");
|
9 | const path = require("path");
|
10 | const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json"), "utf8"));
|
11 | program.version(packageJson.version);
|
12 | function 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 | }
|
18 | program
|
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 | }));
|
30 | program
|
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 | }));
|
38 | program.parse(process.argv);
|
39 |
|
40 | function 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 |
|
\ | No newline at end of file |