@contentstack/cli-cm-seed 1.0.6 → 1.0.9
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 +8 -3
- package/lib/commands/cm/seed.d.ts +7 -1
- package/lib/commands/cm/seed.js +36 -1
- package/lib/seed/contentstack/client.d.ts +4 -1
- package/lib/seed/contentstack/client.js +38 -5
- package/lib/seed/index.d.ts +9 -2
- package/lib/seed/index.js +29 -8
- package/lib/seed/interactive.d.ts +1 -1
- package/lib/seed/interactive.js +20 -16
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,15 +21,20 @@ USAGE
|
|
|
21
21
|
$ csdx cm:seed
|
|
22
22
|
|
|
23
23
|
OPTIONS
|
|
24
|
-
-
|
|
24
|
+
-n, --stack-name=stack-name Name of a new stack that needs to be created.
|
|
25
|
+
-o, --org=org Provide Organization UID to create a new stack
|
|
26
|
+
-r, --repo=repo GitHub account or GitHub account/repository
|
|
27
|
+
-s, --stack=stack Provide stack UID to seed content to
|
|
25
28
|
|
|
26
29
|
EXAMPLES
|
|
27
30
|
$ csdx cm:seed
|
|
28
31
|
$ csdx cm:seed -r "account"
|
|
29
32
|
$ csdx cm:seed -r "account/repository"
|
|
33
|
+
$ csdx cm:seed -r "account/repository" -s "stack-uid" //seed content into specific stack
|
|
34
|
+
$ csdx cm:seed -r "account/repository" -o "your-org-uid" -n "stack-name" //create a new stack in given org uid
|
|
30
35
|
```
|
|
31
36
|
|
|
32
|
-
_See code: [src/commands/cm/seed.ts](https://github.com/contentstack/cli/blob/v1.0.
|
|
37
|
+
_See code: [src/commands/cm/seed.ts](https://github.com/contentstack/cli/blob/v1.0.9/src/commands/cm/seed.ts)_
|
|
33
38
|
<!-- commandsstop -->
|
|
34
39
|
|
|
35
40
|
## Advanced Flags
|
|
@@ -71,4 +76,4 @@ $ csdx cm:seed -r "account/repository"
|
|
|
71
76
|
```
|
|
72
77
|
|
|
73
78
|
## Documentation
|
|
74
|
-
To get more detailed documentation of this command, visit the Seed command documentation on our docs.
|
|
79
|
+
To get more detailed documentation of this command, visit the Seed command documentation on our [docs](https://www.contentstack.com/docs/developers/cli/import-content-using-the-seed-command/).
|
|
@@ -4,6 +4,12 @@ export default class SeedCommand extends Command {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
repo: flags.IOptionFlag<string | undefined>;
|
|
7
|
+
org: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
stack: flags.IOptionFlag<string | undefined>;
|
|
9
|
+
'stack-name': flags.IOptionFlag<string | undefined>;
|
|
10
|
+
'fetch-limit': flags.IOptionFlag<string | undefined>;
|
|
7
11
|
};
|
|
8
|
-
run(): Promise<
|
|
12
|
+
run(): Promise<{
|
|
13
|
+
api_key: string;
|
|
14
|
+
} | undefined>;
|
|
9
15
|
}
|
package/lib/commands/cm/seed.js
CHANGED
|
@@ -14,9 +14,14 @@ class SeedCommand extends cli_command_1.Command {
|
|
|
14
14
|
cmaHost: this.cmaHost,
|
|
15
15
|
authToken: this.authToken,
|
|
16
16
|
gitHubPath: flags.repo,
|
|
17
|
+
orgUid: flags.org,
|
|
18
|
+
stackUid: flags.stack,
|
|
19
|
+
stackName: flags['stack-name'],
|
|
20
|
+
fetchLimit: flags['fetch-limit'],
|
|
17
21
|
};
|
|
18
22
|
const seeder = new seed_1.default(options);
|
|
19
|
-
await seeder.run();
|
|
23
|
+
const result = await seeder.run();
|
|
24
|
+
return result;
|
|
20
25
|
}
|
|
21
26
|
catch (error) {
|
|
22
27
|
this.error(error, { exit: 1, suggestions: error.suggestions });
|
|
@@ -29,6 +34,8 @@ SeedCommand.examples = [
|
|
|
29
34
|
'$ csdx cm:seed',
|
|
30
35
|
'$ csdx cm:seed -r "account"',
|
|
31
36
|
'$ csdx cm:seed -r "account/repository"',
|
|
37
|
+
'$ csdx cm:seed -r "account/repository" -s "stack-uid" //seed content into specific stack',
|
|
38
|
+
'$ csdx cm:seed -r "account/repository" -o "your-org-uid" -n "stack-name" //create a new stack in given org uid',
|
|
32
39
|
];
|
|
33
40
|
SeedCommand.flags = {
|
|
34
41
|
repo: cli_command_1.flags.string({
|
|
@@ -37,4 +44,32 @@ SeedCommand.flags = {
|
|
|
37
44
|
multiple: false,
|
|
38
45
|
required: false,
|
|
39
46
|
}),
|
|
47
|
+
org: cli_command_1.flags.string({
|
|
48
|
+
char: 'o',
|
|
49
|
+
description: 'Provide Organization UID to create a new stack',
|
|
50
|
+
multiple: false,
|
|
51
|
+
required: false,
|
|
52
|
+
exclusive: ['stack'],
|
|
53
|
+
}),
|
|
54
|
+
stack: cli_command_1.flags.string({
|
|
55
|
+
char: 's',
|
|
56
|
+
description: 'Provide stack UID to seed content to',
|
|
57
|
+
multiple: false,
|
|
58
|
+
required: false,
|
|
59
|
+
exclusive: ['org', 'name'],
|
|
60
|
+
}),
|
|
61
|
+
'stack-name': cli_command_1.flags.string({
|
|
62
|
+
char: 'n',
|
|
63
|
+
description: 'Name of a new stack that needs to be created.',
|
|
64
|
+
multiple: false,
|
|
65
|
+
required: false,
|
|
66
|
+
exclusive: ['stack'],
|
|
67
|
+
}),
|
|
68
|
+
'fetch-limit': cli_command_1.flags.string({
|
|
69
|
+
char: 'l',
|
|
70
|
+
description: 'Limit for number of Organizations or stacks to be fetched',
|
|
71
|
+
multiple: false,
|
|
72
|
+
required: false,
|
|
73
|
+
hidden: true,
|
|
74
|
+
}),
|
|
40
75
|
};
|
|
@@ -19,8 +19,11 @@ export interface CreateStackOptions {
|
|
|
19
19
|
}
|
|
20
20
|
export default class ContentstackClient {
|
|
21
21
|
instance: AxiosInstance;
|
|
22
|
-
|
|
22
|
+
limit: number;
|
|
23
|
+
constructor(cmaHost: string, authToken: string, limit: number);
|
|
24
|
+
getOrganization(org_uid: string): Promise<Organization>;
|
|
23
25
|
getOrganizations(): Promise<Organization[]>;
|
|
26
|
+
getStack(stackUID: string): Promise<Stack>;
|
|
24
27
|
getStacks(org_uid: string): Promise<Stack[]>;
|
|
25
28
|
getContentTypeCount(api_key: string): Promise<number>;
|
|
26
29
|
createStack(options: CreateStackOptions): Promise<Stack>;
|
|
@@ -3,29 +3,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const axios_1 = require("axios");
|
|
4
4
|
const error_1 = require("./error");
|
|
5
5
|
class ContentstackClient {
|
|
6
|
-
constructor(cmaHost, authToken) {
|
|
6
|
+
constructor(cmaHost, authToken, limit) {
|
|
7
7
|
this.instance = axios_1.default.create({
|
|
8
8
|
baseURL: `https://${cmaHost}/v3/`,
|
|
9
9
|
headers: {
|
|
10
10
|
authtoken: authToken,
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
|
+
this.limit = limit || 100;
|
|
14
|
+
}
|
|
15
|
+
async getOrganization(org_uid) {
|
|
16
|
+
try {
|
|
17
|
+
const response = await this.instance.get(`/organizations/${org_uid}`);
|
|
18
|
+
const o = response.data.organization;
|
|
19
|
+
return {
|
|
20
|
+
uid: o.uid,
|
|
21
|
+
name: o.name,
|
|
22
|
+
enabled: o.enabled,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw this.buildError(error);
|
|
27
|
+
}
|
|
13
28
|
}
|
|
14
29
|
async getOrganizations() {
|
|
15
30
|
try {
|
|
16
31
|
const response = await this.instance.get('/organizations', {
|
|
17
32
|
params: {
|
|
18
33
|
asc: 'name',
|
|
34
|
+
limit: this.limit,
|
|
19
35
|
},
|
|
20
36
|
});
|
|
21
|
-
|
|
37
|
+
return response.data.organizations.map((o) => {
|
|
22
38
|
return {
|
|
23
39
|
uid: o.uid,
|
|
24
40
|
name: o.name,
|
|
25
41
|
enabled: o.enabled,
|
|
26
42
|
};
|
|
27
43
|
});
|
|
28
|
-
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw this.buildError(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async getStack(stackUID) {
|
|
50
|
+
try {
|
|
51
|
+
const response = await this.instance.get('/stacks', {
|
|
52
|
+
headers: { api_key: stackUID },
|
|
53
|
+
});
|
|
54
|
+
const s = response.data.stack;
|
|
55
|
+
return {
|
|
56
|
+
uid: s.uid,
|
|
57
|
+
name: s.name,
|
|
58
|
+
master_locale: s.master_locale,
|
|
59
|
+
api_key: s.api_key,
|
|
60
|
+
org_uid: s.org_uid,
|
|
61
|
+
};
|
|
29
62
|
}
|
|
30
63
|
catch (error) {
|
|
31
64
|
throw this.buildError(error);
|
|
@@ -38,7 +71,7 @@ class ContentstackClient {
|
|
|
38
71
|
organization_uid: org_uid,
|
|
39
72
|
},
|
|
40
73
|
});
|
|
41
|
-
|
|
74
|
+
return response.data.stacks.map((s) => {
|
|
42
75
|
return {
|
|
43
76
|
uid: s.uid,
|
|
44
77
|
name: s.name,
|
|
@@ -47,7 +80,6 @@ class ContentstackClient {
|
|
|
47
80
|
org_uid: s.org_uid,
|
|
48
81
|
};
|
|
49
82
|
});
|
|
50
|
-
return result;
|
|
51
83
|
}
|
|
52
84
|
catch (error) {
|
|
53
85
|
throw this.buildError(error);
|
|
@@ -60,6 +92,7 @@ class ContentstackClient {
|
|
|
60
92
|
api_key: api_key,
|
|
61
93
|
include_count: true,
|
|
62
94
|
},
|
|
95
|
+
headers: { api_key },
|
|
63
96
|
});
|
|
64
97
|
return response.data.count;
|
|
65
98
|
}
|
package/lib/seed/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Organization } from '../seed/contentstack/client';
|
|
2
|
+
import { InquireStackResponse } from '../seed/interactive';
|
|
2
3
|
export declare const ENGLISH_LOCALE = "en-us";
|
|
3
4
|
export interface ContentModelSeederOptions {
|
|
4
5
|
cdaHost: string;
|
|
5
6
|
cmaHost: string;
|
|
6
7
|
authToken: string;
|
|
7
8
|
gitHubPath: string | undefined;
|
|
9
|
+
orgUid: string | undefined;
|
|
10
|
+
stackUid: string | undefined;
|
|
11
|
+
stackName: string | undefined;
|
|
12
|
+
fetchLimit: string | undefined;
|
|
8
13
|
}
|
|
9
14
|
export default class ContentModelSeeder {
|
|
10
15
|
options: ContentModelSeederOptions;
|
|
@@ -14,10 +19,12 @@ export default class ContentModelSeeder {
|
|
|
14
19
|
private ghRepo;
|
|
15
20
|
get ghPath(): string;
|
|
16
21
|
constructor(options: ContentModelSeederOptions);
|
|
17
|
-
run(): Promise<
|
|
22
|
+
run(): Promise<{
|
|
23
|
+
api_key: string;
|
|
24
|
+
} | undefined>;
|
|
18
25
|
getInput(): Promise<{
|
|
19
26
|
organizationResponse: Organization;
|
|
20
|
-
stackResponse:
|
|
27
|
+
stackResponse: InquireStackResponse;
|
|
21
28
|
}>;
|
|
22
29
|
createStack(organization: Organization, stackName: string): Promise<string>;
|
|
23
30
|
shouldProceed(api_key: string): Promise<boolean>;
|
package/lib/seed/index.js
CHANGED
|
@@ -18,7 +18,8 @@ class ContentModelSeeder {
|
|
|
18
18
|
const gh = client_2.default.parsePath(options.gitHubPath);
|
|
19
19
|
this.ghUsername = gh.username || DEFAULT_OWNER;
|
|
20
20
|
this.ghRepo = gh.repo;
|
|
21
|
-
|
|
21
|
+
const limit = Number(this.options.fetchLimit);
|
|
22
|
+
this.csClient = new client_1.default(options.cmaHost, options.authToken, limit);
|
|
22
23
|
this.ghClient = new client_2.default(this.ghUsername, DEFAULT_STACK_PATTERN);
|
|
23
24
|
}
|
|
24
25
|
get ghPath() {
|
|
@@ -48,12 +49,9 @@ class ContentModelSeeder {
|
|
|
48
49
|
master_locale: exports.ENGLISH_LOCALE,
|
|
49
50
|
tmpPath: tmpPath,
|
|
50
51
|
});
|
|
52
|
+
return { api_key };
|
|
51
53
|
}
|
|
52
54
|
async getInput() {
|
|
53
|
-
const organizations = await this.csClient.getOrganizations();
|
|
54
|
-
if (!organizations || organizations.length === 0) {
|
|
55
|
-
throw new Error('You do not have access to any organizations. Please try again or ask an Administrator for assistance.');
|
|
56
|
-
}
|
|
57
55
|
if (!this.ghRepo) {
|
|
58
56
|
await this.inquireGitHubRepo();
|
|
59
57
|
}
|
|
@@ -62,14 +60,37 @@ class ContentModelSeeder {
|
|
|
62
60
|
cli_ux_1.default.error(`Could not find GitHub repository '${this.ghPath}'.`);
|
|
63
61
|
}
|
|
64
62
|
else {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
let organizationResponse;
|
|
64
|
+
let stackResponse;
|
|
65
|
+
if (this.options.orgUid) {
|
|
66
|
+
organizationResponse = await this.csClient.getOrganization(this.options.orgUid);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const organizations = await this.csClient.getOrganizations();
|
|
70
|
+
if (!organizations || organizations.length === 0) {
|
|
71
|
+
throw new Error('You do not have access to any organizations. Please try again or ask an Administrator for assistance.');
|
|
72
|
+
}
|
|
73
|
+
organizationResponse = await interactive_1.inquireOrganization(organizations);
|
|
74
|
+
}
|
|
75
|
+
if (this.options.stackUid) {
|
|
76
|
+
const stack = await this.csClient.getStack(this.options.stackUid);
|
|
77
|
+
stackResponse = {
|
|
78
|
+
isNew: false,
|
|
79
|
+
name: stack.name,
|
|
80
|
+
uid: stack.uid,
|
|
81
|
+
api_key: stack.api_key,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const stacks = await this.csClient.getStacks(organizationResponse.uid);
|
|
86
|
+
stackResponse = await interactive_1.inquireStack(stacks, this.options.stackName);
|
|
87
|
+
}
|
|
68
88
|
return { organizationResponse, stackResponse };
|
|
69
89
|
}
|
|
70
90
|
}
|
|
71
91
|
async createStack(organization, stackName) {
|
|
72
92
|
cli_ux_1.default.action.start(`Creating Stack '${stackName}' within Organization '${organization.name}'`);
|
|
93
|
+
this.options.fetchLimit;
|
|
73
94
|
const newStack = await this.csClient.createStack({
|
|
74
95
|
name: stackName,
|
|
75
96
|
description: '',
|
|
@@ -10,4 +10,4 @@ export declare function inquireRepo(repos: any[]): Promise<{
|
|
|
10
10
|
}>;
|
|
11
11
|
export declare function inquireOrganization(organizations: Organization[]): Promise<Organization>;
|
|
12
12
|
export declare function inquireProceed(): Promise<number>;
|
|
13
|
-
export declare function inquireStack(stacks: Stack[]): Promise<InquireStackResponse>;
|
|
13
|
+
export declare function inquireStack(stacks: Stack[], stackName?: string): Promise<InquireStackResponse>;
|
package/lib/seed/interactive.js
CHANGED
|
@@ -53,10 +53,10 @@ async function inquireProceed() {
|
|
|
53
53
|
return createResponse.choice;
|
|
54
54
|
}
|
|
55
55
|
exports.inquireProceed = inquireProceed;
|
|
56
|
-
async function inquireStack(stacks) {
|
|
56
|
+
async function inquireStack(stacks, stackName) {
|
|
57
57
|
const result = {};
|
|
58
58
|
const hasStacks = stacks !== null && stacks.length > 0;
|
|
59
|
-
if (hasStacks) {
|
|
59
|
+
if (hasStacks && !stackName) {
|
|
60
60
|
const createResponse = await inquirer.prompt([
|
|
61
61
|
{
|
|
62
62
|
type: 'list',
|
|
@@ -80,25 +80,29 @@ async function inquireStack(stacks) {
|
|
|
80
80
|
result.isNew = true;
|
|
81
81
|
}
|
|
82
82
|
if (result.isNew) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
if (stackName)
|
|
84
|
+
result.name = stackName.trim();
|
|
85
|
+
else {
|
|
86
|
+
const nameResponse = await inquirer.prompt([
|
|
87
|
+
{
|
|
88
|
+
type: 'input',
|
|
89
|
+
name: 'name',
|
|
90
|
+
message: 'Enter a stack name',
|
|
91
|
+
validate: function (input) {
|
|
92
|
+
if (!input || input.trim() === '') {
|
|
93
|
+
return 'Required';
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
},
|
|
93
97
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
]);
|
|
99
|
+
result.name = nameResponse.name.trim();
|
|
100
|
+
}
|
|
97
101
|
}
|
|
98
102
|
else {
|
|
99
103
|
// project stacks into the format the prompt function requires
|
|
100
104
|
const choices = stacks.map(s => {
|
|
101
|
-
return { name: s.name
|
|
105
|
+
return { name: `${s.name}`, value: s.uid };
|
|
102
106
|
});
|
|
103
107
|
choices.sort((a, b) => (a.name > b.name) ? 1 : -1);
|
|
104
108
|
const selectResponse = await inquirer.prompt([
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.9","commands":{"cm:seed":{"id":"cm:seed","description":"Create a Stack from existing content types, entries, assets, etc","pluginName":"@contentstack/cli-cm-seed","pluginType":"core","aliases":[],"examples":["$ csdx cm:seed","$ csdx cm:seed -r \"account\"","$ csdx cm:seed -r \"account/repository\"","$ csdx cm:seed -r \"account/repository\" -s \"stack-uid\" //seed content into specific stack","$ csdx cm:seed -r \"account/repository\" -o \"your-org-uid\" -n \"stack-name\" //create a new stack in given org uid"],"flags":{"repo":{"name":"repo","type":"option","char":"r","description":"GitHub account or GitHub account/repository","required":false},"org":{"name":"org","type":"option","char":"o","description":"Provide Organization UID to create a new stack","required":false},"stack":{"name":"stack","type":"option","char":"s","description":"Provide stack UID to seed content to","required":false},"stack-name":{"name":"stack-name","type":"option","char":"n","description":"Name of a new stack that needs to be created.","required":false},"fetch-limit":{"name":"fetch-limit","type":"option","char":"l","description":"Limit for number of Organizations or stacks to be fetched","hidden":true,"required":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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.0.
|
|
4
|
+
"version": "1.0.9",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-cm-import": "^0.1.1-beta.
|
|
9
|
-
"@contentstack/cli-command": "^0.1.1-beta.
|
|
8
|
+
"@contentstack/cli-cm-import": "^0.1.1-beta.13",
|
|
9
|
+
"@contentstack/cli-command": "^0.1.1-beta.6",
|
|
10
10
|
"@oclif/command": "^1.8.0",
|
|
11
11
|
"@oclif/config": "^1.17.0",
|
|
12
12
|
"axios": "^0.21.1",
|