Commit ff415cfd94d87c90cfd7d775564a459508a86ea6
refactor
mix irving committed on 6/30/2018, 10:01:37 AMParent: 31c197447262cc391a339dfdb59613b351d26fd2
Files changed
.gitignore | changed |
scripts/check-configuration.js | changed |
scripts/setup.js | changed |
server.js | changed mode from 100644 to 100755 |
scuttleshell.json | deleted |
scuttleshell.template.json | added |
.gitignore | ||
---|---|---|
@@ -67,5 +67,4 @@ | ||
67 | 67 … | .yarn-integrity |
68 | 68 … | |
69 | 69 … | # dotenv environment variables file |
70 | 70 … | .env |
71 | - |
scripts/check-configuration.js | ||
---|---|---|
@@ -1,45 +1,39 @@ | ||
1 | - | |
2 | - | |
1 … | +var fs = require('fs') | |
2 … | +var path = require('path') | |
3 | 3 … | var homedir = require('os').homedir() |
4 | -var macPath = homedir + "/Library/Application Support/Mozilla/NativeMessagingHosts/scuttleshell.json" | |
5 | -var linuxPath = homedir + "/.mozilla/native-messaging-hosts/scuttleshell.json" | |
6 | -var manifestPath = process.platform === "darwin" ? macPath : linuxPath | |
7 | -var fs = require("fs") | |
4 … | +var manifestPath = process.platform === 'darwin' | |
5 … | + ? path.join(homedir, '/Library/Application Support/Mozilla/NativeMessagingHosts/scuttleshell.json') | |
6 … | + : path.join(homedir, '/.mozilla/native-messaging-hosts/scuttleshell.json') | |
8 | 7 … | |
9 | -function check() { | |
10 | - | |
11 | - if (process.platform === "win32") { | |
12 | - console.log("This script does not work on windows") | |
8 … | +function check () { | |
9 … | + if (process.platform === 'win32') { | |
10 … | + console.log('This script does not work on windows') | |
13 | 11 … | process.exit(1) |
14 | 12 … | } |
15 | 13 … | |
16 | 14 … | if (!fs.existsSync(manifestPath)) { |
17 | - console.log("[ERROR] App manifest not found at declared location", manifestPath) | |
18 | - console.log("\nTry: npm run setup\n") | |
15 … | + console.log('[ERROR] App manifest not found at declared location', manifestPath) | |
16 … | + console.log('\nTry: npm run setup\n') | |
19 | 17 … | process.exit(1) |
20 | 18 … | } |
21 | 19 … | |
22 | - console.log("[INFO] App manifest path location:", manifestPath) | |
20 … | + console.log('[INFO] App manifest path location:', manifestPath) | |
23 | 21 … | |
24 | - let manifest = JSON.parse(fs.readFileSync(manifestPath)) | |
22 … | + var manifest = require(manifestPath) | |
25 | 23 … | |
26 | - let applicationLauncherPath = manifest.path | |
27 | - | |
28 | - if (!fs.existsSync(applicationLauncherPath)) { | |
29 | - console.log("[ERROR] Launcher not found at declared location", applicationLauncherPath) | |
30 | - console.log("\nTry: npm run setup\n") | |
24 … | + if (!fs.existsSync(manifest.path)) { | |
25 … | + console.log('[ERROR] Launcher not found at declared location', manifest.path) | |
26 … | + console.log('\nTry: npm run setup\n') | |
31 | 27 … | process.exit(1) |
32 | 28 … | } |
33 | 29 … | |
34 | - console.log("[OK] Configuration appears correct\n[INFO] App located at:", applicationLauncherPath) | |
30 … | + console.log('[OK] Configuration appears correct\n[INFO] App located at:', manifest.path) | |
35 | 31 … | |
36 | 32 … | process.exit(0) |
37 | - | |
38 | 33 … | } |
39 | 34 … | |
40 | - | |
41 | 35 … | module.exports = check |
42 | 36 … | |
43 | 37 … | if (require.main === module) { |
44 | 38 … | var errorLevel = check() |
45 | -} | |
39 … | +} |
scripts/setup.js | ||
---|---|---|
@@ -2,50 +2,45 @@ | ||
2 | 2 … | var path = require('path') |
3 | 3 … | var fs = require('fs') |
4 | 4 … | var mkdirp = require('mkdirp') |
5 | 5 … | |
6 | -var manifestFolderPath = process.platform === 'darwin' | |
7 | - ? path.join(homedir, '/Library/Application Support/Mozilla/NativeMessagingHosts') | |
8 | - : path.join(homedir, '/.mozilla/native-messaging-hosts') | |
9 | -var manifestPath = path.join(manifestFolderPath, 'scuttleshell.json') | |
10 | - | |
11 | 6 … | var appPath = path.join(__dirname, '../host-app.js') |
12 | -var localManifestFile = path.join(__dirname, '../scuttleshell.json') | |
13 | 7 … | |
14 | -function setup() { | |
15 | - if (process.platform == "win32") { | |
8 … | +function setup () { | |
9 … | + if (process.platform === 'win32') { | |
16 | 10 … | console.log("This script doesn't work on windows, try npm run setup-win") |
17 | 11 … | return 1 |
18 | 12 … | } |
19 | 13 … | |
20 | 14 … | if (!fs.existsSync(appPath)) { |
21 | - console.log("[ERROR] Application not found at: ", appPath) | |
15 … | + console.log('[ERROR] Application not found at: ', appPath) | |
22 | 16 … | return 1 |
23 | 17 … | } |
24 | 18 … | |
25 | - if (!fs.existsSync(localManifestFile)) { | |
26 | - console.log("[ERROR] Local copy of app manifest not found at: ", localManifestFile) | |
27 | - return 1 | |
28 | - } | |
19 … | + var manifest = buildManifest() | |
20 … | + setupMozillaManifest(manifest) | |
29 | 21 … | |
30 | - let manifest = JSON.parse(fs.readFileSync(localManifestFile)) | |
22 … | + return 0 | |
23 … | +} | |
31 | 24 … | |
32 | - let applicationLauncherPath = manifest.path | |
25 … | +function buildManifest () { | |
26 … | + const template = require(path.join(__dirname, '../scuttleshell.template.json')) | |
27 … | + return Object.assign(template, { path: appPath }) | |
28 … | +} | |
33 | 29 … | |
34 | - if (!fs.existsSync(applicationLauncherPath)) { | |
35 | - console.log("[ERROR] App not found at declared location", applicationLauncherPath) | |
36 | - console.log("FIXING...") | |
37 | - manifest.path = appPath | |
38 | - fs.writeFileSync(localManifestFile, JSON.stringify(manifest, null, 2)) | |
39 | - } else { | |
40 | - console.log("[OK] Application found at the correct location", applicationLauncherPath) | |
41 | - } | |
30 … | +function setupMozillaManifest (manifest) { | |
31 … | + var manifestFolderPath = process.platform === 'darwin' | |
32 … | + ? path.join(homedir, '/Library/Application Support/Mozilla/NativeMessagingHosts') | |
33 … | + : path.join(homedir, '/.mozilla/native-messaging-hosts') | |
42 | 34 … | |
43 | 35 … | mkdirp.sync(manifestFolderPath) |
44 | - fs.writeFileSync(manifestPath, JSON.stringify(manifest)) | |
45 | 36 … | |
46 | - console.log("[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check") | |
47 | - return 0 | |
37 … | + fs.writeFileSync( | |
38 … | + path.join(manifestFolderPath, 'scuttleshell.json'), | |
39 … | + JSON.stringify(manifest, null, 2) | |
40 … | + ) | |
41 … | + | |
42 … | + console.log('[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check') | |
48 | 43 … | } |
49 | 44 … | |
50 | 45 … | module.exports = setup |
51 | 46 … |
server.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 … | #! /usr/bin/env node |
2 | 2 … | |
3 | -const http = require('http') | |
4 | -const serve = require('ecstatic') | |
3 … | +// const http = require('http') | |
4 … | +// const serve = require('ecstatic') | |
5 | 5 … | const fs = require('fs') |
6 | 6 … | const path = require('path') |
7 | 7 … | const ssbKeys = require('ssb-keys') |
8 | 8 … | const minimist = require('minimist') |
scuttleshell.json | ||
---|---|---|
@@ -1,12 +1,0 @@ | ||
1 | -{ | |
2 | - "name": "scuttleshell", | |
3 | - "description": "Native app companion to sbot webextensions", | |
4 | - "path": "/home/mix/projects/SSBC/scuttle-shell/host-app.js", | |
5 | - "type": "stdio", | |
6 | - "allowed_extensions": [ | |
7 | - "share_on_scuttlebutt@andregarzia.com", | |
8 | - "ssb_protocol_handler@andregarzia.com", | |
9 | - "sbot_test@andregarzia.com", | |
10 | - "patchfox@andregarzia.com" | |
11 | - ] | |
12 | -} |
scuttleshell.template.json | ||
---|---|---|
@@ -1,0 +1,12 @@ | ||
1 … | +{ | |
2 … | + "name": "scuttleshell", | |
3 … | + "description": "Native app companion to sbot webextensions", | |
4 … | + "path": "TO BE DETERMINED", | |
5 … | + "type": "stdio", | |
6 … | + "allowed_extensions": [ | |
7 … | + "share_on_scuttlebutt@andregarzia.com", | |
8 … | + "ssb_protocol_handler@andregarzia.com", | |
9 … | + "sbot_test@andregarzia.com", | |
10 … | + "patchfox@andregarzia.com" | |
11 … | + ] | |
12 … | +} |
Built with git-ssb-web