@ridit/lens 0.3.3 → 0.3.4

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.
@@ -7,10 +7,13 @@ export const LENS_FILENAME = "LENS.md";
7
7
  export type LensFile = {
8
8
  overview: string;
9
9
  importantFolders: string[];
10
- missingConfigs: string[];
11
- securityIssues: string[];
10
+ tooling: Record<string, string>;
11
+ keyFiles: string[];
12
+ patterns: string[];
13
+ architecture: string;
12
14
  suggestions: string[];
13
15
  generatedAt: string;
16
+ lastUpdated: string;
14
17
  };
15
18
 
16
19
  export function lensFilePath(repoPath: string): string {
@@ -21,36 +24,96 @@ export function lensFileExists(repoPath: string): boolean {
21
24
  return existsSync(lensFilePath(repoPath));
22
25
  }
23
26
 
24
- export function writeLensFile(repoPath: string, result: AnalysisResult): void {
25
- const data: LensFile = {
26
- ...result,
27
- generatedAt: new Date().toISOString(),
28
- };
27
+ function renderLensFile(data: LensFile): string {
28
+ const toolingLines = Object.entries(data.tooling)
29
+ .map(([k, v]) => `- **${k}**: ${v}`)
30
+ .join("\n");
29
31
 
30
- const content = `# Lens Analysis
31
- > Generated: ${data.generatedAt}
32
+ return `# Lens
33
+ > Generated: ${data.generatedAt}${data.lastUpdated !== data.generatedAt ? ` | Updated: ${data.lastUpdated}` : ""}
32
34
 
33
35
  ## Overview
34
36
  ${data.overview}
35
37
 
38
+ ## Architecture
39
+ ${data.architecture}
40
+
41
+ ## Tooling & Conventions
42
+ ${toolingLines || "- Not yet determined"}
43
+
36
44
  ## Important Folders
37
- ${data.importantFolders.map((f) => `- ${f}`).join("\n")}
45
+ ${data.importantFolders.map((f) => `- ${f}`).join("\n") || "- None"}
38
46
 
39
- ## Missing Configs
40
- ${data.missingConfigs.length > 0 ? data.missingConfigs.map((f) => `- ${f}`).join("\n") : "- None detected"}
47
+ ## Key Files
48
+ ${data.keyFiles.map((f) => `- ${f}`).join("\n") || "- None"}
41
49
 
42
- ## Security Issues
43
- ${data.securityIssues.length > 0 ? data.securityIssues.map((s) => `- ${s}`).join("\n") : "- None detected"}
50
+ ## Patterns & Idioms
51
+ ${data.patterns.map((p) => `- ${p}`).join("\n") || "- None"}
44
52
 
45
53
  ## Suggestions
46
- ${data.suggestions.map((s) => `- ${s}`).join("\n")}
54
+ ${data.suggestions.map((s) => `- ${s}`).join("\n") || "- None"}
47
55
 
48
56
  <!--lens-json
49
57
  ${JSON.stringify(data)}
50
58
  lens-json-->
51
59
  `;
60
+ }
61
+
62
+ export function writeLensFile(repoPath: string, result: AnalysisResult): void {
63
+ const now = new Date().toISOString();
64
+ const data: LensFile = {
65
+ overview: result.overview,
66
+ importantFolders: result.importantFolders,
67
+ tooling: result.tooling ?? {},
68
+ keyFiles: result.keyFiles ?? [],
69
+ patterns: result.patterns ?? [],
70
+ architecture: result.architecture ?? "",
71
+ suggestions: result.suggestions,
72
+ generatedAt: now,
73
+ lastUpdated: now,
74
+ };
75
+ writeFileSync(lensFilePath(repoPath), renderLensFile(data), "utf-8");
76
+ }
77
+
78
+ export function patchLensFile(
79
+ repoPath: string,
80
+ patch: Partial<AnalysisResult>,
81
+ ): void {
82
+ const existing = readLensFile(repoPath);
83
+ const now = new Date().toISOString();
84
+
85
+ const base: LensFile = existing ?? {
86
+ overview: "",
87
+ importantFolders: [],
88
+ tooling: {},
89
+ keyFiles: [],
90
+ patterns: [],
91
+ architecture: "",
92
+ suggestions: [],
93
+ generatedAt: now,
94
+ lastUpdated: now,
95
+ };
96
+
97
+ const merged: LensFile = {
98
+ ...base,
99
+ lastUpdated: now,
100
+ overview: patch.overview ?? base.overview,
101
+ architecture: patch.architecture ?? base.architecture,
102
+ tooling: { ...base.tooling, ...(patch.tooling ?? {}) },
103
+ importantFolders: dedup([
104
+ ...base.importantFolders,
105
+ ...(patch.importantFolders ?? []),
106
+ ]),
107
+ keyFiles: dedup([...base.keyFiles, ...(patch.keyFiles ?? [])]),
108
+ patterns: dedup([...base.patterns, ...(patch.patterns ?? [])]),
109
+ suggestions: dedup([...base.suggestions, ...(patch.suggestions ?? [])]),
110
+ };
111
+
112
+ writeFileSync(lensFilePath(repoPath), renderLensFile(merged), "utf-8");
113
+ }
52
114
 
53
- writeFileSync(lensFilePath(repoPath), content, "utf-8");
115
+ function dedup(arr: string[]): string[] {
116
+ return [...new Map(arr.map((s) => [s.trim().toLowerCase(), s])).values()];
54
117
  }
55
118
 
56
119
  export function readLensFile(repoPath: string): LensFile | null {
@@ -70,8 +133,10 @@ export function lensFileToAnalysisResult(lf: LensFile): AnalysisResult {
70
133
  return {
71
134
  overview: lf.overview,
72
135
  importantFolders: lf.importantFolders,
73
- missingConfigs: lf.missingConfigs,
74
- securityIssues: lf.securityIssues,
136
+ tooling: lf.tooling,
137
+ keyFiles: lf.keyFiles,
138
+ patterns: lf.patterns,
139
+ architecture: lf.architecture,
75
140
  suggestions: lf.suggestions,
76
141
  };
77
142
  }