Skip to content

Commit

Permalink
Resolved #97 and #100
Browse files Browse the repository at this point in the history
  • Loading branch information
ROODAY committed Aug 28, 2017
1 parent d466afb commit c5d62e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
38 changes: 27 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('./src/ImageSequencer');
sequencer = ImageSequencer({ui: false});

var program = require('commander');
var readlineSync = require('readline-sync');

function exit(message) {
console.error(message);
Expand All @@ -18,6 +19,9 @@ program
.option('-op, --opions {object}', 'Options for the step')
.parse(process.argv);

// Parse step into an array to allow for multiple step.
program.step = program.step.split(" ");

// User must input an image.
if(!program.image) exit("Can't read file.")

Expand All @@ -26,19 +30,19 @@ require('fs').access(program.image, function(err){
if(err) exit("Can't read file.")
});

// User must input a step.
if(!program.step || !sequencer.modulesInfo().hasOwnProperty(program.step))
// User must input a step. If step exists, check that every step is a valid step.
if(!program.step || !program.step.every(function(step){return sequencer.modulesInfo().hasOwnProperty(step)}))
exit("Please name a valid step.");

// If there's no user defined output directory, select a default directory
// If there's no user defined output directory, select a default directory.
program.output = program.output || "./output/";

// set sequencer to log module outputs, if any
// Set sequencer to log module outputs, if any.
sequencer.setUI({

onComplete: function(step) {

// get information of outputs
// Get information of outputs.
step.info = sequencer.modulesInfo(step.name);

for (var output in step.info.outputs) {
Expand All @@ -49,20 +53,32 @@ sequencer.setUI({

});

// Finally, if everything is alright, load the image, add the step and run the sequencer.
// Finally, if everything is alright, load the image, add the steps and run the sequencer.
sequencer.loadImages(program.image,function(){

// Add the step inputted by the user
sequencer.addSteps(program.step);
// Iterate through the steps and retrieve their inputs.
program.step.forEach(function(step){
var options = Object.assign({}, sequencer.modulesInfo(step).inputs);

// If inputs exists, iterate through them and prompt for values.
Object.keys(options).forEach(function(input) {
console.log(step + " : " + input + " : " + options[input].desc);
var value = readlineSync.question(step + " : " + "Enter a value for " + input + " : ");
options[input] = value;
});

// Run the sequencer
// Add the step and its options to the sequencer.
sequencer.addSteps(step, options);
});

// Run the sequencer.
sequencer.run(function(){

// Export all images as binary files
// Export all images as binary files.
sequencer.exportBin(program.output);

console.log("Files will be exported to \""+program.output+"\"");

});

});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"font-awesome": "~4.5.0",
"jquery": "~2",
"jsqr": "^0.2.2",
"readline-sync": "^1.4.7",
"urify": "^2.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit c5d62e5

Please sign in to comment.