import { mkdir } from 'node:fs/promises';
import { build } from 'esbuild';

await mkdir('scripts', { recursive: true });

await build({
	entryPoints: ['includes/loader.js'],
	outfile: 'scripts/builder-bundle.min.js',
	bundle: true,
	format: 'iife',
	target: ['es2018'],
	minify: true,
	logLevel: 'info',
	banner: {
		js: 'window.React=window.React||window.wp&&window.wp.element;',
	},
});

await build({
	entryPoints: ['scripts/frontend.js'],
	outfile: 'scripts/frontend-bundle.min.js',
	bundle: true,
	format: 'iife',
	target: ['es2018'],
	minify: true,
	logLevel: 'info',
});
