git ssb

3+

cel / ssb-npm-registry



Tree: 19411b46dcec24746271ae0a8ee1db6b3e66eaf6

Files: 19411b46dcec24746271ae0a8ee1db6b3e66eaf6 / enable.js

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

Built with git-ssb-web