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