git ssb

1+

mixmix / scuttle-shell



Commit da7d6a9b7f9afbf0a78cea0f445b681f437457a1

fixing setup

andre alves garzia committed on 7/3/2018, 4:22:55 AM
Parent: 6cc6e67e04f36d9fa92b14e5030d73797a24a90b

Files changed

scripts/setup-win.jschanged
tests/json2msg.jsadded
tests/msg2json.jsadded
tests/test-end.jsonadded
tests/test-start.jsonadded
tests/test.batadded
scripts/setup-win.jsView
@@ -6,44 +6,37 @@
66 var appManifestTemplateFile = path.resolve(".\\scuttleshell.template.json")
77 var appManifestFile = path.resolve(".\\scuttleshell.json")
88
99
10-function setup() {
10 +function setup(cb) {
1111
1212 if (process.platform !== "win32") {
1313 console.log("This script works only on windows, try npm run setup")
14- return 1
14 + cb(1)
1515 }
1616
1717 if (!fs.existsSync(appPath)) {
1818 console.log("[ERROR] Application not found at: ", appPath)
19- return 1
19 + cb(1)
2020 }
2121
2222 if (!fs.existsSync(appManifestTemplateFile)) {
2323 console.log("[ERROR] App manifest not found at: ", appManifestTemplateFile)
24- return 1
24 + cb(1)
2525 }
2626
27- let manifest = JSON.parse(fs.readFileSync(appManifestTemplateFile))
27 + let manifestTemplate = JSON.parse(fs.readFileSync(appManifestTemplateFile))
2828
29- let applicationLauncherPath = manifest.path
29 + manifestTemplate.path = appPath
30 + fs.writeFileSync(appManifestFile, JSON.stringify(manifestTemplate))
3031
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- }
3932
4033 // This now involves writing to the registry, I am a bit scared of that...
4134
4235 var valuesToPut = {
4336 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell': {
4437 'scuttleshell': {
45- value: appManifestTemplateFile,
38 + value: appManifestFile,
4639 type: 'REG_DEFAULT'
4740 }
4841 }
4942 }
@@ -51,21 +44,21 @@
5144 regedit.createKey('HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell', function (a, b) {
5245 regedit.putValue(valuesToPut, function (err) {
5346 if (err) {
5447 console.log("[ERROR] Problem writing to registry.", err)
55- return 1
48 + cb(1)
5649 } else {
5750 console.log("[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check-win")
58- return 0
51 + cb(0)
5952 }
6053 })
6154 })
62- return 0
6355 }
6456
6557 module.exports = setup
6658
6759 if (require.main === module) {
68- var errorLevel = setup()
69- process.exit(errorLevel)
60 + setup((errorLevel) => {
61 + process.exit(errorLevel)
62 + })
7063 }
7164
tests/json2msg.jsView
@@ -1,0 +1,18 @@
1 +#!/usr/bin/env node
2 +
3 +var fs = require('fs');
4 +var readline = require('readline');
5 +
6 +var nativeMessage = require('chrome-native-messaging');
7 +
8 +var output = new nativeMessage.Output();
9 +
10 +readline.createInterface({
11 + input: process.stdin,
12 + output: output,
13 + terminal: false
14 +}).on('line', function(line) {
15 + output.write(JSON.parse(line));
16 +});
17 +
18 +output.pipe(process.stdout);
tests/msg2json.jsView
@@ -1,0 +1,9 @@
1 +#!/usr/bin/env node
2 +
3 +var nativeMessage = require('chrome-native-messaging');
4 +
5 +process.stdin
6 + .pipe(new nativeMessage.Input())
7 + .pipe(new nativeMessage.Debug())
8 + .pipe(process.stdout)
9 +;
tests/test-end.jsonView
@@ -1,0 +1,1 @@
1 +{"cmd": "stop-server"}
tests/test-start.jsonView
@@ -1,0 +1,1 @@
1 +{"cmd": "start-server"}
tests/test.batView
@@ -1,0 +1,6 @@
1 +@echo off
2 +
3 +node json2msg.js < test-start.json | node ../host-app.js | node msg2json.js
4 +REM sbot whoami
5 +REM timeout /t 120
6 +REM node json2msg.js < test-end.json | node bin.js | node msg2json.js

Built with git-ssb-web