Skip to content

Commit

Permalink
Merge pull request #45 from sutt0n/master
Browse files Browse the repository at this point in the history
fixed utilization of updated version of tar, added unit tests
  • Loading branch information
AshanFernando authored Jun 22, 2019
2 parents 1489ac1 + 1aebdce commit 57695eb
Show file tree
Hide file tree
Showing 5 changed files with 1,090 additions and 60 deletions.
16 changes: 8 additions & 8 deletions dynamodb/config.json
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
}
}
115 changes: 64 additions & 51 deletions dynamodb/installer.js
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;
Loading

0 comments on commit 57695eb

Please sign in to comment.