@ant-design/tools
Version:
tools for ant design
63 lines (62 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _glob = _interopRequireDefault(require("glob"));
var _fs = _interopRequireDefault(require("fs"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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(', '), '| |');
});
}
var _default = () => {
(0, _glob.default)('components/*/*.md', (error, files) => {
files.forEach(filePath => {
const content = _fs.default.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));
});
};
exports.default = _default;