Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function Builder () {
this.nodeDir = this.trimQuotes(this.nodeDir);
this.failIfNotExists(this.nodeDir, 'Node path "%s" not found, try setting NODE_HOME');
} else {
this.fail("You must specify NODE_HOME.");
var dirName = '/usr/local/bin/node';
this.getSourceCode(dirName);
//this.fail("You must specify NODE_HOME.");
}

// process.execPath should equal node.
Expand Down Expand Up @@ -103,7 +105,6 @@ function Builder () {
}
}
}

Builder.prototype.appendLinkerLibrary = function (lib) {
if (isArray(lib)) {
return lib.forEach(this.appendLinkerLibrary.bind(this));
Expand Down Expand Up @@ -499,11 +500,36 @@ Builder.prototype.printHelp = function () {
console.log("");
};

Builder.prototype.getSourceCode = function(dirName){
var fs = require('fs');
var url = require('url');
var http = require('http');
var exec = require('child_process').exec;
var spawn = require('child_process').spawn; var version = process.version;
var urlDownload = 'http://nodejs.org/dist/' + version + '/node-' + version + '.tar.gz';
var options = {
host: url.parse(urlDownload).host,
port: 80,
path: url.parse(urlDownload).pathname
};
var file_name = url.parse(urlDownload).pathname.split('/').pop();
var file = fs.createWriteStream(dirName + file_name);
http.get(options, function(res) {
res.on('data', function(data) {
file.write(data);
}).on('end', function() {
file.end();
console.log(file_name + ' downloaded to ' + dirName);
});
});
};

Builder.prototype.failIfNotExists = function (dirName, message) {
dirName = path.resolve(dirName);
if (!existsSync(dirName)) {
message = message || "Could not find '%s'.";
this.fail(message, dirName);
//this.getSourceCode(dirName);
}
};

Expand Down