dep-brain 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cli.js +60 -17
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -6,11 +6,13 @@ import { promises as fs } from "node:fs";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
async function main() {
|
|
8
8
|
const args = process.argv.slice(2);
|
|
9
|
-
const
|
|
9
|
+
const firstArg = args[0];
|
|
10
|
+
const command = firstArg && !firstArg.startsWith("--") ? firstArg : "analyze";
|
|
10
11
|
const optionValues = new Map();
|
|
11
12
|
const flags = new Set();
|
|
12
13
|
const positionals = [];
|
|
13
|
-
|
|
14
|
+
const startIndex = firstArg && !firstArg.startsWith("--") ? 1 : 0;
|
|
15
|
+
for (let index = startIndex; index < args.length; index += 1) {
|
|
14
16
|
const value = args[index];
|
|
15
17
|
if (!value?.startsWith("--")) {
|
|
16
18
|
positionals.push(value);
|
|
@@ -30,6 +32,11 @@ async function main() {
|
|
|
30
32
|
printHelp();
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
35
|
+
if (flags.has("--version")) {
|
|
36
|
+
const version = await loadPackageVersion();
|
|
37
|
+
console.log(version ?? "unknown");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
33
40
|
if (command !== "analyze") {
|
|
34
41
|
if (command === "config") {
|
|
35
42
|
if (!(await hasPackageJson(targetPath))) {
|
|
@@ -37,13 +44,21 @@ async function main() {
|
|
|
37
44
|
process.exitCode = 1;
|
|
38
45
|
return;
|
|
39
46
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
try {
|
|
48
|
+
const config = await analyzeProject({
|
|
49
|
+
rootDir: targetPath,
|
|
50
|
+
configPath: optionValues.get("--config"),
|
|
51
|
+
config: buildCliConfig(flags, optionValues)
|
|
52
|
+
});
|
|
53
|
+
console.log(JSON.stringify(config.config, null, 2));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error("Failed to resolve config.");
|
|
58
|
+
console.error(error);
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
47
62
|
}
|
|
48
63
|
console.error(`Unknown command: ${command}`);
|
|
49
64
|
printHelp();
|
|
@@ -55,14 +70,29 @@ async function main() {
|
|
|
55
70
|
process.exitCode = 1;
|
|
56
71
|
return;
|
|
57
72
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
try {
|
|
74
|
+
const cliConfig = buildCliConfig(flags, optionValues);
|
|
75
|
+
const result = await analyzeProject({
|
|
76
|
+
rootDir: targetPath,
|
|
77
|
+
configPath: optionValues.get("--config"),
|
|
78
|
+
config: cliConfig
|
|
79
|
+
});
|
|
80
|
+
const output = flags.has("--json")
|
|
81
|
+
? renderJsonReport(result)
|
|
82
|
+
: renderConsoleReport(result);
|
|
83
|
+
if (!output || output.trim().length === 0) {
|
|
84
|
+
console.log(renderJsonReport(result));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
console.log(output);
|
|
88
|
+
}
|
|
89
|
+
if (!result.policy.passed) {
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error("Analysis failed.");
|
|
95
|
+
console.error(error);
|
|
66
96
|
process.exitCode = 1;
|
|
67
97
|
}
|
|
68
98
|
}
|
|
@@ -105,6 +135,7 @@ function printHelp() {
|
|
|
105
135
|
console.log(" dep-brain analyze [path] [--json] [--config path] [--min-score n] [--fail-on-risks] [--fail-on-outdated] [--fail-on-unused] [--fail-on-duplicates]");
|
|
106
136
|
console.log(" dep-brain config [path] [--config path]");
|
|
107
137
|
console.log(" dep-brain help");
|
|
138
|
+
console.log(" dep-brain --version");
|
|
108
139
|
console.log("");
|
|
109
140
|
console.log("Options:");
|
|
110
141
|
console.log(" --json Output JSON for analysis");
|
|
@@ -115,4 +146,16 @@ function printHelp() {
|
|
|
115
146
|
console.log(" --fail-on-unused Fail when unused dependencies exist");
|
|
116
147
|
console.log(" --fail-on-duplicates Fail when duplicates exist");
|
|
117
148
|
console.log(" --help Show this help output");
|
|
149
|
+
console.log(" --version Show CLI version");
|
|
150
|
+
}
|
|
151
|
+
async function loadPackageVersion() {
|
|
152
|
+
try {
|
|
153
|
+
const pkgPath = new URL("../package.json", import.meta.url);
|
|
154
|
+
const content = await fs.readFile(pkgPath, "utf8");
|
|
155
|
+
const pkg = JSON.parse(content);
|
|
156
|
+
return pkg.version ?? null;
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
118
161
|
}
|