-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.js
49 lines (41 loc) · 1.74 KB
/
install.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
const axios = require('axios');
const fs = require('fs');
const { lilconfigSync } = require('lilconfig');
const explorer = lilconfigSync('wiremock', { searchPlaces: ['.wiremock', 'package.json'] });
const config = (explorer.search() || { config: {} }).config;
const options = {
version: process.env.WIREMOCK_VERSION || config.version,
mavenRepoURL: process.env.MAVEN_BASE_URL || process.env.MAVEN_REPO_URL || config.mavenRepoURL || 'https://repo1.maven.org/maven2',
jreVersion: process.env.JRE_VERSION || process.env.JRE_VERSION || config.jreVersion || 'jre8',
};
const mavenPath = 'com/github/tomakehurst';
const name = options.jreVersion === 'jre8' ? 'wiremock-jre8-standalone' : 'wiremock-standalone';
function resolveVersion() {
return axios.get(`${options.mavenRepoURL}/${mavenPath}/${name}/maven-metadata.xml`)
.then(({ data: meta }) => {
if (options.version) {
const regexp = new RegExp(`<version>${options.version}<\/version>`);
if (!regexp.test(meta)) {
throw new Error(`Unknown WireMock version: ${options.version}`);
}
return options.version;
}
// latest
return meta.match(/<release>([.\d]+)<\/release>/m)[1];
});
}
function download(url, dest) {
return axios.get(url, { responseType: 'stream' })
.then(({ data }) => data.pipe(fs.createWriteStream(dest)));
}
resolveVersion()
.then((version) => {
const url = `${options.mavenRepoURL}/${mavenPath}/${name}/${version}/${name}-${version}.jar`;
console.log(`Downloading WireMock standalone from Maven Central...\n ${url}`);
return download(url, './wiremock-standalone.jar')
.then(() => console.log('Done.'));
})
.catch((e) => {
console.error(`\x1b[31m Error: ${e.message}`);
process.exit(1);
});