Skip to content

vtexdocs/vtexhelp-nav-cli

Repository files navigation

VTEX Navigation CLI

A comprehensive command-line tool for both generating and viewing VTEX documentation navigation structures.

Features

πŸ—οΈ Navigation Generation

  • πŸ€– Intelligent Generation: Automatically generates navigation from VTEX Help Center content repository
  • 🎯 Simple Generation: Console-only generator focused on speed and clarity
  • 🌍 Multi-language Support: Processes English, Spanish, and Portuguese content with proper localized slugs
  • πŸ”— Cross-language Linking: Automatically links related documents across languages
  • πŸ“ Smart Slug Generation: Prioritizes legacySlug β†’ filename-based β†’ empty string for missing translations
  • πŸ” Intelligent Duplicate Detection: Only warns about true duplicates (same section + language), not multilingual documents
  • πŸ“Š Validation & Reports: Built-in validation with detailed reporting capabilities
  • ⚑ Performance Optimized: Simple mode offers ~13% better performance

🌳 Interactive Viewer

  • 🌳 Interactive Tree View: Navigate through the VTEX documentation structure with keyboard controls
  • 🌍 Multi-language Support: Switch between English, Spanish, and Portuguese on the fly
  • πŸ“Š Statistics: View detailed statistics about the documentation structure
  • πŸ’Ύ Auto-download: Automatically downloads the navigation file if not present locally
  • ⚑ Fast Navigation: Keyboard shortcuts for efficient browsing

Installation

npm install -g vtexhelp-nav-cli

Or run directly with npx:

npx vtexhelp-nav-cli

Usage

Note: The executable name is vtex-nav (alias: vtexhelp-nav-cli).

πŸ—οΈ Navigation Generation

The CLI currently provides a simple, console-only generation command:

Simple Mode (Recommended for CI/CD)

# Generate navigation with clean console output
vtexhelp-nav gen

# Generate with custom options
vtexhelp-nav gen --output custom-nav.json --verbose --force

# Generate specific languages only
vtexhelp-nav gen --languages en,es --report

Generation Options

Options:
  -d, --content-dir <dir>    Directory to clone/use content from (default: ".vtexhelp-content")
  -o, --output <file>        Output navigation.json file path (default: "generated-navigation.json")
  --validate                 Validate against existing navigation schema (default: true)
  --report                   Generate detailed report (default: false)
  --fix                      Auto-fix common issues (default: false)
  --strict                   Fail generation when validation errors are found (default: false)
  -l, --languages <langs>    Comma-separated languages to process (en,es,pt) (default: "en,es,pt")
  -s, --sections <sections>  Comma-separated sections to process (leave empty for all)
  -v, --verbose              Show detailed log lines in terminal (default: false)
  -b, --branch <branch>      Git branch to clone (default: "main")
  -f, --force                Force overwrite existing content directory (default: false)
  --log-file <file>          Export detailed logs to file
  --show-warnings            Display detailed analysis of all warnings (default: false)

βœ… Validation

Validate a navigation.json file (schema + custom cross-node checks):

# Validate and print issues (non-zero exit only if --strict)
vtex-nav validate ./public/navigation.json

# Fail the build if any errors are found
vtex-nav validate ./public/navigation.json --strict

What’s validated:

  • Structural JSON Schema (Draft-07)
    • name and slug are LocalizedString objects with en, es, pt keys
    • Categories: type=category, children min 1
    • Documents: type=markdown, children must be empty
    • Additional properties are rejected for safety
  • Custom rule: sibling categories under the same parent must have unique english slug (slug.en)

Notes:

  • Empty strings are allowed in LocalizedString fields to indicate a missing translation. This keeps the structure consistent while signalling gaps.

🌳 Viewing Navigation

Basic Viewer Usage

# Run the interactive viewer (downloads navigation.json if not present)
vtex-nav view

# Use a specific navigation file
vtex-nav view --file ./custom-navigation.json

# Start in a specific language
vtex-nav view --language es

Viewer Options

Options:
  --file, -f     Path to navigation.json file
  --language, -l Language to use (en, es, pt) [default: en]
  --help         Show help

Keyboard Shortcuts

Navigation

  • ↑/↓ - Navigate up/down through items
  • PgUp/PgDn - Navigate faster (10 items at a time)
  • Space or Enter - Expand/collapse current item
  • a - Toggle all items expanded/collapsed

Language

  • e - Switch to English
  • s - Switch to Spanish
  • p - Switch to Portuguese

Other

  • h or ? - Toggle help screen
  • i - Toggle statistics view
  • q or Esc - Quit the application

Configuration

You can configure the tool using environment variables:

Create a .env file in your project root:

# URL to fetch navigation.json from
VTEX_NAVIGATION_URL=https://newhelp.vtex.com/navigation.json

# Default output path for downloaded navigation
DEFAULT_OUTPUT_PATH=./navigation.json

# Auto-format JSON output
AUTO_FORMAT_JSON=true

# Request timeout in milliseconds
REQUEST_TIMEOUT=30000

Development

Setup

# Clone the repository
git clone https://github.com/yourusername/vtexhelp-nav-cli.git
cd vtexhelp-nav-cli

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode
npm run dev

