mirror of
https://github.com/LukeHagar/sveltesociety.dev.git
synced 2025-12-06 12:47:44 +00:00
feat: Add zod schemas for CI validation (#479)
* Add zod schemas for CI validation * Stricter Zod validation
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"test": "vitest",
|
"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}",
|
"format": "prettier --write ./**/*.{js,ts,css,md,svelte,html,json}",
|
||||||
"prepare": "husky install"
|
"prepare": "husky install"
|
||||||
},
|
},
|
||||||
@@ -42,7 +42,8 @@
|
|||||||
"typescript": "^5.1.6",
|
"typescript": "^5.1.6",
|
||||||
"undici": "^5.22.1",
|
"undici": "^5.22.1",
|
||||||
"vite": "^4.4.2",
|
"vite": "^4.4.2",
|
||||||
"vitest": "^0.33.0"
|
"vitest": "^0.33.0",
|
||||||
|
"zod": "^3.21.4"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{js,ts,css,md,svx,svelte,html,json}": "prettier --write"
|
"*.{js,ts,css,md,svx,svelte,html,json}": "prettier --write"
|
||||||
|
|||||||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@@ -89,6 +89,9 @@ devDependencies:
|
|||||||
vitest:
|
vitest:
|
||||||
specifier: ^0.33.0
|
specifier: ^0.33.0
|
||||||
version: 0.33.0
|
version: 0.33.0
|
||||||
|
zod:
|
||||||
|
specifier: ^3.21.4
|
||||||
|
version: 3.21.4
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
@@ -3052,3 +3055,7 @@ packages:
|
|||||||
resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==}
|
resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==}
|
||||||
engines: {node: '>=12.20'}
|
engines: {node: '>=12.20'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/zod@3.21.4:
|
||||||
|
resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==}
|
||||||
|
dev: true
|
||||||
|
|||||||
15
scripts/validateData.js
Normal file
15
scripts/validateData.js
Normal file
@@ -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');
|
||||||
65
src/lib/schemas.js
Normal file
65
src/lib/schemas.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const componentsSchema = z.array(
|
||||||
|
z.object({
|
||||||
|
title: z.string(),
|
||||||
|
npm: z
|
||||||
|
.string()
|
||||||
|
.regex(/(@[\w-]+\/)?[\w-]+/)
|
||||||
|
.optional(),
|
||||||
|
url: z.string().url().optional(),
|
||||||
|
repository: z.string().url(),
|
||||||
|
description: z.string(),
|
||||||
|
category: z.enum([
|
||||||
|
'Display Components',
|
||||||
|
'Developer Experience',
|
||||||
|
'Internationalization',
|
||||||
|
'CSS and Layout',
|
||||||
|
'Icons',
|
||||||
|
'Multimedia',
|
||||||
|
'Testing',
|
||||||
|
'Data Visualisation',
|
||||||
|
'Integration',
|
||||||
|
'Design Pattern',
|
||||||
|
'Stores',
|
||||||
|
'Routers',
|
||||||
|
'SvelteKit Adapters',
|
||||||
|
'Design System',
|
||||||
|
'User Interaction',
|
||||||
|
'Forms & User Input'
|
||||||
|
]),
|
||||||
|
tags: z.array(z.string()).optional()
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
export const templatesSchema = z.array(
|
||||||
|
z.object({
|
||||||
|
title: z.string(),
|
||||||
|
url: z.string().url().optional(),
|
||||||
|
repository: z.string().url(),
|
||||||
|
description: z.string(),
|
||||||
|
category: z.enum(['Svelte Add', 'SvelteKit', 'Svelte']),
|
||||||
|
tags: z.array(z.string()).optional()
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
export const toolsSchema = z.array(
|
||||||
|
z.object({
|
||||||
|
title: z.string(),
|
||||||
|
npm: z
|
||||||
|
.string()
|
||||||
|
.regex(/(@[\w-]+\/)?[\w-]+/)
|
||||||
|
.optional(),
|
||||||
|
url: z.string().url().optional(),
|
||||||
|
repository: z.string().url(),
|
||||||
|
description: z.string(),
|
||||||
|
category: z.enum([
|
||||||
|
'Debugging',
|
||||||
|
'Linting and Formatting',
|
||||||
|
'Editor Extensions',
|
||||||
|
'Bundler Plugins',
|
||||||
|
'Preprocessors'
|
||||||
|
]),
|
||||||
|
tags: z.array(z.string()).optional()
|
||||||
|
})
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user