feat: add registry override flag

This commit is contained in:
Shinwoo PARK 2024-06-13 19:43:24 +00:00
parent a966a85f62
commit d8d61aceaa
4 changed files with 22 additions and 8 deletions

View File

@ -85,6 +85,7 @@ export default class Add extends Command {
static override examples = ['<%= config.bin %> <%= command.id %>'] static override examples = ['<%= config.bin %> <%= command.id %>']
static override flags = { static override flags = {
registry: Flags.string({char: 'r', description: 'override registry url'}),
force: Flags.boolean({char: 'f', description: 'override the existing file'}), force: Flags.boolean({char: 'f', description: 'override the existing file'}),
config: Flags.string({char: 'p', description: 'path to config'}), config: Flags.string({char: 'p', description: 'path to config'}),
shared: Flags.string({char: 's', description: 'place for installation of shared.ts'}), shared: Flags.string({char: 's', description: 'place for installation of shared.ts'}),
@ -108,7 +109,10 @@ export default class Add extends Command {
} }
const loadRegistryOra = ora('Fetching registry...').start() const loadRegistryOra = ora('Fetching registry...').start()
const unsafeRegistry = await getRegistry() if (flags.registry) {
this.log(`Using ${flags.registry} for registry.`)
}
const unsafeRegistry = await getRegistry(flags.registry)
if (!unsafeRegistry.ok) { if (!unsafeRegistry.ok) {
loadRegistryOra.fail(unsafeRegistry.message) loadRegistryOra.fail(unsafeRegistry.message)
return return

View File

@ -2,7 +2,6 @@ import {Command, Flags} from '@oclif/core'
import {getAvailableComponentNames, getRegistry, getComponentURL, getComponentRealname} from '../helpers/registry.js' import {getAvailableComponentNames, getRegistry, getComponentURL, getComponentRealname} from '../helpers/registry.js'
import ora from 'ora' import ora from 'ora'
import treeify from 'treeify' import treeify from 'treeify'
import {CONFIG_DEFAULT_PATH} from '../const.js'
import {loadConfig, validateConfig} from '../helpers/config.js' import {loadConfig, validateConfig} from '../helpers/config.js'
import {getComponentsInstalled} from '../helpers/path.js' import {getComponentsInstalled} from '../helpers/path.js'
@ -12,6 +11,7 @@ export default class List extends Command {
static override examples = ['<%= config.bin %> <%= command.id %>'] static override examples = ['<%= config.bin %> <%= command.id %>']
static override flags = { static override flags = {
registry: Flags.string({char: 'r', description: 'override registry url'}),
url: Flags.boolean({char: 'u', description: 'include component file URL'}), url: Flags.boolean({char: 'u', description: 'include component file URL'}),
config: Flags.string({char: 'p', description: 'path to config'}), config: Flags.string({char: 'p', description: 'path to config'}),
} }
@ -25,7 +25,10 @@ export default class List extends Command {
const loadedConfig = await validateConfig((message: string) => this.log(message), await loadConfig(flags.config)) const loadedConfig = await validateConfig((message: string) => this.log(message), await loadConfig(flags.config))
registrySpinner.start() registrySpinner.start()
const unsafeRegistry = await getRegistry() if (flags.registry) {
this.log(`Using ${flags.registry} for registry.`)
}
const unsafeRegistry = await getRegistry(flags.registry)
if (!unsafeRegistry.ok) { if (!unsafeRegistry.ok) {
registrySpinner.fail(unsafeRegistry.message) registrySpinner.fail(unsafeRegistry.message)
return return

View File

@ -1,4 +1,4 @@
import {Command, Args} from '@oclif/core' import {Command, Args, Flags} from '@oclif/core'
import {render} from 'ink' import {render} from 'ink'
import {SearchBox} from '../components/SearchBox.js' import {SearchBox} from '../components/SearchBox.js'
import {getAvailableComponentNames, getRegistry} from '../helpers/registry.js' import {getAvailableComponentNames, getRegistry} from '../helpers/registry.js'
@ -9,14 +9,21 @@ export default class Search extends Command {
query: Args.string({description: 'search query'}), query: Args.string({description: 'search query'}),
} }
static override flags = {
registry: Flags.string({char: 'r', description: 'override registry url'})
}
static override description = 'Search components.' static override description = 'Search components.'
static override examples = ['<%= config.bin %> <%= command.id %>'] static override examples = ['<%= config.bin %> <%= command.id %>']
public async run(): Promise<void> { public async run(): Promise<void> {
const {args} = await this.parse(Search) const {args, flags} = await this.parse(Search)
const registryResult = await getRegistry() if (flags.registry) {
this.log(`Using ${flags.registry} for registry.`)
}
const registryResult = await getRegistry(flags.registry)
if (!registryResult.ok) { if (!registryResult.ok) {
this.error(registryResult.message) this.error(registryResult.message)
} }

View File

@ -1,7 +1,7 @@
import {REGISTRY_URL, Registry} from '../const.js' import {REGISTRY_URL, Registry} from '../const.js'
export async function getRegistry(): Promise<{ok: true; registry: Registry} | {ok: false; message: string}> { export async function getRegistry(REGISTRY_OVERRIDE_URL?: string): Promise<{ok: true; registry: Registry} | {ok: false; message: string}> {
const registryResponse = await fetch(REGISTRY_URL) const registryResponse = await fetch(REGISTRY_OVERRIDE_URL ?? REGISTRY_URL)
if (registryResponse.ok) { if (registryResponse.ok) {
return { return {