Skip to content

Commit

Permalink
feat: allow to set the executable for DaemonController
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Jan 8, 2018
1 parent 85557c9 commit c60dece
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
20 changes: 17 additions & 3 deletions src/daemon-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,21 @@ const defaultConfig = {
* @namespace DaemonController
*/
class DaemonController {
constructor (type) {
this.type = type || 'go'
/**
* Create a DaemonController instance
*
* @param {Object} opts
* - `type` string - one of 'go', 'js' or 'proc',
* the type of the daemon to spawn
* - `exec` string (optional) - the path of the daemon
* executable or IPFS class in the case of `proc`
*
* @return {*}
*/
constructor (opts) {
opts = opts || {}
this.type = opts.type || 'go'
this.exec = opts.exec
}

/**
Expand Down Expand Up @@ -84,7 +97,7 @@ class DaemonController {
options.init = (typeof options.init !== 'undefined' ? options.init : true)
if (!options.disposable) {
const nonDisposableConfig = clone(defaultConfig)
delete nonDisposableConfig['Addresses']
delete nonDisposableConfig.Addresses

options.init = false
options.start = false
Expand All @@ -99,6 +112,7 @@ class DaemonController {

let node
options.type = this.type
options.exec = options.exec || this.exec
if (this.type === 'proc') {
if (typeof options.exec !== 'function') {
return callback(new Error(`'type' proc requires 'exec' to be a coderef`))
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DaemonFactory {
return new remote.RemoteController(options)
}

return new LocalController(options.type)
return new LocalController(options)
}

static createServer (port) {
Expand Down
8 changes: 1 addition & 7 deletions test/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ describe('ipfsd-ctl', () => {
api(df, 'go')()
})

describe('Js daemon', () => {
const df = DaemonFactory.create({ type: 'js' })
daemon(df, 'js')()
api(df, 'js')()
})

describe('In-process daemon', () => {
daemon(DaemonFactory.create({ remote: false, type: 'proc' }), 'proc', IPFS)()
daemon(DaemonFactory.create({ remote: false, type: 'proc', exec: IPFS }), 'proc')()
})
})

0 comments on commit c60dece

Please sign in to comment.