Skip to content

Commit

Permalink
Feat: allow push to love version (#53)
Browse files Browse the repository at this point in the history
* Feat: sort apps and versions by created date, filter only drafts for push

* Feat: increment version

---------

Co-authored-by: Your Full Name <[email protected]>
  • Loading branch information
tsemachLi and Your Full Name authored Oct 31, 2023
1 parent 01bb8d5 commit 610a7fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 11 additions & 4 deletions src/commands/code/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -43,26 +44,32 @@ export default class Push extends AuthenticatedCommand {
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);
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;
}

Expand Down
7 changes: 5 additions & 2 deletions src/services/app-versions-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ export const listAppVersionsByAppId = async (appId: AppId): Promise<Array<AppVer
}
};

export const defaultVersionByAppId = async (appId: AppId): Promise<AppVersion | undefined> => {
export const defaultVersionByAppId = async (appId: AppId, useLiveVersion = false): Promise<AppVersion | undefined> => {
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;
};
4 changes: 2 additions & 2 deletions src/services/dynamic-choices-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 };
Expand Down

0 comments on commit 610a7fa

Please sign in to comment.