This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
manifest.ts
78 lines (69 loc) · 1.62 KB
/
manifest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { promises as fs } from 'fs'
import { resolve } from 'path'
import { arch, platform } from 'process'
import type { InvocationMode } from './function.js'
import type { FunctionResult } from './utils/format_result.js'
import type { Route } from './utils/routes.js'
interface ManifestFunction {
invocationMode?: InvocationMode
mainFile: string
name: string
path: string
routes?: Route[]
runtime: string
runtimeVersion?: string
schedule?: string
displayName?: string
bundler?: string
generator?: string
}
export interface Manifest {
functions: ManifestFunction[]
system: {
arch: string
platform: string
}
timestamp: number
version: number
}
const MANIFEST_VERSION = 1
export const createManifest = async ({ functions, path }: { functions: FunctionResult[]; path: string }) => {
const formattedFunctions = functions.map((func) => formatFunctionForManifest(func))
const payload: Manifest = {
functions: formattedFunctions,
system: { arch, platform },
timestamp: Date.now(),
version: MANIFEST_VERSION,
}
await fs.writeFile(path, JSON.stringify(payload))
}
const formatFunctionForManifest = ({
bundler,
displayName,
generator,
invocationMode,
mainFile,
name,
path,
routes,
runtime,
runtimeVersion,
schedule,
}: FunctionResult): ManifestFunction => {
const manifestFunction: ManifestFunction = {
bundler,
displayName,
generator,
invocationMode,
mainFile,
name,
runtimeVersion,
path: resolve(path),
runtime,
schedule,
}
if (routes?.length !== 0) {
manifestFunction.routes = routes
}
return manifestFunction
}