Skip to content

Commit 65fa965

Browse files
committed
Run prettier
1 parent c7c0243 commit 65fa965

9 files changed

+98
-69
lines changed

.prettierrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
trailingComma: 'es5',
3+
singleQuote: true,
4+
};

lib/SAMLocal.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export interface SAMLocal {
2222
export async function createSAMLocal(
2323
type: SAMLocalType,
2424
cwd: string,
25-
options: SAMLocalOptions = {cliOptions: {}},
25+
options: SAMLocalOptions = { cliOptions: {} }
2626
): Promise<SAMLocal> {
27-
const {onData, onError, cliOptions} = options;
27+
const { onData, onError, cliOptions } = options;
2828
const typeArg = type === 'sdk' ? 'start-lambda' : 'start-api';
2929
const spawnArgs = ['local', typeArg, ...getCLIOptionArgs(type, cliOptions)];
3030
const defer = createDeferred();

lib/SAMLocalCLIOptions.ts

+47-29
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,61 @@
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';
44

55
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+
];
1329

1430
const isLocalStartLambdaCLIArgKey = (key: string) => {
15-
return cliOptionKeys.indexOf(key) > -1
16-
}
31+
return cliOptionKeys.indexOf(key) > -1;
32+
};
1733
const isLocalStartAPICLIArgKey = (key: string) => {
18-
return [...cliOptionKeys, 'staticDir'].indexOf(key) > -1
19-
}
34+
return [...cliOptionKeys, 'staticDir'].indexOf(key) > -1;
35+
};
2036

2137
export const getCLIOptionArgs = (
2238
type: SAMLocalType,
23-
options: SAMLocalCLIOptions,
39+
options: SAMLocalCLIOptions
2440
): string[] => {
2541
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);
2946
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;
3249
}
3350

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[]);
4159

42-
return args
43-
}
60+
return args;
61+
};

lib/generateAppModel.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function generateSAM({
5858
cwd,
5959
onData,
6060
onError,
61-
cliOptions={},
61+
cliOptions = {},
6262
}: Props): Promise<SAM> {
6363
const _tmpDir = tmpDir({ unsafeCleanup: true });
6464
const workdir = _tmpDir.name;
@@ -119,9 +119,9 @@ export async function generateSAM({
119119
let region: string;
120120

121121
async function start() {
122-
port = cliOptions.port || await getPort();
123-
host = cliOptions.host || '127.0.0.1'
124-
region = cliOptions.region || 'local'
122+
port = cliOptions.port || (await getPort());
123+
host = cliOptions.host || '127.0.0.1';
124+
region = cliOptions.region || 'local';
125125
SAM = await createSAMLocal('api', workdir, {
126126
onData,
127127
onError,

lib/generateProxyModel.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function generateProxySAM({
4949
runtime = 'nodejs12.x',
5050
onData,
5151
onError,
52-
cliOptions={},
52+
cliOptions = {},
5353
}: Props): Promise<SAM> {
5454
const _tmpDir = tmpDir({ unsafeCleanup: true });
5555
const workdir = _tmpDir.name;
@@ -99,8 +99,8 @@ export async function generateProxySAM({
9999
async function start() {
100100
// Initialize SAM
101101
port = await getPort();
102-
host = cliOptions.host || '127.0.0.1'
103-
region = cliOptions.region || 'local'
102+
host = cliOptions.host || '127.0.0.1';
103+
region = cliOptions.region || 'local';
104104
SAM = await createSAMLocal('sdk', workdir, {
105105
onData,
106106
onError,

lib/types.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,33 @@ export interface ConfigLambda {
4242
memorySize?: number;
4343
}
4444

45-
export type SAMLocalType = 'sdk' | 'api'
45+
export type SAMLocalType = 'sdk' | 'api';
4646

47-
type WarmContainersOptions = 'EAGER' | 'LAZY'
47+
type WarmContainersOptions = 'EAGER' | 'LAZY';
4848

4949
export interface SAMLocalCLICommonOptions {
50-
host?: string
51-
port?: number
52-
template?: string
53-
envVars?: string
54-
parameterOverrides?: string
55-
debugPort?: string
56-
debuggerPath?: string
57-
debugArgs?: string
58-
warmContainers?: WarmContainersOptions
59-
debugFunction?: string
60-
dockerVolumeBasedir?: string
61-
dockerNetwork?: string
62-
containerEnvVars?: string
63-
logFile?: string
64-
layerCacheBasedir?: string
65-
skipPullImage?: boolean
66-
forceImageBuild?: boolean
67-
profile?: string
68-
region?: string
69-
configFile?: string
70-
configEnv?: string
71-
debug?: boolean
50+
host?: string;
51+
port?: number;
52+
template?: string;
53+
envVars?: string;
54+
parameterOverrides?: string;
55+
debugPort?: string;
56+
debuggerPath?: string;
57+
debugArgs?: string;
58+
warmContainers?: WarmContainersOptions;
59+
debugFunction?: string;
60+
dockerVolumeBasedir?: string;
61+
dockerNetwork?: string;
62+
containerEnvVars?: string;
63+
logFile?: string;
64+
layerCacheBasedir?: string;
65+
skipPullImage?: boolean;
66+
forceImageBuild?: boolean;
67+
profile?: string;
68+
region?: string;
69+
configFile?: string;
70+
configEnv?: string;
71+
debug?: boolean;
7272
// help?: boolean
7373
}
7474

@@ -79,9 +79,9 @@ export interface SAMLocalLambadCLIOptions extends SAMLocalCLICommonOptions {
7979

8080
export interface SAMLocalAPICLIOptions extends SAMLocalCLICommonOptions {
8181
// https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html
82-
staticDir?: string
82+
staticDir?: string;
8383
}
8484

8585
export type SAMLocalCLIOptions =
8686
| SAMLocalLambadCLIOptions
87-
| SAMLocalAPICLIOptions
87+
| SAMLocalAPICLIOptions;

lib/utils/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ export function normalizeCloudFrontHeaders(
140140
}
141141

142142
export const isNotEmptyString = (a: any): a is string => {
143-
return typeof a === 'string' && !!a
144-
}
143+
return typeof a === 'string' && !!a;
144+
};
145145

146146
export const isFinite = (a: any): a is number => {
147-
return Number.isFinite(a)
148-
}
147+
return Number.isFinite(a);
148+
};
149149

150150
export { Deferred, createDeferred } from './deferred';

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"url": "https://github.com/dealmore/sammy.git"
99
},
1010
"scripts": {
11-
"build": "tsc"
11+
"build": "tsc",
12+
"prettier": "prettier --write ."
1213
},
1314
"dependencies": {
1415
"aws-sdk": "^2.771.0",
@@ -25,6 +26,7 @@
2526
"@types/node-fetch": "^2.5.8",
2627
"@types/tmp": "^0.2.0",
2728
"@types/unzipper": "^0.10.3",
29+
"prettier": "^2.2.1",
2830
"typescript": "^4.1.3"
2931
},
3032
"files": [

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ path-is-absolute@^1.0.0:
384384
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
385385
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
386386

387+
prettier@^2.2.1:
388+
version "2.2.1"
389+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
390+
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
391+
387392
process-nextick-args@~2.0.0:
388393
version "2.0.1"
389394
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"

0 commit comments

Comments
 (0)