dep-brain 0.1.1 → 0.1.2

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/dist/cli.js +52 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,6 +51,7 @@ dep-brain config --config depbrain.config.json
51
51
 
52
52
  dep-brain help
53
53
  dep-brain analyze --help
54
+ dep-brain --version
54
55
  ```
55
56
 
56
57
  ## Workspaces
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 command = args[0] ?? "analyze";
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
- for (let index = 1; index < args.length; index += 1) {
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
- const config = await analyzeProject({
41
- rootDir: targetPath,
42
- configPath: optionValues.get("--config"),
43
- config: buildCliConfig(flags, optionValues)
44
- });
45
- console.log(JSON.stringify(config.config, null, 2));
46
- return;
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,21 @@ async function main() {
55
70
  process.exitCode = 1;
56
71
  return;
57
72
  }
58
- const cliConfig = buildCliConfig(flags, optionValues);
59
- const result = await analyzeProject({
60
- rootDir: targetPath,
61
- configPath: optionValues.get("--config"),
62
- config: cliConfig
63
- });
64
- console.log(flags.has("--json") ? renderJsonReport(result) : renderConsoleReport(result));
65
- if (!result.policy.passed) {
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
+ console.log(flags.has("--json") ? renderJsonReport(result) : renderConsoleReport(result));
81
+ if (!result.policy.passed) {
82
+ process.exitCode = 1;
83
+ }
84
+ }
85
+ catch (error) {
86
+ console.error("Analysis failed.");
87
+ console.error(error);
66
88
  process.exitCode = 1;
67
89
  }
68
90
  }
@@ -105,6 +127,7 @@ function printHelp() {
105
127
  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
128
  console.log(" dep-brain config [path] [--config path]");
107
129
  console.log(" dep-brain help");
130
+ console.log(" dep-brain --version");
108
131
  console.log("");
109
132
  console.log("Options:");
110
133
  console.log(" --json Output JSON for analysis");
@@ -115,4 +138,16 @@ function printHelp() {
115
138
  console.log(" --fail-on-unused Fail when unused dependencies exist");
116
139
  console.log(" --fail-on-duplicates Fail when duplicates exist");
117
140
  console.log(" --help Show this help output");
141
+ console.log(" --version Show CLI version");
142
+ }
143
+ async function loadPackageVersion() {
144
+ try {
145
+ const pkgPath = new URL("../package.json", import.meta.url);
146
+ const content = await fs.readFile(pkgPath, "utf8");
147
+ const pkg = JSON.parse(content);
148
+ return pkg.version ?? null;
149
+ }
150
+ catch {
151
+ return null;
152
+ }
118
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dep-brain",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "CLI and library for dependency health analysis",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",