-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.js
66 lines (55 loc) · 1.57 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
61
62
63
64
65
66
const path = require("path");
const solc = require("solc");
const fs = require("fs-extra");
// libraries folder
// const SafeMathSourceCode = fs.readFileSync(
// "./contracts/libraries/SafeMath.sol"
// );
// core folder
const ProjectSourceCode = fs.readFileSync("./contracts/Project.sol");
const ProjectCreatorSourceCode = fs.readFileSync(
"./contracts/ProjectCreator.sol"
);
const buildPath = path.resolve(__dirname, "build");
fs.removeSync(buildPath);
function compileContract(Contract) {
const contractPath = path.resolve(__dirname, ...Contract);
const contractSourceCode = fs.readFileSync(contractPath, "utf8");
fs.ensureDirSync(buildPath);
var input = {
language: "Solidity",
sources: {
Contract: {
content: contractSourceCode,
},
},
settings: {
optimizer: {
enabled: true,
},
outputSelection: {
"*": {
"*": ["*"],
},
},
},
};
function findImports(path) {
// if (path === "libraries/SafeMath.sol")
// return { contents: `${SafeMathSourceCode}` };
if (path === "Project.sol") return { contents: `${ProjectSourceCode}` };
else return { error: "File not found" };
}
let output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);
for (let contractName in output.contracts.Contract) {
fs.outputJsonSync(
path.resolve(buildPath, `${contractName}.json`),
output.contracts.Contract[contractName]
);
}
}
compileContract(["./", "contracts", "Project.sol"]);
compileContract(["./", "contracts", "ProjectCreator.sol"]);
// compileContract(["./", "contracts", "libraries", "SafeMath.sol"]);