Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: allow push to love version #53

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading