-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-typings.pluto
36 lines (31 loc) · 1.12 KB
/
validate-typings.pluto
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
-- Prerequisites: npm i && npm i -g ts-to-zod ts-node
local types = io.contents("index.d.ts").."\nexport interface IPublicExportPlus {";
for line in io.lines("index.d.ts") do
if line:sub(1, 20) == "export declare const" then
types = types .. "\n" .. line:sub(22)
end
end
print("🕐 Generating schemas...")
io.contents("tmp-types.ts", types)
os.execute("ts-to-zod tmp-types.ts tmp-schemas.ts --skipValidation")
io.contents("tmp-schemas.ts", io.contents("tmp-schemas.ts")
:replace("z.object", "z.strictObject")
:replace("iAbilitySchema = z.strictObject({", "iAbilitySchema = z.object({")
)
print("🕐 Validating schemas...")
io.contents("tmp-test.ts", [[
import { z } from "zod";
import { iPublicExportPlusSchema } from "./tmp-schemas";
import publicExportPlus from "./index";
try {
iPublicExportPlusSchema.parse(publicExportPlus);
console.log("✅ Schemas validated successfully.");
}
catch (e) {
console.log((e as Error).message);
}
]])
os.execute([[ts-node -O {\"module\":\"commonjs\"} tmp-test.ts]])
os.remove("tmp-schemas.ts")
os.remove("tmp-types.ts")
os.remove("tmp-test.ts")