-
Notifications
You must be signed in to change notification settings - Fork 0
/
compileAll.js
44 lines (38 loc) · 1.02 KB
/
compileAll.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
var path = require('path');
var solc = require('solc');
var fs = require('fs-extra');
const buildPath = path.resolve(__dirname, 'build');
fs.removeSync(buildPath);
fs.mkdirSync(buildPath);
fs.readdir(path.resolve(__dirname, 'contracts'), function (err, files) {
//listing all files using forEach
files.forEach(function (fileName) {
// Compile each .sol file and dump output in JSON format
console.log('Compiling ', fileName, '...');
const filePath = path.resolve(__dirname, 'contracts', fileName);
const source = fs.readFileSync(filePath, 'utf-8');
var input = {
language: 'Solidity',
sources: {
fileName: {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
var output = JSON.parse(solc.compile(JSON.stringify(input)));
for (let contract in output.contracts.fileName) {
fs.outputJSONSync(
path.resolve(buildPath, contract+'.json'),
output.contracts.fileName[contract]
);
}
console.log(fileName, ' compiled.');
});
});