Skip to content

Commit

Permalink
Commander, corrigido tab/space antes de chamar a função, suporte a ex…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
welbert committed Nov 5, 2016
1 parent bf03b3c commit bf9a7e2
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 44 deletions.
4 changes: 2 additions & 2 deletions bin/guide-automator-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ function exportFiles(text, cb) {
fs.writeFileSync(options.output + '/' + outputHTMLFile, html);

if (options.pdf)
exportPDF(html, cb);
exportPDF(html);
}
}

function exportPDF(html, cb) {
function exportPDF(html) {
var basePath = 'file:///' + path.resolve(options.output).replace(/\\/g, '/') + '/';
html_full_path_imgs = html.replace(/img src="/g, function(match) {
return match + basePath;
Expand Down
8 changes: 4 additions & 4 deletions bin/guide-automator.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function replaceBlockWithImage(blockIndex, filename, width) {
function extractMarkdownAndSelenium(markdownAndCode, cb) {
var rePattern = /<automator>([\s\S]+?)<\/automator>/g;
markdownText = markdownAndCode.replace(rePattern, function(match, p1, offset, string) {
p1 = p1.replace(/\r?\n|\r/g, ''); //TODO Verificar se isso que deu erro ao dar espaço/tab antes de chamar a função
p1 = p1.replace(/\r?\n|\r/g, '');
seleniumBlocks.push(p1);
return '<replaceSelenium>';
});
Expand All @@ -214,7 +214,7 @@ function compile(seleniumBlocks, cb) {
var tokens = seleniumBlocks[i].split(';');
for (var o = 0; o < tokens.length; o++) {
if (tokens[o] !== null && tokens[o] !== '') {
var matches = tokens[o].match(/^(\w+)(?:\(((?:\'.+\'|\d+)(?:,(?:\'.+\'|\d+))*)\))?$/);
var matches = tokens[o].trim().match(/^(\w+)(?:\(((?:\'.+\'|\d+)(?:,(?:\'.+\'|\d+))*)\))?$/);
if (matches && (cmdsDictionary.indexOf(matches[1]) > -1)) { // IE9
cmds[j] = {};
cmds[j].cmd = matches[1];
Expand Down Expand Up @@ -310,8 +310,8 @@ function replaceRemainingBlocks(cb) {
return cb(markdownText);
}

function guideAutomatorParse(data, cb) {
return extractMarkdownAndSelenium(data, function(seleniumBlocks) { //Extração dos blocos 'automator'
function guideAutomatorParse(mdText, cb) {
return extractMarkdownAndSelenium(mdText, function(seleniumBlocks) { //Extração dos blocos 'automator'
return execSelenium(seleniumBlocks, function(err) { //Execução e tratamento dos tokens dos blocos 'automator'
if (err) {
return cb(null, err);
Expand Down
16 changes: 16 additions & 0 deletions examples/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Acessar o google

<automator>
get('http://www.google.com');
takeScreenshotOf('#hplogo',0,1);
</automator>

#Pesquisar coisas

Para pesquisar digite no campo.
Exemplo:

<automator>
fillIn('#lst-ib','Pesquisar');
takeScreenshot;
</automator>
Binary file added output/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions output/manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html><html lang="en"><head><title></title><meta charset="UTF-8"></head><body><h1 id="acessarogoogle">Acessar o google</h1>

<p><img src="1.png" alt="" width="60%" height="auto" /></p>

<h1 id="pesquisarcoisas">Pesquisar coisas</h1>

<p>Para pesquisar digite no campo.
Exemplo:</p>

<p><img src="2.png" alt="" width="60%" height="auto" /></p></body></html>
Binary file added output/manual.pdf
Binary file not shown.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
"gm": "^1.22.0",
"selenium-webdriver": "2.53.3",
"showdown": "1.4.0",
"wkhtmltopdf": "^0.3.3"
"wkhtmltopdf": "^0.3.3",
"commander": "2.9.0"
},
"engines": {
"node": "0.10.x",
"npm": "1.3.x"
"node": "4.6.x",
"npm": "2.15.x"
}
}
80 changes: 45 additions & 35 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,75 @@
#! /usr/bin/env node

//TODO Pensar em uma forma de tratar com ```javascript ao invés de <automator>
//TODO olhar os outros TO DO

//--Variaveis ------------------
var fs = require("fs");
var options = {
input: "",
output: "",
output: ".",
html: true,
pdf: true
};
var pjson = require('./package.json');
var guideAutomator = require('./bin/guide-automator');
var guideAutomatorExportFile = require('./bin/guide-automator-export');
//var program = require('commander');
var program = require('commander');
//-- Fim Variaveis ------------------

//-- EXPORTS -------------
//TODO Criar um export que preste, caso dê suporte a export
exports.printMsg = function() {
console.log("This is a message from the demo package");
exports.defineOptions = function(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.guideAutomatorParse(text, function(value, err) {
if (err)
throw err;
guideAutomatorExportFile.exportFiles(value);
});
};

//-- Fim EXPORTS -------------


//-- Tratamento de Argumentos --------
/*
program
.version(pjson.version)
.option('-i, --input', 'Input .md file')
.option('-o, --output', 'Output folder')
.parse(process.argv);
*/
if (!process.argv[2]) {
console.log('Input file missing');
process.exit();
}
options.input = process.argv[2];

if (!process.argv[3]) {
console.log('Output folder missing');
program.version(pjson.version)
.option('-i, --input <File.md>', 'Input .md file')
.option('-o, --output <Folder>', 'Output destination folder', ".");

program.on('--help', function() {
console.log(' Examples:');
console.log('');
console.log(' $ guide-automator -i input.md -o output/');
console.log(' $ guide-automator -i input.md');
console.log('');
});

program.parse(process.argv);

if (!program.input) {
console.log('Input file missing. See usage with "' + program._name + ' -h"');
process.exit();
}
options.output = process.argv[3];
options.input = program.input;
options.output = program.output;

guideAutomator.defineOptions(options);
guideAutomatorExportFile.defineOptions(options);

fs.stat(options.input, function(err, stats) {
if (err) {
console.log('Input is not a file');
process.exit();
}
});

fs.stat(options.output, function(err, stats) {
if (err) {
console.log('Output is not a folder');
process.exit();
}
});
if (!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();
}

//-- Fim Tratamento de Argumentos --------

Expand All @@ -78,7 +86,9 @@ function processInput(input, cb) {
return cb(err);
}
return guideAutomator.guideAutomatorParse(data, function(value, err) {
guideAutomatorExportFile.exportFiles(value, cb);
if (err)
throw err;
guideAutomatorExportFile.exportFiles(value);
});
});
}

0 comments on commit bf9a7e2

Please sign in to comment.