UNPKG

solidity-audit

Version:
72 lines (62 loc) 1.64 kB
#!/usr/bin/env node 'use strict'; /** * @author github.com/tintinweb * @license MIT * * * */ const glob = require("glob"); const {SolidityMetricsContainer} = require('./metrics/metrics'); const {exportAsHtml} = require('./metrics/helper'); let metrics = new SolidityMetricsContainer("'CLI'", { basePath: "", initDoppelGanger: undefined, inputFileGlobExclusions: undefined, inputFileGlob: undefined, inputFileGlobLimit: undefined, debug: false, repoInfo: { branch: undefined, commit: undefined, remote: undefined } }); const STATE_ID = "--id"; const STATE_JSON = "--json-report"; const STATE_EMPTY = ""; let options = []; const args = new Map(); var prevValue = STATE_EMPTY; process.argv.slice(1,).forEach(f => { args.set(prevValue, f); prevValue = STATE_EMPTY; if (f.startsWith("--")) { prevValue = f; options.push(f); } else if (f.endsWith(".sol")) { // analyze files glob.sync(f).forEach(fg => metrics.analyze(fg)); } }); // output //console.log(metrics.totals()); let dotGraphs = {}; try { dotGraphs = metrics.getDotGraphs(); } catch (error) { console.log(error); } if (options.includes(STATE_ID)) { metrics.addRequestId(args.get(STATE_ID)); } if(options.includes(STATE_JSON)) { metrics.addResultJson(args.get(STATE_JSON)); } metrics.generateReportMarkdown().then(md => { if (options.includes("--html")) { console.log(exportAsHtml(md, metrics.totals(), dotGraphs)); } else { console.log(md); } });