@contentstack/cli-cm-seed 1.4.11 → 1.4.13
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/README.md +2 -0
- package/lib/commands/cm/stacks/seed.js +18 -2
- package/lib/seed/contentstack/client.d.ts +2 -1
- package/lib/seed/contentstack/client.js +30 -15
- package/lib/seed/importer.d.ts +1 -0
- package/lib/seed/importer.js +5 -3
- package/lib/seed/index.d.ts +3 -0
- package/lib/seed/index.js +19 -5
- package/oclif.manifest.json +8 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ USAGE
|
|
|
22
22
|
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
|
|
23
23
|
|
|
24
24
|
FLAGS
|
|
25
|
+
-a, --alias=<value> Alias of the management token
|
|
25
26
|
-k, --stack-api-key=<value> Provide stack api key to seed content to
|
|
26
27
|
-n, --stack-name=<value> Name of a new stack that needs to be created.
|
|
27
28
|
-o, --org=<value> Provide Organization UID to create a new stack
|
|
@@ -56,6 +57,7 @@ USAGE
|
|
|
56
57
|
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
|
|
57
58
|
|
|
58
59
|
FLAGS
|
|
60
|
+
-a, --alias=<value> Alias of the management token
|
|
59
61
|
-k, --stack-api-key=<value> Provide stack api key to seed content to
|
|
60
62
|
-n, --stack-name=<value> Name of a new stack that needs to be created.
|
|
61
63
|
-o, --org=<value> Provide Organization UID to create a new stack
|
|
@@ -7,8 +7,9 @@ class SeedCommand extends cli_command_1.Command {
|
|
|
7
7
|
async run() {
|
|
8
8
|
try {
|
|
9
9
|
const { flags: seedFlags } = await this.parse(SeedCommand);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const managementTokenAlias = seedFlags.alias;
|
|
11
|
+
if (!(0, cli_utilities_1.isAuthenticated)() && !managementTokenAlias) {
|
|
12
|
+
this.error('You need to login or provide an alias for the management token. See: auth:login --help', {
|
|
12
13
|
exit: 2,
|
|
13
14
|
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
|
|
14
15
|
});
|
|
@@ -24,13 +25,24 @@ class SeedCommand extends cli_command_1.Command {
|
|
|
24
25
|
fetchLimit: seedFlags['fetch-limit'],
|
|
25
26
|
skipStackConfirmation: seedFlags['yes'],
|
|
26
27
|
isAuthenticated: (0, cli_utilities_1.isAuthenticated)(),
|
|
28
|
+
alias: managementTokenAlias,
|
|
27
29
|
};
|
|
30
|
+
const listOfTokens = cli_utilities_1.configHandler.get('tokens');
|
|
31
|
+
if (managementTokenAlias && listOfTokens[managementTokenAlias]) {
|
|
32
|
+
options.managementToken = listOfTokens[managementTokenAlias].token;
|
|
33
|
+
options.stackUid = listOfTokens[managementTokenAlias].apiKey;
|
|
34
|
+
}
|
|
28
35
|
const seeder = new seed_1.default(options);
|
|
29
36
|
const result = await seeder.run();
|
|
30
37
|
return result;
|
|
31
38
|
}
|
|
32
39
|
catch (error) {
|
|
33
40
|
let errorObj = error;
|
|
41
|
+
if (errorObj.message !== undefined) {
|
|
42
|
+
cli_utilities_1.cliux.loader();
|
|
43
|
+
cli_utilities_1.cliux.print(`Error: ${errorObj.message}`, { color: 'red' });
|
|
44
|
+
this.exit(1);
|
|
45
|
+
}
|
|
34
46
|
this.error(errorObj, { exit: 1, suggestions: errorObj.suggestions });
|
|
35
47
|
}
|
|
36
48
|
}
|
|
@@ -96,5 +108,9 @@ SeedCommand.flags = {
|
|
|
96
108
|
exclusive: ['org', 'name'],
|
|
97
109
|
parse: (0, cli_utilities_1.printFlagDeprecation)(['s', 'stack'], ['-k', 'stack-api-key']),
|
|
98
110
|
}),
|
|
111
|
+
alias: cli_utilities_1.flags.string({
|
|
112
|
+
char: 'a',
|
|
113
|
+
description: 'Alias of the management token',
|
|
114
|
+
}),
|
|
99
115
|
};
|
|
100
116
|
SeedCommand.aliases = ['cm:seed'];
|
|
@@ -23,9 +23,10 @@ export default class ContentstackClient {
|
|
|
23
23
|
constructor(cmaHost: string, limit: number);
|
|
24
24
|
getOrganization(org_uid: string): Promise<Organization>;
|
|
25
25
|
getOrganizations(skip?: number, organizations?: Organization[]): Promise<Organization[]>;
|
|
26
|
+
private mapOrganization;
|
|
26
27
|
getStack(stackUID: string): Promise<Stack>;
|
|
27
28
|
getStacks(org_uid: string, skip?: number, stacks?: Stack[]): Promise<Stack[]>;
|
|
28
|
-
getContentTypeCount(api_key: string): Promise<number>;
|
|
29
|
+
getContentTypeCount(api_key: string, managementToken?: string): Promise<number>;
|
|
29
30
|
createStack(options: CreateStackOptions): Promise<Stack>;
|
|
30
31
|
private buildError;
|
|
31
32
|
}
|
|
@@ -24,16 +24,20 @@ class ContentstackClient {
|
|
|
24
24
|
async getOrganizations(skip = 0, organizations = []) {
|
|
25
25
|
try {
|
|
26
26
|
const client = await this.instance;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
const configOrgUid = cli_utilities_1.configHandler.get('oauthOrgUid');
|
|
28
|
+
if (configOrgUid) {
|
|
29
|
+
const response = await client.organization(configOrgUid).fetch();
|
|
30
|
+
const mappedOrganization = this.mapOrganization(response);
|
|
31
|
+
organizations.push(mappedOrganization);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const response = await client
|
|
35
|
+
.organization()
|
|
36
|
+
.fetchAll({ limit: this.limit, asc: 'name', include_count: true, skip });
|
|
37
|
+
organizations.push(...response.items.map(this.mapOrganization));
|
|
38
|
+
if (organizations.length < response.count) {
|
|
39
|
+
organizations = await this.getOrganizations(skip + this.limit, organizations);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
return organizations;
|
|
39
43
|
}
|
|
@@ -41,6 +45,13 @@ class ContentstackClient {
|
|
|
41
45
|
throw this.buildError(error);
|
|
42
46
|
}
|
|
43
47
|
}
|
|
48
|
+
mapOrganization(o) {
|
|
49
|
+
return {
|
|
50
|
+
uid: o.uid,
|
|
51
|
+
name: o.name,
|
|
52
|
+
enabled: o.enabled,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
44
55
|
async getStack(stackUID) {
|
|
45
56
|
try {
|
|
46
57
|
const client = await this.instance;
|
|
@@ -66,7 +77,7 @@ class ContentstackClient {
|
|
|
66
77
|
limit: this.limit,
|
|
67
78
|
include_count: true,
|
|
68
79
|
skip: skip,
|
|
69
|
-
query: {}
|
|
80
|
+
query: {},
|
|
70
81
|
})
|
|
71
82
|
.find();
|
|
72
83
|
stacks = stacks.concat(response.items.map((s) => {
|
|
@@ -87,10 +98,14 @@ class ContentstackClient {
|
|
|
87
98
|
throw this.buildError(error);
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
|
-
async getContentTypeCount(api_key) {
|
|
101
|
+
async getContentTypeCount(api_key, managementToken) {
|
|
91
102
|
try {
|
|
92
103
|
const client = await this.instance;
|
|
93
|
-
const response = await client
|
|
104
|
+
const response = await client
|
|
105
|
+
.stack({ api_key: api_key, management_token: managementToken })
|
|
106
|
+
.contentType()
|
|
107
|
+
.query({ include_count: true })
|
|
108
|
+
.find();
|
|
94
109
|
return response.count;
|
|
95
110
|
}
|
|
96
111
|
catch (error) {
|
|
@@ -122,8 +137,8 @@ class ContentstackClient {
|
|
|
122
137
|
}
|
|
123
138
|
buildError(error) {
|
|
124
139
|
var _a;
|
|
125
|
-
const message = ((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.
|
|
126
|
-
const status = error.
|
|
140
|
+
const message = error.errorMessage || ((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.errorMessage) || error.response.statusText;
|
|
141
|
+
const status = error.status;
|
|
127
142
|
return new error_1.default(message, status);
|
|
128
143
|
}
|
|
129
144
|
}
|
package/lib/seed/importer.d.ts
CHANGED
package/lib/seed/importer.js
CHANGED
|
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.run = void 0;
|
|
4
4
|
const process = require("process");
|
|
5
5
|
const path = require("path");
|
|
6
|
+
const cli_cm_import_1 = require("@contentstack/cli-cm-import");
|
|
6
7
|
const STACK_FOLDER = 'stack';
|
|
7
8
|
async function run(options) {
|
|
8
9
|
const importPath = path.resolve(options.tmpPath, STACK_FOLDER);
|
|
10
|
+
const args = options.alias
|
|
11
|
+
? ['-k', options.api_key, '-d', importPath, '--alias', options.alias]
|
|
12
|
+
: ['-k', options.api_key, '-d', importPath];
|
|
9
13
|
process.chdir(options.tmpPath);
|
|
10
|
-
|
|
11
|
-
const { parametersWithAuthToken } = require('@contentstack/cli-cm-import/src/lib/util/import-flags');
|
|
12
|
-
await parametersWithAuthToken(options.api_key, importPath, '', options.cmaHost, '', {});
|
|
14
|
+
await cli_cm_import_1.default.run(args);
|
|
13
15
|
}
|
|
14
16
|
exports.run = run;
|
package/lib/seed/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface ContentModelSeederOptions {
|
|
|
12
12
|
fetchLimit: string | undefined;
|
|
13
13
|
skipStackConfirmation: string | undefined;
|
|
14
14
|
isAuthenticated: boolean | false;
|
|
15
|
+
managementToken?: string | undefined;
|
|
16
|
+
alias?: string | undefined;
|
|
15
17
|
}
|
|
16
18
|
export default class ContentModelSeeder {
|
|
17
19
|
options: ContentModelSeederOptions;
|
|
@@ -21,6 +23,7 @@ export default class ContentModelSeeder {
|
|
|
21
23
|
private readonly _options;
|
|
22
24
|
private ghUsername;
|
|
23
25
|
private ghRepo;
|
|
26
|
+
managementToken?: string | undefined;
|
|
24
27
|
get ghPath(): string;
|
|
25
28
|
constructor(options: ContentModelSeederOptions);
|
|
26
29
|
run(): Promise<{
|
package/lib/seed/index.js
CHANGED
|
@@ -25,6 +25,7 @@ class ContentModelSeeder {
|
|
|
25
25
|
this.ghUsername = gh.username || DEFAULT_OWNER;
|
|
26
26
|
this.ghRepo = gh.repo;
|
|
27
27
|
const limit = Number(this.options.fetchLimit);
|
|
28
|
+
this.managementToken = options.managementToken;
|
|
28
29
|
this.csClient = new client_1.default(options.cmaHost, limit);
|
|
29
30
|
this.ghClient = new client_2.default(this.ghUsername, DEFAULT_STACK_PATTERN);
|
|
30
31
|
}
|
|
@@ -43,7 +44,7 @@ class ContentModelSeeder {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
const tmpPath = await this.downloadRelease();
|
|
46
|
-
cli_utilities_1.cliux.print(`Importing into '${stackResponse.name}'.`);
|
|
47
|
+
cli_utilities_1.cliux.print(`Importing into ${this.managementToken ? 'your stack' : `'${stackResponse.name}'`}.`);
|
|
47
48
|
await importer.run({
|
|
48
49
|
api_key: api_key,
|
|
49
50
|
cdaHost: this.options.cdaHost,
|
|
@@ -51,6 +52,7 @@ class ContentModelSeeder {
|
|
|
51
52
|
master_locale: exports.ENGLISH_LOCALE,
|
|
52
53
|
tmpPath: tmpPath,
|
|
53
54
|
isAuthenticated: this.options.isAuthenticated,
|
|
55
|
+
alias: this.options.alias,
|
|
54
56
|
});
|
|
55
57
|
return { api_key };
|
|
56
58
|
}
|
|
@@ -69,15 +71,26 @@ class ContentModelSeeder {
|
|
|
69
71
|
throw error;
|
|
70
72
|
}
|
|
71
73
|
if (repoExists === false) {
|
|
72
|
-
cli_utilities_1.cliux.error(repoResponseData.status === 403
|
|
74
|
+
cli_utilities_1.cliux.error(repoResponseData.status === 403
|
|
75
|
+
? repoResponseData.statusMessage
|
|
76
|
+
: `Could not find GitHub repository '${this.ghPath}'.`);
|
|
73
77
|
if (this.parent)
|
|
74
78
|
this.parent.exit(1);
|
|
75
79
|
}
|
|
76
80
|
else {
|
|
77
81
|
let organizationResponse;
|
|
78
82
|
let stackResponse;
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
let stack;
|
|
84
|
+
if (this.options.stackUid && this.options.managementToken) {
|
|
85
|
+
stackResponse = {
|
|
86
|
+
isNew: false,
|
|
87
|
+
name: 'your stack',
|
|
88
|
+
uid: this.options.stackUid,
|
|
89
|
+
api_key: this.options.stackUid,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else if (this.options.stackUid) {
|
|
93
|
+
stack = await this.csClient.getStack(this.options.stackUid);
|
|
81
94
|
stackResponse = {
|
|
82
95
|
isNew: false,
|
|
83
96
|
name: stack.name,
|
|
@@ -114,7 +127,8 @@ class ContentModelSeeder {
|
|
|
114
127
|
return newStack.api_key;
|
|
115
128
|
}
|
|
116
129
|
async shouldProceed(api_key) {
|
|
117
|
-
|
|
130
|
+
let count;
|
|
131
|
+
count = await this.csClient.getContentTypeCount(api_key, this.managementToken);
|
|
118
132
|
if (count > 0 && this._options.skipStackConfirmation !== 'yes') {
|
|
119
133
|
const proceed = await (0, interactive_1.inquireProceed)();
|
|
120
134
|
if (!proceed) {
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.13",
|
|
3
3
|
"commands": {
|
|
4
4
|
"cm:stacks:seed": {
|
|
5
5
|
"id": "cm:stacks:seed",
|
|
@@ -89,6 +89,13 @@
|
|
|
89
89
|
"org",
|
|
90
90
|
"name"
|
|
91
91
|
]
|
|
92
|
+
},
|
|
93
|
+
"alias": {
|
|
94
|
+
"name": "alias",
|
|
95
|
+
"type": "option",
|
|
96
|
+
"char": "a",
|
|
97
|
+
"description": "Alias of the management token",
|
|
98
|
+
"multiple": false
|
|
92
99
|
}
|
|
93
100
|
},
|
|
94
101
|
"args": {}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-seed",
|
|
3
3
|
"description": "create a Stack from existing content types, entries, assets, etc.",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.13",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-cm-import": "^1.
|
|
9
|
-
"@contentstack/cli-command": "^1.2.
|
|
10
|
-
"@contentstack/cli-utilities": "^1.
|
|
8
|
+
"@contentstack/cli-cm-import": "^1.7.0",
|
|
9
|
+
"@contentstack/cli-command": "^1.2.11",
|
|
10
|
+
"@contentstack/cli-utilities": "^1.5.1",
|
|
11
11
|
"axios": "1.3.4",
|
|
12
12
|
"inquirer": "8.2.4",
|
|
13
13
|
"mkdirp": "^1.0.4",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"/npm-shrinkwrap.json",
|
|
42
42
|
"/oclif.manifest.json"
|
|
43
43
|
],
|
|
44
|
+
"types": "./types/index.d.ts",
|
|
44
45
|
"homepage": "https://github.com/contentstack/cli",
|
|
45
46
|
"keywords": [
|
|
46
47
|
"contentstack",
|