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
This commit is contained in:
Cryptomental 2018-10-01 20:39:45 +02:00 committed by Pascal Precht
parent 0483920421
commit 10bf3e4412
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
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 {
@ -332,6 +334,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();
@ -341,7 +344,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();
});