Merge pull request #543 from embark-framework/feature/run-ipfs-init
Run `ipfs init` for the case when user has installed ipfs, but not initialised it.
This commit is contained in:
commit
f9e62b9f49
|
@ -33,23 +33,34 @@ class IPFSProcess extends ProcessWrapper {
|
|||
});
|
||||
}
|
||||
|
||||
startIPFSDaemon() {
|
||||
_bindChildEvents(childProcess){
|
||||
const self = this;
|
||||
|
||||
// spawn the daemon (muhaha)
|
||||
this.child = child_process.spawn(this.command, ['daemon']);
|
||||
|
||||
this.child.on('error', (err) => {
|
||||
childProcess.on('error', (err) => {
|
||||
err = err.toString();
|
||||
console.error('IPFS error: ', err);
|
||||
});
|
||||
this.child.stderr.on('data', (data) => {
|
||||
|
||||
childProcess.stderr.on('data', (data) => {
|
||||
data = data.toString();
|
||||
console.log(`IPFS error: ${data}`);
|
||||
// `ipfs daemon called`, but `ipfs init` had not been run yet
|
||||
if(!self.initCalled && data.indexOf('no IPFS repo found') > -1) {
|
||||
self.initCalled = true;
|
||||
let ipfsInitChild = child_process.spawn(this.command, ['init']);
|
||||
self._bindChildEvents(ipfsInitChild);
|
||||
}
|
||||
});
|
||||
this.child.stdout.on('data', (data) => {
|
||||
|
||||
childProcess.stdout.on('data', (data) => {
|
||||
data = data.toString();
|
||||
if (!self.readyCalled && data.indexOf('Daemon is ready') > -1) {
|
||||
|
||||
// ipfs init just run, and we have a successful result
|
||||
// re-run `ipfs daemon`
|
||||
if(self.initCalled && !self.readyCalled && data.indexOf('peer identity:') > -1) {
|
||||
self.startIPFSDaemon();
|
||||
}
|
||||
else if (!self.readyCalled && data.indexOf('Daemon is ready') > -1) {
|
||||
self.readyCalled = true;
|
||||
|
||||
// update IPFS cors before spawning a daemon (muhaha)
|
||||
|
@ -90,13 +101,20 @@ class IPFSProcess extends ProcessWrapper {
|
|||
}
|
||||
console.log('IPFS: ' + data);
|
||||
});
|
||||
this.child.on('exit', (code) => {
|
||||
childProcess.on('exit', (code) => {
|
||||
if (code) {
|
||||
console.error('IPFS exited with error code ' + code);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
startIPFSDaemon() {
|
||||
const self = this;
|
||||
|
||||
// spawn the daemon (muhaha)
|
||||
this.child = child_process.spawn(this.command, ['daemon']);
|
||||
|
||||
self._bindChildEvents(this.child);
|
||||
}
|
||||
|
||||
kill() {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue