Scripts Guide
Date: 2026-01-217
Status: ✅ Active
Overview of npm scripts and utility scripts for Lantern development, deployment, and maintenance. CustomAll scripts live in scripts/ and are documented here instead of a module-level README.
Quick Reference
Most Common Commands
| Command | Description |
|---|---|
npm run dev | Start development server |
npm run build | Production build |
npm run preview | Preview production build locally |
npm test | Run tests in watch mode |
npm run validate | Full validation (tests, lint, format, audit) |
npm run lint:fix | Auto-fix linting issues |
npm run format | Format code with Prettier |
npm run storybook | Start Storybook dev server |
Core Development
App Development
npm run dev # Start Vite dev server (auto-generates version.json)
npm run build # Production build (auto-generates version.json)
npm run build:app # Same as build, explicit version generation
npm run preview # Preview production build locallyAdmin Portal (Workspace)
npm run admin:dev # Start admin portal dev server
npm run admin:build # Build admin portal for production
npm run admin:preview # Preview admin portal buildDiscord Bot (Workspace)
npm start # Start Discord bot (runs in discord-bot workspace)Testing
Unit & Integration Tests
npm test # Run Vitest in watch mode
npm run test:coverage # Run tests with coverage reportWorkflow Tests
npm run test:workflows # Run workflow tests in watch mode
npm run test:workflows:run # Run workflow tests once
npm run test:workflows:real # Run with real API calls (costs money!)
npm run test:workflows:validate # Validate triage config consistency
npm run test:workflows:issue-extraction # Test issue extraction shell scriptNote: test:workflows:real requires RUN_REAL_API_TESTS=true and will make actual API calls.
Linting & Formatting
Linting
npm run lint # Run all linters (ESLint + custom)
npm run lint:fix # Auto-fix ESLint issues
npm run lint:docs # Lint documentation files
npm run lint:docs:strict # Strict documentation linting
npm run lint:conventions # Validate linter naming conventions
npm run lint:console # Find console.log statements
npm run lint:venue-config # Validate venue config (with Firestore)
npm run lint:venue-config:static # Validate venue config (static only)Formatting
npm run format # Format src/**/*.{js,jsx,css} with Prettier
npm run format:check # Check formatting without changesSee: Documentation Linter Guide
Validation & Auditing
Full Validation
npm run validate # Run ALL checks (tests, lint, format, audit, workspaces)
npm run validate:fix # Auto-fix lint, format, and conventionsvalidate runs: headers check → workflow validation → test coverage → format check → lint → audit → workspace validations
Security Auditing
npm run audit # Production-only audit (moderate+ severity)
npm run audit:fix # Auto-fix audit issues
npm run audit:fix:force # Force-fix audit issues (may break things)
npm run validate:headers # Validate security headers configurationDocumentation
VitePress Docs
npm run docs:dev # Start docs dev server
npm run docs:build # Build docs for production
npm run docs:preview # Preview built docsStorybook
Development
npm run storybook # Start Storybook on port 6006
npm run storybook:log # Start with logging to file
npm run storybook:dated-log # Start with timestamped log file
npm run storybook:debug-log # Start with debug logging
npm run storybook:interactive-log # Interactive mode with logging
npm run storybook:interactive-dated-log # Interactive + timestamped
npm run storybook:tail # Tail the Storybook log fileBuilding
npm run build-storybook # Build static Storybook
npm run build-storybook:log # Build with loggingLogs location: logs/storybook/
Available Scripts
Changelog Management
consolidate-changelog.mjs
Consolidates daily [DEV] changelog entries into production releases with semantic versioning.
Usage:
# Interactive mode (prompts for version)
npm run changelog:consolidate
# Automatic versioning
npm run changelog:consolidate -- --auto
# Preview without modifying files
npm run changelog:consolidate -- --dry-run --auto
# Help
npm run changelog:consolidate -- --helpWhat it does:
- Parses all
[DEV] - YYYY-MM-DDsections fromdocs/CHANGELOG.md - Groups changes by category (Added, Changed, Fixed, etc.)
- Removes duplicates
- Suggests semantic version based on change types
- Creates consolidated production release section
- Removes
[DEV]sections after consolidation
See: Changelog Workflow
Database & Venue Management
backfill-geohash.mjs
Backfills geohash data for existing venues in Firestore.
Usage:
npm run backfill:geohashWhat it does:
- Queries all venues from Firestore
- Calculates geohash for each venue's coordinates
- Updates venue documents with geohash field
- Enables geofencing and proximity queries
Manual run (dev Firestore):
# Option 1: Use .env.local (recommended)
# Add to .env.local:
# GOOGLE_APPLICATION_CREDENTIALS=/path/to/dev-service-account.json
# GOOGLE_CLOUD_PROJECT=lantern-app-dev
npm run backfill:geohash
# Option 2: Inline environment variables
GOOGLE_APPLICATION_CREDENTIALS=$HOME/repos/secrets/firebase/lantern-app-dev-firebase-adminsdk-fbsvc-6ea86176a1.json \
GOOGLE_CLOUD_PROJECT=lantern-app-dev \
npm run backfill:geohashNotes:
- Preferred setup: Add
GOOGLE_APPLICATION_CREDENTIALSandGOOGLE_CLOUD_PROJECTto.env.local(both scripts auto-load it). - Optional emulator flag: prepend
FIRESTORE_EMULATOR_HOST=localhost:8080to dry-run against the emulator. - Safe to rerun; rows with correct geohash are skipped. Only
lat,lng, andgeohashare updated. - Use the production service account only after explicit approval.
- CLI auth:
gcloud auth application-default loginthenexport GOOGLE_CLOUD_PROJECT=lantern-app-dev(firebase login alone is not enough for ADC). - If
gcloudis not installed:sudo snap install google-cloud-cli --classic(snap requires the--classicflag) or use the service-account JSON path viaGOOGLE_APPLICATION_CREDENTIALSinstead of CLI auth.
Headless/no-browser auth (servers/WSL):
# Application Default Credentials without launching a browser
gcloud auth application-default login --no-launch-browser || gcloud auth application-default login --no-browser
# Follow the prompt: copy the URL into any browser, complete login,
# paste the verification code back into the terminal when asked.
# Set project for ADC consumers
gcloud config set project lantern-app-dev
export GOOGLE_CLOUD_PROJECT=lantern-app-dev
# If you see a quota project mismatch warning, set the ADC quota project
gcloud auth application-default set-quota-project lantern-app-dev
# Run backfill
npm run backfill:geohashbackfill-venues.mjs
Aggregate backfill for venues (geohash, address, closed flag/status, search terms).
Usage:
# Default: geohash + address + heuristic closed flag + searchTerms
npm run backfill:venues
# Dry run (no writes)
npm run backfill:venues -- --dry-run
# Only specific tasks (comma-separated)
npm run backfill:venues -- --only=geohash,address
# Apply closed status when heuristic triggers (otherwise just sets heuristicLikelyClosed=true)
npm run backfill:venues -- --apply-closed
# Respect Nominatim rate limit (default 1000ms)
npm run backfill:venues -- --rate-limit-ms=1000What it does:
- Ensures
geohashmatcheslat/lng(same behavior asbackfill-geohash) - Reverse geocodes missing/placeholder
addressusing Nominatim (1 req/sec) - Marks
heuristicLikelyClosedwhen OSM lifecycle tags suggest closure; with--apply-closed, setsstatus: 'closed' - Regenerates
searchTermsfromosmTagsand venue name for better keyword matching
Notes:
- Preferred setup: Add
GOOGLE_APPLICATION_CREDENTIALSandGOOGLE_CLOUD_PROJECTto.env.local(both scripts auto-load it). - Nominatim usage follows the 1 request/second policy; adjust with
--rate-limit-ms. - Safe to rerun; only missing or out-of-date fields are updated.
- Network timeouts are handled gracefully; venues that fail reverse geocoding are skipped with a warning.
import-venues-osm.mjs
Imports venue data from OpenStreetMap (OSM) via Overpass API.
Usage:
npm run import:venues:osm -- --lat=32.7157 --lng=-117.1611 --radius=5000Options:
--lat- Center latitude--lng- Center longitude--radius- Search radius in meters--limit- Max venues to import (default: 100)--dry-run- Preview without writing to Firestore--consolidate- Merge duplicate venues by osmId
What it does:
- Queries Overpass API for businesses in geographic area
- Normalizes OSM data to Lantern venue format
- Deduplicates by
osmId - Batch writes to Firestore
- Preserves merchant-customized fields
- Captures hours, cuisine, accessibility, amenities
See: Venue Import Guide
check-duplicate-venues.mjs
Checks for duplicate venues in Firestore.
Usage:
npm run check:venues # Interactive mode
npm run check:venues:ci # CI mode (exits with error code if duplicates found)deduplicate-venues.mjs
Removes duplicate venues from Firestore.
Usage:
npm run deduplicate:venuesdelete-all-venues.mjs
Deletes all venues from Firestore. Use with extreme caution.
Usage:
npm run delete:venueslist-osm-tag-keys.mjs
Lists all OSM tag keys used in imported venues.
Usage:
npm run list:osm-tagslookup-osm-place.mjs
Looks up a place in OpenStreetMap by name or coordinates.
Usage:
npm run lookup:osm -- "Coffee Shop Name"
npm run lookup:osm -- --lat=32.7157 --lng=-117.1611review-closure-reports.mjs
Reviews and processes venue closure reports.
Usage:
npm run review:closuresFirebase Emulators
npm run emulators:firestore # Start Firestore emulator onlyUse emulators for local testing without affecting dev/prod databases.
Build & Development
generate-version.mjs
Generates public/version.json with build metadata.
Usage:
node scripts/generate-version.mjsWhat it does:
- Creates version.json with current version, build timestamp, and git commit
- Auto-runs via
predevandprebuildhooks - Used by PWA for cache busting and version display
build-all.sh
Builds all deployable assets (app, Storybook, docs).
Usage:
./scripts/build-all.shWhat it does:
- Builds main app (
npm run build:app) - Builds Storybook (
npm run build-storybook) - Builds documentation (
npm run docs:build)
Admin Portal & Cloudflare Pages
Commands for managing the admin portal deployment to Cloudflare Pages.
Create Cloudflare Pages Projects
# Create dev project (one-time setup)
npm run admin:pages:create:dev
# Create prod project (one-time setup)
npm run admin:pages:create:prodPrerequisites:
- Wrangler CLI authenticated (
npx wrangler login) - Cloudflare account with Pages access
Deploy Admin Portal
# Deploy to preview (creates preview.lantern-admin-dev.pages.dev)
npm run admin:deploy:preview
# Deploy to dev (production URL for dev project)
npm run admin:deploy:dev
# Deploy to prod (requires approval)
npm run admin:deploy:prodWhat it does:
- Builds the admin portal (
npm run admin:build) - Deploys
admin/distto Cloudflare Pages - Preview deploys to
preview.lantern-admin-dev.pages.dev(safe for testing) - Dev deploys to
lantern-admin-dev.pages.dev - Prod deploys to
lantern-admin-prod.pages.dev
⚠️ Important: Per project NON-NEGOTIABLES, do not run admin:deploy:prod without explicit approval. All production deployments should go through Pull Requests.
See: Admin Portal Setup
Cloudflare Cache Rules
# Setup cache rules for dev
npm run cf:setup-cache-rules:dev
# Setup cache rules for prod
npm run cf:setup-cache-rules:prodWhat it does:
- Configures Cloudflare cache rules for static assets
- Sets appropriate TTLs for different file types
- Optimizes CDN performance
start-storybook-logs.sh
Starts Storybook with logging to file.
Usage:
./scripts/start-storybook-logs.shWhat it does:
- Starts Storybook dev server
- Logs output to
logs/storybook/storybook.log - Useful for debugging component issues
Financial Calculators
fund_allocation_calculator.py
Python-based financial calculator for Four Pillars fund allocation.
Usage:
python scripts/fund_allocation_calculator.pyWhat it does:
- Models budget allocation across Four Pillars
- Calculates safe space contributions
- Computes profit sharing distributions
- Validates allocation percentages
Note: Web-based Vue calculators are available in the docs site: npm run docs:dev
Validation & Audit Scripts
audit-production.js
Runs security audit on production dependencies only (ignores devDependencies).
Usage:
npm run audit # Runs with --level=moderateWhat it does:
- Filters audit to production dependencies only
- Exits with error if moderate+ vulnerabilities found
- Used in CI/CD validation pipeline
validate-headers.js
Validates security headers in public/_headers and public/_redirects.
Usage:
npm run validate:headersvalidate-triage-consistency.js
Validates AI triage configuration consistency.
Usage:
node scripts/validate-triage-consistency.jsPart of npm run test:workflows:validate.
Cache Management
purge-cache.sh
Purges Cloudflare cache for the application.
Usage:
./scripts/purge-cache.shNote: Requires Cloudflare API credentials configured. Build & Development
build-all.sh
Builds all deployable assets (app, Storybook, docs).
Usage:
./scripts/build-all.shWhat it does:
- Builds main app (
npm run build:app) - Builds Storybook (
npm run build-storybook) - Builds documentation (
npm run docs:build)
start-storybook-logs.sh
Starts Storybook with logging to file.
Usage:
./scripts/start-storybook-logs.shWhat it does:
- Starts Storybook dev server
- Logs output to
logs/storybook/storybook.log - Useful for debugging component issues
Financial Calculators
fund_allocation_calculator.py
Python-based financial calculator for Four Pillars fund allocation.
Usage:
python scripts/fund_allocation_calculator.pyWhat it does:
- Models budget allocation across Four Pillars
- Calculates safe space contributions
- Computes profit sharing distributions
- Validates allocation percentages
Note: Web-based Vue calculators are available in the docs site: npm run docs:dev
Adding New Scripts
- Naming: Use kebab-case (e.g.,
my-new-script.mjs). - Executable: Make executable with
chmod +x scripts/my-new-script.mjs. - Shebang: Add
#!/usr/bin/env nodeat top for Node scripts. - npm script: Add to
package.jsonscripts section. - Documentation: Update this guide with usage instructions (do not create
scripts/README.md). - Help flag: Support
--helpfor usage instructions.
Example Script Template
#!/usr/bin/env node
/**
* Script Name
*
* Brief description of what the script does.
*
* Usage:
* npm run script:name # Basic usage
* npm run script:name -- --option # With options
*/
import fs from 'fs';
import path from 'path';
function parseArgs() {
const args = process.argv.slice(2);
return {
help: args.includes('--help') || args.includes('-h'),
dryRun: args.includes('--dry-run')
};
}
function showHelp() {
console.log(`
Script Name
Usage:
npm run script:name Basic usage
npm run script:name -- --help Show help
npm run script:name -- --dry-run Preview mode
`);
}
async function main() {
const args = parseArgs();
if (args.help) {
showHelp();
process.exit(0);
}
// Your script logic here
console.log('Script running...');
}
main().catch(error => {
console.error('Error:', error);
process.exit(1);
});Troubleshooting
Permission Denied
chmod +x scripts/your-script.mjsNode Version
All scripts require Node.js 20+. Check version:
node --versionMissing Dependencies
Install all dependencies:
npm install
cd discord-bot && npm install