-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcompile.js
60 lines (51 loc) · 1.29 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const path = require('path');
const fs = require('fs-extra');
const solc = require('solc');
const buildPath = path.resolve(__dirname, 'build');
const contractsFolderPath = path.resolve(__dirname, 'contracts');
const createBuildFolder = () => {
fs.emptyDirSync(buildPath);
};
const buildSources = () => {
const sources = {};
const contractsFiles = fs.readdirSync(contractsFolderPath);
contractsFiles.forEach((file) => {
const contractFullPath = path.resolve(contractsFolderPath, file);
sources[file] = {
content: fs.readFileSync(contractFullPath, 'utf8'),
};
});
return sources;
};
const input = {
language: 'Solidity',
sources: buildSources(),
settings: {
outputSelection: {
'*': {
'*': ['abi', 'evm.bytecode'],
},
},
},
};
const compileContracts = () => {
const compiledContracts = JSON.parse(
solc.compile(JSON.stringify(input))
).contracts;
for (let contract in compiledContracts) {
for (let contractName in compiledContracts[contract]) {
console.log(contract);
fs.outputJsonSync(
path.resolve(buildPath, `${contractName}.json`),
compiledContracts[contract][contractName],
{
spaces: 2,
}
);
}
}
};
(function run() {
createBuildFolder();
compileContracts();
})();