// enable ssb-npm-registry plugin // If this file is changed, the readme of ssb-npm-registry should be updated to have the new blob id, the repo pushed to git-ssb and package published to ssb-npm. var fs = require('fs') var path = require('path') var ssbAppname = process.env.ssb_appname || 'ssb' var ssbPath = process.env.ssb_path || path.join(require('os').homedir(), '.' + ssbAppname) var confPath = path.join(ssbPath, 'config') var confPathTmp = confPath + '~' var confData try { confData = fs.readFileSync(confPath, 'utf8') } catch(e) { if (e.code === 'ENOENT') confData = 'null' else throw e } var conf = JSON.parse(confData) || {} var plugins = conf.plugins || (conf.plugins = {}) if (plugins['ssb-npm-registry']) { console.log('ssb-npm-registry already enabled') process.exit(0) } plugins['ssb-npm-registry'] = true fs.writeFileSync(confPathTmp, JSON.stringify(conf, 0, 2)) fs.renameSync(confPathTmp, confPath) console.log('ssb-npm-registry enabled')