/
index.ts
103 lines (97 loc) · 3.5 KB
/
index.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* tslint no-var-requires:0 */
"use strict";
import * as program from "commander";
import * as semver from "semver";
import * as actions from "../actions";
import formatError = require("../actions/formatError");
import showLicense = require("../actions/showLicense");
import * as normalizations from "./normalizations";
import * as validations from "./validations";
import { OutputType, NamedStyleType } from "../types";
// tslint:disable-next-line:no-var-requires
const $package = require("../../package.json");
function presentError(e: Error) {
process.stderr.write(formatError(e) + "\n");
process.exit(1);
}
/* istanbul ignore if */
if (!semver.satisfies(process.versions.node, $package.engines.node)) {
process.stderr.write(
`\nERROR: your node version (${process.versions.node}) is not recent enough.\n`
);
process.stderr.write(
` ${$package.name} needs a version of node ${$package.engines.node}\n\n`
);
/* eslint no-process-exit: 0 */
process.exit(1);
}
try {
program
/* tslint:disable-next-line */
.version(require("../../package.json").version)
.option(
"-T --output-type <type>",
validations.validOutputTypeRE,
(pOutputType) =>
validations.validOutputType(pOutputType as OutputType) as string
)
.option(
"-I --input-type <type>",
validations.validInputTypeRE,
validations.validInputType
)
.option("-i --input-from <file>", "File to read from. use - for stdin.")
.option("-o --output-to <file>", "File to write to. use - for stdout.")
.option("-p --parser-output", "Print parsed msc output")
.option("-s --css <string>", "Additional styles to use. Experimental")
.option(
"-n --named-style <style>",
validations.validNamedStyleRE,
(pNamedStyle) =>
validations.validNamedStyle(pNamedStyle as NamedStyleType) as string
)
.option(
"-m --mirror-entities",
`Repeat the entities on the chart's
bottom`
)
.option(
"-v --vertical-alignment <align>",
`Vertical alignment of labels on regular
arcs. Experimental
${validations.validVerticalAlignmentRE}`,
validations.validVerticalAlignment,
"middle"
)
.option(
"--puppeteer-options <file>",
`(advanced) pass puppeteer launch options
see README.md for details`,
validations.validPuppeteerOptions
)
.option("-l --license", "Display license and exit", () => {
process.stdout.write(showLicense());
process.exit(0);
})
.arguments("[infile]")
.parse(process.argv);
validations
.validateArguments(normalizations.normalize(program.args[0], program))
.then(actions.transform)
.catch(presentError);
} catch (pError) {
presentError(pError);
}
/*
This file is part of mscgenjs-cli.
mscgenjs-cli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
mscgen_js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with mscgenjs-cli. If not, see <http://www.gnu.org/licenses/>.
*/