You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
2 years ago
|
/* eslint-disable no-console */
|
||
|
import chalk from 'chalk';
|
||
|
import fs from 'fs-extra';
|
||
|
import ProgressBar from 'progress';
|
||
|
import React from 'react';
|
||
|
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';
|
||
3 years ago
|
|
||
|
console.log(chalk.green(`🔥 Collecting token statistics...`));
|
||
|
|
||
3 years ago
|
const bar = new ProgressBar('🚀 Collecting by component: [:bar] :component (:current/:total)', {
|
||
|
complete: '=',
|
||
|
incomplete: ' ',
|
||
2 years ago
|
total: styleFiles.length,
|
||
3 years ago
|
});
|
||
|
|
||
2 years ago
|
generateCssinjs({
|
||
|
key: 'file',
|
||
2 years ago
|
beforeRender(componentName: string) {
|
||
2 years ago
|
bar.tick(1, { component: componentName });
|
||
|
},
|
||
2 years ago
|
render(Component: any) {
|
||
2 years ago
|
ReactDOMServer.renderToString(React.createElement(Component));
|
||
|
// Render wireframe
|
||
|
ReactDOMServer.renderToString(
|
||
|
React.createElement(
|
||
|
DesignTokenContext.Provider,
|
||
|
{ value: { token: { ...seedToken, wireframe: true } } },
|
||
|
React.createElement(Component),
|
||
|
),
|
||
|
);
|
||
|
},
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
2 years ago
|
(() => {
|
||
|
const tokenPath = `${process.cwd()}/components/version/token.json`;
|
||
|
fs.writeJsonSync(tokenPath, statistic, 'utf8');
|
||
3 years ago
|
console.log(chalk.green(`✅ Collected token statistics successfully, check it in`), tokenPath);
|
||
3 years ago
|
})();
|