Skip to content

Commit

Permalink
Merge pull request #5 from hyperweb-io/feat/multi-contracts
Browse files Browse the repository at this point in the history
multiple contracts
  • Loading branch information
pyramation authored Oct 2, 2024
2 parents 6c19025 + bb50ef4 commit a50790e
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const { entryFile, outFile, externalPackages } = config;

async function main() {
const outfile = join(outputDir, 'contract1.js');

const options: Partial<InterwebBuildOptions> = {
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);

0 comments on commit a50790e

Please sign in to comment.