A 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
# Install as a Contentstack CLI plugin
npm install -g @contentstack/cli-cm-export-query
# Or install locally
npm install @contentstack/cli-cm-export-query
# Export using management token alias
csdx cm:stacks:export-query -a <alias> -q "{'title': {'$exists': true}}"
# Export using API key and management token
csdx cm:stacks:export-query --stack-api-key <api-key> -A <management-token> -q "{'title': {'$exists': true}}"
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 |
Basic Content Query:
csdx cm:stacks:export-query -a prod -q "{'title': {'$regex': 'blog'}}"
Date Range Query:
csdx cm:stacks:export-query -a prod -q "{'updated_at': {'$gte': '2024-01-01'}}"
Complex Query:
csdx cm:stacks:export-query -a prod -q "{'$and': [{'title': {'$exists': true}}, {'tags': {'$in': ['featured']}}]}"
The plugin includes a default configuration file at src/config/export-defaults.json
:
{
"skipReferences": false,
"skipDependencies": false,
"securedAssets": false,
"includeGlobalFieldSchema": true,
"includePublishDetails": true,
"includeDimension": false,
"fetchConcurrency": 5,
"writeConcurrency": 5,
"batchSize": 100
}
Create a custom config file and pass it using the --config
flag:
{
"skipReferences": true,
"batchSize": 50,
"fetchConcurrency": 3,
"securedAssets": true
}
csdx cm:stacks:export-query -a prod -q "{'title': {'$exists': true}}" --config ./my-config.json