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