1- import { FlagInput , Flags } from '@contentstack/cli-utilities' ;
2-
3- import { BaseCommand } from '../../base-command' ;
1+ import { FlagInput } from '@contentstack/cli-utilities' ;
42import Contentfly from '../../util/cloud-function' ;
3+ import { Flags , Command } from '@oclif/core' ;
54
6- export default class Functions extends BaseCommand < typeof Functions > {
5+ export default class Functions extends Command {
76 static description = 'Serve cloud functions' ;
87
98 static examples = [
109 '$ csdx launch:functions' ,
1110 '$ csdx launch:functions --port=port' ,
1211 '$ csdx launch:functions --data-dir <path/of/current/working/dir>' ,
13- '$ csdx launch:functions --config <path/to/launch/config/file>' ,
1412 '$ csdx launch:functions --data-dir <path/of/current/working/dir> -p "port number"' ,
15- '$ csdx launch:functions --config <path/to/launch/config/file> --port=port' ,
1613 ] ;
1714
1815 static flags : FlagInput = {
@@ -21,13 +18,17 @@ export default class Functions extends BaseCommand<typeof Functions> {
2118 default : '3000' ,
2219 description : 'Port number' ,
2320 } ) ,
21+ 'data-dir' : Flags . string ( {
22+ char : 'd' ,
23+ description : 'Current working directory' ,
24+ } ) ,
2425 } ;
2526
2627 async run ( ) : Promise < void > {
27- this . sharedConfig . config =
28- this . flags [ 'data-dir' ] || this . flags . config
29- ? this . flags . config ?. split ( ` ${ this . sharedConfig . configName } ` ) [ 0 ] || this . flags [ 'data-dir' ]
30- : process . cwd ( ) ;
31- await new Contentfly ( this . sharedConfig . config as string ) . serveCloudFunctions ( + this . flags . port ) ;
28+ const { flags } = await this . parse ( Functions ) ;
29+ const currentWorkingDirectory = process . cwd ( ) ;
30+ const projectBasePath = flags [ 'data-dir' ] || currentWorkingDirectory ;
31+
32+ await new Contentfly ( projectBasePath ) . serveCloudFunctions ( + flags . port ) ;
3233 }
3334}
0 commit comments