Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

feat: add Manifest type #770

Merged
merged 11 commits into from
Oct 26, 2021
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface FunctionConfig {
nodeVersion?: NodeVersion
processDynamicNodeImports?: boolean
rustTargetDirectory?: string
schedule?: string
}

type GlobPattern = string
Expand Down
24 changes: 22 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,29 @@ import { arch, platform } from 'process'
import { FunctionResult } from './utils/format_result'
import { writeFile } from './utils/fs'

interface ManifestFunction {
mainFile: string
name: string
path: string
runtime: string
schedule?: string
}

interface Manifest {
functions: ManifestFunction[]
system: {
arch: string
platform: string
}
timestamp: number
version: number
}

const MANIFEST_VERSION = 1

const createManifest = async ({ functions, path }: { functions: FunctionResult[]; path: string }) => {
const formattedFunctions = functions.map(formatFunctionForManifest)
const payload = {
const payload: Manifest = {
functions: formattedFunctions,
system: { arch, platform },
timestamp: Date.now(),
Expand All @@ -18,11 +36,13 @@ const createManifest = async ({ functions, path }: { functions: FunctionResult[]
await writeFile(path, JSON.stringify(payload))
}

const formatFunctionForManifest = ({ mainFile, name, path, runtime }: FunctionResult) => ({
const formatFunctionForManifest = ({ config, mainFile, name, path, runtime }: FunctionResult): ManifestFunction => ({
mainFile,
name,
path: resolve(path),
runtime,
schedule: config.schedule,
})

export { createManifest }
export type { Manifest }
10 changes: 9 additions & 1 deletion tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,14 @@ test('Creates a manifest file with the list of created functions if the `manifes
const manifestPath = join(tmpDir, 'manifest.json')
const { files } = await zipNode(t, 'many-functions', {
length: FUNCTIONS_COUNT,
opts: { manifest: manifestPath },
opts: {
manifest: manifestPath,
config: {
five: {
schedule: '@daily',
},
},
},
})

const manifest = require(manifestPath)
Expand All @@ -2171,6 +2178,7 @@ test('Creates a manifest file with the list of created functions if the `manifes
t.is(fn.name, file.name)
t.is(fn.runtime, file.runtime)
t.is(fn.path, file.path)
t.is(fn.schedule, fn.name === 'five' ? '@daily' : undefined)
})
})

Expand Down