-
Notifications
You must be signed in to change notification settings - Fork 33
/
postinstall.js
36 lines (33 loc) · 1.36 KB
/
postinstall.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
const https = require('https');
const fs = require('fs');
const constants = require('./constants');
const dependencies = {
[constants.VENDOR_PDF_BOX_JAR]: 'https://archive.apache.org/dist/pdfbox/2.0.27/pdfbox-app-2.0.27.jar',
[constants.VENDOR_TIKA_JAR]: 'https://archive.apache.org/dist/tika/2.6.0/tika-app-2.6.0.jar',
};
const download = (filename) => {
const filePath = constants.DIRECTORY.VENDOR + filename;
fs.access(filePath, fs.constants.F_OK, (err) => {
if (err) {
console.log(`Started downloading dependency ${filename}.`);
const request = https.get(dependencies[filename], (response) => {
if (response.statusCode === 200) {
const fileStream = fs.createWriteStream(filePath);
response.pipe(fileStream);
fileStream.addListener('finish', () => {
console.log(`Finished downloading dependency ${filename}.`);
});
} else {
throw new Error(`Failed downloading dependency ${filename}.`);
}
});
request.on('error', () => {
throw new Error(`Failed downloading dependency ${filename}.`);
});
}
});
};
const filenames = Object.keys(dependencies);
filenames.forEach((filename) => {
download(filename);
});