Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

style cleanup + browser build fix #127

Merged
merged 7 commits into from
Nov 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"parser": "babel-eslint",
"extends": "standard"
"extends": "standard",
"rules": {
"no-var": 2
}
}
744 changes: 306 additions & 438 deletions dist/ipfsapi.js

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions dist/ipfsapi.min.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var gulp = require('gulp')
var runSequence = require('run-sequence')
'use strict'

const gulp = require('gulp')
const runSequence = require('run-sequence')

require('require-dir')('tasks')

gulp.task('default', function (done) {
gulp.task('default', done => {
runSequence(
'lint',
'test',
Expand All @@ -17,8 +19,8 @@ gulp.task('default', function (done) {
// The issue for this is that the daemon start seems to keep
// some open connections that are not cleaned up properly and so
// gulp does not exit. So it's probably a bug in node-ipfs-ctl
gulp.on('stop', function () {
process.nextTick(function () {
gulp.on('stop', () => {
process.nextTick(() => {
process.exit()
})
})
22 changes: 11 additions & 11 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
var webpackConfig = require('./tasks/config').webpack
const webpackConfig = require('./tasks/config').webpack

module.exports = function (config) {
var reporters = ['progress']
const reporters = ['progress']

if (process.env.TRAVIS) {
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.')
process.exit(1)
}
// if (process.env.TRAVIS) {
// if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
// console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.')
// process.exit(1)
// }

reporters.push('saucelabs')
}
// reporters.push('saucelabs')
// }

// Browsers to run on Sauce Labs
// Check out https://saucelabs.com/platforms for all browser/OS combos
var customLaunchers = {
const customLaunchers = {
'SL_Chrome': {
base: 'SauceLabs',
platform: 'OS X 10.11',
Expand Down Expand Up @@ -75,7 +75,7 @@ module.exports = function (config) {
logLevel: process.env.DEBUG ? config.LOG_DEBUG : config.LOG_INFO,
autoWatch: false,
customLaunchers: customLaunchers,
browsers: process.env.TRAVIS ? Object.keys(customLaunchers) : ['Chrome'],
browsers: process.env.TRAVIS ? ['Firefox'] /* Object.keys(customLaunchers)*/ : ['Chrome'],
singleRun: false,
concurrency: 2,
browserNoActivityTimeout: 600000
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"babel-loader": "^6.2.0",
"babel-plugin-transform-runtime": "^6.1.18",
"babel-preset-es2015": "^6.0.15",
"babel-runtime": "^5.8.34",
"concurrently": "^1.0.0",
"eslint-config-standard": "^4.4.0",
"eslint-plugin-standard": "^1.3.1",
Expand All @@ -40,6 +41,7 @@
"json-loader": "^0.5.3",
"karma": "^0.13.11",
"karma-chrome-launcher": "^0.2.1",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha": "^0.2.0",
"karma-sauce-launcher": "^0.3.0",
"karma-webpack": "^1.7.0",
Expand All @@ -64,7 +66,7 @@
},
"pre-commit": [
"lint",
"test:node"
"test"
],
"keywords": [
"ipfs"
Expand Down
8 changes: 5 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var pkg = require('../package.json')
'use strict'

exports = module.exports = function getConfig () {
const pkg = require('../package.json')

exports = module.exports = () => {
return {
'api-path': '/api/v0/',
'user-agent': '/node-' + pkg.name + '/' + pkg.version + '/',
'user-agent': `/node-$pkg.name}/${pkg.version}/`,
'host': 'localhost',
'port': '5001'
}
Expand Down
26 changes: 14 additions & 12 deletions src/get-files-stream.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
var File = require('vinyl')
var vinylfs = require('vinyl-fs-browser')
var vmps = require('vinyl-multipart-stream')
var stream = require('stream')
var Merge = require('merge-stream')
'use strict'

const File = require('vinyl')
const vinylfs = require('vinyl-fs-browser')
const vmps = require('vinyl-multipart-stream')
const stream = require('stream')
const Merge = require('merge-stream')

exports = module.exports = getFilesStream

function getFilesStream (files, opts) {
if (!files) return null

// merge all inputs into one stream
var adder = new Merge()
const adder = new Merge()

// single stream for pushing directly
var single = new stream.PassThrough({objectMode: true})
const single = new stream.PassThrough({objectMode: true})
adder.add(single)

for (var i = 0; i < files.length; i++) {
var file = files[i]
for (let i = 0; i < files.length; i++) {
const file = files[i]

if (typeof (file) === 'string') {
var srcOpts = {
const srcOpts = {
buffer: false,
stripBOM: false,
followSymlinks: opts.followSymlinks != null ? opts.followSymlinks : true
Expand Down Expand Up @@ -53,7 +55,7 @@ function vinylFile (file) {
}

// let's try to make a vinyl file?
var f = {cwd: '/', base: '/', path: ''}
const f = {cwd: '/', base: '/', path: ''}
if (file.contents && file.path) {
// set the cwd + base, if there.
f.path = file.path
Expand All @@ -78,7 +80,7 @@ function vinylContentsSafe (c) {
if (typeof (c.pipe) === 'function') {
// hey, looks like a stream. but vinyl won't detect it.
// pipe it to a PassThrough, and use that
var s = new stream.PassThrough()
const s = new stream.PassThrough()
return c.pipe(s)
}

Expand Down
62 changes: 32 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
var multiaddr = require('multiaddr')
var getConfig = require('./config')
var getRequestAPI = require('./request-api')
var Wreck = require('wreck')
'use strict'

const multiaddr = require('multiaddr')
const getConfig = require('./config')
const getRequestAPI = require('./request-api')
const Wreck = require('wreck')

exports = module.exports = IpfsAPI

function IpfsAPI (host_or_multiaddr, port) {
var self = this
var config = getConfig()
const self = this
const config = getConfig()

if (!(self instanceof IpfsAPI)) {
return new IpfsAPI(host_or_multiaddr, port)
}

try {
var maddr = multiaddr(host_or_multiaddr).nodeAddress()
const maddr = multiaddr(host_or_multiaddr).nodeAddress()
config.host = maddr.address
config.port = maddr.port
} catch (e) {
Expand All @@ -25,17 +27,17 @@ function IpfsAPI (host_or_multiaddr, port) {
// autoconfigure in browser
if (!config.host &&
typeof window !== 'undefined') {
var split = window.location.host.split(':')
const split = window.location.host.split(':')
config.host = split[0]
config.port = split[1]
}

var requestAPI = getRequestAPI(config)
const requestAPI = getRequestAPI(config)

// -- Internal

function command (name) {
return function (opts, cb) {
return (opts, cb) => {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
Expand All @@ -45,7 +47,7 @@ function IpfsAPI (host_or_multiaddr, port) {
}

function argCommand (name) {
return function (arg, opts, cb) {
return (arg, opts, cb) => {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
Expand All @@ -58,7 +60,7 @@ function IpfsAPI (host_or_multiaddr, port) {

self.send = requestAPI

self.add = function (files, opts, cb) {
self.add = (files, opts, cb) => {
if (typeof (opts) === 'function' && cb === undefined) {
cb = opts
opts = {}
Expand All @@ -82,17 +84,17 @@ function IpfsAPI (host_or_multiaddr, port) {

self.config = {
get: argCommand('config'),
set: function (key, value, opts, cb) {
set (key, value, opts, cb) {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
}
return requestAPI('config', [key, value], opts, null, cb)
},
show: function (cb) {
show (cb) {
return requestAPI('config/show', null, null, null, true, cb)
},
replace: function (file, cb) {
replace (file, cb) {
return requestAPI('config/replace', null, null, file, cb)
}
}
Expand All @@ -106,15 +108,15 @@ function IpfsAPI (host_or_multiaddr, port) {
self.version = command('version')
self.commands = command('commands')

self.mount = function (ipfs, ipns, cb) {
self.mount = (ipfs, ipns, cb) => {
if (typeof ipfs === 'function') {
cb = ipfs
ipfs = null
} else if (typeof ipns === 'function') {
cb = ipns
ipns = null
}
var opts = {}
const opts = {}
if (ipfs) opts.f = ipfs
if (ipns) opts.n = ipns
return requestAPI('mount', null, opts, null, cb)
Expand All @@ -126,7 +128,7 @@ function IpfsAPI (host_or_multiaddr, port) {

self.block = {
get: argCommand('block/get'),
put: function (file, cb) {
put (file, cb) {
if (Array.isArray(file)) {
return cb(null, new Error('block.put() only accepts 1 file'))
}
Expand All @@ -136,7 +138,7 @@ function IpfsAPI (host_or_multiaddr, port) {

self.object = {
get: argCommand('object/get'),
put: function (file, encoding, cb) {
put (file, encoding, cb) {
if (typeof encoding === 'function') {
return cb(null, new Error("Must specify an object encoding ('json' or 'protobuf')"))
}
Expand All @@ -145,7 +147,7 @@ function IpfsAPI (host_or_multiaddr, port) {
data: argCommand('object/data'),
stat: argCommand('object/stat'),
links: argCommand('object/links'),
patch: function (file, opts, cb) {
patch (file, opts, cb) {
return requestAPI('object/patch', [file].concat(opts), null, null, cb)
}
}
Expand All @@ -155,14 +157,14 @@ function IpfsAPI (host_or_multiaddr, port) {
connect: argCommand('swarm/connect')
}

self.ping = function (id, cb) {
self.ping = (id, cb) => {
return requestAPI('ping', id, { n: 1 }, null, function (err, res) {
if (err) return cb(err, null)
cb(null, res[1])
})
}

self.id = function (id, cb) {
self.id = (id, cb) => {
if (typeof id === 'function') {
cb = id
id = null
Expand All @@ -171,35 +173,35 @@ function IpfsAPI (host_or_multiaddr, port) {
}

self.pin = {
add: function (hash, opts, cb) {
add (hash, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = null
}

requestAPI('pin/add', hash, opts, null, cb)
},
remove: function (hash, opts, cb) {
remove (hash, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = null
}

requestAPI('pin/rm', hash, opts, null, cb)
},
list: function (type, cb) {
list (type, cb) {
if (typeof type === 'function') {
cb = type
type = null
}
var opts = null
let opts = null
if (type) opts = { type: type }
return requestAPI('pin/ls', null, opts, null, cb)
}
}

self.log = {
tail: function (cb) {
tail (cb) {
return requestAPI('log/tail', null, {enc: 'text'}, null, true, cb)
}
}
Expand All @@ -217,13 +219,13 @@ function IpfsAPI (host_or_multiaddr, port) {
self.dht = {
findprovs: argCommand('dht/findprovs'),

get: function (key, opts, cb) {
get (key, opts, cb) {
if (typeof (opts) === 'function' && !cb) {
cb = opts
opts = null
}

return requestAPI('dht/get', key, opts, null, function (err, res) {
return requestAPI('dht/get', key, opts, null, (err, res) => {
if (err) return cb(err)
if (!res) return cb(new Error('empty response'))
if (res.length === 0) return cb(new Error('no value returned for key'))
Expand All @@ -241,7 +243,7 @@ function IpfsAPI (host_or_multiaddr, port) {
})
},

put: function (key, value, opts, cb) {
put (key, value, opts, cb) {
if (typeof (opts) === 'function' && !cb) {
cb = opts
opts = null
Expand Down
Loading