Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed utilization of updated version of tar, added unit tests #45

Merged
merged 10 commits into from
Jun 22, 2019
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