Skip to content

Commit

Permalink
Feat: support builds (#41)
Browse files Browse the repository at this point in the history
* Feat: support builds

* Feat: support builds

---------

Co-authored-by: Your Full Name <[email protected]>
  • Loading branch information
tsemachLi and Your Full Name authored Aug 30, 2023
1 parent 2f0d43f commit b080302
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 14 deletions.
60 changes: 51 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<h3 style="color:red"><b>Public access to this CLI is currently restricted but will become available in the next few months</b></h3>
<h3 style="color:red"><b>Public access to this CLI is currently restricted but will become available in the next few
months</b></h3>

---
monday-code-cli
Expand All @@ -7,12 +8,16 @@ monday-code-cli
monday.com cli tool for `<monday-code />` apps management.

<!-- toc -->

* [Usage](#usage)
* [Commands](#commands)

<!-- tocstop -->

# Usage

<!-- usage -->

```sh-session
$ npm install -g @mondaycom/apps-cli
$ mapps COMMAND
Expand All @@ -24,9 +29,13 @@ USAGE
$ mapps COMMAND
...
```

<!-- usagestop -->

# Commands

<!-- commands -->

* [`mapps app-version:list`](#mapps-app-versionlist)
* [`mapps app:list`](#mapps-applist)
* [`mapps autocomplete [SHELL]`](#mapps-autocomplete-shell)
Expand Down Expand Up @@ -59,7 +68,33 @@ EXAMPLES
$ mapps app-version:list
```

_See code: [dist/commands/app-version/list.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/app-version/list.ts)_
_See
code: [dist/commands/app-version/list.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/app-version/list.ts)_

## `mapps app-version:builds`

List all builds for a specific app-version.

```
USAGE
$ mapps app-version:builds [--verbose] [--print-command] [-i <value>]
FLAGS
-i, --appVersionId=<value> Please enter the app version id of your app:
GLOBAL FLAGS
--print-command Print the command that was executed (optional).
--verbose Print advanced logs (optional).
DESCRIPTION
List all builds for a specific app-version.
EXAMPLES
$ mapps app-version:builds
```

_See
code: [dist/commands/app-version/builds.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/app-version/builds.ts)_

## `mapps app:list`

Expand All @@ -80,7 +115,8 @@ EXAMPLES
$ mapps app:list
```

_See code: [dist/commands/app/list.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/app/list.ts)_
_See
code: [dist/commands/app/list.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/app/list.ts)_

## `mapps autocomplete [SHELL]`

Expand Down Expand Up @@ -111,7 +147,8 @@ EXAMPLES
$ mapps autocomplete --refresh-cache
```

_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v2.2.0/src/commands/autocomplete/index.ts)_
_See
code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v2.2.0/src/commands/autocomplete/index.ts)_

## `mapps code:env`

Expand Down Expand Up @@ -140,7 +177,8 @@ EXAMPLES
$ mapps code:env
```

_See code: [dist/commands/code/env.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/code/env.ts)_
_See
code: [dist/commands/code/env.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/code/env.ts)_

## `mapps code:logs`

Expand Down Expand Up @@ -173,7 +211,8 @@ EXAMPLES
$ mapps code:logs -i APP_VERSION_ID -t LOGS_TYPE
```

_See code: [dist/commands/code/logs.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/code/logs.ts)_
_See
code: [dist/commands/code/logs.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/code/logs.ts)_

## `mapps code:push`

Expand Down Expand Up @@ -201,7 +240,8 @@ EXAMPLES
$ mapps code:push -i APP_VERSION_ID_TO_PUSH
```

_See code: [dist/commands/code/push.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/code/push.ts)_
_See
code: [dist/commands/code/push.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/code/push.ts)_

## `mapps code:status`

Expand All @@ -225,7 +265,8 @@ EXAMPLES
$ mapps code:status -i APP_VERSION_ID
```

_See code: [dist/commands/code/status.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/code/status.ts)_
_See
code: [dist/commands/code/status.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/code/status.ts)_

## `mapps help [COMMANDS]`

Expand Down Expand Up @@ -269,5 +310,6 @@ EXAMPLES
$ mapps init -t SECRET_TOKEN
```

_See code: [dist/commands/init/index.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/init/index.ts)_
_See
code: [dist/commands/init/index.ts](https://github.com/mondaycom/monday-code-cli/blob/v1.0.0/dist/commands/init/index.ts)_
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mondaycom/apps-cli",
"version": "1.0.0",
"version": "1.1.0",
"description": "A cli tool to manage apps (and monday-code projects) in monday.com",
"author": "monday.com Apps Team",
"type": "module",
Expand Down Expand Up @@ -131,4 +131,4 @@
"@oclif/plugin-autocomplete"
]
}
}
}
63 changes: 63 additions & 0 deletions src/commands/app-version/builds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Flags } from '@oclif/core';
import { StatusCodes } from 'http-status-codes';

import Status from 'commands/code/status';
import { AuthenticatedCommand } from 'commands-base/authenticated-command';
import { APP_VERSION_ID_TO_ENTER } from 'consts/messages';
import { listAppBuilds } from 'services/app-builds-service';
import { DynamicChoicesService } from 'services/dynamic-choices-service';
import { AppRelease } from 'services/schemas/app-releases-schema';
import { HttpError } from 'types/errors';
import logger from 'utils/logger';

const printBuilds = (appBuilds: Array<AppRelease>) => {
const appBuildsTable = appBuilds.map(appBuild => {
return {
category: appBuild.category,
...(appBuild.data?.liveUrl && { 'live url': appBuild.data?.liveUrl }),
...(appBuild.data?.url && { url: appBuild.data?.url }),
...(appBuild.data?.latestUrl && { 'static url (latest deployment)': appBuild.data?.latestUrl }),
...(appBuild.data?.sourceUrl && { 'source url (download)': appBuild.data?.sourceUrl }),
...(appBuild.data?.microFrontendName && { 'micro frontend name': appBuild.data?.microFrontendName }),
};
});

logger.table(appBuildsTable);
};

export default class AppVersionBuilds extends AuthenticatedCommand {
static description = 'List all builds for a specific app version';
static examples = ['<%= config.bin %> <%= command.id %> -i APP_VERSION_ID'];
static flags = AppVersionBuilds.serializeFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: APP_VERSION_ID_TO_ENTER,
}),
});

