server.jsView |
---|
7 | 7 … | const notifier = require('node-notifier') |
8 | 8 … | const SysTray = require('systray').default |
9 | 9 … | let tray = {} |
10 | 10 … | |
11 | | -function start(appname) { |
| 11 … | +function start(appname, customPluginPaths) { |
12 | 12 … | |
13 | 13 … | let argv = process.argv.slice(2) |
14 | 14 … | let i = argv.indexOf('--') |
15 | 15 … | let conf = argv.slice(i + 1) |
46 | 46 … | .use(require('ssb-search')) |
47 | 47 … | .use(require('ssb-query')) |
48 | 48 … | .use(require('ssb-ws')) |
49 | 49 … | |
| 50 … | + |
| 51 … | + |
| 52 … | + let appManifestFile = path.resolve('scuttleshell.json') |
| 53 … | + if (fs.existsSync(appManifestFile)) { |
| 54 … | + let manifest = JSON.parse(fs.readFileSync(manifestPath)) |
| 55 … | + if (manifest.hasOwnProperty('plugins') && Array.isArray(manifest.plugins)) { |
| 56 … | + console.log("loading custom plugins: ", manifest.plugins.join(", ")) |
| 57 … | + manifest.plugins.forEach(plugin => createSbot.use(require(plugin))) |
| 58 … | + } |
| 59 … | + } |
| 60 … | + |
| 61 … | + if (Array.isArray(customPluginPaths)) { |
| 62 … | + console.log("loading custom plugins: ", customPluginPaths.join(", ")) |
| 63 … | + customPluginPaths.forEach(plugin => createSbot.use(require(plugin))) |
| 64 … | + } |
| 65 … | + |
50 | 66 … | |
51 | 67 … | |
52 | 68 … | config.keys = keys |
53 | 69 … | const server = createSbot(config) |
102 | 118 … | function stop() { |
103 | 119 … | tray.kill() |
104 | 120 … | } |
105 | 121 … | |
106 | | -module.exports = { start, stop } |
| 122 … | +const getConfig = () => { |
| 123 … | + try { |
| 124 … | + let secret = fs.readFileSync(pathToSecret, "utf8") |
| 125 … | + let keys = JSON.parse(secret.replace(/#[^\n]*/g, '')) |
| 126 … | + let manifest = JSON.parse(fs.readFileSync(path.join(config.path, 'manifest.json'))) |
| 127 … | + let remote = "ws://localhost:8989~shs:" + keys.id.substring(1, keys.id.indexOf('.')) |
| 128 … | + return { type: 'config', keys: keys, manifest: manifest, remote: remote, secret: secret } |
| 129 … | + } catch (n) { |
| 130 … | + return { type: 'error', msg: n.message } |
| 131 … | + } |
| 132 … | +} |
107 | 133 … | |
| 134 … | +module.exports = { start, stop, getConfig } |
| 135 … | + |
108 | 136 … | if (require.main === module) { |
109 | 137 … | var errorLevel = start() |
110 | 138 … | } |