MCPcopy Create free account
hub / github.com/blueberryapps/react-bluekit / generateComponentData

Function generateComponentData

src/createBlueKit.js:71–117  ·  view source on GitHub ↗
(config, file, directory)

Source from the content-addressed store, hash-verified

69}
70
71function generateComponentData(config, file, directory) {
72 const filePath = path.join(directory, file);
73
74 try {
75 const docgen = getDocgen(config, filePath);
76
77 const doc = {
78 ...docgen,
79 propsDefinition: objectToString(docgen.props)
80 }
81
82 const normalizedFile = normalizePath(file);
83 const menu = normalizedFile
84 .replace(/\.\.\//g, '')
85 .replace('.react', '')
86 .replace(/\.(js|jsx|tsx)$/, '')
87 .replace(/(?:^|\/)(\w)/g, (_, c) => c ? ` ${c.toUpperCase()}` : '')
88 .replace(/(?:^|[-_])(\w)/g, (_, c) => c ? `${c.toUpperCase()}` : '')
89 .replace(/\//g, '')
90 .trim();
91
92
93 const name = menu.replace(/\W/g, '');
94
95 const importFile = normalizePath(getImportFile(directory, file));
96 const componentName = normalizedFile.replace(/.*\//, '').split('.')[0];
97 const simpleProps = objectToString(buildProps(docgen.props))
98 const fullProps = objectToString(buildProps(docgen.props, true))
99
100 return {
101 file: importFile,
102 componentName,
103 menu,
104 name,
105 simpleProps,
106 fullProps,
107 ...doc,
108 };
109 }
110 catch (error) {
111 if (error.message !== 'No suitable component definition found.')
112 console.error(`\u001b[31mError parsing component ${file}: ${error.message}\u001b[0m`, error.stack) // eslint-disable-line no-console
113 else
114 console.warn(`\u001b[33m No suitable component definition found in ${file}\u001b[0m`) // eslint-disable-line no-console
115 return null;
116 }
117}
118
119function getValidFiles(files) {
120 return [].concat.apply([], files).filter(file => !!file);

Callers 1

generateFunction · 0.85

Calls 5

getDocgenFunction · 0.85
objectToStringFunction · 0.85
normalizePathFunction · 0.85
getImportFileFunction · 0.85
buildPropsFunction · 0.85

Tested by

no test coverage detected