fix(cli): eslint

This commit is contained in:
p-sw 2024-06-15 04:00:36 +09:00
parent 7f2628eedc
commit bfb044fd43
7 changed files with 22 additions and 20 deletions

View File

@ -43,7 +43,8 @@
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "off",
"import/no-unresolved": "error",
"import/default": "warn",
"import/default": "off",
"import/no-named-as-default-member": "off",
"n/no-missing-import": "off",
"n/no-unsupported-features/es-syntax": "off",
"no-unused-expressions": "off",

View File

@ -11,7 +11,7 @@ import {SearchBox} from '../components/SearchBox.js'
import {getDirComponentRequiredFiles, checkComponentInstalled} from '../helpers/path.js'
import {Choice} from '../components/Choice.js'
import {colorize} from '@oclif/core/ux'
import {safeFetch} from '../helpers/safeFetcher.js'
import {safeFetch} from '../helpers/safe-fetcher.js'
function Generator() {
let complete: boolean = false

View File

@ -52,6 +52,7 @@ export default class List extends Command {
} else if (componentObject.type === 'dir') {
url = Object.fromEntries(await getDirComponentURL(registry, componentObject))
}
final = {...final, [name]: {URL: url, installed}}
} else {
final = {...final, [name]: {installed}}

View File

@ -1,27 +1,27 @@
import {z} from 'zod'
export const REGISTRY_URL = (branch: string) => `https://raw.githubusercontent.com/pswui/ui/${branch}/registry.json`
export const registryURL = (branch: string) => `https://raw.githubusercontent.com/pswui/ui/${branch}/registry.json`
export const CONFIG_DEFAULT_PATH = 'pswui.config.js'
export type RegistryComponent =
| {
type: 'file'
files: string[]
name: string
type: 'dir'
}
| {
type: 'dir'
name: string
files: string[]
type: 'file'
}
export interface Registry {
base: string
components: Record<string, RegistryComponent>
lib: string[]
paths: {
components: string
lib: string
}
lib: string[]
}
export interface Config {

View File

@ -4,7 +4,7 @@ import path from 'node:path'
import {RegistryComponent, ResolvedConfig} from '../const.js'
export async function getDirComponentRequiredFiles<T extends RegistryComponent & {type: 'dir'}>(
export async function getDirComponentRequiredFiles<T extends {type: 'dir'} & RegistryComponent>(
componentObject: T,
config: ResolvedConfig,
) {
@ -25,12 +25,12 @@ export async function checkComponentInstalled(component: RegistryComponent, conf
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
}
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> {

View File

@ -1,10 +1,10 @@
import {Registry, REGISTRY_URL, RegistryComponent} from '../const.js'
import {safeFetch} from './safeFetcher.js'
import {Registry, RegistryComponent, registryURL} from '../const.js'
import {safeFetch} from './safe-fetcher.js'
export async function getRegistry(
branch?: string,
): Promise<{message: string; ok: false} | {ok: true; registry: Registry}> {
const registryResponse = await safeFetch(REGISTRY_URL(branch ?? 'main'))
const registryResponse = await safeFetch(registryURL(branch ?? 'main'))
if (registryResponse.ok) {
const registryJson = (await registryResponse.response.json()) as Registry
@ -21,14 +21,14 @@ export async function getRegistry(
export async function getComponentURL(
registry: Registry,
component: RegistryComponent & {type: 'file'},
component: {type: 'file'} & RegistryComponent,
): Promise<string> {
return registry.base + registry.paths.components.replace('{componentName}', component.name)
}
export async function getDirComponentURL(
registry: Registry,
component: RegistryComponent & {type: 'dir'},
component: {type: 'dir'} & RegistryComponent,
files?: string[],
): Promise<[string, string][]> {
const base = registry.base + registry.paths.components.replace('{componentName}', component.name)

View File

@ -2,7 +2,7 @@ import fetch, {Response} from 'node-fetch'
export async function safeFetch(
url: string,
): Promise<{ok: true; response: Response} | {ok: false; message: string; response: Response}> {
): Promise<{message: string; ok: false; response: Response} | {ok: true; response: Response}> {
const response = await fetch(url)
if (response.ok) {
return {
@ -12,8 +12,8 @@ export async function safeFetch(
}
return {
ok: false,
message: `Error while fetching from ${response.url}: ${response.status} ${response.statusText}`,
ok: false,
response,
}
}