react-file-analyzer
Version:
A comprehensive NPM package for analyzing React and Next.js files, including dependency graphs, component insights, and project structure visualization.
59 lines (43 loc) • 1.7 kB
Markdown
# react-file-analyzer
A powerful NPM package for analyzing React and Next.js projects. It provides tools for file insights, dependency graphs, directory structures, and more. Can be used as a CLI or via an HTTP server.
## Installation
```sh
npm install react-file-analyzer
```
## Usage
### CLI Examples
- Comprehensive file analysis:
```sh
react-file-analyzer --analyze-comprehensive path/to/file.tsx --json
```
- Dependency analysis:
```sh
react-file-analyzer --analyze-deps --diagram-type flowchart
```
- Read file contents:
```sh
react-file-analyzer --read-files file1.tsx,file2.tsx --json
```
- Directory tree:
```sh
react-file-analyzer --dir-tree . --depth 3 --json
```
- Start server:
```sh
react-file-analyzer --serve --port 3000 --token mysecret
```
### Server Endpoints
- POST /analyze-comprehensive { "filePath": "path/to/file.tsx" } - Comprehensive insights.
- POST /analyze-deps { "includePatterns": [...], ... } - Dependency graph.
- POST /read-files { "files": ["file1.tsx", "file2.tsx"] } - File contents.
- GET /dir-structure?dir=. - Directory structure.
- GET /dir-tree?dir=.&depth=3 - Directory tree.
- POST /analyze-simple { "filePath": "path/to/file.tsx" } - Simple insights.
- POST /clean { "dir": "path/to/dir" } - Clean directory.
All endpoints require Bearer token if set.
## Features
- Babel-powered AST analysis for components, hooks, props, state, functions.
- Dependency graph with circular detection and Mermaid diagrams.
- Secure server with path traversal protection.
- Directory traversal and cleaning utilities.
For more details, see the source code or run `--help`.