Skip to content

Commit

Permalink
feat: allow display name in manifest (#140)
Browse files Browse the repository at this point in the history
* feat: allow display name in manifest

* chore: change displayName to name

* chore: add test
  • Loading branch information
danez committed Oct 3, 2022
1 parent a69aeba commit 0fc04e9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
9 changes: 6 additions & 3 deletions node/declaration.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { FunctionConfig } from './config.js'

interface DeclarationWithPath {
interface BaseDeclaration {
function: string
name?: string
}

type DeclarationWithPath = BaseDeclaration & {
path: string
}

interface DeclarationWithPattern {
function: string
type DeclarationWithPattern = BaseDeclaration & {
pattern: string
}

Expand Down
20 changes: 20 additions & 0 deletions node/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ test('Generates a manifest with different bundles', () => {
expect(manifest.bundler_version).toBe(env.npm_package_version as string)
})

test('Generates a manifest with display names', () => {
const functions = [
{ name: 'func-1', path: '/path/to/func-1.ts' },
{ name: 'func-2', path: '/path/to/func-2.ts' },
]
const declarations = [
{ function: 'func-1', name: 'Display Name', path: '/f1/*' },
{ function: 'func-2', path: '/f2/*' },
]
const manifest = generateManifest({ bundles: [], declarations, functions })

const expectedRoutes = [
{ function: 'func-1', name: 'Display Name', pattern: '^/f1/.*/?$' },
{ function: 'func-2', pattern: '^/f2/.*/?$' },
]

expect(manifest.routes).toEqual(expectedRoutes)
expect(manifest.bundler_version).toBe(env.npm_package_version as string)
})

test('Excludes functions for which there are function files but no matching config declarations', () => {
const bundle1 = {
extension: '.ext2',
Expand Down
3 changes: 2 additions & 1 deletion node/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Manifest {
// eslint-disable-next-line camelcase
bundler_version: string
bundles: { asset: string; format: string }[]
routes: { function: string; pattern: string }[]
routes: { function: string; name?: string; pattern: string }[]
}

const generateManifest = ({ bundles = [], declarations = [], functions }: GenerateManifestOptions) => {
Expand All @@ -35,6 +35,7 @@ const generateManifest = ({ bundles = [], declarations = [], functions }: Genera

return {
function: func.name,
name: declaration.name,
pattern: serializablePattern,
}
})
Expand Down

0 comments on commit 0fc04e9

Please sign in to comment.