const { dependencies } = require('./package.json');
const path = require('path');
const fs = require('fs-extra');
const esBuild = require('esbuild');

const entryFile = 'src/index.ts';
const shared = {
  bundle: true,
  minify: true,
  sourcemap: true,
  entryPoints: [entryFile],
  external: Object.keys(dependencies).concat('pg-native'),
  logLevel: 'info',
  format: 'cjs',
  platform: 'node',
  target: 'node16',
  treeShaking: true,
  outfile: 'lib/index.js',
};

Promise.all([
  esBuild.build({
    ...shared,
  }),
]).catch(() => process.exit(1));

// Copy the src component-init-src to the lib folder
fs.copySync(path.resolve(__dirname, 'templates'), path.resolve(__dirname, 'lib/templates'));
