Files: 6994c2171b937fc5df05405a75e38b91142f6664 / scripts / setup.js
1286 bytesRaw
1 | var homedir = require('os').homedir() |
2 | var path = require('path') |
3 | var fs = require('fs') |
4 | var mkdirp = require('mkdirp') |
5 | |
6 | var appPath = path.join(__dirname, '../host-app.js') |
7 | |
8 | function setup () { |
9 | if (process.platform === 'win32') { |
10 | console.log("This script doesn't work on windows, try npm run setup-win") |
11 | return 1 |
12 | } |
13 | |
14 | if (!fs.existsSync(appPath)) { |
15 | console.log('[ERROR] Application not found at: ', appPath) |
16 | return 1 |
17 | } |
18 | |
19 | var manifest = buildManifest() |
20 | setupMozillaManifest(manifest) |
21 | |
22 | return 0 |
23 | } |
24 | |
25 | function buildManifest () { |
26 | const template = require(path.join(__dirname, '../scuttleshell.template.json')) |
27 | return Object.assign(template, { path: appPath }) |
28 | } |
29 | |
30 | function setupMozillaManifest (manifest) { |
31 | var manifestFolderPath = process.platform === 'darwin' |
32 | ? path.join(homedir, '/Library/Application Support/Mozilla/NativeMessagingHosts') |
33 | : path.join(homedir, '/.mozilla/native-messaging-hosts') |
34 | |
35 | mkdirp.sync(manifestFolderPath) |
36 | |
37 | fs.writeFileSync( |
38 | path.join(manifestFolderPath, 'scuttleshell.json'), |
39 | JSON.stringify(manifest, null, 2) |
40 | ) |
41 | |
42 | console.log('[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check') |
43 | } |
44 | |
45 | module.exports = setup |
46 | |
47 | if (require.main === module) { |
48 | var errorLevel = setup() |
49 | process.exit(errorLevel) |
50 | } |
51 |
Built with git-ssb-web