Skip to content
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
35 changes: 34 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
node_modules
**/node_modules/
**/*.log
test/repo-tests*

# Logs
logs
*.log

coverage

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

build

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

lib
dist
32 changes: 32 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
**/node_modules/
**/*.log
test/repo-tests*

# Logs
logs
*.log

coverage

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

build

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
25 changes: 23 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
sudo: false
language: node_js
node_js:
- "4"
- "5"
- 4
- 5
- stable

# Make sure we have new NPM.
before_install:
- npm install -g npm

script:
- npm run lint
- npm test
- npm run coverage

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

addons:
firefox: 'latest'
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
ipfsd-ctl
=========

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Dependency Status](https://david-dm.org/ipfs/js-ipfsd-ctl.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfsd-ctl)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-ipfsd-ctl/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipfsd-ctl?branch=master)
[![Travis CI](https://travis-ci.org/ipfs/js-ipfsd-ctl.svg?branch=master)](https://travis-ci.org/ipfs/js-ipfsd-ctl)
[![Circle CI](https://circleci.com/gh/ipfs/js-ipfsd-ctl.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfsd-ctl)

[![Dependency Status](https://david-dm.org/ipfs/js-ipfsd-ctl.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfsd-ctl) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)

> Control an ipfs node daemon using Node.js

Expand Down
2 changes: 2 additions & 0 deletions examples/id.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var ipfsd = require('../index.js')

ipfsd.disposableApi(function (err, ipfs) {
Expand Down
2 changes: 2 additions & 0 deletions examples/local.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var ipfsd = require('../index.js')

// opens an api connection to local running ipfs node
Expand Down
27 changes: 16 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
"name": "ipfsd-ctl",
"version": "0.13.0",
"description": "simple controls for an ipfs node",
"main": "index.js",
"main": "lib/index.js",
"jsxnext:main": "src/index.js",
"scripts": {
"test": "node_modules/.bin/mocha test",
"lint": "standard"
"lint": "aegir-lint",
"coverage": "aegir-coverage",
"test": "aegir-test --env node",
"build": "aegir-build --env node",
"release": "aegir-release --env node",
"release:minor": "aegir-release --type minor --env node",
"release:major": "aegir-release --type major --env node",
"coverage-publish": "aegir-coverage publish"
},
"engines": {
"node": ">=4.2.2"
Expand All @@ -26,20 +33,18 @@
],
"license": "MIT",
"dependencies": {
"ipfs-api": "^3.0.0",
"go-ipfs-dep": "0.4.1",
"multiaddr": "^1.1.1",
"ipfs-api": "^4.1.0",
"multiaddr": "^2.0.0",
"rimraf": "^2.4.5",
"run-series": "^1.1.4",
"shutdown": "^0.2.4",
"subcomandante": "^1.0.5",
"async": "^1.5.0"
"subcomandante": "^1.0.5"
},
"devDependencies": {
"estraverse": "^4.1.1",
"aegir": "^3.0.4",
"mkdirp": "^0.5.1",
"mocha": "^2.3.4",
"pre-commit": "^1.1.2",
"standard": "^6.0.8"
"pre-commit": "^1.1.2"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const os = require('os')
const join = require('path').join

const Node = require('./lib/node')
const Node = require('./node')

function tempDir () {
return join(os.tmpdir(), `ipfs_${(Math.random() + '').substr(2)}`)
return join(os.tmpdir(), `ipfs_${String(Math.random()).substr(2)}`)
}

module.exports = {
Expand Down
28 changes: 13 additions & 15 deletions lib/node.js → src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const fs = require('fs')
const run = require('subcomandante')
const async = require('async')
const series = require('run-series')
const ipfs = require('ipfs-api')
const multiaddr = require('multiaddr')
const rimraf = require('rimraf')
Expand Down Expand Up @@ -30,17 +30,15 @@ function findIpfsExecutable () {
}

function configureNode (node, conf, done) {
if (Object.keys(conf).length > 0) {
async.forEachOfSeries(conf, (value, key, cb) => {
const env = {env: node.env}

run(node.exec, ['config', key, '--json', JSON.stringify(value)], env)
.on('error', cb)
.on('end', cb)
}, done)
} else {
done()
}
const keys = Object.keys(conf)
series(keys.map((key) => (cb) => {
const value = conf[key]
const env = {env: node.env}

run(node.exec, ['config', key, '--json', JSON.stringify(value)], env)
.on('error', cb)
.on('end', cb)
}), done)
}

// Consistent error handling
Expand Down Expand Up @@ -126,17 +124,17 @@ module.exports = class Node {

this.subprocess = run(this.exec, ['daemon'], {env: this.env})
.on('error', (err) => {
if ((err + '').match('daemon is running')) {
if (String(err).match('daemon is running')) {
// we're good
done(null, ipfs(conf.Addresses.API))
} else if ((err + '').match('non-zero exit code')) {
} else if (String(err).match('non-zero exit code')) {
// ignore when kill -9'd
} else {
done(err)
}
})
.on('data', (data) => {
const match = (data + '').trim().match(/API server listening on (.*)/)
const match = String(data).trim().match(/API server listening on (.*)/)
if (match) {
this.apiAddr = match[1]
const addr = multiaddr(this.apiAddr).nodeAddress()
Expand Down
7 changes: 0 additions & 7 deletions test/.eslintrc

This file was deleted.

24 changes: 11 additions & 13 deletions test/test.js → test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */
'use strict'

