Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
fix install error
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjingboy committed Oct 8, 2018
1 parent fbf10b8 commit 09228c9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ function getNodeCachePath(version) {

function downloadNode(version, callback) {
var nodeCachePath = getNodeCachePath(version);

if (fs.existsSync(nodeCachePath)) {
return callback(true);
}

console.log('Downloading Node %s... '.green, version);
async.waterfall(
[
Expand All @@ -41,7 +39,6 @@ function downloadNode(version, callback) {
}
request.get(url, function(error, response, data) {
var status = true;

if (error !== null || response.statusCode !== 200) {
status = false;
fs.unlinkSync(nodeCachePath);
Expand All @@ -67,7 +64,6 @@ function install(targetPath, version) {
extract(nodeCachePath, { dir: targetPath }, function(error) {
if (error) {
rmdir(path.join(targetPath, nodeFileName), function(err, dirs, files) {
fs.unlinkSync(nodeCachePath);
console.log('Node %s installed failed', version);
});
} else {
Expand All @@ -84,7 +80,6 @@ function install(targetPath, version) {
module.exports = function(version) {
var nodeDir,
versionParts;

version = common.replaceVersion(version);
versionParts = _.map(version.split('.'), function(index) {
return parseInt(index.replace('v', ''));
Expand All @@ -109,7 +104,17 @@ module.exports = function(version) {
],
function(status) {
if (status === true) {
install(path.join(nodeDir, '..'), version);
if (fs.existsSync(nodeDir)) {
rmdir(nodeDir, function(err, dirs, files) {
if (err) {
console.log('Node %s installed failed', version);
} else {
install(path.join(nodeDir, '..'), version);
}
});
} else {
install(path.join(nodeDir, '..'), version);
}
}
}
);
Expand Down

0 comments on commit 09228c9

Please sign in to comment.