diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..fb56239 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,4 @@ +**What's the problem you want to solved?** + +**Is there a solution you'd like to recommend?** + diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md deleted file mode 100644 index f8516a4..0000000 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: "🐞 Bug report" -about: Report a problem with this software -title: '' -labels: '' -assignees: '' - ---- - -**What version of this package are you using?** - -**What operating system, Node.js, and npm version?** - -**What happened?** - -**What did you expect to happen?** - -**Are you willing to submit a pull request to fix this bug?** diff --git a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md deleted file mode 100644 index f79d822..0000000 --- a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: "⭐️ Feature request" -about: Request a new feature to be added -title: '' -labels: '' -assignees: '' - ---- - -**What version of this package are you using?** - -**What problem do you want to solve?** - -**What do you think is the correct solution to this problem?** - -**Are you willing to submit a pull request to implement this change?** diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 0cfc272..e0d58eb 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,4 @@ -**What is the purpose of this pull request?** +**What's the problem you solved?** -**What changes did you make? (brief overview)** +**What solution are you recommending?** -**Is there anything you'd like reviewers to focus on?** diff --git a/README.md b/README.md index 78afc0f..cd12a1c 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,19 @@ some extra tools for debugging, _not_ to support all known message types. ```console $ oasis --help + Usage: oasis [options] Options: - --help Show help [boolean] - --version Show version number [boolean] - --open Automatically open app in web browser [boolean] [default: true] - --host Hostname for web app to listen on[string] [default: "localhost"] - --port Port for web app to listen on [number] [default: 3000] - --debug Use verbose output for debugging [boolean] [default: false] + --version Show version number [boolean] + -h, --help Show help [boolean] + --open Automatically open app in web browser. Use --no-open to disable. + [boolean] [default: true] + --offline Don't try to connect to scuttlebutt peers or pubs + [boolean] [default: false] + --host Hostname for web app to listen on [string] [default: "localhost"] + --port Port for web app to listen on [number] [default: 3000] + --debug Use verbose output for debugging [boolean] [default: false] ``` ## Installation diff --git a/index.js b/index.js new file mode 100755 index 0000000..99fa51e --- /dev/null +++ b/index.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +'use strict' + +const yargs = require('yargs') +const fs = require('fs').promises +const path = require('path') + +const config = yargs + .env('OASIS') + .help('h') + .alias('h', 'help') + .usage('Usage: $0 [options]') + .options('open', { + describe: 'Automatically open app in web browser. Use --no-open to disable.', + default: true, + type: 'boolean' + }) + .options('offline', { + describe: "Don't try to connect to scuttlebutt peers or pubs", + default: false, + type: 'boolean' + }) + .options('host', { + describe: 'Hostname for web app to listen on', + default: 'localhost', + type: 'string' + }) + .options('port', { + describe: 'Port for web app to listen on', + default: 3000, + type: 'number' + }) + .options('debug', { + describe: 'Use verbose output for debugging', + default: false, + type: 'boolean' + }) + .argv + +// This hides arguments from other upstream modules who might parse them. +// +// Unfortunately some modules think that our CLI options are meant for them, +// and since there's no way to disable that behavior (!) we have to hide them +// manually by setting the args property to an empty array. +process.argv = [] + +if (config.debug) { + process.env.DEBUG = 'oasis,oasis:*' +} + +// Awful hack to get the offline config setting deep into src/pages/models/lib/server.js +process.env.OASIS_OFFLINE = '' + config.offline + +const app = require('./src/app') + +const start = async () => { + const filePath = path.join(__dirname, 'README.md') + config.readme = await fs.readFile(filePath, 'utf8') + app(config) +} + +start() diff --git a/src/cli.js b/src/cli.js index 50241cc..b16e797 100644 --- a/src/cli.js +++ b/src/cli.js @@ -6,12 +6,19 @@ module.exports = () => yargs .scriptName('oasis') .env('OASIS') + .help('h') + .alias('h', 'help') .usage('Usage: $0 [options]') .options('open', { - describe: 'Automatically open app in web browser', + describe: 'Automatically open app in web browser. Use --no-open to disable.', default: true, type: 'boolean' }) + .options('offline', { + describe: "Don't try to connect to scuttlebutt peers or pubs", + default: false, + type: 'boolean' + }) .options('host', { describe: 'Hostname for web app to listen on', default: 'localhost', diff --git a/src/index.js b/src/index.js index aa17192..cdd8941 100755 --- a/src/index.js +++ b/src/index.js @@ -38,7 +38,7 @@ const ssb = require('./ssb') // Create "cooler"-style interface from SSB connection. // This handle is passed to the models for their convenience. -const cooler = ssb() +const cooler = ssb({ offline: config.offline }) const { about, @@ -509,8 +509,10 @@ http({ host, port, routes }) const uri = `http://${host}:${port}/` +const isDebugEnabled = debug.enabled debug.enabled = true debug(`Listening on ${uri}`) +debug.enabled = isDebugEnabled if (config.open === true) { open(uri) diff --git a/src/ssb.js b/src/ssb.js index 542a317..1893142 100644 --- a/src/ssb.js +++ b/src/ssb.js @@ -5,13 +5,20 @@ // native support for Promises in the MuxRPC module and auto-generated manifest // files in the SSB-Client module. -const debug = require('debug')('oasis') const ssbClient = require('ssb-client') const ssbConfig = require('ssb-config') const flotilla = require('@fraction/flotilla') +const debug = require('debug')('oasis') const server = flotilla(ssbConfig) +const log = (...args) => { + const isDebugEnabled = debug.enabled + debug.enabled = true + debug(...args) + debug.enabled = isDebugEnabled +} + const rawConnect = () => new Promise((resolve, reject) => { ssbClient({ manifest: { @@ -53,25 +60,23 @@ const rawConnect = () => new Promise((resolve, reject) => { }) }) -debug.enabled = true - let handle -const createConnection = () => { +const createConnection = (config) => { handle = new Promise((resolve) => { rawConnect().then((ssb) => { - debug('Using pre-existing Scuttlebutt server instead of starting one') + log('Using pre-existing Scuttlebutt server instead of starting one') resolve(ssb) }).catch(() => { - debug('Initial connection attempt failed') - debug('Starting Scuttlebutt server') - server({ ws: { http: false } }) + log('Initial connection attempt failed') + log('Starting Scuttlebutt server') + server(config) const connectOrRetry = () => { rawConnect().then((ssb) => { - debug('Retrying connection to own server') + log('Retrying connection to own server') resolve(ssb) }).catch((e) => { - debug(e) + log(e) connectOrRetry() }) } @@ -83,8 +88,22 @@ const createConnection = () => { return handle } -module.exports = () => { - createConnection() +module.exports = ({ offline }) => { + if (offline) { + log('Offline mode activated - not connecting to scuttlebutt peers or pubs') + log('WARNING: offline mode cannot control the behavior of pre-existing servers') + } + + const config = { + conn: { + autostart: !offline + }, + ws: { + http: false + } + } + + createConnection(config) return { connect () { // This has interesting behavior that may be unexpected.