UNPKG

1.59 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 .description(
22 "Format dependency-cruiser output json.\nDetails: https://github.com/sverweij/dependency-cruiser"
23 )
24 .option(
25 "-f, --output-to <file>",
26 "file to write output to; - for stdout",
27 "-"
28 )
29 .option(
30 "-T, --output-type <type>",
31 "output type; e.g. err, err-html, dot, ddot, archi or json",
32 "err"
33 )
34 .option(
35 "-e, --exit-code",
36 "exit with a non-zero exit code when the input json contains error level " +
37 "dependency violations. Works for err, err-long and teamcity output types"
38 )
39 .version($package.version)
40 .arguments("<dependency-cruiser-json>")
41 .parse(process.argv);
42
43 if (program.args[0]) {
44 format(program.args[0], program)
45 .then((pExitCode) => {
46 if (program.exitCode) {
47 process.exitCode = pExitCode;
48 }
49 })
50 .catch(formatError);
51 } else {
52 program.help();
53 }
54} catch (pError) {
55 formatError(pError);
56}