@angular-modernizer/plugin-analyzer 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.
- package/LICENSE +21 -0
- package/README.md +361 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/framework-detector.rule.d.ts +41 -0
- package/dist/rules/framework-detector.rule.d.ts.map +1 -0
- package/dist/rules/framework-detector.rule.js +121 -0
- package/dist/rules/framework-detector.rule.js.map +1 -0
- package/package.json +55 -0
- package/src/index.ts +78 -0
- package/src/rules/framework-detector.rule.ts +145 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Christian Weiss<CWOIDA>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# @angular-modernizer/plugin-analyzer
|
|
2
|
+
|
|
3
|
+
Framework detection and project structure analysis plugin for the Angular Modernization Platform.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The `@angular-modernizer/plugin-analyzer` package provides analysis rules for understanding Angular project structures, detecting build frameworks, and analyzing architectural patterns. This plugin powers the `analyze-project` MCP tool.
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+
This plugin follows the API-driven plugin pattern, using `PublicApi` for all analysis operations:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
class FrameworkDetectorRule implements AnalysisRule {
|
|
15
|
+
analyze(context: AnalysisContext) {
|
|
16
|
+
const { api, sourceFile } = context;
|
|
17
|
+
|
|
18
|
+
const dependencies =
|
|
19
|
+
api.analysis.dependencyAnalyzer.analyzeDependencies(sourceFile);
|
|
20
|
+
// analysis logic
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Analysis Rules
|
|
26
|
+
|
|
27
|
+
### FrameworkDetectorRule
|
|
28
|
+
|
|
29
|
+
**Rule ID:** `analyzer:framework-detection`
|
|
30
|
+
|
|
31
|
+
Detects whether a project uses Angular CLI or Nx, and identifies the technology stack.
|
|
32
|
+
|
|
33
|
+
**Detection Priority:**
|
|
34
|
+
|
|
35
|
+
1. Nx — `nx.json` present, workspace structure
|
|
36
|
+
2. Angular CLI — `angular.json` present, standard structure
|
|
37
|
+
3. Unknown — no clear indicators
|
|
38
|
+
|
|
39
|
+
**Example Output:**
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"ruleId": "framework-detector",
|
|
44
|
+
"violations": [],
|
|
45
|
+
"metadata": {
|
|
46
|
+
"framework": "angular-cli",
|
|
47
|
+
"confidence": 0.95,
|
|
48
|
+
"evidence": [
|
|
49
|
+
"angular.json detected",
|
|
50
|
+
"@angular/core in package.json",
|
|
51
|
+
"src/main.ts with bootstrapApplication"
|
|
52
|
+
],
|
|
53
|
+
"projectType": "application",
|
|
54
|
+
"technologyStack": {
|
|
55
|
+
"angular": "17.x",
|
|
56
|
+
"typescript": "5.x",
|
|
57
|
+
"rxjs": "7.x"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Detection Logic:**
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
class FrameworkDetectorRule implements AnalysisRule {
|
|
67
|
+
async analyze(context: AnalysisContext): Promise<AnalysisResult> {
|
|
68
|
+
const { project } = context;
|
|
69
|
+
|
|
70
|
+
const nxIndicators = await this.checkNxIndicators(project);
|
|
71
|
+
const angularIndicators = await this.checkAngularIndicators(project);
|
|
72
|
+
const framework = this.determineFramework(nxIndicators, angularIndicators);
|
|
73
|
+
const structure = await this.analyzeProjectStructure(project);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
ruleId: this.id,
|
|
77
|
+
violations: [],
|
|
78
|
+
metadata: {
|
|
79
|
+
framework: framework.type,
|
|
80
|
+
confidence: framework.confidence,
|
|
81
|
+
evidence: framework.evidence,
|
|
82
|
+
projectType: structure.type,
|
|
83
|
+
technologyStack: structure.stack,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### LayerDetectorRule (Planned)
|
|
91
|
+
|
|
92
|
+
**Rule ID:** `layer-detector`
|
|
93
|
+
|
|
94
|
+
Analyzes project layering and architectural boundaries via directory structure and import patterns.
|
|
95
|
+
|
|
96
|
+
### TechnologyStackAnalyzerRule (Planned)
|
|
97
|
+
|
|
98
|
+
**Rule ID:** `technology-stack-analyzer`
|
|
99
|
+
|
|
100
|
+
Identifies technologies and versions used in the project via `package.json` analysis.
|
|
101
|
+
|
|
102
|
+
## Usage Examples
|
|
103
|
+
|
|
104
|
+
### Basic Framework Detection
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { Kernel, RealFileSystemAdapter } from '@angular-modernizer/core';
|
|
108
|
+
import { AnalyzerPlugin } from '@angular-modernizer/plugin-analyzer';
|
|
109
|
+
|
|
110
|
+
const kernel = new Kernel({
|
|
111
|
+
tsConfigPath: './tsconfig.json',
|
|
112
|
+
fileSystem: new RealFileSystemAdapter(),
|
|
113
|
+
plugins: [new AnalyzerPlugin()],
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await kernel.initialize();
|
|
117
|
+
|
|
118
|
+
const plugin = kernel.getPlugin('@angular-modernizer/plugin-analyzer');
|
|
119
|
+
const rules = plugin.getAnalysisRules();
|
|
120
|
+
const frameworkRule = rules.find((r) => r.id === 'framework-detector');
|
|
121
|
+
|
|
122
|
+
const project = kernel.getProject();
|
|
123
|
+
const sourceFile = project.addSourceFileAtPath('./package.json');
|
|
124
|
+
|
|
125
|
+
const context = ContextFactory.createAnalysisContext({
|
|
126
|
+
sourceFile,
|
|
127
|
+
project,
|
|
128
|
+
api: createPublicApi(),
|
|
129
|
+
config: {},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const result = await frameworkRule.analyze(context);
|
|
133
|
+
|
|
134
|
+
console.log('Framework detected:', result.metadata.framework);
|
|
135
|
+
console.log('Confidence:', result.metadata.confidence);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### MCP Tool Integration
|
|
139
|
+
|
|
140
|
+
This plugin powers the `analyze-project` MCP tool:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const analysis = await callTool('analyze-project', {
|
|
144
|
+
rootPath: '/path/to/angular/project',
|
|
145
|
+
includeDetails: true,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Result structure
|
|
149
|
+
{
|
|
150
|
+
"framework": "nx",
|
|
151
|
+
"architecture": {
|
|
152
|
+
"pattern": "nx-monorepo",
|
|
153
|
+
"layers": ["apps", "libs", "tools"],
|
|
154
|
+
"confidence": 0.98
|
|
155
|
+
},
|
|
156
|
+
"technologyStack": {
|
|
157
|
+
"angular": "17.0.0",
|
|
158
|
+
"nx": "16.0.0",
|
|
159
|
+
"typescript": "5.1.0"
|
|
160
|
+
},
|
|
161
|
+
"migrationReadiness": {
|
|
162
|
+
"standaloneComponents": 0.75,
|
|
163
|
+
"modernSyntax": 0.60,
|
|
164
|
+
"overall": 0.68
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Configuration Options
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
interface FrameworkDetectorConfig {
|
|
173
|
+
/**
|
|
174
|
+
* Minimum confidence threshold for framework detection.
|
|
175
|
+
* Default: 0.5
|
|
176
|
+
*/
|
|
177
|
+
minConfidence?: number;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Include detailed evidence in results.
|
|
181
|
+
* Default: true
|
|
182
|
+
*/
|
|
183
|
+
includeEvidence?: boolean;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Custom framework indicators.
|
|
187
|
+
*/
|
|
188
|
+
customIndicators?: FrameworkIndicators;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
interface FrameworkIndicators {
|
|
192
|
+
angular: string[];
|
|
193
|
+
nx: string[];
|
|
194
|
+
custom: Record<string, string[]>;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Example Configuration
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const context = ContextFactory.createAnalysisContext({
|
|
202
|
+
sourceFile,
|
|
203
|
+
project,
|
|
204
|
+
api: createPublicApi(),
|
|
205
|
+
config: {
|
|
206
|
+
minConfidence: 0.8,
|
|
207
|
+
includeEvidence: true,
|
|
208
|
+
customIndicators: {
|
|
209
|
+
custom: {
|
|
210
|
+
'my-framework': ['my-framework.json', 'custom-config.js'],
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Package Structure
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
packages/plugin-analyzer/
|
|
221
|
+
src/
|
|
222
|
+
rules/
|
|
223
|
+
framework-detector.rule.ts
|
|
224
|
+
layer-detector.rule.ts (planned)
|
|
225
|
+
technology-stack-analyzer.rule.ts (planned)
|
|
226
|
+
analyzer-plugin.ts
|
|
227
|
+
index.ts
|
|
228
|
+
types.ts
|
|
229
|
+
__tests__/
|
|
230
|
+
rules/
|
|
231
|
+
framework-detector.rule.test.ts
|
|
232
|
+
analyzer-plugin.test.ts
|
|
233
|
+
package.json
|
|
234
|
+
tsconfig.json
|
|
235
|
+
jest.config.js
|
|
236
|
+
README.md
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Testing
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
pnpm --filter @angular-modernizer/plugin-analyzer test
|
|
243
|
+
pnpm --filter @angular-modernizer/plugin-analyzer test --coverage
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Test Fixtures
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
__tests__/fixtures/
|
|
250
|
+
sample-angular-cli-app/
|
|
251
|
+
angular.json
|
|
252
|
+
package.json
|
|
253
|
+
src/main.ts
|
|
254
|
+
sample-nx-app/
|
|
255
|
+
nx.json
|
|
256
|
+
workspace.json
|
|
257
|
+
apps/
|
|
258
|
+
sample-unknown-app/
|
|
259
|
+
package.json
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Test Example
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
describe('FrameworkDetectorRule', () => {
|
|
266
|
+
let rule: FrameworkDetectorRule;
|
|
267
|
+
|
|
268
|
+
beforeEach(() => {
|
|
269
|
+
rule = new FrameworkDetectorRule();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('should detect Angular CLI project', async () => {
|
|
273
|
+
const project = new Project();
|
|
274
|
+
project.addSourceFilesAtPaths('__tests__/fixtures/sample-angular-cli-app/**/*');
|
|
275
|
+
|
|
276
|
+
const context = ContextFactory.createAnalysisContext({
|
|
277
|
+
sourceFile: project.getSourceFile('package.json')!,
|
|
278
|
+
project,
|
|
279
|
+
api: createPublicApi(),
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const result = await rule.analyze(context);
|
|
283
|
+
|
|
284
|
+
expect(result.metadata.framework).toBe('angular-cli');
|
|
285
|
+
expect(result.metadata.confidence).toBeGreaterThan(0.8);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('should detect Nx project', async () => {
|
|
289
|
+
const project = new Project();
|
|
290
|
+
project.addSourceFilesAtPaths('__tests__/fixtures/sample-nx-app/**/*');
|
|
291
|
+
|
|
292
|
+
const context = ContextFactory.createAnalysisContext({
|
|
293
|
+
sourceFile: project.getSourceFile('nx.json')!,
|
|
294
|
+
project,
|
|
295
|
+
api: createPublicApi(),
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const result = await rule.analyze(context);
|
|
299
|
+
|
|
300
|
+
expect(result.metadata.framework).toBe('nx');
|
|
301
|
+
expect(result.metadata.confidence).toBeGreaterThan(0.9);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Dependencies
|
|
307
|
+
|
|
308
|
+
- `@angular-modernizer/api` - Public API with analysis tools
|
|
309
|
+
- `@angular-modernizer/core` - Kernel and infrastructure
|
|
310
|
+
- `@angular-modernizer/plugin-system` - Plugin contracts and contexts
|
|
311
|
+
|
|
312
|
+
## Contributing
|
|
313
|
+
|
|
314
|
+
When adding new analysis rules:
|
|
315
|
+
|
|
316
|
+
1. Follow the `AnalysisRule` interface — implement all required methods
|
|
317
|
+
2. Use `PublicApi` tools — do not implement low-level AST logic directly
|
|
318
|
+
3. Include comprehensive tests using real fixtures where possible
|
|
319
|
+
4. Provide meaningful metadata including confidence scores and evidence
|
|
320
|
+
5. Update this README with configuration options
|
|
321
|
+
|
|
322
|
+
### Adding a New Analysis Rule
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
// 1. Implement the rule
|
|
326
|
+
class MyAnalysisRule implements AnalysisRule {
|
|
327
|
+
readonly id = 'my-analysis';
|
|
328
|
+
readonly name = 'My Analysis Rule';
|
|
329
|
+
readonly description = 'Analyzes something specific';
|
|
330
|
+
|
|
331
|
+
async analyze(context: AnalysisContext): Promise<AnalysisResult> {
|
|
332
|
+
const { api, sourceFile } = context;
|
|
333
|
+
|
|
334
|
+
const findings = await api.analysis.someTool.analyze(sourceFile);
|
|
335
|
+
|
|
336
|
+
return {
|
|
337
|
+
ruleId: this.id,
|
|
338
|
+
violations: [],
|
|
339
|
+
metadata: {
|
|
340
|
+
findings,
|
|
341
|
+
confidence: 0.9,
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// 2. Add to plugin
|
|
348
|
+
class AnalyzerPlugin implements Plugin {
|
|
349
|
+
getAnalysisRules(): AnalysisRule[] {
|
|
350
|
+
return [
|
|
351
|
+
new FrameworkDetectorRule(),
|
|
352
|
+
new MyAnalysisRule(),
|
|
353
|
+
];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## See Also
|
|
359
|
+
|
|
360
|
+
- [packages/api/README.md](../api/README.md) - Public API tools
|
|
361
|
+
- [packages/plugin-solid/README.md](../plugin-solid/README.md) - SOLID analysis rules
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-analyzer
|
|
3
|
+
*
|
|
4
|
+
* Analysis plugin for detecting project architecture, framework, and layers.
|
|
5
|
+
* This plugin provides rules for high-level project analysis.
|
|
6
|
+
*
|
|
7
|
+
* Philosophy: "Know Before You Transform"
|
|
8
|
+
* - Analysis rules run first to understand the codebase
|
|
9
|
+
* - They provide insights that guide transformation decisions
|
|
10
|
+
* - They never modify code, only observe and report
|
|
11
|
+
*/
|
|
12
|
+
import type { IKernel } from '@angular-modernizer/plugin-system';
|
|
13
|
+
import type { Plugin, AnalysisRule, TransformRule, ValidationRule } from '@angular-modernizer/plugin-system';
|
|
14
|
+
/**
|
|
15
|
+
* Analyzer Plugin - Provides project-level analysis capabilities.
|
|
16
|
+
*
|
|
17
|
+
* Rules provided:
|
|
18
|
+
* - FrameworkDetectorRule: Detects Angular CLI vs Nx
|
|
19
|
+
* - [Future] LayerDetectorRule: Identifies architectural layers
|
|
20
|
+
* - [Future] DependencyAnalyzerRule: Analyzes dependency structure
|
|
21
|
+
*/
|
|
22
|
+
export declare class AnalyzerPlugin implements Plugin {
|
|
23
|
+
readonly name = "analyzer";
|
|
24
|
+
readonly version = "1.0.0";
|
|
25
|
+
readonly description = "Project architecture and framework analysis";
|
|
26
|
+
readonly author = "Angular Modernizer";
|
|
27
|
+
private frameworkDetectorRule;
|
|
28
|
+
constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the plugin.
|
|
31
|
+
* Called once during Kernel initialization.
|
|
32
|
+
*/
|
|
33
|
+
initialize(kernel: IKernel): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Get all analysis rules provided by this plugin.
|
|
36
|
+
*/
|
|
37
|
+
getAnalysisRules(): AnalysisRule[];
|
|
38
|
+
/**
|
|
39
|
+
* Get all transformation rules provided by this plugin.
|
|
40
|
+
* This plugin doesn't provide transformations.
|
|
41
|
+
*/
|
|
42
|
+
getTransformRules(): TransformRule[];
|
|
43
|
+
/**
|
|
44
|
+
* Get all validation rules provided by this plugin.
|
|
45
|
+
* This plugin doesn't provide validations.
|
|
46
|
+
*/
|
|
47
|
+
getValidationRules(): ValidationRule[];
|
|
48
|
+
}
|
|
49
|
+
export { FrameworkDetectorRule } from './rules/framework-detector.rule.js';
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,aAAa,EACb,cAAc,EACf,MAAM,mCAAmC,CAAC;AAG3C;;;;;;;GAOG;AACH,qBAAa,cAAe,YAAW,MAAM;IAC3C,QAAQ,CAAC,IAAI,cAAc;IAC3B,QAAQ,CAAC,OAAO,WAAW;IAC3B,QAAQ,CAAC,WAAW,iDAAiD;IACrE,QAAQ,CAAC,MAAM,wBAAwB;IAEvC,OAAO,CAAC,qBAAqB,CAAwB;;IAOrD;;;OAGG;IACG,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhD;;OAEG;IACH,gBAAgB,IAAI,YAAY,EAAE;IAIlC;;;OAGG;IACH,iBAAiB,IAAI,aAAa,EAAE;IAIpC;;;OAGG;IACH,kBAAkB,IAAI,cAAc,EAAE;CAGvC;AAGD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @angular-modernizer/plugin-analyzer
|
|
4
|
+
*
|
|
5
|
+
* Analysis plugin for detecting project architecture, framework, and layers.
|
|
6
|
+
* This plugin provides rules for high-level project analysis.
|
|
7
|
+
*
|
|
8
|
+
* Philosophy: "Know Before You Transform"
|
|
9
|
+
* - Analysis rules run first to understand the codebase
|
|
10
|
+
* - They provide insights that guide transformation decisions
|
|
11
|
+
* - They never modify code, only observe and report
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.FrameworkDetectorRule = exports.AnalyzerPlugin = void 0;
|
|
15
|
+
const framework_detector_rule_js_1 = require("./rules/framework-detector.rule.js");
|
|
16
|
+
/**
|
|
17
|
+
* Analyzer Plugin - Provides project-level analysis capabilities.
|
|
18
|
+
*
|
|
19
|
+
* Rules provided:
|
|
20
|
+
* - FrameworkDetectorRule: Detects Angular CLI vs Nx
|
|
21
|
+
* - [Future] LayerDetectorRule: Identifies architectural layers
|
|
22
|
+
* - [Future] DependencyAnalyzerRule: Analyzes dependency structure
|
|
23
|
+
*/
|
|
24
|
+
class AnalyzerPlugin {
|
|
25
|
+
name = 'analyzer';
|
|
26
|
+
version = '1.0.0';
|
|
27
|
+
description = 'Project architecture and framework analysis';
|
|
28
|
+
author = 'Angular Modernizer';
|
|
29
|
+
frameworkDetectorRule;
|
|
30
|
+
constructor() {
|
|
31
|
+
// Initialize rules
|
|
32
|
+
this.frameworkDetectorRule = new framework_detector_rule_js_1.FrameworkDetectorRule();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Initialize the plugin.
|
|
36
|
+
* Called once during Kernel initialization.
|
|
37
|
+
*/
|
|
38
|
+
async initialize(kernel) {
|
|
39
|
+
// No initialization needed for this plugin yet
|
|
40
|
+
// Future: Could load configuration, validate dependencies, etc.
|
|
41
|
+
void kernel; // Mark as used to avoid linting error
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get all analysis rules provided by this plugin.
|
|
45
|
+
*/
|
|
46
|
+
getAnalysisRules() {
|
|
47
|
+
return [this.frameworkDetectorRule];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get all transformation rules provided by this plugin.
|
|
51
|
+
* This plugin doesn't provide transformations.
|
|
52
|
+
*/
|
|
53
|
+
getTransformRules() {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get all validation rules provided by this plugin.
|
|
58
|
+
* This plugin doesn't provide validations.
|
|
59
|
+
*/
|
|
60
|
+
getValidationRules() {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.AnalyzerPlugin = AnalyzerPlugin;
|
|
65
|
+
// Export the plugin class and rules
|
|
66
|
+
var framework_detector_rule_js_2 = require("./rules/framework-detector.rule.js");
|
|
67
|
+
Object.defineProperty(exports, "FrameworkDetectorRule", { enumerable: true, get: function () { return framework_detector_rule_js_2.FrameworkDetectorRule; } });
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AASH,mFAA2E;AAE3E;;;;;;;GAOG;AACH,MAAa,cAAc;IAChB,IAAI,GAAG,UAAU,CAAC;IAClB,OAAO,GAAG,OAAO,CAAC;IAClB,WAAW,GAAG,6CAA6C,CAAC;IAC5D,MAAM,GAAG,oBAAoB,CAAC;IAE/B,qBAAqB,CAAwB;IAErD;QACE,mBAAmB;QACnB,IAAI,CAAC,qBAAqB,GAAG,IAAI,kDAAqB,EAAE,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAC,MAAe;QAC9B,+CAA+C;QAC/C,gEAAgE;QAChE,KAAK,MAAM,CAAC,CAAC,sCAAsC;IACrD,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,iBAAiB;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;OAGG;IACH,kBAAkB;QAChB,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA7CD,wCA6CC;AAED,oCAAoC;AACpC,iFAA2E;AAAlE,mIAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-analyzer - Framework Detector Rule
|
|
3
|
+
*
|
|
4
|
+
* Detects the Angular framework type (Angular CLI vs Nx) by analyzing
|
|
5
|
+
* configuration files in the project root.
|
|
6
|
+
*
|
|
7
|
+
* Detection Logic:
|
|
8
|
+
* - If nx.json exists: Framework is "Nx"
|
|
9
|
+
* - If angular.json exists: Framework is "Angular CLI"
|
|
10
|
+
* - If neither exists: Framework is "Unknown"
|
|
11
|
+
*/
|
|
12
|
+
import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
|
|
13
|
+
/**
|
|
14
|
+
* Framework detection rule.
|
|
15
|
+
* This is a project-level rule that examines configuration files.
|
|
16
|
+
*/
|
|
17
|
+
export declare class FrameworkDetectorRule implements AnalysisRule {
|
|
18
|
+
readonly id = "analyzer:framework-detector";
|
|
19
|
+
readonly name = "Framework Detector";
|
|
20
|
+
readonly description = "Detects whether the project uses Angular CLI or Nx";
|
|
21
|
+
readonly severity: "info";
|
|
22
|
+
readonly category = "project-analysis";
|
|
23
|
+
readonly tags: string[];
|
|
24
|
+
analyze(context: AnalysisContext): Promise<AnalysisResult[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the project root directory.
|
|
27
|
+
* Uses the directory containing the first tsconfig.json found.
|
|
28
|
+
*/
|
|
29
|
+
private getProjectRoot;
|
|
30
|
+
/**
|
|
31
|
+
* Find project root by traversing up the directory tree.
|
|
32
|
+
* Looks for tsconfig.json, package.json, or stops at root.
|
|
33
|
+
*/
|
|
34
|
+
private findProjectRoot;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a file exists in the file system.
|
|
37
|
+
* Uses the file system adapter from the context if available.
|
|
38
|
+
*/
|
|
39
|
+
private fileExists;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=framework-detector.rule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-detector.rule.d.ts","sourceRoot":"","sources":["../../src/rules/framework-detector.rule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACf,MAAM,mCAAmC,CAAC;AAG3C;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,YAAY;IACxD,QAAQ,CAAC,EAAE,iCAAiC;IAC5C,QAAQ,CAAC,IAAI,wBAAwB;IACrC,QAAQ,CAAC,WAAW,wDAAwD;IAC5E,QAAQ,CAAC,QAAQ,EAAG,MAAM,CAAU;IACpC,QAAQ,CAAC,QAAQ,sBAAsB;IACvC,QAAQ,CAAC,IAAI,WAAyC;IAEhD,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA+ClE;;;OAGG;IACH,OAAO,CAAC,cAAc;IAatB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAcvB;;;OAGG;YACW,UAAU;CA2BzB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @angular-modernizer/plugin-analyzer - Framework Detector Rule
|
|
4
|
+
*
|
|
5
|
+
* Detects the Angular framework type (Angular CLI vs Nx) by analyzing
|
|
6
|
+
* configuration files in the project root.
|
|
7
|
+
*
|
|
8
|
+
* Detection Logic:
|
|
9
|
+
* - If nx.json exists: Framework is "Nx"
|
|
10
|
+
* - If angular.json exists: Framework is "Angular CLI"
|
|
11
|
+
* - If neither exists: Framework is "Unknown"
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.FrameworkDetectorRule = void 0;
|
|
15
|
+
const node_path_1 = require("node:path");
|
|
16
|
+
/**
|
|
17
|
+
* Framework detection rule.
|
|
18
|
+
* This is a project-level rule that examines configuration files.
|
|
19
|
+
*/
|
|
20
|
+
class FrameworkDetectorRule {
|
|
21
|
+
id = 'analyzer:framework-detector';
|
|
22
|
+
name = 'Framework Detector';
|
|
23
|
+
description = 'Detects whether the project uses Angular CLI or Nx';
|
|
24
|
+
severity = 'info';
|
|
25
|
+
category = 'project-analysis';
|
|
26
|
+
tags = ['framework', 'detection', 'project'];
|
|
27
|
+
async analyze(context) {
|
|
28
|
+
// Get the project root directory
|
|
29
|
+
// We'll use the directory containing the tsconfig file as the project root
|
|
30
|
+
const projectRoot = this.getProjectRoot(context);
|
|
31
|
+
// Check for framework configuration files
|
|
32
|
+
const hasNxConfig = await this.fileExists(context, (0, node_path_1.join)(projectRoot, 'nx.json'));
|
|
33
|
+
const hasAngularConfig = await this.fileExists(context, (0, node_path_1.join)(projectRoot, 'angular.json'));
|
|
34
|
+
// Determine framework type
|
|
35
|
+
let framework;
|
|
36
|
+
let message;
|
|
37
|
+
if (hasNxConfig) {
|
|
38
|
+
framework = 'Nx';
|
|
39
|
+
message = 'Project uses Nx workspace';
|
|
40
|
+
}
|
|
41
|
+
else if (hasAngularConfig) {
|
|
42
|
+
framework = 'Angular CLI';
|
|
43
|
+
message = 'Project uses Angular CLI';
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
framework = 'Unknown';
|
|
47
|
+
message =
|
|
48
|
+
'Could not determine framework type (no nx.json or angular.json found)';
|
|
49
|
+
}
|
|
50
|
+
// Return analysis result
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
ruleId: this.id,
|
|
54
|
+
message,
|
|
55
|
+
filePath: context.filePath,
|
|
56
|
+
metadata: {
|
|
57
|
+
framework,
|
|
58
|
+
hasNxConfig,
|
|
59
|
+
hasAngularConfig,
|
|
60
|
+
projectRoot,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the project root directory.
|
|
67
|
+
* Uses the directory containing the first tsconfig.json found.
|
|
68
|
+
*/
|
|
69
|
+
getProjectRoot(context) {
|
|
70
|
+
// Get all tsconfig files from the project
|
|
71
|
+
const compilerOptions = context.project.getCompilerOptions();
|
|
72
|
+
const configFiles = compilerOptions['configFilePath'];
|
|
73
|
+
if (configFiles && typeof configFiles === 'string') {
|
|
74
|
+
return (0, node_path_1.dirname)(configFiles);
|
|
75
|
+
}
|
|
76
|
+
// Fallback: use the directory of the current source file and traverse up
|
|
77
|
+
return this.findProjectRoot(context.filePath);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Find project root by traversing up the directory tree.
|
|
81
|
+
* Looks for tsconfig.json, package.json, or stops at root.
|
|
82
|
+
*/
|
|
83
|
+
findProjectRoot(startPath) {
|
|
84
|
+
const current = (0, node_path_1.dirname)(startPath);
|
|
85
|
+
const root = '/';
|
|
86
|
+
// Keep traversing up until we find a project marker or hit root
|
|
87
|
+
while (current !== root) {
|
|
88
|
+
// TODO: In a real implementation, we'd check for files here
|
|
89
|
+
// For now, just return the directory
|
|
90
|
+
return current;
|
|
91
|
+
}
|
|
92
|
+
return current;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if a file exists in the file system.
|
|
96
|
+
* Uses the file system adapter from the context if available.
|
|
97
|
+
*/
|
|
98
|
+
async fileExists(context, filePath) {
|
|
99
|
+
try {
|
|
100
|
+
// Try using ts-morph to check if the file exists
|
|
101
|
+
const sourceFile = context.project.getSourceFile(filePath);
|
|
102
|
+
if (sourceFile) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
// Try using the file system directly
|
|
106
|
+
// The project should have a file system we can query
|
|
107
|
+
const projectWithFs = context.project;
|
|
108
|
+
const fileSystem = projectWithFs.getFileSystem?.();
|
|
109
|
+
if (fileSystem && typeof fileSystem.fileExistsSync === 'function') {
|
|
110
|
+
return fileSystem.fileExistsSync(filePath);
|
|
111
|
+
}
|
|
112
|
+
// Fallback: just return false
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.FrameworkDetectorRule = FrameworkDetectorRule;
|
|
121
|
+
//# sourceMappingURL=framework-detector.rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-detector.rule.js","sourceRoot":"","sources":["../../src/rules/framework-detector.rule.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@angular-modernizer/plugin-analyzer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Analysis plugin for detecting project architecture, framework, and layers.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"angular",
|
|
7
|
+
"modernization",
|
|
8
|
+
"typescript",
|
|
9
|
+
"ast",
|
|
10
|
+
"ts-morph",
|
|
11
|
+
"code-analysis"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/eiweiss/tsanalyzer.git",
|
|
17
|
+
"directory": "packages/plugin-analyzer"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/eiweiss/tsanalyzer#readme",
|
|
20
|
+
"bugs": "https://github.com/eiweiss/tsanalyzer/issues",
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"!dist/**/__tests__/**",
|
|
26
|
+
"!src/**/__tests__/**",
|
|
27
|
+
"!src/**/*.test.ts",
|
|
28
|
+
"!src/**/*.spec.ts"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@angular-modernizer/core": "0.1.0",
|
|
32
|
+
"@angular-modernizer/api": "0.1.0",
|
|
33
|
+
"@angular-modernizer/plugin-system": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/jest": "^30.0.0",
|
|
37
|
+
"jest": "^30.2.0",
|
|
38
|
+
"ts-jest": "^29.4.5"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"typedocOptions": {
|
|
44
|
+
"entryPoints": [
|
|
45
|
+
"./src/index.ts"
|
|
46
|
+
],
|
|
47
|
+
"tsconfig": "./tsconfig.json"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc --build",
|
|
51
|
+
"test": "jest --passWithNoTests",
|
|
52
|
+
"lint": "eslint src/**/*.ts",
|
|
53
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-analyzer
|
|
3
|
+
*
|
|
4
|
+
* Analysis plugin for detecting project architecture, framework, and layers.
|
|
5
|
+
* This plugin provides rules for high-level project analysis.
|
|
6
|
+
*
|
|
7
|
+
* Philosophy: "Know Before You Transform"
|
|
8
|
+
* - Analysis rules run first to understand the codebase
|
|
9
|
+
* - They provide insights that guide transformation decisions
|
|
10
|
+
* - They never modify code, only observe and report
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { IKernel } from '@angular-modernizer/plugin-system';
|
|
14
|
+
import type {
|
|
15
|
+
Plugin,
|
|
16
|
+
AnalysisRule,
|
|
17
|
+
TransformRule,
|
|
18
|
+
ValidationRule,
|
|
19
|
+
} from '@angular-modernizer/plugin-system';
|
|
20
|
+
import { FrameworkDetectorRule } from './rules/framework-detector.rule.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Analyzer Plugin - Provides project-level analysis capabilities.
|
|
24
|
+
*
|
|
25
|
+
* Rules provided:
|
|
26
|
+
* - FrameworkDetectorRule: Detects Angular CLI vs Nx
|
|
27
|
+
* - [Future] LayerDetectorRule: Identifies architectural layers
|
|
28
|
+
* - [Future] DependencyAnalyzerRule: Analyzes dependency structure
|
|
29
|
+
*/
|
|
30
|
+
export class AnalyzerPlugin implements Plugin {
|
|
31
|
+
readonly name = 'analyzer';
|
|
32
|
+
readonly version = '1.0.0';
|
|
33
|
+
readonly description = 'Project architecture and framework analysis';
|
|
34
|
+
readonly author = 'Angular Modernizer';
|
|
35
|
+
|
|
36
|
+
private frameworkDetectorRule: FrameworkDetectorRule;
|
|
37
|
+
|
|
38
|
+
constructor() {
|
|
39
|
+
// Initialize rules
|
|
40
|
+
this.frameworkDetectorRule = new FrameworkDetectorRule();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the plugin.
|
|
45
|
+
* Called once during Kernel initialization.
|
|
46
|
+
*/
|
|
47
|
+
async initialize(kernel: IKernel): Promise<void> {
|
|
48
|
+
// No initialization needed for this plugin yet
|
|
49
|
+
// Future: Could load configuration, validate dependencies, etc.
|
|
50
|
+
void kernel; // Mark as used to avoid linting error
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get all analysis rules provided by this plugin.
|
|
55
|
+
*/
|
|
56
|
+
getAnalysisRules(): AnalysisRule[] {
|
|
57
|
+
return [this.frameworkDetectorRule];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get all transformation rules provided by this plugin.
|
|
62
|
+
* This plugin doesn't provide transformations.
|
|
63
|
+
*/
|
|
64
|
+
getTransformRules(): TransformRule[] {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get all validation rules provided by this plugin.
|
|
70
|
+
* This plugin doesn't provide validations.
|
|
71
|
+
*/
|
|
72
|
+
getValidationRules(): ValidationRule[] {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Export the plugin class and rules
|
|
78
|
+
export { FrameworkDetectorRule } from './rules/framework-detector.rule.js';
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-analyzer - Framework Detector Rule
|
|
3
|
+
*
|
|
4
|
+
* Detects the Angular framework type (Angular CLI vs Nx) by analyzing
|
|
5
|
+
* configuration files in the project root.
|
|
6
|
+
*
|
|
7
|
+
* Detection Logic:
|
|
8
|
+
* - If nx.json exists: Framework is "Nx"
|
|
9
|
+
* - If angular.json exists: Framework is "Angular CLI"
|
|
10
|
+
* - If neither exists: Framework is "Unknown"
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
AnalysisRule,
|
|
15
|
+
AnalysisContext,
|
|
16
|
+
AnalysisResult,
|
|
17
|
+
} from '@angular-modernizer/plugin-system';
|
|
18
|
+
import { dirname, join } from 'node:path';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Framework detection rule.
|
|
22
|
+
* This is a project-level rule that examines configuration files.
|
|
23
|
+
*/
|
|
24
|
+
export class FrameworkDetectorRule implements AnalysisRule {
|
|
25
|
+
readonly id = 'analyzer:framework-detector';
|
|
26
|
+
readonly name = 'Framework Detector';
|
|
27
|
+
readonly description = 'Detects whether the project uses Angular CLI or Nx';
|
|
28
|
+
readonly severity = 'info' as const;
|
|
29
|
+
readonly category = 'project-analysis';
|
|
30
|
+
readonly tags = ['framework', 'detection', 'project'];
|
|
31
|
+
|
|
32
|
+
async analyze(context: AnalysisContext): Promise<AnalysisResult[]> {
|
|
33
|
+
// Get the project root directory
|
|
34
|
+
// We'll use the directory containing the tsconfig file as the project root
|
|
35
|
+
const projectRoot = this.getProjectRoot(context);
|
|
36
|
+
|
|
37
|
+
// Check for framework configuration files
|
|
38
|
+
const hasNxConfig = await this.fileExists(
|
|
39
|
+
context,
|
|
40
|
+
join(projectRoot, 'nx.json'),
|
|
41
|
+
);
|
|
42
|
+
const hasAngularConfig = await this.fileExists(
|
|
43
|
+
context,
|
|
44
|
+
join(projectRoot, 'angular.json'),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Determine framework type
|
|
48
|
+
let framework: string;
|
|
49
|
+
let message: string;
|
|
50
|
+
|
|
51
|
+
if (hasNxConfig) {
|
|
52
|
+
framework = 'Nx';
|
|
53
|
+
message = 'Project uses Nx workspace';
|
|
54
|
+
} else if (hasAngularConfig) {
|
|
55
|
+
framework = 'Angular CLI';
|
|
56
|
+
message = 'Project uses Angular CLI';
|
|
57
|
+
} else {
|
|
58
|
+
framework = 'Unknown';
|
|
59
|
+
message =
|
|
60
|
+
'Could not determine framework type (no nx.json or angular.json found)';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Return analysis result
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
ruleId: this.id,
|
|
67
|
+
message,
|
|
68
|
+
filePath: context.filePath,
|
|
69
|
+
metadata: {
|
|
70
|
+
framework,
|
|
71
|
+
hasNxConfig,
|
|
72
|
+
hasAngularConfig,
|
|
73
|
+
projectRoot,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the project root directory.
|
|
81
|
+
* Uses the directory containing the first tsconfig.json found.
|
|
82
|
+
*/
|
|
83
|
+
private getProjectRoot(context: AnalysisContext): string {
|
|
84
|
+
// Get all tsconfig files from the project
|
|
85
|
+
const compilerOptions = context.project.getCompilerOptions();
|
|
86
|
+
const configFiles = compilerOptions['configFilePath'];
|
|
87
|
+
|
|
88
|
+
if (configFiles && typeof configFiles === 'string') {
|
|
89
|
+
return dirname(configFiles);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Fallback: use the directory of the current source file and traverse up
|
|
93
|
+
return this.findProjectRoot(context.filePath);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Find project root by traversing up the directory tree.
|
|
98
|
+
* Looks for tsconfig.json, package.json, or stops at root.
|
|
99
|
+
*/
|
|
100
|
+
private findProjectRoot(startPath: string): string {
|
|
101
|
+
const current = dirname(startPath);
|
|
102
|
+
const root = '/';
|
|
103
|
+
|
|
104
|
+
// Keep traversing up until we find a project marker or hit root
|
|
105
|
+
while (current !== root) {
|
|
106
|
+
// TODO: In a real implementation, we'd check for files here
|
|
107
|
+
// For now, just return the directory
|
|
108
|
+
return current;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return current;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Check if a file exists in the file system.
|
|
116
|
+
* Uses the file system adapter from the context if available.
|
|
117
|
+
*/
|
|
118
|
+
private async fileExists(
|
|
119
|
+
context: AnalysisContext,
|
|
120
|
+
filePath: string,
|
|
121
|
+
): Promise<boolean> {
|
|
122
|
+
try {
|
|
123
|
+
// Try using ts-morph to check if the file exists
|
|
124
|
+
const sourceFile = context.project.getSourceFile(filePath);
|
|
125
|
+
if (sourceFile) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Try using the file system directly
|
|
130
|
+
// The project should have a file system we can query
|
|
131
|
+
const projectWithFs = context.project as unknown as {
|
|
132
|
+
getFileSystem?: () => { fileExistsSync?: (path: string) => boolean };
|
|
133
|
+
};
|
|
134
|
+
const fileSystem = projectWithFs.getFileSystem?.();
|
|
135
|
+
if (fileSystem && typeof fileSystem.fileExistsSync === 'function') {
|
|
136
|
+
return fileSystem.fileExistsSync(filePath);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Fallback: just return false
|
|
140
|
+
return false;
|
|
141
|
+
} catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|