const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const path = require( 'path' );
const glob = require( 'glob' );

// Auto-discover block entry points from src/blocks/*/index.js
const blockEntries = {};
const blockFiles = glob.sync( './src/blocks/*/index.js' );

blockFiles.forEach( ( file ) => {
	const name = file.match( /src\/blocks\/(.+?)\/index\.js/ )[ 1 ];
	blockEntries[ `blocks/${ name }/index` ] = path.resolve( process.cwd(), file );
} );

module.exports = {
	...defaultConfig,
	entry: {
		...blockEntries,
	},
	output: {
		...defaultConfig.output,
		path: path.resolve( process.cwd(), 'build' ),
	},
};
