mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 03:59:01 +08:00
fd53ce6258
* chore: share component render in scripts * chore: code clean
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const React = require('react');
|
|
const glob = require('glob');
|
|
const path = require('path');
|
|
|
|
const styleFiles = glob.globSync(
|
|
path.join(
|
|
process.cwd(),
|
|
'components/!(version|config-provider|icon|auto-complete|col|row|time-picker)/style/index.?(ts|tsx)',
|
|
),
|
|
);
|
|
|
|
module.exports = {
|
|
generateCssinjs({ key, beforeRender, render }) {
|
|
const EmptyElement = React.createElement('div');
|
|
|
|
styleFiles.forEach((file) => {
|
|
let useStyle = () => {};
|
|
if (file.includes('grid')) {
|
|
// eslint-disable-next-line global-require,import/no-dynamic-require
|
|
const { useColStyle, useRowStyle } = require(file);
|
|
useStyle = () => {
|
|
useRowStyle();
|
|
useColStyle();
|
|
};
|
|
} else {
|
|
// eslint-disable-next-line global-require,import/no-dynamic-require
|
|
useStyle = require(file).default;
|
|
}
|
|
const Component = () => {
|
|
useStyle(key);
|
|
return EmptyElement;
|
|
};
|
|
|
|
const pathArr = file.split('/');
|
|
const styleIndex = pathArr.lastIndexOf('style');
|
|
const componentName = pathArr[styleIndex - 1];
|
|
beforeRender?.(componentName);
|
|
render(Component);
|
|
});
|
|
},
|
|
filenames: styleFiles,
|
|
};
|