Merge pull request #17350 from ant-design/clean-up-scripts

chore: move scripts to antd-tools
This commit is contained in:
偏右 2019-06-28 13:59:15 +08:00 committed by GitHub
commit a8f68d7a5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 3 additions and 215 deletions

View File

@ -1,5 +0,0 @@
const config = {
plugins: ['remark-preset-lint-recommended', ['remark-lint-list-item-indent', 'space']],
};
module.exports = config;

View File

@ -106,9 +106,8 @@
"@types/react-intl": "^2.3.17",
"@types/warning": "^3.0.0",
"@yesmeck/offline-plugin": "^5.0.5",
"ansi-styles": "^4.0.0",
"antd-theme-generator": "^1.1.6",
"antd-tools": "^7.3.5",
"antd-tools": "^7.6.0",
"babel-eslint": "^10.0.1",
"babel-plugin-add-react-displayname": "^0.0.5",
"bisheng": "^1.2.4",
@ -147,7 +146,6 @@
"logrocket": "^1.0.0",
"logrocket-react": "^3.0.0",
"lz-string": "^1.4.4",
"majo": "^0.8.0",
"mockdate": "^2.0.2",
"node-fetch": "^2.6.0",
"pre-commit": "^1.2.2",
@ -175,13 +173,6 @@
"react-sticky": "^6.0.3",
"react-test-renderer": "^16.8.6",
"react-virtualized": "~9.21.1",
"remark-cli": "^6.0.1",
"remark-frontmatter": "^1.3.1",
"remark-lint": "^6.0.4",
"remark-parse": "^6.0.3",
"remark-preset-lint-recommended": "^3.0.2",
"remark-stringify": "^6.0.4",
"remark-yaml-config": "^4.0.3",
"reqwest": "^2.0.5",
"rimraf": "^2.6.3",
"scrollama": "^2.0.0",
@ -193,7 +184,6 @@
"stylelint-declaration-block-no-ignored-properties": "^2.1.0",
"stylelint-order": "^3.0.0",
"typescript": "~3.5.1",
"unified": "^7.1.0",
"xhr-mock": "^2.4.1",
"xhr2": "^0.2.0"
},
@ -214,7 +204,8 @@
"lint-fix:code": "eslint --fix tests site scripts components ./.*.js ./webpack.config.js --ext '.js,.jsx'",
"lint-fix:demo": "eslint-tinker ./components/*/demo/*.md",
"lint-fix:style": "stylelint --fix '{site,components}/**/*.less' --syntax less",
"sort-api": "node ./scripts/sort-api-table.js",
"sort-api": "antd-tools run sort-api-table",
"api-collection": "antd-tools run api-collection",
"dist": "antd-tools run dist",
"compile": "antd-tools run compile",
"tsc": "tsc",

View File

@ -1,66 +0,0 @@
// 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);
// eslint-disable-next-line no-console
console.log('| name | components | comments |');
// eslint-disable-next-line no-console
console.log('| ---- | ---------- | -------- |');
apiList.forEach(({ name, componentList }) => {
// eslint-disable-next-line no-console
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));
});

View File

@ -1,132 +0,0 @@
const program = require('commander');
const majo = require('majo');
const style = require('ansi-styles');
const unified = require('unified');
const parse = require('remark-parse');
const stringify = require('remark-stringify');
const yamlConfig = require('remark-yaml-config');
const frontmatter = require('remark-frontmatter');
const remarkWithYaml = unified()
.use(parse)
.use(stringify, {
paddedTable: false,
listItemIndent: 1,
})
.use(frontmatter)
.use(yamlConfig);
const stream = majo();
function getCellValue(node) {
return node.children[0].children[0].value;
}
// from small to large
const sizeBreakPoints = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
const groups = {
isDynamic: val => /^on[A-Z]/.test(val),
isSize: val => sizeBreakPoints.indexOf(val) > -1,
};
function asciiSort(prev, next) {
if (prev > next) {
return 1;
}
if (prev < next) {
return -1;
}
return 0;
}
// follow the alphabet order
function alphabetSort(nodes) {
// use toLowerCase to keep `case insensitive`
return nodes.sort((...comparison) =>
asciiSort(...comparison.map(val => getCellValue(val).toLowerCase())),
);
}
function sizeSort(nodes) {
return nodes.sort((...comparison) =>
asciiSort(...comparison.map(val => sizeBreakPoints.indexOf(getCellValue(val).toLowerCase()))),
);
}
function sort(ast) {
ast.children.forEach(child => {
const staticProps = [];
// prefix with `on`
const dynamicProps = [];
// one of ['xs', 'sm', 'md', 'lg', 'xl']
const sizeProps = [];
// find table markdown type
if (child.type === 'table') {
// slice will create new array, so sort can affect the original array.
// slice(1) cut down the thead
child.children.slice(1).forEach(node => {
const value = getCellValue(node);
if (groups.isDynamic(value)) {
dynamicProps.push(node);
} else if (groups.isSize(value)) {
sizeProps.push(node);
} else {
staticProps.push(node);
}
});
// eslint-disable-next-line
child.children = [
child.children[0],
...alphabetSort(staticProps),
...sizeSort(sizeProps),
...alphabetSort(dynamicProps),
];
}
});
return ast;
}
function sortAPI(md) {
return remarkWithYaml.stringify(sort(remarkWithYaml.parse(md)));
}
program
.version('0.1.0')
.option(
'-f, --file [file]',
'Specify which file to be transformed',
// default value
'components/**/index.+(zh-CN|en-US).md',
)
.parse(process.argv);
function sortMiddleware(ctx) {
Object.keys(ctx.files).forEach(filename => {
const content = ctx.fileContents(filename);
ctx.writeContents(filename, sortAPI(content));
});
}
// Get the markdown file all need to be transformed
stream
.source(program.file)
.use(sortMiddleware)
.dest('.')
.then(() => {
/* eslint-disable no-console */
console.log(`${style.green.open}sort ant-design api successfully!${style.green.close}`);
/* eslint-enable no-console */
});
module.exports = {
getCellValue,
sort,
};