feat(config): add TypeScript build and config support

This commit is contained in:
2026-04-27 08:53:17 -04:00
parent 2f83fa3117
commit 6b3ec32b3a
12 changed files with 1043 additions and 127 deletions

View File

@@ -20,7 +20,8 @@ If running directly with Node.js, install dependencies and make sure `firefox` a
```bash
npm install
node src/index.js exec https://example.com --js='return document.title'
npm run build
node dist/src/index.js exec https://example.com --js='return document.title'
```
## Glimpse CLI
@@ -31,6 +32,7 @@ glimpse <command> [options]
Common options:
- `--config=<file>` - read config from a custom path instead of `~/.config/glimpse/config.json`
- `--no-headless` - show Firefox instead of running headless
- `--url=<server>` - connect to an existing WebDriver server
- `--timeout=<ms>` - maximum wait time in milliseconds for command waits (default: `10000`)
@@ -173,22 +175,45 @@ Output:
Search using a supported provider and print a JSON array of results. Currently only Kagi is supported.
Kagi requires `--token=<token>` or a `KAGI_TOKEN` environment variable. The token is validated by the Kagi provider and sent to Kagi as the `token` query parameter.
Kagi requires a token from `--token=<token>`, `KAGI_TOKEN`, or the glimpse config file. The token is validated by the Kagi provider and sent to Kagi as the `token` query parameter.
Default config path:
```text
~/.config/glimpse/config.json
```
Example config:
```json
{
"search": {
"provider": "kagi"
},
"providers": {
"kagi": {
"token": "your-kagi-token"
}
}
}
```
Then search without exposing the token in command arguments:
```bash
KAGI_TOKEN=... nix run .#glimpse -- search --provider=kagi "nix flakes selenium webdriver"
nix run .#glimpse -- search "nix flakes selenium webdriver"
```
Local usage:
```bash
KAGI_TOKEN=... ./result/bin/glimpse search "nix flakes selenium webdriver"
./result/bin/glimpse search "nix flakes selenium webdriver"
```
Options:
- `--provider=<provider>` - search provider: `kagi` (default: `kagi`)
- `--token=<token>` - Kagi token (default: `KAGI_TOKEN`)
- `--provider=<provider>` - search provider: `kagi` (default: config or `kagi`)
- `--token=<token>` - Kagi token (default: `KAGI_TOKEN` or config)
- `--no-headless` - show Firefox instead of running headless
- `--url=<server>` - connect to an existing WebDriver server
- `--timeout=<ms>` - wait time for results before returning `[]` (default: `10000`)
@@ -217,7 +242,7 @@ Run the built tool:
```bash
./result/bin/glimpse exec https://example.com --js='return document.title'
KAGI_TOKEN=... ./result/bin/glimpse search "example query"
./result/bin/glimpse search "example query"
```
## Development
@@ -253,16 +278,19 @@ node test/smoke.js snapshot js
Useful local commands:
```bash
node src/index.js snapshot 'data:text/html,<title>Hello</title><h1>Hello</h1>'
node src/index.js exec 'data:text/html,<title>Hello</title>' --js='return document.title'
node src/index.js screenshot 'data:text/html,<title>Hello</title>' --output=/tmp/page.png
node src/index.js reader 'https://example.com/article'
npm run build
node dist/src/index.js snapshot 'data:text/html,<title>Hello</title><h1>Hello</h1>'
node dist/src/index.js exec 'data:text/html,<title>Hello</title>' --js='return document.title'
node dist/src/index.js screenshot 'data:text/html,<title>Hello</title>' --output=/tmp/page.png
node dist/src/index.js reader 'https://example.com/article'
```
## Project Structure
- `src/index.js` - `glimpse` CLI with subcommands, including Firefox Reader View extraction and provider-backed search
- `src/driver.js` - Firefox WebDriver creation and geckodriver resolution
- `src/providers/kagi.js` - reusable Kagi search provider implementation
- `src/index.ts` - `glimpse` CLI with subcommands, including Firefox Reader View extraction and provider-backed search
- `src/config.ts` - home-dir config loading for CLI defaults and provider settings
- `src/driver.ts` - Firefox WebDriver creation and geckodriver resolution
- `src/providers/kagi.ts` - reusable Kagi search provider implementation
- `tsconfig.json` - TypeScript compiler settings; build output goes to `dist/`
- `flake.nix` - Nix dev shell, package, wrappers, and apps
- `KAGI.md` - Kagi-specific notes