Skip to content

Commit 9e148c2

Browse files
authored
feat: add --dry-run option to load user's function but not start a server (#118)
* feat: add --dry-run option to load user's function but not start a server * Change the --dry-run log message.
1 parent f2544de commit 9e148c2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const FLAG = {
4343
TARGET: 'target',
4444
SIGNATURE_TYPE: 'signature-type', // dash
4545
SOURCE: 'source',
46+
DRY_RUN: 'dry-run',
4647
};
4748

4849
// Supported environment variables
@@ -51,14 +52,15 @@ const ENV = {
5152
TARGET: 'FUNCTION_TARGET',
5253
SIGNATURE_TYPE: 'FUNCTION_SIGNATURE_TYPE', // underscore
5354
SOURCE: 'FUNCTION_SOURCE',
55+
DRY_RUN: 'DRY_RUN',
5456
};
5557

5658
enum NodeEnv {
5759
PRODUCTION = 'production',
5860
}
5961

6062
const argv = minimist(process.argv, {
61-
string: [FLAG.PORT, FLAG.TARGET, FLAG.SIGNATURE_TYPE],
63+
string: [FLAG.PORT, FLAG.TARGET, FLAG.SIGNATURE_TYPE, FLAG.DRY_RUN],
6264
});
6365

6466
const CODE_LOCATION = resolve(
@@ -77,6 +79,7 @@ if (SIGNATURE_TYPE === undefined) {
7779
console.error(`Function signature type must be one of 'http' or 'event'.`);
7880
process.exit(1);
7981
}
82+
const DRY_RUN = argv[FLAG.DRY_RUN] || process.env[ENV.DRY_RUN] || false;
8083

8184
// CLI Help Flag
8285
if (process.argv[2] === '-h' || process.argv[2] === '--help') {
@@ -97,6 +100,14 @@ if (!USER_FUNCTION) {
97100

98101
const SERVER = getServer(USER_FUNCTION!, SIGNATURE_TYPE!);
99102
const ERROR_HANDLER = new ErrorHandler(SERVER);
103+
104+
if (DRY_RUN) {
105+
console.log(`Function: ${TARGET}`);
106+
console.log(`URL: http://localhost:${PORT}/`);
107+
console.log('Dry run successful, shutting down.');
108+
process.exit(0);
109+
}
110+
100111
SERVER.listen(PORT, () => {
101112
ERROR_HANDLER.register();
102113
if (process.env.NODE_ENV !== NodeEnv.PRODUCTION) {

0 commit comments

Comments
 (0)