2023-04-28 23:21:51 +08:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
import {
|
2023-01-20 10:31:27 +08:00
|
|
|
StyleProvider,
|
|
|
|
legacyNotSelectorLinter,
|
2023-04-28 23:21:51 +08:00
|
|
|
logicalPropertiesLinter,
|
2023-01-20 10:31:27 +08:00
|
|
|
parentSelectorLinter,
|
2023-04-28 23:21:51 +08:00
|
|
|
} from '@ant-design/cssinjs';
|
|
|
|
import chalk from 'chalk';
|
|
|
|
import React from 'react';
|
|
|
|
import ReactDOMServer from 'react-dom/server';
|
|
|
|
import { generateCssinjs } from './generate-cssinjs';
|
2023-01-20 10:31:27 +08:00
|
|
|
|
|
|
|
console.log(chalk.green(`🔥 Checking CSS-in-JS...`));
|
|
|
|
|
|
|
|
let errorCount = 0;
|
|
|
|
const originError = console.error;
|
2023-04-28 23:21:51 +08:00
|
|
|
console.error = (msg: any) => {
|
2023-01-20 10:31:27 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-03 11:59:25 +08:00
|
|
|
generateCssinjs({
|
|
|
|
key: 'check',
|
2023-04-28 23:21:51 +08:00
|
|
|
render(Component: any) {
|
2023-04-03 11:59:25 +08:00
|
|
|
ReactDOMServer.renderToString(
|
|
|
|
React.createElement(
|
|
|
|
StyleProvider,
|
|
|
|
{ linters: [logicalPropertiesLinter, legacyNotSelectorLinter, parentSelectorLinter] },
|
|
|
|
React.createElement(Component),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-01-20 10:31:27 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
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.`));
|
|
|
|
}
|