Skip to content

Commit

Permalink
Merge pull request #1507 from contentstack/staging
Browse files Browse the repository at this point in the history
DX | 08-08-2024 | Release
  • Loading branch information
cs-raj authored Aug 12, 2024
2 parents 1637d05 + 26a1ea3 commit 3e5383c
Show file tree
Hide file tree
Showing 48 changed files with 601 additions and 1,093 deletions.
695 changes: 94 additions & 601 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.6.4 darwin-arm64 node-v22.2.0
@contentstack/cli-audit/1.6.5 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.6.4",
"version": "1.6.5",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand All @@ -19,7 +19,7 @@
],
"dependencies": {
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^5.0.0",
"chalk": "^4.1.2",
Expand Down Expand Up @@ -86,4 +86,4 @@
"keywords": [
"oclif"
]
}
}
13 changes: 4 additions & 9 deletions packages/contentstack-audit/src/messages/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import memoize from 'lodash/memoize';
import { escapeRegExp, validateRegex } from '@contentstack/cli-utilities';

const errors = {};

Expand Down Expand Up @@ -47,7 +46,7 @@ const auditFixMsg = {
AUDIT_FIX_CMD_DESCRIPTION: 'Perform audits and fix possible errors in the exported Contentstack data.',
WF_FIX_MSG: 'Successfully removed the workflow {uid} named {name}.',
ENTRY_MANDATORY_FIELD_FIX: `Removing the publish details from the entry with UID '{uid}' in Locale '{locale}'...`,
ENTRY_SELECT_FIELD_FIX: `Adding the value '{value}' in the select field of entry UID '{uid}'...`
ENTRY_SELECT_FIELD_FIX: `Adding the value '{value}' in the select field of entry UID '{uid}'...`,
};

const messages: typeof errors &
Expand Down Expand Up @@ -76,13 +75,9 @@ function $t(msg: string, args: Record<string, string>): string {
if (!msg) return '';

for (const key of Object.keys(args)) {
const escapedKey = escapeRegExp(key);
const escapedKeyRegex = new RegExp(`{${escapedKey}}`, 'g');
let { status } = validateRegex(escapedKeyRegex)
if (status === 'safe') {
const sanitizedValue = args[key] ? escapeRegExp(args[key]) : '';
msg = msg.replace(escapedKeyRegex, sanitizedValue || escapedKey);
}
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const placeholder = `{${escapedKey}}`;
msg = msg.split(placeholder).join(args[key]);
}

return msg;
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
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
4 changes: 2 additions & 2 deletions 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 All @@ -19,7 +19,7 @@
"dependencies": {
"@contentstack/cli-cm-seed": "~1.7.6",
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"inquirer": "8.2.4",
"mkdirp": "^1.0.4",
"tar": "^6.2.1 "
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
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 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: 'contentstack/contentstack-universal-demo',
stack: 'contentstack/stack-contentstack-universal-demo',
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-branches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"@oclif/core": "^3.26.5",
"async": "^3.2.4",
"big-json": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"bluebird": "^3.7.2",
"chalk": "^4.1.2",
"dotenv": "^16.1.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.11.6",
"@contentstack/cli-cm-import": "~1.16.4",
"@contentstack/cli-cm-import": "~1.16.5",
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"async": "^3.2.4",
"chalk": "^4.1.0",
"child_process": "^1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-command/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"format": "eslint src/**/*.ts --fix"
},
"dependencies": {
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"contentstack": "^3.10.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"chalk": "^4.1.0",
"fast-csv": "^4.3.6",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/cli-utilities": "~1.7.1",
"@oclif/core": "^3.26.5",
"async": "^3.2.4",
"big-json": "^3.2.0",
Expand Down
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.4 darwin-arm64 node-v22.2.0
@contentstack/cli-cm-import/1.16.5 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
8 changes: 4 additions & 4 deletions packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.16.4",
"version": "1.16.5",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-audit": "~1.6.3",
"@contentstack/cli-audit": "~1.6.5",
"@contentstack/cli-command": "~1.2.19",
"@contentstack/cli-utilities": "~1.7.0",
"@contentstack/management": "~1.15.3",
"@contentstack/cli-utilities": "~1.7.1",
"@contentstack/management": "~1.17.0",
"@oclif/core": "^3.26.5",
"big-json": "^3.2.0",
"bluebird": "^3.7.2",
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
Loading

0 comments on commit 3e5383c

Please sign in to comment.