diff --git a/src/base-command.ts b/src/base-command.ts index 570b3b0..6ab435e 100644 --- a/src/base-command.ts +++ b/src/base-command.ts @@ -70,9 +70,9 @@ export abstract class BaseCommand extends Command { this.registerConfig(); this.developerHubBaseUrl = - this.sharedConfig.developerHubBaseUrl || (await getDeveloperHubUrl()); + this.sharedConfig.developerHubBaseUrl || getDeveloperHubUrl(); await this.initCmaSDK(); - + // Init logger const logger = new Logger(this.sharedConfig); this.log = logger.log.bind(logger); @@ -164,9 +164,9 @@ export abstract class BaseCommand extends Command { validateRegionAndAuth() { if (this.region) { if (!isAuthenticated()) { - this.log(this.messages.CLI_APP_CLI_LOGIN_FAILED, "error"); - this.exit(1); - } + this.log(this.messages.CLI_APP_CLI_LOGIN_FAILED, "error"); + this.exit(1); + } } } } diff --git a/src/config/index.ts b/src/config/index.ts index a0f84d4..b0ba642 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -5,16 +5,6 @@ const config = { manifestPath: resolve(__dirname, "manifest.json"), boilerplateName: "marketplace-app-boilerplate-main", developerHubBaseUrl: "", - developerHubUrls: { - // NOTE CDA url used as developer-hub url mapper to avoid conflict if user used any custom name - "https://api.contentstack.io": "developerhub-api.contentstack.com", - "https://eu-api.contentstack.com": "eu-developerhub-api.contentstack.com", - "https://azure-na-api.contentstack.com": - "azure-na-developerhub-api.contentstack.com", - "https://azure-eu-api.contentstack.com": - "azure-eu-developerhub-api.contentstack.com", - "https://gcp-na-api.contentstack.com": "gcp-na-developerhub-api.contentstack.com", - }, appBoilerplateGithubUrl: "https://codeload.github.com/contentstack/marketplace-app-boilerplate/zip/refs/heads/main", defaultAppFileName: "manifest", diff --git a/src/util/inquirer.ts b/src/util/inquirer.ts index 4d6bfb8..51f44e2 100644 --- a/src/util/inquirer.ts +++ b/src/util/inquirer.ts @@ -158,7 +158,7 @@ async function getInstalledApps( * * @return {*} {Promise} */ -async function getDeveloperHubUrl(): Promise { +function getDeveloperHubUrl(): string { const { cma } = configHandler.get("region") || {}; let developerHubBaseUrl = cma.replace("api", "developerhub-api"); diff --git a/test/unit/commands/app/create.test.ts b/test/unit/commands/app/create.test.ts index 587a6f5..cedd9ea 100644 --- a/test/unit/commands/app/create.test.ts +++ b/test/unit/commands/app/create.test.ts @@ -12,14 +12,13 @@ import config from "../../../../src/config"; import messages from "../../../../src/messages"; import * as mock from "../../mock/common.mock.json"; import manifestData from "../../../../src/config/manifest.json"; +import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; const { origin, pathname } = new URL(config.appBoilerplateGithubUrl); const zipPath = join(process.cwd(), "test", "unit", "mock", "boilerplate.zip"); const region: { cma: string; name: string; cda: string } = configHandler.get("region"); -const developerHubBaseUrl = (config.developerHubUrls as Record)[ - region.cma -]; +const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:create", () => { beforeEach(() => { diff --git a/test/unit/commands/app/delete.test.ts b/test/unit/commands/app/delete.test.ts index eadbaae..c3d8dea 100644 --- a/test/unit/commands/app/delete.test.ts +++ b/test/unit/commands/app/delete.test.ts @@ -2,14 +2,12 @@ import { test, expect } from "@oclif/test"; import { cliux, configHandler, ux } from "@contentstack/cli-utilities"; import * as mock from "../../mock/common.mock.json" -import config from "../../../../src/config"; import messages, {$t} from "../../../../src/messages"; +import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; const region: { cma: string; name: string; cda: string } = configHandler.get("region"); -const developerHubBaseUrl = (config.developerHubUrls as Record)[ - region.cma -]; +const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:delete", () => { describe("app:delete with --org and --app-uid flags", () => { diff --git a/test/unit/commands/app/get.test.ts b/test/unit/commands/app/get.test.ts index 0202dbd..c71ff7c 100644 --- a/test/unit/commands/app/get.test.ts +++ b/test/unit/commands/app/get.test.ts @@ -9,12 +9,12 @@ import * as mock from "../../mock/common.mock.json"; import manifestData from "../../config/manifest.json"; import messages, { $t } from "../../../../src/messages"; import * as commonUtils from "../../../../src/util/common-utils"; +import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; const region: { cma: string; name: string; cda: string } = configHandler.get("region"); -const developerHubBaseUrl = (config.developerHubUrls as Record)[ - region.cma -]; +const developerHubBaseUrl = getDeveloperHubUrl(); + describe("app:get", () => { describe("Get app manifest", () => { diff --git a/test/unit/commands/app/install.test.ts b/test/unit/commands/app/install.test.ts index 694d367..7516db4 100644 --- a/test/unit/commands/app/install.test.ts +++ b/test/unit/commands/app/install.test.ts @@ -3,11 +3,11 @@ import {expect, test} from "@oclif/test"; import * as mock from "../../mock/common.mock.json" -import config from "../../../../src/config"; import messages, { $t } from "../../../../src/messages"; +import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; const region: { cma: string, cda: string, name: string } = configHandler.get("region"); -const developerHubBaseUrl = (config.developerHubUrls as Record)[region.cma]; +const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:install", () => { describe("Install an app on organization", () => { diff --git a/test/unit/commands/app/reinstall.test.ts b/test/unit/commands/app/reinstall.test.ts index a73baf1..d34b546 100644 --- a/test/unit/commands/app/reinstall.test.ts +++ b/test/unit/commands/app/reinstall.test.ts @@ -2,14 +2,16 @@ import { ux, cliux, configHandler } from "@contentstack/cli-utilities"; import { expect, test } from "@oclif/test"; import * as mock from "../../mock/common.mock.json"; import messages, { $t } from "../../../../src/messages"; +import { getDeveloperHubUrl } from "../../../../lib/util/inquirer"; const region: { cma: string; cda: string; name: string } = configHandler.get("region"); -const developerHubBaseUrl = configHandler.get("developerHubBaseUrl"); +const developerHubBaseUrl = getDeveloperHubUrl(); + describe("app:reinstall", () => { describe("Reinstall an app on a stack", () => { test - .stdout({ print: true }) + .stdout({ print: process.env.PRINT === "true" || false }) .stub(ux.action, "stop", () => {}) .stub(ux.action, "start", () => {}) .stub(cliux, "inquire", async (...args: any) => { diff --git a/test/unit/commands/app/uninstall.test.ts b/test/unit/commands/app/uninstall.test.ts index 55157a0..55cf098 100644 --- a/test/unit/commands/app/uninstall.test.ts +++ b/test/unit/commands/app/uninstall.test.ts @@ -3,11 +3,11 @@ import { expect, test } from "@oclif/test"; import * as mock from "../../mock/common.mock.json" -import config from "../../../../src/config" import messages, {$t} from "../../../../src/messages"; +import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; const region: { cma: string, cda: string, name: string } = configHandler.get("region"); -const developerHubBaseUrl = (config.developerHubUrls as Record)[region.cma]; +const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:uninstall", () => { describe("Uninstall an app from organization", () => { diff --git a/test/unit/commands/app/update.test.ts b/test/unit/commands/app/update.test.ts index 39f2ec9..36f375e 100644 --- a/test/unit/commands/app/update.test.ts +++ b/test/unit/commands/app/update.test.ts @@ -4,16 +4,14 @@ import { PassThrough } from "stream"; import { expect, test } from "@oclif/test"; import { cliux, ux, configHandler } from "@contentstack/cli-utilities"; -import config from "../../../../src/config"; import messages from "../../../../src/messages"; import * as mock from "../../mock/common.mock.json"; import manifestData from "../../config/manifest.json"; +import { getDeveloperHubUrl } from "../../../../src/util/inquirer"; const region: { cma: string; name: string; cda: string } = configHandler.get("region"); -const developerHubBaseUrl = (config.developerHubUrls as Record)[ - region.cma -]; +const developerHubBaseUrl = getDeveloperHubUrl(); describe("app:update", () => { describe("Update app with `--app-manifest` flag", () => { diff --git a/test/unit/util/common-utils.test.ts b/test/unit/util/common-utils.test.ts index ea166bd..8c288df 100644 --- a/test/unit/util/common-utils.test.ts +++ b/test/unit/util/common-utils.test.ts @@ -7,16 +7,15 @@ import { managementSDKClient, } from "@contentstack/cli-utilities"; -import config from "../../../src/config"; import { LogFn } from "../../../src/types"; import * as mock from "../mock/common.mock.json"; import { fetchApps, getOrganizations } from "../../../src/util/common-utils"; +import { getDeveloperHubUrl } from "../../../src/util/inquirer"; const region: { cma: string; name: string; cda: string } = configHandler.get("region"); -const developerHubBaseUrl = (config.developerHubUrls as Record)[ - region.cma -]; +const developerHubBaseUrl = getDeveloperHubUrl(); + describe("common utils", () => { const log: LogFn = () => {};