Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Resolved review comments
  • Loading branch information
netrajpatel committed Jan 23, 2026
commit 020029fdfdc68d9f90ef96ad3969e08fcb65da4a
28 changes: 3 additions & 25 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: 61df9c5119a68d5058fcf232905ed8a76d6cc58406c13207788c7e6a49bf456a
- filename: packages/contentstack-export-to-csv/src/types/index.ts
checksum: 28c19efb0c13969d40df964f86fa6de444316e320801f19dee7392df7a36851d
- filename: package-lock.json
checksum: e8fd31693cede1935a30511076c1c442e7a50c246f8d58dcb88ffd3ce04d3cb3
- filename: packages/contentstack-clone/test/commands/stack-clone.test.ts
checksum: 889b9d64434261910a50c14e039e6256fd6157727076308f39bba87b854d459a
- filename: packages/contentstack-clone/.eslintrc
checksum: a7230ffa600c58047ac73f2dec7a23ca5862e36e68f04f2671379496739bd818
- filename: packages/contentstack-clone/src/types/clone-config.ts
checksum: c22f8b8a592e7b4da967715e595e79a680ab970ca85b65528d5ac318032e1857
- filename: packages/contentstack-clone/test/lib/helpers/command-helpers.test.ts
checksum: 2702c3cedd9def635fa48408a3a4bbab6728ec8a2700af4f8d5ed6bbe2da4faa
- filename: packages/contentstack-clone/test/lib/util/clone-handler.helpers.test.ts
checksum: efd55d08a7b5263e9ba0d871208552c5df941274bc035bac6101ed26b6ba2da4
- filename: packages/contentstack-clone/test/lib/util/clone-handler.branch.test.ts
checksum: 0f1fccb38c89b4baa9fa2b145905b626b5ce9633ae30021676a924fa88aa570c
- filename: packages/contentstack-clone/package.json
checksum: a81ef3f125ddb91a4e13e77745d9c7927f02e3ff17978374560de6f4825db1c9
- filename: packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts
checksum: e3c5be3312013df0c20faca3ff280130f9ce187a4187c5045b016b0c7b489b46
- filename: packages/contentstack-clone/test/lib/util/clone-handler.execution.test.ts
checksum: d63e7253b2c8eb4da3238fdf78b66dfbad8e6340fb6ff0b4bcb6ae5cafba1328
- filename: packages/contentstack-clone/test/commands/cm/stacks/clone.test.ts
checksum: 577aa1cba4e06b3c864c568853692eeaf6eee276b6eb3e040df112259118f4c4
- filename: packages/contentstack-clone/src/core/util/clone-handler.ts
checksum: b34987603f2e53c4b5d3753a4b5f4370fcb6d3cc9181b953de13fcc7214648a1
checksum: faa364dac78a89d142916b71b5ceba7fdc80acbf8dc71f15dfb38d622c9dc664
version: '1.0'
43 changes: 6 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 24 additions & 72 deletions packages/contentstack-export-to-csv/README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,40 @@
# @contentstack/cli-cm-export-to-csv
@contentstack/cli-cm-export-to-csv
=============

