From 8b5b3074bf54cfdcbd63b6ce6d67228eee8c1482 Mon Sep 17 00:00:00 2001 From: Antony Date: Mon, 29 Jan 2024 15:23:55 +0530 Subject: [PATCH] refactor: Launch base class refactor --- package-lock.json | 1 + packages/contentstack-launch/src/adapters/github.ts | 6 +++--- .../src/{commands/launch => }/base-command.ts | 12 +++++------- .../src/commands/launch/deployments.ts | 3 +-- .../src/commands/launch/environments.ts | 3 +-- .../src/commands/launch/functions.ts | 3 +-- .../contentstack-launch/src/commands/launch/index.ts | 5 ++--- .../contentstack-launch/src/commands/launch/logs.ts | 3 +-- .../contentstack-launch/src/commands/launch/open.ts | 3 +-- packages/contentstack-launch/src/config/index.ts | 1 + pnpm-lock.yaml | 8 +++++--- 11 files changed, 22 insertions(+), 26 deletions(-) rename packages/contentstack-launch/src/{commands/launch => }/base-command.ts (95%) diff --git a/package-lock.json b/package-lock.json index ca5dd8be5f..1516d9804c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24238,6 +24238,7 @@ "child_process": "^1.0.2", "fancy-test": "^1.4.10", "inquirer": "8.2.4", + "lodash": "^4.17.20", "merge": "^2.1.1", "ora": "^5.1.0", "prompt": "^1.3.0", diff --git a/packages/contentstack-launch/src/adapters/github.ts b/packages/contentstack-launch/src/adapters/github.ts index d140932e2f..e6b049cf34 100755 --- a/packages/contentstack-launch/src/adapters/github.ts +++ b/packages/contentstack-launch/src/adapters/github.ts @@ -60,7 +60,6 @@ export default class GitHub extends BaseClass { async createNewProject(): Promise { const { branch, - provider, framework, repository, projectName, @@ -68,8 +67,9 @@ export default class GitHub extends BaseClass { selectedStack, outputDirectory, environmentName, + provider: gitProvider, } = this.config; - const username = split(repository?.fullName, "/")[0]; + const username = split(repository?.fullName, '/')[0]; await this.apolloClient .mutate({ @@ -80,9 +80,9 @@ export default class GitHub extends BaseClass { cmsStackApiKey: selectedStack?.api_key || '', repository: { username, - gitProvider: provider, repositoryUrl: repository?.url, repositoryName: repository?.fullName, + gitProviderMetadata: { gitProvider }, }, environment: { gitBranch: branch, diff --git a/packages/contentstack-launch/src/commands/launch/base-command.ts b/packages/contentstack-launch/src/base-command.ts similarity index 95% rename from packages/contentstack-launch/src/commands/launch/base-command.ts rename to packages/contentstack-launch/src/base-command.ts index 4fdb5551cb..018ef3ecde 100755 --- a/packages/contentstack-launch/src/commands/launch/base-command.ts +++ b/packages/contentstack-launch/src/base-command.ts @@ -17,9 +17,9 @@ import { managementSDKInitiator, } from '@contentstack/cli-utilities'; -import config from '../../config'; -import { GraphqlApiClient, Logger } from '../../util'; -import { ConfigType, LogFn, Providers } from '../../types'; +import config from './config'; +import { GraphqlApiClient, Logger } from './util'; +import { ConfigType, LogFn, Providers } from './types'; export type Flags = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>; export type Args = Interfaces.InferredArgs; @@ -36,8 +36,6 @@ export abstract class BaseCommand extends Command { protected flags!: Flags; protected args!: Args; - static hidden = true; - // define flags that can be inherited by any command that extends BaseCommand static baseFlags: FlagInput = { 'data-dir': Flags.string({ @@ -107,9 +105,9 @@ export abstract class BaseCommand extends Command { this.flags['data-dir'] || this.flags.config ? this.flags.config || resolve(this.flags['data-dir'], config.configName) : resolve(process.cwd(), config.configName); - const baseUrl = (config.launchHubUrls as Record)[this.cmaAPIUrl]; + const baseUrl = config.launchBaseUrl || (config.launchHubUrls as Record)[this.cmaAPIUrl]; this.sharedConfig = { - ...require('../../config').default, + ...require('./config').default, currentConfig: {}, ...this.flags, flags: this.flags, diff --git a/packages/contentstack-launch/src/commands/launch/deployments.ts b/packages/contentstack-launch/src/commands/launch/deployments.ts index ef22181647..07b85ecfb4 100755 --- a/packages/contentstack-launch/src/commands/launch/deployments.ts +++ b/packages/contentstack-launch/src/commands/launch/deployments.ts @@ -4,12 +4,11 @@ import find from 'lodash/find'; import isEmpty from 'lodash/isEmpty'; import { FlagInput, Flags, cliux as ux } from '@contentstack/cli-utilities'; -import { BaseCommand } from './base-command'; +import { BaseCommand } from '../../base-command'; import { environmentsQuery } from '../../graphql'; import { Logger, selectOrg, selectProject } from '../../util'; export default class Deployments extends BaseCommand { - static hidden = false; static description = 'Show list of deployments for an environment'; static examples = [ diff --git a/packages/contentstack-launch/src/commands/launch/environments.ts b/packages/contentstack-launch/src/commands/launch/environments.ts index 45473d76ca..bbab7c9fdc 100755 --- a/packages/contentstack-launch/src/commands/launch/environments.ts +++ b/packages/contentstack-launch/src/commands/launch/environments.ts @@ -4,12 +4,11 @@ import find from 'lodash/find'; import isEmpty from 'lodash/isEmpty'; import { FlagInput, Flags, cliux as ux } from '@contentstack/cli-utilities'; -import { BaseCommand } from './base-command'; +import { BaseCommand } from '../../base-command'; import { Logger, selectOrg, selectProject } from '../../util'; import { environmentsQuery, projectsQuery } from '../../graphql'; export default class Environments extends BaseCommand { - static hidden = false; static description = 'Show list of environments for a project'; static examples = [ diff --git a/packages/contentstack-launch/src/commands/launch/functions.ts b/packages/contentstack-launch/src/commands/launch/functions.ts index 76816b7f33..c5e3b78605 100755 --- a/packages/contentstack-launch/src/commands/launch/functions.ts +++ b/packages/contentstack-launch/src/commands/launch/functions.ts @@ -1,10 +1,9 @@ import { FlagInput, Flags } from '@contentstack/cli-utilities'; -import { BaseCommand } from './base-command'; +import { BaseCommand } from '../../base-command'; import Contentfly from '../../util/cloud-function'; export default class Functions extends BaseCommand { - static hidden = false; static description = 'Serve cloud functions'; static examples = [ diff --git a/packages/contentstack-launch/src/commands/launch/index.ts b/packages/contentstack-launch/src/commands/launch/index.ts index 8fd4cd1e76..06abde2cd4 100755 --- a/packages/contentstack-launch/src/commands/launch/index.ts +++ b/packages/contentstack-launch/src/commands/launch/index.ts @@ -2,15 +2,13 @@ import map from 'lodash/map'; import { FlagInput, Flags } from '@contentstack/cli-utilities'; import config from '../../config'; -import { BaseCommand } from './base-command'; +import { BaseCommand } from '../../base-command'; import { AdapterConstructorInputs } from '../../types'; import { FileUpload, GitHub, PreCheck } from '../../adapters'; export default class Launch extends BaseCommand { public preCheck!: PreCheck; - static hidden = false; - static description = 'Launch related operations'; static examples = [ @@ -58,6 +56,7 @@ export default class Launch extends BaseCommand { description: '[Optional, Hidden] Show variable values on the UI', }), init: Flags.boolean({ + hidden: true, description: '[Optional, Hidden] Reinitialize the project if it is an existing launch project.', }), }; diff --git a/packages/contentstack-launch/src/commands/launch/logs.ts b/packages/contentstack-launch/src/commands/launch/logs.ts index 2be2025ea5..581d56ce66 100755 --- a/packages/contentstack-launch/src/commands/launch/logs.ts +++ b/packages/contentstack-launch/src/commands/launch/logs.ts @@ -5,13 +5,12 @@ import isArray from 'lodash/isArray'; import includes from 'lodash/includes'; import { Flags, FlagInput, cliux as ux } from '@contentstack/cli-utilities'; -import { BaseCommand } from './base-command'; +import { BaseCommand } from '../../base-command'; import { environmentsQuery } from '../../graphql'; import { Logger, LogPolling, selectOrg, selectProject } from '../../util'; import { EmitMessage, DeploymentLogResp, ServerLogResp } from '../../types'; export default class Logs extends BaseCommand { - static hidden = false; static description = 'Show deployment or server logs'; static examples = [ diff --git a/packages/contentstack-launch/src/commands/launch/open.ts b/packages/contentstack-launch/src/commands/launch/open.ts index b68b8ab83a..76a6c24464 100755 --- a/packages/contentstack-launch/src/commands/launch/open.ts +++ b/packages/contentstack-launch/src/commands/launch/open.ts @@ -4,12 +4,11 @@ import find from 'lodash/find'; import isEmpty from 'lodash/isEmpty'; import { FlagInput, Flags, cliux as ux } from '@contentstack/cli-utilities'; -import { BaseCommand } from './base-command'; +import { BaseCommand } from '../../base-command'; import { environmentsQuery } from '../../graphql'; import { print, Logger, selectOrg, selectProject } from '../../util'; export default class Open extends BaseCommand { - static hidden = false; static description = 'Open a website for an environment'; static examples = [ diff --git a/packages/contentstack-launch/src/config/index.ts b/packages/contentstack-launch/src/config/index.ts index 7aab1b2fce..578444da76 100755 --- a/packages/contentstack-launch/src/config/index.ts +++ b/packages/contentstack-launch/src/config/index.ts @@ -28,6 +28,7 @@ const config = { 'https://azure-na-api.contentstack.com': '', 'https://azure-eu-api.contentstack.com': '', }, + launchBaseUrl: '', supportedAdapters: ['GitHub'], deploymentStatus: ['LIVE', 'FAILED', 'SKIPPED', 'DEPLOYED'], pollingInterval: 1000, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c89a21811a..79c0d9f9d9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -438,6 +438,7 @@ importers: globby: ^10.0.2 inquirer: 8.2.4 jest: ^29.4.2 + lodash: ^4.17.20 merge: ^2.1.1 mocha: ^10.0.0 nyc: ^15.1.0 @@ -458,6 +459,7 @@ importers: child_process: 1.0.2 fancy-test: 1.4.10 inquirer: 8.2.4 + lodash: 4.17.21 merge: 2.1.1 ora: 5.4.1 prompt: 1.3.0 @@ -6446,7 +6448,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 6.13.2_7hj7rehet5x3fvq7nqub5sammm + '@typescript-eslint/parser': 6.13.2_sjjl3gun7puonkp27uqtyjm5b4 debug: 3.2.7 eslint: 8.55.0 eslint-import-resolver-node: 0.3.9 @@ -6476,7 +6478,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 6.13.2_7hj7rehet5x3fvq7nqub5sammm + '@typescript-eslint/parser': 6.13.2_sjjl3gun7puonkp27uqtyjm5b4 debug: 3.2.7 eslint: 8.55.0 eslint-import-resolver-typescript: 3.6.1_hdscurta55xxypqxbdhu44qa6e @@ -6581,7 +6583,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 6.13.2_7hj7rehet5x3fvq7nqub5sammm + '@typescript-eslint/parser': 6.13.2_sjjl3gun7puonkp27uqtyjm5b4 array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2