|
|
|
@ -4,6 +4,7 @@ import { describe, expect, it } from 'vitest'
|
|
|
|
|
|
|
|
|
|
|
|
const COMPONENTS_DIR = 'src/uix/eidos/components'
|
|
|
|
const COMPONENTS_DIR = 'src/uix/eidos/components'
|
|
|
|
const ROOT_FILE_EXCEPTIONS = new Set(['svg'])
|
|
|
|
const ROOT_FILE_EXCEPTIONS = new Set(['svg'])
|
|
|
|
|
|
|
|
const COMPONENT_SOURCE_FILE = /\.(css|svelte|ts)$/
|
|
|
|
|
|
|
|
|
|
|
|
interface NamespaceContract {
|
|
|
|
interface NamespaceContract {
|
|
|
|
component: string
|
|
|
|
component: string
|
|
|
|
@ -22,6 +23,17 @@ function readComponentDirs(): readonly string[] {
|
|
|
|
.sort()
|
|
|
|
.sort()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function readComponentSourceFiles(dir = COMPONENTS_DIR): readonly { path: string; source: string }[] {
|
|
|
|
|
|
|
|
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
|
|
|
|
|
|
const path = join(dir, entry.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entry.isDirectory()) return readComponentSourceFiles(path)
|
|
|
|
|
|
|
|
if (!entry.isFile() || !COMPONENT_SOURCE_FILE.test(entry.name)) return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [{ path, source: stripComments(readFileSync(path, 'utf8')) }]
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function readIndexSource(component: string): string {
|
|
|
|
function readIndexSource(component: string): string {
|
|
|
|
return stripComments(readFileSync(join(COMPONENTS_DIR, component, 'index.ts'), 'utf8'))
|
|
|
|
return stripComments(readFileSync(join(COMPONENTS_DIR, component, 'index.ts'), 'utf8'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -63,6 +75,14 @@ describe('Eidos component API contract', () => {
|
|
|
|
expect(violations).toEqual([])
|
|
|
|
expect(violations).toEqual([])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('keeps removed flat API markers out of component source', () => {
|
|
|
|
|
|
|
|
const violations = readComponentSourceFiles()
|
|
|
|
|
|
|
|
.filter(({ source }) => /\bdata-[a-z0-9-]+-flat\b/.test(source))
|
|
|
|
|
|
|
|
.map(({ path }) => path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(violations).toEqual([])
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('keeps every public Eidos component rooted at {component}.svelte', () => {
|
|
|
|
it('keeps every public Eidos component rooted at {component}.svelte', () => {
|
|
|
|
const missingRoots = readComponentDirs()
|
|
|
|
const missingRoots = readComponentDirs()
|
|
|
|
.filter((component) => !ROOT_FILE_EXCEPTIONS.has(component))
|
|
|
|
.filter((component) => !ROOT_FILE_EXCEPTIONS.has(component))
|
|
|
|
|