UNPKG

@mondaycom/apps-cli

Version:

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

48 lines (47 loc) 2.31 kB
import { Flags } from '@oclif/core'; import { BaseCommand } from '../../commands-base/base-command.js'; import { CONFIG_KEYS } from '../../consts/config.js'; import { CONFIG_NAME, ConfigService } from '../../services/config-service.js'; import { getCurrentWorkingDirectory } from '../../services/env-service.js'; import { createGitignoreAndAppendConfigFileIfNeeded } from '../../services/files-service.js'; import { PromptService } from '../../services/prompt-service.js'; import logger from '../../utils/logger.js'; const accessTokenPrompt = async () => PromptService.promptForHiddenInput('token', 'Please enter your monday.com api access token', 'You must provide an access token'); export default class Init extends BaseCommand { static description = `Initialize mapps config file - "${CONFIG_NAME}".`; static withPrintCommand = false; forcefullyExitAfterRun = false; // init exists in any case after it's run, so we don't need to forcefully exit static examples = ['<%= config.bin %> <%= command.id %> -t SECRET_TOKEN']; static flags = Init.serializeFlags({ token: Flags.string({ char: 't', description: 'monday.com api access token (https://developer.monday.com/api-reference/docs/authentication)', }), local: Flags.boolean({ char: 'l', description: 'create the configuration file locally, in the current project working directory', default: false, required: false, }), }); static args = {}; DEBUG_TAG = 'init'; async run() { const { flags } = await this.parse(Init); const args = { [CONFIG_KEYS.ACCESS_TOKEN]: flags.token || (await accessTokenPrompt()), }; try { if (flags.local) { this.config.configDir = getCurrentWorkingDirectory(); createGitignoreAndAppendConfigFileIfNeeded(this.config.configDir); } ConfigService.init(args, this.config.configDir, { override: true, setInProcessEnv: true }); logger.info(`'${CONFIG_NAME}' created inside '${this.config.configDir}'`); } catch (error) { logger.debug(error, this.DEBUG_TAG); logger.error(`'${CONFIG_NAME}' failed to initialize`); } } }