From ee8e8daf4fd2c1261669b42a912b8e47f56a60d2 Mon Sep 17 00:00:00 2001 From: Your Full Name Date: Tue, 9 Jan 2024 18:16:01 +0200 Subject: [PATCH] Fix: allow choosing live versions --- package.json | 2 +- src/commands/app-features/build.ts | 5 +- src/commands/app-features/list.ts | 5 +- src/commands/app-version/builds.ts | 2 +- src/commands/app/deploy.ts | 5 +- src/commands/code/logs.ts | 83 +++++++++++++------------ src/commands/code/push.ts | 6 +- src/commands/code/status.ts | 2 +- src/services/dynamic-choices-service.ts | 16 +++-- 9 files changed, 68 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index 951dd02..3c5f318 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mondaycom/apps-cli", - "version": "2.2.1", + "version": "2.2.2", "description": "A cli tool to manage apps (and monday-code projects) in monday.com", "author": "monday.com Apps Team", "type": "module", diff --git a/src/commands/app-features/build.ts b/src/commands/app-features/build.ts index 35e3b57..7c246d6 100644 --- a/src/commands/app-features/build.ts +++ b/src/commands/app-features/build.ts @@ -75,7 +75,10 @@ export default class Build extends AuthenticatedCommand { } if (!appVersionId) { - const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion({ appId }); + const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, false, { + appId, + autoSelectVersion: false, + }); appVersionId = appAndAppVersion.appVersionId; appId = appAndAppVersion.appId; } diff --git a/src/commands/app-features/list.ts b/src/commands/app-features/list.ts index 85de881..be7454d 100644 --- a/src/commands/app-features/list.ts +++ b/src/commands/app-features/list.ts @@ -36,7 +36,10 @@ export default class AppFeatureList extends AuthenticatedCommand { let appVersionId = flags.appVersionId; if (!appVersionId) { - const appIdAndAppVersionId = await DynamicChoicesService.chooseAppAndAppVersion({ appId }); + const appIdAndAppVersionId = await DynamicChoicesService.chooseAppAndAppVersion(true, true, { + appId, + autoSelectVersion: false, + }); appVersionId = Number(appIdAndAppVersionId.appVersionId); } diff --git a/src/commands/app-version/builds.ts b/src/commands/app-version/builds.ts index f0166a6..9a02ad6 100644 --- a/src/commands/app-version/builds.ts +++ b/src/commands/app-version/builds.ts @@ -42,7 +42,7 @@ export default class AppVersionBuilds extends AuthenticatedCommand { const { flags } = await this.parse(Status); let appVersionId = flags.appVersionId; if (!appVersionId) { - const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(); + const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(true, true); appVersionId = appAndAppVersion.appVersionId; } diff --git a/src/commands/app/deploy.ts b/src/commands/app/deploy.ts index 43385d8..92e6d82 100644 --- a/src/commands/app/deploy.ts +++ b/src/commands/app/deploy.ts @@ -46,10 +46,9 @@ export default class AppDeploy extends AuthenticatedCommand { async getAppVersionId(appVersionId: string | undefined, appId: string | undefined, force: boolean): Promise { if (appVersionId) return appVersionId; - const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion({ + const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, Boolean(force), { appId: Number(appId), - useDefaultVersion: true, - useLiveVersion: force, + autoSelectVersion: true, }); return latestDraftVersion.appVersionId.toString(); diff --git a/src/commands/code/logs.ts b/src/commands/code/logs.ts index 96d315d..d58ebb2 100755 --- a/src/commands/code/logs.ts +++ b/src/commands/code/logs.ts @@ -79,9 +79,50 @@ export default class Logs extends AuthenticatedCommand { static args = {}; DEBUG_TAG = 'logs'; + + public async run(): Promise { + try { + const { flags } = await this.parse(Logs); + + const appVersionId = await this.getAppVersionId(flags.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, + ); + + const args: LogsCommandArguments = { + appVersionId, + logsType, + logsFilterCriteria, + }; + + this.preparePrintCommand(this, { + appVersionId, + logsType, + eventSource, + logsStartDate: logsFilterCriteria?.fromDate && `"${logsFilterCriteria.fromDate.toString()}"`, + logsEndDate: logsFilterCriteria?.toDate && `"${logsFilterCriteria.toDate.toString()}"`, + logSearchFromText: logsFilterCriteria?.text, + }); + + const clientChannel = await logsStream(args.appVersionId, args.logsType, logsFilterCriteria); + await streamMessages(clientChannel); + } catch (error: any) { + logger.debug(error, this.DEBUG_TAG); + + // need to signal to the parent process that the command failed + process.exit(1); + } + } + private async getAppVersionId(appVersionId?: number): Promise { if (!appVersionId) { - const { appVersionId: inputAppVersionId } = await DynamicChoicesService.chooseAppAndAppVersion(); + const { appVersionId: inputAppVersionId } = await DynamicChoicesService.chooseAppAndAppVersion(true, true); return inputAppVersionId; } @@ -199,44 +240,4 @@ export default class Logs extends AuthenticatedCommand { return { fromDate, toDate, text }; } - - public async run(): Promise { - try { - const { flags } = await this.parse(Logs); - - const appVersionId = await this.getAppVersionId(flags.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, - ); - - const args: LogsCommandArguments = { - appVersionId, - logsType, - logsFilterCriteria, - }; - - this.preparePrintCommand(this, { - appVersionId, - logsType, - eventSource, - logsStartDate: logsFilterCriteria?.fromDate && `"${logsFilterCriteria.fromDate.toString()}"`, - logsEndDate: logsFilterCriteria?.toDate && `"${logsFilterCriteria.toDate.toString()}"`, - logSearchFromText: logsFilterCriteria?.text, - }); - - const clientChannel = await logsStream(args.appVersionId, args.logsType, logsFilterCriteria); - await streamMessages(clientChannel); - } catch (error: any) { - logger.debug(error, this.DEBUG_TAG); - - // need to signal to the parent process that the command failed - process.exit(1); - } - } } diff --git a/src/commands/code/push.ts b/src/commands/code/push.ts index f004423..7f4f05a 100644 --- a/src/commands/code/push.ts +++ b/src/commands/code/push.ts @@ -52,11 +52,11 @@ export default class Push extends AuthenticatedCommand { if (!appVersionId) { const force = flags.force; const appId = flags.appId; - const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion({ + const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, Boolean(force), { appId: Number(appId), - useDefaultVersion: true, - useLiveVersion: force, + autoSelectVersion: true, }); + appVersionId = appAndAppVersion.appVersionId; } diff --git a/src/commands/code/status.ts b/src/commands/code/status.ts index 5eac576..851143c 100644 --- a/src/commands/code/status.ts +++ b/src/commands/code/status.ts @@ -47,7 +47,7 @@ export default class Status extends AuthenticatedCommand { let appVersionId = flags.appVersionId; try { if (!appVersionId) { - const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(); + const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(true, true); appVersionId = appAndAppVersion.appVersionId; } diff --git a/src/services/dynamic-choices-service.ts b/src/services/dynamic-choices-service.ts index d10387e..3db4d68 100644 --- a/src/services/dynamic-choices-service.ts +++ b/src/services/dynamic-choices-service.ts @@ -45,13 +45,17 @@ export const DynamicChoicesService = { return selectedAppVersionId; }, - async chooseAppAndAppVersion(options?: { appId?: number; useDefaultVersion?: boolean; useLiveVersion?: boolean }) { - const { appId, useDefaultVersion = false, useLiveVersion = false } = options || {}; - const filterByStatus = useLiveVersion - ? [APP_VERSION_STATUS.LIVE, APP_VERSION_STATUS.DRAFT] - : [APP_VERSION_STATUS.DRAFT]; + async chooseAppAndAppVersion( + useDeprecatedVersion: boolean, + useLiveVersion: boolean, + options?: { appId?: number; autoSelectVersion?: boolean }, + ) { + const { appId, autoSelectVersion = false } = options || {}; + const filterByStatus = [APP_VERSION_STATUS.DRAFT]; + if (useDeprecatedVersion) filterByStatus.push(APP_VERSION_STATUS.DEPRECATED); + if (useLiveVersion) filterByStatus.push(APP_VERSION_STATUS.LIVE); - if (useDefaultVersion && appId) { + if (appId && autoSelectVersion) { const defaultVersion = await defaultVersionByAppId(appId, useLiveVersion); if (!defaultVersion) throw new Error(`No default version found for app id - ${appId}`);