|
| 1 | +/** |
| 2 | + * CLI utilities and base command classes for building B2C Commerce CLI commands. |
| 3 | + * |
| 4 | + * This module provides reusable base classes, configuration loading, and table |
| 5 | + * rendering utilities for oclif-based CLI applications. |
| 6 | + * |
| 7 | + * ## Base Command Classes |
| 8 | + * |
| 9 | + * Extend these classes to create CLI commands with pre-configured functionality: |
| 10 | + * |
| 11 | + * - {@link BaseCommand} - Foundation class with logging, JSON output, and error handling |
| 12 | + * - {@link OAuthCommand} - Adds OAuth authentication setup |
| 13 | + * - {@link InstanceCommand} - Adds B2C Commerce instance configuration |
| 14 | + * - {@link CartridgeCommand} - Adds cartridge path configuration for code operations |
| 15 | + * - {@link JobCommand} - Adds job execution configuration |
| 16 | + * - {@link MrtCommand} - Adds Managed Runtime API authentication |
| 17 | + * - {@link OdsCommand} - Adds On-Demand Sandbox configuration |
| 18 | + * |
| 19 | + * ## Command Hierarchy |
| 20 | + * |
| 21 | + * Commands inherit in a chain, each adding specific functionality: |
| 22 | + * |
| 23 | + * ``` |
| 24 | + * BaseCommand |
| 25 | + * └─ OAuthCommand (adds OAuth) |
| 26 | + * └─ InstanceCommand (adds instance config) |
| 27 | + * ├─ CartridgeCommand (adds cartridge paths) |
| 28 | + * └─ JobCommand (adds job config) |
| 29 | + * └─ MrtCommand (adds MRT API auth) |
| 30 | + * └─ OdsCommand (adds ODS config) |
| 31 | + * ``` |
| 32 | + * |
| 33 | + * ## Example Usage |
| 34 | + * |
| 35 | + * ```typescript |
| 36 | + * import { InstanceCommand, createTable, type ColumnDef } from '@salesforce/b2c-tooling/cli'; |
| 37 | + * |
| 38 | + * export default class ListSites extends InstanceCommand { |
| 39 | + * static description = 'List all sites on the instance'; |
| 40 | + * |
| 41 | + * async run() { |
| 42 | + * const client = await this.createOcapiClient(); |
| 43 | + * const sites = await client.getSites(); |
| 44 | + * |
| 45 | + * const columns: Record<string, ColumnDef<Site>> = { |
| 46 | + * id: { header: 'ID', get: (s) => s.id }, |
| 47 | + * name: { header: 'Name', get: (s) => s.display_name }, |
| 48 | + * }; |
| 49 | + * |
| 50 | + * createTable(columns).render(sites, ['id', 'name']); |
| 51 | + * } |
| 52 | + * } |
| 53 | + * ``` |
| 54 | + * |
| 55 | + * ## Configuration Loading |
| 56 | + * |
| 57 | + * Use {@link loadConfig} to resolve configuration from multiple sources: |
| 58 | + * |
| 59 | + * ```typescript |
| 60 | + * import { loadConfig } from '@salesforce/b2c-tooling/cli'; |
| 61 | + * |
| 62 | + * const config = await loadConfig({ |
| 63 | + * flags: { hostname: 'example.com' }, |
| 64 | + * configPath: './dw.json', |
| 65 | + * }); |
| 66 | + * ``` |
| 67 | + * |
| 68 | + * ## Table Rendering |
| 69 | + * |
| 70 | + * Use {@link createTable} for consistent tabular output: |
| 71 | + * |
| 72 | + * ```typescript |
| 73 | + * import { createTable, type ColumnDef } from '@salesforce/b2c-tooling/cli'; |
| 74 | + * |
| 75 | + * const columns: Record<string, ColumnDef<Item>> = { |
| 76 | + * id: { header: 'ID', get: (item) => item.id }, |
| 77 | + * status: { header: 'Status', get: (item) => item.status }, |
| 78 | + * }; |
| 79 | + * |
| 80 | + * createTable(columns).render(items, ['id', 'status']); |
| 81 | + * ``` |
| 82 | + * |
| 83 | + * @module cli |
| 84 | + */ |
| 85 | + |
1 | 86 | // Base command classes |
2 | 87 | export {BaseCommand} from './base-command.js'; |
3 | 88 | export type {Flags, Args} from './base-command.js'; |
|
0 commit comments