Skip to content

Commit 020029f

Browse files
committed
Resolved review comments
1 parent df4031e commit 020029f

File tree

15 files changed

+210
-290
lines changed

15 files changed

+210
-290
lines changed

.talismanrc

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
fileignoreconfig:
2-
- filename: pnpm-lock.yaml
3-
checksum: 61df9c5119a68d5058fcf232905ed8a76d6cc58406c13207788c7e6a49bf456a
2+
- filename: packages/contentstack-export-to-csv/src/types/index.ts
3+
checksum: 28c19efb0c13969d40df964f86fa6de444316e320801f19dee7392df7a36851d
44
- filename: package-lock.json
5-
checksum: e8fd31693cede1935a30511076c1c442e7a50c246f8d58dcb88ffd3ce04d3cb3
6-
- filename: packages/contentstack-clone/test/commands/stack-clone.test.ts
7-
checksum: 889b9d64434261910a50c14e039e6256fd6157727076308f39bba87b854d459a
8-
- filename: packages/contentstack-clone/.eslintrc
9-
checksum: a7230ffa600c58047ac73f2dec7a23ca5862e36e68f04f2671379496739bd818
10-
- filename: packages/contentstack-clone/src/types/clone-config.ts
11-
checksum: c22f8b8a592e7b4da967715e595e79a680ab970ca85b65528d5ac318032e1857
12-
- filename: packages/contentstack-clone/test/lib/helpers/command-helpers.test.ts
13-
checksum: 2702c3cedd9def635fa48408a3a4bbab6728ec8a2700af4f8d5ed6bbe2da4faa
14-
- filename: packages/contentstack-clone/test/lib/util/clone-handler.helpers.test.ts
15-
checksum: efd55d08a7b5263e9ba0d871208552c5df941274bc035bac6101ed26b6ba2da4
16-
- filename: packages/contentstack-clone/test/lib/util/clone-handler.branch.test.ts
17-
checksum: 0f1fccb38c89b4baa9fa2b145905b626b5ce9633ae30021676a924fa88aa570c
18-
- filename: packages/contentstack-clone/package.json
19-
checksum: a81ef3f125ddb91a4e13e77745d9c7927f02e3ff17978374560de6f4825db1c9
20-
- filename: packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts
21-
checksum: e3c5be3312013df0c20faca3ff280130f9ce187a4187c5045b016b0c7b489b46
22-
- filename: packages/contentstack-clone/test/lib/util/clone-handler.execution.test.ts
23-
checksum: d63e7253b2c8eb4da3238fdf78b66dfbad8e6340fb6ff0b4bcb6ae5cafba1328
24-
- filename: packages/contentstack-clone/test/commands/cm/stacks/clone.test.ts
25-
checksum: 577aa1cba4e06b3c864c568853692eeaf6eee276b6eb3e040df112259118f4c4
26-
- filename: packages/contentstack-clone/src/core/util/clone-handler.ts
27-
checksum: b34987603f2e53c4b5d3753a4b5f4370fcb6d3cc9181b953de13fcc7214648a1
5+
checksum: faa364dac78a89d142916b71b5ceba7fdc80acbf8dc71f15dfb38d622c9dc664
286
version: '1.0'

package-lock.json

Lines changed: 6 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,40 @@
1-
# @contentstack/cli-cm-export-to-csv
1+
@contentstack/cli-cm-export-to-csv
2+
=============
23

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

5-
> **Note**: This is a TypeScript rewrite of the original `contentstack-export-to-csv` package.
8+
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.
69

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

