UNPKG

@ant-design/tools

Version:
55 lines 1.66 kB
import glob from 'glob'; import fs from 'fs'; const COMPONENT_NAME = /components\/([^/]*)/; const PROP_NAME = /^\s*\|\s*([^\s|]*)/; const components = {}; function mappingPropLine(component, line) { const propMatch = line.match(PROP_NAME); if (!propMatch) return; const propName = propMatch[1]; if (!/^[a-z]/.test(propName)) return; components[component] = Array.from(new Set([...(components[component] || []), propName])); } function apiReport(entities) { const apis = {}; Object.keys(entities).forEach(component => { const apiList = entities[component]; apiList.forEach(api => { if (typeof apis[api] === 'function') { apis[api] = []; } apis[api] = [...(apis[api] || []), component]; }); }); return apis; } function printReport(apis) { const apiList = Object.keys(apis).map(api => ({ name: api, componentList: apis[api] })); apiList.sort((a, b) => b.componentList.length - a.componentList.length); console.log('| name | components | comments |'); console.log('| ---- | ---------- | -------- |'); apiList.forEach(({ name, componentList }) => { console.log('|', name, '|', componentList.join(', '), '| |'); }); } export default (() => { glob('components/*/*.md', (error, files) => { files.forEach(filePath => { const content = fs.readFileSync(filePath, 'utf8'); const match = filePath.match(COMPONENT_NAME); if (!match) return; const component = match[1]; const lines = content.split(/[\r\n]+/); lines.forEach(line => { mappingPropLine(component, line); }); }); printReport(apiReport(components)); }); });