-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcompile.js
44 lines (37 loc) · 1016 Bytes
/
compile.js
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
const solc = require('solc')
const fs = require('fs')
// const input = require('./contracts.json')
const CONTRACT_NAME = 'Batcher.sol'
const CONTRACT_FILE = `./contracts/${CONTRACT_NAME}`
const CONTRACT_NAME2 = 'Dummy.sol'
const CONTRACT_FILE2 = `./contracts/${CONTRACT_NAME2}`
const content = fs.readFileSync(CONTRACT_FILE).toString()
const content2 = fs.readFileSync(CONTRACT_FILE2).toString()
const input = {
language: 'Solidity',
sources: {
[CONTRACT_NAME]: {
content: content
},
[CONTRACT_NAME2]: {
content: content2
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
}
// console.log(input)
const output = solc.compile(JSON.stringify(input))
const errors = JSON.parse(output).errors
console.log(errors)
if (errors.filter((err) => err.severity !== 'warning').length > 0) {
throw Error(`Compile error -- see stdout`)
}
const outFile = './build.json'
fs.writeFileSync(outFile, output)
console.log(`output written to ${outFile}`)