const ipfsd = require('../index.js')
const ipfsd = require('../src')
const assert = require('assert')
const ipfsApi = require('ipfs-api')
const run = require('subcomandante')
Expand All @@ -9,9 +10,6 @@ const rimraf = require('rimraf')
const mkdirp = require('mkdirp')
const path = require('path')

// this comment is used by mocha, do not delete
/*global describe, before, it*/

describe('ipfs executable path', function () {
this.timeout(2000)
let Node
Expand All @@ -22,12 +20,12 @@ describe('ipfs executable path', function () {

mkdirp(npm3Path, (err) => {
if (err) {
console.log(err)
throw err
}

fs.writeFileSync(path.join(npm3Path, 'ipfs'))
delete require.cache[require.resolve('../lib/node.js')]
Node = require('../lib/node.js')
delete require.cache[require.resolve('../src/node.js')]
Node = require('../src/node.js')
var node = new Node()
assert.equal(node.exec, '/tmp/ipfsd-ctl-test/node_modules/go-ipfs-dep/go-ipfs/ipfs')
rimraf('/tmp/ipfsd-ctl-test', done)
Expand All @@ -40,12 +38,12 @@ describe('ipfs executable path', function () {

mkdirp(npm2Path, (err) => {
if (err) {
console.log(err)
throw err
}

fs.writeFileSync(path.join(npm2Path, 'ipfs'))
delete require.cache[require.resolve('../lib/node.js')]
Node = require('../lib/node.js')
delete require.cache[require.resolve('../src/node.js')]
Node = require('../src/node.js')
var node = new Node()
assert.equal(node.exec, '/tmp/ipfsd-ctl-test/node_modules/ipfsd-ctl/node_modules/go-ipfs-dep/go-ipfs/ipfs')
rimraf('/tmp/ipfsd-ctl-test', done)
Expand Down Expand Up @@ -359,14 +357,14 @@ describe('ipfs-api version', function () {
})
})

// NOTE: if you change ../lib/node.js, the hash will need to be changed
// NOTE: if you change ../src/, the hash will need to be changed
it('uses the correct ipfs-api', (done) => {
ipfs.add(path.join(__dirname, '../lib'), { recursive: true }, (err, res) => {
ipfs.add(path.join(__dirname, '../src'), { recursive: true }, (err, res) => {
if (err) throw err

const added = res[res.length - 1]
assert(added)
assert.equal(added.Hash, 'QmdZt3Uiv3HZkHPsjGyWbrX1kMiRjst8cxQYsUjMqbXc7G')
assert.equal(added.Hash, 'Qmafmh1Cw3H1bwdYpaaj5AbCW4LkYyUWaM7Nykpn5NZoYL')
done()
})
})
Expand Down