Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

version #43

Merged
merged 6 commits into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"lint": "standard",
"coverage": "istanbul cover --print both -- _mocha tests/*-test.js",
"test": "mocha tests/*-test.js"
"test": "mocha tests/test-*/test-*.js"
},
"pre-commit": [
"lint"
Expand All @@ -29,20 +29,18 @@
"homepage": "https://github.com/ipfs/js-ipfs#readme",
"devDependencies": {
"chai": "^3.4.1",
"ipfsd-ctl": "^0.6.1",
"istanbul": "^0.4.1",
"mocha": "^2.3.4",
"ncp": "^2.0.0",
"nexpect": "^0.5.0",
"pre-commit": "^1.1.2",
"rimraf": "^2.4.4",
"standard": "^5.3.1"
},
"dependencies": {
"hapi": "^11.1.4",
"ipfs-api": "^2.7.0",
"ipfs-repo": "^0.1.0",
"peer-id": "^0.4.0",
"peer-info": "^0.4.0",
"debug": "^2.2.0",
"hapi": "^12.0.0",
"ipfs-repo": "^0.2.2",
"ronin": "^0.3.11"
}
}
6 changes: 4 additions & 2 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#! /usr/bin/env node

var ronin = require('ronin')
'use strict'

var cli = ronin(__dirname)
const ronin = require('ronin')

const cli = ronin(__dirname)

cli.run()

Expand Down
6 changes: 4 additions & 2 deletions src/cli/commands/add.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
6 changes: 4 additions & 2 deletions src/cli/commands/commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
17 changes: 14 additions & 3 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command
const httpAPI = require('../../http-api')
const debug = require('debug')
let log = debug('cli:daemon')
log.error = debug('cli:damon:error')

module.exports = Command.extend({
desc: '',
desc: 'Start a long-running daemon process',

run: function (name) {}
run: name => {
httpAPI.start((err) => {
if (err) { return log.error(err) }
log('daemon started')
})
}
})
6 changes: 4 additions & 2 deletions src/cli/commands/dns.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
4 changes: 2 additions & 2 deletions src/cli/commands/get.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Command = require('ronin').Command
const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
17 changes: 9 additions & 8 deletions src/cli/commands/id.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
var Command = require('ronin').Command
var IPFS = require('../../ipfs-core')
const Command = require('ronin').Command
const IPFS = require('../../ipfs-core')
const debug = require('debug')
let log = debug('cli:id')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be const

log.error = debug('cli:id:error')

