async function createIcons()

in packages/bui-icons/builder.js [30:64]


async function createIcons() {
  rimraf.sync(`${outputDir}/*.tsx`);

  const tsxFiles = [];
  const svgPaths = await globAsync(
    normalizePath(path.join(inputDir, '**/*.svg')),
  );

  svgPaths.forEach((svgPath) => {
    const data = fse.readFileSync(svgPath, { encoding: 'utf8' });
    const iconName = path.basename(svgPath).replace('.svg', '');
    const result = svgo.optimize(data);
    const pathData = result.data.match(/<svg[^>]+?>([^$]+?)<\/svg>/)[1];

    tsxFiles.push({
      name: iconName,
      content: `// Automatically generated by cli tools, please do not modify this file directly
import createSvgIcon from '../utils/createSvgIcon';

export default createSvgIcon(
  '${pathData}',
  '${iconName}Icon',
);
`,
    });
  });

  tsxFiles.forEach(({ name, content }) => {
    console.log(`${chalk.blue(name)} icon created`);
    const absDestPath = path.join(outputDir, `${name}.tsx`);
    fse.writeFileSync(absDestPath, content);
  });

  generateIndex();
}