|
1 |
| -import {paramCase} from 'change-case' |
2 |
| -import { SAMLocalCLIOptions, SAMLocalType } from "./types" |
3 |
| -import { isNotEmptyString, isFinite} from "./utils" |
| 1 | +import { paramCase } from 'change-case'; |
| 2 | +import { SAMLocalCLIOptions, SAMLocalType } from './types'; |
| 3 | +import { isNotEmptyString, isFinite } from './utils'; |
4 | 4 |
|
5 | 5 | const cliOptionKeys = [
|
6 |
| - 'host', 'port', 'template', 'envVars', 'parameterOverrides', |
7 |
| - 'debugPort', 'debuggerPath', 'debugArgs', 'warmContainers', |
8 |
| - 'debugFunction', 'dockerVolumeBasedir', 'dockerNetwork', |
9 |
| - 'containerEnvVars', 'logFile', 'layerCacheBasedir', |
10 |
| - 'skipPullImage', 'forceImageBuild', 'profile', |
11 |
| - 'region', 'configFile', 'configEnv', 'debug', |
12 |
| -] |
| 6 | + 'host', |
| 7 | + 'port', |
| 8 | + 'template', |
| 9 | + 'envVars', |
| 10 | + 'parameterOverrides', |
| 11 | + 'debugPort', |
| 12 | + 'debuggerPath', |
| 13 | + 'debugArgs', |
| 14 | + 'warmContainers', |
| 15 | + 'debugFunction', |
| 16 | + 'dockerVolumeBasedir', |
| 17 | + 'dockerNetwork', |
| 18 | + 'containerEnvVars', |
| 19 | + 'logFile', |
| 20 | + 'layerCacheBasedir', |
| 21 | + 'skipPullImage', |
| 22 | + 'forceImageBuild', |
| 23 | + 'profile', |
| 24 | + 'region', |
| 25 | + 'configFile', |
| 26 | + 'configEnv', |
| 27 | + 'debug', |
| 28 | +]; |
13 | 29 |
|
14 | 30 | const isLocalStartLambdaCLIArgKey = (key: string) => {
|
15 |
| - return cliOptionKeys.indexOf(key) > -1 |
16 |
| -} |
| 31 | + return cliOptionKeys.indexOf(key) > -1; |
| 32 | +}; |
17 | 33 | const isLocalStartAPICLIArgKey = (key: string) => {
|
18 |
| - return [...cliOptionKeys, 'staticDir'].indexOf(key) > -1 |
19 |
| -} |
| 34 | + return [...cliOptionKeys, 'staticDir'].indexOf(key) > -1; |
| 35 | +}; |
20 | 36 |
|
21 | 37 | export const getCLIOptionArgs = (
|
22 | 38 | type: SAMLocalType,
|
23 |
| - options: SAMLocalCLIOptions, |
| 39 | + options: SAMLocalCLIOptions |
24 | 40 | ): string[] => {
|
25 | 41 | const args = Object.keys(options).reduce((prev, key) => {
|
26 |
| - const validKey = type === 'api' |
27 |
| - ? isLocalStartAPICLIArgKey(key) |
28 |
| - : isLocalStartLambdaCLIArgKey(key) |
| 42 | + const validKey = |
| 43 | + type === 'api' |
| 44 | + ? isLocalStartAPICLIArgKey(key) |
| 45 | + : isLocalStartLambdaCLIArgKey(key); |
29 | 46 | if (!validKey) {
|
30 |
| - console.warn(`Unknown option: ${key}. It is ignored.`) |
31 |
| - return prev |
| 47 | + console.warn(`Unknown option: ${key}. It is ignored.`); |
| 48 | + return prev; |
32 | 49 | }
|
33 | 50 |
|
34 |
| - const value = options[key as keyof SAMLocalCLIOptions] |
35 |
| - const paramArgs = |
36 |
| - isNotEmptyString(value) ? [`--${paramCase(key)}`, value] |
37 |
| - : isFinite(value) ? [`--${paramCase(key)}`, value+''] |
38 |
| - :/*typeof value === 'boolean'*/ [`--${paramCase(key)}`] |
39 |
| - return [...prev, ...paramArgs] |
40 |
| - }, [] as string[]) |
| 51 | + const value = options[key as keyof SAMLocalCLIOptions]; |
| 52 | + const paramArgs = isNotEmptyString(value) |
| 53 | + ? [`--${paramCase(key)}`, value] |
| 54 | + : isFinite(value) |
| 55 | + ? [`--${paramCase(key)}`, value + ''] |
| 56 | + : /*typeof value === 'boolean'*/ [`--${paramCase(key)}`]; |
| 57 | + return [...prev, ...paramArgs]; |
| 58 | + }, [] as string[]); |
41 | 59 |
|
42 |
| - return args |
43 |
| -} |
| 60 | + return args; |
| 61 | +}; |
0 commit comments