-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathresolc.ts
60 lines (54 loc) · 1.97 KB
/
resolc.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
49
50
51
52
53
54
55
56
57
58
59
60
//Example usage of ResoverEngine in solcjs-like wrapper for solc
//Prints only compiled contracts ABI
//Eg usage: ./resolc contracts/**/*.sol
const solc = require("solc");
const chalk = require("chalk");
const yargs = require("yargs");
import { gatherSources, ImportsFsEngine } from "@resolver-engine/imports-fs";
import glob = require("glob");
var argv = yargs.argv;
var filesGlob: string = "{" + argv._.join() + ",}";
function missingImport(p: string) {
console.log(chalk.magenta("File not supplied: ") + p);
return { contents: "" };
}
glob(filesGlob, function(er: Error | null, fileList: Array<string>) {
gatherSources(fileList, process.cwd(), ImportsFsEngine()).then(function(input) {
let sources: { [s: string]: {} } = {};
for (let file of input) {
sources[file.url] = { content: file.source };
}
const inputJSON = {
language: "Solidity",
sources: sources,
settings: {
evmVersion: "byzantium",
outputSelection: {
"*": {
"*": ["abi", "evm.bytecode"],
},
},
},
};
const compiledContractsString = solc.compile(JSON.stringify(inputJSON), missingImport);
const compiledContracts = JSON.parse(compiledContractsString);
for (let e of compiledContracts.errors) {
if (e.severity === "warning") {
console.log(chalk.yellow(chalk.bold("warning:")));
}
if (e.severity === "error") {
console.log(chalk.red(chalk.bold("error:")));
}
console.log(e.formattedMessage);
}
console.log(chalk.green(chalk.bold("COMPILED CONTRACTS:")));
for (let key in compiledContracts.contracts) {
console.log(chalk.blue("FILE: ") + chalk.bold(key));
for (let contract in compiledContracts.contracts[key]) {
console.log(chalk.cyan("Contract: ") + chalk.bold(contract));
console.log(chalk.green("ABI: ") + chalk.bold(JSON.stringify(compiledContracts.contracts[key][contract].abi)));
console.log();
}
}
});
});