Files: 5a0419f6c2662e881e7cb6c76d64e1b5b1f55de7 / scripts / setup-win.js
1631 bytesRaw
1 | |
2 | var path = require('path') |
3 | var regedit = require('regedit') |
4 | var fs = require("fs") |
5 | var appPath = path.resolve(".\\app.bat") |
6 | var appManifestTemplateFile = path.resolve(".\\scuttleshell.template.json") |
7 | var appManifestFile = path.resolve(".\\scuttleshell.json") |
8 | |
9 | |
10 | function setup(cb) { |
11 | |
12 | if (process.platform !== "win32") { |
13 | console.log("This script works only on windows, try npm run setup") |
14 | cb(1) |
15 | } |
16 | |
17 | if (!fs.existsSync(appPath)) { |
18 | console.log("[ERROR] Application not found at: ", appPath) |
19 | cb(1) |
20 | } |
21 | |
22 | if (!fs.existsSync(appManifestTemplateFile)) { |
23 | console.log("[ERROR] App manifest not found at: ", appManifestTemplateFile) |
24 | cb(1) |
25 | } |
26 | |
27 | let manifestTemplate = JSON.parse(fs.readFileSync(appManifestTemplateFile)) |
28 | |
29 | manifestTemplate.path = appPath |
30 | fs.writeFileSync(appManifestFile, JSON.stringify(manifestTemplate)) |
31 | |
32 | |
33 | // This now involves writing to the registry, I am a bit scared of that... |
34 | |
35 | var valuesToPut = { |
36 | 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell': { |
37 | 'scuttleshell': { |
38 | value: appManifestFile, |
39 | type: 'REG_DEFAULT' |
40 | } |
41 | } |
42 | } |
43 | |
44 | regedit.createKey('HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell', function (a, b) { |
45 | regedit.putValue(valuesToPut, function (err) { |
46 | if (err) { |
47 | console.log("[ERROR] Problem writing to registry.", err) |
48 | cb(1) |
49 | } else { |
50 | console.log("[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check-win") |
51 | cb(0) |
52 | } |
53 | }) |
54 | }) |
55 | } |
56 | |
57 | module.exports = setup |
58 | |
59 | if (require.main === module) { |
60 | setup((errorLevel) => { |
61 | process.exit(errorLevel) |
62 | }) |
63 | } |
64 | |
65 |
Built with git-ssb-web