-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner_gecko.js
71 lines (68 loc) · 2.42 KB
/
runner_gecko.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
console.log(process.argv[2])
fs = require('fs')
fs.readFile(process.argv[2], 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var path = require('path')
var absPath = path.resolve(__dirname , process.argv[2]);
console.log(absPath)
// convert
//var phantom = require('phantom');
var driver = require('node-phantom-simple');
driver.create({ path: require('slimerjs').path }, function (err, browser) {
browser.createPage(function (err, page) {
/*
page.onConsoleMessage(function (msg) {
console.log("Phantom Console: " + msg)
})
*/
page.open("tool/html2xml/index.html", function (err,status) {
page.evaluate(function (data, absPath, point) {
window.point = point
var code = document.getElementById("code");
code.value = data;
onSubmit();
document.querySelector('iframe').src = absPath;
return "submit"
}, data, absPath, absPath.substring(0,absPath.lastIndexOf("/")+1),
function (err,result) {
console.log(result);
});
});
setTimeout(function wait() {
page.render('result.png');
page.evaluate(function (absPath) {
var result = document.getElementById("result");
console.log(result.value)
return result.value;
}, absPath,
function (err, res) {
console.log(res);
browser.exit();
fs.writeFile('result.xml', res, function (err) {
if (err) throw err;
console.log('It\'s saved!');
var d = path.dirname(absPath);
var args = ['result.xml' ,'--working-directory='+d + "/"];
for(var i = 3; i < process.argv.length; i ++) {
args.push(process.argv[i])
}
console.log(args)
var child = require('child_process').execFile('./StarFish', args)
child.stdout.on('data', function(buf) {
console.log('stdout "%s"', String(buf));
});
child.stderr.on('data', function(buf) {
console.log('stderr "%s"', String(buf));
});
// child.stdout.pipe(process.stdout)
child.on('exit', function() {
process.exit()
})
});
});
}, 3000)
});
});
});