refactor(cli): remove getComponentsInstalled & make getDirComponentRequiredFiles

This commit is contained in:
p-sw 2024-06-15 03:13:04 +09:00
parent bba1a80550
commit 5a41b84c9a

View File

@ -4,41 +4,18 @@ import path from 'node:path'
import {RegistryComponent, ResolvedConfig} from '../const.js' import {RegistryComponent, ResolvedConfig} from '../const.js'
export async function getComponentsInstalled(components: string[], config: ResolvedConfig) { export async function getDirComponentRequiredFiles<T extends RegistryComponent & {type: 'dir'}>(
const componentPath = path.join(process.cwd(), config.paths.components)
if (!existsSync(componentPath)) {
return []
}
const dir = await readdir(componentPath)
const dirOnlyContainsComponent = []
for (const fileName of dir) {
if (components.includes(fileName)) {
dirOnlyContainsComponent.push(fileName)
}
}
return dirOnlyContainsComponent
}
export async function getDirComponentInstalledFiles<T extends RegistryComponent & {type: 'dir'}>(
componentObject: T, componentObject: T,
config: ResolvedConfig, config: ResolvedConfig,
) { ) {
const componentPath = path.join(process.cwd(), config.paths.components, componentObject.name) const componentPath = path.join(process.cwd(), config.paths.components, componentObject.name)
if (!existsSync(componentPath)) { if (!existsSync(componentPath)) {
return [] return componentObject.files
} }
const dir = await readdir(componentPath) const dir = await readdir(componentPath):w
const dirOnlyContainsComponentFile = []
for (const fileName of dir) {
if (componentObject.files.includes(fileName)) {
dirOnlyContainsComponentFile.push(fileName)
}
}
return dirOnlyContainsComponentFile return componentObject.files.map((filename) => !dir.includes(filename))
} }
export async function checkComponentInstalled(component: RegistryComponent, config: ResolvedConfig): Promise<boolean> { export async function checkComponentInstalled(component: RegistryComponent, config: ResolvedConfig): Promise<boolean> {