From 1e6a91cdc7bae2691881bcd0e09c1ef9e0c80780 Mon Sep 17 00:00:00 2001 From: dhruvparekh12 Date: Tue, 11 Mar 2025 14:24:14 +0530 Subject: [PATCH] Skip logging in, init and sdk initialization for 'functions' command as it would not be required if a user simply wants to run launch cloud functions locally or in a serverless environment --- src/commands/launch/functions.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/commands/launch/functions.ts b/src/commands/launch/functions.ts index c5e3b78..8e5f46d 100755 --- a/src/commands/launch/functions.ts +++ b/src/commands/launch/functions.ts @@ -1,18 +1,15 @@ -import { FlagInput, Flags } from '@contentstack/cli-utilities'; - -import { BaseCommand } from '../../base-command'; +import { FlagInput } from '@contentstack/cli-utilities'; import Contentfly from '../../util/cloud-function'; +import { Flags, Command } from '@oclif/core'; -export default class Functions extends BaseCommand { +export default class Functions extends Command { static description = 'Serve cloud functions'; static examples = [ '$ csdx launch:functions', '$ csdx launch:functions --port=port', '$ csdx launch:functions --data-dir ', - '$ csdx launch:functions --config ', '$ csdx launch:functions --data-dir -p "port number"', - '$ csdx launch:functions --config --port=port', ]; static flags: FlagInput = { @@ -21,13 +18,17 @@ export default class Functions extends BaseCommand { default: '3000', description: 'Port number', }), + 'data-dir': Flags.string({ + char: 'd', + description: 'Current working directory', + }), }; async run(): Promise { - this.sharedConfig.config = - this.flags['data-dir'] || this.flags.config - ? this.flags.config?.split(`${this.sharedConfig.configName}`)[0] || this.flags['data-dir'] - : process.cwd(); - await new Contentfly(this.sharedConfig.config as string).serveCloudFunctions(+this.flags.port); + const { flags } = await this.parse(Functions); + const currentWorkingDirectory = process.cwd(); + const projectBasePath = flags['data-dir'] || currentWorkingDirectory; + + await new Contentfly(projectBasePath).serveCloudFunctions(+flags.port); } }