diff --git a/package.json b/package.json index c8b8784..fc7ab99 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mondaycom/apps-cli", - "version": "1.4.1", + "version": "1.4.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/code/push.ts b/src/commands/code/push.ts index 817fbce..653b159 100644 --- a/src/commands/code/push.ts +++ b/src/commands/code/push.ts @@ -19,6 +19,7 @@ const MESSAGES = { directory: 'Directory path of you project in your machine. If not included will use the current working directory.', appVersionId: APP_VERSION_ID_TO_ENTER, appId: APP_ID_TO_ENTER, + force: 'Force push to live version', }; export default class Push extends AuthenticatedCommand { @@ -43,6 +44,10 @@ export default class Push extends AuthenticatedCommand { aliases: ['v'], description: MESSAGES.appVersionId, }), + force: Flags.boolean({ + char: 'f', + description: MESSAGES.force, + }), }); static args = {}; @@ -50,19 +55,21 @@ export default class Push extends AuthenticatedCommand { public async run(): Promise { const { flags } = await this.parse(Push); - let appVersionId; + let appVersionId: number | undefined; const appId = flags.appId; + const force = flags.force; if (appId) { - const latestDraftVersion = await defaultVersionByAppId(Number(appId)); - if (!latestDraftVersion) throw new Error('No draft version found for the given app id.'); + const latestDraftVersion = await defaultVersionByAppId(Number(appId), force); + if (!latestDraftVersion) throw new Error('No editable version found for the given app id.'); appVersionId = latestDraftVersion.id; } else { appVersionId = flags.appVersionId; } if (!appVersionId) { - const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion([APP_VERSION_STATUS.DRAFT]); + const allowedStatuses = force ? [APP_VERSION_STATUS.DRAFT, APP_VERSION_STATUS.LIVE] : [APP_VERSION_STATUS.DRAFT]; + const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(allowedStatuses); appVersionId = appAndAppVersion.appVersionId; } diff --git a/src/services/app-versions-service.ts b/src/services/app-versions-service.ts index 9af1430..79e8c18 100644 --- a/src/services/app-versions-service.ts +++ b/src/services/app-versions-service.ts @@ -31,8 +31,11 @@ export const listAppVersionsByAppId = async (appId: AppId): Promise => { +export const defaultVersionByAppId = async (appId: AppId, useLiveVersion = false): Promise => { const appVersions = await listAppVersionsByAppId(appId); const latestVersion = appVersions.sort((a, b) => b.id - a.id)[0]; - return latestVersion.status === APP_VERSION_STATUS.DRAFT ? latestVersion : undefined; + const allowedStatuses = useLiveVersion + ? [APP_VERSION_STATUS.LIVE, APP_VERSION_STATUS.DRAFT] + : [APP_VERSION_STATUS.DRAFT]; + return allowedStatuses.includes(latestVersion.status) ? latestVersion : undefined; }; diff --git a/src/services/dynamic-choices-service.ts b/src/services/dynamic-choices-service.ts index 07a6e4e..8c89ee6 100644 --- a/src/services/dynamic-choices-service.ts +++ b/src/services/dynamic-choices-service.ts @@ -20,7 +20,7 @@ export const DynamicChoicesService = { return selectedAppId; }, - async chooseAppVersion(appId: number, filterByStatus?: [APP_VERSION_STATUS]) { + async chooseAppVersion(appId: number, filterByStatus?: APP_VERSION_STATUS[]) { let appVersions = await listAppVersionsByAppId(appId); if (filterByStatus) { appVersions = appVersions.filter(appVersion => filterByStatus.includes(appVersion.status)); @@ -42,7 +42,7 @@ export const DynamicChoicesService = { return selectedAppVersionId; }, - async chooseAppAndAppVersion(filterByStatus?: [APP_VERSION_STATUS]) { + async chooseAppAndAppVersion(filterByStatus?: APP_VERSION_STATUS[]) { const appId = await this.chooseApp(); const appVersionId = await this.chooseAppVersion(appId, filterByStatus); return { appId, appVersionId };