-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from sutt0n/master
fixed utilization of updated version of tar, added unit tests
- Loading branch information
Showing
5 changed files
with
1,090 additions
and
60 deletions.
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,10 +1,10 @@ | ||
{ | ||
"setup": { | ||
"download_url": "http://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz", | ||
"install_path": "./bin", | ||
"jar": "DynamoDBLocal.jar" | ||
}, | ||
"start": { | ||
"port": 8000 | ||
} | ||
"setup": { | ||
"download_url": "http://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz", | ||
"install_path": "bin", | ||
"jar": "DynamoDBLocal.jar" | ||
}, | ||
"start": { | ||
"port": 8000 | ||
} | ||
} |
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,62 +1,75 @@ | ||
'use strict'; | ||
"use strict"; | ||
|
||
var tar = require('tar'), | ||
zlib = require('zlib'), | ||
path = require('path'), | ||
http = require('http'), | ||
fs = require('fs'), | ||
ProgressBar = require('progress'), | ||
utils = require('./utils'); | ||
var tar = require("tar"), | ||
zlib = require("zlib"), | ||
path = require("path"), | ||
http = require("http"), | ||
fs = require("fs"), | ||
ProgressBar = require("progress"), | ||
utils = require("./utils"); | ||
|
||
var download = function (downloadUrl, installPath, callback) { | ||
console.log("Started downloading Dynamodb-local. Process may take few minutes."); | ||
http.get(downloadUrl, function (response) { | ||
var len = parseInt(response.headers['content-length'], 10), | ||
bar = new ProgressBar('Downloading dynamodb-local [:bar] :percent :etas', { | ||
complete: '=', | ||
incomplete: ' ', | ||
width: 40, | ||
total: len | ||
}); | ||
var download = function(downloadUrl, installPath, callback) { | ||
console.log( | ||
`Started downloading dynamodb-local from ${downloadUrl} into ${installPath}. Process may take few minutes.` | ||
); | ||
http | ||
.get(downloadUrl, function(response) { | ||
var len = parseInt(response.headers["content-length"], 10), | ||
bar = new ProgressBar( | ||
"Downloading dynamodb-local [:bar] :percent :etas", | ||
{ | ||
complete: "=", | ||
incomplete: " ", | ||
width: 40, | ||
total: len | ||
} | ||
); | ||
|
||
if (200 != response.statusCode) { | ||
throw new Error('Error getting DynamoDb local latest tar.gz location ' + response.headers.location + ': ' + response.statusCode); | ||
} | ||
if (200 != response.statusCode) { | ||
throw new Error( | ||
"Error getting DynamoDb local latest tar.gz location " + | ||
response.headers.location + | ||
": " + | ||
response.statusCode | ||
); | ||
} | ||
|
||
response | ||
.pipe(zlib.Unzip()) | ||
.pipe(tar.Extract({ | ||
path: installPath | ||
})) | ||
.on('data', function (chunk) { | ||
bar.tick(chunk.length); | ||
}) | ||
.on('end', function () { | ||
callback("\n Installation complete!"); | ||
}) | ||
.on('error', function (err) { | ||
throw new Error("Error in downloading Dynamodb local " + err); | ||
}); | ||
}) | ||
.on('error', function (err) { | ||
throw new Error("Error in downloading Dynamodb local " + err); | ||
response | ||
.pipe(zlib.Unzip()) | ||
.pipe( | ||
tar.x({ | ||
C: installPath | ||
}) | ||
) | ||
.on("data", function(chunk) { | ||
bar.tick(chunk.length); | ||
}) | ||
.on("end", function() { | ||
callback("\n Installation complete!"); | ||
}) | ||
.on("error", function(err) { | ||
throw new Error("Error in downloading Dynamodb local " + err); | ||
}); | ||
}) | ||
.on("error", function(err) { | ||
throw new Error("Error in downloading Dynamodb local " + err); | ||
}); | ||
}; | ||
|
||
var install = function (config, callback) { | ||
var install_path = utils.absPath(config.setup.install_path), | ||
jar = config.setup.jar, | ||
download_url = config.setup.download_url; | ||
var install = function(config, callback) { | ||
var install_path = utils.absPath(config.setup.install_path), | ||
jar = config.setup.jar, | ||
download_url = config.setup.download_url; | ||
|
||
try { | ||
if (fs.existsSync(path.join(install_path, jar))) { | ||
callback("Dynamodb is already installed on path!"); | ||
} else { | ||
utils.createDir(config.setup.install_path); | ||
download(download_url, install_path, callback); | ||
} | ||
} catch (err) { | ||
throw new Error("Error configuring or installing Dynamodb local " + err); | ||
try { | ||
if (fs.existsSync(path.join(install_path, jar))) { | ||
callback("Dynamodb is already installed on path!"); | ||
} else { | ||
utils.createDir(config.setup.install_path); | ||
download(download_url, install_path, callback); | ||
} | ||
} catch (err) { | ||
throw new Error("Error configuring or installing Dynamodb local " + err); | ||
} | ||
}; | ||
module.exports.install = install; |
Oops, something went wrong.