summaryrefslogtreecommitdiff
path: root/support/pdbf-toolkit/external-tools/captureDatabase.js
blob: 2e162f2a1bffe7a913ad44322545317e68c39f27 (plain)
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
var system = require('system');
var fs = require('fs');
if (system.args.length !== 3) {
	console.log('Usage: ' + system.args[0] + ' webpagefile basedir');
	phantom.exit();
} 

var page = require('webpage').create();

page.onError = function (msg, trace) {
    console.log(msg);
    trace.forEach(function(item) {
        console.log('  ', item.file, ':', item.line);
    });
	phantom.exit();
};

fs.changeWorkingDirectory(system.args[2]);

page.open(system.args[1], function() {
	var size = page.evaluate(function() {
		document.body.bgColor = 'white';
		return {w: outw, h: outh};
	});
	
	page.viewportSize = {
		width: size.w,
		height: size.h
	};

	var data = page.evaluate(function() {
		return LZString.compressToBase64(JSON.stringify(alasql.databases));
	});
		
	window.setTimeout(function () {
		fs.write('../' + 'pdbf-db.json', data, 'w');
		phantom.exit();
	}, 500);
});