Files: 50a93d0c463cd37de0b35d49fef7daf6e9e287db / enable-plugin.js
816 bytesRaw
1 | // Work around broken plugins.enable RPC method |
2 | |
3 | var fs = require('fs') |
4 | var path = require('path') |
5 | |
6 | var pluginName = require('./package').name |
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 = fs.existsSync(confPath) |
14 | ? fs.readFileSync(confPath, 'utf8') |
15 | : 'null' |
16 | var conf = JSON.parse(confData) || {} |
17 | |
18 | var plugins = conf.plugins || (conf.plugins = {}) |
19 | if (plugins[pluginName]) { |
20 | console.log(pluginName + ' already enabled') |
21 | process.exit(0) |
22 | } |
23 | plugins[pluginName] = true |
24 | |
25 | fs.writeFileSync(confPathTmp, JSON.stringify(conf, 0, 2)) |
26 | fs.renameSync(confPathTmp, confPath) |
27 | console.log(pluginName + ' enabled. Restart ssb-server.') |
28 |
Built with git-ssb-web