Skip to content

Commit 175dbaa

Browse files
Fixed seed command for existing stack
1 parent 2141589 commit 175dbaa

10 files changed

Lines changed: 1025 additions & 822 deletions

File tree

.talismanrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: 8d0430a55a8bbfe3f1be5264dfcc914616175bbd0c0ddb33b0796ccc811dbd91
3+
checksum: ed57f970124a7225759c0428158d71b6071f28d695fa2ab21174959a5d0c12d0
44
- filename: pnpm-lock.yaml
5-
checksum: 9e6a3c280cfd7356f1440a592c8b4f1d6294f4ae133696680c253a029be017c7
5+
checksum: a46f5110bb9be1dc852dda65443da3e6baf2fa3c646a2d5b67862488d3d39787
66
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
77
checksum: 6e6fb00bb11b03141e5ad27eeaa4af9718dc30520c3e73970bc208cc0ba2a7d2
88
version: '1.0'

package-lock.json

Lines changed: 973 additions & 759 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": "1.18.4",
4+
"version": "1.18.5",
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": "~1.14.3",
19+
"@contentstack/cli-cm-seed": "~1.14.4",
2020
"@contentstack/cli-command": "~1.7.2",
2121
"@contentstack/cli-config": "~1.19.0",
2222
"@contentstack/cli-utilities": "~1.17.4",

packages/contentstack-bootstrap/src/bootstrap/utils.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,20 @@ export const setupEnvironments = async (
4040
if (!managementToken) {
4141
const managementBody = {
4242
token: {
43-
name: 'sample app',
44-
description: 'This is a sample management token.',
43+
name: 'Compass Starter App',
44+
description: 'This is a compass starter app management token.',
4545
scope: [
4646
{
47-
module: 'content_type',
47+
module: '$all',
4848
acl: {
4949
read: true,
5050
write: true,
5151
},
5252
},
53-
{
54-
module: 'branch',
55-
branches: ['main'],
56-
acl: {
57-
read: true,
58-
},
59-
},
6053
],
61-
expires_on: '3000-01-01',
54+
expires_on: null,
6255
is_email_notification_enabled: false,
56+
rate_limit_enabled: false,
6357
},
6458
};
6559
managementTokenResult = await managementAPIClient
@@ -313,7 +307,7 @@ const envFileHandler = async (
313307
}CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
314308
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false\nCONTENTSTACK_API_HOST=${customHost ? customHost : managementAPIHost
315309
}${!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
316-
}\nCONTENTSTACK_APP_HOST=${appHost}\nCONTENTSTACK_MANAGEMENT_TOKEN=${managementTokenResult.uid
310+
}\nCONTENTSTACK_APP_HOST=${appHost}\nCONTENTSTACK_MANAGEMENT_TOKEN=${managementTokenResult.token
317311
}\nCONTENTSTACK_HOST=${cdnHost}`;
318312
result = await writeEnvFile(content, filePath);
319313
break;

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": "1.14.3",
4+
"version": "1.14.4",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {

packages/contentstack-seed/src/commands/cm/stacks/seed.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export default class SeedCommand extends Command {
8080
}),
8181
locale: flags.string({
8282
description: 'Master Locale of the stack',
83+
default: 'en-us',
8384
hidden: true,
8485
}),
8586
};

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
@@ -26,14 +26,14 @@
2626
"@contentstack/cli-cm-export": "~1.23.2",
2727
"@contentstack/cli-cm-import": "~1.31.3",
2828
"@contentstack/cli-auth": "~1.7.3",
29-
"@contentstack/cli-cm-bootstrap": "~1.18.4",
29+
"@contentstack/cli-cm-bootstrap": "~1.18.5",
3030
"@contentstack/cli-cm-branches": "~1.6.3",
3131
"@contentstack/cli-cm-bulk-publish": "~1.10.7",
3232
"@contentstack/cli-cm-clone": "~1.20.1",
3333
"@contentstack/cli-cm-export-to-csv": "~1.11.0",
3434
"@contentstack/cli-cm-import-setup": "~1.7.3",
3535
"@contentstack/cli-cm-migrate-rte": "~1.6.4",
36-
"@contentstack/cli-cm-seed": "~1.14.3",
36+
"@contentstack/cli-cm-seed": "~1.14.4",
3737
"@contentstack/cli-command": "~1.7.2",
3838
"@contentstack/cli-config": "~1.19.0",
3939
"@contentstack/cli-launch": "^1.9.6",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)