install.js 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. var spawn = require('child_process').spawn
  2. , exec = require('child_process').exec
  3. , fs = require('fs')
  4. , version = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8')).version
  5. , verbose = process.env['npm_package_config_verbose'] != null ? process.env['npm_package_config_verbose'] === 'true' : false;
  6. console.log('[websocket v%s] Attempting to compile native extensions.', version);
  7. var gyp = exec('node-gyp rebuild', {cwd: __dirname});
  8. gyp.stdout.on('data', function(data) {
  9. if (verbose) process.stdout.write(data);
  10. });
  11. gyp.stderr.on('data', function(data) {
  12. if (verbose) process.stdout.write(data);
  13. });
  14. gyp.on('exit', function(code) {
  15. if (code !== 0) {
  16. console.log("[websocket v%s]", version);
  17. console.log(' Native code compile failed!!');
  18. console.log(' Please note that this module DOES NOT REQUIRE the native components');
  19. console.log(' and will still work without them, though not quite as efficiently.');
  20. console.log('');
  21. console.log(' On Windows, native extensions require Visual Studio and Python.');
  22. console.log(' On Unix, native extensions require Python, make and a C++ compiler.');
  23. console.log(' Start npm with --websocket:verbose to show compilation output (if any).');
  24. }
  25. else {
  26. console.log('[websocket v%s] Native extension compilation successful!', version);
  27. }
  28. process.exit();
  29. });