UNPKG

@mondaycom/apps-cli

Version:

A cli tool to manage apps (and monday-code projects) in monday.com

52 lines (51 loc) 2.46 kB
import path from 'node:path'; import { Flags } from '@oclif/core'; import { Listr } from 'listr2'; import { AuthenticatedCommand } from '../../commands-base/authenticated-command.js'; import { cloneAppTemplateAndLoadManifest, createApp, createFeatures } from '../../services/apps-service.js'; import { DynamicChoicesService } from '../../services/dynamic-choices-service.js'; import { PromptService } from '../../services/prompt-service.js'; import logger from '../../utils/logger.js'; import { getLastParam } from '../../utils/urls-builder.js'; export default class AppCreate extends AuthenticatedCommand { static description = 'Create an app.'; static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> -n NEW_APP_NAME']; static flags = AppCreate.serializeFlags({ name: Flags.string({ char: 'n', description: 'Name your new app.', required: false, }), targetDir: Flags.string({ char: 'd', description: 'Directory to create the app in.', required: false, }), }); DEBUG_TAG = 'app_create'; async run() { try { const { flags } = await this.parse(AppCreate); let name = flags.name; if (!name) { name = await PromptService.promptInput('Enter app name:'); } this.preparePrintCommand(this, { targetDir: flags.targetDir, name }); const { githubUrl, folder, branch } = await DynamicChoicesService.chooseAppTemplate(); const targetDir = flags.targetDir || process.cwd(); const selectedTemplatePath = path.join(targetDir, getLastParam(folder)); const tasks = new Listr([ { title: 'Downloading template', task: cloneAppTemplateAndLoadManifest }, { title: 'Creating app', task: createApp }, { title: 'Creating features', task: createFeatures }, ]); await tasks.run({ appName: name, targetPath: selectedTemplatePath, folder: folder, branch, githubUrl }); logger.success(`Your app is ready, 'cd ${getLastParam(tasks.ctx.targetPath)}' to see your app files. \n` + `Go to developer center to see your app: '${tasks.ctx.appName}' (id: ${tasks.ctx.appId})`); } catch (error) { logger.debug(error, this.DEBUG_TAG); throw error; } } }