const fs = require('fs');

const fromFolder = `${__dirname}/icons`;
const fromNewFolder = `${__dirname}/new-icons`;
const toFolder = `${__dirname}/components`;

async function bootstrap() {
  let icons = 'export default {\n';
  await Promise.all(fs.readdirSync(fromFolder).map((file) => {
    return new Promise((resolve) => {
      fs.readFile(`${fromFolder}/${file}`, { encoding: 'utf-8' }, (err, data) => {
        fs.writeFile(`${toFolder}/${file.replace('.svg', '.vue')}`, `<template>${data}</template>`, (err) => {
          icons += `  '${file.replace('.svg', '')}': () => import('./components/${file.replace('.svg', '.vue')}'),\n`;
          resolve();
        });
      });
    });
  }));
  await Promise.all(fs.readdirSync(fromNewFolder).map((file) => {
    if (file.includes('.DS_Store')) {
      return;
    }
    return new Promise((resolve) => {
      fs.readFile(`${fromNewFolder}/${file}`, { encoding: 'utf-8' }, (err, data) => {
        fs.writeFile(`${toFolder}/nomi-${file.replace('.svg', '.vue')}`, `<template>${data}</template>`, (err) => {
          icons += `  'nomi-${file.replace('.svg', '')}': () => import('./components/nomi-${file.replace('.svg', '.vue')}'),\n`;
          resolve();
        });
      });
    });
  }));
  icons += '}';

  fs.writeFile(`${fromFolder}.js`, icons, (err) => {

  });
}
bootstrap();
