Skip to content

Commit

Permalink
Merge pull request #1270 from contentstack/refactor/CS-43461
Browse files Browse the repository at this point in the history
refactor: Launch base class refactor
  • Loading branch information
antonyagustine authored Jan 29, 2024
2 parents 9ed1453 + 67cfdf9 commit d26ab7c
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 26 deletions.
1 change: 1 addition & 0 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions packages/contentstack-launch/src/adapters/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ export default class GitHub extends BaseClass {
async createNewProject(): Promise<void> {
const {
branch,
provider,
framework,
repository,
projectName,
buildCommand,
selectedStack,
outputDirectory,
environmentName,
provider: gitProvider,
} = this.config;
const username = split(repository?.fullName, "/")[0];
const username = split(repository?.fullName, '/')[0];

await this.apolloClient
.mutate({
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>;
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
Expand All @@ -36,8 +36,6 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
protected flags!: Flags<T>;
protected args!: Args<T>;

static hidden = true;

// define flags that can be inherited by any command that extends BaseCommand
static baseFlags: FlagInput = {
'data-dir': Flags.string({
Expand Down Expand Up @@ -107,9 +105,9 @@ export abstract class BaseCommand<T extends typeof Command> 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<string, string>)[this.cmaAPIUrl];
const baseUrl = config.launchBaseUrl || (config.launchHubUrls as Record<string, string>)[this.cmaAPIUrl];
this.sharedConfig = {
...require('../../config').default,
...require('./config').default,
currentConfig: {},
...this.flags,
flags: this.flags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Deployments> {
static hidden = false;
static description = 'Show list of deployments for an environment';

static examples = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Environments> {
static hidden = false;
static description = 'Show list of environments for a project';

static examples = [
Expand Down
Original file line number Diff line number Diff line change
@@ -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<typeof Functions> {
static hidden = false;
static description = 'Serve cloud functions';

static examples = [
Expand Down
5 changes: 2 additions & 3 deletions packages/contentstack-launch/src/commands/launch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Launch> {
public preCheck!: PreCheck;

static hidden = false;

static description = 'Launch related operations';

static examples = [
Expand Down Expand Up @@ -58,6 +56,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
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.',
}),
};
Expand Down
3 changes: 1 addition & 2 deletions packages/contentstack-launch/src/commands/launch/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Logs> {
static hidden = false;
static description = 'Show deployment or server logs';

static examples = [
Expand Down
3 changes: 1 addition & 2 deletions packages/contentstack-launch/src/commands/launch/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Open> {
static hidden = false;
static description = 'Open a website for an environment';

static examples = [
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-launch/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 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 d26ab7c

Please sign in to comment.