'use strict';

const { existsSync, copyFileSync } = require('fs');
const { dirname, join } = require('path');
const mkdirp = require('mkdirp');
const config = require('../config');

Object.keys(config).forEach(theme => {
  const { pkg } = config[theme];
  const buildDir = join(__dirname, '../..', 'build', theme);
  const themeDir = dirname(require.resolve(pkg));
  const sourceFile = join(themeDir, 'dist', 'next.css');
  const targetFile = join(buildDir, 'index.css');

  if (!existsSync(buildDir)) {
    mkdirp.sync(buildDir);
  }
  copyFileSync(sourceFile, targetFile);
});
