@pagebridge/cli
v0.2.0
Published
CLI for PageBridge — sync Google Search Console data, detect content decay, and generate refresh tasks
Downloads
853
Maintainers
Readme
@pagebridge/cli
Command-line interface for PageBridge. Syncs Google Search Console data to your PostgreSQL database, matches URLs to Sanity documents, detects content decay, and generates refresh tasks.
Installation
pnpm add -D @pagebridge/cliOr run from the monorepo:
pnpm build --filter=@pagebridge/cliCommands
pagebridge init
Interactive setup wizard. Walks you through configuring credentials, tests each connection, and writes a .env file with PAGEBRIDGE_-prefixed variables.
pagebridge initOptions:
| Option | Description |
|--------|-------------|
| --skip-db-check | Skip database connection test |
| --skip-sanity-check | Skip Sanity API test |
| --skip-gsc-check | Skip Google Search Console API test |
pagebridge doctor
Diagnose configuration issues. Checks your env file, credentials, database connection, schema, Sanity access, and GSC API access.
pagebridge doctor
pagebridge doctor --verboseLooks for .env.local first, then .env. Loads the file and validates all required variables.
pagebridge sync
Sync Google Search Console data and optionally generate refresh tasks for decaying content.
pagebridge sync --site sc-domain:example.comOptions:
| Option | Description | Default |
|--------|-------------|---------|
| --site <url> | GSC site URL (required) | — |
| --dry-run | Preview changes without writing to Sanity | false |
| --skip-tasks | Only sync data, skip task generation | false |
| --check-index | Check Google index status for pages | false |
| --quiet-period <days> | Days to ignore recently published content | 45 |
| --diagnose | Show detailed diagnostics for unmatched URLs | false |
| --diagnose-url <url> | Diagnose why a specific URL is not matching | — |
| --migrate | Run database migrations before syncing | false |
| --debug | Enable debug logging with timing information | false |
All credentials can also be passed as flags (--db-url, --sanity-project-id, etc.) to override env vars.
Examples:
# First sync — creates tables automatically
pagebridge sync --site sc-domain:example.com --migrate
# Preview what would be synced
pagebridge sync --site sc-domain:example.com --dry-run
# Sync data only, no refresh tasks
pagebridge sync --site sc-domain:example.com --skip-tasks
# Debug why a URL isn't matching
pagebridge sync --site sc-domain:example.com --diagnose-url https://example.com/my-pagepagebridge list-sites
List all Google Search Console properties accessible by the configured service account.
pagebridge list-sitespagebridge diagnose
Show stored diagnostics for unmatched URLs from previous sync runs.
pagebridge diagnose --site sc-domain:example.comEnvironment Variables
Create a .env.local or .env file. PageBridge uses a PAGEBRIDGE_ prefix to avoid conflicts with your project's existing env vars:
# Google Service Account JSON (stringified)
PAGEBRIDGE_GOOGLE_SERVICE_ACCOUNT='{"type":"service_account","project_id":"..."}'
# PostgreSQL connection string
PAGEBRIDGE_DATABASE_URL='postgresql://user:password@localhost:5432/pagebridge'
# Sanity configuration
PAGEBRIDGE_SANITY_PROJECT_ID='your-project-id'
PAGEBRIDGE_SANITY_DATASET='production'
PAGEBRIDGE_SANITY_TOKEN='sk...'
# Your website base URL (used for URL matching)
PAGEBRIDGE_SITE_URL='https://example.com'Unprefixed names (DATABASE_URL, SANITY_TOKEN, etc.) are also supported as a fallback. The PAGEBRIDGE_-prefixed version always takes priority.
Sync Workflow
The sync command performs these steps:
- Validate connections — Tests database, Sanity, and GSC access
- Find or create gscSite — Ensures a Sanity document exists for the site
- Fetch GSC data — Retrieves 90 days of search analytics (skipping last 3 days for data stability)
- Store metrics — Writes page and query metrics to PostgreSQL
- Match URLs — Maps GSC pages to Sanity documents by slug
- Detect decay — Analyzes metrics for position drops, CTR issues, and traffic decline
- Generate tasks — Creates
gscRefreshTaskdocuments for pages showing decay - Write snapshots — Creates
gscSnapshotdocuments in Sanity with metrics and top queries
Dependencies
@pagebridge/core— Sync engine, decay detection, URL matching@pagebridge/db— PostgreSQL schema and queries@sanity/client— Sanity API clientcommander— CLI framework
Development
# Watch mode
pnpm dev --filter=@pagebridge/cli
# Build
pnpm build --filter=@pagebridge/cli
# Type check
pnpm check-types --filter=@pagebridge/cliLicense
MIT
