git ssb

1+

mixmix / scuttle-shell



Commit 6994c2171b937fc5df05405a75e38b91142f6664

windows: overhaul install scripts

Henry committed on 10/19/2018, 4:59:07 PM
Parent: 80270d887629afdb27e3408113701bdbc3a6ff89

Files changed

scripts/check-configuration-win.jschanged
scripts/install.jschanged
scripts/setup-win.jschanged
scripts/check-configuration-win.jsView
@@ -1,52 +1,49 @@
1-
2-
31 var regedit = require('regedit')
42 var key = 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell'
53 var fs = require("fs")
64
7-function check() {
5 +function check(cb) {
86
97 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"))
129 }
1310
1411 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. `)
1913
2014 let manifestPath = results[key].values[""].value
2115
2216 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)
2618 }
2719
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 + }
2928
30- let manifest = JSON.parse(fs.readFileSync(manifestPath))
31-
32- let applicationLauncherPath = manifest.path
33-
3429 if (!fs.existsSync(applicationLauncherPath)) {
3530 console.log("[ERROR] Launcher not found at declared location", applicationLauncherPath)
36- console.log("\nTry: npm run setup-win\n")
37- process.exit(1)
3831 }
39-
40- console.log("[OK] Configuration appears correct\n[INFO] App located at:", applicationLauncherPath)
41-
42- process.exit(0)
32 +
33 + cb(null, applicationLauncherPath)
4334 })
44-
4535 }
4636
4737
4838 module.exports = check
4939
5040 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.jsView
@@ -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 + })
914 }
1015
11-setup()
12-check()
13-
scripts/setup-win.jsView
@@ -1,5 +1,4 @@
1-
21 var path = require('path')
32 var regedit = require('regedit')
43 var fs = require("fs")
54 var appPath = path.resolve(".\\app.bat")
@@ -9,30 +8,29 @@
98
109 function setup(cb) {
1110
1211 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"))
1513 }
1614
1715 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))
2017 }
2118
2219 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))
2521 }
2622
27- let manifestTemplate = JSON.parse(fs.readFileSync(appManifestTemplateFile))
23 + try {
24 + let manifestTemplate = JSON.parse(fs.readFileSync(appManifestTemplateFile))
2825
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 + }
3131
32-
3332 // This now involves writing to the registry, I am a bit scared of that...
34-
3533 var valuesToPut = {
3634 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell': {
3735 'scuttleshell': {
3836 value: appManifestFile,
@@ -40,25 +38,30 @@
4038 }
4139 }
4240 }
4341
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)
4544 regedit.putValue(valuesToPut, function (err) {
4645 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))
5248 }
49 + console.log("[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check-win")
50 + cb(null)
5351 })
5452 })
5553 }
5654
5755 module.exports = setup
5856
5957 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 + }
6164 process.exit(errorLevel)
6265 })
6366 }
6467

Built with git-ssb-web