ant-design/scripts/generate-cssinjs.js
MadCcc fd53ce6258
chore: share component render in scripts (#41603)
* chore: share component render in scripts

* chore: code clean
2023-04-03 11:59:25 +08:00

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,
};