Skip to content

Commit

Permalink
+ plantuml exec lib
Browse files Browse the repository at this point in the history
  • Loading branch information
rascafr committed Sep 2, 2019
1 parent 43d938b commit 14e748c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions plantuml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const PlantUML = module.exports;
const D = require('./definitions');
const { exec } = require('child_process');

PlantUML.toUML = function(frames) {
let file = ['@startuml'];
frames.forEach(frame => {
if (frame.cmd !== 0x65 && frame.cmd !== 0x64 && frame.cmd !== 0x61) {
file.push(format(frame));
}
});
file.push('@enduml');
return file.join('\n');
}

PlantUML.generateImage = function(jar, umlFile) {
exec(`java -jar ${jar} "${umlFile}"`, (err, stdout, stderr) => {
if (err) {
console.log('Failed to generate uml file', err);
} else {
console.log('UML file generated!');
}
});
}

function format(frame) {
return D.addresses[frame.src] + ' -> ' + D.addresses[frame.dst] + ': '
+ (D.commands[frame.cmd] || frame.cmd)
+ ' (' + (D.isRegisterOperation(frame.cmd) ? D.registers[frame.arg] || frame.arg : frame.arg) + ')';
}

0 comments on commit 14e748c

Please sign in to comment.