Skip to content

Commit 635eaed

Browse files
authored
Merge pull request #62 from selemondev/refactor/registry-url
refactor: registry url
2 parents cac2b77 + f891cf1 commit 635eaed

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

src/utils/registry.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { ofetch } from "ofetch";
22
import { to } from "./index";
33
import { detectPackageManager } from "./vscode";
4-
import { getSvelteVersion } from "./getSvelteVersion";
54

65
type OgComponent = {
7-
type: "components:ui";
6+
type: "registry:ui";
87
name: string;
98
files: string[];
109
dependencies?: string[];
@@ -19,8 +18,7 @@ export type Component = {
1918
export type Components = Component[];
2019

2120
export const getRegistry = async (): Promise<Components | null> => {
22-
const svelteVersion = await getSvelteVersion();
23-
const reqUrl = svelteVersion >= 5 ? "https://next.shadcn-svelte.com/registry/index.json" : "https://shadcn-svelte.com/registry/index.json";
21+
const reqUrl = "https://shadcn-svelte.com/registry/index.json";
2422
const [res, err] = await to(ofetch(reqUrl));
2523

2624
if (err || !res) {
@@ -33,51 +31,47 @@ export const getRegistry = async (): Promise<Components | null> => {
3331
return null;
3432
}
3533

36-
const components: Components = (data as OgComponent[]).map((c) => {
34+
const components: Components = (data as OgComponent[]).filter((c) => c.type === 'registry:ui').map((c) => {
3735
const component: Component = {
3836
label: c.name,
39-
detail: `dependencies: ${c.dependencies && c.dependencies.length > 0 ? c.dependencies.join(" ") : "no dependency"}`,
37+
detail: `dependencies: ${c.registryDependencies && c.registryDependencies.length > 0 ? c.registryDependencies.join(", ") : "no dependency"}`,
4038
};
4139

4240
return component;
4341
});
44-
4542
return components;
4643
};
4744

4845
export const getInstallCmd = async (components: string[], cwd: string) => {
4946
const packageManager = await detectPackageManager();
5047
const componentStr = components.join(" ");
51-
const svelteVersion = await getSvelteVersion();
5248

5349
if (packageManager === "bun") {
54-
return svelteVersion >= 5 ? `bunx shadcn-svelte@next add ${componentStr} -c ${cwd}` : `bunx shadcn-svelte add ${componentStr} -c ${cwd}`;
50+
return `bunx shadcn-svelte@latest add ${componentStr} -c ${cwd}`;
5551
}
5652

5753
if (packageManager === "pnpm") {
58-
return svelteVersion >= 5 ? `pnpm dlx shadcn-svelte@next add ${componentStr} -c ${cwd}` : `pnpm dlx shadcn-svelte@latest add ${componentStr} -c ${cwd}`;
54+
return `pnpm dlx shadcn-svelte@latest add ${componentStr} -c ${cwd}`;
5955
}
6056

61-
return svelteVersion >= 5 ? `npx shadcn-svelte@next add ${componentStr} -c ${cwd}` : `npx shadcn-svelte@latest add ${componentStr} -c ${cwd}`;
57+
return `npx shadcn-svelte@latest add ${componentStr} -c ${cwd}`;
6258
};
6359

6460
export const getInitCmd = async (cwd: string) => {
6561
const packageManager = await detectPackageManager();
66-
const svelteVersion = await getSvelteVersion();
6762

6863
if (packageManager === "bun") {
69-
return svelteVersion >= 5 ? `bunx shadcn-svelte@next init -c ${cwd}` : `bunx shadcn-svelte init -c ${cwd}`;
64+
return `bunx shadcn-svelte@latest init -c ${cwd}`;
7065
}
7166

7267
if (packageManager === "pnpm") {
73-
return svelteVersion >= 5 ? `pnpm dlx shadcn-svelte@next init -c ${cwd}` : `pnpm dlx shadcn-svelte@latest init -c ${cwd}`;
68+
return `pnpm dlx shadcn-svelte@latest init -c ${cwd}`;
7469
}
7570

76-
return svelteVersion >= 5 ? `npx shadcn-svelte@next init -c ${cwd}` : `npx shadcn-svelte@latest init -c ${cwd}`;
71+
return `npx shadcn-svelte@latest init -c ${cwd}`;
7772
};
7873

7974
export const getComponentDocLink = async (component: string) => {
80-
const svelteVersion = await getSvelteVersion();
81-
const shadCnDocUrl = svelteVersion >= 5 ? "https://next.shadcn-svelte.com/docs" : "https://shadcn-svelte.com/docs";
75+
const shadCnDocUrl = "https://shadcn-svelte.com/docs";
8276
return `${shadCnDocUrl}/components/${component}`;
8377
};

src/utils/vscode.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ export const getFileStat = async (fileName: string) => {
3333
};
3434

3535
export const detectPackageManager = async (): Promise<PackageManager> => {
36-
const [bunLockExists, bunLockBExists] = await Promise.all([
37-
getFileStat("bun.lock").then(() => true).catch(() => false),
38-
getFileStat("bun.lockb").then(() => true).catch(() => false),
39-
]);
40-
if (bunLockExists || bunLockBExists) {
36+
const lockFiles = ["bun.lock", "bun.lockb"];
37+
const results = await Promise.all(
38+
lockFiles.map((file) =>
39+
getFileStat(file).catch(err => err.code === 'ENOENT' ? false : Promise.reject(err))
40+
)
41+
);
42+
43+
if (results.some(Boolean)) {
4144
return 'bun';
4245
}
4346

47+
4448
const pnpmLockExists = await getFileStat("pnpm-lock.yaml");
4549
if (pnpmLockExists) {
4650
return "pnpm";

0 commit comments

Comments
 (0)