module.exports = Command.extend({
desc: 'Shows IPFS Node ID info',
Expand All @@ -11,12 +14,10 @@ module.exports = Command.extend({
}
},

run: function (name) {
var node = new IPFS()
node.id(function (err, id) {
if (err) {
return console.error(err)
}
run: name => {
let node = new IPFS()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why let?

node.id((err, id) => {
if (err) { return log.error(err) }
console.log(id)
})
}
Expand Down
11 changes: 4 additions & 7 deletions src/cli/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
var Command = require('ronin').Command
// var help = require('../src/help-menu.js')
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: 'Initialize ipfs local configuration',

// help: help,

options: {
bits: {
type: 'number',
Expand All @@ -25,7 +24,5 @@ module.exports = Command.extend({
}
},

run: function (name) {
console.log('NA - https://github.com/ipfs/js-ipfs/tree/jsipfs#getting-jsipfs-ready')
}
run: name => {}
})
6 changes: 4 additions & 2 deletions src/cli/commands/ls.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
6 changes: 4 additions & 2 deletions src/cli/commands/mount.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
6 changes: 4 additions & 2 deletions src/cli/commands/ping.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
6 changes: 4 additions & 2 deletions src/cli/commands/refs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
6 changes: 4 additions & 2 deletions src/cli/commands/resolve.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
6 changes: 4 additions & 2 deletions src/cli/commands/update.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Command = require('ronin').Command
'use strict'

const Command = require('ronin').Command

module.exports = Command.extend({
desc: '',

run: function (name) {}
run: name => {}
})
18 changes: 11 additions & 7 deletions src/cli/commands/version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
var Command = require('ronin').Command
var IPFS = require('../../ipfs-core')
'use strict'

const Command = require('ronin').Command
const IPFS = require('../../ipfs-core')
const debug = require('debug')
let log = debug('cli:version')
log.error = debug('cli:version:error')

module.exports = Command.extend({
desc: 'Shows IPFS version information',
Expand All @@ -20,12 +25,11 @@ module.exports = Command.extend({
}
},

run: function (name) {
run: (name) => {
var node = new IPFS()
node.version(function (err, version) {
if (err) {
return console.error(err)
}
node.version((err, version) => {
if (err) { return log.error(err) }

console.log(version)
})
}
Expand Down
40 changes: 40 additions & 0 deletions src/http-api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict'

const Hapi = require('hapi')
const IPFS = require('../ipfs-core')
const debug = require('debug')
let log = debug('api')
log.error = debug('api:error')

exports = module.exports

exports.start = callback => {
// start IPFS and exports.ipfs = new IPFS()

exports.ipfs = new IPFS()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this looks like asking for trouble when the export is only available after start was called, also what will happen to module caching plus calling start twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the .ipfs is to be used by the http-api resources, which are only loaded after start is called (from routes), so there is no conflict. Did I get your question right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of, but why not just pass these resources through explicitly, this could easily break, or be miss used by someone not understanding these exports


var server = exports.server = new Hapi.Server({
connections: {
routes: {
cors: true
}
}
})

server.connection({
port: 9000
})

// load routes
require('./routes/version.js')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be much cleaner:

server.route(require('./routes/version.js')

// version.js
var resources = require('./../resources')

module.exports = {
  method: 'GET',
  path: '/api/v0/version',
  handler: resources.version.get
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that "much" cleaner? If there was more than one route on that file I would have to go and

server.route(require('./routes/version.js').routeA)
server.route(require('./routes/version.js').routeB)
// etc

Meaning that I have to alter the route file and index.js, the way I have, I only have to open and modify one file. Also, having the server object available means I always have server methods at my hand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not about that, could also change it to

require('./routes/version.js').forEach(server.route.bind(server)

// version.js
module.exports = [
  // my routes
]

The main issue I have your current implementation is that it introduces a circular dependency from this file to the routes files.

If you want to have the server object be available make it like this:

require('./routes/version.js')(server)

// version.js
server.route({...})

that way the circular dependency is removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could DI the server obj (and the IPFS core object), but I kind of like making available by knowing where to pick it from other then move it around. I've been doing this for a while, if it becomes complicated over time, I will reconsider your suggestion :)


server.start(err => {
if (err) { return callback(err) }
log('server started: ' + server.info.uri)
callback()
})
}

exports.stop = () => {

}
1 change: 1 addition & 0 deletions src/http-api/resources/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.version = require('./version')
14 changes: 14 additions & 0 deletions src/http-api/resources/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

const ipfs = require('./../index.js').ipfs
const boom = require('boom')

exports = module.exports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because although they point to the same thing initially, if not binded, once exports changes it will stop pointing to module.exports and therefore none of the functions that gets exported by exports. will be exposed

more info and examples:
https://blog.tableflip.io/the-difference-between-module-exports-and-exports/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm but you don't use module.exports

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not in this case, but it is kind of the same why I always add {} to if statements, keeping the code uniform, avoid having to debug someday cause 'I forgot one' or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay


exports.get = (request, reply) => {
ipfs.version((err, version) => {
if (err) { return reply(boom.badRequest(err)) }
return reply(version)
})
}

10 changes: 10 additions & 0 deletions src/http-api/routes/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const server = require('./../index.js').server
const resources = require('./../resources')

server.route({
method: 'GET',
path: '/api/v0/version',
handler: resources.version.get
})
4 changes: 3 additions & 1 deletion src/ipfs-core/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var os = require('os')
'use strict'

const os = require('os')

exports = module.exports

Expand Down
Loading