Scaffold monorepo dev setup
This commit is contained in:
commit
d2a09e095a
47 changed files with 1033 additions and 0 deletions
11
packages/config/package.json
Normal file
11
packages/config/package.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "@islandflow/config",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"zod": "^3.23.8"
|
||||
}
|
||||
}
|
||||
34
packages/config/src/env.ts
Normal file
34
packages/config/src/env.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { z } from "zod";
|
||||
|
||||
export class EnvError extends Error {
|
||||
readonly issues: z.ZodIssue[];
|
||||
|
||||
constructor(message: string, issues: z.ZodIssue[]) {
|
||||
super(message);
|
||||
this.name = "EnvError";
|
||||
this.issues = issues;
|
||||
}
|
||||
}
|
||||
|
||||
const formatIssues = (issues: z.ZodIssue[]): string => {
|
||||
return issues
|
||||
.map((issue) => {
|
||||
const path = issue.path.length > 0 ? issue.path.join(".") : "<root>";
|
||||
return `${path}: ${issue.message}`;
|
||||
})
|
||||
.join("; ");
|
||||
};
|
||||
|
||||
export const readEnv = <T extends z.ZodTypeAny>(
|
||||
schema: T,
|
||||
env: Record<string, string | undefined> = Bun.env
|
||||
): z.infer<T> => {
|
||||
const result = schema.safeParse(env);
|
||||
|
||||
if (!result.success) {
|
||||
const details = formatIssues(result.error.issues);
|
||||
throw new EnvError(`Invalid environment: ${details}`, result.error.issues);
|
||||
}
|
||||
|
||||
return result.data;
|
||||
};
|
||||
1
packages/config/src/index.ts
Normal file
1
packages/config/src/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./env";
|
||||
7
packages/config/tsconfig.json
Normal file
7
packages/config/tsconfig.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"types": []
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue