diff --git a/scripts/build.ts b/scripts/build.ts index 84f50fe..4a25ab1 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -1,25 +1,54 @@ import { join } from 'path'; import { InterwebBuild, InterwebBuildOptions } from '@interweb/build'; -const root = join(__dirname, '/../'); -const outputDir = join(root, 'contracts'); -const srcDir = join(root, 'src'); +interface BuildConfig { + entryFile: string; + outFile: string; + externalPackages: string[]; +} + +const rootDir = join(__dirname, '/../'); + +async function buildInterweb(config: BuildConfig): Promise { + const { entryFile, outFile, externalPackages } = config; -async function main() { - const outfile = join(outputDir, 'contract1.js'); - const options: Partial = { - entryPoints: [join(srcDir, 'contract1/index.ts')], - outfile, - external: ['otherpackage', '~somepackage'], + entryPoints: [join(rootDir, entryFile)], + outfile: join(rootDir, outFile), + external: externalPackages }; try { await InterwebBuild.build(options); - console.log('Build completed successfully!'); + console.log(`Build completed successfully! Output: ${options.outfile}`); } catch (error) { console.error('Build failed:', error); + throw error; + } +} + +// Example usage +async function main() { + const configs: BuildConfig[] = [ + { + entryFile: 'src/contract1/index.ts', + outFile: 'contracts/bundle1.js', + externalPackages: ['otherpackage', '~somepackage'] + }, + { + entryFile: 'src/contract2/index.ts', + outFile: 'contracts/bundle2.js', + externalPackages: ['differentpackage'] + } + ]; + + for (const config of configs) { + try { + await buildInterweb(config); + } catch (error) { + console.error(`Build failed for ${config.entryFile}:`, error); + } } } -main().catch(console.error); +main().catch(console.error); \ No newline at end of file