Skip to content

Commit

Permalink
feature: add support for multi-region param (#93)
Browse files Browse the repository at this point in the history
* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: add support for multi region param

* feature: update version

* feature: remove specific error

* feature: version#

* feature: [beta] mutli-region support basic cli flags

* feature: [beta] mutli-region support basic cli flags

* feature: [beta] fix imports

* Feature/shayel/add support for multi region param interactive (#96)

* feature: add support for multi region param

* feature: add support for multi region param

* feature: update version

* feature: [beta] added interactive

* feature: [beta] added interactive

* feature: [beta] added interactive

* feature: [beta] added interactive

* feature: [beta] added interactive

* feature: fix name of type

* feature: fix version

* feature: fix version
  • Loading branch information
ShayElkana authored Jun 3, 2024
1 parent efce815 commit f6ec128
Show file tree
Hide file tree
Showing 26 changed files with 411 additions and 146 deletions.
2 changes: 1 addition & 1 deletion src/commands-base/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export abstract class BaseCommand extends Command {
} as typeof flags & typeof this.sharedFlags;
}

static sharedFlags? = {
static sharedFlags = {
verbose: Flags.boolean({
description: 'Print advanced logs (optional).',
default: false,
Expand Down
68 changes: 41 additions & 27 deletions src/commands/app/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getManifestAssetPath, readManifestFile } from 'services/manifest-servic
import { getTasksForClientSide, getTasksForServerSide } from 'services/share/deploy';
import { ManifestHostingType } from 'types/services/manifest-service';
import logger from 'utils/logger';
import { addRegionToFlags, chooseRegionIfNeeded, getRegionFromString } from 'utils/region';

const MESSAGES = {
directory: 'Directory path of you project in your machine. If not included will use the current working directory.',
Expand All @@ -19,27 +20,29 @@ export default class AppDeploy extends AuthenticatedCommand {
static description = 'Deploy an app using manifest file.';
static withPrintCommand = false;
static examples = ['<%= config.bin %> <%= command.id %>'];
static flags = AppDeploy.serializeFlags({
directoryPath: Flags.string({
char: 'd',
description: MESSAGES.directory,
static flags = AppDeploy.serializeFlags(
addRegionToFlags({
directoryPath: Flags.string({
char: 'd',
description: MESSAGES.directory,
}),
appId: Flags.string({
char: 'a',
aliases: ['appId'],
description: MESSAGES.appId,
}),
appVersionId: Flags.string({
char: 'v',
aliases: ['versionId'],
description: MESSAGES.appVersionId,
}),
force: Flags.boolean({
char: 'f',
aliases: ['force'],
description: MESSAGES.force,
}),
}),
appId: Flags.string({
char: 'a',
aliases: ['appId'],
description: MESSAGES.appId,
}),
appVersionId: Flags.string({
char: 'v',
aliases: ['versionId'],
description: MESSAGES.appVersionId,
}),
force: Flags.boolean({
char: 'f',
aliases: ['force'],
description: MESSAGES.force,
}),
});
);

DEBUG_TAG = 'app_deploy';

Expand All @@ -57,26 +60,37 @@ export default class AppDeploy extends AuthenticatedCommand {
public async run(): Promise<void> {
try {
const { flags } = await this.parse(AppDeploy);

const manifestFileDir = flags.directoryPath || getCurrentWorkingDirectory();
const { directoryPath, force } = flags;
let { appId, appVersionId } = flags;
const region = getRegionFromString(flags?.region);
const manifestFileDir = directoryPath || getCurrentWorkingDirectory();
const manifestFileData = readManifestFile(manifestFileDir);
flags.appId = flags.appId || manifestFileData.app.id;
appId = appId || manifestFileData.app.id;

appVersionId = await this.getAppVersionId(appVersionId, appId, force);

flags.appVersionId = await this.getAppVersionId(flags.appVersionId, flags.appId, flags.force);
const selectedRegion = await chooseRegionIfNeeded(region, {
appVersionId: Number(appVersionId),
});

this.preparePrintCommand(this, { appVersionId: flags.appVersionId, directoryPath: manifestFileData });
this.preparePrintCommand(this, { appVersionId: appVersionId, directoryPath: manifestFileData });

const { cdn, server } = manifestFileData.app?.hosting || {};
if (cdn && cdn.type === ManifestHostingType.Upload) {
logger.info('Deploying files to cdn...');
await getTasksForClientSide(Number(flags.appVersionId), getManifestAssetPath(manifestFileDir, cdn.path)).run();
await getTasksForClientSide(
Number(appVersionId),
getManifestAssetPath(manifestFileDir, cdn.path),
selectedRegion,
).run();
}

if (server && server.type === ManifestHostingType.Upload) {
logger.info('Deploying server side files...');
await getTasksForServerSide(
Number(flags.appVersionId),
Number(appVersionId),
getManifestAssetPath(manifestFileDir, server.path),
selectedRegion,
).run();
}
} catch (error) {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/app/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { App } from 'types/services/apps-service';
import logger from 'utils/logger';

const printApps = (apps: Array<App>) => {
logger.table(apps);
const cleanedApps = apps.map(app => {
return { id: app.id, name: app.name };
});
logger.table(cleanedApps);
};

export default class AppList extends AuthenticatedCommand {
Expand Down
53 changes: 30 additions & 23 deletions src/commands/code/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PromptService } from 'services/prompt-service';
import { ManageAppEnvFlags } from 'types/commands/manage-app-env';
import { AppId } from 'types/general';
import logger from 'utils/logger';
import { addRegionToFlags, chooseRegionIfNeeded, getRegionFromString } from 'utils/region';

const MODES_WITH_KEYS: Array<APP_ENV_MANAGEMENT_MODES> = [
APP_ENV_MANAGEMENT_MODES.SET,
Expand Down Expand Up @@ -68,46 +69,52 @@ export default class Env extends AuthenticatedCommand {

static examples = ['<%= config.bin %> <%= command.id %>'];

static flags = Env.serializeFlags({
appId: Flags.integer({
char: 'i',
aliases: ['a'],
description: 'The id of the app to manage environment variables for',
static flags = Env.serializeFlags(
addRegionToFlags({
appId: Flags.integer({
char: 'i',
aliases: ['a'],
description: 'The id of the app to manage environment variables for',
}),
mode: Flags.string({
char: 'm',
description: 'management mode',
options: Object.values(APP_ENV_MANAGEMENT_MODES),
}),
key: Flags.string({
char: 'k',
description: 'variable key [required for set and delete]]',
relationships: [flagsWithModeRelationships],
}),
value: Flags.string({
char: 'v',
description: 'variable value [required for set]',
relationships: [flagsWithModeRelationships],
}),
}),
mode: Flags.string({
char: 'm',
description: 'management mode',
options: Object.values(APP_ENV_MANAGEMENT_MODES),
}),
key: Flags.string({
char: 'k',
description: 'variable key [required for set and delete]]',
relationships: [flagsWithModeRelationships],
}),
value: Flags.string({
char: 'v',
description: 'variable value [required for set]',
relationships: [flagsWithModeRelationships],
}),
});
);

static args = {};
DEBUG_TAG = 'env';
public async run(): Promise<void> {
try {
const { flags } = await this.parse(Env);
const { region: strRegion } = flags;
const region = getRegionFromString(strRegion);
let { mode, key, value, appId } = flags as ManageAppEnvFlags;

if (!appId) {
appId = Number(await DynamicChoicesService.chooseApp());
}

const selectedRegion = await chooseRegionIfNeeded(region, { appId });

mode = await promptForModeIfNotProvided(mode);
key = await promptForKeyIfNotProvided(mode, appId, key);
value = await promptForValueIfNotProvided(mode, value);
this.preparePrintCommand(this, { appId, mode, key, value });
this.preparePrintCommand(this, { appId, mode, key, value, region: selectedRegion });

await handleEnvironmentRequest(appId, mode, key, value);
await handleEnvironmentRequest(appId, mode, key, value, selectedRegion);
} catch (error: any) {
logger.debug(error, this.DEBUG_TAG);

Expand Down
74 changes: 39 additions & 35 deletions src/commands/code/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PromptService } from 'services/prompt-service';
import { EventSource, LogType, LogsCommandArguments, LogsFilterCriteriaArguments } from 'types/commands/logs';
import { isDefined } from 'utils/guards';
import logger from 'utils/logger';
import { addRegionToFlags, chooseRegionIfNeeded, getRegionFromString } from 'utils/region';
import { TIME_IN_MILLISECONDS } from 'utils/time-enum';
import { getDayDiff, isDate } from 'utils/validations';

Expand Down Expand Up @@ -46,53 +47,56 @@ export default class Logs extends AuthenticatedCommand {

static examples = ['<%= config.bin %> <%= command.id %> -i APP_VERSION_ID -t LOGS_TYPE'];

static flags = Logs.serializeFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: APP_VERSION_ID_TO_ENTER,
static flags = Logs.serializeFlags(
addRegionToFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: APP_VERSION_ID_TO_ENTER,
}),
logsType: Flags.string({
char: 't',
description: LOGS_TYPE_TO_LISTEN_PROMPT_MESSAGE,
}),
eventSource: Flags.string({
char: 's',
description: EVENT_SOURCE,
}),
logsStartDate: Flags.string({
char: 'f',
description: 'Start date (MM/DD/YYYY HH:mm) e.g. "03/24/1983 15:45"' + SUPPORTED_HISTORY_FLAGS,
relationships,
}),
logsEndDate: Flags.string({
char: 'e',
description: 'End date (MM/DD/YYYY HH:mm) e.g. "03/25/1983 16:45"' + SUPPORTED_HISTORY_FLAGS,
relationships,
}),
logSearchFromText: Flags.string({
char: 'r',
description: EVENT_SEARCH_FOR_TEXT,
relationships,
}),
}),
logsType: Flags.string({
char: 't',
description: LOGS_TYPE_TO_LISTEN_PROMPT_MESSAGE,
}),
eventSource: Flags.string({
char: 's',
description: EVENT_SOURCE,
}),
logsStartDate: Flags.string({
char: 'f',
description: 'Start date (MM/DD/YYYY HH:mm) e.g. "03/24/1983 15:45"' + SUPPORTED_HISTORY_FLAGS,
relationships,
}),
logsEndDate: Flags.string({
char: 'e',
description: 'End date (MM/DD/YYYY HH:mm) e.g. "03/25/1983 16:45"' + SUPPORTED_HISTORY_FLAGS,
relationships,
}),
logSearchFromText: Flags.string({
char: 'r',
description: EVENT_SEARCH_FOR_TEXT,
relationships,
}),
});
);

static args = {};
DEBUG_TAG = 'logs';

public async run(): Promise<void> {
try {
const { flags } = await this.parse(Logs);

const { logsStartDate, logsEndDate, logSearchFromText, region: strRegion } = flags;
const region = getRegionFromString(strRegion);
const appVersionId = await this.getAppVersionId(flags.appVersionId);

const selectedRegion = await chooseRegionIfNeeded(region, { appVersionId });
const eventSource = (flags.eventSource || (await eventSourcePrompt())) as EventSource;
const logsType = await this.getLogType(eventSource, flags.logsType);
const logsFilterCriteria = await this.getLogsFilterCriteria(
eventSource,
flags.logsStartDate,
flags.logsEndDate,
flags.logSearchFromText,
logsStartDate,
logsEndDate,
logSearchFromText,
);

const args: LogsCommandArguments = {
Expand All @@ -110,7 +114,7 @@ export default class Logs extends AuthenticatedCommand {
logSearchFromText: logsFilterCriteria?.text,
});

const clientChannel = await logsStream(args.appVersionId, args.logsType, logsFilterCriteria);
const clientChannel = await logsStream(args.appVersionId, args.logsType, logsFilterCriteria, selectedRegion);
await streamMessages(clientChannel);
} catch (error: any) {
logger.debug(error, this.DEBUG_TAG);
Expand Down
47 changes: 27 additions & 20 deletions src/commands/code/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { APP_ID_TO_ENTER, APP_VERSION_ID_TO_ENTER } from 'consts/messages';
import { DynamicChoicesService } from 'services/dynamic-choices-service';
import { getTasksForServerSide } from 'services/share/deploy';
import logger from 'utils/logger';
import { addRegionToFlags, chooseRegionIfNeeded, getRegionFromString } from 'utils/region';

const MESSAGES = {
directory: 'Directory path of you project in your machine. If not included will use the current working directory.',
Expand All @@ -21,31 +22,35 @@ export default class Push extends AuthenticatedCommand {
'<%= config.bin %> <%= command.id %> -a APP_ID_TO_PUSH',
];

static flags = Push.serializeFlags({
directoryPath: Flags.string({
char: 'd',
description: MESSAGES.directory,
static flags = Push.serializeFlags(
addRegionToFlags({
directoryPath: Flags.string({
char: 'd',
description: MESSAGES.directory,
}),
appId: Flags.string({
char: 'a',
description: MESSAGES.appId,
}),
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: MESSAGES.appVersionId,
}),
force: Flags.boolean({
char: 'f',
description: MESSAGES.force,
}),
}),
appId: Flags.string({
char: 'a',
description: MESSAGES.appId,
}),
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: MESSAGES.appVersionId,
}),
force: Flags.boolean({
char: 'f',
description: MESSAGES.force,
}),
});
);

static args = {};
DEBUG_TAG = 'code_push';

public async run(): Promise<void> {
const { flags } = await this.parse(Push);
const { directoryPath, region: strRegion } = flags;
const region = getRegionFromString(strRegion);
let appVersionId = flags.appVersionId;

try {
Expand All @@ -60,10 +65,12 @@ export default class Push extends AuthenticatedCommand {
appVersionId = appAndAppVersion.appVersionId;
}

const selectedRegion = await chooseRegionIfNeeded(region, { appVersionId });

logger.debug(`push code to appVersionId: ${appVersionId}`, this.DEBUG_TAG);
this.preparePrintCommand(this, { appVersionId, directoryPath: flags.directoryPath });
this.preparePrintCommand(this, { appVersionId, directoryPath: directoryPath });

const tasks = getTasksForServerSide(appVersionId, flags.directoryPath);
const tasks = getTasksForServerSide(appVersionId, directoryPath, selectedRegion);

await tasks.run();
} catch (error: any) {
Expand Down
Loading

0 comments on commit f6ec128

Please sign in to comment.