UNPKG

@mondaycom/apps-cli

Version:

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

60 lines (59 loc) 2.58 kB
import { Flags } from '@oclif/core'; import { Listr } from 'listr2'; import { AuthenticatedCommand } from '../../commands-base/authenticated-command.js'; import { connectTunnel, createTunnelConnection, generateTunnelingAuthToken } from '../../services/tunnel-service.js'; import { validateStringAsSafeInt } from '../../types/utils/validation.js'; import logger from '../../utils/logger.js'; export default class TunnelCreate extends AuthenticatedCommand { static description = 'Create a networking tunnel to publicly expose code running on the local machine.'; static withPrintCommand = false; static examples = [ '<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> -p PORT_FOR_TUNNEL', '<%= config.bin %> <%= command.id %> -a APP_ID_FOR_TUNNEL', '<%= config.bin %> <%= command.id %> -p PORT_FOR_TUNNEL -a APP_ID_FOR_TUNNEL', ]; static flags = TunnelCreate.serializeFlags({ port: Flags.integer({ char: 'p', description: 'Port to forward tunnel traffic to.', default: 8080, }), appId: Flags.integer({ char: 'a', description: 'Specify an app id to get a unique tunnel domain for this app.', required: false, }), }); DEBUG_TAG = 'tunnel_create'; async run() { try { const { flags } = await this.parse(TunnelCreate); const { port, appId } = flags; logger.debug(`creating tunnel: port=${port}, appId=${appId}`, this.DEBUG_TAG); const tasks = new Listr([ { title: 'Fetching tunnel connection auth token', task: generateTunnelingAuthToken, enabled: () => validateStringAsSafeInt(String(port)), }, { title: 'Creating tunnel connection', task: createTunnelConnection, enabled: ctx => Boolean(ctx.authToken) && Boolean(ctx.tunnelDomain), }, { title: 'Tunnel is up and running', task: connectTunnel, enabled: ctx => Boolean(ctx.forwardingAddress) && Boolean(ctx.tunnel), }, ], { ctx: { appId, tunnelPort: port } }); await tasks.run(); } catch (error) { logger.debug(error, this.DEBUG_TAG); // need to signal to the parent process that the command failed process.exit(1); } } }