Files
react-test/packages/api-docs-builder/utils/findComponents.ts
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

40 lines
908 B
TypeScript

import fs from 'fs';
import path from 'path';
import findIndexFile from './findIndexFile';
const componentRegex = /^(Unstable_)?([A-Z][a-z]*)+2?\.(js|tsx)/;
/**
* Returns the component source in a flat array.
* @param {string} directory
* @param {Array<{ filename: string, indexFilename: string }>} components
*/
export default function findComponents(
directory: string,
components: { filename: string; indexFilename: string | null }[] = [],
) {
const items = fs.readdirSync(directory);
items.forEach((item) => {
const itemPath = path.resolve(directory, item);
if (fs.statSync(itemPath).isDirectory()) {
findComponents(itemPath, components);
return;
}
if (!componentRegex.test(item)) {
return;
}
const indexFile = findIndexFile(directory);
components.push({
filename: itemPath,
...indexFile,
});
});
return components;
}