Skip to content

Commit

Permalink
maintainance + error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
joehand committed Feb 12, 2019
1 parent 8068a16 commit 6e27d0e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
package-lock.json
6 changes: 6 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ var args = require('minimist')(process.argv.slice(2), {
}
})

if (!args._.length) {
console.error('Usage:')
console.error(' dat-push <dat-directory> [<server>]')
process.exit(1)
}

var DatPush = require('.')
DatPush(args.dir, args._, function (err) {
if (err) throw err
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand All @@ -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)
})
Expand All @@ -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 = () => {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e27d0e

Please sign in to comment.