DEBUG_TAG = 'app_version_builds';

public async run(): Promise<void> {
const { flags } = await this.parse(Status);
let appVersionId = flags.appVersionId;
if (!appVersionId) {
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion();
appVersionId = appAndAppVersion.appVersionId;
}

try {
this.preparePrintCommand(this, { appVersionId });
const appReleases = await listAppBuilds(appVersionId);
printBuilds(appReleases);
} catch (error: unknown) {
if (error instanceof HttpError && error.code === StatusCodes.NOT_FOUND) {
logger.error(`No builds found for provided app version id - "${appVersionId}"`);
} else {
logger.error(`An unknown error happened while fetching builds for app version id - "${appVersionId}"`);
}

process.exit(0);
}
}
}
2 changes: 0 additions & 2 deletions src/commands/code/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import logger from 'utils/logger';
const printDeploymentStatus = (appVersionId: number, deploymentStatus: AppVersionDeploymentStatus) => {
const { deployment, status, error } = deploymentStatus;
const url = deployment?.url || 'none';
const latestUrl = deployment?.latestUrl || 'none';
const errorMessage: string | undefined = error?.message;
const tableData = {
id: appVersionId,
status,
url,
'static url (latest deployment)': latestUrl,
...(errorMessage && { errorMessage }),
};

Expand Down
4 changes: 4 additions & 0 deletions src/consts/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ export const appEnvironmentUrl = (appId: AppId, key: string): string => {
export const appEnvironmentKeysUrl = (appId: AppId): string => {
return `/api/code/${appId}/env-keys`;
};

export const appReleasesUrl = (appVersionId: AppId): string => {
return `/apps_ms/app-versions/${appVersionId}/releases`;
};
29 changes: 29 additions & 0 deletions src/services/app-builds-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { appReleasesUrl } from 'consts/urls';
import { execute } from 'services/api-service';
import { AppRelease, AppReleasesResponse, appReleasesSchema } from 'services/schemas/app-releases-schema';
import { HttpError } from 'types/errors';
import { AppVersionId } from 'types/general';
import { HttpMethodTypes } from 'types/services/api-service';
import { appsUrlBuilder } from 'utils/urls-builder';

export const listAppBuilds = async (appVersionId: AppVersionId): Promise<Array<AppRelease>> => {
try {
const path = appReleasesUrl(appVersionId);
const url = appsUrlBuilder(path);
const response = await execute<AppReleasesResponse>(
{
url,
headers: { Accept: 'application/json' },
method: HttpMethodTypes.GET,
},
appReleasesSchema,
);
return response.appReleases;
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
}

throw new Error('Failed to list app versions.');
}
};
32 changes: 32 additions & 0 deletions src/services/schemas/app-releases-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { z } from 'zod';

import { baseResponseHttpMetaDataSchema } from 'services/schemas/api-service-schemas';
import { appReleaseIdSchema, appVersionIdSchema } from 'services/schemas/general-schemas';

export const appReleaseSchema = z.object({
id: appReleaseIdSchema,
// eslint-disable-next-line camelcase
app_version_id: appVersionIdSchema,
kind: z.string(),
category: z.string(),
state: z.string(),
data: z
.object({
url: z.string().optional(),
latestUrl: z.string().optional(),
liveUrl: z.string().optional(),
deploymentState: z.string().optional(),
sourceUrl: z.string().optional(),
microFrontendName: z.string().optional(),
})
.optional(),
});

export const appReleasesSchema = z
.object({
appReleases: z.array(appReleaseSchema),
})
.merge(baseResponseHttpMetaDataSchema);

export type AppReleasesResponse = z.infer<typeof appReleasesSchema>;
export type AppRelease = z.infer<typeof appReleaseSchema>;
1 change: 1 addition & 0 deletions src/services/schemas/general-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import { z } from 'zod';

export const appIdSchema = z.number();
export const appVersionIdSchema = z.number();
export const appReleaseIdSchema = z.number();
3 changes: 2 additions & 1 deletion src/types/general/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod';

import { appIdSchema } from 'services/schemas/general-schemas';
import { appIdSchema, appVersionIdSchema } from 'services/schemas/general-schemas';

export type AppId = z.infer<typeof appIdSchema>;
export type AppVersionId = z.infer<typeof appVersionIdSchema>;

0 comments on commit b080302

Please sign in to comment.