Skip to content

Commit

Permalink
Add zod schemas for CI validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlancollins committed Nov 5, 2023
1 parent f08577a commit 9fff772
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"test": "vitest",
"lint": "prettier --check ./**/*.{js,ts,css,md,svelte,html,json} && eslint --ignore-path .gitignore .",
"lint": "prettier --check ./**/*.{js,ts,css,md,svelte,html,json} && eslint --ignore-path .gitignore . && node scripts/validateData.js",
"format": "prettier --write ./**/*.{js,ts,css,md,svelte,html,json}",
"prepare": "husky install"
},
Expand Down Expand Up @@ -42,7 +42,8 @@
"typescript": "^5.1.6",
"undici": "^5.22.1",
"vite": "^4.4.2",
"vitest": "^0.33.0"
"vitest": "^0.33.0",
"zod": "^3.21.4"
},
"lint-staged": {
"*.{js,ts,css,md,svx,svelte,html,json}": "prettier --write"
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions scripts/validateData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-check

import { componentsSchema, templatesSchema, toolsSchema } from '../src/lib/schemas.js';
import components from '../src/routes/components/components.json' assert { type: 'json' };
import templates from '../src/routes/templates/templates.json' assert { type: 'json' };
import tools from '../src/routes/tools/tools.json' assert { type: 'json' };

componentsSchema.parse(components);
console.log('Validated components.json');

templatesSchema.parse(templates);
console.log('Validated templates.json');

toolsSchema.parse(tools);
console.log('Validated tools.json');
33 changes: 33 additions & 0 deletions src/lib/schemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { z } from 'zod';

export const componentsSchema = z.array(
z.object({
title: z.string(),
url: z.string().optional(),
repository: z.string(),
description: z.string(),
npm: z.string().optional(),
category: z.string(),
tags: z.array(z.string()).optional()
})
);

export const templatesSchema = z.array(
z.object({
title: z.string(),
repository: z.string(),
description: z.string(),
category: z.string(),
tags: z.array(z.string()).optional()
})
);

export const toolsSchema = z.array(
z.object({
title: z.string(),
repository: z.string(),
description: z.string(),
category: z.string(),
tags: z.array(z.string()).optional()
})
);

0 comments on commit 9fff772

Please sign in to comment.