|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +This plugin generates the Salesforce CLI command reference documentation guide (https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/). It's an oclif plugin that reads command metadata from other Salesforce CLI plugins and transforms them into DITA XML format for publication. |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +### Build and Development |
| 12 | + |
| 13 | +```bash |
| 14 | +# Build the project (compile + lint) |
| 15 | +yarn build |
| 16 | + |
| 17 | +# Compile TypeScript only |
| 18 | +yarn compile |
| 19 | + |
| 20 | +# Run linter |
| 21 | +yarn lint |
| 22 | + |
| 23 | +# Format code |
| 24 | +yarn format |
| 25 | +``` |
| 26 | + |
| 27 | +### Testing |
| 28 | + |
| 29 | +```bash |
| 30 | +# Run all tests (includes test:compile, test:only, and lint) |
| 31 | +yarn test |
| 32 | + |
| 33 | +# Run only unit tests (skips compilation and lint) |
| 34 | +yarn test:only |
| 35 | + |
| 36 | +# Run a single test file |
| 37 | +yarn mocha test/unit/utils.test.ts |
| 38 | +``` |
| 39 | + |
| 40 | +### Local Development |
| 41 | + |
| 42 | +```bash |
| 43 | +# Link plugin to local Salesforce CLI for testing |
| 44 | +sf plugins link . |
| 45 | + |
| 46 | +# Run command using dev executable |
| 47 | +./bin/dev.js commandreference generate --plugins auth |
| 48 | + |
| 49 | +# Generate documentation for multiple plugins |
| 50 | +sf commandreference generate --plugins auth user deploy-retrieve --output-dir ./test-output |
| 51 | +``` |
| 52 | + |
| 53 | +### Generate Command Reference |
| 54 | + |
| 55 | +```bash |
| 56 | +# Generate docs for specific plugins (default: DITA XML format) |
| 57 | +sf commandreference generate --plugins auth user |
| 58 | + |
| 59 | +# Generate docs in Markdown format |
| 60 | +sf commandreference generate --plugins auth --format markdown |
| 61 | + |
| 62 | +# Generate docs for all plugins |
| 63 | +sf commandreference generate --all |
| 64 | + |
| 65 | +# Generate docs with error on warnings (useful in CI) |
| 66 | +sf commandreference generate --plugins auth --error-on-warnings |
| 67 | + |
| 68 | +# Install JIT plugins (needed for comprehensive doc generation) |
| 69 | +sf jit install |
| 70 | +``` |
| 71 | + |
| 72 | +## Code Architecture |
| 73 | + |
| 74 | +### Core Components |
| 75 | + |
| 76 | +**Docs class (`src/docs.ts`)** |
| 77 | + |
| 78 | +- Entry point for documentation generation |
| 79 | +- Orchestrates the entire documentation generation process |
| 80 | +- Groups commands by topics and subtopics using `groupTopicsAndSubtopics()` |
| 81 | +- Iterates through all topics and calls `populateTopic()` for each |
| 82 | +- Each topic generates multiple DITA XML files through various ditamap classes |
| 83 | + |
| 84 | +**Command Reference Generator (`src/commands/commandreference/generate.ts`)** |
| 85 | + |
| 86 | +- Main CLI command implementation |
| 87 | +- Loads plugin configurations and metadata from oclif |
| 88 | +- Resolves plugin dependencies and child plugins |
| 89 | +- Extracts topic metadata from plugin `package.json` oclif configurations |
| 90 | +- Loads all commands from specified plugins |
| 91 | +- Initializes Docs class and triggers generation |
| 92 | + |
| 93 | +**Ditamap Base Class (`src/ditamap/ditamap.ts`)** |
| 94 | + |
| 95 | +- Abstract base class for all DITA XML generators |
| 96 | +- Uses Handlebars templates from `templates/` directory |
| 97 | +- Manages file paths, naming conventions, and output directory |
| 98 | +- Registers Handlebars helpers for XML generation (xmlFile, uniqueId, isCodeBlock, etc.) |
| 99 | +- Static properties like `outputDir`, `suffix`, `cliVersion` are shared across all ditamap instances |
| 100 | + |
| 101 | +### Ditamap Hierarchy |
| 102 | + |
| 103 | +The plugin generates multiple types of DITA files through specialized ditamap classes: |
| 104 | + |
| 105 | +- **BaseDitamap** (`src/ditamap/base-ditamap.ts`): Top-level ditamap that references all topic ditamaps |
| 106 | +- **CLIReference** (`src/ditamap/cli-reference.ts`): CLI version and plugin version metadata |
| 107 | +- **HelpReference** (`src/ditamap/help-reference.ts`): General help content |
| 108 | +- **TopicDitamap** (`src/ditamap/topic-ditamap.ts`): Maps for each topic, referencing all commands in that topic |
| 109 | +- **TopicCommands** (`src/ditamap/topic-commands.ts`): Topic-level command listing pages |
| 110 | +- **Command** (`src/ditamap/command.ts`): Individual command documentation pages with flags, examples, descriptions |
| 111 | + |
| 112 | +### Handlebars Templates |
| 113 | + |
| 114 | +All templates are in `templates/` directory: |
| 115 | + |
| 116 | +- `base_ditamap.hbs`: Top-level namespace ditamap |
| 117 | +- `cli_reference_xml.hbs`: CLI and plugin version information |
| 118 | +- `cli_reference_help.hbs`: Help reference page |
| 119 | +- `cli_reference_topic_commands.hbs`: Topic overview pages |
| 120 | +- `topic_ditamap.hbs`: Topic-level ditamaps |
| 121 | +- `command.hbs`: Individual command documentation (flags, examples, descriptions) |
| 122 | + |
| 123 | +### Topic and Command Metadata |
| 124 | + |
| 125 | +Topics and subtopics are defined in each plugin's `package.json` under the `oclif.topics` section: |
| 126 | + |
| 127 | +```json |
| 128 | +{ |
| 129 | + "oclif": { |
| 130 | + "topics": { |
| 131 | + "commandreference": { |
| 132 | + "description": "generate the Salesforce CLI command reference guide.", |
| 133 | + "longDescription": "..." |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +The generator reads this metadata to: |
| 141 | + |
| 142 | +- Organize commands into hierarchical topics/subtopics |
| 143 | +- Extract descriptions and long descriptions |
| 144 | +- Determine command state (beta, pilot, deprecated) |
| 145 | +- Handle hidden topics/commands based on the `--hidden` flag |
| 146 | + |
| 147 | +### Command Processing Flow |
| 148 | + |
| 149 | +1. `CommandReferenceGenerate.run()` loads all plugins and commands |
| 150 | +2. Calls `Docs.build()` with the command list |
| 151 | +3. `Docs.populateTemplate()` groups commands into topics/subtopics |
| 152 | +4. For each topic, `Docs.populateTopic()` generates ditamaps |
| 153 | +5. For each command, `Docs.populateCommand()` creates command XML via `Command` class |
| 154 | +6. Each ditamap class extends `Ditamap` and uses corresponding `.hbs` template |
| 155 | +7. Handlebars transforms data into DITA XML format |
| 156 | +8. Files are written to the output directory (default: `./tmp/root`) |
| 157 | + |
| 158 | +### Event System |
| 159 | + |
| 160 | +The plugin uses Node's EventEmitter (`events` in `src/utils.ts`) to communicate status: |
| 161 | + |
| 162 | +- `'topic'`: Emitted when processing a new topic |
| 163 | +- `'subtopics'`: Emitted with subtopic names |
| 164 | +- `'warning'`: Emitted for metadata issues or validation warnings |
| 165 | + |
| 166 | +### Wireit Task Dependencies |
| 167 | + |
| 168 | +This project uses Wireit for build orchestration. Key task dependencies: |
| 169 | + |
| 170 | +- `build` depends on `compile` and `lint` |
| 171 | +- `test` depends on `test:compile`, `test:only`, and `lint` |
| 172 | +- `test:only` depends on `test:command-reference` (generates test fixtures by running the command) |
| 173 | +- Tests run using Mocha with `ts-node/esm` loader for ESM support |
| 174 | + |
| 175 | +### TypeScript Configuration |
| 176 | + |
| 177 | +- Uses ESM modules (`"type": "module"` in package.json) |
| 178 | +- Extends strict TypeScript configuration from `@salesforce/dev-config` |
| 179 | +- Source in `src/`, compiled output in `lib/` |
| 180 | +- Mocha tests use `ts-node/esm` loader for direct TypeScript execution |
| 181 | + |
| 182 | +## Output Formats |
| 183 | + |
| 184 | +The plugin supports two output formats via the `--format` flag: |
| 185 | + |
| 186 | +### DITA XML (default) |
| 187 | + |
| 188 | +- Original format for Salesforce documentation pipeline |
| 189 | +- Uses templates in `templates/` directory |
| 190 | +- Generates XML files following the DITA specification |
| 191 | +- Output includes `.ditamap` files for documentation aggregation |
| 192 | + |
| 193 | +### Markdown |
| 194 | + |
| 195 | +- Alternative format for easier reading and contribution |
| 196 | +- Uses templates in `templates/markdown/` directory |
| 197 | +- Generates `.md` files with GitHub-flavored Markdown |
| 198 | +- Creates README.md files for topic/command navigation |
| 199 | +- Useful for hosting docs on GitHub or other Markdown-friendly platforms |
| 200 | + |
| 201 | +Both formats use the same data pipeline and Handlebars templating system. The Markdown generator classes (`src/markdown/`) mirror the DITA generator classes (`src/ditamap/`) in structure. |
| 202 | + |
| 203 | +## Important Notes |
| 204 | + |
| 205 | +- The plugin reads metadata from other plugins' `package.json` oclif configurations - it doesn't generate its own command metadata |
| 206 | +- Warnings are emitted when plugins lack required metadata (topic descriptions, command metadata) |
| 207 | +- The `--error-on-warnings` flag is useful in CI to enforce metadata completeness |
| 208 | +- Commands are grouped by namespace (e.g., `force:org:create` → topic: `force`, subtopic: `org`) |
| 209 | +- The `--ditamap-suffix` flag allows multiple doc sets to coexist (default: "unified") |
| 210 | +- The plugin supports generating documentation for external/JIT plugins via the `jit install` command |
| 211 | +- Both DITA and Markdown formats share the same suffix configuration for consistency |
0 commit comments