-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (56 loc) · 1.89 KB
/
index.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
var REPORT_ENGINE = 'ReportEngine';
var GEN_REPORT_UNIX = 'genReport.sh',
GEN_REPORT_WIN = 'genReport.bat';
var MODE_RUN = 'run',
MODE_RENDER = 'render',
MODE_RUNRENDER = 'runrender';
var os = require('os'),
path = require('path'),
fs = require('fs'),
exec = require('child_process').exec;
var genReportScriptName = /^win/.test(os.platform()) ? GEN_REPORT_WIN : GEN_REPORT_UNIX;
module.exports = function(birtHome, workDir) {
if (!birtHome || !birtHome.length) {
throw new Error('No BIRT home specified');
}
var genReportScript = path.resolve(birtHome, REPORT_ENGINE, genReportScriptName);
if (!fs.existsSync(genReportScript)) {
throw new Error('BIRT genReport script doesn\'t exist: ' + genReportScript);
}
var execOptions = {
env: {
BIRT_HOME: birtHome
}
};
if (workDir) {
execOptions.cwd = workDir;
}
function execBirt(mode, rptFile, options, callback) {
var command = '"' + genReportScript + '"';
command += ' --mode ' + mode;
for (var option in options) {
var optionValue = options[option];
if (typeof(optionValue) == 'object') {
for (var key in optionValue) {
command += ' --' + option + ' ' + '"' + key + '=' + optionValue[key] + '"';
}
} else {
command += ' --' + option + ' ' + '"' + optionValue + '"';
}
}
command += ' ' + '"' + rptFile + '"';
console.log('Executing BIRT Runtime: ' + command);
return exec(command, execOptions, callback);
}
return {
run: function(rptdesignFile, options, callback) {
return execBirt(MODE_RUN, rptdesignFile, options, callback);
},
render: function(rptdocumentFile, options, callback) {
return execBirt(MODE_RENDER, rptdocumentFile, options, callback);
},
runAndRender: function(rptdesignFile, options, callback) {
return execBirt(MODE_RUNRENDER, rptdesignFile, options, callback);
}
};
};