Skip to content

Commit

Permalink
fix: Resolved the issue of private apps re-creation after selecting n…
Browse files Browse the repository at this point in the history
…o by skipping the private app. Version bump
  • Loading branch information
cs-raj committed Mar 28, 2024
1 parent b9633a5 commit 5da1cef
Show file tree
Hide file tree
Showing 9 changed files with 450 additions and 239 deletions.
588 changes: 394 additions & 194 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.11.1",
"@contentstack/cli-cm-import": "~1.15.0",
"@contentstack/cli-cm-import": "~1.15.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"async": "^3.2.4",
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.15.0",
"version": "1.15.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
61 changes: 34 additions & 27 deletions packages/contentstack-import/src/import/modules/marketplace-apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,35 +231,38 @@ export default class ImportMarketplaceApps {
return Promise.resolve();
}

await getConfirmationToCreateApps(privateApps, this.importConfig);

log(this.importConfig, 'Starting developer hub private apps re-creation', 'success');
let canCreatePrivateApp = await getConfirmationToCreateApps(privateApps, this.importConfig);
this.importConfig.canCreatePrivateApp = canCreatePrivateApp;
if (canCreatePrivateApp) {
log(this.importConfig, 'Starting developer hub private apps re-creation', 'success');
for (let app of privateApps) {
if (this.importConfig.skipPrivateAppRecreationIfExist && (await this.isPrivateAppExistInDeveloperHub(app))) {
// NOTE Found app already exist in the same org
this.appUidMapping[app.uid] = app.uid;
cliux.print(`App '${app.manifest.name}' already exist. skipping app recreation.!`, { color: 'yellow' });
continue;
}

for (let app of privateApps) {
if (this.importConfig.skipPrivateAppRecreationIfExist && (await this.isPrivateAppExistInDeveloperHub(app))) {
// NOTE Found app already exist in the same org
this.appUidMapping[app.uid] = app.uid;
cliux.print(`App '${app.manifest.name}' already exist. skipping app recreation.!`, { color: 'yellow' });
continue;
// NOTE keys can be passed to install new app in the developer hub
const validKeys = [
'uid',
'name',
'icon',
'oauth',
'webhook',
'visibility',
'target_type',
'description',
'ui_location',
'framework_version',
];
const manifest = pick(app.manifest, validKeys) as Manifest;
this.appOriginalName = manifest.name;

await this.createPrivateApp(manifest);
}

// NOTE keys can be passed to install new app in the developer hub
const validKeys = [
'uid',
'name',
'icon',
'oauth',
'webhook',
'visibility',
'target_type',
'description',
'ui_location',
'framework_version',
];
const manifest = pick(app.manifest, validKeys) as Manifest;
this.appOriginalName = manifest.name;

await this.createPrivateApp(manifest);
} else {
log(this.importConfig, 'Skipping developer hub private apps creation', 'success');
}

this.appOriginalName = undefined;
Expand Down Expand Up @@ -422,6 +425,10 @@ export default class ImportMarketplaceApps {

if (!currentStackApp) {
// NOTE install new app
if (app.manifest.visibility === 'private' && !this.importConfig.canCreatePrivateApp) {
log(this.importConfig, `Skipping the installation of Private App ${app.manifest.name}`, 'info');
return Promise.resolve();
}
const installation = await this.installApp(
this.importConfig,
// NOTE if it's private app it should get uid from mapper else will use manifest uid
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-import/src/types/import-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ExternalConfig {
}

export default interface ImportConfig extends DefaultConfig, ExternalConfig {
canCreatePrivateApp: boolean;
contentDir: string;
data: string;
management_token?: string;
Expand Down
23 changes: 13 additions & 10 deletions packages/contentstack-import/src/utils/marketplace-app-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
configHandler,
managementSDKClient,
marketplaceSDKClient,
createDeveloperHubUrl
createDeveloperHubUrl,
} from '@contentstack/cli-utilities';

import { log } from './logger';
Expand Down Expand Up @@ -72,6 +72,7 @@ export const getOrgUid = async (config: ImportConfig): Promise<string> => {
};

export const getConfirmationToCreateApps = async (privateApps: any, config: ImportConfig): Promise<boolean> => {
console.log(privateApps);
if (!config.forceStopMarketplaceAppsPrompt) {
if (
!(await cliux.confirm(
Expand All @@ -90,15 +91,17 @@ export const getConfirmationToCreateApps = async (privateApps: any, config: Impo
),
)
) {
return Promise.resolve(true);
}

if (
!(await cliux.confirm(
chalk.yellow('\nWould you like to re-create the private app and then proceed with the installation? (y/n)'),
))
) {
process.exit();
return Promise.resolve(false);
} else {
if (
!(await cliux.confirm(
chalk.yellow('\nWould you like to re-create the private app and then proceed with the installation? (y/n)'),
))
) {
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-cm-import": "~1.15.0",
"@contentstack/cli-cm-import": "~1.15.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"inquirer": "8.2.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli",
"description": "Command-line tool (CLI) to interact with Contentstack",
"version": "1.17.0",
"version": "1.17.1",
"author": "Contentstack",
"bin": {
"csdx": "./bin/run"
Expand Down Expand Up @@ -30,7 +30,7 @@
"@contentstack/cli-cm-export": "~1.11.1",
"@contentstack/cli-cm-clone": "~1.10.3",
"@contentstack/cli-cm-export-to-csv": "~1.7.0",
"@contentstack/cli-cm-import": "~1.15.0",
"@contentstack/cli-cm-import": "~1.15.1",
"@contentstack/cli-cm-migrate-rte": "~1.4.15",
"@contentstack/cli-cm-seed": "~1.7.3",
"@contentstack/cli-command": "~1.2.17",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

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

0 comments on commit 5da1cef

Please sign in to comment.