-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-model-rules.ts
36 lines (34 loc) · 1.21 KB
/
check-model-rules.ts
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
import chalk from 'chalk'
import assert from 'node:assert/strict'
import { readFile, readdir, stat } from 'node:fs/promises'
import path from 'node:path'
import { ModelIDRegExp } from './types.js'
import { parseREADME } from 'markdown/parseREADME.js'
console.log(chalk.gray('Models rules check'))
console.log('')
const modelsDir = path.join(process.cwd(), 'models')
for (const model of await readdir(modelsDir)) {
const modelDir = path.join(modelsDir, model)
if (!(await stat(modelDir)).isDirectory()) continue
console.log(chalk.white('·'), chalk.white.bold(model))
assert.match(
model,
ModelIDRegExp,
'Model identifiers must consist of numbers, letters, dash, plus, and underscore only',
)
console.log(chalk.green('✔'), chalk.gray('Model name is correct'))
// A README.md should exist
try {
await stat(path.join(modelDir, 'README.md'))
} catch {
throw new Error(`No README.md defined for model ${model}!`)
}
console.log(chalk.green('✔'), chalk.gray(`README.md exists`))
try {
parseREADME(await readFile(path.join(modelDir, 'README.md'), 'utf-8'))
} catch (err) {
console.error(err)
throw new Error(`README is not valid for ${model}!`)
}
console.log(chalk.green('✔'), chalk.gray(`README.md is valid`))
}