@wiremock/npm-jar-wrapper-maker 1.0.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 ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024 WireMock Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # npm-jar-wrapper-maker
2
+
3
+ Create NPM wrappers for Java JARs with automatic JRE management.
4
+
5
+ This tool generates NPM packages that wrap Java JAR files, allowing them to be distributed and run via `npm install` without requiring users to manually install Java. If Java is not found on the system, the wrapper will automatically download and cache a JRE from Adoptium.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install -g npm-jar-wrapper-maker
11
+ ```
12
+
13
+ Or as a dev dependency in your Java project:
14
+
15
+ ```bash
16
+ npm install --save-dev npm-jar-wrapper-maker
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### CLI Usage
22
+
23
+ #### Initialize a Configuration File
24
+
25
+ ```bash
26
+ npm-jar-wrapper-maker --init
27
+ ```
28
+
29
+ This creates a `wrapper-config.json` file that you can customize.
30
+
31
+ #### Generate from Configuration File
32
+
33
+ ```bash
34
+ npm-jar-wrapper-maker --config wrapper-config.json --output ./npm-package
35
+ ```
36
+
37
+ #### Generate with Inline Options
38
+
39
+ ```bash
40
+ npm-jar-wrapper-maker \
41
+ --package-name @myorg/my-cli \
42
+ --cli-name my-cli \
43
+ --jar-file-name my-app.jar \
44
+ --java-version 17 \
45
+ --output ./npm-package
46
+ ```
47
+
48
+ ### Programmatic Usage
49
+
50
+ ```javascript
51
+ const { generateWrapper, validateConfig } = require('npm-jar-wrapper-maker');
52
+
53
+ const config = {
54
+ packageName: '@myorg/my-cli',
55
+ version: '1.0.0',
56
+ description: 'My Java CLI tool',
57
+ cliName: 'my-cli',
58
+ jarFileName: 'my-app.jar',
59
+ targetJavaVersion: 17,
60
+ author: 'Your Name',
61
+ license: 'Apache-2.0',
62
+ };
63
+
64
+ // Validate configuration
65
+ const validation = validateConfig(config);
66
+ if (!validation.valid) {
67
+ console.error('Invalid config:', validation.errors);
68
+ process.exit(1);
69
+ }
70
+
71
+ // Generate the wrapper
72
+ const result = generateWrapper(config, './output-dir');
73
+
74
+ console.log('Generated files:', result.files);
75
+ console.log('Copy your JAR to:', result.jarPlaceholder);
76
+ ```
77
+
78
+ ## Configuration Options
79
+
80
+ | Option | Type | Required | Default | Description |
81
+ |--------|------|----------|---------|-------------|
82
+ | `packageName` | string | Yes | - | NPM package name (e.g., `@myorg/my-cli`) |
83
+ | `cliName` | string | Yes | - | CLI command name (e.g., `my-cli`) |
84
+ | `jarFileName` | string | Yes | - | JAR file name (e.g., `my-app.jar`) |
85
+ | `version` | string | No | `1.0.0` | Package version |
86
+ | `description` | string | No | `""` | Package description |
87
+ | `author` | string | No | `""` | Package author |
88
+ | `license` | string | No | `Apache-2.0` | Package license |
89
+ | `targetJavaVersion` | number | No | `17` | Target Java version (8+) |
90
+ | `javaOpts` | string[] | No | `[]` | Additional JVM options |
91
+ | `enableNativeAccess` | boolean | No | `false` | Enable Java native access |
92
+ | `enablePostinstall` | boolean | No | `false` | Enable postinstall script |
93
+ | `postinstallCommand` | string | No | `""` | Custom postinstall command |
94
+ | `configDirName` | string | No | Same as `cliName` | Config directory name for JRE cache |
95
+ | `repository` | object | No | `{}` | Repository info for package.json |
96
+ | `homepage` | string | No | `""` | Homepage URL |
97
+ | `bugs` | object | No | `{}` | Bugs URL |
98
+ | `keywords` | string[] | No | `[]` | Additional keywords |
99
+
100
+ ## Generated Files
101
+
102
+ The generator creates the following files:
103
+
104
+ - `package.json` - NPM package manifest
105
+ - `index.js` - CLI entry point (with shebang)
106
+ - `cli.js` - Java runtime management and execution logic
107
+ - `.gitignore` - Git ignore rules
108
+ - `.npmignore` - NPM ignore rules
109
+ - `README.md` - Basic documentation
110
+ - `postinstall.js` - (optional) Post-install hook
111
+
112
+ ## How the Generated Wrapper Works
113
+
114
+ 1. When the CLI is executed, it first looks for Java:
115
+ - Checks `JAVA_HOME` environment variable
116
+ - Checks for `java` on the system PATH
117
+ - Checks for a previously downloaded JRE in `~/.config/<cli-name>/jre`
118
+
119
+ 2. If no Java is found, it automatically:
120
+ - Fetches JRE metadata from Adoptium API
121
+ - Downloads the appropriate JRE for the user's platform and architecture
122
+ - Verifies the download checksum
123
+ - Extracts and caches the JRE locally
124
+
125
+ 3. Executes the JAR file with the found/downloaded Java
126
+
127
+ ## Integration with Gradle/Maven
128
+
129
+ You can integrate this tool into your Java build process. For example, in a Gradle project:
130
+
131
+ ```groovy
132
+ // build.gradle
133
+ task generateNpmWrapper(type: Exec) {
134
+ dependsOn bootJar
135
+
136
+ commandLine 'npx', 'npm-jar-wrapper-maker',
137
+ '--package-name', '@myorg/my-cli',
138
+ '--cli-name', 'my-cli',
139
+ '--jar-file-name', 'my-cli.jar',
140
+ '--output', "${buildDir}/npm-wrapper"
141
+
142
+ doLast {
143
+ copy {
144
+ from bootJar.archiveFile
145
+ into "${buildDir}/npm-wrapper"
146
+ rename { 'my-cli.jar' }
147
+ }
148
+ }
149
+ }
150
+ ```
151
+
152
+ Or with a configuration file:
153
+
154
+ ```groovy
155
+ task generateNpmWrapper(type: Exec) {
156
+ dependsOn bootJar
157
+
158
+ commandLine 'npx', 'npm-jar-wrapper-maker',
159
+ '--config', 'npm-wrapper-config.json',
160
+ '--output', "${buildDir}/npm-wrapper"
161
+
162
+ doLast {
163
+ copy {
164
+ from bootJar.archiveFile
165
+ into "${buildDir}/npm-wrapper"
166
+ rename { 'my-cli.jar' }
167
+ }
168
+ }
169
+ }
170
+ ```
171
+
172
+ ## Security Features
173
+
174
+ The generated wrapper includes several security measures:
175
+
176
+ - **Checksum verification**: Downloaded JREs are verified against SHA256 checksums from Adoptium
177
+ - **Path traversal protection**: Archive extraction rejects paths that could escape the target directory (CVE-2020-12265 mitigation)
178
+ - **HTTPS only**: All downloads use HTTPS
179
+
180
+ ## Supported Platforms
181
+
182
+ The generated wrappers support:
183
+
184
+ - macOS (Intel and Apple Silicon)
185
+ - Linux (x64 and ARM64)
186
+ - Windows (x64)
187
+
188
+ ## License
189
+
190
+ Apache-2.0
package/bin/cli.js ADDED
@@ -0,0 +1,291 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * npm-jar-wrapper-maker CLI
5
+ *
6
+ * Generate NPM wrapper projects for Java JARs.
7
+ */
8
+
9
+ const fs = require('node:fs');
10
+ const path = require('node:path');
11
+ const { generateWrapper, validateConfig, defaults } = require('../lib/generator');
12
+
13
+ const USAGE = `
14
+ npm-jar-wrapper-maker - Create NPM wrappers for Java JARs
15
+
16
+ USAGE:
17
+ npm-jar-wrapper-maker [options]
18
+ npm-jar-wrapper-maker --config <config-file>
19
+ npm-jar-wrapper-maker --init
20
+
21
+ OPTIONS:
22
+ --config, -c <file> Path to configuration JSON file
23
+ --output, -o <dir> Output directory (default: ./npm-wrapper)
24
+ --init Create a sample configuration file
25
+ --help, -h Show this help message
26
+ --version, -v Show version
27
+
28
+ INLINE OPTIONS (alternative to config file):
29
+ --package-name <name> NPM package name (e.g., @org/my-cli)
30
+ --cli-name <name> CLI command name (e.g., my-cli)
31
+ --jar-file-name <name> JAR file name (e.g., my-app.jar)
32
+ --java-version <ver> Target Java version (default: 17)
33
+ --description <desc> Package description
34
+ --version-number <ver> Package version (default: 1.0.0)
35
+ --author <author> Package author
36
+ --license <license> Package license (default: Apache-2.0)
37
+ --enable-postinstall Enable postinstall script
38
+ --enable-native-access Enable Java native access
39
+
40
+ EXAMPLES:
41
+ # Initialize a config file
42
+ npm-jar-wrapper-maker --init
43
+
44
+ # Generate from config file
45
+ npm-jar-wrapper-maker --config wrapper-config.json
46
+
47
+ # Generate with inline options
48
+ npm-jar-wrapper-maker \\
49
+ --package-name @myorg/my-tool \\
50
+ --cli-name my-tool \\
51
+ --jar-file-name my-tool.jar \\
52
+ --output ./my-tool-npm
53
+
54
+ # Generate from config with custom output
55
+ npm-jar-wrapper-maker -c config.json -o ./dist/npm-package
56
+ `;
57
+
58
+ const SAMPLE_CONFIG = {
59
+ packageName: '@myorg/my-java-cli',
60
+ version: '1.0.0',
61
+ description: 'My Java CLI tool distributed via NPM',
62
+ author: 'Your Name',
63
+ license: 'Apache-2.0',
64
+ cliName: 'my-java-cli',
65
+ jarFileName: 'my-java-cli.jar',
66
+ targetJavaVersion: 17,
67
+ javaOpts: [],
68
+ enableNativeAccess: false,
69
+ enablePostinstall: false,
70
+ postinstallCommand: '',
71
+ configDirName: 'my-java-cli',
72
+ repository: {
73
+ type: 'git',
74
+ url: 'https://github.com/myorg/my-java-cli.git',
75
+ },
76
+ homepage: 'https://github.com/myorg/my-java-cli',
77
+ bugs: {
78
+ url: 'https://github.com/myorg/my-java-cli/issues',
79
+ },
80
+ keywords: ['cli', 'tool'],
81
+ };
82
+
83
+ /**
84
+ * Parse command line arguments
85
+ */
86
+ function parseArgs(args) {
87
+ const parsed = {
88
+ config: null,
89
+ output: './npm-wrapper',
90
+ init: false,
91
+ help: false,
92
+ version: false,
93
+ // Inline options
94
+ packageName: null,
95
+ cliName: null,
96
+ jarFileName: null,
97
+ targetJavaVersion: null,
98
+ description: null,
99
+ versionNumber: null,
100
+ author: null,
101
+ license: null,
102
+ enablePostinstall: false,
103
+ enableNativeAccess: false,
104
+ };
105
+
106
+ for (let i = 0; i < args.length; i++) {
107
+ const arg = args[i];
108
+ const next = args[i + 1];
109
+
110
+ switch (arg) {
111
+ case '--config':
112
+ case '-c':
113
+ parsed.config = next;
114
+ i++;
115
+ break;
116
+ case '--output':
117
+ case '-o':
118
+ parsed.output = next;
119
+ i++;
120
+ break;
121
+ case '--init':
122
+ parsed.init = true;
123
+ break;
124
+ case '--help':
125
+ case '-h':
126
+ parsed.help = true;
127
+ break;
128
+ case '--version':
129
+ case '-v':
130
+ parsed.version = true;
131
+ break;
132
+ case '--package-name':
133
+ parsed.packageName = next;
134
+ i++;
135
+ break;
136
+ case '--cli-name':
137
+ parsed.cliName = next;
138
+ i++;
139
+ break;
140
+ case '--jar-file-name':
141
+ parsed.jarFileName = next;
142
+ i++;
143
+ break;
144
+ case '--java-version':
145
+ parsed.targetJavaVersion = parseInt(next, 10);
146
+ i++;
147
+ break;
148
+ case '--description':
149
+ parsed.description = next;
150
+ i++;
151
+ break;
152
+ case '--version-number':
153
+ parsed.versionNumber = next;
154
+ i++;
155
+ break;
156
+ case '--author':
157
+ parsed.author = next;
158
+ i++;
159
+ break;
160
+ case '--license':
161
+ parsed.license = next;
162
+ i++;
163
+ break;
164
+ case '--enable-postinstall':
165
+ parsed.enablePostinstall = true;
166
+ break;
167
+ case '--enable-native-access':
168
+ parsed.enableNativeAccess = true;
169
+ break;
170
+ default:
171
+ if (arg.startsWith('-')) {
172
+ console.error(`Unknown option: ${arg}`);
173
+ process.exit(1);
174
+ }
175
+ }
176
+ }
177
+
178
+ return parsed;
179
+ }
180
+
181
+ /**
182
+ * Build config from parsed arguments
183
+ */
184
+ function buildConfigFromArgs(parsed) {
185
+ const config = {};
186
+
187
+ if (parsed.packageName) config.packageName = parsed.packageName;
188
+ if (parsed.cliName) config.cliName = parsed.cliName;
189
+ if (parsed.jarFileName) config.jarFileName = parsed.jarFileName;
190
+ if (parsed.targetJavaVersion) config.targetJavaVersion = parsed.targetJavaVersion;
191
+ if (parsed.description) config.description = parsed.description;
192
+ if (parsed.versionNumber) config.version = parsed.versionNumber;
193
+ if (parsed.author) config.author = parsed.author;
194
+ if (parsed.license) config.license = parsed.license;
195
+ if (parsed.enablePostinstall) config.enablePostinstall = true;
196
+ if (parsed.enableNativeAccess) config.enableNativeAccess = true;
197
+
198
+ return config;
199
+ }
200
+
201
+ /**
202
+ * Main entry point
203
+ */
204
+ function main() {
205
+ const args = parseArgs(process.argv.slice(2));
206
+
207
+ // Show help
208
+ if (args.help) {
209
+ console.log(USAGE);
210
+ process.exit(0);
211
+ }
212
+
213
+ // Show version
214
+ if (args.version) {
215
+ const pkg = require('../package.json');
216
+ console.log(pkg.version);
217
+ process.exit(0);
218
+ }
219
+
220
+ // Initialize config file
221
+ if (args.init) {
222
+ const configPath = 'wrapper-config.json';
223
+ if (fs.existsSync(configPath)) {
224
+ console.error(`Error: ${configPath} already exists`);
225
+ process.exit(1);
226
+ }
227
+ fs.writeFileSync(configPath, JSON.stringify(SAMPLE_CONFIG, null, 2) + '\n');
228
+ console.log(`Created ${configPath}`);
229
+ console.log('\nEdit the file and then run:');
230
+ console.log(' npm-jar-wrapper-maker --config wrapper-config.json');
231
+ process.exit(0);
232
+ }
233
+
234
+ // Load config
235
+ let config;
236
+ if (args.config) {
237
+ // Load from config file
238
+ const configPath = path.resolve(args.config);
239
+ if (!fs.existsSync(configPath)) {
240
+ console.error(`Error: Config file not found: ${configPath}`);
241
+ process.exit(1);
242
+ }
243
+ try {
244
+ const configContent = fs.readFileSync(configPath, 'utf-8');
245
+ config = JSON.parse(configContent);
246
+ } catch (e) {
247
+ console.error(`Error parsing config file: ${e.message}`);
248
+ process.exit(1);
249
+ }
250
+ } else if (args.packageName && args.cliName && args.jarFileName) {
251
+ // Build config from inline options
252
+ config = buildConfigFromArgs(args);
253
+ } else {
254
+ console.error('Error: Either --config or inline options (--package-name, --cli-name, --jar-file-name) are required');
255
+ console.log('\nRun with --help for usage information');
256
+ process.exit(1);
257
+ }
258
+
259
+ // Validate config
260
+ const validation = validateConfig(config);
261
+ if (!validation.valid) {
262
+ console.error('Configuration errors:');
263
+ for (const error of validation.errors) {
264
+ console.error(` - ${error}`);
265
+ }
266
+ process.exit(1);
267
+ }
268
+
269
+ // Generate wrapper
270
+ const outputDir = path.resolve(args.output);
271
+ console.log(`Generating NPM wrapper in: ${outputDir}`);
272
+
273
+ try {
274
+ const result = generateWrapper(config, outputDir);
275
+ console.log('\nGenerated files:');
276
+ for (const file of result.files) {
277
+ console.log(` - ${path.relative(process.cwd(), file)}`);
278
+ }
279
+ console.log(`\nNext steps:`);
280
+ console.log(` 1. Copy your JAR file to: ${path.relative(process.cwd(), result.jarPlaceholder)}`);
281
+ console.log(` 2. cd ${path.relative(process.cwd(), outputDir)}`);
282
+ console.log(` 3. npm install`);
283
+ console.log(` 4. npm link (for local testing)`);
284
+ console.log(` 5. npm publish (when ready)`);
285
+ } catch (e) {
286
+ console.error(`Error generating wrapper: ${e.message}`);
287
+ process.exit(1);
288
+ }
289
+ }
290
+
291
+ main();