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
23 changes: 21 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,7 +36,7 @@ const createManifest = async ({ functions, path }: { functions: FunctionResult[]
await writeFile(path, JSON.stringify(payload))
}

const formatFunctionForManifest = ({ config, mainFile, name, path, runtime }: FunctionResult) => ({
const formatFunctionForManifest = ({ config, mainFile, name, path, runtime }: FunctionResult): ManifestFunction => ({
mainFile,
name,
path: resolve(path),
Expand All @@ -27,3 +45,4 @@ const formatFunctionForManifest = ({ config, mainFile, name, path, runtime }: Fu
})

export { createManifest }
export type { Manifest }