@digital-herd/content-hub-cli
v1.2.9
Published
CLI tools for managing Sitecore Content Hub external components and scripts
Keywords
Readme
ContentHub CLI (content-hub-tools)
ContentHub build & utility CLI used to build, watch and manage external components and scripts.
Quick Reference
| Command | Description |
|---------|-------------|
| create-component | Create a new React component from template |
| create-script | Create a new C# script with API auto-fetch |
| create-manual-patch | Create a new manual patch from template |
| run-manual-patch | Run a manual patch on ContentHub |
| build | Build external components for production |
| watch | Watch and serve components with HMR |
| publish-script | Publish scripts to ContentHub environment |
| sync-scripts | Sync scripts from ContentHub to local |
Jump to:
Install
- From source (recommended during development):
cd contenthub-cli
npm install
npm run build
# make the CLI available locally
npm linkAfter installation the binary is content-hub-tools.
Config file
The CLI loads its configuration from contenthubConfig.build.config.ts by default. Example shape:
export default {
componentDir: "external-components/components",
scriptDir: "scripts",
port: 5173,
mainEnvironment: "local",
environments: [
{ name: "local", domain: "https://localhost", apiToken: "<token>" },
{ name: "staging", domain: "https://staging.example.com", apiToken: "<token>" }
]
};If your config lives in a different path, set NODE_ENV or adjust imports when invoking programmatically or update the getCliConfig call.
Global options
-e, --environment <environment>: select which environment (name) from the config to use. If omitted themainEnvironmentfrom the config is used.
Commands
All commands are exposed via the content-hub-tools binary. Usage:
content-hub-tools <command> [options]create-component — Create a new external component from template (interactive)
This command will interactively prompt you to:
- Select which section (folder) to create the component in
- Enter a component name (must start with uppercase and contain only letters/numbers)
The command copies the template from
contenthub-cli/templates/external-components/and creates the new component with all template files renamed and updated with your component name.Examples:
- Create a new component (interactive prompts):
content-hub-tools create-component
The interactive prompts will guide you through:
- Section selection: Choose from available sections (e.g.,
asset,general,workflows/cgi) - Component name: Enter a PascalCase name (e.g.,
ProductCard,MyNewWidget)
After running, the component will be created at:
external-components/components/<section>/<ComponentName>/create-script — Create a new script from template (interactive)
This command will interactively prompt you to provide script details. If you provide an identifier that exists in the environment, it will automatically fetch the default values (title, description, execute as user) from the API.
Examples:
- Create a new script (interactive prompts):
content-hub-tools create-script
The interactive prompts will guide you through:
- Identifier: Script identifier (e.g.,
M.Script.MyNewScript) - Auto-fetch: If the identifier exists in the environment, defaults will be fetched
- Title: Script title (pre-filled if fetched from API)
- Description: Script description (pre-filled if fetched from API)
- Type: Script type (Action or Trigger)
- Execute as user: Whether to execute as user (pre-filled if fetched from API)
After running, the script will be created at:
action-scripts/scripts/<ScriptName>/Files created:
<ScriptName>.config.ts- Script configuration with metadata<ScriptName>.cs- C# script implementation file
- Create a new script (interactive prompts):
build — Build External component(s)
Options:
-c, --components <comp>: comma-separated component names to build. If omitted, builds all components.-d, --deprecated: build usingtsconfig.deprecated.json(TypeScript strict mode disabled) instead of the defaulttsconfig.json.-p, --publish: after building, publish the built components to the configured ContentHub environment portal asset.
Examples:
Build all components using default tsconfig:
content-hub-tools buildBuild all components using mainEnvironment from config:
content-hub-tools buildBuild a single component:
content-hub-tools build -c "ProductCard"Build multiple specific components:
content-hub-tools build -c "Button,Card,Header"Build and publish to production:
content-hub-tools build -c "Button,Card" -pBuild all components and publish:
content-hub-tools build -pBuild using deprecated TS config (compatibility mode):
content-hub-tools build -dBuild specific components with deprecated config and publish:
content-hub-tools build -c "LegacyComponent" -d -p
watch — Watch and serve External component(s) with HMR (development)
Options:
-c, --components <comp>: comma-separated list of components to watch. If omitted, watches all components.-d, --deprecated: usetsconfig.deprecated.json(TypeScript strict mode disabled) while watching.
When using
-cor--components, the external component is set to localhost for the selected environment.Examples:
Watch all components with HMR:
content-hub-tools watchWatch all components using mainEnvironment:
content-hub-tools watchWatch a single component for development:
content-hub-tools watch -c "ProductCard"Watch multiple specific components:
content-hub-tools watch -c "Button,Card,Header"Watch with deprecated tsconfig:
content-hub-tools watch -dWatch specific components with deprecated config:
content-hub-tools watch -c "LegacyComponent,OldCard" -d
publish-script — Publish scripts to environment
Options:
-s, --scripts <script>: comma-separated list of script names to publish (required).
Examples:
Publish a single script:
content-hub-tools publish-script -s "myScript"Publish multiple scripts:
content-hub-tools publish-script -s "myScript,anotherScript"Publish to production environment:
content-hub-tools publish-script -s "ProductionScript"Publish scripts using mainEnvironment:
content-hub-tools publish-script -s "myScript,anotherScript"
sync-scripts — Sync scripts from environment to local
Examples:
Sync scripts from staging environment:
content-hub-tools sync-scriptsSync scripts from production:
content-hub-tools sync-scriptsSync using mainEnvironment from config:
content-hub-tools sync-scriptsSync from local development environment:
content-hub-tools sync-scripts
create-manual-patch — Create a new manual patch from template (interactive)
This command will interactively prompt you to provide a patch name and create a TypeScript patch file that can be used to run one-off data migrations or fixes.
Examples:
- Create a new patch (interactive prompts):
content-hub-tools create-manual-patch
The interactive prompts will guide you through:
- Patch name: Enter a PascalCase name (e.g.,
FixUserIssue,MigrateData) - Only letters are allowed in the name
- The name will be automatically converted to PascalCase if needed
After running, the patch will be created at:
patches/<PatchName>.patch.tsThe generated patch file will contain:
PatchParamsinterface with ContentHub clientrunPatch<Name>function ready for implementation
- Create a new patch (interactive prompts):
run-manual-patch — Run a manual patch on ContentHub (interactive)
This command will display all available patches sorted by last modified date (newest first) and execute the selected patch.
Examples:
Run a patch (interactive selection):
content-hub-tools run-manual-patchRun a patch on production:
content-hub-tools run-manual-patch
The interactive prompt will show:
- List of all available
.patch.tsfiles - Last modified timestamp for each patch
- Patches sorted with newest first
The patch will be executed with:
- Access to the ContentHub client via
PatchParams - Connection to the selected environment
Developer notes
- The CLI is implemented with
commanderand TypeScript. Entry point:src/bin.ts. - Commands are registered from
src/modules/*— seesrc/modules/external-componentsandsrc/modules/scripts. - The CLI expects a config matching src/types/ContentHubConfig.interface.ts.
- The binary target is
dist/bin.jsas defined inpackage.json'sbinfield.
Troubleshooting
❌ environment not specified -e or --environment: either pass-e <name>or setmainEnvironmentin the config.❌ Failed to load config: confirmcontenthubConfig.build.config.tspath is correct and exports a default config.
License
UNLICENSED - This is proprietary software developed by Digital Herd.
The compiled package is available for use, but the source code is not open source and may not be redistributed or modified. All rights reserved.
