UNPKG

1.68 kBJavaScriptView Raw
1#!/usr/bin/env node
2const validateNodeEnvironment = require("../src/cli/validate-node-environment");
3
4function formatError(pError) {
5 process.stderr.write(pError.message);
6 process.exitCode = 1;
7}
8
9try {
10 validateNodeEnvironment();
11
12 // importing things only after the validateNodeEnv check so we can show an understandable
13 // error. Otherwise, on unsupported platforms we would show a stack trace, which is
14 // not so nice
15 /* eslint-disable node/global-require */
16 const program = require("commander");
17 const $package = require("../package.json");
18 const format = require("../src/cli/format");
19
20 program
21 .version($package.version)
22 .description(
23 "Format dependency-cruiser output json.\nDetails: https://github.com/sverweij/dependency-cruiser"
24 )
25 .option(
26 "-f, --output-to <file>",
27 `file to write output to; - for stdout
28 `,
29 "-"
30 )
31 .option(
32 "-T, --output-type <type>",
33 `output type - err|err-long|err-html|dot|ddot|archi|json
34 `,
35 "err"
36 )
37 .option(
38 "-e, --exit-code",
39 `exit with a non-zero exit code when the input json
40 contains error level dependency violations. Works for
41 err, err-long and teamcity output types`
42 )
43 .arguments("<dependency-cruiser-json>")
44 .parse(process.argv);
45
46 if (program.args[0]) {
47 format(program.args[0], program)
48 .then((pExitCode) => {
49 if (program.exitCode) {
50 process.exitCode = pExitCode;
51 }
52 })
53 .catch(formatError);
54 } else {
55 program.help();
56 }
57} catch (pError) {
58 formatError(pError);
59}