feat(cli): add checkComponentInstalled taking RegistryComponent

This commit is contained in:
p-sw 2024-06-15 03:12:37 +09:00
parent 1902b9606a
commit bba1a80550

View File

@ -41,6 +41,21 @@ export async function getDirComponentInstalledFiles<T extends RegistryComponent
return dirOnlyContainsComponentFile
}
export async function checkComponentInstalled(component: RegistryComponent, config: ResolvedConfig): Promise<boolean> {
const componentDirRoot = path.join(process.cwd(), config.paths.components)
if (!existsSync(componentDirRoot)) return false
if (component.type === 'file') {
const dir = await readdir(componentDirRoot)
return dir.includes(component.name)
} else {
const componentDir = path.join(componentDirRoot, component.name)
if (!existsSync(componentDir)) return false
const dir = await readdir(componentDir)
return component.files.filter((filename) => !dir.includes(filename)).length === 0
}
}
export async function changeExtension(_path: string, extension: string): Promise<string> {
return path.join(path.dirname(_path), path.basename(_path, path.extname(_path)) + extension)
}