Skip to content
Closed
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@
"lodash.clone": "^4.5.0",
"lodash.defaults": "^4.2.0",
"lodash.defaultsdeep": "^4.6.1",
"merge-options": "^1.0.1",
"multiaddr": "^6.1.0",
"safe-json-stringify": "^1.2.0",
"superagent": "^5.0.5"
"superagent": "^5.0.5",
"temp-write": "^4.0.0"
},
"devDependencies": {
"aegir": "^20.0.0",
Expand All @@ -87,7 +89,7 @@
"dirty-chai": "^2.0.1",
"go-ipfs-dep": "~0.4.22",
"husky": "^3.0.4",
"ipfs": "~0.37.1",
"ipfs": "github:ipfs/js-ipfs#feat/daemon-start-init",
"is-running": "^2.1.0",
"lint-staged": "^9.2.5",
"proxyquire": "^2.1.3",
Expand Down
3 changes: 2 additions & 1 deletion src/defaults/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"type": "go",
"disposable": true,
"start": true,
"init": true
"init": true,
"args": []
}
12 changes: 12 additions & 0 deletions src/factory-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const tmpDir = require('./utils/tmp-dir')
const Daemon = require('./ipfsd-daemon')
const defaultConfig = require('./defaults/config.json')
const defaultOptions = require('./defaults/options.json')
const { configFile } = require('./utils/config-file')

/** @ignore @typedef {import("./index").SpawnOptions} SpawnOptions */

Expand Down Expand Up @@ -112,6 +113,17 @@ class FactoryDaemon {
options.initOptions = defaultsDeep({}, this.options.initOptions, options.initOptions)

const node = new Daemon(options)
if (options.init && options.start && options.type === 'js') {
const configPath = await configFile(options.type, options.config)
const args = options.args.concat([
'--init',
'--init-config', configPath,
'--init-profile', options.initOptions.profile
])
await node.start(args)

return node
}

if (options.init) {
await node.init(options.initOptions)
Expand Down
14 changes: 11 additions & 3 deletions src/ipfsd-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const tmpDir = require('./utils/tmp-dir')
const findIpfsExecutable = require('./utils/find-ipfs-executable')
const setConfigValue = require('./utils/set-config-value')
const run = require('./utils/run')
const { configFile } = require('./utils/config-file')

// amount of ms to wait before sigkill
const GRACE_PERIOD = 10500
Expand Down Expand Up @@ -180,12 +181,19 @@ class Daemon {
}
}

if (this.opts.type === 'js') {
const configPath = await configFile('js', this.opts.config)
args.push(`--init-config`, configPath)
}

await run(this, args, { env: this.env })
.catch(translateError)

const conf = await this.getConfig()
if (this.opts.type === 'go') {
const conf = await this.getConfig()

await this.replaceConfig(defaults({}, this.opts.config, conf))
await this.replaceConfig(defaults({}, this.opts.config, conf))
}

this.clean = false
this.initialized = true
Expand Down Expand Up @@ -215,7 +223,7 @@ class Daemon {
* @return {Promise}
*/
start (flags = []) {
const args = ['daemon'].concat(flags || [])
const args = ['daemon'].concat(flags)

const setApiAddr = (addr) => {
this._apiAddr = multiaddr(addr)
Expand Down
11 changes: 11 additions & 0 deletions src/utils/config-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'
const tempWrite = require('temp-write')
const merge = require('merge-options')

function configFile (type, config) {
return tempWrite(JSON.stringify(merge({}, config)), 'config.json')
}

module.exports = {
configFile
}