-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpostinstall.js
75 lines (60 loc) · 1.9 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// BINARIES:
// https://code.google.com/p/wkhtmltopdf/downloads/list?can=1
'use strict';
var HTI_URL = 'http://cdn.codecorico.com/wkhtmltoimage',
DESTINATION = 'vendor/wkhtmltoimage',
LINKS = {
'windows-32-old': 'win32-old/wkhtmltoimage.exe',
'windows-64-old': 'win64-old/wkhtmltoimage.exe',
'windows-32': 'win32/wkhtmltoimage.exe',
'windows-64': 'win64/wkhtmltoimage.exe',
'mac': 'mac/wkhtmltoimage',
'linux': 'linux/wkhtmltoimage'
},
os = require('os'),
fs = require('fs'),
http = require('http'),
ProgressBar = require('progress'),
release = os.release(),
link = [];
if(fs.existsSync(DESTINATION)) {
return console.log('Card renderer (wkhtmltoimage) already installed');
}
if(process.platform == 'win32') {
link.push('windows');
link.push(process.arch == 'x64' ? '64' : '32');
if(parseInt(release.split('.')[0], 10) < 6) {
link.push('old');
}
}
else if(process.platform == 'darwin') {
link.push('mac');
}
else if(process.platform == 'linux') {
link.push('linux');
}
if(!link.length) {
return console.error('This operating system doesn\'t support The Machine');
}
link = HTI_URL + '/' + LINKS[link.join('-')];
var file = link.substr(link.lastIndexOf('/') + 1, link.length - link.lastIndexOf('/') - 1),
fileDestination = DESTINATION + '/' + file;
console.log('Downloading the card renderer (wkhtmltoimage)');
http.get(link, function(response) {
fs.mkdirSync(DESTINATION);
response.pipe(fs.createWriteStream(fileDestination));
var progressbar = new ProgressBar('[:bar] :percent :etas', {
complete: '=',
incomplete: ' ',
width: 20,
total: parseInt(response.headers['content-length'], 10)
});
progressbar.render();
response.on('end', function() {
fs.chmod(fileDestination, '755');
console.log('INSTALLED');
});
response.on('data', function(chunk) {
progressbar.tick(chunk.length);
});
});