mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-07 22:18:39 +00:00
feat(cli): use https_proxy and consider previous install locations (#430)
* feat(cli): use system proxy * feat(cli): adds default installation directory * style: formatting * feat: update lockfile --------- Co-authored-by: shadcn <m@shadcn.com>
This commit is contained in:
@@ -144,7 +144,11 @@ async function main() {
|
||||
selectedComponents = await promptForComponents(availableComponents)
|
||||
}
|
||||
|
||||
const dir = await promptForDestinationDir()
|
||||
const dir = await promptForDestinationDir(
|
||||
projectInfo?.srcComponentsUiDir
|
||||
? "./src/components/ui"
|
||||
: "./components/ui"
|
||||
)
|
||||
|
||||
if (!selectedComponents?.length) {
|
||||
logger.warn("No components selected. Nothing to install.")
|
||||
@@ -206,13 +210,13 @@ async function promptForComponents(components: Component[]) {
|
||||
return selectedComponents
|
||||
}
|
||||
|
||||
async function promptForDestinationDir() {
|
||||
async function promptForDestinationDir(installDir = "./components/ui") {
|
||||
const { dir } = await prompts([
|
||||
{
|
||||
type: "text",
|
||||
name: "dir",
|
||||
message: "Where would you like to install the component(s)?",
|
||||
initial: "./components/ui",
|
||||
initial: installDir,
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { HttpsProxyAgent } from "https-proxy-agent"
|
||||
import fetch from "node-fetch"
|
||||
import * as z from "zod"
|
||||
|
||||
const baseUrl = process.env.COMPONENTS_BASE_URL ?? "https://ui.shadcn.com"
|
||||
const agent = process.env.https_proxy
|
||||
? new HttpsProxyAgent(process.env.https_proxy)
|
||||
: undefined
|
||||
|
||||
const componentSchema = z.object({
|
||||
component: z.string(),
|
||||
@@ -22,7 +26,7 @@ const componentsSchema = z.array(componentSchema)
|
||||
|
||||
export async function getAvailableComponents() {
|
||||
try {
|
||||
const response = await fetch(`${baseUrl}/api/components`)
|
||||
const response = await fetch(`${baseUrl}/api/components`, { agent })
|
||||
const components = await response.json()
|
||||
|
||||
return componentsSchema.parse(components)
|
||||
|
||||
@@ -8,6 +8,8 @@ export async function getProjectInfo() {
|
||||
alias: null,
|
||||
srcDir: false,
|
||||
appDir: false,
|
||||
srcComponentsUiDir: false,
|
||||
componentsUiDir: false,
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -22,6 +24,8 @@ export async function getProjectInfo() {
|
||||
appDir:
|
||||
existsSync(path.resolve("./app")) ||
|
||||
existsSync(path.resolve("./src/app")),
|
||||
srcComponentsUiDir: existsSync(path.resolve("./src/components/ui")),
|
||||
componentsUiDir: existsSync(path.resolve("./components/ui")),
|
||||
}
|
||||
} catch (error) {
|
||||
return info
|
||||
|
||||
Reference in New Issue
Block a user