You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
2 years ago
|
/* eslint-disable no-console */
|
||
|
import {
|
||
2 years ago
|
StyleProvider,
|
||
|
legacyNotSelectorLinter,
|
||
2 years ago
|
logicalPropertiesLinter,
|
||
2 years ago
|
parentSelectorLinter,
|
||
2 years ago
|
} from '@ant-design/cssinjs';
|
||
|
import chalk from 'chalk';
|
||
|
import React from 'react';
|
||
|
import ReactDOMServer from 'react-dom/server';
|
||
|
import { generateCssinjs } from './generate-cssinjs';
|
||
2 years ago
|
|
||
|
console.log(chalk.green(`🔥 Checking CSS-in-JS...`));
|
||
|
|
||
|
let errorCount = 0;
|
||
|
const originError = console.error;
|
||
2 years ago
|
console.error = (msg: any) => {
|
||
2 years ago
|
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);
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
generateCssinjs({
|
||
|
key: 'check',
|
||
2 years ago
|
render(Component: any) {
|
||
2 years ago
|
ReactDOMServer.renderToString(
|
||
|
React.createElement(
|
||
|
StyleProvider,
|
||
|
{ linters: [logicalPropertiesLinter, legacyNotSelectorLinter, parentSelectorLinter] },
|
||
|
React.createElement(Component),
|
||
|
),
|
||
|
);
|
||
|
},
|
||
2 years ago
|
});
|
||
|
|
||
|
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.`));
|
||
|
}
|