diff --git a/docs/customization.md b/docs/customization.md index 27994b5..653078f 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -110,6 +110,14 @@ keys: ``` For alerts customization, see [full explanation with examples](alerts.md). +- **`"browserOptions"`**\ + Options to specify which browser to open, including arguments, as specified + [here](https://www.npmjs.com/package/open#app). Examples: + + ```json + "browserOptions": { "name": "firefox" } + "browserOptions": { "name": "chromium", "arguments": ["--incognito"] } + ``` ### Reloading config diff --git a/loader.mjs b/loader.mjs new file mode 100644 index 0000000..9e43805 --- /dev/null +++ b/loader.mjs @@ -0,0 +1,4 @@ +import { register } from 'node:module'; +import { pathToFileURL } from 'node:url'; + +register('ts-node/esm', pathToFileURL('./')); diff --git a/package.json b/package.json index 74d8775..474d95d 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "repository": "https://github.com/jannis-baum/vivify.git", "author": "Jannis Baum", "scripts": { - "dev": "VIV_TIMEOUT=0 VIV_PORT=3000 NODE_ENV=development nodemon --ignore tests/rendering/symlinks --exec node --loader ts-node/esm src/app.ts", - "viv": "VIV_PORT=3000 node --loader ts-node/esm src/app.ts", + "dev": "VIV_TIMEOUT=0 VIV_PORT=3000 NODE_ENV=development nodemon --ignore tests/rendering/symlinks --exec node --import ./loader.mjs src/app.ts", + "viv": "VIV_PORT=3000 node --import ./loader.mjs src/app.ts", "lint": "eslint src static", "lint-markdown": "markdownlint-cli2 --config .github/.markdownlint-cli2.yaml", - "test": "node --loader ts-node/esm --test tests/unit/cli.ts tests/unit/alerts.ts", + "test": "node --import ./loader.mjs --test tests/unit/cli.ts tests/unit/alerts.ts", "deduplicate": "yarn-deduplicate" }, "type": "module", diff --git a/src/cli.ts b/src/cli.ts index 1d19e4b..8276f99 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -2,7 +2,7 @@ import axios from 'axios'; import { existsSync } from 'fs'; import open from 'open'; import { resolve as presolve } from 'path'; -import { address } from './config.js'; +import { address, config } from './config.js'; import { pathToURL, preferredPath } from './utils/path.js'; // exported for unit test @@ -20,7 +20,7 @@ export const getPathAndLine = ( }; export const openFileAt = async (path: string) => - open(`${address}${pathToURL(preferredPath(path))}`); + open(`${address}${pathToURL(preferredPath(path))}`, { app: config.browserOptions }); const openTarget = async (target: string) => { const { path, line } = getPathAndLine(target); diff --git a/src/config.ts b/src/config.ts index a3f14c5..de56439 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import { globSync } from 'glob'; +import { App } from 'open'; import { homedir } from 'os'; import path from 'path'; @@ -26,6 +27,7 @@ type Config = { titles?: Record; fallbackIcon?: string; }; + browserOptions?: App | App[]; }; // fills in values from config file config that are not present