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 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
- [![Version](https://img.shields.io/npm/v/java-caller.svg)](https://npmjs.org/package/node-java-caller)
5
- [![Downloads/week](https://img.shields.io/npm/dw/java-caller.svg)](https://npmjs.org/package/java-caller)
6
- [![Downloads/total](https://img.shields.io/npm/dt/java-caller.svg)](https://npmjs.org/package/java-caller)
7
- [![CircleCI](https://circleci.com/gh/nvuillam/node-java-caller/tree/master.svg?style=shield)](https://circleci.com/gh/nvuillam/node-java-caller/tree/master)
8
- [![codecov](https://codecov.io/gh/nvuillam/node-java-caller/branch/master/graph/badge.svg)](https://codecov.io/gh/nvuillam/node-java-caller)
9
- [![Codacy Badge](https://app.codacy.com/project/badge/Grade/2f74d43c38764caab0c6f76a7a668df3)](https://www.codacy.com/manual/nvuillam/node-java-caller?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=nvuillam/node-java-caller&amp;utm_campaign=Badge_Grade)
10
- [![GitHub contributors](https://img.shields.io/github/contributors/nvuillam/node-java-caller.svg)](https://gitHub.com/nvuillam/node-java-caller/graphs/contributors/)
11
- [![GitHub stars](https://img.shields.io/github/stars/nvuillam/node-java-caller?label=Star&maxAge=2592000)](https://GitHub.com/nvuillam/node-java-caller/stargazers/)
12
- [![License](https://img.shields.io/npm/l/java-caller.svg)](https://github.com/nvuillam/node-java-caller/blob/master/LICENSE)
13
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](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) | `.` (current folder) | `"java/myJar.jar:java/myOtherJar.jar"` |
46
- | mainClass | If classPath set, main class to call | | `"com.example.MyClass"` |
47
- | 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"` |
48
- | 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` |
49
- | 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` |
50
- | javaType | jre or jdk (if not defined and installation is required, jre will be installed) | | `"jre"` |
51
- | additionalJavaArgs | Additional parameters for JVM that will be added in every JavaCaller instance runs | | `["-Xms256m","-Xmx2048m"]` |
52
- | 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"` |
53
-
54
- ### JAVA_ARGUMENTS
55
-
56
- The list of arguments can contain both arguments types together:
57
-
58
- - Java arguments (**-X*** , **-D***). ex: `"-Xms256m"`, `"-Xmx2048m"`
59
- - Main class arguments (sent to `public static void main method`). ex: `"--someflag"` , `"--someflagwithvalue myVal"` , `"-c"`
60
-
61
- Example: `["-Xms256m", "--someflagwithvalue myVal", "-c"]`
62
-
63
- ### JAVA_CALLER_RUN_OPTIONS
64
-
65
- | Parameter | Description | Default | Example |
66
- |----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|-------------------------|
67
- | [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` |
68
- | waitForErrorMs | If detached is true, number of milliseconds to wait to detect an error before exiting JavaCaller run | `500` | `2000` |
69
- | [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` |
70
-
71
- ## Examples
72
-
73
- Call a class located in classpath
74
-
75
- ```javascript
76
- const java = new JavaCaller({
77
- classPath: 'test/java/dist',
78
- mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
79
- });
80
- const { status, stdout, stderr } = await java.run();
81
- ```
82
-
83
- Call a class located in classpath with java and custom arguments
84
-
85
- ```javascript
86
- const java = new JavaCaller({
87
- classPath: 'test/java/dist',
88
- mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
89
- });
90
- const { status, stdout, stderr } = await java.run(['-Xms256m', '-Xmx2048m', '--customarg nico']);
91
- ```
92
-
93
- Call a class in jar located in classpath
94
-
95
- ```javascript
96
- const java = new JavaCaller({
97
- classPath: 'test/java/jar/JavaCallerTester.jar',
98
- mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
99
- });
100
- const { status, stdout, stderr } = await java.run();
101
- ```
102
-
103
- Call a runnable jar
104
-
105
- ```javascript
106
- const java = new JavaCaller({
107
- jar: 'test/java/jar/JavaCallerTesterRunnable.jar',
108
- });
109
- const { status, stdout, stderr } = await java.run();
110
- ```
111
-
112
- Call a detached java process
113
-
114
- ```javascript
115
- const java = new JavaCaller({
116
- classPath: 'test/java/dist',
117
- mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
118
- });
119
- const { status, stdout, stderr, childJavaProcess } = await java.run(['--sleep'], { detached: true });
120
-
121
- // Kill later the java process if necessary
122
- childJavaProcess.kill('SIGINT');
123
- ```
124
-
125
- You can see **more examples in** [**test methods**](https://github.com/nvuillam/node-java-caller/blob/master/test/java-caller.test.js)
126
-
127
- ## TROUBLESHOOTING
128
-
129
- Set environment variable `DEBUG=java-caller` before calling your code using java-caller module, and you will see the java commands executed.
130
-
131
- Example debug log:
132
-
133
- ```shell
134
- java-caller Found Java version 1.80131 +1s
135
- java-caller Java command: java -Xms256m -Xmx2048m -cp C:\Work\gitPerso\node-java-caller\test\java\dist com.nvuillam.javacaller.JavaCallerTester -customarg nico +1ms
136
- ```
137
-
138
- ## CONTRIBUTE
139
-
140
- Contributions are very welcome !
141
-
142
- Please follow [Contribution instructions](https://github.com/nvuillam/node-java-caller/blob/master/CONTRIBUTING.md)
143
-
144
- ## RELEASE NOTES
145
-
146
- ### [2.2.3] 2020-09-05
147
-
148
- - Fix Java 8 detection ([#101@npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint/issues/101))
149
-
150
- ### [2.2.0] 2020-08-29
151
-
152
- - Fix CLASSPATH on windows in case there are spaces in paths
153
- - Update License to MIT
154
-
155
- ### [2.1.0] 2020-08-12
156
-
157
- - Allow to use java-caller to build your own CLI embedding java sources
158
- - Example projects using module and CLI
159
-
160
- ### [2.0.0] 2020-08-11
161
-
162
- - Big refactoring to simplify and enhance performances of code checking/installing java version
163
- - Replace use of deprecated package [node-jre](https://github.com/schreiben/node-jre) by [njre](https://github.com/raftario/njre)
164
- - Compliance with JDK & JRE from 8 to 14 ([AdoptOpenJdk](https://adoptopenjdk.net/) releases)
165
-
166
- ### [1.1.0] 2020-08-10
167
-
168
- - Return `javaChildProcess` when `detached` is true, so it can be used to be killed later
169
-
170
- ### [1.0.0] 2020-08-10
171
-
172
- - Initial version
173
-
174
- ____
175
-
176
- See complete [CHANGELOG](https://github.com/nvuillam/node-java-caller/blob/master/CHANGELOG.md)
1
+ <!-- markdownlint-disable MD033 -->
2
+ # Java Caller for Node.js
3
+
4
+ [![Version](https://img.shields.io/npm/v/java-caller.svg)](https://www.npmjs.com/package/java-caller)
5
+ [![Downloads/week](https://img.shields.io/npm/dw/java-caller.svg)](https://npmjs.org/package/java-caller)
6
+ [![Downloads/total](https://img.shields.io/npm/dt/java-caller.svg)](https://npmjs.org/package/java-caller)
7
+ [![CircleCI](https://circleci.com/gh/nvuillam/node-java-caller/tree/master.svg?style=shield)](https://circleci.com/gh/nvuillam/node-java-caller/tree/master)
8
+ [![Mega-Linter](https://github.com/nvuillam/node-java-caller/workflows/Mega-Linter/badge.svg)](https://github.com/nvuillam/mega-linter#readme)
9
+ [![codecov](https://codecov.io/gh/nvuillam/node-java-caller/branch/master/graph/badge.svg)](https://codecov.io/gh/nvuillam/node-java-caller)
10
+ [![GitHub contributors](https://img.shields.io/github/contributors/nvuillam/node-java-caller.svg)](https://gitHub.com/nvuillam/node-java-caller/graphs/contributors/)
11
+ [![GitHub stars](https://img.shields.io/github/stars/nvuillam/node-java-caller?label=Star&maxAge=2592000)](https://GitHub.com/nvuillam/node-java-caller/stargazers/)
12
+ [![License](https://img.shields.io/npm/l/java-caller.svg)](https://github.com/nvuillam/node-java-caller/blob/master/LICENSE)
13
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](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 };