diff --git a/README.md b/README.md index 39e1753..42e85ca 100644 --- a/README.md +++ b/README.md @@ -18,58 +18,16 @@ No browser JavaScript! Oasis has strict security rules that prevent any JavaScript from running in your browser, which helps us make Oasis accessible and easy to improve. +## Example + +```sh +oasis +``` + ![Screenshot of Oasis](./docs/screenshot.png) -## Usage - -Start Oasis from a command-line interface with the `oasis` command. - -```console -$ oasis --help -Usage: oasis [options] - -Options: - --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. This can be - changed on the 'settings' page while Oasis is running. - [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] - -c --config Show current default configuration [boolean] [default: false] -``` - -## Configuration - -The above options can be permanently set with a configuration file found in a -standard folder for configuration, depending on your operating system: - -- Linux: `$XDG_CONFIG_HOME/oasis/default.json`. - Usually this is `/home//.config/oasis/default.json` - -- Windows `%APPDATA%\oasis\default.json`. -- Mac OS, `/Users//Library/Preferences/oasis/default.json` - -The configuration file can override any or all of the command-line _defaults_. -Here is an example customizing the port number and the "open" settings: - -```json -{ - "open": false, - "port": 19192 -} -``` - -### Configuration Semantics - -Which value is given is decided like this: - -1. If an argument is given on the command-line, use that value. -2. Otherwise, use the value from the configuration file if present. -3. If neither command-line nor configuration file are given, use the built-in default value. +Use `oasis --help` to get configuration options. You can change the default +values with a custom [configuration](./docs/configuring.md). ## Installation @@ -86,7 +44,8 @@ For faster updates and less stability, install from GitHub and upgrade often. npm -g install fraction/oasis ``` -Want more? Check out [`install.md`](https://github.com/fraction/oasis/blob/master/docs/install.md). +Check out [`install.md`](https://github.com/fraction/oasis/blob/master/docs/install.md) +for more information. ## Resources diff --git a/docs/configuring.md b/docs/configuring.md new file mode 100644 index 0000000..8751702 --- /dev/null +++ b/docs/configuring.md @@ -0,0 +1,28 @@ +# Configuring + +The default options can be permanently set with a configuration file found in a +standard folder for configuration, depending on your operating system: + +- Linux: `$XDG_CONFIG_HOME/oasis/default.json`. + Usually this is `/home//.config/oasis/default.json` + +- Windows `%APPDATA%\oasis\default.json`. +- Mac OS, `/Users//Library/Preferences/oasis/default.json` + +The configuration file can override any or all of the command-line _defaults_. +Here is an example customizing the port number and the "open" settings: + +```json +{ + "open": false, + "port": 19192 +} +``` + +## Semantics + +Which value is given is decided like this: + +1. If an argument is given on the command-line, use that value. +2. Otherwise, use the value from the configuration file if present. +3. If neither command-line nor configuration file are given, use the built-in default value. diff --git a/src/index.js b/src/index.js index 567cbf9..b8d42c1 100755 --- a/src/index.js +++ b/src/index.js @@ -2,28 +2,18 @@ "use strict"; -// Koa application to provide HTTP interface. - -const fs = require("fs"); -const envPaths = require("env-paths"); +// Minimum required to get config const path = require("path"); -const nodeHttp = require("http"); -const debug = require("debug")("oasis"); +const envPaths = require("env-paths"); +const cli = require("./cli"); +const fs = require("fs"); +const defaultConfig = {}; const defaultConfigFile = path.join( envPaths("oasis", { suffix: "" }).config, "/default.json" ); - -const log = (...args) => { - const isDebugEnabled = debug.enabled; - debug.enabled = true; - debug(...args); - debug.enabled = isDebugEnabled; -}; - -const defaultConfig = {}; -var haveConfig; +let haveConfig; try { const defaultConfigOverride = fs.readFileSync(defaultConfigFile, "utf8"); @@ -40,8 +30,21 @@ try { } } -const cli = require("./cli"); const config = cli(defaultConfig, defaultConfigFile); +if (config.debug) { + process.env.DEBUG = "oasis,oasis:*"; +} + +const nodeHttp = require("http"); +const debug = require("debug")("oasis"); + +const log = (...args) => { + const isDebugEnabled = debug.enabled; + debug.enabled = true; + debug(...args); + debug.enabled = isDebugEnabled; +}; + delete config._; delete config.$0; @@ -49,26 +52,17 @@ const { host } = config; const { port } = config; const url = `http://${host}:${port}`; -console.log(); if (haveConfig) { - console.log(`Configuration read defaults from ${defaultConfigFile}`); + log(`Configuration read defaults from ${defaultConfigFile}`); } else { - console.log( - `No configuration file found at ${defaultConfigFile}. ` + - "Using built-in default values." + log( + `No configuration file found at ${defaultConfigFile}, using built-in default values.` ); } -console.log("Current configuration:"); -console.log(); -console.log(JSON.stringify(config, null, 2)); -console.log(); -console.log(`Note: You can save the above to ${defaultConfigFile} to make \ -these settings the default. See the readme for details.`); -console.log(); -if (config.debug) { - process.env.DEBUG = "oasis,oasis:*"; -} +debug("Current configuration: %O", config); +debug(`You can save the above to ${defaultConfigFile} to make \ +these settings the default. See the readme for details.`); const oasisCheckPath = "/.well-known/oasis";