forked from Allan1/guide-automator
-
Notifications
You must be signed in to change notification settings - Fork 4
/
guide-automator.js
150 lines (123 loc) · 4.08 KB
/
guide-automator.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env node
//--Variaveis ------------------
var themeList = ['lightBlue', 'lightOrange'];
var fs = require("fs");
var options = {
debug: false,
input: "",
output: ".",
outlineStyle: "solid red 3px",
html: false,
pdf: false,
/* If true, only image will be export */
image: false,
style: 'default',
autosleep: 200,
browser: "",
headless: false,
window: "",
outlineOff: "solid red 0px"
};
var pjson = require('./package.json');
var program = require('commander');
var listOfHighlights = [];
//-- Fim Variaveis ------------------
//-- EXPORTS -------------
exports.defineOptions = function(arg) {
options.html = options.pdf = true; //Change to default, but can be change on arg
Object.keys(options)
.forEach(function(key) {
options[key] = arg[key] || options[key];
});
};
exports.generateManual = function(text) {
if (!text)
throw "Text input is missing";
return guideAutomator.guideAutomatorParser(text, function(value, err) {
if (err)
throw err;
guideAutomatorExportFile.exportFiles(value);
});
};
//-- Fim EXPORTS -------------
//-- Tratamento de Argumentos --------
program.version(pjson.version)
.option('-i, --input <File.md>', 'Input .md file')
.option('-o, --output <Folder>', 'Output destination folder', ".")
.option('-P, --pdf', 'Export manual to PDF, default is export for all types', false)
.option('-H, --html', 'Export manual to HTML, default is export for all types', false)
.option('-I, --image', `Export ONLY manual's image and ignore others types, default is export for all types`, false)
.option('-s, --style <style.css>', 'Css style to be used in the manual or theme [' + themeList.toString() + ']')
.option('-t, --autosleep <Millisecond>', 'Time to sleep before screenshot', 200)
.option('-d, --debug', 'Show progress of code')
.option('-b, --browser <path>', 'Use Chromium browser at given path')
.option('-l, --headless', 'Use headless Chrome (does not require a GUI)', false)
.option('-w, --window <dimensions>', 'Set browser window\'s dimensions (e.g., 800x600)');
program.on('--help', function() {
console.log(' Examples:');
console.log('');
console.log(' $ guide-automator -i input.md');
console.log(' $ guide-automator -i input.md -o output/');
console.log(' $ guide-automator -i input.md -o output/ -s lightBlue');
console.log('');
});
program.parse(process.argv);
if (program.debug) {
console.log("Version: " + pjson.version);
console.log("Options Used.:");
}
Object.keys(options)
.forEach(function(key) {
options[key] = program[key] || options[key];
if (options.debug)
console.log(" " + key + ": " + options[key].toString());
});
if (options.debug) {
console.log("--------");
console.time("Guide-Automator");
}
//if image, others exports type are ignored
if (options.image)
options.pdf = options.html = false;
else {
//if all exports type are false, change to true all
if (!options.pdf && !options.html)
options.pdf = options.html = true;
}
if (!options.input) {
console.log('Input file missing. See usage with "' + program._name + ' -h"');
process.exit();
}
if (!fs.existsSync(options.input) || !fs.lstatSync(options.input).isFile()) {
console.log('Input is not a file');
process.exit();
}
if (!fs.lstatSync(options.output).isDirectory()) {
console.log('Output is not a folder');
process.exit();
}
var guideAutomator = require('./bin/guide-automator-parser');
var guideAutomatorExportFile = require('./bin/guide-automator-export');
guideAutomator.defineOptions(options);
guideAutomatorExportFile.defineOptions(options);
//-- Fim Tratamento de Argumentos --------
//-- Tratamento dos blocos 'automator'-----
processInput(options.input, function(err) {
if (err) {
throw err;
}
});
function processInput(input, cb) {
fs.readFile(input, 'utf8', (err, data) => { //Leitura do arquivo
if (err)
return cb(err);
if (options.debug)
console.log(`File's line: ` + data.split(/\r\n|\r|\n/).length);
return guideAutomator.guideAutomatorParser(data, function(value, err) {
if (err)
throw err;
guideAutomatorExportFile.exportFiles(value);
});
});
}
//-- Fim Tratamento para exportar o produto final ----------