Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shep list & shep serve implementation #308

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ Commands:
deploy Deploy functions and APIs to AWS. Will create a new API if the ID is not specified
doctor Checks your projects against best standards
generate Run `shep generate --help` for additional information
list Lists endpoints
logs [name] Streams logs from the specified version of a function
new [path] Create a new shep project
pull Pulls a swagger JSON representation of an existing API and writes it to a local file
push Create a new shep project
run [pattern] Run a function in your local environment
serve Start local server

Options:
--version Show version number [boolean]
Expand Down Expand Up @@ -184,6 +186,14 @@ Options:
Examples:
shep generate webpack -o foo.js Writes default webpack configuration to foo.js
```
#### `shep list`
```
shep list

Options:
--version Show version number [boolean]
--help Show help [boolean]
```
#### `shep logs`
```
shep logs [name]
Expand Down Expand Up @@ -273,3 +283,20 @@ Examples:
shep run '*' Runs all functions for all events
shep run 'foo-*' Runs all functions matching pattern `foo-*`
```
#### `shep serve`
```
shep serve

Options:
--version Show version number [boolean]
--help Show help [boolean]
--build Build functions before running. If omitted functions are transpiled by babel on the fly [default: false]
--verbose Show detailed logs [default: false]
--env Environment value [default: "development"]
--port Start local server on the given port [default: 3000]
-q, --quiet Don't log anything [default: false]

Examples:
shep serve Starts local server default port 3000
shep serve --port 4000 Starts local server on port 4000
```
63 changes: 39 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A framework for building JavaScript APIs with AWS API Gateway and Lambda",
"main": "lib/index.js",
"scripts": {
"dev": "babel -d lib/ src/ -w",
"compile": "babel -d lib/ src/",
"test": "mocha && ava",
"lint": "eslint ./",
Expand Down Expand Up @@ -40,6 +41,7 @@
"aws-sdk": "^2.4.13",
"bluebird": "^3.4.7",
"chalk": "^1.1.3",
"cli-table": "^0.3.1",
"cliui": "^3.2.0",
"debug": "^2.6.8",
"dotenv": "^4.0.0",
Expand All @@ -55,13 +57,15 @@
"loud-rejection": "^1.6.0",
"minimatch": "^3.0.3",
"ora": "^1.3.0",
"require-uncached": "^1.0.3",
"resolve": "^1.1.7",
"stream-buffers": "^3.0.0",
"yargs": "^6.0.1",
"zipit": "^1.0.2"
},
"devDependencies": {
"ava": "^0.18.1",
"babel": "^6.23.0",
"babel-cli": "^6.18.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-async-to-module-method": "^6.16.0",
Expand Down
4 changes: 2 additions & 2 deletions src/build/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import build from '../util/build-functions'

export default function ({ functions = '*', env = 'development' }) {
return build(functions, env)
export default function ({ functions = '*', env = 'development', quiet }) {
return build(functions, env, { quiet })
}
21 changes: 21 additions & 0 deletions src/commands/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Table from 'cli-table'
import list from '../list'

export const command = 'list'
export const desc = 'Lists endpoints'
// export function builder (yargs) {
// return yargs
// .describe('quiet', 'Don\'t log anything')
// .default('quiet', false)
// }

export async function handler (opts) {
const endpoints = await list(opts)
const table = new Table({
head: ['Path', 'Method', 'Lambda Function', 'Region']
})
endpoints.map(endpoint => {
table.push([endpoint.path, endpoint.method, endpoint.handler, endpoint.region])
})
console.log(table.toString())
}
24 changes: 24 additions & 0 deletions src/commands/serve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import serve from '../serve'

export const command = 'serve'
export const desc = 'Start local server'
export function builder (yargs) {
return yargs
.describe('quiet', 'Don\'t log anything')
.default('quiet', false)
.alias('q', 'quiet')
.describe('build', 'Build functions before running. If omitted functions are transpiled by babel on the fly')
.default('build', false)
.describe('verbose', 'Show detailed logs')
.default('verbose', false)
.describe('env', 'Environment value')
.default('env', 'development')
.describe('port', 'Start local server on the given port')
.default('port', 3000)
.example('shep serve', 'Starts local server default port 3000')
.example('shep serve --port 4000', 'Starts local server on port 4000')
}

export async function handler (opts) {
await serve(opts)
}
4 changes: 2 additions & 2 deletions src/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import setPermissions from '../util/set-permissions'
import * as load from '../util/load'
import push from '../util/push-api'

export default async function ({ apiId, api: deployApi = true, functions = '*', env = 'development', region, bucket, build = true, logger = () => {} }) {
export default async function ({ apiId, api: deployApi = true, functions = '*', env = 'development', region, bucket, build = true, logger = () => {}, quiet }) {
const api = await load.api()

let uploadFuncs, aliases

try {
if (build) {
logger({ type: 'start', body: `Build Functions` })
await buildFuncs(functions, env)
await buildFuncs(functions, env, { quiet })
} else {
logger({ type: 'skip', body: 'Called with --no-build' })
}
Expand Down
28 changes: 28 additions & 0 deletions src/list/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as load from '../util/load'
import parseApi from '../util/parse-api'

export default async function list (opts) {
const api = await load.api() || {}
let endpoints = parseApi(api)
endpoints = endpoints
.filter(endpoint => endpoint.method !== 'options')
.map(endpoint => ({
path: endpoint.path,
method: endpoint.method,
handler: getFunction(endpoint.integration.uri),
region: getRegion(endpoint.integration.uri)
}))
return endpoints
}

function getRegion (uri) {
// `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${region}:${accountId}:function:${functionName}:\${stageVariables.functionAlias}/invocations`
const uriParts = uri.split(':')
return uriParts[3]
}

function getFunction (uri) {
// `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${region}:${accountId}:function:${functionName}:\${stageVariables.functionAlias}/invocations`
const uriParts = uri.split(':')
return uriParts[11]
}
Loading