@mondaycom/apps-cli
Version:
A cli tool to manage apps (and monday-code projects) in monday.com
72 lines (71 loc) • 2.97 kB
JavaScript
import { Flags } from '@oclif/core';
import { Listr } from 'listr2';
import { AuthenticatedCommand } from '../../commands-base/authenticated-command.js';
import { DynamicChoicesService } from '../../services/dynamic-choices-service.js';
import * as exportService from '../../services/export-manifest-service.js';
import logger from '../../utils/logger.js';
const MESSAGES = {
appId: 'App id (will export the live version)',
appVersionId: 'App version id',
path: 'Path to export your app manifest files to',
};
export default class ManifestExport extends AuthenticatedCommand {
static description = 'export app manifest.';
static withPrintCommand = false;
static examples = [
'<%= config.bin %> <%= command.id %>',
'<%= config.bin %> <%= command.id %> -p ./exports',
'<%= config.bin %> <%= command.id %> --manifestPath ./my-manifests',
];
static flags = ManifestExport.serializeFlags({
manifestPath: Flags.string({
char: 'p',
description: MESSAGES.path,
}),
appId: Flags.string({
char: 'a',
description: MESSAGES.appId,
}),
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: MESSAGES.appVersionId,
}),
});
DEBUG_TAG = 'manifest_export';
async getAppVersionId(appVersionId, appId) {
if (appVersionId)
return appVersionId;
const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, true, {
appId: Number(appId),
autoSelectVersion: false,
});
return latestDraftVersion.appVersionId;
}
async run() {
try {
const { flags } = await this.parse(ManifestExport);
const { manifestPath, appId: appIdAsString, appVersionId: appVersionIdAsString } = flags;
let appId = appIdAsString ? Number(appIdAsString) : undefined;
let appVersionId = appVersionIdAsString ? Number(appVersionIdAsString) : undefined;
if (appVersionId && !appId) {
logger.error('App id is required when app version id is provided');
process.exit(1);
}
if (!appId && !appVersionId) {
appId = Number(await DynamicChoicesService.chooseApp());
appVersionId = await this.getAppVersionId(undefined, appId);
}
this.preparePrintCommand(this, flags);
const tasks = new Listr([
{ title: 'Validate app before exporting manifest', task: exportService.validateManifestTask },
{ title: 'Export app manifest', task: exportService.downloadManifestTask },
], { ctx: { appVersionId, appId: appId, manifestPath } });
await tasks.run();
}
catch (error) {
logger.debug(error, this.DEBUG_TAG);
process.exit(1);
}
}
}