9-
```sh-session
10-
$ npm install -g @contentstack/cli-cm-export-to-csv
11-
```
12-
13-
## Usage
12+
[![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE)
1413

14+
* [Usage](#usage)
15+
* [Commands](#commands)
16+
# Usage
1517
```sh-session
16-
$ csdx cm:export-to-csv [OPTIONS]
18+
$ npm install -g @contentstack/cli-cm-export-to-csv
19+
$ csdx COMMAND
20+
running command...
21+
$ csdx (-v|--version|version)
22+
@contentstack/cli-cm-export-to-csv/0.1.0-beta linux-x64 node-v12.18.4
23+
$ csdx --help [COMMAND]
24+
USAGE
25+
$ csdx COMMAND
26+
...
1727
```
18-
19-
## Commands
28+
# Commands
29+
* [`csdx cm:export-to-csv`](#csdx-cmexport-to-csv)
2030

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

23-
Export entries, taxonomies, terms, or organization users to CSV.
33+
Export entries or organization users to csv using this command
2434

2535
```
2636
USAGE
27-
$ csdx cm:export-to-csv [--action <entries|users|teams|taxonomies>] [--alias <alias>]
28-
[--org <org-uid>] [--stack-api-key <api-key>] [--locale <locale>]
29-
[--content-type <uid>] [--branch <branch>] [--delimiter <char>]
30-
31-
FLAGS
32-
-a, --alias=<value> Alias of the management token
33-
-k, --stack-api-key=<value> API Key of the source stack
34-
-n, --stack-name=<value> Name of the stack for CSV filename
35-
--action=<option> Export action [options: entries, users, teams, taxonomies]
36-
--branch=<value> Branch from which entries will be exported
37-
--content-type=<value> Content type of entries to export
38-
--delimiter=<value> [default: ,] CSV delimiter character
39-
--fallback-locale=<value> Fallback locale for taxonomy export
40-
--include-fallback Include fallback locale data for taxonomies
41-
--locale=<value> Locale of entries to export
42-
--org=<value> Organization UID
43-
--org-name=<value> Organization name for CSV filename
44-
--taxonomy-uid=<value> Taxonomy UID for specific taxonomy export
45-
--team-uid=<value> Team UID for specific team export
46-
47-
EXAMPLES
4837
$ csdx cm:export-to-csv
49-
50-
$ csdx cm:export-to-csv --action entries --locale en-us --alias my-token --content-type blog_post
51-
52-
$ csdx cm:export-to-csv --action users --org blt123456789
53-
54-
$ csdx cm:export-to-csv --action teams --org blt123456789
55-
56-
$ csdx cm:export-to-csv --action taxonomies --alias my-token --taxonomy-uid categories
57-
```
58-
59-
## Output
60-
61-
CSV files are written to a `./data/` directory in the current working directory.
62-
63-
| Action | Output File Pattern |
64-
|--------|---------------------|
65-
| entries | `{stackName}_{contentType}_{locale}_entries_export.csv` |
66-
| users | `{orgName}_users_export.csv` |
67-
| teams | `{orgName}_teams_export.csv` |
68-
| taxonomies | `{stackName}_taxonomies.csv` |
69-
70-
## Development
71-
72-
```sh-session
73-
# Install dependencies
74-
$ pnpm install
75-
76-
# Build
77-
$ pnpm build
78-
79-
# Run tests
80-
$ pnpm test
81-
82-
# Lint
83-
$ pnpm lint
8438
```
8539

86-
## License
87-
88-
MIT
40+
_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)_

packages/contentstack-export-to-csv/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"files": [
4040
"/bin",
41-
"/dist",
41+
"/lib",
4242
"/npm-shrinkwrap.json",
4343
"/oclif.manifest.json"
4444
],
@@ -51,10 +51,10 @@
5151
"csv"
5252
],
5353
"license": "MIT",
54-
"main": "./dist/index.js",
55-
"types": "./dist/index.d.ts",
54+
"main": "./lib/index.js",
55+
"types": "./lib/index.d.ts",
5656
"oclif": {
57-
"commands": "./dist/commands",
57+
"commands": "./lib/commands",
5858
"bin": "csdx",
5959
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-export-to-csv/<%- commandPath %>"
6060
},
@@ -66,7 +66,7 @@
6666
"repository": "https://github.com/contentstack/cli",
6767
"scripts": {
6868
"build": "npm run clean && npm run compile",
69-
"clean": "rm -rf ./dist ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
69+
"clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
7070
"compile": "tsc -b tsconfig.json",
7171
"lint": "eslint src/**/*.ts",
7272
"lint:fix": "eslint src/**/*.ts --fix",

packages/contentstack-export-to-csv/src/commands/cm/export-to-csv.ts

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '@contentstack/cli-utilities';
1919

2020
import config from '../../config';
21+
import { messages } from '../../messages';
2122
import { BaseCommand } from '../../base-command';
2223
import {
2324
startupQuestions,
@@ -59,38 +60,11 @@ import type {
5960
TaxonomyPayload,
6061
TaxonomyLocaleOptions,
6162
EnvironmentMap,
63+
TokensMap,
64+
BranchExistsResult,
65+
ContentTypeItem,
6266
} from '../../types';
6367

64-
/**
65-
* Token configuration from config handler.
66-
*/
67-
interface TokenConfig {
68-
apiKey: string;
69-
token: string;
70-
}
71-
72-
/**
73-
* Tokens map from config handler.
74-
*/
75-
interface TokensMap {
76-
[alias: string]: TokenConfig;
77-
}
78-
79-
/**
80-
* Branch existence check result.
81-
*/
82-
interface BranchExistsResult {
83-
errorCode?: string;
84-
errorMessage?: string;
85-
}
86-
87-
/**
88-
* Content type item from API.
89-
*/
90-
interface ContentTypeItem {
91-
uid: string;
92-
}
93-
9468
export default class ExportToCsvCommand extends BaseCommand {
9569
static readonly description = 'Export entries, taxonomies, terms or organization users to csv using this command';
9670

@@ -229,7 +203,7 @@ export default class ExportToCsvCommand extends BaseCommand {
229203

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

247221
switch (action) {
248-
case config.exportEntries:
222+
case messages.ACTION_EXPORT_ENTRIES:
249223
case 'entries': {
250224
await this.exportEntries({
251225
managementAPIClient: managementAPIClient!,
@@ -261,7 +235,7 @@ export default class ExportToCsvCommand extends BaseCommand {
261235
break;
262236
}
263237

264-
case config.exportUsers:
238+
case messages.ACTION_EXPORT_USERS:
265239
case 'users': {
266240
await this.exportUsers({
267241
managementAPIClient: managementAPIClient!,
@@ -273,7 +247,7 @@ export default class ExportToCsvCommand extends BaseCommand {
273247
break;
274248
}
275249

276-
case config.exportTeams:
250+
case messages.ACTION_EXPORT_TEAMS:
277251
case 'teams': {
278252
await this.exportTeamsData({
279253
managementAPIClient: managementAPIClient!,
@@ -286,7 +260,7 @@ export default class ExportToCsvCommand extends BaseCommand {
286260
break;
287261
}
288262

289-
case config.exportTaxonomies:
263+
case messages.ACTION_EXPORT_TAXONOMIES:
290264
case 'taxonomies': {
291265
await this.exportTaxonomiesData({
292266
managementAPIClient: managementAPIClient!,
@@ -742,7 +716,7 @@ export default class ExportToCsvCommand extends BaseCommand {
742716

743717
if (!isAuthenticated()) {
744718
log.debug('User not authenticated', this.commandContext);
745-
this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
719+
this.error(messages.ERROR_NOT_LOGGED_IN, {
746720
exit: 2,
747721
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
748722
});

packages/contentstack-export-to-csv/src/config/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55

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

2011
export default config;

packages/contentstack-export-to-csv/src/messages/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export const messages = {
2525
FLAG_DELIMITER:
2626
"[Optional] Provide a delimiter to separate individual data fields within the CSV file. For example: cm:export-to-csv --delimiter '|'",
2727

28+
// Action choices for interactive prompts
29+
ACTION_EXPORT_ENTRIES: 'Export entries to a .CSV file',
30+
ACTION_EXPORT_USERS: "Export organization users' data to a .CSV file",
31+
ACTION_EXPORT_TEAMS: "Export organization teams' data to a .CSV file",
32+
ACTION_EXPORT_TAXONOMIES: 'Export taxonomies to a .CSV file',
33+
ACTION_CANCEL: 'Cancel and Exit',
34+
2835
// Error messages
2936
ERROR_NOT_LOGGED_IN: 'You need to either login or provide a management token to execute this command',
3037
ERROR_LOGIN_REQUIRED: 'You need to login to execute this command. See: auth:login --help',
@@ -35,6 +42,7 @@ export const messages = {
3542
ERROR_ORG_NOT_FOUND: 'Org UID not found',
3643
ERROR_MANAGEMENT_TOKEN_NOT_FOUND: 'The provided management token alias was not found in your config',
3744
ERROR_MANAGEMENT_TOKEN_INVALID: 'Management token or stack API key is invalid',
45+
ERROR_ADMIN_ACCESS_DENIED: "Unable to export data. Make sure you're an admin or owner of this organization",
3846

3947
// Info messages
4048
INFO_NO_TAXONOMIES: 'No taxonomies found!',

0 commit comments

Comments
 (0)