Skip to content

Commit a63d09b

Browse files
authored
feat: Add manifest import/export commands (#135)
* feat: Add manifest import/export commands - Add manifest import command with custom path and missing variables support - Add manifest export command with custom path and validation - Add validation functionality for manifest export - Add templating utilities for manifest processing - Add comprehensive tests for import functionality - Update API service and file utilities - Update package version and documentation * bump minor * fix readme * fix readme
1 parent 252dfab commit a63d09b

18 files changed

+795
-63
lines changed

README.md

Lines changed: 93 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
monday-apps-cli
2-
=================
1+
# monday-apps-cli
32

43
monday.com cli tool for monday apps management.
54

65
<!-- toc -->
7-
* [Usage](#usage)
8-
* [Commands](#commands)
6+
7+
- [Usage](#usage)
8+
- [Commands](#commands)
99
<!-- tocstop -->
1010

1111
# Usage
1212

1313
<!-- usage -->
14+
1415
```sh-session
1516
$ npm install -g @mondaycom/apps-cli
1617
$ mapps COMMAND
@@ -22,39 +23,53 @@ USAGE
2223
$ mapps COMMAND
2324
...
2425
```
26+
2527
<!-- usagestop -->
2628

2729
# Commands
2830

2931
<!-- commands -->
30-
* [`mapps api:generate`](#mapps-apigenerate)
31-
* [`mapps app-features:build`](#mapps-app-featuresbuild)
32-
* [`mapps app-features:create`](#mapps-app-featurescreate)
33-
* [`mapps app-features:list`](#mapps-app-featureslist)
34-
* [`mapps app-version:builds`](#mapps-app-versionbuilds)
35-
* [`mapps app-version:list`](#mapps-app-versionlist)
36-
* [`mapps app:create`](#mapps-appcreate)
37-
* [`mapps app:deploy`](#mapps-appdeploy)
38-
* [`mapps app:list`](#mapps-applist)
32+
33+
- [`mapps api:generate`](#mapps-apigenerate)
34+
- [`mapps app-features:build`](#mapps-app-featuresbuild)
35+
- [`mapps app-features:create`](#mapps-app-featurescreate)
36+
- [`mapps app-features:list`](#mapps-app-featureslist)
37+
- [`mapps app-version:builds`](#mapps-app-versionbuilds)
38+
- [`mapps app-version:list`](#mapps-app-versionlist)
39+
- [`mapps app:create`](#mapps-appcreate)
40+
- [`mapps app:deploy`](#mapps-appdeploy)
41+
- [`mapps app:list`](#mapps-applist)
42+
3943
* [`mapps app:promote`](#mapps-apppromote)
40-
* [`mapps autocomplete [SHELL]`](#mapps-autocomplete-shell)
41-
* [`mapps code:env`](#mapps-codeenv)
42-
* [`mapps code:logs`](#mapps-codelogs)
43-
* [`mapps code:push`](#mapps-codepush)
44+
45+
- [`mapps autocomplete [SHELL]`](#mapps-autocomplete-shell)
46+
- [`mapps code:env`](#mapps-codeenv)
47+
- [`mapps code:logs`](#mapps-codelogs)
48+
- [`mapps code:push`](#mapps-codepush)
49+
4450
* [`mapps code:secret`](#mapps-codesecret)
45-
* [`mapps code:status`](#mapps-codestatus)
51+
52+
- [`mapps code:status`](#mapps-codestatus)
53+
4654
* [`mapps database:connection-string`](#mapps-databaseconnection-string)
47-
* [`mapps help [COMMANDS]`](#mapps-help-commands)
48-
* [`mapps init`](#mapps-init)
55+
56+
- [`mapps help [COMMANDS]`](#mapps-help-commands)
57+
- [`mapps init`](#mapps-init)
58+
4959
* [`mapps scheduler:create`](#mapps-schedulercreate)
5060
* [`mapps scheduler:delete`](#mapps-schedulerdelete)
5161
* [`mapps scheduler:list`](#mapps-schedulerlist)
5262
* [`mapps scheduler:run`](#mapps-schedulerrun)
5363
* [`mapps scheduler:update`](#mapps-schedulerupdate)
54-
* [`mapps storage:export`](#mapps-storageexport)
64+
65+
- [`mapps manifest:export`](#mapps-manifestexport)
66+
- [`mapps manifest:import`](#mapps-manifestimport)
67+
- [`mapps storage:export`](#mapps-storageexport)
68+
5569
* [`mapps storage:remove-data`](#mapps-storageremove-data)
56-
* [`mapps storage:search`](#mapps-storagesearch)
57-
* [`mapps tunnel:create`](#mapps-tunnelcreate)
70+
71+
- [`mapps storage:search`](#mapps-storagesearch)
72+
- [`mapps tunnel:create`](#mapps-tunnelcreate)
5873

5974
## `mapps api:generate`
6075

@@ -202,7 +217,7 @@ EXAMPLES
202217
$ mapps app-version:list
203218
```
204219

205-
_See code: [src/commands/app-version/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app-version/list.ts)_
220+
_See code: [src/commands/app-version/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/master/src/commands/app-version/list.ts)_
206221

207222
## `mapps app:create`
208223

@@ -567,6 +582,58 @@ EXAMPLES
567582

568583
_See code: [src/commands/init/index.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/init/index.ts)_
569584

585+
## `mapps manifest:export`
586+
587+
export manifest.
588+
589+
```
590+
USAGE
591+
$ mapps manifest:export [--verbose] [--print-command] [-a <value>] [-v <value>]
592+
593+
FLAGS
594+
-a, --appId=<value> App id (will export the live version)
595+
-v, --appVersionId=<value> App version id
596+
597+
GLOBAL FLAGS
598+
--print-command Print the command that was executed (optional).
599+
--verbose Print advanced logs (optional).
600+
601+
DESCRIPTION
602+
export manifest.
603+
604+
EXAMPLES
605+
$ mapps manifest:export
606+
```
607+
608+
_See code: [src/commands/manifest/export.ts](https://github.com/mondaycom/monday-apps-cli/blob/master/src/commands/manifest/export.ts)_
609+
610+
## `mapps manifest:import`
611+
612+
Import manifest.
613+
614+
```
615+
USAGE
616+
$ mapps manifest:import [--verbose] [--print-command] [-p <value>] [-a <value>] [-v <value>] [-n]
617+
618+
FLAGS
619+
-a, --appId=<value> App id (will create new draft version)
620+
-n, --newApp Create new app
621+
-p, --manifestPath=<value> Path of you manifest file in your machine
622+
-v, --appVersionId=<value> App version id to override
623+
624+
GLOBAL FLAGS
625+
--print-command Print the command that was executed (optional).
626+
--verbose Print advanced logs (optional).
627+
628+
DESCRIPTION
629+
Import manifest.
630+
631+
EXAMPLES
632+
$ mapps manifest:import
633+
```
634+
635+
_See code: [src/commands/manifest/import.ts](https://github.com/mondaycom/monday-apps-cli/blob/master/src/commands/manifest/import.ts)_
636+
570637
## `mapps scheduler:create`
571638

572639
Create a new scheduler job for an app
@@ -829,5 +896,6 @@ EXAMPLES
829896
$ mapps tunnel:create -p PORT_FOR_TUNNEL -a APP_ID_FOR_TUNNEL
830897
```
831898

832-
_See code: [src/commands/tunnel/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/tunnel/create.ts)_
899+
_See code: [src/commands/tunnel/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/master/src/commands/tunnel/create.ts)_
900+
833901
<!-- commandsstop -->

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mondaycom/apps-cli",
3-
"version": "4.7.5",
3+
"version": "4.8.0",
44
"description": "A cli tool to manage apps (and monday-code projects) in monday.com",
55
"author": "monday.com Apps Team",
66
"type": "module",
@@ -53,6 +53,7 @@
5353
"@oclif/core": "^3.18.1",
5454
"@oclif/plugin-autocomplete": "^3.0.5",
5555
"@oclif/plugin-help": "^6.0.12",
56+
"adm-zip": "^0.5.16",
5657
"archiver": "^5.3.1",
5758
"args-parser": "^1.3.0",
5859
"axios": "^1.6.5",
@@ -65,6 +66,7 @@
6566
"fs-extra": "^11.2.0",
6667
"fuzzy": "^0.1.3",
6768
"glob": "^8.1.0",
69+
"handlebars": "^4.7.8",
6870
"http-status-codes": "^2.2.0",
6971
"inquirer": "^8.2.6",
7072
"inquirer-autocomplete-prompt": "^2.0.0",
@@ -83,10 +85,12 @@
8385
"zod": "^3.20.2"
8486
},
8587
"devDependencies": {
88+
"@types/adm-zip": "^0.5.7",
8689
"@types/archiver": "^5.3.1",
8790
"@types/figlet": "^1.5.5",
8891
"@types/fs-extra": "^11.0.4",
8992
"@types/glob": "^8.0.0",
93+
"@types/handlebars": "^4.1.0",
9094
"@types/inquirer": "^8.2.10",
9195
"@types/inquirer-autocomplete-prompt": "^2.0.2",
9296
"@types/jest": "^29.5.6",

src/commands/manifest/export.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { Flags } from '@oclif/core';
2+
import { Listr } from 'listr2';
3+
4+
import { AuthenticatedCommand } from 'commands-base/authenticated-command';
5+
import { DynamicChoicesService } from 'services/dynamic-choices-service';
6+
import * as exportService from 'services/export-manifest-service';
7+
import { ExportCommandTasksContext } from 'types/commands/manifest-export';
8+
import logger from 'utils/logger';
9+
10+
const MESSAGES = {
11+
appId: 'App id (will export the live version)',
12+
appVersionId: 'App version id',
13+
path: 'Path to export your app manifest files to',
14+
};
15+
16+
export default class ManifestExport extends AuthenticatedCommand {
17+
static description = 'export app manifest.';
18+
static withPrintCommand = false;
19+
static examples = [
20+
'<%= config.bin %> <%= command.id %>',
21+
'<%= config.bin %> <%= command.id %> -p ./exports',
22+
'<%= config.bin %> <%= command.id %> --manifestPath ./my-manifests',
23+
];
24+
25+
static flags = ManifestExport.serializeFlags({
26+
manifestPath: Flags.string({
27+
char: 'p',
28+
description: MESSAGES.path,
29+
}),
30+
appId: Flags.string({
31+
char: 'a',
32+
description: MESSAGES.appId,
33+
}),
34+
appVersionId: Flags.integer({
35+
char: 'i',
36+
aliases: ['v'],
37+
description: MESSAGES.appVersionId,
38+
}),
39+
});
40+
41+
DEBUG_TAG = 'manifest_export';
42+
43+
async getAppVersionId(appVersionId: number | undefined, appId: number | undefined): Promise<number> {
44+
if (appVersionId) return appVersionId;
45+
46+
const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, true, {
47+
appId: Number(appId),
48+
autoSelectVersion: false,
49+
});
50+
51+
return latestDraftVersion.appVersionId;
52+
}
53+
54+
public async run(): Promise<void> {
55+
try {
56+
const { flags } = await this.parse(ManifestExport);
57+
const { manifestPath, appId: appIdAsString, appVersionId: appVersionIdAsString } = flags;
58+
59+
let appId = appIdAsString ? Number(appIdAsString) : undefined;
60+
let appVersionId = appVersionIdAsString ? Number(appVersionIdAsString) : undefined;
61+
62+
if (appVersionId && !appId) {
63+
logger.error('App id is required when app version id is provided');
64+
process.exit(1);
65+
}
66+
67+
if (!appId && !appVersionId) {
68+
appId = Number(await DynamicChoicesService.chooseApp());
69+
appVersionId = await this.getAppVersionId(undefined, appId);
70+
}
71+
72+
this.preparePrintCommand(this, flags);
73+
74+
const tasks = new Listr<ExportCommandTasksContext>(
75+
[
76+
{ title: 'Validate app before exporting manifest', task: exportService.validateManifestTask },
77+
{ title: 'Export app manifest', task: exportService.downloadManifestTask },
78+
],
79+
{ ctx: { appVersionId, appId: appId!, manifestPath } },
80+
);
81+
82+
await tasks.run();
83+
} catch (error) {
84+
logger.debug(error, this.DEBUG_TAG);
85+
process.exit(1);
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)