From 7c5bda319e435c70b6958d1854adf02b50ae9632 Mon Sep 17 00:00:00 2001 From: Cryptomental Date: Mon, 1 Oct 2018 20:39:45 +0200 Subject: [PATCH] cmd, cmd_controller, graph: Add --output option to graph. Add optional --output argument to graph generator. The argument allows to specify a filepath for graph output. Default filepath is ./diagram.svg if the argument is not specified. Refs: https://github.com/embark-framework/embark/issues/944 --- cmd/cmd.js | 6 +++++- cmd/cmd_controller.js | 2 +- lib/modules/graph/index.js | 4 +--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/cmd.js b/cmd/cmd.js index ff04da366..42156f6fb 100644 --- a/cmd/cmd.js +++ b/cmd/cmd.js @@ -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'] }); }); } diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index 41ff8ce76..b659b293d 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -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(); diff --git a/lib/modules/graph/index.js b/lib/modules/graph/index.js index 5ccfe2952..cc29ee1f5 100644 --- a/lib/modules/graph/index.js +++ b/lib/modules/graph/index.js @@ -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(); });