-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
41 lines (34 loc) · 1.11 KB
/
index.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
const path = require("path");
const fs = require("fs-extra");
const shelljs = require("shelljs");
function isSlitherInstalled() {
return shelljs.which("slither");
}
function executeSlither(astFile, flags = '') {
shelljs.exec(`slither ${astFile} ${Array.isArray(flags) ? flags.join(' ') : flags}`);
}
function buildAstData(sources) {
const header = "JSON AST (compact format):\n";
const data = Object.keys(sources).map((key) => {
return `
======= ${key} =======
${JSON.stringify(sources[key].ast, null, 2)}
`;
});
return header + data.join("\n");
}
async function run(embark, compilationResult) {
if (!isSlitherInstalled()) {
console.log("Slither is not installed, visit: https://github.com/trailofbits/slither");
return;
}
const astFile = path.join(".embark", "slither", "ast.json");
const astData = buildAstData(compilationResult.sources);
await fs.ensureFile(astFile);
await fs.writeFile(astFile, astData);
executeSlither(astFile, embark.pluginConfig.flags);
}
function register(embark) {
embark.events.on("contracts:compiled:solc", run.bind(null, embark));
}
module.exports = register;