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