@contentstack/cli-cm-seed 1.0.12 → 1.1.1
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/LICENSE +21 -0
- package/README.md +21 -15
- package/lib/commands/cm/{seed.d.ts → stacks/seed.d.ts} +5 -1
- package/lib/commands/cm/{seed.js → stacks/seed.js} +37 -19
- package/lib/seed/github/client.d.ts +1 -0
- package/lib/seed/github/client.js +10 -6
- package/lib/seed/importer.js +1 -1
- package/lib/seed/index.d.ts +3 -1
- package/lib/seed/index.js +23 -22
- package/lib/seed/interactive.js +7 -7
- package/oclif.manifest.json +1 -1
- package/package.json +13 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Contentstack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -10,31 +10,37 @@ To import content to your stack, you can choose from the following two sources:
|
|
|
10
10
|
<!-- usagestop -->
|
|
11
11
|
## Commands
|
|
12
12
|
<!-- commands -->
|
|
13
|
-
* [`csdx cm:seed`](#csdx-
|
|
13
|
+
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y-value--s-value)
|
|
14
14
|
|
|
15
|
-
## `csdx cm:seed`
|
|
15
|
+
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]`
|
|
16
16
|
|
|
17
|
-
Create a
|
|
17
|
+
Create a stack from existing content types, entries, assets, etc
|
|
18
18
|
|
|
19
19
|
```
|
|
20
20
|
USAGE
|
|
21
|
-
$ csdx cm:seed
|
|
21
|
+
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
|
|
22
22
|
|
|
23
23
|
OPTIONS
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
24
|
+
-k, --stack-api-key=stack-api-key Provide stack api key to seed content to
|
|
25
|
+
-n, --stack-name=stack-name Name of a new stack that needs to be created.
|
|
26
|
+
-o, --org=org Provide Organization UID to create a new stack
|
|
27
|
+
-r, --repo=repo GitHub account or GitHub account/repository
|
|
28
|
+
-s, --stack=stack Provide stack UID to seed content to
|
|
29
|
+
-y, --yes=yes
|
|
30
|
+
|
|
31
|
+
ALIASES
|
|
32
|
+
$ csdx cm:seed
|
|
28
33
|
|
|
29
34
|
EXAMPLES
|
|
30
|
-
$ csdx cm:seed
|
|
31
|
-
$ csdx cm:seed
|
|
32
|
-
$ csdx cm:seed
|
|
33
|
-
$ csdx cm:seed
|
|
34
|
-
$ csdx cm:seed
|
|
35
|
+
$ csdx cm:stacks:seed
|
|
36
|
+
$ csdx cm:stacks:seed --repo "account"
|
|
37
|
+
$ csdx cm:stacks:seed --repo "account/repository"
|
|
38
|
+
$ csdx cm:stacks:seed --repo "account/repository" --stack-api-key "stack-api-key" //seed content into specific stack
|
|
39
|
+
$ csdx cm:stacks:seed --repo "account/repository" --org "your-org-uid" --stack-name "stack-name" //create a new stack
|
|
40
|
+
in given org uid
|
|
35
41
|
```
|
|
36
42
|
|
|
37
|
-
_See code: [src/commands/cm/seed.ts](https://github.com/contentstack/cli/blob/v1.
|
|
43
|
+
_See code: [src/commands/cm/stacks/seed.ts](https://github.com/contentstack/cli/blob/v1.1.1/src/commands/cm/stacks/seed.ts)_
|
|
38
44
|
<!-- commandsstop -->
|
|
39
45
|
|
|
40
46
|
## Advanced Flags
|
|
@@ -45,7 +51,7 @@ The account name can be a personal user account, organization account, or enterp
|
|
|
45
51
|
$ csdx cm:seed -r "account/repository"
|
|
46
52
|
```
|
|
47
53
|
|
|
48
|
-
**Step 1.** Export a Stack
|
|
54
|
+
**Step 1.** Export a Stack
|
|
49
55
|
|
|
50
56
|
Identify a Stack that you would like to export.
|
|
51
57
|
This stack might be used in conjunction with a sample web site or mobile app you have created.
|
|
@@ -2,13 +2,17 @@ import { Command, flags } from '@contentstack/cli-command';
|
|
|
2
2
|
export default class SeedCommand extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
|
+
static usage: string;
|
|
5
6
|
static flags: {
|
|
6
7
|
repo: flags.IOptionFlag<string | undefined>;
|
|
7
8
|
org: flags.IOptionFlag<string | undefined>;
|
|
8
|
-
stack: flags.IOptionFlag<string | undefined>;
|
|
9
|
+
'stack-api-key': flags.IOptionFlag<string | undefined>;
|
|
9
10
|
'stack-name': flags.IOptionFlag<string | undefined>;
|
|
10
11
|
'fetch-limit': flags.IOptionFlag<string | undefined>;
|
|
12
|
+
yes: flags.IOptionFlag<string | undefined>;
|
|
13
|
+
stack: flags.IOptionFlag<string | undefined>;
|
|
11
14
|
};
|
|
15
|
+
static aliases: string[];
|
|
12
16
|
run(): Promise<{
|
|
13
17
|
api_key: string;
|
|
14
18
|
} | undefined>;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const cli_command_1 = require("@contentstack/cli-command");
|
|
4
|
-
const seed_1 = require("
|
|
4
|
+
const seed_1 = require("../../../seed");
|
|
5
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
6
|
class SeedCommand extends cli_command_1.Command {
|
|
6
7
|
async run() {
|
|
7
8
|
try {
|
|
8
9
|
const { flags: seedFlags } = this.parse(SeedCommand);
|
|
9
10
|
if (!this.authToken) {
|
|
10
|
-
this.error(
|
|
11
|
+
this.error('You need to login, first. See: auth:login --help', {
|
|
11
12
|
exit: 2,
|
|
12
|
-
suggestions: [
|
|
13
|
-
"https://www.contentstack.com/docs/developers/cli/authentication/",
|
|
14
|
-
],
|
|
13
|
+
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
|
|
15
14
|
});
|
|
16
15
|
}
|
|
17
16
|
const options = {
|
|
@@ -20,34 +19,38 @@ class SeedCommand extends cli_command_1.Command {
|
|
|
20
19
|
authToken: this.authToken,
|
|
21
20
|
gitHubPath: seedFlags.repo,
|
|
22
21
|
orgUid: seedFlags.org,
|
|
23
|
-
stackUid: seedFlags.stack,
|
|
24
|
-
stackName: seedFlags[
|
|
25
|
-
fetchLimit: seedFlags[
|
|
22
|
+
stackUid: seedFlags['stack-api-key'] || seedFlags.stack,
|
|
23
|
+
stackName: seedFlags['stack-name'],
|
|
24
|
+
fetchLimit: seedFlags['fetch-limit'],
|
|
25
|
+
skipStackConfirmation: seedFlags['yes'],
|
|
26
26
|
};
|
|
27
27
|
const seeder = new seed_1.default(options);
|
|
28
28
|
const result = await seeder.run();
|
|
29
29
|
return result;
|
|
30
30
|
}
|
|
31
31
|
catch (error) {
|
|
32
|
-
|
|
32
|
+
let errorObj = error;
|
|
33
|
+
this.error(errorObj, { exit: 1, suggestions: errorObj.suggestions });
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
exports.default = SeedCommand;
|
|
37
|
-
SeedCommand.description = 'Create a
|
|
38
|
+
SeedCommand.description = 'Create a stack from existing content types, entries, assets, etc';
|
|
38
39
|
SeedCommand.examples = [
|
|
39
|
-
'$ csdx cm:seed',
|
|
40
|
-
'$ csdx cm:seed
|
|
41
|
-
'$ csdx cm:seed
|
|
42
|
-
'$ csdx cm:seed
|
|
43
|
-
'$ csdx cm:seed
|
|
40
|
+
'$ csdx cm:stacks:seed',
|
|
41
|
+
'$ csdx cm:stacks:seed --repo "account"',
|
|
42
|
+
'$ csdx cm:stacks:seed --repo "account/repository"',
|
|
43
|
+
'$ csdx cm:stacks:seed --repo "account/repository" --stack-api-key "stack-api-key" //seed content into specific stack',
|
|
44
|
+
'$ csdx cm:stacks:seed --repo "account/repository" --org "your-org-uid" --stack-name "stack-name" //create a new stack in given org uid',
|
|
44
45
|
];
|
|
46
|
+
SeedCommand.usage = 'cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]';
|
|
45
47
|
SeedCommand.flags = {
|
|
46
48
|
repo: cli_command_1.flags.string({
|
|
47
49
|
char: 'r',
|
|
48
50
|
description: 'GitHub account or GitHub account/repository',
|
|
49
51
|
multiple: false,
|
|
50
52
|
required: false,
|
|
53
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['-r'], ['--repo']),
|
|
51
54
|
}),
|
|
52
55
|
org: cli_command_1.flags.string({
|
|
53
56
|
char: 'o',
|
|
@@ -55,13 +58,14 @@ SeedCommand.flags = {
|
|
|
55
58
|
multiple: false,
|
|
56
59
|
required: false,
|
|
57
60
|
exclusive: ['stack'],
|
|
61
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['-o'], ['--org']),
|
|
58
62
|
}),
|
|
59
|
-
stack: cli_command_1.flags.string({
|
|
60
|
-
char: '
|
|
61
|
-
description: 'Provide stack
|
|
63
|
+
'stack-api-key': cli_command_1.flags.string({
|
|
64
|
+
char: 'k',
|
|
65
|
+
description: 'Provide stack api key to seed content to',
|
|
62
66
|
multiple: false,
|
|
63
67
|
required: false,
|
|
64
|
-
exclusive: ['org'
|
|
68
|
+
exclusive: ['org'],
|
|
65
69
|
}),
|
|
66
70
|
'stack-name': cli_command_1.flags.string({
|
|
67
71
|
char: 'n',
|
|
@@ -77,4 +81,18 @@ SeedCommand.flags = {
|
|
|
77
81
|
required: false,
|
|
78
82
|
hidden: true,
|
|
79
83
|
}),
|
|
84
|
+
yes: cli_command_1.flags.string({
|
|
85
|
+
char: 'y',
|
|
86
|
+
required: false,
|
|
87
|
+
}),
|
|
88
|
+
//To be deprecated
|
|
89
|
+
stack: cli_command_1.flags.string({
|
|
90
|
+
char: 's',
|
|
91
|
+
description: 'Provide stack UID to seed content to',
|
|
92
|
+
multiple: false,
|
|
93
|
+
required: false,
|
|
94
|
+
exclusive: ['org', 'name'],
|
|
95
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['s', 'stack'], ['-k', 'stack-api-key']),
|
|
96
|
+
}),
|
|
80
97
|
};
|
|
98
|
+
SeedCommand.aliases = ['cm:seed'];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
4
|
const zlib = require("zlib");
|
|
5
5
|
const tar = require("tar");
|
|
6
6
|
const mkdirp = require("mkdirp");
|
|
@@ -10,6 +10,7 @@ class GitHubClient {
|
|
|
10
10
|
this.username = username;
|
|
11
11
|
this.gitHubRepoUrl = `https://api.github.com/repos/${username}`;
|
|
12
12
|
this.gitHubUserUrl = `https://api.github.com/search/repositories?q=org%3A${username}+in:name+${defaultStackPattern}`;
|
|
13
|
+
this.httpClient = cli_utilities_1.HttpClient.create();
|
|
13
14
|
}
|
|
14
15
|
static parsePath(path) {
|
|
15
16
|
const result = {
|
|
@@ -27,7 +28,7 @@ class GitHubClient {
|
|
|
27
28
|
}
|
|
28
29
|
async getAllRepos(count = 100) {
|
|
29
30
|
try {
|
|
30
|
-
const response = await
|
|
31
|
+
const response = await this.httpClient.get(`${this.gitHubUserUrl}&per_page=${count}`);
|
|
31
32
|
return response.data.items;
|
|
32
33
|
}
|
|
33
34
|
catch (error) {
|
|
@@ -42,7 +43,7 @@ class GitHubClient {
|
|
|
42
43
|
}
|
|
43
44
|
async checkIfRepoExists(repo) {
|
|
44
45
|
try {
|
|
45
|
-
const response = await
|
|
46
|
+
const response = await this.httpClient.send('HEAD', `${this.gitHubRepoUrl}/${repo}/contents`);
|
|
46
47
|
return response.status === 200;
|
|
47
48
|
}
|
|
48
49
|
catch (error) {
|
|
@@ -52,7 +53,7 @@ class GitHubClient {
|
|
|
52
53
|
}
|
|
53
54
|
async getLatestTarballUrl(repo) {
|
|
54
55
|
try {
|
|
55
|
-
const response = await
|
|
56
|
+
const response = await this.httpClient.get(`${this.gitHubRepoUrl}/${repo}/releases/latest`);
|
|
56
57
|
return response.data.tarball_url;
|
|
57
58
|
}
|
|
58
59
|
catch (error) {
|
|
@@ -60,9 +61,12 @@ class GitHubClient {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
async streamRelease(url) {
|
|
63
|
-
const response = await
|
|
64
|
+
const response = await this.httpClient
|
|
65
|
+
.options({
|
|
64
66
|
responseType: 'stream',
|
|
65
|
-
})
|
|
67
|
+
})
|
|
68
|
+
.get(url);
|
|
69
|
+
this.httpClient.resetConfig();
|
|
66
70
|
return response.data;
|
|
67
71
|
}
|
|
68
72
|
async extract(destination, stream) {
|
package/lib/seed/importer.js
CHANGED
|
@@ -9,6 +9,6 @@ async function run(options) {
|
|
|
9
9
|
process.chdir(options.tmpPath);
|
|
10
10
|
// moving here to fix jest testing bug
|
|
11
11
|
const { parametersWithAuthToken } = require('@contentstack/cli-cm-import/src/lib/util/import-flags');
|
|
12
|
-
await parametersWithAuthToken(options.authToken, options.api_key, importPath, '', options.cmaHost);
|
|
12
|
+
await parametersWithAuthToken(options.authToken, options.api_key, importPath, '', options.cmaHost, '', {});
|
|
13
13
|
}
|
|
14
14
|
exports.run = run;
|
package/lib/seed/index.d.ts
CHANGED
|
@@ -10,11 +10,13 @@ export interface ContentModelSeederOptions {
|
|
|
10
10
|
stackUid: string | undefined;
|
|
11
11
|
stackName: string | undefined;
|
|
12
12
|
fetchLimit: string | undefined;
|
|
13
|
+
skipStackConfirmation: string | undefined;
|
|
13
14
|
}
|
|
14
15
|
export default class ContentModelSeeder {
|
|
15
16
|
options: ContentModelSeederOptions;
|
|
16
17
|
private readonly csClient;
|
|
17
18
|
private readonly ghClient;
|
|
19
|
+
private readonly _options;
|
|
18
20
|
private ghUsername;
|
|
19
21
|
private ghRepo;
|
|
20
22
|
get ghPath(): string;
|
|
@@ -25,7 +27,7 @@ export default class ContentModelSeeder {
|
|
|
25
27
|
getInput(): Promise<{
|
|
26
28
|
organizationResponse: Organization;
|
|
27
29
|
stackResponse: InquireStackResponse;
|
|
28
|
-
}>;
|
|
30
|
+
} | any>;
|
|
29
31
|
createStack(organization: Organization, stackName: string): Promise<string>;
|
|
30
32
|
shouldProceed(api_key: string): Promise<boolean>;
|
|
31
33
|
downloadRelease(): Promise<string>;
|
package/lib/seed/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ENGLISH_LOCALE = void 0;
|
|
4
|
-
const cli_ux_1 = require("cli-ux");
|
|
5
4
|
const tmp = require("tmp");
|
|
5
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
6
|
const importer = require("../seed/importer");
|
|
7
7
|
const client_1 = require("../seed/contentstack/client");
|
|
8
8
|
const interactive_1 = require("../seed/interactive");
|
|
@@ -15,6 +15,7 @@ class ContentModelSeeder {
|
|
|
15
15
|
constructor(options) {
|
|
16
16
|
this.options = options;
|
|
17
17
|
this.ghUsername = DEFAULT_OWNER;
|
|
18
|
+
this._options = options;
|
|
18
19
|
const gh = client_2.default.parsePath(options.gitHubPath);
|
|
19
20
|
this.ghUsername = gh.username || DEFAULT_OWNER;
|
|
20
21
|
this.ghRepo = gh.repo;
|
|
@@ -35,12 +36,12 @@ class ContentModelSeeder {
|
|
|
35
36
|
api_key = stackResponse.api_key;
|
|
36
37
|
const proceed = await this.shouldProceed(api_key);
|
|
37
38
|
if (!proceed) {
|
|
38
|
-
|
|
39
|
+
cli_utilities_1.cliux.print('Exiting. Please re-run the command, if you wish to seed content.');
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
const tmpPath = await this.downloadRelease();
|
|
43
|
-
|
|
44
|
+
cli_utilities_1.cliux.print(`Importing into '${stackResponse.name}'.`);
|
|
44
45
|
await importer.run({
|
|
45
46
|
api_key: api_key,
|
|
46
47
|
authToken: this.options.authToken,
|
|
@@ -57,21 +58,11 @@ class ContentModelSeeder {
|
|
|
57
58
|
}
|
|
58
59
|
const repoExists = await this.ghClient.checkIfRepoExists(this.ghRepo);
|
|
59
60
|
if (repoExists === false) {
|
|
60
|
-
|
|
61
|
+
cli_utilities_1.cliux.error(`Could not find GitHub repository '${this.ghPath}'.`);
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
63
64
|
let organizationResponse;
|
|
64
65
|
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 (0, interactive_1.inquireOrganization)(organizations);
|
|
74
|
-
}
|
|
75
66
|
if (this.options.stackUid) {
|
|
76
67
|
const stack = await this.csClient.getStack(this.options.stackUid);
|
|
77
68
|
stackResponse = {
|
|
@@ -82,6 +73,16 @@ class ContentModelSeeder {
|
|
|
82
73
|
};
|
|
83
74
|
}
|
|
84
75
|
else {
|
|
76
|
+
if (this.options.orgUid) {
|
|
77
|
+
organizationResponse = await this.csClient.getOrganization(this.options.orgUid);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const organizations = await this.csClient.getOrganizations();
|
|
81
|
+
if (!organizations || organizations.length === 0) {
|
|
82
|
+
throw new Error('You do not have access to any organizations. Please try again or ask an Administrator for assistance.');
|
|
83
|
+
}
|
|
84
|
+
organizationResponse = await (0, interactive_1.inquireOrganization)(organizations);
|
|
85
|
+
}
|
|
85
86
|
const stacks = await this.csClient.getStacks(organizationResponse.uid);
|
|
86
87
|
stackResponse = await (0, interactive_1.inquireStack)(stacks, this.options.stackName);
|
|
87
88
|
}
|
|
@@ -89,7 +90,7 @@ class ContentModelSeeder {
|
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
async createStack(organization, stackName) {
|
|
92
|
-
|
|
93
|
+
cli_utilities_1.cliux.loader(`Creating Stack '${stackName}' within Organization '${organization.name}'`);
|
|
93
94
|
this.options.fetchLimit;
|
|
94
95
|
const newStack = await this.csClient.createStack({
|
|
95
96
|
name: stackName,
|
|
@@ -97,12 +98,12 @@ class ContentModelSeeder {
|
|
|
97
98
|
master_locale: exports.ENGLISH_LOCALE,
|
|
98
99
|
org_uid: organization.uid,
|
|
99
100
|
});
|
|
100
|
-
|
|
101
|
+
cli_utilities_1.cliux.loader();
|
|
101
102
|
return newStack.api_key;
|
|
102
103
|
}
|
|
103
104
|
async shouldProceed(api_key) {
|
|
104
105
|
const count = await this.csClient.getContentTypeCount(api_key);
|
|
105
|
-
if (count > 0) {
|
|
106
|
+
if (count > 0 && this._options.skipStackConfirmation !== 'yes') {
|
|
106
107
|
const proceed = await (0, interactive_1.inquireProceed)();
|
|
107
108
|
if (!proceed) {
|
|
108
109
|
return false;
|
|
@@ -114,20 +115,20 @@ class ContentModelSeeder {
|
|
|
114
115
|
const tmpDir = tmp.dirSync({
|
|
115
116
|
unsafeCleanup: true,
|
|
116
117
|
});
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
cli_utilities_1.cliux.print(`Creating temporary directory '${tmpDir.name}'.`);
|
|
119
|
+
cli_utilities_1.cliux.loader('Downloading and extracting Stack');
|
|
119
120
|
try {
|
|
120
121
|
await this.ghClient.getLatest(this.ghRepo, tmpDir.name);
|
|
121
122
|
}
|
|
122
123
|
catch (error) {
|
|
123
124
|
if (error instanceof error_1.default) {
|
|
124
125
|
if (error.status === 404) {
|
|
125
|
-
|
|
126
|
+
cli_utilities_1.cliux.error(`Unable to find a release for '${this.ghPath}'.`);
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
finally {
|
|
130
|
-
|
|
131
|
+
cli_utilities_1.cliux.loader();
|
|
131
132
|
}
|
|
132
133
|
return tmpDir.name;
|
|
133
134
|
}
|
|
@@ -139,7 +140,7 @@ class ContentModelSeeder {
|
|
|
139
140
|
this.ghRepo = repoResponse.choice;
|
|
140
141
|
}
|
|
141
142
|
catch (error) {
|
|
142
|
-
|
|
143
|
+
cli_utilities_1.cliux.error(`Unable to find any Stack repositories within the '${this.ghUsername}' GitHub account. Please re-run this command with a GitHub repository in the 'account/repo' format. You can also re-run the command without arguments to pull from the official Stack list.`);
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
}
|
package/lib/seed/interactive.js
CHANGED
|
@@ -8,7 +8,7 @@ async function inquireRepo(repos) {
|
|
|
8
8
|
if (repos.length === 1) {
|
|
9
9
|
return { choice: extractRepoName(repos[0].html_url) };
|
|
10
10
|
}
|
|
11
|
-
const choices = repos.map(r => {
|
|
11
|
+
const choices = repos.map((r) => {
|
|
12
12
|
return { name: formatStackName(r.name), value: extractRepoName(r.html_url) };
|
|
13
13
|
});
|
|
14
14
|
const response = await inquirer.prompt([
|
|
@@ -28,7 +28,7 @@ async function inquireOrganization(organizations) {
|
|
|
28
28
|
if (organizations.length === 1) {
|
|
29
29
|
return organizations[0];
|
|
30
30
|
}
|
|
31
|
-
const choices = organizations.map(r => {
|
|
31
|
+
const choices = organizations.map((r) => {
|
|
32
32
|
return { name: r.name, value: r.uid };
|
|
33
33
|
});
|
|
34
34
|
const response = await inquirer.prompt([
|
|
@@ -39,7 +39,7 @@ async function inquireOrganization(organizations) {
|
|
|
39
39
|
choices,
|
|
40
40
|
},
|
|
41
41
|
]);
|
|
42
|
-
return organizations.find(r => r.uid === response.uid);
|
|
42
|
+
return organizations.find((r) => r.uid === response.uid);
|
|
43
43
|
}
|
|
44
44
|
exports.inquireOrganization = inquireOrganization;
|
|
45
45
|
async function inquireProceed() {
|
|
@@ -101,10 +101,10 @@ async function inquireStack(stacks, stackName) {
|
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
103
103
|
// project stacks into the format the prompt function requires
|
|
104
|
-
const choices = stacks.map(s => {
|
|
104
|
+
const choices = stacks.map((s) => {
|
|
105
105
|
return { name: `${s.name}`, value: s.uid };
|
|
106
106
|
});
|
|
107
|
-
choices.sort((a, b) => (a.name > b.name
|
|
107
|
+
choices.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
108
108
|
const selectResponse = await inquirer.prompt([
|
|
109
109
|
{
|
|
110
110
|
type: 'list',
|
|
@@ -113,7 +113,7 @@ async function inquireStack(stacks, stackName) {
|
|
|
113
113
|
choices: choices,
|
|
114
114
|
},
|
|
115
115
|
]);
|
|
116
|
-
const stack = stacks.find(r => r.uid === selectResponse.uid);
|
|
116
|
+
const stack = stacks.find((r) => r.uid === selectResponse.uid);
|
|
117
117
|
result.name = stack.name;
|
|
118
118
|
result.uid = stack.uid;
|
|
119
119
|
result.api_key = stack.api_key;
|
|
@@ -125,7 +125,7 @@ function formatStackName(name) {
|
|
|
125
125
|
return name
|
|
126
126
|
.replace('stack-', '')
|
|
127
127
|
.replace(/-/g, ' ')
|
|
128
|
-
.replace(/(?:^|\s)\S/g, match => {
|
|
128
|
+
.replace(/(?:^|\s)\S/g, (match) => {
|
|
129
129
|
return match.toUpperCase();
|
|
130
130
|
});
|
|
131
131
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.
|
|
1
|
+
{"version":"1.1.1","commands":{"cm:stacks:seed":{"id":"cm:stacks:seed","description":"Create a stack from existing content types, entries, assets, etc","usage":"cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]","pluginName":"@contentstack/cli-cm-seed","pluginType":"core","aliases":["cm:seed"],"examples":["$ csdx cm:stacks:seed","$ csdx cm:stacks:seed --repo \"account\"","$ csdx cm:stacks:seed --repo \"account/repository\"","$ csdx cm:stacks:seed --repo \"account/repository\" --stack-api-key \"stack-api-key\" //seed content into specific stack","$ csdx cm:stacks:seed --repo \"account/repository\" --org \"your-org-uid\" --stack-name \"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-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"Provide stack api key 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},"yes":{"name":"yes","type":"option","char":"y","required":false},"stack":{"name":"stack","type":"option","char":"s","description":"Provide stack UID to seed content to","required":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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
|
+
"version": "1.1.1",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-cm-import": "^
|
|
9
|
-
"@contentstack/cli-command": "^0.1
|
|
10
|
-
"@
|
|
11
|
-
"@oclif/
|
|
8
|
+
"@contentstack/cli-cm-import": "^1.1.0",
|
|
9
|
+
"@contentstack/cli-command": "^1.0.1",
|
|
10
|
+
"@contentstack/cli-utilities": "^1.0.2",
|
|
11
|
+
"@oclif/command": "^1.8.16",
|
|
12
|
+
"@oclif/config": "^1.18.3",
|
|
12
13
|
"axios": "^0.21.1",
|
|
13
|
-
"cli-ux": "^5.5.0",
|
|
14
14
|
"inquirer": "^8.0.0",
|
|
15
15
|
"mkdirp": "^1.0.4",
|
|
16
16
|
"tar": "^6.0.5",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@oclif/dev-cli": "^1.22.2",
|
|
22
|
-
"@oclif/plugin-help": "^
|
|
22
|
+
"@oclif/plugin-help": "^5.1.12",
|
|
23
23
|
"@types/inquirer": "^7.3.1",
|
|
24
24
|
"@types/jest": "^26.0.15",
|
|
25
25
|
"@types/mkdirp": "^1.0.1",
|
|
26
26
|
"@types/node": "^14.14.32",
|
|
27
27
|
"@types/tar": "^4.0.3",
|
|
28
28
|
"@types/tmp": "^0.2.0",
|
|
29
|
-
"eslint": "^
|
|
29
|
+
"eslint": "^8.18.0",
|
|
30
30
|
"eslint-config-oclif": "^3.1.0",
|
|
31
31
|
"eslint-config-oclif-typescript": "^0.1.0",
|
|
32
32
|
"globby": "^10.0.2",
|
|
@@ -57,6 +57,11 @@
|
|
|
57
57
|
"@oclif/plugin-help"
|
|
58
58
|
]
|
|
59
59
|
},
|
|
60
|
+
"csdxConfig": {
|
|
61
|
+
"expiredCommands": {
|
|
62
|
+
"cm:seed": "csdx cm:stacks:seed"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
60
65
|
"repository": "contentstack/cli",
|
|
61
66
|
"scripts": {
|
|
62
67
|
"test": "jest",
|