import { access, readFile } from 'node:fs/promises' import path from 'node:path' const outputDir = path.resolve('dist/r') const sourceRegistryPath = path.resolve('registry/components/registry.json') const outputRegistryPath = path.join(outputDir, 'registry.json') await access(outputRegistryPath) const sourceRegistry = JSON.parse(await readFile(sourceRegistryPath, 'utf8')) const outputRegistry = JSON.parse(await readFile(outputRegistryPath, 'utf8')) if (outputRegistry.name !== 'kri') throw new Error(`Unexpected registry name: ${outputRegistry.name}`) if (!Array.isArray(outputRegistry.items)) throw new Error('registry.items must be an array.') if (outputRegistry.items.length !== sourceRegistry.items.length) { throw new Error(`Expected ${sourceRegistry.items.length} items, received ${outputRegistry.items.length}.`) } for (const expected of sourceRegistry.items) { const itemPath = path.join(outputDir, `${expected.name}.json`) await access(itemPath) const item = JSON.parse(await readFile(itemPath, 'utf8')) if (item.name !== expected.name) throw new Error(`Unexpected item name: ${item.name}`) if (!outputRegistry.items.some((entry) => entry.name === expected.name)) { throw new Error(`${expected.name} was not found in registry.json.`) } for (const dependency of expected.registryDependencies ?? []) { if (!item.registryDependencies?.includes(dependency)) { throw new Error(`${expected.name} must depend on registry item ${dependency}.`) } } for (const dependency of expected.dependencies ?? []) { if (!item.dependencies?.includes(dependency)) { throw new Error(`${expected.name} must include package ${dependency}.`) } } for (const expectedFile of expected.files ?? []) { const generatedFile = item.files?.find((file) => file.target === expectedFile.target) if (!generatedFile?.content) throw new Error(`${expected.name}: ${expectedFile.target} content was not generated.`) if (generatedFile.content.includes('content-text-')) { throw new Error(`${expected.name}: project-specific content-text class remains in ${expectedFile.target}.`) } if (generatedFile.content.includes('@kri/common/ui')) { throw new Error(`${expected.name}: @kri/common/ui import remains in ${expectedFile.target}.`) } } console.log(`[OK] item=${item.name} files=${item.files?.length ?? 0}`) } console.log(`[OK] registry=${outputRegistry.name}`) console.log(`[OK] items=${outputRegistry.items.length}`) console.log(`[OK] output=${outputDir}`)