ant-design/scripts/generate-cssinjs.js
dependabot[bot] 5b23a6aac2
chore(deps-dev): bump glob from 9.3.5 to 10.0.0 (#41737)
* chore(deps-dev): bump glob from 9.3.5 to 10.0.0

Bumps [glob](https://github.com/isaacs/node-glob) from 9.3.5 to 10.0.0.
- [Release notes](https://github.com/isaacs/node-glob/releases)
- [Changelog](https://github.com/isaacs/node-glob/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/node-glob/compare/v9.3.5...v10.0.0)

---
updated-dependencies:
- dependency-name: glob
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: upgrade glob usage

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: afc163 <afc163@gmail.com>
2023-04-12 11:40:09 +08:00

43 lines
1.2 KiB
JavaScript

const React = require('react');
const { globSync } = require('glob');
const path = require('path');
const styleFiles = 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) => {
const pathArr = file.split('/');
const styleIndex = pathArr.lastIndexOf('style');
const componentName = pathArr[styleIndex - 1];
let useStyle = () => {};
if (file.includes('grid')) {
// eslint-disable-next-line global-require,import/no-dynamic-require
const { useColStyle, useRowStyle } = require(file);
useStyle = (prefixCls) => {
useRowStyle(prefixCls);
useColStyle(prefixCls);
};
} else {
// eslint-disable-next-line global-require,import/no-dynamic-require
useStyle = require(file).default;
}
const Component = () => {
useStyle(`${key}-${componentName}`);
return EmptyElement;
};
beforeRender?.(componentName);
render(Component);
});
},
filenames: styleFiles,
};