Skip to content

Commit

Permalink
Compass app integration and removed error messages while importing a …
Browse files Browse the repository at this point in the history
…stack.
  • Loading branch information
sunil-lakshman committed Jul 22, 2024
1 parent b08bac8 commit e9c40b8
Show file tree
Hide file tree
Showing 25 changed files with 122 additions and 57 deletions.
8 changes: 4 additions & 4 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.3 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.3",
"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));
}
}
}
}
44 changes: 41 additions & 3 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,40 @@ 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 (Array.isArray(environmentResult.items) && environmentResult.items.length > 0) {
for (const environment of environmentResult.items) {
if (environment.name) {
Expand Down Expand Up @@ -144,6 +178,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?.uiHost?.substring(8)?.replace('app', 'cdn');
appHost = region?.uiHost?.substring(8);
const isUSRegion = regionName === 'us' || regionName === 'na';
if (regionName !== 'eu' && !isUSRegion) {
Expand Down Expand Up @@ -204,9 +239,12 @@ const envFileHandler = async (
customHost ? customHost : managementAPIHost
}${
!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false\nCONTENTSTACK_API_HOST=${
customHost ? customHost : managementAPIHost
}${
!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
}\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
6 changes: 5 additions & 1 deletion packages/contentstack-bootstrap/src/commands/cm/bootstrap.ts
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 All @@ -29,7 +30,7 @@ const config: Configuration = {
{ displayName: 'Vue JS', configKey: 'vue-starter' },
{ displayName: 'Stencil', configKey: 'stencil-starter' },
{ displayName: 'Nuxt3', configKey: 'nuxt3-starter' },
// { displayName: 'Compass App', configKey: 'compass-app' }
{ displayName: 'Compass App', configKey: 'compass-app' }
],
appLevelConfig: {
nextjs: {
Expand All @@ -50,7 +51,8 @@ const config: Configuration = {
},
'compass-app': {
source: 'SunilLsagar/universal-demo',
stack: 'SunilLsagar/stack-universal-demo',
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];
}
}
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.16.0 darwin-arm64 node-v22.2.0
@contentstack/cli-cm-import/1.16.1 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.16.0",
"version": "1.16.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
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 @@ -78,7 +78,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
2 changes: 1 addition & 1 deletion packages/contentstack-launch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-launch
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-launch/1.0.19 darwin-arm64 node-v18.20.2
@contentstack/cli-launch/1.0.19 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
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
Loading

0 comments on commit e9c40b8

Please sign in to comment.