Skip to content

Commit

Permalink
Merge pull request #33 from gdotdesign/development
Browse files Browse the repository at this point in the history
Install to dist directory alongside the scripts.
  • Loading branch information
gdotdesign authored Aug 4, 2017
2 parents 5081c1b + 975cfef commit 9b01636
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage
test.elm
test.rb
index.html
scripts/dist*
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
elm_install (1.1.1)
elm_install (1.1.0)
adts (~> 0.1.2)
commander (~> 4.4, >= 4.4.2)
contracts (~> 0.16.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/elm_install/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ElmInstall
# The version of ElmInstall
VERSION = '1.1.1'.freeze
VERSION = '1.1.0'.freeze
end
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
},
"dependencies": {
"adm-zip": "^0.4.7",
"progress": "^2.0.0",
"request": "2.74.0",
"request-progress": "^3.0.0",
"shelljs": "0.7.5",
"tar-fs": "1.15.0",
"tmp": "^0.0.31"
Expand Down
44 changes: 33 additions & 11 deletions scripts/install.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var progress = require('request-progress')
var ProgressBar = require('progress')
var request = require('request')
var shell = require('shelljs')
var AdmZip = require('adm-zip')
var shell = require('shelljs')
var tar = require('tar-fs')
var path = require('path')
var zlib = require('zlib')
Expand All @@ -13,7 +15,11 @@ var version =
fs.readFileSync(versionPath, 'utf-8')
.match(/(\d+\.\d+\.\d+)/)[1]

var homedir = path.join(os.homedir(), '.elm-install')
var homedir = path.join(__dirname, 'dist-' + version)

// We already have that version downloaded
if(fs.existsSync(homedir)){ process.exit() }

var platform = os.platform()
var arch = process.arch

Expand All @@ -29,12 +35,31 @@ var packageUrl = function(suffix) {
].join('/')
}

var download = function(suffix){
console.log(
'Downloading and extracting the binary from: ' + packageUrl(suffix))
var downloadRequest = function(url) {
var bar, lastTransferred

request
.get(packageUrl(suffix))
return progress(request.get(url))
.on("progress", function(data){
if (bar) {
bar.tick(data.size.transferred - lastTransferred)
lastTransferred = data.size.transferred
} else {
lastTransferred = 0
bar = new ProgressBar(
'Downloading and extracting the binary: [:bar] :rate/bps :percent :etas',
{
total: data.size.total,
incomplete: ' ',
complete: '=',
width: 60
}
)
}
})
}

var download = function(suffix){
downloadRequest(packageUrl(suffix))
.pipe(zlib.createGunzip())
.pipe(extractor)
}
Expand All @@ -53,10 +78,7 @@ if(platform === 'linux' && arch === 'x64') {
'elm-install-' + version + '-win32.zip'
].join('/')

console.log('Downloading and extracting the binary from: ' + url)

request
.get(url)
downloadRequest(url)
.pipe(fs.createWriteStream(tmpFile.name))
.on('finish', function(){
var zip = new AdmZip(tmpFile.name)
Expand Down
2 changes: 1 addition & 1 deletion scripts/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var version =
fs.readFileSync(versionPath, 'utf-8')
.match(/(\d+\.\d+\.\d+)/)[1]

var homedir = path.join(os.homedir(), '.elm-install')
var homedir = path.join(__dirname, 'dist-' + version)
var platform = os.platform()
var arch = process.arch

Expand Down

0 comments on commit 9b01636

Please sign in to comment.