git ssb

1+

mixmix / scuttle-shell



Commit ff415cfd94d87c90cfd7d775564a459508a86ea6

refactor

mix irving committed on 6/30/2018, 10:01:37 AM
Parent: 31c197447262cc391a339dfdb59613b351d26fd2

Files changed

.gitignorechanged
scripts/check-configuration.jschanged
scripts/setup.jschanged
server.jschanged mode from 100644 to 100755
scuttleshell.jsondeleted
scuttleshell.template.jsonadded
.gitignoreView
@@ -67,5 +67,4 @@
6767 .yarn-integrity
6868
6969 # dotenv environment variables file
7070 .env
71-
scripts/check-configuration.jsView
@@ -1,45 +1,39 @@
1-
2-
1 +var fs = require('fs')
2 +var path = require('path')
33 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')
87
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')
1311 process.exit(1)
1412 }
1513
1614 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')
1917 process.exit(1)
2018 }
2119
22- console.log("[INFO] App manifest path location:", manifestPath)
20 + console.log('[INFO] App manifest path location:', manifestPath)
2321
24- let manifest = JSON.parse(fs.readFileSync(manifestPath))
22 + var manifest = require(manifestPath)
2523
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')
3127 process.exit(1)
3228 }
3329
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)
3531
3632 process.exit(0)
37-
3833 }
3934
40-
4135 module.exports = check
4236
4337 if (require.main === module) {
4438 var errorLevel = check()
45-}
39 +}
scripts/setup.jsView
@@ -2,50 +2,45 @@
22 var path = require('path')
33 var fs = require('fs')
44 var mkdirp = require('mkdirp')
55
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-
116 var appPath = path.join(__dirname, '../host-app.js')
12-var localManifestFile = path.join(__dirname, '../scuttleshell.json')
137
14-function setup() {
15- if (process.platform == "win32") {
8 +function setup () {
9 + if (process.platform === 'win32') {
1610 console.log("This script doesn't work on windows, try npm run setup-win")
1711 return 1
1812 }
1913
2014 if (!fs.existsSync(appPath)) {
21- console.log("[ERROR] Application not found at: ", appPath)
15 + console.log('[ERROR] Application not found at: ', appPath)
2216 return 1
2317 }
2418
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)
2921
30- let manifest = JSON.parse(fs.readFileSync(localManifestFile))
22 + return 0
23 +}
3124
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 +}
3329
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')
4234
4335 mkdirp.sync(manifestFolderPath)
44- fs.writeFileSync(manifestPath, JSON.stringify(manifest))
4536
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')
4843 }
4944
5045 module.exports = setup
5146
server.jsView
@@ -1,8 +1,8 @@
11 #! /usr/bin/env node
22
3-const http = require('http')
4-const serve = require('ecstatic')
3 +// const http = require('http')
4 +// const serve = require('ecstatic')
55 const fs = require('fs')
66 const path = require('path')
77 const ssbKeys = require('ssb-keys')
88 const minimist = require('minimist')
scuttleshell.jsonView
@@ -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.jsonView
@@ -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