Merge pull request #951 from cryptomental/feature/add-output-option-to-embark-graph

cmd, cmd_controller, graph: Add --output option to graph.
This commit is contained in:
Iuri Matias 2018-10-02 18:39:37 -04:00 committed by GitHub
commit c09c58f406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -30,6 +30,8 @@ process.env.NODE_PATH = utils.joinPath(process.env.EMBARK_PATH, 'node_modules')
(process.env.NODE_PATH ? require('path').delimiter : '') +
(process.env.NODE_PATH || '');
process.env.DEFAULT_DIAGRAM_PATH = utils.joinPath(process.env.DAPP_PATH, 'diagram.svg');
function checkDeps() {
const path = require('path');
try {
@ -331,6 +333,7 @@ class Cmd {
.option('--skip-functions', __('Graph will not include functions'))
.option('--skip-events', __('Graph will not include events'))
.option('--locale [locale]', __('language to use (default: en)'))
.option('--output [svgfile]', __('filepath to output SVG graph to (default: %s)', process.env['DEFAULT_DIAGRAM_PATH']))
.description(__('generates documentation based on the smart contracts configured'))
.action(function(env, options) {
checkDeps();
@ -340,7 +343,8 @@ class Cmd {
logFile: options.logfile,
skipUndeployed: options.skipUndeployed,
skipFunctions: options.skipFunctions,
skipEvents: options.skipEvents
skipEvents: options.skipEvents,
output: options.output || process.env['DEFAULT_DIAGRAM_PATH']
});
});
}

View File

@ -399,7 +399,7 @@ class EmbarkController {
} else {
engine.events.request("graph:create", options, () => {
engine.logger.info(__("Done. %s generated", "./diagram.svg").underline);
engine.logger.info(__("Done. %s generated", options.output).underline);
});
}
process.exit();

View File

@ -133,9 +133,7 @@ class GraphGenerator {
let svg = Viz(dot);
let filename = "diagram.svg";
fs.writeFileSync(filename, svg, (err) => {
fs.writeFileSync(options.output, svg, (err) => {
if (err) throw err;
next();
});