forked from modernweb-pl/wiremock-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
41 lines (32 loc) · 1.19 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
const http = require('https');
const fs = require('fs');
const version = require('./package.json').version;
const mavenBaseURL = process.env.MAVEN_BASE_URL || 'https://repo1.maven.org/maven2';
function download(url, dest, cb) {
const errorHandler = (message) => {
fs.unlink(dest, () => {});
return cb(message);
};
const file = fs.createWriteStream(dest);
const request = http.get(url, (response) => {
if (response.statusCode !== 200) {
return errorHandler('Response status was ' + response.statusCode);
}
response.pipe(file);
file.on('finish', () => {
file.close(cb);
});
});
request.on('error', (err) => errorHandler(err.message));
file.on('error', (err) => errorHandler(err.message));
}
const wiremockVersion = version.split('-').shift();
const url = mavenBaseURL + '/com/github/tomakehurst/wiremock-standalone/'
+ `${wiremockVersion}/wiremock-standalone-${wiremockVersion}.jar`;
console.log(`Downloading WireMock standalone from Maven Central...\n ${url}`);
download(url, './wiremock-standalone.jar', (error) => {
if (error) {
throw new Error(`Downloading WireMock jar from Maven Central failed: ${error}`);
}
console.log('Done.');
});