-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from hyperweb-io/feat/multi-contracts
multiple contracts
- Loading branch information
Showing
1 changed file
with
40 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |