From 7126623867c41b5b8680f6f8a9942d383e3af847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gardu=C3=B1o?= Date: Sat, 6 Jul 2019 11:27:21 -0500 Subject: [PATCH 1/3] new: Adds source flag for flexibility to execute different paths --- src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 77e42e9a..7a236265 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,6 +28,7 @@ // unmarshalled from an incoming request. import * as minimist from 'minimist'; +import { resolve } from 'path'; import { ErrorHandler, @@ -41,6 +42,7 @@ const FLAG = { PORT: 'port', TARGET: 'target', SIGNATURE_TYPE: 'signature-type', // dash + SOURCE: 'source', }; // Supported environment variables @@ -48,6 +50,7 @@ const ENV = { PORT: 'PORT', TARGET: 'FUNCTION_TARGET', SIGNATURE_TYPE: 'FUNCTION_SIGNATURE_TYPE', // underscore + SOURCE: 'SOURCE', }; enum NodeEnv { @@ -58,7 +61,10 @@ const argv = minimist(process.argv, { string: [FLAG.PORT, FLAG.TARGET, FLAG.SIGNATURE_TYPE], }); -const CODE_LOCATION = process.cwd(); +const CODE_LOCATION = resolve( + process.cwd(), + argv[FLAG.SOURCE] || process.env[ENV.SOURCE] || '/' +); const PORT = argv[FLAG.PORT] || process.env[ENV.PORT] || '8080'; const TARGET = argv[FLAG.TARGET] || process.env[ENV.TARGET] || 'function'; From c3edef3d6af69d53a6dec23761109625d0e61305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gardu=C3=B1o?= Date: Sat, 6 Jul 2019 23:50:28 -0500 Subject: [PATCH 2/3] Add the option flag/env to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e46eceea..ea4c357a 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ Command-line flag | Environment variable | Description `--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080` `--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function` `--signature-type` | `FUNCTION_SIGNATURE_TYPE` | The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http` or `event` +`--source` | `SOURCE` | The path of your project directory where you want to start. Functions framework always look only at root path, setting this option will look for your function in any other folder. Default: `/` You can set command-line flags in your `package.json` via the `start` script. For example: From c69c05becc2ab5b70744484d35085744920bcca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gardu=C3=B1o?= Date: Tue, 9 Jul 2019 21:13:25 -0500 Subject: [PATCH 3/3] fix: env vars must start with FUNCTION_ prefix --- README.md | 2 +- src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea4c357a..fa8c9fd1 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Command-line flag | Environment variable | Description `--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080` `--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function` `--signature-type` | `FUNCTION_SIGNATURE_TYPE` | The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http` or `event` -`--source` | `SOURCE` | The path of your project directory where you want to start. Functions framework always look only at root path, setting this option will look for your function in any other folder. Default: `/` +`--source` | `FUNCTION_SOURCE` | The path of your project directory where you want to start. Functions framework always look only at root path, setting this option will look for your function in any other folder. Default: `/` You can set command-line flags in your `package.json` via the `start` script. For example: diff --git a/src/index.ts b/src/index.ts index 7a236265..6b3c58f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,7 +50,7 @@ const ENV = { PORT: 'PORT', TARGET: 'FUNCTION_TARGET', SIGNATURE_TYPE: 'FUNCTION_SIGNATURE_TYPE', // underscore - SOURCE: 'SOURCE', + SOURCE: 'FUNCTION_SOURCE', }; enum NodeEnv {