Skip to content

Commit ac036f9

Browse files
committed
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
1 parent 252dfab commit ac036f9

18 files changed

+795
-60
lines changed

README.md

Lines changed: 94 additions & 23 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,54 @@ 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:remove-data`](#mapps-storageremove-data)
72+
- [`mapps storage:search`](#mapps-storagesearch)
73+
- [`mapps tunnel:create`](#mapps-tunnelcreate)
5874

5975
## `mapps api:generate`
6076

@@ -67,6 +83,7 @@ USAGE
6783
DESCRIPTION
6884
Prepares your environment for custom queries development. run it from your root directory!
6985
Creates all necessary files and scripts
86+
Creates all necessary files and scripts
7087
to start working with custom api queries and mutations.
7188
Read the documentation at
7289
[@mondaydotcomorg/setup-api](https://github.com/mondaycom/monday-graphql-api/tree/main/packages/setup-api)
@@ -202,6 +219,7 @@ EXAMPLES
202219
$ mapps app-version:list
203220
```
204221

222+
_See code: [src/commands/app-version/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.3.2/src/commands/app-version/list.ts)_
205223
_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)_
206224

207225
## `mapps app:create`
@@ -567,6 +585,58 @@ EXAMPLES
567585

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

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

572642
Create a new scheduler job for an app
@@ -830,4 +900,5 @@ EXAMPLES
830900
```
831901

832902
_See code: [src/commands/tunnel/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/tunnel/create.ts)_
903+
833904
<!-- commandsstop -->

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)