(componentFolder: string, componentName: string)
| 30 | } |
| 31 | |
| 32 | function getComponentCode(componentFolder: string, componentName: string) { |
| 33 | const componentContents = fs |
| 34 | .readdirSync(componentFolder) |
| 35 | .filter( |
| 36 | (item) => |
| 37 | (item.endsWith('.tsx') && !item.endsWith('.story.tsx')) || |
| 38 | item.endsWith('.ts') || |
| 39 | item.endsWith('.css') |
| 40 | ); |
| 41 | |
| 42 | const mainFileContent = removeReact( |
| 43 | fs.readFileSync(path.join(componentFolder, `${componentName}.tsx`), 'utf-8') |
| 44 | ); |
| 45 | const otherFilesContent = componentContents |
| 46 | .filter((file) => file !== `${componentName}.tsx`) |
| 47 | .map((file) => ({ |
| 48 | name: file, |
| 49 | content: removeReact(fs.readFileSync(path.join(componentFolder, file), 'utf-8')), |
| 50 | })); |
| 51 | |
| 52 | return [ |
| 53 | { fileName: `${componentName}.tsx`, language: 'tsx', code: mainFileContent }, |
| 54 | ...otherFilesContent.map(({ name, content }) => ({ |
| 55 | fileName: name, |
| 56 | language: name.endsWith('.css') ? 'scss' : 'tsx', |
| 57 | code: content, |
| 58 | })), |
| 59 | ]; |
| 60 | } |
| 61 | |
| 62 | export function getAllComponents(): ComponentInfo[] { |
| 63 | const rootFolder = path.join('lib'); |
no test coverage detected