MCPcopy Create free account
hub / github.com/mantinedev/ui.mantine.dev / getComponentCode

Function getComponentCode

data/components.ts:32–60  ·  view source on GitHub ↗
(componentFolder: string, componentName: string)

Source from the content-addressed store, hash-verified

30}
31
32function 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
62export function getAllComponents(): ComponentInfo[] {
63 const rootFolder = path.join('lib');

Callers 1

getAllComponentsFunction · 0.85

Calls 1

removeReactFunction · 0.85

Tested by

no test coverage detected