forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 209
/
sequencerSteps.js
88 lines (79 loc) · 2.86 KB
/
sequencerSteps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var Spinner = require('ora');
var readlineSync = require('readline-sync');
var utils = require('../CliUtils');
module.exports = function (program, sequencer, outputFilename) {
utils.makedir(program.output, () => {
console.log('Files will be exported to "' + program.output + '"');
if (program.basic)
console.log('Basic mode is enabled, outputting only final image');
// Iterate through the steps and retrieve their inputs.
program.step.forEach(function(step) {
var options = Object.assign({}, sequencer.modulesInfo(step).inputs);
// If inputs exists, print to console.
if (Object.keys(options).length) {
console.log('[' + step + ']: Inputs');
}
// If inputs exists, print them out with descriptions.
Object.keys(options).forEach(function(input) {
// The array below creates a variable number of spaces. This is done with (length + 1).
// The extra 4 that makes it (length + 5) is to account for the []: characters
console.log(
new Array(step.length + 5).join(' ') +
input +
': ' +
options[input].desc
);
});
if (program.config) {
try {
var config = JSON.parse(program.config);
console.log('The parsed options object: ', config);
} catch (e) {
console.error(
'\x1b[31m%s\x1b[0m',
'Options(Config) is not a not valid JSON Fallback activate'
);
program.config = false;
console.log(e);
}
}
if (program.config && utils.validateConfig(config, options)) {
console.log('Now using Options object');
Object.keys(options).forEach(function(input) {
options[input] = config[input];
});
} else {
// If inputs exist, iterate through them and prompt for values.
Object.keys(options).forEach(function(input) {
var value = readlineSync.question(
'[' +
step +
']: Enter a value for ' +
input +
' (' +
options[input].type +
', default: ' +
options[input].default +
'): '
);
options[input] = value;
});
}
// Add the step and its inputs to the sequencer.
sequencer.addSteps(step, options);
});
var spinnerObj = { succeed: () => { }, stop: () => { } };
if (!process.env.TEST)
spinnerObj = Spinner('Your Image is being processed..').start();
// Run the sequencer.
sequencer.run({ progressObj: spinnerObj }, function() {
// Export all images or final image as binary files.
sequencer.exportBin(program.output, program.basic, outputFilename);
//check if spinner was not overriden stop it
if (!spinnerObj.overrideFlag) {
spinnerObj.succeed();
console.log('\nDone!!');
}
});
});
};