2023-04-28 23:21:51 +08:00
|
|
|
/* eslint-disable no-console */
|
2023-10-13 11:54:05 +08:00
|
|
|
import React from 'react';
|
2023-04-28 23:21:51 +08:00
|
|
|
import chalk from 'chalk';
|
2024-04-07 22:45:53 +08:00
|
|
|
import cliProgress from 'cli-progress';
|
2024-04-08 14:04:08 +08:00
|
|
|
import fs from 'fs-extra';
|
2023-04-28 23:21:51 +08:00
|
|
|
import ReactDOMServer from 'react-dom/server';
|
2023-10-13 11:54:05 +08:00
|
|
|
|
2023-04-28 23:21:51 +08:00
|
|
|
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';
|
2022-05-30 20:22:48 +08:00
|
|
|
|
2024-04-07 22:45:53 +08:00
|
|
|
console.log(`🪄 Collecting token statistics...`);
|
2022-05-30 20:22:48 +08:00
|
|
|
|
2024-04-07 22:45:53 +08:00
|
|
|
const bar = new cliProgress.SingleBar(
|
|
|
|
{
|
|
|
|
format: `🪄 Collecting by component: [${chalk.cyan('{bar}')}] {component} | {value}/{total}`,
|
|
|
|
},
|
|
|
|
cliProgress.Presets.rect,
|
|
|
|
);
|
|
|
|
|
|
|
|
bar.start(styleFiles.length, 0);
|
2022-07-05 14:23:43 +08:00
|
|
|
|
2023-05-08 15:25:48 +08:00
|
|
|
(async () => {
|
|
|
|
await generateCssinjs({
|
|
|
|
key: 'file',
|
|
|
|
beforeRender(componentName: string) {
|
2024-04-07 22:45:53 +08:00
|
|
|
bar.increment({ component: componentName });
|
2023-05-08 15:25:48 +08:00
|
|
|
},
|
|
|
|
render(Component: any) {
|
|
|
|
ReactDOMServer.renderToString(React.createElement(Component));
|
|
|
|
// Render wireframe
|
2023-10-13 11:54:05 +08:00
|
|
|
const wireframeToken = { ...seedToken, wireframe: true };
|
2023-05-08 15:25:48 +08:00
|
|
|
ReactDOMServer.renderToString(
|
|
|
|
React.createElement(
|
|
|
|
DesignTokenContext.Provider,
|
2023-10-13 11:54:05 +08:00
|
|
|
{
|
|
|
|
value: {
|
|
|
|
token: wireframeToken,
|
|
|
|
override: {
|
|
|
|
override: wireframeToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-05-08 15:25:48 +08:00
|
|
|
React.createElement(Component),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2024-04-07 22:45:53 +08:00
|
|
|
bar.stop();
|
2022-11-25 14:23:11 +08:00
|
|
|
const tokenPath = `${process.cwd()}/components/version/token.json`;
|
|
|
|
fs.writeJsonSync(tokenPath, statistic, 'utf8');
|
2024-04-07 22:45:53 +08:00
|
|
|
console.log(chalk.green(`✅ Collected token statistics successfully, check it in`), tokenPath);
|
2022-05-30 20:22:48 +08:00
|
|
|
})();
|