@contentstack/cli-cm-export-to-csv 1.3.9 → 1.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/oclif.manifest.json +9 -1
- package/package.json +2 -1
- package/src/commands/cm/export-to-csv.js +30 -8
- package/src/util/index.js +17 -4
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.10",
|
|
3
3
|
"commands": {
|
|
4
4
|
"cm:export-to-csv": {
|
|
5
5
|
"id": "cm:export-to-csv",
|
|
@@ -58,6 +58,14 @@
|
|
|
58
58
|
"required": false,
|
|
59
59
|
"multiple": false
|
|
60
60
|
},
|
|
61
|
+
"stack-api-key": {
|
|
62
|
+
"name": "stack-api-key",
|
|
63
|
+
"type": "option",
|
|
64
|
+
"char": "k",
|
|
65
|
+
"description": "API key of the source stack",
|
|
66
|
+
"required": false,
|
|
67
|
+
"multiple": false
|
|
68
|
+
},
|
|
61
69
|
"org-name": {
|
|
62
70
|
"name": "org-name",
|
|
63
71
|
"type": "option",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-export-to-csv",
|
|
3
3
|
"description": "Export entities to csv",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.10",
|
|
5
5
|
"author": "Abhinav Gupta @abhinav-from-contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"postpack": "rm -f oclif.manifest.json",
|
|
45
45
|
"prepack": "oclif manifest && oclif readme",
|
|
46
46
|
"test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
|
|
47
|
+
"test:unit": "nyc mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.js\"",
|
|
47
48
|
"version": "oclif readme && git add README.md",
|
|
48
49
|
"clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
|
|
49
50
|
},
|
|
@@ -33,6 +33,12 @@ class ExportToCsvCommand extends Command {
|
|
|
33
33
|
required: false,
|
|
34
34
|
description: 'Name of the stack that needs to be created as csv filename.',
|
|
35
35
|
}),
|
|
36
|
+
'stack-api-key': flags.string({
|
|
37
|
+
char: 'k',
|
|
38
|
+
multiple: false,
|
|
39
|
+
required: false,
|
|
40
|
+
description: 'API key of the source stack',
|
|
41
|
+
}),
|
|
36
42
|
'org-name': flags.string({
|
|
37
43
|
multiple: false,
|
|
38
44
|
required: false,
|
|
@@ -64,6 +70,7 @@ class ExportToCsvCommand extends Command {
|
|
|
64
70
|
action: actionFlag,
|
|
65
71
|
'org-name': orgName,
|
|
66
72
|
'stack-name': stackName,
|
|
73
|
+
'stack-api-key': stackAPIKey,
|
|
67
74
|
locale: locale,
|
|
68
75
|
'content-type': contentTypesFlag,
|
|
69
76
|
alias: managementTokenAlias,
|
|
@@ -119,8 +126,11 @@ class ExportToCsvCommand extends Command {
|
|
|
119
126
|
} else {
|
|
120
127
|
organization = await util.chooseOrganization(managementAPIClient); // prompt for organization
|
|
121
128
|
}
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
if (!stackAPIKey) {
|
|
130
|
+
stack = await util.chooseStack(managementAPIClient, organization.uid); // prompt for stack
|
|
131
|
+
} else {
|
|
132
|
+
stack = await util.chooseStack(managementAPIClient, organization.uid, stackAPIKey);
|
|
133
|
+
}
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
stackAPIClient = this.getStackClient(managementAPIClient, stack);
|
|
@@ -156,6 +166,19 @@ class ExportToCsvCommand extends Command {
|
|
|
156
166
|
|
|
157
167
|
if (contentTypesFlag) {
|
|
158
168
|
contentTypes = contentTypesFlag.split(',').map(this.snakeCase);
|
|
169
|
+
const contentTypesArray = await stackAPIClient
|
|
170
|
+
.contentType()
|
|
171
|
+
.query()
|
|
172
|
+
.find()
|
|
173
|
+
.then((res) => res.items.map((contentType) => contentType.uid));
|
|
174
|
+
|
|
175
|
+
const doesContentTypeExist = contentTypesArray.includes(contentTypesFlag);
|
|
176
|
+
|
|
177
|
+
if (!doesContentTypeExist) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`The Content Type ${contentTypesFlag} was not found. Please try again. Content Type is not valid.`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
159
182
|
} else {
|
|
160
183
|
for (let index = 0; index <= contentTypeCount / 100; index++) {
|
|
161
184
|
const contentTypesMap = await util.getContentTypes(stackAPIClient, index);
|
|
@@ -193,12 +216,11 @@ class ExportToCsvCommand extends Command {
|
|
|
193
216
|
);
|
|
194
217
|
flatEntries = flatEntries.concat(flatEntriesResult);
|
|
195
218
|
}
|
|
196
|
-
let fileName = `${stack.name}_${contentType}_${language.code}_entries_export.csv`;
|
|
197
|
-
|
|
219
|
+
let fileName = `${stackName ? stackName : stack.name}_${contentType}_${language.code}_entries_export.csv`;
|
|
198
220
|
util.write(this, flatEntries, fileName, 'entries'); // write to file
|
|
199
221
|
}
|
|
200
222
|
} catch (error) {
|
|
201
|
-
|
|
223
|
+
cliux.error(util.formatError(error));
|
|
202
224
|
}
|
|
203
225
|
break;
|
|
204
226
|
}
|
|
@@ -225,13 +247,13 @@ class ExportToCsvCommand extends Command {
|
|
|
225
247
|
const mappedRoles = util.getMappedRoles(orgRoles);
|
|
226
248
|
const listOfUsers = util.cleanOrgUsers(orgUsers, mappedUsers, mappedRoles);
|
|
227
249
|
const fileName = `${util.kebabize(
|
|
228
|
-
organization.name.replace(config.organizationNameRegex, ''),
|
|
250
|
+
(orgName ? orgName : organization.name).replace(config.organizationNameRegex, ''),
|
|
229
251
|
)}_users_export.csv`;
|
|
230
252
|
|
|
231
253
|
util.write(this, listOfUsers, fileName, 'organization details');
|
|
232
254
|
} catch (error) {
|
|
233
255
|
if (error.message || error.errorMessage) {
|
|
234
|
-
|
|
256
|
+
cliux.error(util.formatError(error));
|
|
235
257
|
}
|
|
236
258
|
}
|
|
237
259
|
break;
|
|
@@ -239,7 +261,7 @@ class ExportToCsvCommand extends Command {
|
|
|
239
261
|
}
|
|
240
262
|
} catch (error) {
|
|
241
263
|
if (error.message || error.errorMessage) {
|
|
242
|
-
|
|
264
|
+
cliux.error(util.formatError(error));
|
|
243
265
|
}
|
|
244
266
|
}
|
|
245
267
|
}
|
package/src/util/index.js
CHANGED
|
@@ -98,13 +98,24 @@ function getOrganizationsWhereUserIsAdmin(managementAPIClient) {
|
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
function chooseStack(managementAPIClient, orgUid) {
|
|
101
|
+
function chooseStack(managementAPIClient, orgUid, stackApiKey) {
|
|
102
102
|
return new Promise(async (resolve, reject) => {
|
|
103
103
|
try {
|
|
104
104
|
let stacks = await getStacks(managementAPIClient, orgUid);
|
|
105
|
+
|
|
106
|
+
if (stackApiKey) {
|
|
107
|
+
const stackName = Object.keys(stacks).find((key) => stacks[key] === stackApiKey);
|
|
108
|
+
|
|
109
|
+
if (stackName) {
|
|
110
|
+
resolve({ name: stackName, apiKey: stackApiKey });
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error('Could not find stack');
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
105
117
|
let stackList = Object.keys(stacks);
|
|
106
118
|
stackList.push(config.cancelString);
|
|
107
|
-
|
|
108
119
|
let _chooseStack = [
|
|
109
120
|
{
|
|
110
121
|
type: 'list',
|
|
@@ -242,7 +253,9 @@ function getContentTypes(stackAPIClient, skip) {
|
|
|
242
253
|
});
|
|
243
254
|
resolve(result);
|
|
244
255
|
})
|
|
245
|
-
.catch((error) =>
|
|
256
|
+
.catch((error) => {
|
|
257
|
+
reject(error);
|
|
258
|
+
});
|
|
246
259
|
});
|
|
247
260
|
}
|
|
248
261
|
|
|
@@ -397,7 +410,7 @@ function write(command, entries, fileName, message) {
|
|
|
397
410
|
process.chdir(directory);
|
|
398
411
|
}
|
|
399
412
|
// eslint-disable-next-line no-undef
|
|
400
|
-
|
|
413
|
+
cliux.print(`Writing ${message} to file: ${process.cwd()}${delimeter}${fileName}`);
|
|
401
414
|
fastcsv.writeToPath(fileName, entries, { headers: true });
|
|
402
415
|
}
|
|
403
416
|
|