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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
// **********************************************************************
// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in th
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
var execFile = require('child_process').execFile;
var fs = require('fs');
var http = require('http');
var os = require('os');
var path = require('path');
var url = require('url');
var util = require('util');
var zlib = require('zlib');
var platform = os.platform();
var arch = os.arch();
var BIN_DIR = path.join(__dirname, 'bin');
var slice2js = platform === 'win32' ? 'slice2js.exe' : 'slice2js';
slice2js = path.join(BIN_DIR, slice2js);
var pkgVer = require('./package.json').slice2js;
function downloadSlice2js(redirectUrl)
{
if(fs.existsSync(slice2js))
{
fs.unlinkSync(slice2js);
}
var SLICE2JS_URL = redirectUrl ||
process.env.SLICE2JS_URL ||
process.env.npm_config_SLICE2JS_URL ||
'http://zeroc.com/download/3.6/';
var dlPath =
{
'darwin' :
{
'x64' : util.format('slice2js-%s-osx.gz', pkgVer)
},
'linux':
{
'x64' : util.format('slice2js-%s-linux-%s.gz', pkgVer, arch),
'x86' : util.format('slice2js-%s-linux-%s.gz', pkgVer, arch)
},
'win32':
{
'x64' : util.format('slice2js-%s-win-%s.exe.gz', pkgVer, arch),
'x86' : util.format('slice2js-%s-win-%s.exe.gz', pkgVer, arch)
}
};
var slice2js_url = url.resolve(SLICE2JS_URL, dlPath[platform][arch]);
console.log('Downloading slice2js from: ' + slice2js_url);
var req = http.get(slice2js_url,
function(res)
{
if(res.statusCode !== 200)
{
if(res.statusCode === 302 && !redirectUrl)
{
return downloadSlice2js(res.headers.location);
}
else if (res.statusCode === 404)
{
console.log('Unable to find slice2js at %s. Proceeding without it.', SLICE2JS_URL);
process.exit(0);
}
else
{
consle.log('There was an error downloading slice2js.');
process.exit(0);
}
}
var progress = 0;
var dlStream = fs.createWriteStream(slice2js + '.gz');
res.pipe(dlStream);
res.on('end',
function()
{
console.log('Slice2js downloaded.');
dlStream.end();
var zipSteam = fs.createReadStream(slice2js+'.gz');
var fileStream = fs.createWriteStream(slice2js, {flags : 'w', mode: 33261});
zipSteam.pipe(zlib.createGunzip()).pipe(fileStream);
fileStream.on('close',
function()
{
fs.unlinkSync(slice2js+'.gz');
});
});
});
req.on('error',
function(err)
{
console.log('There was an error retrieving slice2js. ' + err.message);
});
}
if(fs.existsSync(slice2js) === true)
{
execFile(slice2js, ['--version'],
function(err, stdout, stderr)
{
if (err)
{
return downloadSlice2js();
}
var version = stdout.trim() || stderr.trim();
if(version === pkgVer)
{
return;
}
else
{
downloadSlice2js();
}
});
}
else
{
downloadSlice2js();
}
module.exports.path = slice2js;
module.exports.version = pkgVer;
|