Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compass app integration and removed error messages while importing a stack #1469

Merged
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.9.4 darwin-arm64 node-v22.2.0
@contentstack/cli-cm-bootstrap/1.10.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.9.4",
"version": "1.10.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion packages/contentstack-bootstrap/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface BootstrapOptions {
accessToken?: string;
appType: string;
livePreviewEnabled?: boolean;
master_locale: any;
}

export interface SeedParams {
Expand Down Expand Up @@ -97,6 +98,9 @@ export default class Bootstrap {
if (this.options.seedParams.managementTokenAlias) {
cmd.push('--alias', this.options.seedParams.managementTokenAlias);
}
if (this.options.master_locale) {
cmd.push('--locale', this.options.master_locale);
}

const result = await ContentStackSeed.run(cmd);
if (result && result.api_key) {
Expand Down Expand Up @@ -127,4 +131,4 @@ export default class Bootstrap {
cliux.error(messageHandler.parse('CLI_BOOTSTRAP_STACK_CREATION_FAILED', this.appConfig.stack));
}
}
}
}
59 changes: 53 additions & 6 deletions packages/contentstack-bootstrap/src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface EnviornmentVariables {
* Create delivery token
* Create enviroment
*/

let managementTokenResult: any;
export const setupEnvironments = async (
managementAPIClient: any,
api_key: string,
Expand All @@ -34,6 +34,51 @@ export const setupEnvironments = async (
.environment()
.query()
.find();

//create management token if not present
if(!managementToken){
const managementBody = {
"token":{
"name":"sample app",
"description":"This is a sample management token.",
"scope":[
{
"module":"content_type",
"acl":{
"read":true,
"write":true
}
},
{
"module":"branch",
"branches":[
"main"
],
"acl":{
"read":true
}
}
],
"expires_on": "3000-01-01",
"is_email_notification_enabled":false
}
}
managementTokenResult = await managementAPIClient
.stack({ api_key: api_key })
.managementToken()
.create(managementBody);
if(!managementTokenResult.uid){
cliux.print(
`Info: Failed to generate a management token.\nNote: Management token is not available in your plan. Please contact the admin for support.`,
{
color: 'yellow',
},
);
if ((await continueBootstrapCommand()) === 'no') {
return;
}
}
}
if (Array.isArray(environmentResult.items) && environmentResult.items.length > 0) {
for (const environment of environmentResult.items) {
if (environment.name) {
Expand Down Expand Up @@ -144,6 +189,7 @@ const envFileHandler = async (
const managementAPIHost = region?.cma?.substring('8');
const regionName = region && region.name && region.name.toLowerCase();
previewHost = region?.uiHost?.substring(8)?.replace('app', 'rest-preview');
const cdnHost = region?.cda?.substring('8');
appHost = region?.uiHost?.substring(8);
const isUSRegion = regionName === 'us' || regionName === 'na';
if (regionName !== 'eu' && !isUSRegion) {
Expand Down Expand Up @@ -194,19 +240,20 @@ const envFileHandler = async (
filePath = pathValidator(path.join(sanitizePath(clonedDirectory), sanitizePath(fileName)));
content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${
environmentVariables.deliveryToken
}\n${
}\nCONTENTSTACK_BRANCH=main${
livePreviewEnabled
? `\nCONTENTSTACK_PREVIEW_TOKEN=${
environmentVariables.preview_token || `''`
}\nCONTENTSTACK_PREVIEW_HOST=${previewHost}\nCONTENTSTACK_APP_HOST=${appHost}\n`
}\nCONTENTSTACK_PREVIEW_HOST=${previewHost}\n`
: '\n'
}CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${
}CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${
!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false\nCONTENTSTACK_API_HOST=${
customHost ? customHost : managementAPIHost
}${
!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
}\nCONTENTSTACK_APP_HOST=${appHost}\nCONTENTSTACK_MANAGEMENT_TOKEN=${managementTokenResult.uid}\nCONTENTSTACK_HOST=${cdnHost}`;
result = await writeEnvFile(content, filePath);
break;
case 'gatsby':
case 'gatsby-starter':
fileName = `.env.${environmentVariables.environment}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import config, { getAppLevelConfigByName, AppConfig } from '../../config';
import messageHandler from '../../messages';

export const DEFAULT_MASTER_LOCALE = 'en-us';
export default class BootstrapCommand extends Command {
private bootstrapManagementAPIClient: any;

Expand Down Expand Up @@ -152,6 +153,8 @@ export default class BootstrapCommand extends Command {
const yes = bootstrapCommandFlags.yes as string;

const appConfig: AppConfig = getAppLevelConfigByName(selectedAppName || selectedApp.configKey);

let master_locale = appConfig.master_locale || DEFAULT_MASTER_LOCALE;

let cloneDirectory =
(bootstrapCommandFlags.directory as string) || (bootstrapCommandFlags['project-dir'] as string);
Expand Down Expand Up @@ -187,11 +190,12 @@ export default class BootstrapCommand extends Command {
region: this.region,
appType,
livePreviewEnabled,
master_locale,
};
const bootstrap = new Bootstrap(options);
await bootstrap.run();
} catch (error: any) {
this.error(error, { exit: 1, suggestions: error.suggestions });
}
}
}
}
8 changes: 5 additions & 3 deletions packages/contentstack-bootstrap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface AppConfig {
private?: boolean;
branch?: string;
appConfigKey?: string;
master_locale?: string;
}

const config: Configuration = {
Expand Down Expand Up @@ -49,8 +50,9 @@ const config: Configuration = {
stack: 'contentstack/stack-contentstack-angular-modularblock-example',
},
'compass-app': {
source: 'SunilLsagar/universal-demo',
stack: 'SunilLsagar/stack-universal-demo',
source: 'SunilLsagar/universal-demo-latest',
stack: 'SunilLsagar/stack-universal-demo-latest',
master_locale: 'en',
},
'nuxtjs-disabled': {
source: 'contentstack/contentstack-nuxtjs-vue-universal-demo',
Expand Down Expand Up @@ -98,4 +100,4 @@ export function getAppLevelConfigByName(appConfigKey: string): any {
}
config.appLevelConfig[appConfigKey].appConfigKey = appConfigKey;
return config.appLevelConfig[appConfigKey];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class ImportCustomRoles extends BaseClass {
this.customRoles = fsUtil.readFile(join(this.customRolesFolderPath, this.customRolesConfig.fileName),true) as Record<string, unknown>;
this.customRolesLocales = fsUtil.readFile(join(this.customRolesFolderPath, this.customRolesConfig.customRolesLocalesFileName),true) as Record<string, unknown>;
} else {
log(this.importConfig, `No such file or directory - '${this.customRolesFolderPath}'`, 'error');
log(this.importConfig, `No custom-rules are found - '${this.customRolesFolderPath}'`, 'info');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class ImportEnvironments extends BaseClass {
unknown
>;
} else {
log(this.importConfig, `No such file or directory - '${this.environmentsFolderPath}'`, 'error');
log(this.importConfig, `No Environments Found - '${this.environmentsFolderPath}'`, 'info');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class ImportExtensions extends BaseClass {
Record<string, unknown>
>;
} else {
log(this.importConfig, `No such file or directory - '${this.extensionsFolderPath}'`, 'error');
log(this.importConfig, `No Extensions Found - '${this.extensionsFolderPath}'`, 'info');
return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-import/src/import/modules/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class Importlabels extends BaseClass {
if (fileHelper.fileExistsSync(this.labelsFolderPath)) {
this.labels = fsUtil.readFile(join(this.labelsFolderPath, 'labels.json'), true) as Record<string, unknown>;
} else {
log(this.importConfig, `No such file or directory - '${this.labelsFolderPath}'`, 'error');
log(this.importConfig, `No labels found - '${this.labelsFolderPath}'`, 'info');
return;
}

Expand All @@ -71,7 +71,7 @@ export default class Importlabels extends BaseClass {

async importlabels() {
if (this.labels === undefined || isEmpty(this.labels)) {
log(this.importConfig, 'No Label Found', 'info');
log(this.importConfig, 'No Labels Found', 'info');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class ImportMarketplaceApps {
true,
) as Installation[];
} else {
log(this.importConfig, `No such file or directory - '${this.marketPlaceFolderPath}'`, 'error');
log(this.importConfig, `No Marketplace apps are found - '${this.marketPlaceFolderPath}'`, 'info');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class ImportTaxonomies extends BaseClass {
unknown
>;
} else {
log(this.importConfig, `No such file or directory - '${this.taxonomiesFolderPath}'`, 'error');
log(this.importConfig, `No Taxonomies Found! - '${this.taxonomiesFolderPath}'`, 'info');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class ImportWebhooks extends BaseClass {
if (fileHelper.fileExistsSync(this.webhooksFolderPath)) {
this.webhooks = fsUtil.readFile(join(this.webhooksFolderPath, 'webhooks.json'), true) as Record<string, unknown>;
} else {
log(this.importConfig, `No such file or directory - '${this.webhooksFolderPath}'`, 'error');
log(this.importConfig, `No Webhooks Found - '${this.webhooksFolderPath}'`, 'info');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class ImportWorkflows extends BaseClass {
unknown
>;
} else {
log(this.importConfig, `No such file or directory - '${this.workflowsFolderPath}'`, 'error');
log(this.importConfig, `No Workflows Found - '${this.workflowsFolderPath}'`, 'info');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = ({ migration, stackSDKInstance, managementAPIClient, config })
task: async (params) => {
try {
stack = stackClient();
if (!fs.existsSync(dataDir)) throw new Error(`No such file or directory - ${dataDir}`);
if (!fs.existsSync(dataDir)) throw new Error(`No Taxonomies folder found! - ${dataDir}`);
const taxonomies = await readCsv(dataDir, { headers: true, delimiter });

if (!taxonomies?.length) throw new Error('No Taxonomies found!');
Expand Down
14 changes: 8 additions & 6 deletions packages/contentstack-seed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ To import content to your stack, you can choose from the following two sources:
<!-- usagestop -->
## Commands
<!-- commands -->
* [`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)
* [`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-1)
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y-value--s-value---locale-value)
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y-value--s-value---locale-value-1)

## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]`
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]`

Create a stack from existing content types, entries, assets, etc

```
USAGE
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale
<value>]

FLAGS
-a, --alias=<value> Alias of the management token
Expand Down Expand Up @@ -48,13 +49,14 @@ EXAMPLES
$ csdx cm:stacks:seed --repo "account/repository" --org "your-org-uid" --stack-name "stack-name" //create a new stack in given org uid
```

## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]`
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]`

Create a stack from existing content types, entries, assets, etc

```
USAGE
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale
<value>]

FLAGS
-a, --alias=<value> Alias of the management token
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-seed",
"description": "create a Stack from existing content types, entries, assets, etc.",
"version": "1.7.7",
"version": "1.7.8",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
Loading
Loading