-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild:contracts.ts
48 lines (41 loc) · 1.15 KB
/
build:contracts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as Fs from 'node:fs/promises'
import * as Path from 'node:path'
await Fs.rmdir(
Path.resolve(
import.meta.dirname,
'../src/core/internal/_generated/contracts',
),
{ recursive: true },
)
await Fs.mkdir(
Path.resolve(
import.meta.dirname,
'../src/core/internal/_generated/contracts',
),
{
recursive: true,
},
)
for await (const file of Fs.glob(
Path.resolve(import.meta.dirname, '../contracts/src/**/*.sol'),
)) {
const name = Path.basename(file)
const outPath = Path.resolve(import.meta.dirname, '../contracts/out/' + name)
for await (const file of await Fs.readdir(outPath)) {
const path = Path.resolve(outPath, file)
const name = Path.basename(path, '.json')
const { abi, bytecode } = JSON.parse(await Fs.readFile(path, 'utf-8'))
let code = ''
code += `export const abi = ${JSON.stringify(abi, null, 2)} as const;\n\n`
code += `export const code = ${JSON.stringify(
bytecode.object,
null,
2,
)} as const;\n\n`
const out = Path.resolve(
import.meta.dirname,
`../src/core/internal/_generated/contracts/${name}.ts`,
)
await Fs.appendFile(out, code)
}
}