-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Francois Laberge
authored and
Francois Laberge
committed
Aug 27, 2017
1 parent
ad2cb4c
commit 8fe4d5d
Showing
9 changed files
with
171 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
|
||
var program = require('commander'), | ||
build = require('../src/build') | ||
fs = require('fs'); | ||
|
||
program | ||
.parse(process.argv); | ||
|
||
// There should not be more than one directory provided | ||
if( process.argv.length>=4 ){ | ||
reportError('Only one directory argument expected'); | ||
} | ||
|
||
// Validate the directory if it was provided, otherwise default to current directory | ||
var directory = "."; | ||
if( process.argv.length === 3 ) { | ||
directory = process.argv[2]; | ||
|
||
try { | ||
var dirInfo = fs.readdirSync(directory); | ||
} catch( err ) { | ||
if(err.code === "ENOENT"){ | ||
reportError("Provided directory does not exist"); | ||
} | ||
if(err.code === "ENOTDIR"){ | ||
reportError("Provided directory is a file"); | ||
} | ||
} | ||
} | ||
|
||
build(false, directory, (err) => { | ||
if(err){ | ||
console.log("Error: " + explanation ); | ||
process.exit(1); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var path = require('path'); | ||
|
||
function build(watch, directory, cb){ | ||
|
||
if(watch){ | ||
var chokidar = require('chokidar'); | ||
// Chokidar didn't seem to respect a glob pattern properly, so I have implemented | ||
// the filtering on a watch of the entire directory. I filed an issue/question here: | ||
// https://github.com/paulmillr/chokidar/issues/544 | ||
chokidar.watch(directory, {ignoreInitial:false}).on('all', (event, inputPath) => { | ||
if( inputPath.match(/^.*\.(dot|sequence|flowchart|railroad)$/) !== null ){ | ||
if( event==='add' || event==='change' ) { | ||
convertFile(inputPath); | ||
} | ||
} | ||
}); | ||
} else { | ||
var glob = require('glob'); | ||
let buildPattern = `${directory}/**/*.@(dot|sequence|flowchart|railroad)`; | ||
glob(buildPattern, {}, function (err, files) { | ||
if(err){ | ||
return cb(err); | ||
} | ||
files.forEach( (file)=>{ | ||
convertFile(file); | ||
}); | ||
cb(null); | ||
}) | ||
} | ||
} | ||
|
||
function convertFile(inputPath) { | ||
var extension = inputPath.match(/^.*\.(dot|sequence|flowchart|railroad)$/)[1]; | ||
var outputPath = inputPath+'.svg'; | ||
|
||
console.log(inputPath + ' -> ' + outputPath); | ||
|
||
// Create dynamic path to matching generator for extension. Example for 'sequence' it ends | ||
// up as: var generator = require('../src/sequence/sequence') | ||
var generator = require('../src/'+extension+'/'+extension); | ||
generator(inputPath, outputPath, function(err){ | ||
if(err){ | ||
reportError(err); | ||
} | ||
}) | ||
} | ||
|
||
|
||
module.exports = build; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.