2023-11-13 11:56:13 +08:00
|
|
|
/* eslint-disable no-console */
|
2023-11-14 10:30:57 +08:00
|
|
|
import React from 'react';
|
2023-11-13 11:56:13 +08:00
|
|
|
import {
|
|
|
|
legacyNotSelectorLinter,
|
|
|
|
logicalPropertiesLinter,
|
|
|
|
NaNLinter,
|
|
|
|
parentSelectorLinter,
|
|
|
|
StyleProvider,
|
|
|
|
} from '@ant-design/cssinjs';
|
|
|
|
import chalk from 'chalk';
|
|
|
|
import ReactDOMServer from 'react-dom/server';
|
2023-11-14 10:30:57 +08:00
|
|
|
|
2023-11-13 11:56:13 +08:00
|
|
|
import { ConfigProvider } from '../components';
|
2023-11-14 10:30:57 +08:00
|
|
|
import { generateCssinjs } from './generate-cssinjs';
|
2023-11-13 11:56:13 +08:00
|
|
|
|
|
|
|
console.log(chalk.green(`🔥 Checking CSS-in-JS...`));
|
|
|
|
|
|
|
|
let errorCount = 0;
|
|
|
|
const originError = console.error;
|
|
|
|
console.error = (msg: any) => {
|
|
|
|
if (msg.includes('Warning: [Ant Design CSS-in-JS]')) {
|
|
|
|
errorCount += 1;
|
|
|
|
console.log(chalk.red(`❌ `), msg.slice(msg.indexOf('Error in')).replace(/\s+/g, ' '));
|
|
|
|
} else {
|
|
|
|
originError(msg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
async function checkCSSVar() {
|
|
|
|
const ignore = [
|
|
|
|
'calendar',
|
|
|
|
'cascader',
|
|
|
|
'checkbox',
|
|
|
|
'collapse',
|
|
|
|
'color-picker',
|
|
|
|
'float-button',
|
|
|
|
'grid',
|
|
|
|
'icon',
|
|
|
|
'pagination',
|
|
|
|
'radio',
|
|
|
|
'space',
|
|
|
|
'steps',
|
|
|
|
'switch',
|
|
|
|
'table',
|
|
|
|
];
|
|
|
|
|
|
|
|
await generateCssinjs({
|
|
|
|
key: 'check',
|
|
|
|
ignore,
|
|
|
|
render(Component: any) {
|
|
|
|
ReactDOMServer.renderToString(
|
|
|
|
<StyleProvider linters={[NaNLinter]}>
|
|
|
|
<ConfigProvider theme={{ cssVar: true, hashed: false }}>
|
|
|
|
<Component />
|
|
|
|
</ConfigProvider>
|
|
|
|
</StyleProvider>,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
await generateCssinjs({
|
|
|
|
key: 'check',
|
|
|
|
render(Component: any) {
|
|
|
|
ReactDOMServer.renderToString(
|
|
|
|
<StyleProvider
|
|
|
|
linters={[logicalPropertiesLinter, legacyNotSelectorLinter, parentSelectorLinter]}
|
|
|
|
>
|
|
|
|
<Component />
|
|
|
|
</StyleProvider>,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await checkCSSVar();
|
|
|
|
|
|
|
|
if (errorCount > 0) {
|
|
|
|
console.log(chalk.red(`❌ CSS-in-JS check failed with ${errorCount} errors.`));
|
|
|
|
process.exit(1);
|
|
|
|
} else {
|
|
|
|
console.log(chalk.green(`✅ CSS-in-JS check passed.`));
|
|
|
|
}
|
|
|
|
})();
|