()
| 118 | } |
| 119 | |
| 120 | async function validateLayouts(): Promise<void> { |
| 121 | const problems = new Problems<Layout, "_additional">("Layouts", { |
| 122 | _additional: |
| 123 | "Layout files present but missing in packages/schemas/src/layouts.ts", |
| 124 | }); |
| 125 | |
| 126 | for (let layoutName of LayoutsList) { |
| 127 | let layoutData = undefined; |
| 128 | if (!fs.existsSync(`./static/layouts/${layoutName}.json`)) { |
| 129 | problems.add( |
| 130 | layoutName, |
| 131 | `missing json file frontend/static/layouts/${layoutName}.json`, |
| 132 | ); |
| 133 | continue; |
| 134 | } |
| 135 | try { |
| 136 | layoutData = JSON.parse( |
| 137 | fs.readFileSync(`./static/layouts/${layoutName}.json`, "utf-8"), |
| 138 | ) as LayoutObject; |
| 139 | } catch (e) { |
| 140 | problems.add( |
| 141 | layoutName, |
| 142 | `Unable to parse ${e instanceof Error ? e.message : e}`, |
| 143 | ); |
| 144 | continue; |
| 145 | } |
| 146 | |
| 147 | const validationResult = LayoutObjectSchema.safeParse(layoutData); |
| 148 | problems.addValidation(layoutName, validationResult); |
| 149 | } |
| 150 | |
| 151 | //no files not defined in LayoutsList |
| 152 | const additionalLayoutFiles = fs |
| 153 | .readdirSync("./static/layouts") |
| 154 | .filter((it) => !LayoutsList.some((layout) => `${layout}.json` === it)); |
| 155 | if (additionalLayoutFiles.length !== 0) { |
| 156 | additionalLayoutFiles.forEach((it) => problems.add("_additional", it)); |
| 157 | } |
| 158 | |
| 159 | console.log(problems.toString()); |
| 160 | |
| 161 | if (problems.hasError()) { |
| 162 | throw new Error("layouts with errors"); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | async function validateQuotes(): Promise<void> { |
| 167 | const problems = new Problems<string, never>("Quotes", {}); |
nothing calls this directly
no test coverage detected