@nebulord/sickbay 0.1.0

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.
@@ -0,0 +1,375 @@
1
+ import {
2
+ Header
3
+ } from "./chunk-BIK4EL4H.js";
4
+ import {
5
+ shortName
6
+ } from "./chunk-BUD5BE6U.js";
7
+
8
+ // src/components/StatsApp.tsx
9
+ import React, { useState, useEffect } from "react";
10
+ import { Box, Text, useApp } from "ink";
11
+ import Spinner from "ink-spinner";
12
+
13
+ // src/commands/stats.ts
14
+ import { readFileSync, readdirSync, statSync, existsSync } from "fs";
15
+ import { join, extname } from "path";
16
+ import { execSync } from "child_process";
17
+ import { detectProject } from "@nebulord/sickbay-core";
18
+ var IGNORE_DIRS = /* @__PURE__ */ new Set([
19
+ "node_modules",
20
+ ".git",
21
+ "dist",
22
+ "build",
23
+ ".next",
24
+ "coverage",
25
+ ".turbo",
26
+ ".cache",
27
+ ".vite",
28
+ "__pycache__",
29
+ ".svelte-kit"
30
+ ]);
31
+ var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
32
+ ".ts",
33
+ ".tsx",
34
+ ".js",
35
+ ".jsx",
36
+ ".mjs",
37
+ ".cjs",
38
+ ".css",
39
+ ".scss",
40
+ ".less",
41
+ ".sass",
42
+ ".json",
43
+ ".html",
44
+ ".svg",
45
+ ".vue",
46
+ ".svelte"
47
+ ]);
48
+ function walkDir(dir, extensions) {
49
+ const results = [];
50
+ try {
51
+ const entries = readdirSync(dir, { withFileTypes: true });
52
+ for (const entry of entries) {
53
+ if (entry.name.startsWith(".") && entry.isDirectory()) continue;
54
+ if (IGNORE_DIRS.has(entry.name)) continue;
55
+ const fullPath = join(dir, entry.name);
56
+ if (entry.isDirectory()) {
57
+ results.push(...walkDir(fullPath, extensions));
58
+ } else {
59
+ const ext = extname(entry.name).toLowerCase();
60
+ if (extensions.has(ext)) {
61
+ results.push({ path: fullPath, ext });
62
+ }
63
+ }
64
+ }
65
+ } catch {
66
+ }
67
+ return results;
68
+ }
69
+ function countLines(filePath) {
70
+ try {
71
+ const content = readFileSync(filePath, "utf-8");
72
+ return content.split("\n").length;
73
+ } catch {
74
+ return 0;
75
+ }
76
+ }
77
+ function countComponents(filePath) {
78
+ try {
79
+ const content = readFileSync(filePath, "utf-8");
80
+ const functional = (content.match(
81
+ /(?:export\s+)?(?:default\s+)?function\s+[A-Z]\w*\s*\(/g
82
+ ) ?? []).length + (content.match(
83
+ /(?:export\s+)?(?:default\s+)?const\s+[A-Z]\w*\s*[=:]\s*(?:\(|React\.)/g
84
+ ) ?? []).length;
85
+ const classBased = (content.match(
86
+ /class\s+[A-Z]\w*\s+extends\s+(?:React\.)?(?:Component|PureComponent)/g
87
+ ) ?? []).length;
88
+ return { functional, classBased };
89
+ } catch {
90
+ return { functional: 0, classBased: 0 };
91
+ }
92
+ }
93
+ function getGitInfo(projectPath) {
94
+ try {
95
+ if (!existsSync(join(projectPath, ".git"))) return null;
96
+ const commits = parseInt(
97
+ execSync("git rev-list --count HEAD", {
98
+ cwd: projectPath,
99
+ encoding: "utf-8"
100
+ }).trim(),
101
+ 10
102
+ );
103
+ const contributors = parseInt(
104
+ execSync("git log --format='%ae' | sort -u | wc -l", {
105
+ cwd: projectPath,
106
+ encoding: "utf-8",
107
+ shell: "/bin/sh"
108
+ }).trim(),
109
+ 10
110
+ );
111
+ const firstCommit = execSync("git log --reverse --format='%ar' | head -1", {
112
+ cwd: projectPath,
113
+ encoding: "utf-8",
114
+ shell: "/bin/sh"
115
+ }).trim();
116
+ const branch = execSync("git branch --show-current", {
117
+ cwd: projectPath,
118
+ encoding: "utf-8"
119
+ }).trim();
120
+ return { commits, contributors, age: firstCommit, branch };
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
125
+ function formatBytes(bytes) {
126
+ if (bytes < 1024) return `${bytes} B`;
127
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
128
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
129
+ }
130
+ async function gatherStats(projectPath) {
131
+ const project = await detectProject(projectPath);
132
+ const files = walkDir(projectPath, SOURCE_EXTENSIONS);
133
+ const byExtension = {};
134
+ for (const f of files) {
135
+ byExtension[f.ext] = (byExtension[f.ext] ?? 0) + 1;
136
+ }
137
+ let totalLines = 0;
138
+ let totalFunctional = 0;
139
+ let totalClassBased = 0;
140
+ let testFiles = 0;
141
+ let totalBytes = 0;
142
+ const componentExts = /* @__PURE__ */ new Set([".tsx", ".jsx", ".js", ".ts"]);
143
+ for (const f of files) {
144
+ const lines = countLines(f.path);
145
+ totalLines += lines;
146
+ try {
147
+ totalBytes += statSync(f.path).size;
148
+ } catch {
149
+ }
150
+ if (componentExts.has(f.ext)) {
151
+ const { functional, classBased } = countComponents(f.path);
152
+ totalFunctional += functional;
153
+ totalClassBased += classBased;
154
+ }
155
+ const name = f.path.toLowerCase();
156
+ if (name.includes(".test.") || name.includes(".spec.") || name.includes("__tests__")) {
157
+ testFiles++;
158
+ }
159
+ }
160
+ const git = getGitInfo(projectPath);
161
+ return {
162
+ project,
163
+ files: {
164
+ total: files.length,
165
+ byExtension
166
+ },
167
+ lines: {
168
+ total: totalLines,
169
+ avgPerFile: files.length > 0 ? Math.round(totalLines / files.length) : 0
170
+ },
171
+ components: {
172
+ total: totalFunctional + totalClassBased,
173
+ functional: totalFunctional,
174
+ classBased: totalClassBased
175
+ },
176
+ dependencies: {
177
+ prod: Object.keys(project.dependencies).length,
178
+ dev: Object.keys(project.devDependencies).length,
179
+ total: project.totalDependencies
180
+ },
181
+ git,
182
+ testFiles,
183
+ sourceSize: formatBytes(totalBytes)
184
+ };
185
+ }
186
+
187
+ // src/components/StatsApp.tsx
188
+ var FRAMEWORK_LABELS = {
189
+ next: "Next.js",
190
+ vite: "Vite",
191
+ cra: "Create React App",
192
+ react: "React",
193
+ unknown: "Unknown"
194
+ };
195
+ var PM_LABELS = {
196
+ npm: "npm",
197
+ pnpm: "pnpm",
198
+ yarn: "Yarn"
199
+ };
200
+ function StatRow({
201
+ label,
202
+ value,
203
+ dimValue
204
+ }) {
205
+ return /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, label.padEnd(18)), /* @__PURE__ */ React.createElement(Text, { bold: true }, value), dimValue && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ", dimValue));
206
+ }
207
+ function formatExtBreakdown(byExtension) {
208
+ const sorted = Object.entries(byExtension).sort((a, b) => b[1] - a[1]).slice(0, 6);
209
+ return sorted.map(([ext, count]) => `${ext}: ${count}`).join(", ");
210
+ }
211
+ function ToolBadges({ project }) {
212
+ const badges = [
213
+ { label: "TypeScript", active: project.hasTypeScript },
214
+ { label: "ESLint", active: project.hasESLint },
215
+ { label: "Prettier", active: project.hasPrettier }
216
+ ];
217
+ return /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "Tooling".padEnd(18)), badges.map((b, i) => /* @__PURE__ */ React.createElement(React.Fragment, { key: b.label }, i > 0 && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " "), /* @__PURE__ */ React.createElement(Text, { color: b.active ? "green" : "red" }, b.active ? "\u2713" : "\u2717", " ", b.label))));
218
+ }
219
+ function SingleProjectStats({ stats }) {
220
+ const {
221
+ project,
222
+ files,
223
+ lines,
224
+ components,
225
+ dependencies,
226
+ git,
227
+ testFiles,
228
+ sourceSize
229
+ } = stats;
230
+ const frameworkLabel = FRAMEWORK_LABELS[project.framework] ?? project.framework;
231
+ const techStack = [frameworkLabel];
232
+ if (project.hasTypeScript) {
233
+ const tsVersion = { ...project.dependencies, ...project.devDependencies }["typescript"];
234
+ techStack.push(
235
+ `TypeScript${tsVersion ? ` ${tsVersion.replace("^", "")}` : ""}`
236
+ );
237
+ }
238
+ const reactVersion = project.dependencies["react"] ?? project.devDependencies["react"];
239
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2 }, /* @__PURE__ */ React.createElement(
240
+ StatRow,
241
+ {
242
+ label: "Framework",
243
+ value: frameworkLabel,
244
+ dimValue: reactVersion ? `(React ${reactVersion.replace("^", "")})` : void 0
245
+ }
246
+ ), /* @__PURE__ */ React.createElement(
247
+ StatRow,
248
+ {
249
+ label: "Package Manager",
250
+ value: PM_LABELS[project.packageManager] ?? project.packageManager
251
+ }
252
+ ), /* @__PURE__ */ React.createElement(ToolBadges, { project })), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, marginLeft: 2, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u2501".repeat(48))), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2 }, /* @__PURE__ */ React.createElement(
253
+ StatRow,
254
+ {
255
+ label: "Files",
256
+ value: `${files.total}`,
257
+ dimValue: `(${formatExtBreakdown(files.byExtension)})`
258
+ }
259
+ ), /* @__PURE__ */ React.createElement(
260
+ StatRow,
261
+ {
262
+ label: "Lines of Code",
263
+ value: lines.total.toLocaleString(),
264
+ dimValue: `(avg ${lines.avgPerFile}/file)`
265
+ }
266
+ ), /* @__PURE__ */ React.createElement(StatRow, { label: "Source Size", value: sourceSize })), components.total > 0 && /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2 }, /* @__PURE__ */ React.createElement(
267
+ StatRow,
268
+ {
269
+ label: "Components",
270
+ value: `${components.total}`,
271
+ dimValue: `(${components.functional} functional${components.classBased > 0 ? `, ${components.classBased} class` : ""})`
272
+ }
273
+ )), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2 }, /* @__PURE__ */ React.createElement(
274
+ StatRow,
275
+ {
276
+ label: "Dependencies",
277
+ value: `${dependencies.total}`,
278
+ dimValue: `(prod: ${dependencies.prod}, dev: ${dependencies.dev})`
279
+ }
280
+ ), /* @__PURE__ */ React.createElement(
281
+ StatRow,
282
+ {
283
+ label: "Test Files",
284
+ value: `${testFiles}`,
285
+ dimValue: files.total > 0 ? `(covering ${Math.round(testFiles / files.total * 100)}% of files)` : void 0
286
+ }
287
+ )), git && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Box, { marginTop: 1, marginLeft: 2, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u2501".repeat(48))), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2 }, /* @__PURE__ */ React.createElement(StatRow, { label: "Git Branch", value: git.branch }), /* @__PURE__ */ React.createElement(
288
+ StatRow,
289
+ {
290
+ label: "Commits",
291
+ value: `${git.commits}`,
292
+ dimValue: `by ${git.contributors} contributor${git.contributors !== 1 ? "s" : ""}`
293
+ }
294
+ ), /* @__PURE__ */ React.createElement(StatRow, { label: "Project Age", value: git.age }))));
295
+ }
296
+ function StatsApp({
297
+ projectPath,
298
+ jsonOutput,
299
+ isMonorepo,
300
+ packagePaths,
301
+ packageNames
302
+ }) {
303
+ const { exit } = useApp();
304
+ const [stats, setStats] = useState(null);
305
+ const [packageStats, setPackageStats] = useState([]);
306
+ const [loading, setLoading] = useState(true);
307
+ const [error, setError] = useState(null);
308
+ useEffect(() => {
309
+ if (isMonorepo && packagePaths && packageNames) {
310
+ Promise.all(
311
+ packagePaths.map(async (pkgPath) => {
312
+ const name = packageNames.get(pkgPath) ?? pkgPath;
313
+ const s = await gatherStats(pkgPath);
314
+ return { name, path: pkgPath, stats: s };
315
+ })
316
+ ).then((all) => {
317
+ setPackageStats(all);
318
+ setLoading(false);
319
+ if (jsonOutput) {
320
+ const output = all.map((p) => ({
321
+ package: p.name,
322
+ path: p.path,
323
+ stats: p.stats
324
+ }));
325
+ process.stdout.write(JSON.stringify(output, null, 2) + "\n");
326
+ }
327
+ setTimeout(() => exit(), 100);
328
+ }).catch((err) => {
329
+ setError(err instanceof Error ? err.message : String(err));
330
+ setLoading(false);
331
+ setTimeout(() => exit(), 100);
332
+ });
333
+ } else {
334
+ gatherStats(projectPath).then((s) => {
335
+ setStats(s);
336
+ setLoading(false);
337
+ if (jsonOutput) {
338
+ process.stdout.write(JSON.stringify(s, null, 2) + "\n");
339
+ }
340
+ setTimeout(() => exit(), 100);
341
+ }).catch((err) => {
342
+ setError(err instanceof Error ? err.message : String(err));
343
+ setLoading(false);
344
+ setTimeout(() => exit(), 100);
345
+ });
346
+ }
347
+ }, []);
348
+ if (loading) {
349
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", padding: 1 }, /* @__PURE__ */ React.createElement(Header, null), /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { color: "green" }, /* @__PURE__ */ React.createElement(Spinner, { type: "dots" })), " ", "Scanning project", isMonorepo ? ` (${packagePaths?.length} packages)` : "", "..."));
350
+ }
351
+ if (error) {
352
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", padding: 1 }, /* @__PURE__ */ React.createElement(Header, null), /* @__PURE__ */ React.createElement(Text, { color: "red" }, "\u2717 Error: ", error));
353
+ }
354
+ if (jsonOutput) return null;
355
+ if (isMonorepo && packageStats.length > 0) {
356
+ const totals = packageStats.reduce(
357
+ (acc, p) => ({
358
+ files: acc.files + p.stats.files.total,
359
+ lines: acc.lines + p.stats.lines.total,
360
+ deps: acc.deps + p.stats.dependencies.total,
361
+ tests: acc.tests + p.stats.testFiles
362
+ }),
363
+ { files: 0, lines: 0, deps: 0, tests: 0 }
364
+ );
365
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", padding: 1 }, /* @__PURE__ */ React.createElement(Header, null), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Monorepo Overview"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, packageStats.length, " packages"), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2 }, /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Package".padEnd(36)), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Framework".padEnd(14)), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Files".padEnd(8)), /* @__PURE__ */ React.createElement(Text, { bold: true }, "LOC".padEnd(10)), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Deps".padEnd(8)), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Tests")), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u2501".repeat(84)), packageStats.map((pkg) => {
366
+ const fw = FRAMEWORK_LABELS[pkg.stats.project.framework] ?? pkg.stats.project.framework;
367
+ return /* @__PURE__ */ React.createElement(Box, { key: pkg.path }, /* @__PURE__ */ React.createElement(Text, { color: "cyan" }, shortName(pkg.name).padEnd(36)), /* @__PURE__ */ React.createElement(Text, null, fw.padEnd(14)), /* @__PURE__ */ React.createElement(Text, null, String(pkg.stats.files.total).padEnd(8)), /* @__PURE__ */ React.createElement(Text, null, pkg.stats.lines.total.toLocaleString().padEnd(10)), /* @__PURE__ */ React.createElement(Text, null, String(pkg.stats.dependencies.total).padEnd(8)), /* @__PURE__ */ React.createElement(Text, null, pkg.stats.testFiles));
368
+ }), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u2501".repeat(84)), /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Total".padEnd(36)), /* @__PURE__ */ React.createElement(Text, null, "".padEnd(14)), /* @__PURE__ */ React.createElement(Text, { bold: true }, String(totals.files).padEnd(8)), /* @__PURE__ */ React.createElement(Text, { bold: true }, totals.lines.toLocaleString().padEnd(10)), /* @__PURE__ */ React.createElement(Text, { bold: true }, String(totals.deps).padEnd(8)), /* @__PURE__ */ React.createElement(Text, { bold: true }, totals.tests))));
369
+ }
370
+ if (!stats) return null;
371
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", padding: 1 }, /* @__PURE__ */ React.createElement(Header, { projectName: stats.project.name }), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Codebase Overview"), /* @__PURE__ */ React.createElement(SingleProjectStats, { stats }));
372
+ }
373
+ export {
374
+ StatsApp
375
+ };
@@ -0,0 +1,118 @@
1
+ import {
2
+ sparkline,
3
+ trendArrow
4
+ } from "./chunk-SSUXSMGH.js";
5
+ import {
6
+ detectRegressions,
7
+ loadHistory
8
+ } from "./chunk-5KJOYSVJ.js";
9
+ import {
10
+ Header
11
+ } from "./chunk-BIK4EL4H.js";
12
+ import {
13
+ shortName
14
+ } from "./chunk-BUD5BE6U.js";
15
+
16
+ // src/components/TrendApp.tsx
17
+ import React, { useState, useEffect } from "react";
18
+ import { Box, Text, useApp } from "ink";
19
+ var CATEGORIES = [
20
+ "dependencies",
21
+ "security",
22
+ "code-quality",
23
+ "performance",
24
+ "git"
25
+ ];
26
+ var CATEGORY_LABELS = {
27
+ dependencies: "Dependencies",
28
+ security: "Security",
29
+ "code-quality": "Code Quality",
30
+ performance: "Performance",
31
+ git: "Git"
32
+ };
33
+ function trendColor(direction) {
34
+ if (direction === "up") return "green";
35
+ if (direction === "down") return "red";
36
+ return "gray";
37
+ }
38
+ function SingleTrendView({
39
+ history,
40
+ last
41
+ }) {
42
+ const entries = history.entries.slice(-last);
43
+ const scores = entries.map((e) => e.overallScore);
44
+ const overall = trendArrow(scores);
45
+ const regressions = detectRegressions(entries);
46
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Score History"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, entries.length, " scan", entries.length !== 1 ? "s" : "", " recorded"), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, marginLeft: 2, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Overall".padEnd(15)), /* @__PURE__ */ React.createElement(Text, { color: trendColor(overall.direction) }, sparkline(scores)), /* @__PURE__ */ React.createElement(Text, { bold: true }, " ", scores[scores.length - 1], "/100 "), /* @__PURE__ */ React.createElement(Text, { color: trendColor(overall.direction) }, overall.label)), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, flexDirection: "column" }, CATEGORIES.map((cat) => {
47
+ const catScores = entries.map((e) => e.categoryScores[cat]).filter((s) => s !== void 0);
48
+ if (catScores.length === 0) return null;
49
+ const catTrend = trendArrow(catScores);
50
+ return /* @__PURE__ */ React.createElement(Box, { key: cat }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, (CATEGORY_LABELS[cat] ?? cat).padEnd(15)), /* @__PURE__ */ React.createElement(Text, { color: trendColor(catTrend.direction) }, sparkline(catScores)), /* @__PURE__ */ React.createElement(Text, null, " ", catScores[catScores.length - 1], "/100 "), /* @__PURE__ */ React.createElement(Text, { color: trendColor(catTrend.direction) }, catTrend.label));
51
+ }))), regressions.length > 0 && /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: "red" }, "Regressions Detected:"), regressions.map((r) => /* @__PURE__ */ React.createElement(Box, { key: r.category, marginLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { color: "red" }, "\u2193 ", CATEGORY_LABELS[r.category] ?? r.category, ": ", r.from, " \u2192", " ", r.to, " (-", r.drop, " pts)")))), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u2501".repeat(52))), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "First scan: ", new Date(entries[0].timestamp).toLocaleDateString(), " \xB7 ", "Latest:", " ", new Date(
52
+ entries[entries.length - 1].timestamp
53
+ ).toLocaleDateString())));
54
+ }
55
+ function TrendApp({
56
+ projectPath,
57
+ last,
58
+ jsonOutput,
59
+ isMonorepo,
60
+ packagePaths,
61
+ packageNames
62
+ }) {
63
+ const { exit } = useApp();
64
+ const [history, setHistory] = useState(null);
65
+ const [packageTrends, setPackageTrends] = useState([]);
66
+ const [loaded, setLoaded] = useState(false);
67
+ useEffect(() => {
68
+ if (isMonorepo && packagePaths && packageNames) {
69
+ const trends = packagePaths.map((pkgPath) => {
70
+ const name = packageNames.get(pkgPath) ?? pkgPath;
71
+ const h = loadHistory(pkgPath);
72
+ return { name, path: pkgPath, history: h };
73
+ });
74
+ setPackageTrends(trends);
75
+ setLoaded(true);
76
+ if (jsonOutput) {
77
+ const output = trends.map((t) => ({
78
+ package: t.name,
79
+ path: t.path,
80
+ history: t.history
81
+ }));
82
+ process.stdout.write(JSON.stringify(output, null, 2) + "\n");
83
+ }
84
+ setTimeout(() => exit(), 100);
85
+ } else {
86
+ const h = loadHistory(projectPath);
87
+ setHistory(h);
88
+ setLoaded(true);
89
+ if (jsonOutput && h) {
90
+ process.stdout.write(JSON.stringify(h, null, 2) + "\n");
91
+ }
92
+ setTimeout(() => exit(), 100);
93
+ }
94
+ }, []);
95
+ if (!loaded) return null;
96
+ if (jsonOutput) return null;
97
+ if (isMonorepo && packageTrends.length > 0) {
98
+ const withHistory = packageTrends.filter(
99
+ (t) => t.history && t.history.entries.length > 0
100
+ );
101
+ if (withHistory.length === 0) {
102
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", padding: 1 }, /* @__PURE__ */ React.createElement(Header, null), /* @__PURE__ */ React.createElement(Text, { color: "yellow" }, "No scan history found for any package in this monorepo."), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "Run "), /* @__PURE__ */ React.createElement(Text, { color: "cyan" }, "sickbay --package <name>"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " first to start tracking scores.")));
103
+ }
104
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", padding: 1 }, /* @__PURE__ */ React.createElement(Header, null), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Monorepo Score Trends"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, withHistory.length, " of ", packageTrends.length, " packages have history"), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2 }, /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Package".padEnd(24)), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Trend".padEnd(22)), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Score".padEnd(10)), /* @__PURE__ */ React.createElement(Text, { bold: true }, "Direction")), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u2501".repeat(64)), withHistory.map((pkg) => {
105
+ const entries = pkg.history.entries.slice(-last);
106
+ const scores = entries.map((e) => e.overallScore);
107
+ const trend = trendArrow(scores);
108
+ return /* @__PURE__ */ React.createElement(Box, { key: pkg.path }, /* @__PURE__ */ React.createElement(Text, { color: "cyan" }, shortName(pkg.name).padEnd(24)), /* @__PURE__ */ React.createElement(Text, { color: trendColor(trend.direction) }, sparkline(scores).padEnd(22)), /* @__PURE__ */ React.createElement(Text, { bold: true }, String(scores[scores.length - 1]).padEnd(10)), /* @__PURE__ */ React.createElement(Text, { color: trendColor(trend.direction) }, trend.label));
109
+ })), packageTrends.length > withHistory.length && /* @__PURE__ */ React.createElement(Box, { marginTop: 1, marginLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, packageTrends.length - withHistory.length, " package", packageTrends.length - withHistory.length !== 1 ? "s" : "", " with no history yet")));
110
+ }
111
+ if (!history || history.entries.length === 0) {
112
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", padding: 1 }, /* @__PURE__ */ React.createElement(Header, null), /* @__PURE__ */ React.createElement(Text, { color: "yellow" }, "No scan history found for this project."), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "Run "), /* @__PURE__ */ React.createElement(Text, { color: "cyan" }, "sickbay"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " first to start tracking scores.")));
113
+ }
114
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", padding: 1 }, /* @__PURE__ */ React.createElement(Header, { projectName: history.projectName }), /* @__PURE__ */ React.createElement(SingleTrendView, { history, last }));
115
+ }
116
+ export {
117
+ TrendApp
118
+ };