Skip to content

Commit 6254e55

Browse files
committed
feat: added test script and validation
1 parent c33f6c9 commit 6254e55

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"main": "index.js",
66
"type": "module",
77
"scripts": {
8-
"test": "echo \"Error: no test specified\" && exit 1",
8+
"lint:biome": "biome lint .",
9+
"lint:biome:format": "biome format .",
10+
"validate": "tsx scripts/validate-books.ts",
11+
"test": "pnpm run lint:biome && pnpm run lint:biome:format && pnpm run validate",
912
"build": "rm -rf dist && tsx scripts/build.ts"
1013
},
1114
"keywords": [],
@@ -16,6 +19,7 @@
1619
"@biomejs/biome": "1.6.1",
1720
"@types/node": "^20.11.28",
1821
"@types/turndown": "^5.0.4",
22+
"ajv": "^8.12.0",
1923
"cheerio": "1.0.0-rc.12",
2024
"marked": "^12.0.1",
2125
"mkdirp": "^3.0.1",

pnpm-lock.yaml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { cp, readFile, writeFile } from 'node:fs/promises'
22
import { dirname, join } from 'node:path'
3-
import { fileURLToPath } from 'node:url'
4-
// biome-ignore lint/nursery/noUndeclaredDependencies: <explanation>
53
import { marked } from 'marked'
64
import { mkdirp } from 'mkdirp'
75
import slugify from 'slugify'
@@ -12,7 +10,7 @@ const REPO_URL = 'https://github.com/FullStackBulletin/fullstack-books'
1210
const GH_PAGES_URL = 'https://fullStackbulletin.github.io/fullstack-books'
1311
const baseUrl = process.env.BASE_URL ?? GH_PAGES_URL
1412

15-
const __dirname = dirname(fileURLToPath(import.meta.url))
13+
const __dirname = dirname(new URL(import.meta.url).pathname)
1614
const destPath = join(__dirname, '..', 'dist')
1715
const booksPath = join(__dirname, '..', 'dist', 'books')
1816
const authorsPath = join(__dirname, '..', 'dist', 'authors')

scripts/validate-books.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { readFile } from 'node:fs/promises'
2+
import { dirname, join } from 'node:path'
3+
import Ajv from 'ajv'
4+
import { parse } from 'yaml'
5+
6+
const __dirname = dirname(new URL(import.meta.url).pathname)
7+
const sourcePath = join(__dirname, '..', 'src', 'books.yml')
8+
const schemaPath = join(__dirname, '..', 'src', 'raw-books.schema.json')
9+
const data = parse(await readFile(sourcePath, 'utf-8'))
10+
const schema = parse(await readFile(schemaPath, 'utf-8'))
11+
12+
const ajv = new Ajv.default()
13+
14+
if (!ajv.validate(schema, data)) {
15+
console.error(ajv.errors)
16+
process.exit(1)
17+
}

src/raw-books.schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"subtitle": {
1616
"type": "string"
1717
},
18+
"cover": {
19+
"type": "string"
20+
},
1821
"edition": {
1922
"type": "number"
2023
},
@@ -45,6 +48,7 @@
4548
"type": "string"
4649
}
4750
},
48-
"required": ["title", "authors", "links", "description"]
51+
"required": ["title", "authors", "links", "description"],
52+
"additionalProperties": false
4953
}
5054
}

0 commit comments

Comments
 (0)