Skip to content

Commit

Permalink
command line interface with #import support
Browse files Browse the repository at this point in the history
  • Loading branch information
skanaar committed Jun 18, 2016
1 parent e21e14a commit 0ec91f0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ nomnoml.sublime-workspace
node_modules/

output.*
nomnoml-0.1.0.tgz
41 changes: 41 additions & 0 deletions dist/nomnoml-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /usr/bin/env node
var fs = require('fs')
var nomnoml = require('./nomnoml.js')

var args = process.argv

if (args[2] == '--help' || args.length == 2){
console.log(`
Load source file and send rendered svg to stdout
nomnoml <source_file>
Load source file and save rendered svg to <output_file>
nomnoml <source_file> <output_file>
Third parameter overrides the import depth limit
that protects us from recursive imports
nomnoml <source_file> <output_file> <max_import_chain_length>`)
return
}

var maxImportChainLength = args[4] || 10

var svg = nomnoml.renderSvg(preprocessFile(args[2], 0))
if (args[3]){
fs.writeFileSync(args[3], svg)
}
else {
console.log(svg)
}

function preprocessFile(filepath, depth){
if (depth > maxImportChainLength)
throw Error('max_import_chain_length exceeded')
var source = fs.readFileSync(filepath, {encoding:'utf8'})
return source.replace(/#import: *(.*)/g, function (a, file) {
return preprocessFile(file, depth+1)
})
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nomnoml",
"version": "0.0.4",
"version": "0.1.0",
"description": "The sassy UML renderer that generates diagrams from text",
"homepage": "http://www.nomnoml.com",
"author": "Daniel Kallin <daniel.kallin@gmail.com>",
Expand All @@ -9,7 +9,7 @@
"uml"
],
"main": "dist/nomnoml.js",
"files": ["dist/nomnoml.js"],
"files": ["dist/nomnoml.js", "dist/nomnoml-cli.js"],
"dependencies": {
"lodash": "~3.7.0",
"dagre": "0.4.x"
Expand All @@ -30,5 +30,8 @@
},
"bugs": {
"url": "https://github.com/skanaar/nomnoml/issues"
},
"bin": {
"nomnoml": "dist/nomnoml-cli.js"
}
}

0 comments on commit 0ec91f0

Please sign in to comment.