46 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-05-28 11:48:27 -04:00
const shelljs = require('shelljs');
const ProcessWrapper = require('../../process/processWrapper');
const constants = require('../../constants');
2018-05-28 11:51:38 -04:00
let ipfsProcess; // eslint-disable-line no-unused-vars
2018-05-28 11:48:27 -04:00
class IPFSProcess extends ProcessWrapper {
constructor(_options) {
super();
this.startIPFSDaemon();
}
startIPFSDaemon() {
2018-05-28 11:51:38 -04:00
const self = this;
const child = shelljs.exec('ipfs daemon', {silent: true}, (err, _stdout, _stderr) => {
2018-05-28 11:48:27 -04:00
if (err) {
console.error(err);
process.exit(1);
}
process.exit();
});
2018-05-28 11:51:38 -04:00
let lastMessage;
child.stdout.on('data', (data) => {
if (!self.readyCalled && data.indexOf('Daemon is ready') > -1) {
self.readyCalled = true;
self.send({result: constants.storage.initiated});
}
lastMessage = data;
console.log('IPFS: ' + data);
});
child.on('exit', (code) => {
if (code) {
console.error('IPFS exited with error code ' + code);
console.error(lastMessage);
}
});
2018-05-28 11:48:27 -04:00
}
}
process.on('message', (msg) => {
if (msg.action === constants.storage.init) {
2018-05-28 11:48:27 -04:00
ipfsProcess = new IPFSProcess(msg.options);
}
});