From 6e27d0e07951322b1c820c356e44120c0da94326 Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Tue, 12 Feb 2019 12:07:50 -0800 Subject: [PATCH] maintainance + error handling --- .gitignore | 3 ++- cli.js | 6 ++++++ index.js | 9 +++++---- package.json | 8 +++++--- readme.md | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index b512c09..25c8fdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +package-lock.json \ No newline at end of file diff --git a/cli.js b/cli.js index 798fdf2..f0f03c3 100755 --- a/cli.js +++ b/cli.js @@ -6,6 +6,12 @@ var args = require('minimist')(process.argv.slice(2), { } }) +if (!args._.length) { + console.error('Usage:') + console.error(' dat-push []') + process.exit(1) +} + var DatPush = require('.') DatPush(args.dir, args._, function (err) { if (err) throw err diff --git a/index.js b/index.js index a1c92da..58b6adb 100755 --- a/index.js +++ b/index.js @@ -6,12 +6,12 @@ var debug = require('debug')('dat-push') const WANT_TIMEOUT = 5e3 module.exports = function (datPath, pushTo, cb) { - assert.equal(typeof datPath, 'string', 'dat-push: string path required') + assert.strictEqual(typeof datPath, 'string', 'dat-push: string path required') if (typeof pushTo === 'function') { cb = pushTo pushTo = null } - assert.equal(typeof cb, 'function', 'dat-push: callback required') + assert.strictEqual(typeof cb, 'function', 'dat-push: callback required') debug('dir', datPath) if (!pushTo) return push([]) @@ -33,11 +33,12 @@ module.exports = function (datPath, pushTo, cb) { } function push (whitelist) { - Dat(datPath, {createIfMissing: false}, function (err, dat) { + Dat(datPath, { createIfMissing: false }, function (err, dat) { if (err) return cb(err) var stats = dat.trackStats() var activePeers = 0 + console.log('Importing newest files...') dat.importFiles(function (err) { if (err) return cb(err) }) @@ -55,7 +56,7 @@ module.exports = function (datPath, pushTo, cb) { }) function replicate (peer) { - var stream = dat.archive.replicate({live: false}) + var stream = dat.archive.replicate({ live: false }) console.log('Replicating with', peer.host) const onClose = () => { diff --git a/package.json b/package.json index 90eea4d..d6e36f5 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,13 @@ "license": "MIT", "dependencies": { "dat-node": "^3.5.3", - "debug": "^3.0.1", + "debug": "^4.1.1", "minimist": "^1.2.0", - "pump": "^1.0.1" + "pump": "^3.0.0" + }, + "devDependencies": { + "standard": "*" }, - "devDependencies": {}, "repository": { "type": "git", "url": "git+https://github.com/joehand/dat-push.git" diff --git a/readme.md b/readme.md index 189a27c..514ee03 100644 --- a/readme.md +++ b/readme.md @@ -27,7 +27,7 @@ dat-push ./existing/dat-dir hashbase.io ## License -[MIT](LICENSE.md) +[MIT](LICENSE) [npm-image]: https://img.shields.io/npm/v/dat-download.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/dat-download