2022-07-04 22:08:24 +08:00
|
|
|
/* eslint-disable import/no-unresolved,no-console,global-require,import/no-dynamic-require */
|
2022-05-30 20:22:48 +08:00
|
|
|
|
|
|
|
const chalk = require('chalk');
|
|
|
|
const React = require('react');
|
|
|
|
const ReactDOMServer = require('react-dom/server');
|
|
|
|
const fs = require('fs-extra');
|
2022-07-04 22:08:24 +08:00
|
|
|
const glob = require('glob');
|
|
|
|
const path = require('path');
|
2022-07-05 14:23:43 +08:00
|
|
|
const ProgressBar = require('progress');
|
2022-07-04 22:08:24 +08:00
|
|
|
const { statistic } = require('../components/theme/util/statistic');
|
2022-11-23 20:22:38 +08:00
|
|
|
const { DesignTokenContext } = require('../components/theme/internal');
|
2022-09-13 11:52:56 +08:00
|
|
|
const seedToken = require('../components/theme/themes/seed');
|
2022-05-30 20:22:48 +08:00
|
|
|
|
|
|
|
console.log(chalk.green(`🔥 Collecting token statistics...`));
|
|
|
|
|
|
|
|
const EmptyElement = React.createElement('div');
|
|
|
|
|
2022-07-04 22:08:24 +08:00
|
|
|
const styleFiles = glob.sync(
|
|
|
|
path.join(
|
|
|
|
process.cwd(),
|
2023-01-04 17:54:31 +08:00
|
|
|
'components/!(version|config-provider|icon|locale-provider|auto-complete|col|row|time-picker|)/style/index.?(ts|tsx)',
|
2022-07-04 22:08:24 +08:00
|
|
|
),
|
2022-05-30 20:22:48 +08:00
|
|
|
);
|
2022-07-05 14:23:43 +08:00
|
|
|
|
|
|
|
const bar = new ProgressBar('🚀 Collecting by component: [:bar] :component (:current/:total)', {
|
|
|
|
complete: '=',
|
|
|
|
incomplete: ' ',
|
|
|
|
total: styleFiles.length,
|
|
|
|
});
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
styleFiles.forEach((file) => {
|
2022-07-05 14:23:43 +08:00
|
|
|
const pathArr = file.split('/');
|
|
|
|
const styleIndex = pathArr.lastIndexOf('style');
|
|
|
|
const componentName = pathArr[styleIndex - 1];
|
|
|
|
bar.tick(1, { component: componentName });
|
2022-07-04 22:08:24 +08:00
|
|
|
let useStyle = () => {};
|
|
|
|
if (file.includes('grid')) {
|
|
|
|
const { useColStyle, useRowStyle } = require(file);
|
|
|
|
useStyle = () => {
|
|
|
|
useRowStyle();
|
|
|
|
useColStyle();
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
useStyle = require(file).default;
|
|
|
|
}
|
|
|
|
const Component = () => {
|
|
|
|
useStyle('file');
|
|
|
|
return EmptyElement;
|
|
|
|
};
|
|
|
|
ReactDOMServer.renderToString(React.createElement(Component));
|
2022-09-13 11:52:56 +08:00
|
|
|
// Render wireframe
|
|
|
|
ReactDOMServer.renderToString(
|
|
|
|
React.createElement(
|
|
|
|
DesignTokenContext.Provider,
|
|
|
|
{ value: { token: { ...seedToken, wireframe: true } } },
|
|
|
|
React.createElement(Component),
|
|
|
|
),
|
|
|
|
);
|
2022-07-04 22:08:24 +08:00
|
|
|
});
|
2022-05-30 20:22:48 +08:00
|
|
|
|
2022-11-25 14:23:11 +08:00
|
|
|
(() => {
|
|
|
|
const tokenPath = `${process.cwd()}/components/version/token.json`;
|
|
|
|
fs.writeJsonSync(tokenPath, statistic, 'utf8');
|
2022-05-31 16:44:55 +08:00
|
|
|
|
2022-07-05 14:23:43 +08:00
|
|
|
console.log(chalk.green(`✅ Collected token statistics successfully, check it in`), tokenPath);
|
2022-05-30 20:22:48 +08:00
|
|
|
})();
|