-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcli.js
61 lines (50 loc) · 1.65 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
const baseDEBUG = require('./DEBUG');
const error = console.error
const log = console.log
const program = require('commander');
const inklecate = require('./inklecate');
const { version } = require('./package.json');
const { assertValid } = require('ts-assertions');
program
.version(version)
.usage('inklecate <options> <inputFilepath>')
.option('-v', 'Get the version identifier.', () => {
log(version);
process.exit(0);
})
.option('-o, --outputFile <outputFile>', 'Output file name')
.option('-c', 'Count all visits to knots, stitches and weave points, not\n' +
'just those referenced by TURNS_SINCE and read counts')
.option('--verbose', 'Verbose mode - print compilation timings')
.option('--DEBUG', 'Enable debug mode for inklecate-node (not inklecate).')
.parse(process.argv);
const DEBUG = baseDEBUG || program.DEBUG;
const inputFilepath = assertValid(
program.args.find((arg) => arg[0] !== '-'),
'No input filepath was found.',
(result) => result.length,
);
const opts = Object.freeze({
inputFilepath,
countAllVisits: Boolean(program.c),
outputFilepath: program.outputFile || null,
verbose: Boolean(program.verbose),
DEBUG: Boolean(program.DEBUG),
});
inklecate(opts).then(
(data) => {
DEBUG && log('inklecate-node has completed.');
if (!data ||
(Array.isArray(data) && !data.length) ||
!Object.keys(data).length)
{
DEBUG && error('The return value from inklecate was null or undefined.');
error('No result from inklecate-node.');
return;
}
DEBUG && log('inklecate-node is outputting the response.');
log(data);
},
error,
);