-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentify-react-components.js
32 lines (27 loc) · 1.01 KB
/
identify-react-components.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const path = require('path');
const directory = './my-app/components'; // Adjust the directory path to your components folder
const isReactComponent = (filePath) => {
const content = fs.readFileSync(filePath, 'utf-8');
return (
// JSX-like syntax
(content.includes('return') &&
(content.includes('<') && content.includes('>')) && content.match(/export\s+(const|function|default|class)/))
);
};
const scanDirectory = (dir) => {
fs.readdirSync(dir).forEach((file) => {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
scanDirectory(fullPath);
} else if (fullPath.endsWith('.tsx') || fullPath.endsWith('.jsx')) {
if (isReactComponent(fullPath)) {
console.log(`React Component: ${fullPath}`);
} else {
console.log(`Not a React Component: ${fullPath}`);
}
}
});
};
scanDirectory(directory);