Export entries, taxonomies, terms, or organization users to CSV files.
The cm:export-to-csv command allows you to export the following data into a CSV file:
* Multiple stack’s content and structure (schema)
* [Organization users’ details](https://www.contentstack.com/docs/owners-and-admins/organization-users/)

> **Note**: This is a TypeScript rewrite of the original `contentstack-export-to-csv` package.
To be able to export the content of a stack, you need to have access to it. Likewise, to export an organization’s user data, you need to be the “[owner](https://www.contentstack.com/docs/owners-and-admins/organization-roles/#organization-owner)” or an “[admin](https://www.contentstack.com/docs/owners-and-admins/organization-roles/#organization-admin)” user of that organization.

## Installation
Refer to the [Export Content to .CSV](https://www.contentstack.com/docs/developers/cli/export-content-to-csv-file/) file guide to learn more.

```sh-session
$ npm install -g @contentstack/cli-cm-export-to-csv
```

## Usage
[![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE)

* [Usage](#usage)
* [Commands](#commands)
# Usage
```sh-session
$ csdx cm:export-to-csv [OPTIONS]
$ npm install -g @contentstack/cli-cm-export-to-csv
$ csdx COMMAND
running command...
$ csdx (-v|--version|version)
@contentstack/cli-cm-export-to-csv/0.1.0-beta linux-x64 node-v12.18.4
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
...
```

## Commands
# Commands
* [`csdx cm:export-to-csv`](#csdx-cmexport-to-csv)

### `csdx cm:export-to-csv`

Export entries, taxonomies, terms, or organization users to CSV.
Export entries or organization users to csv using this command

```
USAGE
$ csdx cm:export-to-csv [--action <entries|users|teams|taxonomies>] [--alias <alias>]
[--org <org-uid>] [--stack-api-key <api-key>] [--locale <locale>]
[--content-type <uid>] [--branch <branch>] [--delimiter <char>]

FLAGS
-a, --alias=<value> Alias of the management token
-k, --stack-api-key=<value> API Key of the source stack
-n, --stack-name=<value> Name of the stack for CSV filename
--action=<option> Export action [options: entries, users, teams, taxonomies]
--branch=<value> Branch from which entries will be exported
--content-type=<value> Content type of entries to export
--delimiter=<value> [default: ,] CSV delimiter character
--fallback-locale=<value> Fallback locale for taxonomy export
--include-fallback Include fallback locale data for taxonomies
--locale=<value> Locale of entries to export
--org=<value> Organization UID
--org-name=<value> Organization name for CSV filename
--taxonomy-uid=<value> Taxonomy UID for specific taxonomy export
--team-uid=<value> Team UID for specific team export

EXAMPLES
$ csdx cm:export-to-csv

$ csdx cm:export-to-csv --action entries --locale en-us --alias my-token --content-type blog_post

$ csdx cm:export-to-csv --action users --org blt123456789

$ csdx cm:export-to-csv --action teams --org blt123456789

$ csdx cm:export-to-csv --action taxonomies --alias my-token --taxonomy-uid categories
```

## Output

CSV files are written to a `./data/` directory in the current working directory.

| Action | Output File Pattern |
|--------|---------------------|
| entries | `{stackName}_{contentType}_{locale}_entries_export.csv` |
| users | `{orgName}_users_export.csv` |
| teams | `{orgName}_teams_export.csv` |
| taxonomies | `{stackName}_taxonomies.csv` |

## Development

```sh-session
# Install dependencies
$ pnpm install

# Build
$ pnpm build

# Run tests
$ pnpm test

# Lint
$ pnpm lint
```

## License

MIT
_See code: [src/commands/cm/export-to-csv.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-export-to-csv/src/commands/cm/export-to-csv.js)_
10 changes: 5 additions & 5 deletions packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"files": [
"/bin",
"/dist",
"/lib",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
],
Expand All @@ -51,10 +51,10 @@
"csv"
],
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"oclif": {
"commands": "./dist/commands",
"commands": "./lib/commands",
"bin": "csdx",
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-export-to-csv/<%- commandPath %>"
},
Expand All @@ -66,7 +66,7 @@
"repository": "https://github.com/contentstack/cli",
"scripts": {
"build": "npm run clean && npm run compile",
"clean": "rm -rf ./dist ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
"clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
"compile": "tsc -b tsconfig.json",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@contentstack/cli-utilities';

import config from '../../config';
import { messages } from '../../messages';
import { BaseCommand } from '../../base-command';
import {
startupQuestions,
Expand Down Expand Up @@ -59,38 +60,11 @@ import type {
TaxonomyPayload,
TaxonomyLocaleOptions,
EnvironmentMap,
TokensMap,
BranchExistsResult,
ContentTypeItem,
} from '../../types';

/**
* Token configuration from config handler.
*/
interface TokenConfig {
apiKey: string;
token: string;
}

/**
* Tokens map from config handler.
*/
interface TokensMap {
[alias: string]: TokenConfig;
}

/**
* Branch existence check result.
*/
interface BranchExistsResult {
errorCode?: string;
errorMessage?: string;
}

/**
* Content type item from API.
*/
interface ContentTypeItem {
uid: string;
}

export default class ExportToCsvCommand extends BaseCommand {
static readonly description = 'Export entries, taxonomies, terms or organization users to csv using this command';

Expand Down Expand Up @@ -229,7 +203,7 @@ export default class ExportToCsvCommand extends BaseCommand {

if (!isAuthenticated()) {
log.debug('User not authenticated', this.commandContext);
this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
this.error(messages.ERROR_NOT_LOGGED_IN, {
exit: 2,
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
});
Expand All @@ -245,7 +219,7 @@ export default class ExportToCsvCommand extends BaseCommand {
}

switch (action) {
case config.exportEntries:
case messages.ACTION_EXPORT_ENTRIES:
case 'entries': {
await this.exportEntries({
managementAPIClient: managementAPIClient!,
Expand All @@ -261,7 +235,7 @@ export default class ExportToCsvCommand extends BaseCommand {
break;
}

case config.exportUsers:
case messages.ACTION_EXPORT_USERS:
case 'users': {
await this.exportUsers({
managementAPIClient: managementAPIClient!,
Expand All @@ -273,7 +247,7 @@ export default class ExportToCsvCommand extends BaseCommand {
break;
}

case config.exportTeams:
case messages.ACTION_EXPORT_TEAMS:
case 'teams': {
await this.exportTeamsData({
managementAPIClient: managementAPIClient!,
Expand All @@ -286,7 +260,7 @@ export default class ExportToCsvCommand extends BaseCommand {
break;
}

case config.exportTaxonomies:
case messages.ACTION_EXPORT_TAXONOMIES:
case 'taxonomies': {
await this.exportTaxonomiesData({
managementAPIClient: managementAPIClient!,
Expand Down Expand Up @@ -742,7 +716,7 @@ export default class ExportToCsvCommand extends BaseCommand {

if (!isAuthenticated()) {
log.debug('User not authenticated', this.commandContext);
this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
this.error(messages.ERROR_NOT_LOGGED_IN, {
exit: 2,
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
});
Expand Down
9 changes: 0 additions & 9 deletions packages/contentstack-export-to-csv/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@

const config = {
limit: 100,
cancelString: 'Cancel and Exit',
exportEntries: 'Export entries to a .CSV file',
exportUsers: "Export organization users' data to a .CSV file",
exportTeams: "Export organization teams' data to a .CSV file",
exportTaxonomies: 'Export taxonomies to a .CSV file',
adminError: "Unable to export data. Make sure you're an admin or owner of this organization",
organizationNameRegex: /'/g,
CLI_EXPORT_CSV_LOGIN_FAILED: 'You need to login to execute this command. See: auth:login --help',
CLI_EXPORT_CSV_ENTRIES_ERROR: 'You need to either login or provide a management token to execute this command',
CLI_EXPORT_CSV_API_FAILED: 'Something went wrong! Please try again',
};

export default config;
8 changes: 8 additions & 0 deletions packages/contentstack-export-to-csv/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export const messages = {
FLAG_DELIMITER:
"[Optional] Provide a delimiter to separate individual data fields within the CSV file. For example: cm:export-to-csv --delimiter '|'",

// Action choices for interactive prompts
ACTION_EXPORT_ENTRIES: 'Export entries to a .CSV file',
ACTION_EXPORT_USERS: "Export organization users' data to a .CSV file",
ACTION_EXPORT_TEAMS: "Export organization teams' data to a .CSV file",
ACTION_EXPORT_TAXONOMIES: 'Export taxonomies to a .CSV file',
ACTION_CANCEL: 'Cancel and Exit',

// Error messages
ERROR_NOT_LOGGED_IN: 'You need to either login or provide a management token to execute this command',
ERROR_LOGIN_REQUIRED: 'You need to login to execute this command. See: auth:login --help',
Expand All @@ -35,6 +42,7 @@ export const messages = {
ERROR_ORG_NOT_FOUND: 'Org UID not found',
ERROR_MANAGEMENT_TOKEN_NOT_FOUND: 'The provided management token alias was not found in your config',
ERROR_MANAGEMENT_TOKEN_INVALID: 'Management token or stack API key is invalid',
ERROR_ADMIN_ACCESS_DENIED: "Unable to export data. Make sure you're an admin or owner of this organization",

// Info messages
INFO_NO_TAXONOMIES: 'No taxonomies found!',
Expand Down
Loading
Loading