@contentstack/cli-cm-seed 1.15.0-beta.0 → 1.15.0-beta.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/README.md +10 -10
- package/lib/commands/cm/stacks/seed.js +4 -3
- package/lib/seed/github/client.d.ts +1 -0
- package/lib/seed/github/client.js +17 -0
- package/lib/seed/importer.js +7 -1
- package/lib/seed/index.d.ts +1 -1
- package/lib/seed/index.js +7 -37
- package/oclif.manifest.json +5 -5
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -10,17 +10,17 @@ 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:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y
|
|
14
|
-
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y
|
|
13
|
+
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y] [-s <value>] [--locale <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y--s-value---locale-value)
|
|
14
|
+
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y] [-s <value>] [--locale <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y--s-value---locale-value)
|
|
15
15
|
|
|
16
|
-
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y
|
|
16
|
+
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y] [-s <value>] [--locale <value>]`
|
|
17
17
|
|
|
18
18
|
Create a stack from existing content types, entries, assets, etc
|
|
19
19
|
|
|
20
20
|
```
|
|
21
21
|
USAGE
|
|
22
|
-
$ csdx cm:seed cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>]
|
|
23
|
-
|
|
22
|
+
$ csdx cm:seed cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y] [-s <value>]
|
|
23
|
+
[--locale <value>]
|
|
24
24
|
|
|
25
25
|
FLAGS
|
|
26
26
|
-a, --alias=<value> Alias of the management token
|
|
@@ -29,7 +29,7 @@ FLAGS
|
|
|
29
29
|
-o, --org=<value> Provide Organization UID to create a new stack
|
|
30
30
|
-r, --repo=<value> GitHub organization name or GitHub user name/repository name.
|
|
31
31
|
-s, --stack=<value> Provide the stack UID to seed content.
|
|
32
|
-
-y, --yes
|
|
32
|
+
-y, --yes [Optional] Skip the stack confirmation.
|
|
33
33
|
|
|
34
34
|
DESCRIPTION
|
|
35
35
|
Create a stack from existing content types, entries, assets, etc
|
|
@@ -49,14 +49,14 @@ EXAMPLES
|
|
|
49
49
|
$ csdx cm:stacks:seed --repo "account/repository" --org "your-org-uid" --stack-name "stack-name" //create a new stack in given org uid
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y
|
|
52
|
+
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y] [-s <value>] [--locale <value>]`
|
|
53
53
|
|
|
54
54
|
Create a stack from existing content types, entries, assets, etc
|
|
55
55
|
|
|
56
56
|
```
|
|
57
57
|
USAGE
|
|
58
|
-
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y
|
|
59
|
-
|
|
58
|
+
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y] [-s <value>] [--locale
|
|
59
|
+
<value>]
|
|
60
60
|
|
|
61
61
|
FLAGS
|
|
62
62
|
-a, --alias=<value> Alias of the management token
|
|
@@ -65,7 +65,7 @@ FLAGS
|
|
|
65
65
|
-o, --org=<value> Provide Organization UID to create a new stack
|
|
66
66
|
-r, --repo=<value> GitHub organization name or GitHub user name/repository name.
|
|
67
67
|
-s, --stack=<value> Provide the stack UID to seed content.
|
|
68
|
-
-y, --yes
|
|
68
|
+
-y, --yes [Optional] Skip the stack confirmation.
|
|
69
69
|
|
|
70
70
|
DESCRIPTION
|
|
71
71
|
Create a stack from existing content types, entries, assets, etc
|
|
@@ -23,7 +23,7 @@ class SeedCommand extends cli_command_1.Command {
|
|
|
23
23
|
stackUid: seedFlags['stack-api-key'] || seedFlags.stack,
|
|
24
24
|
stackName: seedFlags['stack-name'],
|
|
25
25
|
fetchLimit: seedFlags['fetch-limit'],
|
|
26
|
-
skipStackConfirmation: seedFlags
|
|
26
|
+
skipStackConfirmation: seedFlags.yes,
|
|
27
27
|
isAuthenticated: (0, cli_utilities_1.isAuthenticated)(),
|
|
28
28
|
alias: managementTokenAlias,
|
|
29
29
|
master_locale: seedFlags['locale'],
|
|
@@ -57,7 +57,7 @@ SeedCommand.examples = [
|
|
|
57
57
|
'$ csdx cm:stacks:seed --repo "account/repository" --stack-api-key "stack-api-key" //seed content into specific stack',
|
|
58
58
|
'$ csdx cm:stacks:seed --repo "account/repository" --org "your-org-uid" --stack-name "stack-name" //create a new stack in given org uid',
|
|
59
59
|
];
|
|
60
|
-
SeedCommand.usage = 'cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y
|
|
60
|
+
SeedCommand.usage = 'cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y] [-s <value>] [--locale <value>]';
|
|
61
61
|
SeedCommand.flags = {
|
|
62
62
|
repo: cli_utilities_1.flags.string({
|
|
63
63
|
char: 'r',
|
|
@@ -95,7 +95,7 @@ SeedCommand.flags = {
|
|
|
95
95
|
required: false,
|
|
96
96
|
hidden: true,
|
|
97
97
|
}),
|
|
98
|
-
yes: cli_utilities_1.flags.
|
|
98
|
+
yes: cli_utilities_1.flags.boolean({
|
|
99
99
|
char: 'y',
|
|
100
100
|
required: false,
|
|
101
101
|
description: '[Optional] Skip the stack confirmation.',
|
|
@@ -115,6 +115,7 @@ SeedCommand.flags = {
|
|
|
115
115
|
}),
|
|
116
116
|
locale: cli_utilities_1.flags.string({
|
|
117
117
|
description: 'Master Locale of the stack',
|
|
118
|
+
default: 'en-us',
|
|
118
119
|
hidden: true,
|
|
119
120
|
}),
|
|
120
121
|
};
|
|
@@ -15,6 +15,7 @@ export default class GitHubClient {
|
|
|
15
15
|
makeHeadApiCall(repo: string): Promise<any>;
|
|
16
16
|
makeGetApiCall(repo: string): Promise<any>;
|
|
17
17
|
checkIfRepoExists(repo: string): Promise<boolean>;
|
|
18
|
+
getMasterLocaleFromRepo(repo: string): Promise<string | null>;
|
|
18
19
|
getLatestTarballUrl(repo: string): Promise<any>;
|
|
19
20
|
streamRelease(url: string): Promise<Stream>;
|
|
20
21
|
extract(destination: string, stream: Stream): Promise<void>;
|
|
@@ -100,6 +100,23 @@ class GitHubClient {
|
|
|
100
100
|
}
|
|
101
101
|
return false;
|
|
102
102
|
}
|
|
103
|
+
async getMasterLocaleFromRepo(repo) {
|
|
104
|
+
var _a;
|
|
105
|
+
try {
|
|
106
|
+
const response = await this.httpClient.get(`https://raw.githubusercontent.com/${this.username}/${repo}/main/stack/locales/master-locale.json`);
|
|
107
|
+
if (response.data) {
|
|
108
|
+
const localeData = response.data;
|
|
109
|
+
const localeKey = Object.keys(localeData)[0];
|
|
110
|
+
if (localeKey && ((_a = localeData[localeKey]) === null || _a === void 0 ? void 0 : _a.code)) {
|
|
111
|
+
return localeData[localeKey].code;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.log('Could not fetch master locale from repository', error);
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
103
120
|
async getLatestTarballUrl(repo) {
|
|
104
121
|
try {
|
|
105
122
|
const response = await this.httpClient.get(`${this.gitHubRepoUrl}/${repo}/releases/latest`);
|
package/lib/seed/importer.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.run = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
const process = require("process");
|
|
5
6
|
const path = require("path");
|
|
6
7
|
const cli_cm_import_1 = require("@contentstack/cli-cm-import");
|
|
7
8
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
8
9
|
const STACK_FOLDER = 'stack';
|
|
9
10
|
async function run(options) {
|
|
10
|
-
const
|
|
11
|
+
const tmpPathResolved = path.resolve((0, cli_utilities_1.sanitizePath)(options.tmpPath));
|
|
12
|
+
const stackPath = path.join(tmpPathResolved, STACK_FOLDER);
|
|
13
|
+
// Support both structures: repo with stack/ folder (per docs) or content at root
|
|
14
|
+
const importPath = fs.existsSync(stackPath)
|
|
15
|
+
? (0, cli_utilities_1.pathValidator)(stackPath)
|
|
16
|
+
: (0, cli_utilities_1.pathValidator)(tmpPathResolved);
|
|
11
17
|
const args = options.alias
|
|
12
18
|
? ['-k', options.api_key, '-d', importPath, '--alias', options.alias]
|
|
13
19
|
: ['-k', options.api_key, '-d', importPath];
|
package/lib/seed/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface ContentModelSeederOptions {
|
|
|
10
10
|
stackUid: string | undefined;
|
|
11
11
|
stackName: string | undefined;
|
|
12
12
|
fetchLimit: string | undefined;
|
|
13
|
-
skipStackConfirmation:
|
|
13
|
+
skipStackConfirmation: boolean | undefined;
|
|
14
14
|
isAuthenticated: boolean | false;
|
|
15
15
|
managementToken?: string | undefined;
|
|
16
16
|
alias?: string | undefined;
|
package/lib/seed/index.js
CHANGED
|
@@ -127,48 +127,18 @@ class ContentModelSeeder {
|
|
|
127
127
|
return newStack.api_key;
|
|
128
128
|
}
|
|
129
129
|
async shouldProceed(api_key) {
|
|
130
|
-
let count;
|
|
131
130
|
const stack_details = await this.csClient.getStack(api_key);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
const repoMasterLocale = await this.ghClient.getMasterLocaleFromRepo(this.ghRepo);
|
|
132
|
+
const expectedLocale = repoMasterLocale || this.options.master_locale || exports.ENGLISH_LOCALE;
|
|
133
|
+
if (stack_details.master_locale !== expectedLocale) {
|
|
134
|
+
cli_utilities_1.cliux.print(`Repository '${this.ghRepo}' requires the master locale to be set to '${expectedLocale}', but your stack has '${stack_details.master_locale}'.`, {
|
|
135
|
+
color: 'yellow',
|
|
135
136
|
bold: true,
|
|
136
137
|
});
|
|
137
138
|
return false;
|
|
138
139
|
}
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
"description": "This is a compass app management token.",
|
|
142
|
-
"scope": [
|
|
143
|
-
{
|
|
144
|
-
"module": "content_type",
|
|
145
|
-
"acl": {
|
|
146
|
-
"read": true,
|
|
147
|
-
"write": true
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
"module": "branch",
|
|
152
|
-
"branches": [
|
|
153
|
-
"main"
|
|
154
|
-
],
|
|
155
|
-
"acl": {
|
|
156
|
-
"read": true
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
],
|
|
160
|
-
"expires_on": "3000-01-01",
|
|
161
|
-
"is_email_notification_enabled": false
|
|
162
|
-
};
|
|
163
|
-
let managementTokenResult = await this.csClient.createManagementToken(api_key, this.managementToken, managementBody);
|
|
164
|
-
if ((managementTokenResult === null || managementTokenResult === void 0 ? void 0 : managementTokenResult.response_code) == "161" || (managementTokenResult === null || managementTokenResult === void 0 ? void 0 : managementTokenResult.response_code) == "401") {
|
|
165
|
-
cli_utilities_1.cliux.print(`Info: Failed to generate a management token.\nNote: Management token is not available in your plan. Please contact the admin for support.`, {
|
|
166
|
-
color: 'red',
|
|
167
|
-
});
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
count = await this.csClient.getContentTypeCount(api_key, this.managementToken);
|
|
171
|
-
if (count > 0 && this._options.skipStackConfirmation !== 'yes') {
|
|
140
|
+
const count = await this.csClient.getContentTypeCount(api_key, this.managementToken);
|
|
141
|
+
if (count > 0 && !this._options.skipStackConfirmation) {
|
|
172
142
|
const proceed = await (0, interactive_1.inquireProceed)();
|
|
173
143
|
if (!proceed) {
|
|
174
144
|
return false;
|
package/oclif.manifest.json
CHANGED
|
@@ -74,9 +74,8 @@
|
|
|
74
74
|
"description": "[Optional] Skip the stack confirmation.",
|
|
75
75
|
"name": "yes",
|
|
76
76
|
"required": false,
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"type": "option"
|
|
77
|
+
"allowNo": false,
|
|
78
|
+
"type": "boolean"
|
|
80
79
|
},
|
|
81
80
|
"stack": {
|
|
82
81
|
"char": "s",
|
|
@@ -103,6 +102,7 @@
|
|
|
103
102
|
"description": "Master Locale of the stack",
|
|
104
103
|
"hidden": true,
|
|
105
104
|
"name": "locale",
|
|
105
|
+
"default": "en-us",
|
|
106
106
|
"hasDynamicHelp": false,
|
|
107
107
|
"multiple": false,
|
|
108
108
|
"type": "option"
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"pluginName": "@contentstack/cli-cm-seed",
|
|
116
116
|
"pluginType": "core",
|
|
117
117
|
"strict": true,
|
|
118
|
-
"usage": "cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y
|
|
118
|
+
"usage": "cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y] [-s <value>] [--locale <value>]",
|
|
119
119
|
"isESM": false,
|
|
120
120
|
"relativePath": [
|
|
121
121
|
"lib",
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
]
|
|
127
127
|
}
|
|
128
128
|
},
|
|
129
|
-
"version": "1.15.0-beta.
|
|
129
|
+
"version": "1.15.0-beta.1"
|
|
130
130
|
}
|
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.15.0-beta.
|
|
4
|
+
"version": "1.15.0-beta.1",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-cm-import": "~1.32.0-beta.
|
|
9
|
-
"@contentstack/cli-command": "~1.8.0-beta.
|
|
10
|
-
"@contentstack/cli-utilities": "~1.
|
|
8
|
+
"@contentstack/cli-cm-import": "~1.32.0-beta.1",
|
|
9
|
+
"@contentstack/cli-command": "~1.8.0-beta.1",
|
|
10
|
+
"@contentstack/cli-utilities": "~1.19.0-beta.0",
|
|
11
11
|
"inquirer": "8.2.7",
|
|
12
12
|
"mkdirp": "^1.0.4",
|
|
13
|
-
"tar": "^7.5.
|
|
13
|
+
"tar": "^7.5.11",
|
|
14
14
|
"tmp": "^0.2.5"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
@@ -71,4 +71,4 @@
|
|
|
71
71
|
"compile": "tsc -b tsconfig.json",
|
|
72
72
|
"build": "pnpm compile && oclif manifest && oclif readme"
|
|
73
73
|
}
|
|
74
|
-
}
|
|
74
|
+
}
|