const path = require('path');
const keysTransformer = require('ts-transformer-keys/transformer').default;
const SRC_DIR = path.join(__dirname, 'src');

module.exports = (env, argv) => {
  // 共通設定項目
  const BASE_CONFIG = {
    mode: ("mode" in argv) ? argv["mode"] : "development",
    output: {
      filename: '[name].js',
      path: path.join(__dirname, 'app'),
    },
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          use: [
            {
              loader: 'ts-loader',
              options: {
                getCustomTransformers: p => ({
                  before: [keysTransformer(p)]
                })
              }
            }
          ],
          exclude: [
            /node_modules/,
          ]
        }
      ]
    },
    resolve: {
      extensions: ['.tsx', '.ts', '.js']
    }
  };

  return [
    // main
    Object.assign({}, BASE_CONFIG, {
      target: 'electron-main',
      entry: {
        main: path.join(SRC_DIR, 'main', 'main.ts'),
      },
      node: {
        __dirname: false,
        __filename: false,
      }
    }),
    // preload
    Object.assign({}, BASE_CONFIG, {
      target: 'electron-preload',
      entry: {
        preload: path.join(SRC_DIR, 'preload', 'preload.ts'),
      }
    }),
    // renderer
    Object.assign({}, BASE_CONFIG, {
      target: 'web',
      entry: {
        renderer: path.join(SRC_DIR, 'renderer', 'renderer.ts')
      }
    })
  ];
}
