diff --git a/src/daemon-ctrl.js b/src/daemon-ctrl.js index 4460431c..6afa653e 100644 --- a/src/daemon-ctrl.js +++ b/src/daemon-ctrl.js @@ -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 } /** @@ -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 @@ -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`)) diff --git a/src/index.js b/src/index.js index 154acaa4..10d2898f 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,7 @@ class DaemonFactory { return new remote.RemoteController(options) } - return new LocalController(options.type) + return new LocalController(options) } static createServer (port) { diff --git a/test/daemon.js b/test/daemon.js index 0ddac6ad..bfc79301 100644 --- a/test/daemon.js +++ b/test/daemon.js @@ -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')() }) })