This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix node download logic #1048
Merged
Merged
Fix node download logic #1048
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"use strict"; | ||
|
||
var _ = require("underscore"); | ||
var gulp = require('gulp'); | ||
var exec = require('child_process').exec; | ||
|
@@ -8,8 +10,8 @@ var spawn = require('child_process').spawn; | |
var merge = require('merge-stream'); | ||
var rename = require("gulp-rename"); | ||
var download = require('gulp-download-stream'); | ||
var decompress = require('gulp-decompress'); | ||
var tap = require("gulp-tap"); | ||
const shell = require('shelljs'); | ||
const mocha = require('gulp-spawn-mocha'); | ||
// const zip = require('gulp-zip'); | ||
// var zip = require('gulp-zip'); | ||
|
@@ -133,87 +135,114 @@ gulp.task('clean:nodes', function (cb) { | |
], cb); | ||
}); | ||
|
||
gulp.task('downloadNodes', ['clean:nodes'], function(done) { | ||
var streams = []; | ||
|
||
_.each(nodeUrls, function(nodeUrl, os){ | ||
gulp.task('downloadNodes', ['clean:nodes'], function() { | ||
let toDownload = []; | ||
|
||
//var destPath = (os === 'darwin-x64') | ||
// ? path +'/'+ filenameUppercase +'.app/Contents/Frameworks/node' | ||
//: path +'/resources/node'; | ||
_.each(nodeUrls, function(url, osArch) { | ||
let ext = (0 <= osArch.indexOf('linux') ? '.tar.bz2' : '.zip'); | ||
|
||
|
||
// donwload nodes | ||
if (os.indexOf(options.platform) !== -1 || options.platform == 'all') | ||
streams.push(download(nodeUrl) | ||
.pipe(gulp.dest('./nodes/geth/'))); | ||
if (osArch.indexOf(options.platform) !== -1 || options.platform == 'all') { | ||
toDownload.push({ | ||
file: `geth-${gethVersion}_${osArch}_${ext}`, | ||
url: url, | ||
}); | ||
} | ||
|
||
toDownload.push({ | ||
file: `geth-${gethVersion}_${osArch}_${ext}`, | ||
url: url, | ||
}); | ||
}); | ||
|
||
return merge.apply(null, streams); | ||
return download(toDownload) | ||
.pipe(gulp.dest('./nodes/geth/')); | ||
}); | ||
|
||
|
||
|
||
gulp.task('unzipNodes', ['downloadNodes'], function(done) { | ||
let nodeZips = fs.readdirSync('./nodes/geth'); | ||
|
||
var streams = []; | ||
|
||
_.each(nodeUrls, function(nodeUrl, os){ | ||
for (let zipFileName of nodeZips) { | ||
let match = zipFileName.match(/_(\w+\-\w+)_/); | ||
if (!match) { | ||
continue; | ||
} | ||
|
||
var fileName = nodeUrl.substr(nodeUrl.lastIndexOf('/')); | ||
let osArch = match[1]; | ||
|
||
// unzip nodes | ||
streams.push(gulp.src('./nodes/geth'+ fileName) | ||
.pipe(decompress({strip: 1})) | ||
.pipe(gulp.dest('./nodes/geth/'+ os))); | ||
let ret; | ||
|
||
}); | ||
shell.mkdir('-p', `./nodes/geth/${osArch}`); | ||
|
||
return merge.apply(null, streams); | ||
if (0 <= osArch.indexOf('linux')) { | ||
ret = shell.exec(`tar -xzf ./nodes/geth/${zipFileName} -C ./nodes/geth/${osArch}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @hiddentao There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @luclu should be fixed |
||
|
||
} else { | ||
ret = shell.exec(`unzip -o ./nodes/geth/${zipFileName} -d ./nodes/geth/${osArch}`); | ||
} | ||
|
||
if (0 !== ret.code) { | ||
console.error('Error unzipping ' + zipFileName); | ||
console.log(ret.stdout); | ||
console.error(ret.stderr); | ||
return done(ret.stderr); | ||
} | ||
} | ||
|
||
done(); | ||
}); | ||
|
||
|
||
|
||
gulp.task('renameNodes', ['unzipNodes'], function(done) { | ||
var streams = []; | ||
|
||
_.each(nodeUrls, function(nodeUrl, os){ | ||
for (let osArch in nodeUrls) { | ||
const file = fs.readdirSync('./nodes/geth/' + osArch).pop(); | ||
|
||
var fileName = nodeUrl.substr(nodeUrl.lastIndexOf('/')).replace('download_file?file_path=','').replace('.tar.bz2','').replace('.zip',''); | ||
const finalName = (0 <= osArch.indexOf('win32') ? 'geth.exe' : 'geth'); | ||
|
||
// unzip nodes | ||
if(os === 'linux-ia32' || os === 'win32-ia32') { | ||
console.log(fileName); | ||
var task = gulp.src('./nodes/geth/'+ os + fileName); | ||
const originalPath = `./nodes/geth/${osArch}/${file}`, | ||
finalPath = `./nodes/geth/${osArch}/${finalName}`; | ||
|
||
if(os === 'linux-ia32') | ||
task.pipe(rename('geth/'+ os + '/geth')); | ||
if(os === 'win32-ia32') | ||
task.pipe(rename('geth/'+ os + '/geth.exe')); | ||
let ret = shell.mv(originalPath, finalPath); | ||
|
||
task.pipe(gulp.dest('./nodes/')); | ||
if (0 !== ret.code) { | ||
console.error(`Error renaming ${originalPath}`); | ||
|
||
streams.push(task); | ||
return done(ret.stderr); | ||
} | ||
|
||
}); | ||
ret = shell.exec(`chmod +x ${finalPath}`); | ||
|
||
return merge.apply(null, streams); | ||
}); | ||
if (0 !== ret.code) { | ||
console.error(`Error setting executable permission: ${finalPath}`); | ||
|
||
gulp.task('renameNodesDeleteOld', ['renameNodes'], function (cb) { | ||
return del([ | ||
'./nodes/geth/linux-ia32/'+ nodeUrls['linux-ia32'].substr(nodeUrls['linux-ia32'].lastIndexOf('/')).replace('download_file?file_path=','').replace('.tar.bz2','').replace('.zip',''), | ||
'./nodes/geth/win32-ia32/'+ nodeUrls['win32-ia32'].substr(nodeUrls['linux-ia32'].lastIndexOf('/')).replace('download_file?file_path=','').replace('.tar.bz2','').replace('.zip',''), | ||
], cb); | ||
return done(ret.stderr); | ||
} | ||
} | ||
|
||
return done(); | ||
}); | ||
|
||
|
||
|
||
|
||
// CHECK FOR NODES | ||
|
||
var updatedNeeded = true; | ||
gulp.task('checkNodes', function() { | ||
return gulp.src('./nodes/geth/*.{zip,tar.bz2}') | ||
.pipe(tap(function(file, t) { | ||
if(!!~file.path.indexOf('-'+ gethVersion +'-')) { | ||
updatedNeeded = false; | ||
} | ||
})) | ||
|
||
var nodeUpdateNeeded = false; | ||
gulp.task('checkNodes', function(cb) { | ||
return gulp.src('./nodes/geth/*.{zip,tar.bz2}', { read: false }) | ||
.pipe(tap(function(file, t) { | ||
nodeUpdateNeeded = | ||
nodeUpdateNeeded || (0 > file.path.indexOf(gethVersion)); | ||
})) | ||
.pipe(gulp.dest('./nodes/geth/')); | ||
}); | ||
|
||
|
@@ -223,7 +252,7 @@ gulp.task('checkNodes', function() { | |
gulp.task('copy-files', ['checkNodes', 'clean:dist'], function() { | ||
|
||
// check if nodes are there | ||
if(updatedNeeded){ | ||
if(nodeUpdateNeeded){ | ||
console.error('YOUR NODES NEED TO BE UPDATED run $ gulp update-nodes'); | ||
throw new Error('YOUR NODES NEED TO BE UPDATED run $ gulp update-nodes'); | ||
} | ||
|
@@ -508,7 +537,7 @@ gulp.task('taskQueue', [ | |
|
||
// DOWNLOAD nodes | ||
gulp.task('update-nodes', [ | ||
'renameNodesDeleteOld' | ||
'renameNodes' | ||
]); | ||
gulp.task('download-nodes', ['update-nodes']); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant code L153-L156
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed!