From 0055ad6d11a92e99ffdc33630c98a2bbdf12d83e Mon Sep 17 00:00:00 2001 From: Anuar Ustayev Date: Tue, 6 Mar 2018 15:49:30 +0600 Subject: [PATCH] [v0.3.2][s]: Progress bar when uploading files to S3 (#31) * [progress bar][s]: now we show progress bar of each file being uploaded - refs https://github.com/datahq/data-cli/issues/116 * [progress bar][xs]: clear a progress bar once completed - refs https://github.com/datahq/data-cli/issues/116 --- lib/utils/datahub.js | 13 ++++++++++++- package.json | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/utils/datahub.js b/lib/utils/datahub.js index 85b2d8e..f8b007e 100644 --- a/lib/utils/datahub.js +++ b/lib/utils/datahub.js @@ -9,6 +9,7 @@ const toArray = require('stream-to-array') const infer = require('tableschema').infer const YAML = require('yamljs') const urljoin = require('url-join') +const ProgressBar = require('progress') const {Agent} = require('./agent') const {checkUrlIsOK} = require('./common') @@ -86,7 +87,17 @@ class DataHub extends EventEmitter { // https://github.com/datahq/datahub-qa/issues/60 throw new Error("> You can not push empty files, please add some data and try again:\n" + resource.path) } - + // Show the progress bar for each file being uploaded: + let bar = new ProgressBar(` Uploading [:bar] :percent (:etas left) ${resource.descriptor.path}`, { + complete: '*', + incomplete: ' ', + width: 30, + total: totalLength, + clear: true + }) + formData.on('data', (chunk) => { + bar.tick(chunk.length) + }) // Use straight fetch as not interacting with API but with external object store const res = await fetch(creds.upload_url, { method: 'POST', diff --git a/package.json b/package.json index fcf628b..6d103c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datahub-client", - "version": "0.3.1", + "version": "0.3.2", "description": "APIs for interacting with DataHub", "main": "index.js", "scripts": { @@ -51,7 +51,6 @@ "markdown-table": "^1.1.1", "mkdirp": "^0.5.1", "nconf": "^0.9.1", - "nock": "^9.1.0", "node-fetch": "^1.7.3", "opn": "^5.1.0", "progress": "^2.0.0", @@ -64,6 +63,7 @@ "devDependencies": { "ava": "^0.19.1", "inquirer-test": "^1.0.5", + "nock": "^9.1.0", "sinon": "^4.1.2", "stream-to-array": "^2.3.0", "xo": "^0.18.2"