-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathneon.ts
More file actions
16 lines (14 loc) · 580 Bytes
/
neon.ts
File metadata and controls
16 lines (14 loc) · 580 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { readFile } from "fs/promises";
import { load } from "js-yaml";
import { join, resolve } from "path";
export function resolveNeon(contents: string, env: Record<string, string>) {
return contents.replace(/(?:%(\w+)%)/g, (_, name) => env[name] ?? "");
}
export async function parseNeonFile<T = unknown>(
path: string,
env: Record<string, string> = {}
): Promise<T> {
const contents = (await readFile(resolve(join(env.currentWorkingDirectory, path)))).toString();
const yaml = resolveNeon(contents.replace(/\t/g, " "), env);
return load(yaml) as Promise<T>;
}