ant-design/scripts/collect-token-statistic.ts
二货爱吃白萝卜 317dac6a8e
refactor: more cache (#45302)
* chore: cache

* chore: clean up

* chore: clean up

* refactor: part

* chore: bump

* chore: fix lint

* chore: fix lint

* chore: fix alt
2023-10-13 11:54:05 +08:00

52 lines
1.6 KiB
TypeScript

/* eslint-disable no-console */
import React from 'react';
import chalk from 'chalk';
import fs from 'fs-extra';
import ProgressBar from 'progress';
import ReactDOMServer from 'react-dom/server';
import { DesignTokenContext } from '../components/theme/internal';
import seedToken from '../components/theme/themes/seed';
import { statistic } from '../components/theme/util/statistic';
import { generateCssinjs, styleFiles } from './generate-cssinjs';
console.log(chalk.green(`🔥 Collecting token statistics...`));
const bar = new ProgressBar('🚀 Collecting by component: [:bar] :component (:current/:total)', {
complete: '=',
incomplete: ' ',
total: styleFiles.length,
});
(async () => {
await generateCssinjs({
key: 'file',
beforeRender(componentName: string) {
bar.tick(1, { component: componentName });
},
render(Component: any) {
ReactDOMServer.renderToString(React.createElement(Component));
// Render wireframe
const wireframeToken = { ...seedToken, wireframe: true };
ReactDOMServer.renderToString(
React.createElement(
DesignTokenContext.Provider,
{
value: {
token: wireframeToken,
override: {
override: wireframeToken,
},
},
},
React.createElement(Component),
),
);
},
});
const tokenPath = `${process.cwd()}/components/version/token.json`;
fs.writeJsonSync(tokenPath, statistic, 'utf8');
console.log(chalk.green(`✅ Collected token statistics successfully, check it in`), tokenPath);
})();