|
| 1 | +var promisify = require("promisify-node"); |
| 2 | +var Promise = require("nodegit-promise"); |
| 3 | +var path = require("path"); |
| 4 | +var fs = require("fs"); |
| 5 | + |
| 6 | +var whichNativeNodish = require("which-native-nodish"); |
| 7 | +var spinner = new require("node-spinner")(); |
| 8 | +spinner.set('|/-\\'); |
| 9 | + |
| 10 | +var exec = promisify(function(command, opts, callback) { |
| 11 | + return require("child_process").exec(command, opts, callback); |
| 12 | +}); |
| 13 | + |
| 14 | +module.exports = function() { |
| 15 | + return whichNativeNodish("..") |
| 16 | + .then(function(results) { |
| 17 | + var type = "node"; |
| 18 | + if (results.nwVersion) { |
| 19 | + type = "nw.js"; |
| 20 | + } |
| 21 | + else if (results.asVersion) { |
| 22 | + type = "atom-shell"; |
| 23 | + } |
| 24 | + console.info("[nodegit] Building native " + type + " module"); |
| 25 | + |
| 26 | + spinner.reset(); |
| 27 | + spin(); |
| 28 | + var interval = setInterval(spin, 250); |
| 29 | + |
| 30 | + var opts = { |
| 31 | + cwd: ".", |
| 32 | + maxBuffer: Number.MAX_VALUE |
| 33 | + }; |
| 34 | + |
| 35 | + var prefix = ""; |
| 36 | + var target = ""; |
| 37 | + var debug = (process.env.BUILD_DEBUG ? " --debug" : ""); |
| 38 | + var builder = "pangyp"; |
| 39 | + var distUrl = ""; |
| 40 | + if (results.asVersion) { |
| 41 | + prefix = (process.platform == "win32" ? |
| 42 | + "SET HOME=%HOME%\\.atom-shell-gyp&& " : |
| 43 | + "HOME=~/.atom-shell-gyp"); |
| 44 | + |
| 45 | + target = "--target=" + results.asVersion; |
| 46 | + |
| 47 | + distUrl = "--dist-url=https://gh-contractor-zcbenz.s3." + |
| 48 | + "amazonaws.com/atom-shell/dist"; |
| 49 | + } |
| 50 | + else if (results.nwVersion) { |
| 51 | + builder = "nw-gyp"; |
| 52 | + target = "--target=" + results.nwVersion; |
| 53 | + } |
| 54 | + return exec("npm install nan " + builder) |
| 55 | + .then(function() { |
| 56 | + builder = path.resolve(".", "node_modules", ".bin", builder); |
| 57 | + builder = builder.replace(/\s/g, "\\$&"); |
| 58 | + var cmd = [prefix, builder, "rebuild", target, debug, distUrl] |
| 59 | + .join(" ").trim(); |
| 60 | + |
| 61 | + return exec(cmd, opts); |
| 62 | + }) |
| 63 | + .then(function() { |
| 64 | + if (interval) { |
| 65 | + clearInterval(interval); |
| 66 | + process.stdout.write('\r'); |
| 67 | + } |
| 68 | + console.info("[nodegit] Compilation complete."); |
| 69 | + console.info("[nodegit] Completed installation successfully."); |
| 70 | + }, |
| 71 | + function(reason) { |
| 72 | + if (interval) { |
| 73 | + clearInterval(interval); |
| 74 | + process.stdout.write('\r'); |
| 75 | + } |
| 76 | + return Promise.reject(reason); |
| 77 | + }); |
| 78 | + }); |
| 79 | +}; |
| 80 | + |
| 81 | +function spin() { |
| 82 | + process.stdout.write('\r \033[36mbuilding\033[m ' + spinner.next()); |
| 83 | +} |
0 commit comments