summaryrefslogtreecommitdiff
path: root/distribution/src/js/npm/installSlice2js.js
diff options
context:
space:
mode:
authorJoe George <joe@zeroc.com>2014-09-05 15:24:15 -0230
committerJoe George <joe@zeroc.com>2014-09-05 15:24:15 -0230
commita3a7a19af2c48ef4911f5c4dcccab118c279f333 (patch)
tree4c19c7ba3145674ca0aa2679f1422519495b83c4 /distribution/src/js/npm/installSlice2js.js
parentICE-5659 remove Ice.MonitorConnections from properties (diff)
downloadice-a3a7a19af2c48ef4911f5c4dcccab118c279f333.tar.bz2
ice-a3a7a19af2c48ef4911f5c4dcccab118c279f333.tar.xz
ice-a3a7a19af2c48ef4911f5c4dcccab118c279f333.zip
ICE-5658 - NPM support for IceJS distribution
Diffstat (limited to 'distribution/src/js/npm/installSlice2js.js')
-rw-r--r--distribution/src/js/npm/installSlice2js.js135
1 files changed, 135 insertions, 0 deletions
diff --git a/distribution/src/js/npm/installSlice2js.js b/distribution/src/js/npm/installSlice2js.js
new file mode 100644
index 00000000000..9c76feb21f8
--- /dev/null
+++ b/distribution/src/js/npm/installSlice2js.js
@@ -0,0 +1,135 @@
+// **********************************************************************
+// Copyright (c) 2003-2014 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;