mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-04 19:33:33 +00:00
Run ipfs init
for the case when user has installed ipfs, but not initialised it.
Runs `ipfs daemon` first, reads stdout for message regarding ipfs not initialised, then runs `ipfs init`, then re-runs `ipfs daemon`.
This commit is contained in:
parent
7706e276bf
commit
bb4fdbe369
@ -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() {
|
||||
|
376
package-lock.json
generated
376
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user