-
Notifications
You must be signed in to change notification settings - Fork 67.8k
Expand file tree
/
Copy pathindex.ts
More file actions
52 lines (42 loc) · 1.78 KB
/
Copy pathindex.ts
File metadata and controls
52 lines (42 loc) · 1.78 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
interface DataSchemas {
[key: string]: string
}
// Auto-discover table schemas from data/tables/ directory
function loadTableSchemas(): DataSchemas {
const tablesDir = path.join(process.cwd(), 'data/tables')
const schemasDir = path.join(__dirname, 'tables')
const tableSchemas: DataSchemas = {}
if (fs.existsSync(tablesDir)) {
const yamlFiles = fs.readdirSync(tablesDir).filter((file) => file.endsWith('.yml'))
for (const yamlFile of yamlFiles) {
const name = path.basename(yamlFile, '.yml')
const schemaPath = path.join(schemasDir, `${name}.ts`)
if (fs.existsSync(schemaPath)) {
// Use relative path from test file for vitest 4.x compatibility with dynamic imports
tableSchemas[`data/tables/${yamlFile}`] = `../lib/data-schemas/tables/${name}.ts`
}
}
}
return tableSchemas
}
// Manual schema registrations for non-table data
// Use relative paths from the test file for vitest 4.x compatibility with dynamic imports
const manualSchemas: DataSchemas = {
'data/features': '../lib/data-schemas/features.ts',
'data/variables': '../lib/data-schemas/variables.ts',
'data/learning-tracks': '../lib/data-schemas/learning-tracks.ts',
'data/release-notes': '../lib/data-schemas/release-notes.ts',
'data/code-languages.yml': '../lib/data-schemas/code-languages.ts',
'data/glossaries/candidates.yml': '../lib/data-schemas/glossaries-candidates.ts',
'data/glossaries/external.yml': '../lib/data-schemas/glossaries-external.ts',
}
// Combine manual registrations with auto-discovered table schemas
const dataSchemas: DataSchemas = {
...manualSchemas,
...loadTableSchemas(),
}
export default dataSchemas