Commit 6994c2171b937fc5df05405a75e38b91142f6664
windows: overhaul install scripts
Henry committed on 10/19/2018, 4:59:07 PMParent: 80270d887629afdb27e3408113701bdbc3a6ff89
Files changed
scripts/check-configuration-win.js | changed |
scripts/install.js | changed |
scripts/setup-win.js | changed |
scripts/check-configuration-win.js | ||
---|---|---|
@@ -1,52 +1,49 @@ | ||
1 | - | |
2 | - | |
3 | 1 … | var regedit = require('regedit') |
4 | 2 … | var key = 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell' |
5 | 3 … | var fs = require("fs") |
6 | 4 … | |
7 | -function check() { | |
5 … | +function check(cb) { | |
8 | 6 … | |
9 | 7 … | if (process.platform !== "win32") { |
10 | - console.log("This script works only on windows") | |
11 | - process.exit(1) | |
8 … | + return cb(new Error("This script works only on windows")) | |
12 | 9 … | } |
13 | 10 … | |
14 | 11 … | regedit.list(key, (err, results) => { |
15 | - if (err) { | |
16 | - console.log(`[ERROR] Registry key: ${key} doesn't exist\n\nTry: npm run setup-win\n`) | |
17 | - process.exit(1) | |
18 | - } | |
12 … | + if (err) return cb(new Error(`Registry key: ${key} doesn't exist. `) | |
19 | 13 … | |
20 | 14 … | let manifestPath = results[key].values[""].value |
21 | 15 … | |
22 | 16 … | if (!fs.existsSync(manifestPath)) { |
23 | - console.log("[ERROR] App manifest not found at declared location", manifestPath) | |
24 | - console.log("\nTry: npm run setup-win\n") | |
25 | - process.exit(1) | |
17 … | + return cb(new Error("App manifest not found at declared location:" + manifestPath) | |
26 | 18 … | } |
27 | 19 … | |
28 | - console.log("[INFO] App manifest path location:", manifestPath) | |
20 … | + let applicationLauncherPath | |
21 … | + try { | |
22 … | + console.log("[INFO] App manifest path location:", manifestPath) | |
23 … | + let manifest = JSON.parse(fs.readFileSync(manifestPath)) | |
24 … | + applicationLauncherPath = manifest.path | |
25 … | + } catch(e) { | |
26 … | + return cb(e) | |
27 … | + } | |
29 | 28 … | |
30 | - let manifest = JSON.parse(fs.readFileSync(manifestPath)) | |
31 | - | |
32 | - let applicationLauncherPath = manifest.path | |
33 | - | |
34 | 29 … | if (!fs.existsSync(applicationLauncherPath)) { |
35 | 30 … | console.log("[ERROR] Launcher not found at declared location", applicationLauncherPath) |
36 | - console.log("\nTry: npm run setup-win\n") | |
37 | - process.exit(1) | |
38 | 31 … | } |
39 | - | |
40 | - console.log("[OK] Configuration appears correct\n[INFO] App located at:", applicationLauncherPath) | |
41 | - | |
42 | - process.exit(0) | |
32 … | + | |
33 … | + cb(null, applicationLauncherPath) | |
43 | 34 … | }) |
44 | - | |
45 | 35 … | } |
46 | 36 … | |
47 | 37 … | |
48 | 38 … | module.exports = check |
49 | 39 … | |
50 | 40 … | if (require.main === module) { |
51 | - var errorLevel = check() | |
52 | -} | |
41 … | + check(function(err, launchPath) { | |
42 … | + if (err) { | |
43 … | + console.error(err) | |
44 … | + console.log("\nTry: npm run setup-win\n") | |
45 … | + return | |
46 … | + } | |
47 … | + console.log("[OK] Configuration appears correct\n[INFO] App located at:", launchPath) | |
48 … | + }) | |
49 … | +} |
scripts/install.js | ||
---|---|---|
@@ -1,13 +1,15 @@ | ||
1 | -if (process.platform === "win32") { | |
2 | - // do windows setup | |
3 | - var setup = require("./setup-win") | |
4 | - var check = require("./check-configuration-win") | |
5 | -} else { | |
6 | - // do linux/mac setup | |
7 | - var setup = require("./setup") | |
8 | - var check = require("./check-configuration") | |
1 … | +var suffix = '' | |
2 … | +if (process.platform === "win32") suffix = '-win' | |
3 … | + | |
4 … | +var setup = require("./setup"+suffix) | |
5 … | +var check = require("./check-configuration"+suffix) | |
6 … | + | |
7 … | + | |
8 … | +let steps = [setup, check] | |
9 … | + | |
10 … | +for (const s of steps) { | |
11 … | + s((err) => { | |
12 … | + if (err) throw err | |
13 … | + }) | |
9 | 14 … | } |
10 | 15 … | |
11 | -setup() | |
12 | -check() | |
13 | - |
scripts/setup-win.js | |||
---|---|---|---|
@@ -1,5 +1,4 @@ | |||
1 | - | ||
2 | 1 … | var path = require('path') | |
3 | 2 … | var regedit = require('regedit') | |
4 | 3 … | var fs = require("fs") | |
5 | 4 … | var appPath = path.resolve(".\\app.bat") | |
@@ -9,30 +8,29 @@ | |||
9 | 8 … | ||
10 | 9 … | function setup(cb) { | |
11 | 10 … | ||
12 | 11 … | if (process.platform !== "win32") { | |
13 | - console.log("This script works only on windows, try npm run setup") | ||
14 | - cb(1) | ||
12 … | + return cb(new Error("This script works only on windows, try npm run setup")) | ||
15 | 13 … | } | |
16 | 14 … | ||
17 | 15 … | if (!fs.existsSync(appPath)) { | |
18 | - console.log("[ERROR] Application not found at: ", appPath) | ||
19 | - cb(1) | ||
16 … | + return cb(new Error("Application not found at: " + appPath)) | ||
20 | 17 … | } | |
21 | 18 … | ||
22 | 19 … | if (!fs.existsSync(appManifestTemplateFile)) { | |
23 | - console.log("[ERROR] App manifest not found at: ", appManifestTemplateFile) | ||
24 | - cb(1) | ||
20 … | + return cb(new Error("App manifest not found at: " + appManifestTemplateFile)) | ||
25 | 21 … | } | |
26 | 22 … | ||
27 | - let manifestTemplate = JSON.parse(fs.readFileSync(appManifestTemplateFile)) | ||
23 … | + try { | ||
24 … | + let manifestTemplate = JSON.parse(fs.readFileSync(appManifestTemplateFile)) | ||
28 | 25 … | ||
29 | - manifestTemplate.path = appPath | ||
30 | - fs.writeFileSync(appManifestFile, JSON.stringify(manifestTemplate)) | ||
26 … | + manifestTemplate.path = appPath | ||
27 … | + fs.writeFileSync(appManifestFile, JSON.stringify(manifestTemplate)) | ||
28 … | + } catch(e) { | ||
29 … | + return cb(e) | ||
30 … | + } | ||
31 | 31 … | ||
32 | - | ||
33 | 32 … | // This now involves writing to the registry, I am a bit scared of that... | |
34 | - | ||
35 | 33 … | var valuesToPut = { | |
36 | 34 … | 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell': { | |
37 | 35 … | 'scuttleshell': { | |
38 | 36 … | value: appManifestFile, | |
@@ -40,25 +38,30 @@ | |||
40 | 38 … | } | |
41 | 39 … | } | |
42 | 40 … | } | |
43 | 41 … | ||
44 | - regedit.createKey('HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell', function (a, b) { | ||
42 … | + regedit.createKey('HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell', function (err) { | ||
43 … | + if (err) return cb(err) | ||
45 | 44 … | regedit.putValue(valuesToPut, function (err) { | |
46 | 45 … | 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) | ||
46 … | + console.error(err) | ||
47 … | + return cb(new Error("[ERROR] Problem writing to registry. "+err.message)) | ||
52 | 48 … | } | |
49 … | + console.log("[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check-win") | ||
50 … | + cb(null) | ||
53 | 51 … | }) | |
54 | 52 … | }) | |
55 | 53 … | } | |
56 | 54 … | ||
57 | 55 … | module.exports = setup | |
58 | 56 … | ||
59 | 57 … | if (require.main === module) { | |
60 | - setup((errorLevel) => { | ||
58 … | + setup((err) => { | ||
59 … | + var exitLevel = 0 | ||
60 … | + if (err) { | ||
61 … | + console.error(err) | ||
62 … | + exitLevel = 1 | ||
63 … | + } | ||
61 | 64 … | process.exit(errorLevel) | |
62 | 65 … | }) | |
63 | 66 … | } | |
64 | 67 … |
Built with git-ssb-web