forked from modernweb-pl/wiremock-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
52 lines (42 loc) · 1.18 KB
/
cli.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
#!/usr/bin/env node
'use strict';
const spawnSync = require('child_process').spawnSync;
const jarPath = require.resolve('./wiremock-standalone.jar');
const argv = process.argv;
const wiremockArgs = [];
const javaArgs = [];
const permittedSystemKeys = [];
for (let i = 2; i < argv.length; i++) {
if (argv[i] === '--permitted-system-keys') {
permittedSystemKeys.push(argv[++i]);
continue;
}
if (argv[i] === '--java-arg') {
const javaArg = argv[++i].trim();
// collect system properties and append to `--permitted-system-keys`
if (javaArg.startsWith('-D')) {
permittedSystemKeys.push(javaArg.substr(2).split('=')[0]);
}
javaArgs.push(javaArg);
continue;
}
wiremockArgs.push(argv[i]);
}
if (permittedSystemKeys.length) {
wiremockArgs.push('--permitted-system-keys', permittedSystemKeys.join(','));
}
const result = spawnSync(
'java',
javaArgs.concat('-jar', jarPath, ...wiremockArgs),
{ stdio: 'inherit' },
);
if (result.error) {
if (result.error.code === 'ENOENT') {
console.error('Could not find "java" in your PATH.');
} else {
console.error(result.error.message);
}
process.exit(1);
} else {
process.exit(result.status);
}