-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandbox.js
104 lines (89 loc) · 3.32 KB
/
commandbox.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
'use strict';
const { exec } = require('child_process');
const path = require('path');
const { dialog, app, BrowserWindow } = require('electron');
let path_to_module = __dirname;
let server_started = false;
let server_stopping = false;
let java_home_path = null;
// Starts a CommandBox Instance
module.exports.start = function (resource_path, commandbox_home) {
boxExecute(resource_path, 'server start', commandbox_home);
}
// Stops CommandBox Instance
module.exports.stop = function (resource_path, commandbox_home) {
if (java_home_path != null && !server_stopping) {
server_stopping = true;
boxExecute(resource_path, 'server stop', commandbox_home);
}
}
// Custom CommandBox Commands
module.exports.execute = function (resource_path, command, commandbox_home) {
boxExecute(resource_path, command. commandbox_home);
}
function boxExecute(resource_path, command, commandbox_home) {
if (java_home_path == null) {
require('find-java-home')(function(err, home){
if(err || typeof(home) != 'string') {
dialog.showMessageBox({
title: 'Unable to Find Java',
message: 'Unable to find java on your computer.',
detail: 'If you have java installed make sure you set JAVA_HOME, or install Java 11 from: https://www.microsoft.com/openjdk'
}).then(function() {
app.quit();
});
console.log(err);
console.log(home);
return;
}
java_home_path = home;
boxExecuteWithJava(resource_path, command, commandbox_home, java_home_path);
});
} else {
boxExecuteWithJava(resource_path, command, commandbox_home, java_home_path);
}
}
function boxExecuteWithJava(resource_path, command, commandbox_home, java_home) {
var home = java_home;
if (!commandbox_home) {
var properties_path = path.join(resource_path, 'commandbox', 'home');
commandbox_home = properties_path;
}
var properites_data = `-commandbox_home="${commandbox_home}"`;
var java_path = path.join(home, 'bin', 'java');
var box_path = path.join(resource_path, 'box.jar');
var cfml_path = path.join(resource_path, 'cfml');
var cmd = `cd "${cfml_path}" && "${java_path}" -jar "${box_path}" ${properites_data} ${command}`;
console.log(cmd);
execute(cmd, (output, failed) => {
console.log(output);
})
}
function execute(command, callback) {
exec(command, (error, stdout, stderr) => {
if( error ) {
if ( stdout ) {
dialog.showMessageBox({
title: 'Failed to Start CommandBox',
message: 'Failed to Start CommandBox',
detail: stdout.toString()
});
}
callback(error, true);
}
if( stderr ) {
callback(stderr, true);
dialog.showMessageBox({
title: 'Failed to Start CommandBox',
message: 'Failed to Start CommandBox',
detail: stderr.toString()
});
}
if( stdout ) {
if (command.indexOf('server start') != -1) {
server_started = true;
}
callback(stdout, false);
}
})
}