java-caller 2.2.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +190 -176
- package/lib/cli.js +34 -34
- package/lib/index.js +7 -7
- package/lib/java-caller.js +416 -395
- package/package.json +75 -75
- package/CHANGELOG.md +0 -29
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Nicolas Vuillamy
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nicolas Vuillamy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,176 +1,190 @@
|
|
|
1
|
-
<!-- markdownlint-disable MD033 -->
|
|
2
|
-
# Java Caller for Node.js
|
|
3
|
-
|
|
4
|
-
[](https://npmjs.
|
|
5
|
-
[](https://npmjs.org/package/java-caller)
|
|
6
|
-
[](https://npmjs.org/package/java-caller)
|
|
7
|
-
[](https://circleci.com/gh/nvuillam/node-java-caller/tree/master)
|
|
8
|
-
[](https://gitHub.com/nvuillam/node-java-caller/graphs/contributors/)
|
|
11
|
-
[](https://GitHub.com/nvuillam/node-java-caller/stargazers/)
|
|
12
|
-
[](https://github.com/nvuillam/node-java-caller/blob/master/LICENSE)
|
|
13
|
-
[](http://makeapullrequest.com)
|
|
14
|
-
|
|
15
|
-
Lightweight cross-platform javascript module to **easily call java commands from Node.js sources**.
|
|
16
|
-
|
|
17
|
-
- **Automatically installs required Java version** if not present on the system
|
|
18
|
-
- Compliant with **JDK & JRE** from **8 to 14**
|
|
19
|
-
- Uses node [spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) method to perform the call
|
|
20
|
-
|
|
21
|
-
There are two ways to use java-caller:
|
|
22
|
-
|
|
23
|
-
- **module**: Manually call JavaCaller in your custom JS/TS code ([example project](https://github.com/nvuillam/node-java-caller/tree/master/examples/module_app))
|
|
24
|
-
- **CLI**: Just define a java-caller-config.json and you can deliver your java executables as your own NPM packages ! ([example project](https://github.com/nvuillam/node-java-caller/tree/master/examples/cli_app), which can be used as starter kit)
|
|
25
|
-
|
|
26
|
-
## Installation
|
|
27
|
-
|
|
28
|
-
```shell
|
|
29
|
-
npm install java-caller --save
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Usage
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
const JavaCaller = require('java-caller');
|
|
36
|
-
const java = new JavaCaller(JAVA_CALLER_OPTIONS);
|
|
37
|
-
const {status, stdout, stderr} = java.run(JAVA_ARGUMENTS,JAVA_CALLER_RUN_OPTIONS);
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### JAVA_CALLER_OPTIONS
|
|
41
|
-
|
|
42
|
-
| Parameter
|
|
43
|
-
|
|
44
|
-
| jar
|
|
45
|
-
| classPath
|
|
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
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
### [2.
|
|
161
|
-
|
|
162
|
-
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
1
|
+
<!-- markdownlint-disable MD033 -->
|
|
2
|
+
# Java Caller for Node.js
|
|
3
|
+
|
|
4
|
+
[](https://www.npmjs.com/package/java-caller)
|
|
5
|
+
[](https://npmjs.org/package/java-caller)
|
|
6
|
+
[](https://npmjs.org/package/java-caller)
|
|
7
|
+
[](https://circleci.com/gh/nvuillam/node-java-caller/tree/master)
|
|
8
|
+
[](https://github.com/nvuillam/mega-linter#readme)
|
|
9
|
+
[](https://codecov.io/gh/nvuillam/node-java-caller)
|
|
10
|
+
[](https://gitHub.com/nvuillam/node-java-caller/graphs/contributors/)
|
|
11
|
+
[](https://GitHub.com/nvuillam/node-java-caller/stargazers/)
|
|
12
|
+
[](https://github.com/nvuillam/node-java-caller/blob/master/LICENSE)
|
|
13
|
+
[](http://makeapullrequest.com)
|
|
14
|
+
|
|
15
|
+
Lightweight cross-platform javascript module to **easily call java commands from Node.js sources**.
|
|
16
|
+
|
|
17
|
+
- **Automatically installs required Java version** if not present on the system
|
|
18
|
+
- Compliant with **JDK & JRE** from **8 to 14**
|
|
19
|
+
- Uses node [spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) method to perform the call
|
|
20
|
+
|
|
21
|
+
There are two ways to use java-caller:
|
|
22
|
+
|
|
23
|
+
- **module**: Manually call JavaCaller in your custom JS/TS code ([example project](https://github.com/nvuillam/node-java-caller/tree/master/examples/module_app))
|
|
24
|
+
- **CLI**: Just define a java-caller-config.json and you can deliver your java executables as your own NPM packages ! ([example project](https://github.com/nvuillam/node-java-caller/tree/master/examples/cli_app), which can be used as starter kit)
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
npm install java-caller --save
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const JavaCaller = require('java-caller');
|
|
36
|
+
const java = new JavaCaller(JAVA_CALLER_OPTIONS);
|
|
37
|
+
const {status, stdout, stderr} = java.run(JAVA_ARGUMENTS,JAVA_CALLER_RUN_OPTIONS);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### JAVA_CALLER_OPTIONS
|
|
41
|
+
|
|
42
|
+
| Parameter | Description | Default value | Example |
|
|
43
|
+
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | ---------------------------------------- |
|
|
44
|
+
| jar | Path to executable jar file | | `"myfolder/myjar.jar"` |
|
|
45
|
+
| classPath | If jar parameter is not set, classpath to use<br/>Use `:` as separator (it will be converted if runned on Windows), or use a string array. | `.` (current folder) | `"java/myJar.jar:java/myOtherJar.jar"` |
|
|
46
|
+
| useAbsoluteClassPaths | Set to true if classpaths should not be based on the rootPath | `false` | `true` |
|
|
47
|
+
| mainClass | If classPath set, main class to call | | `"com.example.MyClass"` |
|
|
48
|
+
| rootPath | If classPath elements are not relative to the current folder, you can define a root path. <br/> You may use `__dirname` if you classes / jars are in your module folder | `.` (current folder) | `"/home/my/folder/containing/jars"` |
|
|
49
|
+
| minimumJavaVersion | Minimum java version to be used to call java command.<br/> If the java version found on machine is lower, java-caller will try to install and use the appropriate one | `8` | `11` |
|
|
50
|
+
| maximumJavaVersion | Maximum java version to be used to call java command.<br/> If the java version found on machine is upper, java-caller will try to install and use the appropriate one <br/> Can be equal to minimumJavaVersion | | `10` |
|
|
51
|
+
| javaType | jre or jdk (if not defined and installation is required, jre will be installed) | | `"jre"` |
|
|
52
|
+
| additionalJavaArgs | Additional parameters for JVM that will be added in every JavaCaller instance runs | | `["-Xms256m","-Xmx2048m"]` |
|
|
53
|
+
| javaExecutable | You can force to use a defined java executable, instead of letting java-caller find/install one | | `"/home/some-java-version/bin/java.exe"` |
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### JAVA_ARGUMENTS
|
|
57
|
+
|
|
58
|
+
The list of arguments can contain both arguments types together:
|
|
59
|
+
|
|
60
|
+
- Java arguments (**-X*** , **-D***). ex: `"-Xms256m"`, `"-Xmx2048m"`
|
|
61
|
+
- Main class arguments (sent to `public static void main method`). ex: `"--someflag"` , `"--someflagwithvalue myVal"` , `"-c"`
|
|
62
|
+
|
|
63
|
+
Example: `["-Xms256m", "--someflagwithvalue myVal", "-c"]`
|
|
64
|
+
|
|
65
|
+
### JAVA_CALLER_RUN_OPTIONS
|
|
66
|
+
|
|
67
|
+
| Parameter | Description | Default | Example |
|
|
68
|
+
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|-------------------------|
|
|
69
|
+
| [detached](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) | If set to true, node will node wait for the java command to be completed.<br/>In that case, `childJavaProcess` property will be returned, but `stdout` and `stderr` may be empty, except if an error is triggered at command execution | `false` | `true` |
|
|
70
|
+
| waitForErrorMs | If detached is true, number of milliseconds to wait to detect an error before exiting JavaCaller run | `500` | `2000` |
|
|
71
|
+
| [cwd](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) | You can override cwd of spawn called by JavaCaller runner | `process.cwd()` | `some/other/cwd/folder` |
|
|
72
|
+
| javaArgs | List of arguments for JVM only, not the JAR or the class | `[]` | `['--add-opens=java.base/java.lang=ALL-UNNAMED']` |
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## Examples
|
|
76
|
+
|
|
77
|
+
Call a class located in classpath
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
const java = new JavaCaller({
|
|
81
|
+
classPath: 'test/java/dist',
|
|
82
|
+
mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
|
|
83
|
+
});
|
|
84
|
+
const { status, stdout, stderr } = await java.run();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Call a class with multiple folders in the classPath
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
const java = new JavaCaller({
|
|
91
|
+
classPath: ['C:\\pathA\\test\\java\\dist', 'C:\\pathB\\test\\java\\dist'],
|
|
92
|
+
mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
|
|
93
|
+
});
|
|
94
|
+
const { status, stdout, stderr } = await java.run();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Call a class located in classpath with java and custom arguments
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
const java = new JavaCaller({
|
|
101
|
+
classPath: 'test/java/dist',
|
|
102
|
+
mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
|
|
103
|
+
});
|
|
104
|
+
const { status, stdout, stderr } = await java.run(['-Xms256m', '-Xmx2048m', '--customarg nico']);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Call a class in jar located in classpath
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
const java = new JavaCaller({
|
|
111
|
+
classPath: 'test/java/jar/JavaCallerTester.jar',
|
|
112
|
+
mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
|
|
113
|
+
});
|
|
114
|
+
const { status, stdout, stderr } = await java.run();
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Call a runnable jar
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
const java = new JavaCaller({
|
|
121
|
+
jar: 'test/java/jar/JavaCallerTesterRunnable.jar',
|
|
122
|
+
});
|
|
123
|
+
const { status, stdout, stderr } = await java.run();
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Call a detached java process
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
const java = new JavaCaller({
|
|
130
|
+
classPath: 'test/java/dist',
|
|
131
|
+
mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
|
|
132
|
+
});
|
|
133
|
+
const { status, stdout, stderr, childJavaProcess } = await java.run(['--sleep'], { detached: true });
|
|
134
|
+
|
|
135
|
+
// Kill later the java process if necessary
|
|
136
|
+
childJavaProcess.kill('SIGINT');
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
You can see **more examples in** [**test methods**](https://github.com/nvuillam/node-java-caller/blob/master/test/java-caller.test.js)
|
|
140
|
+
|
|
141
|
+
## TROUBLESHOOTING
|
|
142
|
+
|
|
143
|
+
Set environment variable `DEBUG=java-caller` before calling your code using java-caller module, and you will see the java commands executed.
|
|
144
|
+
|
|
145
|
+
Example debug log:
|
|
146
|
+
|
|
147
|
+
```shell
|
|
148
|
+
java-caller Found Java version 1.80131 +1s
|
|
149
|
+
java-caller Java command: java -Xms256m -Xmx2048m -cp C:\Work\gitPerso\node-java-caller\test\java\dist com.nvuillam.javacaller.JavaCallerTester -customarg nico +1ms
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## CONTRIBUTE
|
|
153
|
+
|
|
154
|
+
Contributions are very welcome !
|
|
155
|
+
|
|
156
|
+
Please follow [Contribution instructions](https://github.com/nvuillam/node-java-caller/blob/master/CONTRIBUTING.md)
|
|
157
|
+
|
|
158
|
+
## RELEASE NOTES
|
|
159
|
+
|
|
160
|
+
### [2.2.3] 2020-09-05
|
|
161
|
+
|
|
162
|
+
- Fix Java 8 detection ([#101@npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint/issues/101))
|
|
163
|
+
|
|
164
|
+
### [2.2.0] 2020-08-29
|
|
165
|
+
|
|
166
|
+
- Fix CLASSPATH on windows in case there are spaces in paths
|
|
167
|
+
- Update License to MIT
|
|
168
|
+
|
|
169
|
+
### [2.1.0] 2020-08-12
|
|
170
|
+
|
|
171
|
+
- Allow to use java-caller to build your own CLI embedding java sources
|
|
172
|
+
- Example projects using module and CLI
|
|
173
|
+
|
|
174
|
+
### [2.0.0] 2020-08-11
|
|
175
|
+
|
|
176
|
+
- Big refactoring to simplify and enhance performances of code checking/installing java version
|
|
177
|
+
- Replace use of deprecated package [node-jre](https://github.com/schreiben/node-jre) by [njre](https://github.com/raftario/njre)
|
|
178
|
+
- Compliance with JDK & JRE from 8 to 14 ([AdoptOpenJdk](https://adoptopenjdk.net/) releases)
|
|
179
|
+
|
|
180
|
+
### [1.1.0] 2020-08-10
|
|
181
|
+
|
|
182
|
+
- Return `javaChildProcess` when `detached` is true, so it can be used to be killed later
|
|
183
|
+
|
|
184
|
+
### [1.0.0] 2020-08-10
|
|
185
|
+
|
|
186
|
+
- Initial version
|
|
187
|
+
|
|
188
|
+
____
|
|
189
|
+
|
|
190
|
+
See complete [CHANGELOG](https://github.com/nvuillam/node-java-caller/blob/master/CHANGELOG.md)
|
package/lib/cli.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
const { JavaCaller } = require("./java-caller");
|
|
3
|
-
const fse = require("fs-extra");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
class JavaCallerCli {
|
|
7
|
-
"use strict";
|
|
8
|
-
|
|
9
|
-
javaCallerOptions;
|
|
10
|
-
|
|
11
|
-
constructor(baseDir) {
|
|
12
|
-
// Use user-defined JSON file to read configuration
|
|
13
|
-
const configFile = path.resolve(`${baseDir}/java-caller-config.json`);
|
|
14
|
-
const options = fse.readJSONSync(configFile);
|
|
15
|
-
// Default output is console with CLI
|
|
16
|
-
if (options.output == null) {
|
|
17
|
-
options.output = "console";
|
|
18
|
-
}
|
|
19
|
-
if (options.rootPath == null) {
|
|
20
|
-
options.rootPath = baseDir;
|
|
21
|
-
}
|
|
22
|
-
this.javaCallerOptions = options;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async process() {
|
|
26
|
-
const java = new JavaCaller(this.javaCallerOptions);
|
|
27
|
-
const args = [...process.argv];
|
|
28
|
-
args.splice(0, 2);
|
|
29
|
-
const { status } = await java.run(args);
|
|
30
|
-
process.exitCode = status;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = { JavaCallerCli };
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
const { JavaCaller } = require("./java-caller");
|
|
3
|
+
const fse = require("fs-extra");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
class JavaCallerCli {
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
javaCallerOptions;
|
|
10
|
+
|
|
11
|
+
constructor(baseDir) {
|
|
12
|
+
// Use user-defined JSON file to read configuration
|
|
13
|
+
const configFile = path.resolve(`${baseDir}/java-caller-config.json`);
|
|
14
|
+
const options = fse.readJSONSync(configFile);
|
|
15
|
+
// Default output is console with CLI
|
|
16
|
+
if (options.output == null) {
|
|
17
|
+
options.output = "console";
|
|
18
|
+
}
|
|
19
|
+
if (options.rootPath == null) {
|
|
20
|
+
options.rootPath = baseDir;
|
|
21
|
+
}
|
|
22
|
+
this.javaCallerOptions = options;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async process() {
|
|
26
|
+
const java = new JavaCaller(this.javaCallerOptions);
|
|
27
|
+
const args = [...process.argv];
|
|
28
|
+
args.splice(0, 2);
|
|
29
|
+
const { status } = await java.run(args);
|
|
30
|
+
process.exitCode = status;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = { JavaCallerCli };
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
const { JavaCaller } = require("./java-caller");
|
|
5
|
-
const { JavaCallerCli } = require("./cli");
|
|
6
|
-
|
|
7
|
-
module.exports = { JavaCaller, JavaCallerCli };
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { JavaCaller } = require("./java-caller");
|
|
5
|
+
const { JavaCallerCli } = require("./cli");
|
|
6
|
+
|
|
7
|
+
module.exports = { JavaCaller, JavaCallerCli };
|