git ssb

3+

cel / ssb-npm-registry



Tree: 5eeba2c58721e0dda8b9b829f4b3feb22e7a9a26

Files: 5eeba2c58721e0dda8b9b829f4b3feb22e7a9a26 / enable.js

977 bytesRaw
1// enable ssb-npm-registry plugin
2
3// 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.
4
5var fs = require('fs')
6var path = require('path')
7
8var ssbAppname = process.env.ssb_appname || 'ssb'
9var ssbPath = process.env.ssb_path ||
10 path.join(require('os').homedir(), '.' + ssbAppname)
11var confPath = path.join(ssbPath, 'config')
12var confPathTmp = confPath + '~'
13var confData
14try {
15 confData = fs.readFileSync(confPath, 'utf8')
16} catch(e) {
17 if (e.code === 'ENOENT') confData = 'null'
18 else throw e
19}
20var conf = JSON.parse(confData) || {}
21
22var plugins = conf.plugins || (conf.plugins = {})
23if (plugins['ssb-npm-registry']) {
24 console.log('ssb-npm-registry already enabled')
25 process.exit(0)
26}
27plugins['ssb-npm-registry'] = true
28
29fs.writeFileSync(confPathTmp, JSON.stringify(conf, 0, 2))
30fs.renameSync(confPathTmp, confPath)
31console.log('ssb-npm-registry enabled')
32

Built with git-ssb-web