Skip to content

Commit f308fb0

Browse files
Fixed seed command for existing stack
1 parent 5e5f3fa commit f308fb0

7 files changed

Lines changed: 44 additions & 50 deletions

File tree

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-bootstrap/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-cm-bootstrap",
33
"description": "Bootstrap contentstack apps",
4-
"version": "2.0.0-beta.9",
4+
"version": "2.0.0-beta.10",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"scripts": {
@@ -16,7 +16,7 @@
1616
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
1717
},
1818
"dependencies": {
19-
"@contentstack/cli-cm-seed": "~2.0.0-beta.8",
19+
"@contentstack/cli-cm-seed": "~2.0.0-beta.9",
2020
"@contentstack/cli-command": "~2.0.0-beta",
2121
"@contentstack/cli-utilities": "~2.0.0-beta",
2222
"@contentstack/cli-config": "~2.0.0-beta.2",

packages/contentstack-seed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-cm-seed",
33
"description": "create a Stack from existing content types, entries, assets, etc.",
4-
"version": "2.0.0-beta.8",
4+
"version": "2.0.0-beta.9",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {

packages/contentstack-seed/src/seed/github/client.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ export default class GitHubClient {
118118
return false;
119119
}
120120

121+
async getMasterLocaleFromRepo(repo: string): Promise<string | null> {
122+
try {
123+
const response = await this.httpClient.get(
124+
`https://raw.githubusercontent.com/${this.username}/${repo}/main/stack/locales/master-locale.json`
125+
);
126+
127+
if (response.data) {
128+
const localeData = response.data;
129+
const localeKey = Object.keys(localeData)[0];
130+
if (localeKey && localeData[localeKey]?.code) {
131+
return localeData[localeKey].code;
132+
}
133+
}
134+
} catch (error) {
135+
console.log('Could not fetch master locale from repository', error);
136+
}
137+
138+
return null;
139+
}
140+
121141
async getLatestTarballUrl(repo: string) {
122142
try {
123143
const response = await this.httpClient.get(`${this.gitHubRepoUrl}/${repo}/releases/latest`);

packages/contentstack-seed/src/seed/index.ts

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -183,47 +183,21 @@ export default class ContentModelSeeder {
183183
async shouldProceed(api_key: string) {
184184
let count;
185185
const stack_details = await this.csClient.getStack(api_key);
186-
if(this.options.master_locale != stack_details.master_locale){
187-
cliux.print(`Compass app requires the master locale to be set to English (en).`,{
188-
color: "yellow",
189-
bold: true,
190-
});
191-
return false;
192-
}
193-
const managementBody = {
194-
"name":"Checking roles for creating management token",
195-
"description":"This is a compass app management token.",
196-
"scope":[
197-
{
198-
"module":"content_type",
199-
"acl":{
200-
"read":true,
201-
"write":true
202-
}
203-
},
204-
{
205-
"module":"branch",
206-
"branches":[
207-
"main"
208-
],
209-
"acl":{
210-
"read":true
211-
}
212-
}
213-
],
214-
"expires_on": "3000-01-01",
215-
"is_email_notification_enabled":false
216-
}
217-
let managementTokenResult = await this.csClient.createManagementToken(api_key, this.managementToken, managementBody);
218-
if(managementTokenResult?.response_code == "161" || managementTokenResult?.response_code == "401"){
186+
187+
const repoMasterLocale = await this.ghClient.getMasterLocaleFromRepo(this.ghRepo as string);
188+
const expectedLocale = repoMasterLocale || this.options.master_locale || ENGLISH_LOCALE;
189+
190+
if (stack_details.master_locale !== expectedLocale) {
219191
cliux.print(
220-
`Info: Failed to generate a management token.\nNote: Management token is not available in your plan. Please contact the admin for support.`,
192+
`Repository '${this.ghRepo}' requires the master locale to be set to '${expectedLocale}', but your stack has '${stack_details.master_locale}'.`,
221193
{
222-
color: 'red',
223-
},
194+
color: "yellow",
195+
bold: true,
196+
}
224197
);
225198
return false;
226-
}
199+
}
200+
227201
count = await this.csClient.getContentTypeCount(api_key, this.managementToken);
228202

229203
if (count > 0 && this._options.skipStackConfirmation !== 'yes') {

packages/contentstack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"@contentstack/cli-cm-import": "~2.0.0-beta.9",
2828
"@contentstack/cli-auth": "~2.0.0-beta.5",
2929
"@contentstack/cli-bulk-operations": "^1.0.0-beta",
30-
"@contentstack/cli-cm-bootstrap": "~2.0.0-beta.9",
30+
"@contentstack/cli-cm-bootstrap": "~2.0.0-beta.10",
3131
"@contentstack/cli-cm-branches": "~2.0.0-beta",
3232
"@contentstack/cli-cm-clone": "~2.0.0-beta.10",
3333
"@contentstack/cli-cm-export-to-csv": "~2.0.0-beta",
3434
"@contentstack/cli-cm-import-setup": "~2.0.0-beta.4",
35-
"@contentstack/cli-cm-seed": "~2.0.0-beta.8",
35+
"@contentstack/cli-cm-seed": "~2.0.0-beta.9",
3636
"@contentstack/cli-command": "~2.0.0-beta",
3737
"@contentstack/cli-config": "~2.0.0-beta.2",
3838
"@contentstack/cli-launch": "^1.9.6",

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)