From bba1a80550a296d7f8e7ed0a0af7d29a5f6ef99d Mon Sep 17 00:00:00 2001 From: p-sw Date: Sat, 15 Jun 2024 03:12:37 +0900 Subject: [PATCH] feat(cli): add checkComponentInstalled taking RegistryComponent --- packages/cli/src/helpers/path.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/cli/src/helpers/path.ts b/packages/cli/src/helpers/path.ts index b943d00..356e19a 100644 --- a/packages/cli/src/helpers/path.ts +++ b/packages/cli/src/helpers/path.ts @@ -41,6 +41,21 @@ export async function getDirComponentInstalledFiles { + 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 { return path.join(path.dirname(_path), path.basename(_path, path.extname(_path)) + extension) }