Skip to content

Commit f4bfba6

Browse files
committed
Added serverless spinner instead of the percentage counter.
1 parent c74fdf1 commit f4bfba6

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

dynamodb/core.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let runningProcesses = {},
2828
* @param options
2929
* @returns {Promise.<ChildProcess>}
3030
*/
31-
start: function (options) {
31+
start: function (options, spinner) {
3232
return new BbPromise(function (resolve, reject) {
3333
/* Dynamodb local documentation http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html */
3434
let additionalArgs = [];
@@ -54,8 +54,7 @@ let runningProcesses = {},
5454
if (options.help) {
5555
additionalArgs.push('-help');
5656
}
57-
58-
installer.setup(DB_PATH, DOWNLOAD_PATH, JAR)
57+
installer.setup(DB_PATH, DOWNLOAD_PATH, JAR, spinner)
5958
.then(function () {
6059
let args = [
6160
'-Djava.library.path=./DynamoDBLocal_lib', '-jar', JAR, '-port', options.port

dynamodb/installer.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ let BbPromise = require('bluebird'),
66
path = require('path'),
77
http = require('http'),
88
fs = require('fs');
9+
910

10-
let download = function (source, destination) {
11-
let createDir = function (path) {
11+
let download = function (source, destination, spinner) {
12+
let createDir = function (path) {
1213
if (!fs.existsSync(path)) {
1314
fs.mkdirSync(path);
1415
}
@@ -23,7 +24,7 @@ let download = function (source, destination) {
2324
let len = parseInt(redirectResponse.headers['content-length'], 10),
2425
cur = 0,
2526
total = len / 1048576; //1048576 - bytes in 1Megabyte
26-
console.log("Downloading dynamodb local (Size " + total.toFixed(2) + " mb). This is one-time operation and can take several minutes ...");
27+
console.log("Downloading dynamodb local (Size " + total.toFixed(2) + " mb). This is one-time operation and can take several minutes ...");
2728
if (200 != redirectResponse.statusCode) {
2829
reject(new Error('Error getting DynamoDb local latest tar.gz location ' + response.headers.location + ': ' + redirectResponse.statusCode));
2930
}
@@ -33,14 +34,15 @@ let download = function (source, destination) {
3334
path: destination
3435
}))
3536
.on('end', function () {
37+
spinner.stop(true);
3638
console.log("Installation complete ...");
3739
resolve();
3840
})
3941
.on('error', function (err) {
4042
reject(err);
4143
}).on("data", function (chunk) {
4244
cur += chunk.length;
43-
process.stdout.write("Downloading " + (100.0 * cur / len).toFixed(2) + "% \r");
45+
//process.stdout.write("Downloading " + (100.0 * cur / len).toFixed(2) + "% \r");
4446
});
4547
})
4648
.on('error', function (e) {
@@ -53,13 +55,14 @@ let download = function (source, destination) {
5355
});
5456
};
5557

56-
let setup = function (dbPath, downloadPath, jar) {
57-
return new BbPromise(function (resolve, reject) {
58+
let setup = function (dbPath, downloadPath, jar, spinner) {
59+
return new BbPromise(function (resolve, reject) {
5860
try {
5961
if (fs.existsSync(path.join(dbPath, jar))) {
62+
spinner.stop(true);
6063
resolve(true);
6164
} else {
62-
download(downloadPath, dbPath).then(resolve, reject);
65+
download(downloadPath, dbPath, spinner).then(resolve, reject);
6366
}
6467
} catch (e) {}
6568
});

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const _ = require('lodash'),
66
dynamodb = require('./dynamodb/core');
77

88
module.exports = function (S) { // Always pass in the ServerlessPlugin Class
9+
const SCli = require(S.getServerlessPath('utils/cli'));
910

1011
class DynamodbLocal extends S.classes.Plugin {
1112

@@ -120,7 +121,9 @@ module.exports = function (S) { // Always pass in the ServerlessPlugin Class
120121

121122
_startDynamodb(evt) {
122123
var self = this,
123-
config = S.getProject().custom.dynamodb;
124+
config = S.getProject().custom.dynamodb,
125+
_spinner = SCli.spinner();
126+
124127
let options = _.merge({
125128
sharedDb: evt.options.sharedDb || true
126129
},
@@ -129,12 +132,13 @@ module.exports = function (S) { // Always pass in the ServerlessPlugin Class
129132
);
130133
return new BbPromise(function (resolve, reject) {
131134
if (options.create) {
132-
dynamodb.start(options).then(function () {
135+
dynamodb.start(options).then(function () {
133136
console.log(""); // seperator
134137
self._tables(evt).then(resolve, reject);
135138
});
136139
} else {
137-
dynamodb.start(options).then(resolve, reject);
140+
_spinner.start();
141+
dynamodb.start(options, _spinner).then(resolve, reject);
138142
}
139143
});
140144
}

0 commit comments

Comments
 (0)