Browse Source

add api collection script & update input-number doc (#16253)

pull/16256/head
zombieJ 6 years ago
committed by GitHub
parent
commit
3951556fc0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/input-number/index.en-US.md
  2. 63
      scripts/apiCollection.js

2
components/input-number/index.en-US.md

@ -12,7 +12,7 @@ When a numeric value needs to be provided.
## API
| property | description | type | default |
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| autoFocus | get focus when component mounted | boolean | false |
| defaultValue | initial value | number | |

63
scripts/apiCollection.js

@ -0,0 +1,63 @@
// Read all the api from current documents
const glob = require('glob');
const fs = require('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(', '), '| |');
});
}
glob('components/*/*.md', (error, files) => {
files.forEach(filePath => {
// Read md file to parse content
const content = fs.readFileSync(filePath, 'utf8');
const component = filePath.match(COMPONENT_NAME)[1];
// Parse lines to get API
const lines = content.split(/[\r\n]+/);
lines.forEach(line => {
mappingPropLine(component, line);
});
});
printReport(apiReport(components));
});
Loading…
Cancel
Save