Skip to content

Commit

Permalink
Add support for create plugin API; fixes #1410, thanks @pachoclo!
Browse files Browse the repository at this point in the history
Update deps and readme
  • Loading branch information
ryanblock committed Apr 10, 2023
1 parent a88a0be commit caf92df
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -4,3 +4,5 @@ coverage/
foo/
node_modules/
scratch/
test/mock/defaults/public/
test/mock/defaults/src/http/get-new/
13 changes: 13 additions & 0 deletions changelog.md
Expand Up @@ -2,6 +2,19 @@

---

## [1.2.0] 2023-04-10

### Added

- Added support for `create` plugin API; fixes #1410, thanks @pachoclo!


### Changed

- Updated dependencies

---

## [1.1.0] 2023-02-20

### Added
Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -21,18 +21,18 @@
"src/*"
],
"dependencies": {
"@types/aws-lambda": "^8.10.110",
"esbuild": "^0.17.10",
"@types/aws-lambda": "^8.10.114",
"esbuild": "^0.17.16",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@architect/architect": "^10.10.2",
"@architect/architect": "^10.12.0-RC.1",
"@architect/eslint-config": "^2.1.1",
"cross-env": "^7.0.3",
"eslint": "^8.34.0",
"eslint": "^8.38.0",
"tap-arc": "^0.3.5",
"tape": "^5.6.3",
"tiny-json-http": "^7.4.2"
"tiny-json-http": "^7.5.1"
},
"eslintConfig": {
"extends": "@architect/eslint-config"
Expand Down
15 changes: 5 additions & 10 deletions readme.md
Expand Up @@ -45,18 +45,13 @@ Now, simply author and port Lambdas in the `src` tree with `index.ts` handlers.

```ts
// src/http/get-index/index.ts
import { Context, APIGatewayProxyResult, APIGatewayEvent } from 'aws-lambda';
import { Context, APIGatewayProxyResult, APIGatewayEvent } from 'aws-lambda'

export const handler = async (event: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> => {
console.log(`Event: ${JSON.stringify(event, null, 2)}`);
console.log(`Context: ${JSON.stringify(context, null, 2)}`);
return {
statusCode: 200,
body: JSON.stringify({
message: 'hello world',
}),
};
};
console.log(`Event:`, event)
console.log(`Context:`, context)
return { message: 'hello world' }
}
```

The above function will be automatically transpiled by Architect to `./.build/http/get-index.js`. (The destination build directory is configurable, [see below](#configuration).)
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Expand Up @@ -4,6 +4,14 @@ let {
getTsConfig,
} = require('./_compile')

let body = `import { Context, APIGatewayProxyResult, APIGatewayEvent } from 'aws-lambda'
export const handler = async (event: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> => {
console.log('Event:', event)
console.log('Context:', context)
return { message: 'Hello world!' }
}`

module.exports = {
set: {
runtimes: function ({ inventory }) {
Expand All @@ -27,6 +35,9 @@ module.exports = {
}
}
},
create: {
handlers: () => ({ filename: 'index.ts', body })
},
deploy: {
// TODO: add support for custom TS check commands (e.g. `tsc -p .`)?
start: compileProject
Expand Down
10 changes: 9 additions & 1 deletion test/integration/project-test.js
Expand Up @@ -6,11 +6,12 @@ let sandbox = require('@architect/sandbox')

let port = 6666
let mock = join(process.cwd(), 'test', 'mock')
let cwd, build
let cwd, build, newHandler
let url = path => `http://localhost:${port}/${path}`
let banner = /lolidk/

function reset () {
rmSync(newHandler, { recursive: true, force: true })
rmSync(build, { recursive: true, force: true })
}

Expand All @@ -21,6 +22,7 @@ function reset () {
test('Start Sandbox (default project)', async t => {
t.plan(1)
cwd = join(mock, 'defaults')
newHandler = join(cwd, 'src', 'http', 'get-new')
build = join(cwd, '.build')
reset()
await sandbox.start({ cwd, port, quiet: true })
Expand Down Expand Up @@ -59,6 +61,12 @@ test('Sourcemap support', async t => {
}
})

test('Handler created', async t => {
t.plan(1)
let result = await get({ url: url('new') })
t.deepEqual(result.body, { message: 'Hello world!' }, 'Freshly created and transpiled handler returned correct body')
})

test('Shut down Sandbox', async t => {
t.plan(1)
await sandbox.end()
Expand Down
1 change: 1 addition & 0 deletions test/mock/defaults/app.arc
Expand Up @@ -7,6 +7,7 @@ runtime typescript
@http
get /ok
get /fail
get /new

@plugins
architect/plugin-typescript
Expand Down
2 changes: 2 additions & 0 deletions test/mock/defaults/prefs.arc
@@ -0,0 +1,2 @@
@create
autocreate true

0 comments on commit caf92df

Please sign in to comment.