Skip to content

Commit 43befab

Browse files
Add standard linter
1 parent eb4f1de commit 43befab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+200
-215
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ language: node_js
22
node_js:
33
- stable
44
install:
5-
- npm install -g ava
65
- npm install
76

87
script:
8+
- npm run lint
99
- npm run test

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"description": "A framework for building JavaScript APIs with AWS API Gateway and Lambda",
55
"main": "lib/index.js",
66
"scripts": {
7-
"compile": "./node_modules/.bin/babel -d lib/ src/",
7+
"compile": "babel -d lib/ src/",
88
"test": "ava",
9-
"lint": "jshint --exclude ./node_modules .",
9+
"lint": "standard",
1010
"prepublish": "npm run compile"
1111
},
1212
"keywords": [
@@ -53,6 +53,7 @@
5353
"babel-plugin-add-module-exports": "^0.2.1",
5454
"babel-preset-es2015-node4": "^2.1.0",
5555
"babel-register": "^6.7.2",
56+
"standard": "^8.3.0",
5657
"testdouble": "^1.6.1"
5758
},
5859
"babel": {

src/build/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import listr from '../util/modules/listr'
22
import build from '../util/build-functions'
33

4-
export default function(opts) {
5-
4+
export default function (opts) {
65
const functions = opts.functions || '*'
76
const env = opts.env || 'development'
87

@@ -14,5 +13,4 @@ export default function(opts) {
1413
], opts.quiet)
1514

1615
return tasks.run()
17-
1816
}

src/commands/build.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import merge from 'lodash.merge'
55

66
export const command = 'build [env] [functions]'
77
export const desc = 'Builds functions and writes them to disk'
8-
export function builder (yargs){
8+
export function builder (yargs) {
99
return yargs
1010
.example('shep build', 'Launch an interactive CLI')
1111
.example('shep build beta', 'Build all functions with beta environment variables')
1212
.example('shep build beta create-user', 'Build only the create-user function')
1313
.example('shep build beta *-user', 'Build functions matching the pattern *-user')
1414
}
1515

16-
export function handler(opts) {
16+
export function handler (opts) {
1717
const questions = [
1818
{
1919
name: 'env',
@@ -23,7 +23,7 @@ export function handler(opts) {
2323
}
2424
]
2525

26-
inquirer.prompt(questions.filter((q)=> !opts[q.name] ))
27-
.then((inputs) => merge({}, inputs, opts) )
26+
inquirer.prompt(questions.filter((q) => !opts[q.name]))
27+
.then((inputs) => merge({}, inputs, opts))
2828
.then(build)
2929
}

src/commands/deploy.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import merge from 'lodash.merge'
55

66
export const command = 'deploy [env] [functions]'
77
export const desc = 'Deploy both functions and APIs to AWS. Will create a new API if the ID is not specified'
8-
export function builder (yargs){
8+
export function builder (yargs) {
99
return yargs
1010
.pkgConf('shep', process.cwd())
1111
.describe('build', 'Build functions before deployment. Use --no-build to skip this step')
@@ -17,7 +17,7 @@ export function builder (yargs){
1717
.example('shep deploy beta *-user', 'Deploy only functions matching the pattern *-user')
1818
}
1919

20-
export function handler(opts) {
20+
export function handler (opts) {
2121
const questions = [
2222
{
2323
name: 'env',
@@ -27,7 +27,7 @@ export function handler(opts) {
2727
}
2828
]
2929

30-
inquirer.prompt(questions.filter((q)=> !opts[q.name] ))
31-
.then((inputs) => merge({}, inputs, opts) )
30+
inquirer.prompt(questions.filter((q) => !opts[q.name]))
31+
.then((inputs) => merge({}, inputs, opts))
3232
.then(deploy)
3333
}

src/commands/generate.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import inquirer from 'inquirer'
2-
31
export const command = 'generate'
42
export const desc = 'Run `shep generate --help` for additional information'
5-
export function builder (yargs){
3+
export function builder (yargs) {
64
return yargs
75
.commandDir('./generate')
86
}

src/commands/generate/endpoint.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import inquirer from 'inquirer'
22
import generateEndpoint from '../../generate-endpoint'
33
import merge from 'lodash.merge'
44

5-
const httpMethods = ['get','post','put','delete','options','any']
5+
const httpMethods = ['get', 'post', 'put', 'delete', 'options', 'any']
66

77
export const command = 'endpoint [path]'
88
export const desc = 'Generate a new API endpoint'
9-
export function builder (yargs){
9+
export function builder (yargs) {
1010
return yargs
1111
.pkgConf('shep', process.cwd())
1212
.describe('method', 'HTTP Method')
1313
.choices('method', httpMethods)
1414
}
1515

16-
export function handler(opts) {
16+
export function handler (opts) {
1717
inquirer.prompt([
1818
{
1919
name: 'path',

src/commands/generate/function.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ const questions = [
66
{
77
name: 'name',
88
type: 'input',
9-
message: 'Function name',
9+
message: 'Function name'
1010
}
1111
]
1212

1313
export const command = 'function [name]'
1414
export const desc = 'Generate a new function'
15-
export function builder (yargs){
15+
export function builder (yargs) {
1616
return yargs
1717
.pkgConf('shep', process.cwd())
1818
.describe('name', 'Function name')
1919
.example('shep generate function', 'Launch an interactive CLI')
2020
.example('shep generate function foo', 'Genereate a new functon called "foo"')
2121
}
2222

23-
export function handler(opts) {
24-
inquirer.prompt(questions.filter((q)=> !opts[q.name] ))
25-
.then((inputs) => merge({}, inputs, opts) )
23+
export function handler (opts) {
24+
inquirer.prompt(questions.filter((q) => !opts[q.name]))
25+
.then((inputs) => merge({}, inputs, opts))
2626
.then(generateFunction)
2727
}

src/commands/new.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ const questions = [
1313

1414
export const command = 'new [path]'
1515
export const desc = 'Create a new shep project'
16-
export function builder (yargs){
16+
export function builder (yargs) {
1717
return yargs
1818
.describe('path', 'Location to create the new shep project')
1919
.example('shep new', 'Launch an interactive CLI')
2020
.example('shep new my-api', 'Generates a project at `my-api`')
2121
}
2222

2323
export function handler (opts) {
24-
inquirer.prompt(questions.filter((q)=> !opts[q.name] ))
25-
.then((inputs) => merge({}, inputs, opts) )
24+
inquirer.prompt(questions.filter((q) => !opts[q.name]))
25+
.then((inputs) => merge({}, inputs, opts))
2626
.then(_new)
2727
}

src/commands/pull.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const command = 'pull'
22
export const desc = 'Pulls a swagger JSON representation of an existing API and writes it to a local file'
3-
export function builder (yargs){
3+
export function builder (yargs) {
44
return yargs
55
.pkgConf('shep', process.cwd())
66
.describe('region', 'AWS region')
@@ -20,5 +20,4 @@ export function builder (yargs){
2020
.example('shep pull --output other-path.json', 'Writes the JSON swagger file to `other-path.json`')
2121
}
2222

23-
2423
export { default as handler } from '../pull'

src/commands/push.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const command = 'push'
22
export const desc = 'Create a new shep project'
3-
export function builder(yargs){
3+
export function builder (yargs) {
44
return yargs
55
.pkgConf('shep', process.cwd())
66
.describe('api-id', 'API Gateway resource id. Read from package.json if not provided')

src/commands/run.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import merge from 'lodash.merge'
55

66
export const command = 'run [name]'
77
export const desc = 'Run a function in your local environemnt'
8-
export function builder (yargs){
8+
export function builder (yargs) {
99
return yargs
1010
.pkgConf('shep', process.cwd())
1111
.describe('environment', 'Environment variables to use')
@@ -20,7 +20,7 @@ export function builder (yargs){
2020
.example('shep run foo --environment production', 'Runs the `foo` function with production environment')
2121
}
2222

23-
export function handler(opts) {
23+
export function handler (opts) {
2424
const questions = [
2525
{
2626
name: 'name',
@@ -30,7 +30,7 @@ export function handler(opts) {
3030
}
3131
]
3232

33-
inquirer.prompt(questions.filter((q)=> !opts[q.name] ))
34-
.then((inputs) => merge({}, inputs, opts) )
33+
inquirer.prompt(questions.filter((q) => !opts[q.name]))
34+
.then((inputs) => merge({}, inputs, opts))
3535
.then(run)
3636
}

src/deploy/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import push from '../util/push-api'
88
import AWS from 'aws-sdk'
99
import listr from '../util/modules/listr'
1010

11-
export default function(opts){
11+
export default function (opts) {
1212
const functions = opts.functions || '*'
1313
const env = opts.env || 'development'
1414
const region = opts.region
@@ -17,7 +17,7 @@ export default function(opts){
1717

1818
let apiId, uploadedFuncs
1919

20-
if (opts.apiId){ apiId = opts.apiId }
20+
if (opts.apiId) { apiId = opts.apiId }
2121

2222
AWS.config.update({region})
2323

@@ -26,22 +26,22 @@ export default function(opts){
2626
title: `Build Functions`,
2727
task: () => build(functions, env),
2828
skip: () => {
29-
if (performBuild === false){
29+
if (performBuild === false) {
3030
return 'Called with --no-build'
3131
}
3232
}
3333
},
3434
{
3535
title: 'Upload Functions to AWS',
36-
task: () => upload(functions).tap((funcs) => uploadedFuncs = funcs)
36+
task: () => upload(functions).tap((funcs) => { uploadedFuncs = funcs })
3737
}
3838
], opts.quiet)
3939

40-
if (api){
40+
if (api) {
4141
tasks.add([
4242
{
4343
title: 'Upload API.json',
44-
task: () => push(api, apiId, region).tap((id) => apiId = id)
44+
task: () => push(api, apiId, region).tap((id) => { apiId = id })
4545
}
4646
])
4747
}
@@ -53,7 +53,7 @@ export default function(opts){
5353
}
5454
])
5555

56-
if (api){
56+
if (api) {
5757
tasks.add([
5858
{
5959
title: 'Setup Lambda Permissions',

src/generate-endpoint/index.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import * as load from '../util/load'
77

88
const integration = 'x-amazon-apigateway-integration'
99

10-
module.exports = function(opts){
10+
module.exports = function (opts) {
1111
let accountId = opts.accountId
1212
let path = opts.path
1313
let method = opts.method
1414

15-
if (!accountId){
15+
if (!accountId) {
1616
throw new Error('Unable to determine your AWS Account ID. Please set it in the `shep` section of package.json')
1717
}
1818

@@ -43,21 +43,20 @@ module.exports = function(opts){
4343
return tasks.run()
4444
}
4545

46-
47-
function addPath(api, path, method, accountId, functionName){
46+
function addPath (api, path, method, accountId, functionName) {
4847
if (method === 'any') { method = 'x-amazon-apigateway-any-method' }
4948

5049
api.paths[path] = api.paths[path] || {}
51-
if (api.paths[path][method] !== undefined){ throw new Error(`Method '${method}' on path '${path}' already exists`)}
50+
if (api.paths[path][method] !== undefined) { throw new Error(`Method '${method}' on path '${path}' already exists`) }
5251
api.paths[path][method] = api.paths[path][method] || {}
5352
api.paths[path][method][integration] = {
54-
uri : `arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:${accountId}:function:${functionName}:\${stageVariables.functionAlias}/invocations`,
55-
passthroughBehavior: "when_no_match",
56-
httpMethod: "POST",
57-
type: "aws_proxy"
53+
uri: `arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:${accountId}:function:${functionName}:\${stageVariables.functionAlias}/invocations`,
54+
passthroughBehavior: 'when_no_match',
55+
httpMethod: 'POST',
56+
type: 'aws_proxy'
5857
}
5958
}
6059

61-
function setupCORS(api, path){
60+
function setupCORS (api, path) {
6261
api.paths[path].options = api.paths[path].options || cors
6362
}

src/generate-endpoint/templates.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
export const cors = {
2-
"responses": {
3-
"200": {
4-
"description": "200 response",
5-
"headers": {
6-
"Access-Control-Allow-Origin": {
7-
"type": "string"
2+
'responses': {
3+
'200': {
4+
'description': '200 response',
5+
'headers': {
6+
'Access-Control-Allow-Origin': {
7+
'type': 'string'
88
},
9-
"Access-Control-Allow-Methods": {
10-
"type": "string"
9+
'Access-Control-Allow-Methods': {
10+
'type': 'string'
1111
},
12-
"Access-Control-Allow-Headers": {
13-
"type": "string"
12+
'Access-Control-Allow-Headers': {
13+
'type': 'string'
1414
}
1515
}
1616
}
1717
},
18-
"x-amazon-apigateway-integration": {
19-
"responses": {
20-
"default": {
21-
"statusCode": "200",
22-
"responseParameters": {
23-
"method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'",
24-
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'",
25-
"method.response.header.Access-Control-Allow-Origin": "'*'"
18+
'x-amazon-apigateway-integration': {
19+
'responses': {
20+
'default': {
21+
'statusCode': '200',
22+
'responseParameters': {
23+
'method.response.header.Access-Control-Allow-Methods': "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'",
24+
'method.response.header.Access-Control-Allow-Headers': "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'",
25+
'method.response.header.Access-Control-Allow-Origin': "'*'"
2626
}
2727
}
2828
},
29-
"requestTemplates": {
30-
"application/json": "{\"statusCode\": 200}"
29+
'requestTemplates': {
30+
'application/json': '{"statusCode": 200}'
3131
},
32-
"passthroughBehavior": "when_no_match",
33-
"type": "mock"
32+
'passthroughBehavior': 'when_no_match',
33+
'type': 'mock'
3434
}
3535
}

0 commit comments

Comments
 (0)