Temporary caches and external repositories

This project clones content repositories locally for generation. These folders are temporary, ignored by Git, and can be safely deleted at any time:

  • .vtexhelp-content β€” VTEX Help Center content clone
  • .vtexhelp-known-issues β€” Known issues repository clone used for categorization

If either folder is missing, the generator will fetch it automatically when needed.

Project Structure

vtexhelp-nav-cli/
β”œβ”€β”€ source/
β”‚   β”œβ”€β”€ app.tsx                        # Main viewer app component
β”‚   β”œβ”€β”€ cli.tsx                        # CLI entry point and command routing
β”‚   β”œβ”€β”€ NavigationTree.tsx             # Interactive tree component
β”‚   β”œβ”€β”€ commands/
β”‚   β”‚   β”œβ”€β”€ generate-simple.tsx        # Simple mode generation command
β”‚   β”‚   β”œβ”€β”€ generateCommand.ts         # Command definitions and options
β”‚   β”‚   └── generate/                  # Generation system
β”‚   β”‚       β”œβ”€β”€ index.ts               # Main generation orchestrator
β”‚   β”‚       β”œβ”€β”€ simple-generator.ts    # Simple mode generator (Ink-free)
β”‚   β”‚       β”œβ”€β”€ scanner.ts             # Content repository scanner
β”‚   β”‚       β”œβ”€β”€ categorizer.ts         # Category hierarchy builder
β”‚   β”‚       β”œβ”€β”€ linker.ts              # Cross-language document linker
β”‚   β”‚       β”œβ”€β”€ transformer.ts         # Navigation format transformer
β”‚   β”‚       β”œβ”€β”€ external-repositories.ts # Handles cloning/using external content repos
β”‚   β”‚       β”œβ”€β”€ validator.ts           # Navigation validation engine
β”‚   β”‚       β”œβ”€β”€ types.ts               # Generation-specific types
β”‚   β”‚       └── ui/                    # Interactive UI components
β”‚   β”‚           β”œβ”€β”€ GenerationDashboard.tsx  # Main dashboard
β”‚   β”‚           β”œβ”€β”€ ProgressBar.tsx           # Progress visualization
β”‚   β”‚           β”œβ”€β”€ StatsPanel.tsx            # Statistics display
β”‚   β”‚           └── logger.ts                 # Dual-mode logger
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   └── navigation.ts              # Core navigation types
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── navigationService.ts       # Navigation data service
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── config.ts                  # Configuration management
β”‚   └── utils/
β”‚       └── validateSchema.ts          # Schema validation utilities
β”œβ”€β”€ source/schemas/
β”‚   └── navigation.schema.json         # JSON schema for validation
└── dist/                              # Compiled TypeScript output

Examples

πŸ—οΈ Generation Workflow

# 1. Generate navigation (perfect for CI/CD)
vtex-nav gen --verbose --report --output production-nav.json

# 2. Generate with custom branch and specific languages
vtex-nav gen --branch develop --languages en,pt --force

# 3. Validate generated file
vtex-nav view --file production-nav.json

🌳 Viewer Workflow

# 1. Quick view with auto-download
vtex-nav view

# 2. Browse specific navigation file
vtex-nav view --file ./my-navigation.json --language es

# 3. Compare different navigation structures
vtex-nav view --file ./old-nav.json
vtex-nav view --file ./new-nav.json

πŸ”„ Full Development Cycle

# Generate fresh navigation
vtex-nav gen --verbose --report --output latest-nav.json

# Inspect and validate the structure
vtex-nav view --file latest-nav.json

# Generate detailed report for review
vtex-nav gen --report --log-file generation.log

Schema overview

LocalizedString

  • Keys: en, es, pt
  • Value: string (can be empty to indicate missing translation)

NavigationNode

  • name: LocalizedString
  • slug: LocalizedString
  • type: "category" | "markdown"
  • children: NavigationNode[]
  • Rules:
    • category: children.length >= 1
    • markdown: children.length == 0

Merging and duplicates

  • Categories across languages are merged by their English slug (slug.en), treating categories as localized entities.
  • Within the same parent, sibling category english slugs must be unique; duplicates are flagged by validation.

Architecture

🎯 Generation Mode

  • Simple mode (gen): console logging, optimized performance, clean output
  • Designed for CI/CD and automation
  • Use --verbose for detailed logs and --show-warnings for in-depth analysis
  • No interactive generation mode is available at the moment

πŸ—οΈ Generation Pipeline

  1. Repository Initialization: Clones VTEX Help Center content
  2. Content Scanning: Parses markdown files across all languages
  3. Category Building: Constructs hierarchical category structure
  4. Cross-language Linking: Links related documents across languages
  5. Navigation Transformation: Converts to VTEX navigation format
  6. Validation: Ensures schema compliance and content integrity
  7. Output Generation: Writes navigation JSON and optional reports

Requirements

  • Node.js >= 16
  • Terminal with UTF-8 support for proper character display
  • Git (for content repository cloning)
  • ~100MB disk space for content cache

License

MIT

About

VTEX Navigation CLI: generate and view documentation navigation structures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published