Contentstack CLI plugin to export content from stack
npm install @contentstack/cli-cm-export-queryA powerful CLI plugin for Contentstack that enables query-based content export with intelligent dependency resolution and asset reference detection.
This plugin extends the Contentstack CLI to export content based on custom queries, automatically resolving dependencies between content types, global fields, extensions, and taxonomies. It intelligently detects and exports referenced assets to ensure complete content portability.
- 🔍 Query-based Export: Export content using custom queries instead of entire content types
- 🔗 Dependency Resolution: Automatically resolve and export dependencies (global fields, extensions, taxonomies)
- 🖼️ Asset Reference Detection: Intelligent detection of asset references in various formats
- 📁 Organized Output: Well-structured export with separate folders for each module
- ⚙️ Configurable: Support for external config files and flexible options
- 🌐 Multi-locale Support: Export content across different locales
- 📊 Export Metadata: Comprehensive metadata tracking for export operations
``bashInstall as a Contentstack CLI plugin
npm install -g @contentstack/cli-cm-export-query
Usage
$3
`bash
Export using management token alias
csdx cm:stacks:export-query -a -q "{'title': {'$exists': true}}"Export using API key and management token
csdx cm:stacks:export-query --stack-api-key -A -q "{'title': {'$exists': true}}"
`$3
| Flag | Description | Required |
|------|-------------|----------|
|
-a, --alias | Management token alias | Yes (or use -A) |
| -A, --management-token | Management token | Yes (or use -a) |
| --stack-api-key | Stack API key | Yes |
| -q, --query | Query for content export | Yes |
| -d, --data-dir | Export directory path | No |
| --branch | Branch name | No |
| --skip-references | Skip reference resolution | No |
| --skip-dependencies | Skip dependency export | No |
| --secured-assets | Include secured assets | No |
| --config | External config file path | No |$3
Basic Content Query:
`bash
csdx cm:stacks:export-query -a prod -q "{'title': {'$regex': 'blog'}}"
`Date Range Query:
`bash
csdx cm:stacks:export-query -a prod -q "{'updated_at': {'$gte': '2024-01-01'}}"
`Complex Query:
`bash
csdx cm:stacks:export-query -a prod -q "{'$and': [{'title': {'$exists': true}}, {'tags': {'$in': ['featured']}}]}"
`Configuration
$3
The plugin includes a default configuration file at
src/config/export-defaults.json:`json
{
"skipReferences": false,
"skipDependencies": false,
"securedAssets": false,
"includeGlobalFieldSchema": true,
"includePublishDetails": true,
"includeDimension": false,
"fetchConcurrency": 5,
"writeConcurrency": 5,
"batchSize": 100
}
`$3
Create a custom config file and pass it using the
--config flag:`json
{
"skipReferences": true,
"batchSize": 50,
"fetchConcurrency": 3,
"securedAssets": true
}
``bash
csdx cm:stacks:export-query -a prod -q "{'title': {'$exists': true}}" --config ./my-config.json
``