juas.dev 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # juas.dev CLI
2
+
3
+ > **Official CLI for [juas.dev](https://juas.dev)**
4
+ > Install beautiful, production-ready React UI components directly into your project as editable source files — like `shadcn/ui` but for juas.dev.
5
+
6
+ ```bash
7
+ npx juas.dev add liquid-glass-button
8
+ ```
9
+
10
+ ---
11
+
12
+ ## How It Works
13
+
14
+ The Juas CLI is **source-first** — it writes the component's full code directly into your project, not into `node_modules`. You own and edit it completely.
15
+
16
+ ```
17
+ Your project/
18
+ └── src/
19
+ └── components/
20
+ └── juas/
21
+ └── liquid-glass-button/
22
+ ├── LiquidGlassButton.tsx ← full editable source
23
+ └── LiquidGlassButton.css
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Quick Start
29
+
30
+ ```bash
31
+ # 1. Initialise (creates juas.config.json)
32
+ npx juas.dev init
33
+
34
+ # 2. Add a component by its slug
35
+ npx juas.dev add liquid-glass-button
36
+
37
+ # 3. Import and use it
38
+ import { LiquidGlassButton } from "./components/juas/liquid-glass-button/LiquidGlassButton";
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Commands
44
+
45
+ | Command | Description |
46
+ |---------|-------------|
47
+ | `npx juas.dev init` | Set up juas in your project |
48
+ | `npx juas.dev add <slug>` | Install a component by slug |
49
+ | `npx juas.dev list` | Browse all available components |
50
+ | `npx juas.dev list --category buttons` | Filter by category |
51
+ | `npx juas.dev search "glass button"` | Search by name or tag |
52
+ | `npx juas.dev add <slug> --dry-run` | Preview without writing files |
53
+ | `npx juas.dev add <slug> --no-deps` | Skip npm dependency install |
54
+
55
+ ---
56
+
57
+ ## Configuration — `juas.config.json`
58
+
59
+ Created automatically by `npx juas.dev init`:
60
+
61
+ ```json
62
+ {
63
+ "outputDir": "src/components/juas",
64
+ "typescript": true,
65
+ "framework": "react"
66
+ }
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Requirements
72
+
73
+ - **Node.js** 18+
74
+ - **React** 18+
75
+ - **Tailwind CSS** v3 / v4 (recommended)
76
+
77
+ ---
78
+
79
+ ## Browse Components
80
+
81
+ Visit **[juas.dev](https://juas.dev)** to explore all available components.
82
+
83
+ ---
84
+
85
+ ## License
86
+
87
+ MIT — [juas.dev](https://juas.dev)
package/bin/juas.js ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ // ============================================================
3
+ // juas CLI — entry point
4
+ // npx juas init
5
+ // npx juas add <slug>
6
+ // npx juas list
7
+ // npx juas search <query>
8
+ // ============================================================
9
+ import { createRequire } from "module";
10
+ import { program } from "commander";
11
+ import { readFileSync } from "fs";
12
+ import { fileURLToPath } from "url";
13
+ import path from "path";
14
+
15
+ import { cmdAdd } from "../src/commands/add.js";
16
+ import { cmdInit } from "../src/commands/init.js";
17
+ import { cmdList } from "../src/commands/list.js";
18
+ import { cmdSearch } from "../src/commands/search.js";
19
+
20
+ // ── Read version from package.json ──────────────────────────
21
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
22
+ const pkg = JSON.parse(readFileSync(path.join(__dirname, "../package.json"), "utf-8"));
23
+
24
+ program
25
+ .name("juas")
26
+ .description("Official CLI for juas.dev — install beautiful UI components into your project.")
27
+ .version(pkg.version, "-v, --version");
28
+
29
+ // ── juas init ───────────────────────────────────────────────
30
+ program
31
+ .command("init")
32
+ .description("Initialize juas in your project (creates juas.config.json)")
33
+ .option("--ts", "Use TypeScript (default)", true)
34
+ .option("--js", "Use JavaScript")
35
+ .option("--dir <dir>", "Component output directory", "src/components/juas")
36
+ .action(cmdInit);
37
+
38
+ // ── juas add <slug> ──────────────────────────────────────────
39
+ program
40
+ .command("add <slug>")
41
+ .description("Add a component by its slug from juas.dev")
42
+ .option("--dir <dir>", "Override output directory")
43
+ .option("--no-deps", "Skip installing npm dependencies")
44
+ .option("--dry-run", "Preview what would be written without writing files")
45
+ .action(cmdAdd);
46
+
47
+ // ── juas list ────────────────────────────────────────────────
48
+ program
49
+ .command("list")
50
+ .description("List all available components on juas.dev")
51
+ .option("--category <cat>", "Filter by category")
52
+ .option("--json", "Output raw JSON")
53
+ .action(cmdList);
54
+
55
+ // ── juas search <query> ──────────────────────────────────────
56
+ program
57
+ .command("search <query>")
58
+ .description("Search components by name, tag or description")
59
+ .option("--json", "Output raw JSON")
60
+ .action(cmdSearch);
61
+
62
+ program.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,17 +1,49 @@
1
1
  {
2
2
  "name": "juas.dev",
3
- "version": "1.0.0",
4
- "description": "CLI for juas.dev components",
5
- "main": "index.js",
3
+ "version": "1.0.2",
4
+ "description": "Official CLI for juas.dev — install beautiful UI components directly into your React project as source files.",
5
+ "type": "module",
6
6
  "bin": {
7
- "dhil-ui": "./index.js"
7
+ "juas": "bin/juas.js"
8
8
  },
9
- "type": "module",
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "dev": "node bin/juas.js",
16
+ "test": "node bin/juas.js --version"
17
+ },
18
+ "keywords": [
19
+ "juas",
20
+ "juas.dev",
21
+ "ui",
22
+ "components",
23
+ "cli",
24
+ "react",
25
+ "tailwindcss",
26
+ "design-system",
27
+ "shadcn",
28
+ "source-first"
29
+ ],
30
+ "author": "dhileepkumar",
31
+ "license": "MIT",
10
32
  "dependencies": {
11
- "commander": "^11.0.0",
12
- "prompts": "^2.4.2",
13
- "picocolors": "^1.0.0",
14
- "ora": "^7.0.1",
15
- "@supabase/supabase-js": "^2.39.0"
16
- }
17
- }
33
+ "commander": "^13.1.0",
34
+ "fs-extra": "^11.3.0",
35
+ "ora": "^8.2.0",
36
+ "picocolors": "^1.1.1"
37
+ },
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/dhileepkumar/juas.dev"
47
+ },
48
+ "homepage": "https://juas.dev"
49
+ }
@@ -0,0 +1,145 @@
1
+ // ============================================================
2
+ // commands/add.js
3
+ // npx juas add <slug>
4
+ //
5
+ // 1. Fetch component + latest version code from Supabase
6
+ // 2. Write TSX/JSX + optional CSS to outputDir
7
+ // 3. Install missing npm dependencies
8
+ // 4. Print usage snippet
9
+ // ============================================================
10
+ import path from "path";
11
+ import fs from "fs-extra";
12
+ import ora from "ora";
13
+ import pc from "picocolors";
14
+
15
+ import { logger } from "../lib/logger.js";
16
+ import { loadConfig } from "../lib/config.js";
17
+ import { fetchComponentBySlug } from "../lib/supabase.js";
18
+ import { getMissingPackages, installDependencies, detectPackageManager }
19
+ from "../lib/deps.js";
20
+
21
+ export async function cmdAdd(slug, options) {
22
+ logger.banner();
23
+ logger.info(`Adding component: ${pc.bold(slug)}`);
24
+ logger.blank();
25
+
26
+ const cwd = process.cwd();
27
+ const config = loadConfig(cwd);
28
+
29
+ // Allow --dir override
30
+ const outDir = options.dir
31
+ ? path.resolve(cwd, options.dir)
32
+ : path.resolve(cwd, config.outputDir);
33
+
34
+ const spinner = ora(`Fetching ${pc.bold(slug)} from juas.dev…`).start();
35
+
36
+ let result;
37
+ try {
38
+ result = await fetchComponentBySlug(slug);
39
+ } catch (err) {
40
+ spinner.fail("Network error.");
41
+ logger.error(err.message);
42
+ process.exit(1);
43
+ }
44
+
45
+ if (!result) {
46
+ spinner.fail(`Component "${slug}" not found on juas.dev.`);
47
+ logger.blank();
48
+ logger.info(`Search available components: ${pc.bold("npx juas search " + slug)}`);
49
+ logger.info(`Browse all: ${pc.underline("https://juas.dev")}`);
50
+ process.exit(1);
51
+ }
52
+
53
+ const { component, version } = result;
54
+
55
+ if (!version?.code_tsx) {
56
+ spinner.fail(`"${slug}" has no source code yet. It may still be processing.`);
57
+ process.exit(1);
58
+ }
59
+
60
+ spinner.succeed(`Found: ${pc.bold(component.name)} v${version.version}`);
61
+
62
+ // ── Build file paths ────────────────────────────────────────
63
+ const useTs = config.typescript !== false;
64
+ const ext = useTs ? ".tsx" : ".jsx";
65
+ const compDir = path.join(outDir, slug);
66
+ const tsxFile = path.join(compDir, `${toPascalCase(slug)}${ext}`);
67
+ const cssFile = path.join(compDir, `${toPascalCase(slug)}.css`);
68
+
69
+ if (options.dryRun) {
70
+ logger.blank();
71
+ logger.warn("Dry run — no files written.");
72
+ logger.label("Would write TSX", tsxFile);
73
+ if (version.code_css) logger.label("Would write CSS", cssFile);
74
+ logger.blank();
75
+ showUsageSnippet(slug, component.name);
76
+ return;
77
+ }
78
+
79
+ // ── Write files ────────────────────────────────────────────
80
+ const fileSpinner = ora("Writing component files…").start();
81
+ try {
82
+ await fs.ensureDir(compDir);
83
+ await fs.outputFile(tsxFile, version.code_tsx, "utf-8");
84
+ if (version.code_css?.trim()) {
85
+ await fs.outputFile(cssFile, version.code_css, "utf-8");
86
+ }
87
+ fileSpinner.succeed("Files written.");
88
+ } catch (err) {
89
+ fileSpinner.fail("Failed to write files.");
90
+ logger.error(err.message);
91
+ process.exit(1);
92
+ }
93
+
94
+ // ── Install missing npm dependencies ──────────────────────
95
+ const declaredDeps = version.dependencies ?? [];
96
+
97
+ if (declaredDeps.length && options.deps !== false) {
98
+ const missing = getMissingPackages(declaredDeps, cwd);
99
+ if (missing.length) {
100
+ const pm = detectPackageManager(cwd);
101
+ const depSpinner = ora(`Installing ${missing.length} dependenc${missing.length > 1 ? "ies" : "y"} via ${pm}…`).start();
102
+ try {
103
+ installDependencies(missing, cwd);
104
+ depSpinner.succeed("Dependencies installed.");
105
+ } catch (err) {
106
+ depSpinner.fail("Dependency install failed — install manually.");
107
+ logger.warn(`Run: ${pc.bold(pm + " install " + missing.join(" "))}`);
108
+ }
109
+ } else {
110
+ logger.success("All dependencies already installed.");
111
+ }
112
+ }
113
+
114
+ // ── Summary ────────────────────────────────────────────────
115
+ logger.blank();
116
+ logger.divider();
117
+ logger.success(pc.bold(`${component.name} installed!`));
118
+ logger.divider();
119
+ logger.blank();
120
+ logger.label("File", path.relative(cwd, tsxFile));
121
+ if (version.code_css?.trim()) logger.label("CSS", path.relative(cwd, cssFile));
122
+ if (component.description) logger.label("About", component.description);
123
+ logger.blank();
124
+ showUsageSnippet(slug, component.name);
125
+ logger.blank();
126
+ logger.info(`View on web: ${pc.underline("https://juas.dev/components/" + slug)}`);
127
+ logger.blank();
128
+ }
129
+
130
+ // ── Helpers ──────────────────────────────────────────────────
131
+
132
+ function toPascalCase(str) {
133
+ return str
134
+ .split(/[-_\s]+/)
135
+ .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
136
+ .join("");
137
+ }
138
+
139
+ function showUsageSnippet(slug, name) {
140
+ const pascal = toPascalCase(slug);
141
+ console.log(pc.dim(" Usage:"));
142
+ console.log(pc.cyan(` import { ${pascal} } from "./${slug}/${pascal}";`));
143
+ console.log();
144
+ console.log(pc.cyan(` <${pascal} />`));
145
+ }
@@ -0,0 +1,52 @@
1
+ // ============================================================
2
+ // commands/init.js
3
+ // npx juas init
4
+ // Creates juas.config.json and the output directory.
5
+ // ============================================================
6
+ import path from "path";
7
+ import fs from "fs-extra";
8
+ import ora from "ora";
9
+ import pc from "picocolors";
10
+
11
+ import { logger } from "../lib/logger.js";
12
+ import { writeConfig } from "../lib/config.js";
13
+
14
+ export async function cmdInit(options) {
15
+ logger.banner();
16
+
17
+ const cwd = process.cwd();
18
+ const cfgExists = fs.existsSync(path.join(cwd, "juas.config.json"));
19
+
20
+ if (cfgExists) {
21
+ logger.warn("juas.config.json already exists. Remove it first to reinitialise.");
22
+ process.exit(0);
23
+ }
24
+
25
+ // Determine typescript flag
26
+ const useTs = options.js ? false : true;
27
+ const dir = options.dir ?? "src/components/juas";
28
+
29
+ const spinner = ora("Initialising juas…").start();
30
+
31
+ try {
32
+ // Write config
33
+ await writeConfig(cwd, { outputDir: dir, typescript: useTs, framework: "react" });
34
+
35
+ // Create output directory
36
+ await fs.ensureDir(path.join(cwd, dir));
37
+
38
+ spinner.succeed(pc.green("juas initialised successfully!"));
39
+ logger.blank();
40
+ logger.label("Config", "juas.config.json");
41
+ logger.label("Components dir", dir);
42
+ logger.label("TypeScript", String(useTs));
43
+ logger.blank();
44
+ logger.info(`Now run: ${pc.bold("npx juas add <component-slug>")}`);
45
+ logger.info(`Browse components: ${pc.underline("https://juas.dev")}`);
46
+ logger.blank();
47
+ } catch (err) {
48
+ spinner.fail("Initialisation failed.");
49
+ logger.error(err.message);
50
+ process.exit(1);
51
+ }
52
+ }
@@ -0,0 +1,56 @@
1
+ // ============================================================
2
+ // commands/list.js
3
+ // npx juas list [--category buttons] [--json]
4
+ // ============================================================
5
+ import ora from "ora";
6
+ import pc from "picocolors";
7
+
8
+ import { logger } from "../lib/logger.js";
9
+ import { listComponents } from "../lib/supabase.js";
10
+
11
+ export async function cmdList(options) {
12
+ logger.banner();
13
+
14
+ const spinner = ora("Fetching component registry…").start();
15
+
16
+ let components;
17
+ try {
18
+ components = await listComponents({ category: options.category });
19
+ spinner.succeed(`${components.length} component${components.length !== 1 ? "s" : ""} found.`);
20
+ } catch (err) {
21
+ spinner.fail("Failed to fetch registry.");
22
+ logger.error(err.message);
23
+ process.exit(1);
24
+ }
25
+
26
+ if (!components.length) {
27
+ logger.info("No components found.");
28
+ return;
29
+ }
30
+
31
+ if (options.json) {
32
+ console.log(JSON.stringify(components, null, 2));
33
+ return;
34
+ }
35
+
36
+ // Group by category
37
+ const grouped = components.reduce((acc, c) => {
38
+ const cat = c.category ?? "Uncategorised";
39
+ (acc[cat] = acc[cat] ?? []).push(c);
40
+ return acc;
41
+ }, {});
42
+
43
+ logger.blank();
44
+
45
+ for (const [cat, items] of Object.entries(grouped).sort()) {
46
+ console.log(pc.bold(pc.magenta(` ${cat}`)));
47
+ for (const item of items) {
48
+ const tags = item.tags?.slice(0, 3).map((t) => pc.dim(`#${t}`)).join(" ") ?? "";
49
+ console.log(` ${pc.green(item.slug.padEnd(36))} ${pc.dim("v" + (item.latest_version ?? "?"))} ${tags}`);
50
+ }
51
+ logger.blank();
52
+ }
53
+
54
+ logger.info(`Install any component: ${pc.bold("npx juas add <slug>")}`);
55
+ logger.blank();
56
+ }
@@ -0,0 +1,52 @@
1
+ // ============================================================
2
+ // commands/search.js
3
+ // npx juas search "glass button"
4
+ // ============================================================
5
+ import ora from "ora";
6
+ import pc from "picocolors";
7
+
8
+ import { logger } from "../lib/logger.js";
9
+ import { searchComponents } from "../lib/supabase.js";
10
+
11
+ export async function cmdSearch(query, options) {
12
+ logger.banner();
13
+ logger.info(`Searching for: ${pc.bold(query)}`);
14
+ logger.blank();
15
+
16
+ const spinner = ora("Searching juas.dev…").start();
17
+
18
+ let results;
19
+ try {
20
+ results = await searchComponents(query);
21
+ spinner.succeed(`${results.length} result${results.length !== 1 ? "s" : ""}`);
22
+ } catch (err) {
23
+ spinner.fail("Search failed.");
24
+ logger.error(err.message);
25
+ process.exit(1);
26
+ }
27
+
28
+ if (!results.length) {
29
+ logger.warn(`No components matched "${query}".`);
30
+ logger.info(`Try browsing all: ${pc.bold("npx juas list")}`);
31
+ return;
32
+ }
33
+
34
+ if (options.json) {
35
+ console.log(JSON.stringify(results, null, 2));
36
+ return;
37
+ }
38
+
39
+ logger.blank();
40
+ for (const item of results) {
41
+ const tags = item.tags?.slice(0, 4).map((t) => pc.dim(`#${t}`)).join(" ") ?? "";
42
+ console.log(` ${pc.green(pc.bold(item.slug.padEnd(36)))} ${pc.dim(item.category ?? "")}`);
43
+ if (item.description) {
44
+ console.log(` ${pc.dim(item.description.slice(0, 72))}`);
45
+ }
46
+ if (tags) console.log(` ${tags}`);
47
+ console.log();
48
+ }
49
+
50
+ logger.info(`Install: ${pc.bold("npx juas add <slug>")}`);
51
+ logger.blank();
52
+ }
@@ -0,0 +1,48 @@
1
+ // ============================================================
2
+ // config.js — read/write juas.config.json in the user's project
3
+ // ============================================================
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+
7
+ const CONFIG_FILE = "juas.config.json";
8
+
9
+ /** Default config shape */
10
+ const DEFAULT_CONFIG = {
11
+ outputDir: "src/components/juas",
12
+ typescript: true,
13
+ framework: "react",
14
+ };
15
+
16
+ /**
17
+ * Find the nearest juas.config.json walking up from cwd.
18
+ * Returns the absolute path or null if not found.
19
+ */
20
+ export function findConfig(cwd = process.cwd()) {
21
+ let dir = cwd;
22
+ while (true) {
23
+ const candidate = path.join(dir, CONFIG_FILE);
24
+ if (fs.existsSync(candidate)) return candidate;
25
+ const parent = path.dirname(dir);
26
+ if (parent === dir) return null; // reached filesystem root
27
+ dir = parent;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Load config. Falls back to defaults if no file found.
33
+ */
34
+ export function loadConfig(cwd = process.cwd()) {
35
+ const cfgPath = findConfig(cwd);
36
+ if (!cfgPath) return { ...DEFAULT_CONFIG, _path: null };
37
+ const raw = fs.readJsonSync(cfgPath);
38
+ return { ...DEFAULT_CONFIG, ...raw, _path: cfgPath };
39
+ }
40
+
41
+ /**
42
+ * Write a new config file.
43
+ */
44
+ export async function writeConfig(dir, data) {
45
+ const cfgPath = path.join(dir, CONFIG_FILE);
46
+ await fs.outputJson(cfgPath, { ...DEFAULT_CONFIG, ...data }, { spaces: 2 });
47
+ return cfgPath;
48
+ }
@@ -0,0 +1,55 @@
1
+ // ============================================================
2
+ // deps.js — detect the user's package manager & install deps
3
+ // ============================================================
4
+ import { execSync, spawnSync } from "child_process";
5
+ import fs from "fs-extra";
6
+ import path from "path";
7
+
8
+ /** Detect which package manager is in use. */
9
+ export function detectPackageManager(cwd = process.cwd()) {
10
+ if (fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
11
+ if (fs.existsSync(path.join(cwd, "yarn.lock"))) return "yarn";
12
+ if (fs.existsSync(path.join(cwd, "bun.lockb"))) return "bun";
13
+ return "npm";
14
+ }
15
+
16
+ /**
17
+ * Install an array of npm packages using the detected package manager.
18
+ * @param {string[]} packages - e.g. ["framer-motion", "clsx"]
19
+ * @param {string} cwd - project root
20
+ */
21
+ export function installDependencies(packages, cwd = process.cwd()) {
22
+ if (!packages.length) return;
23
+ const pm = detectPackageManager(cwd);
24
+
25
+ const installCmd = {
26
+ npm: `npm install ${packages.join(" ")}`,
27
+ pnpm: `pnpm add ${packages.join(" ")}`,
28
+ yarn: `yarn add ${packages.join(" ")}`,
29
+ bun: `bun add ${packages.join(" ")}`,
30
+ }[pm];
31
+
32
+ execSync(installCmd, { cwd, stdio: "inherit" });
33
+ }
34
+
35
+ /**
36
+ * Check whether the user already has a package installed.
37
+ */
38
+ export function isPackageInstalled(pkg, cwd = process.cwd()) {
39
+ const pkgJsonPath = path.join(cwd, "package.json");
40
+ if (!fs.existsSync(pkgJsonPath)) return false;
41
+ const pkgJson = fs.readJsonSync(pkgJsonPath);
42
+ const allDeps = {
43
+ ...(pkgJson.dependencies ?? {}),
44
+ ...(pkgJson.devDependencies ?? {}),
45
+ ...(pkgJson.peerDependencies ?? {}),
46
+ };
47
+ return pkg in allDeps;
48
+ }
49
+
50
+ /**
51
+ * Filter out already-installed packages.
52
+ */
53
+ export function getMissingPackages(packages, cwd = process.cwd()) {
54
+ return packages.filter((p) => !isPackageInstalled(p, cwd));
55
+ }
@@ -0,0 +1,22 @@
1
+ // ============================================================
2
+ // logger.js — colourful terminal output helpers
3
+ // ============================================================
4
+ import pc from "picocolors";
5
+
6
+ export const logger = {
7
+ info: (...args) => console.log(pc.cyan(" ●"), ...args),
8
+ success: (...args) => console.log(pc.green(" ✔"), ...args),
9
+ warn: (...args) => console.log(pc.yellow(" ⚠"), ...args),
10
+ error: (...args) => console.error(pc.red(" ✖"), ...args),
11
+ label: (label, value) => console.log(` ${pc.bold(label + ":")} ${value}`),
12
+ divider: () => console.log(pc.dim(" " + "─".repeat(52))),
13
+ blank: () => console.log(),
14
+
15
+ banner() {
16
+ console.log();
17
+ console.log(pc.bold(pc.magenta(" ┌──────────────────────────────────────┐")));
18
+ console.log(pc.bold(pc.magenta(" │ juas.dev CLI ⚡ │")));
19
+ console.log(pc.bold(pc.magenta(" └──────────────────────────────────────┘")));
20
+ console.log();
21
+ },
22
+ };
@@ -0,0 +1,81 @@
1
+ // ============================================================
2
+ // supabase.js — lightweight REST client for the CLI
3
+ // Uses the PUBLIC anon key — safe to ship in the npm package
4
+ // ============================================================
5
+
6
+ export const SUPABASE_URL = "https://jznmqsiueeauoulgvzww.supabase.co";
7
+ export const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imp6bm1xc2l1ZWVhdW91bGd2end3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODE1MTA0MjIsImV4cCI6MjA5NzA4NjQyMn0.KG54rFl_jT0ofhQ9KuYGEQYNC8_kZD0KxoCpmXWz1pU";
8
+
9
+ /**
10
+ * Thin fetch wrapper around the Supabase REST API.
11
+ */
12
+ export async function supabaseGet(table, params = {}) {
13
+ const url = new URL(`${SUPABASE_URL}/rest/v1/${table}`);
14
+ Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
15
+
16
+ const res = await fetch(url.toString(), {
17
+ headers: {
18
+ apikey: SUPABASE_ANON_KEY,
19
+ Authorization: `Bearer ${SUPABASE_ANON_KEY}`,
20
+ "Content-Type": "application/json",
21
+ },
22
+ });
23
+
24
+ if (!res.ok) {
25
+ const txt = await res.text();
26
+ throw new Error(`Supabase error ${res.status}: ${txt}`);
27
+ }
28
+
29
+ return res.json();
30
+ }
31
+
32
+ /**
33
+ * Fetch a single component + its latest version code by slug.
34
+ */
35
+ export async function fetchComponentBySlug(slug) {
36
+ const components = await supabaseGet("components", {
37
+ slug: `eq.${slug}`,
38
+ status: "eq.published",
39
+ select: "id,name,slug,description,category,tags,tech_stack,framework,latest_version",
40
+ limit: "1",
41
+ });
42
+
43
+ if (!components.length) return null;
44
+ const component = components[0];
45
+
46
+ const versions = await supabaseGet("component_versions", {
47
+ component_id: `eq.${component.id}`,
48
+ version: `eq.${component.latest_version}`,
49
+ select: "id,version,code_tsx,code_css,dependencies,readme",
50
+ limit: "1",
51
+ });
52
+
53
+ return { component, version: versions[0] ?? null };
54
+ }
55
+
56
+ /**
57
+ * List all published components.
58
+ */
59
+ export async function listComponents({ category } = {}) {
60
+ const params = {
61
+ status: "eq.published",
62
+ select: "id,name,slug,description,category,tags,tech_stack,latest_version",
63
+ order: "name.asc",
64
+ limit: "200",
65
+ };
66
+ if (category) params.category = `eq.${category}`;
67
+ return supabaseGet("components", params);
68
+ }
69
+
70
+ /**
71
+ * Search components by name or description.
72
+ */
73
+ export async function searchComponents(query) {
74
+ return supabaseGet("components", {
75
+ status: "eq.published",
76
+ or: `name.ilike.*${query}*,description.ilike.*${query}*`,
77
+ select: "id,name,slug,description,category,tags,latest_version",
78
+ order: "name.asc",
79
+ limit: "50",
80
+ });
81
+ }
package/index.js DELETED
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import prompts from 'prompts';
5
- import pc from 'picocolors';
6
- import ora from 'ora';
7
- import fs from 'fs/promises';
8
- import path from 'path';
9
- import { createClient } from '@supabase/supabase-js';
10
-
11
- // Hardcoded for CLI public access
12
- const SUPABASE_URL = "https://jznmqsiueeauoulgvzww.supabase.co";
13
- const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imp6bm1xc2l1ZWVhdW91bGd2end3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODE1MTA0MjIsImV4cCI6MjA5NzA4NjQyMn0.KG54rFl_jT0ofhQ9KuYGEQYNC8_kZD0KxoCpmXWz1pU";
14
-
15
- const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
16
- const program = new Command();
17
-
18
- program
19
- .name('dhil-ui')
20
- .description('Add ultra-premium React components to your project')
21
- .version('1.0.0');
22
-
23
- // --- INIT COMMAND ---
24
- program
25
- .command('init')
26
- .description('Initialize your project and choose your components directory')
27
- .action(async () => {
28
- console.log(pc.bold(pc.red('Welcome to dhil.dev CLI\n')));
29
-
30
- const response = await prompts({
31
- type: 'text',
32
- name: 'componentsDir',
33
- message: 'Where is your components directory?',
34
- initial: 'components/ui'
35
- });
36
-
37
- if (!response.componentsDir) {
38
- console.log(pc.red('Operation cancelled.'));
39
- process.exit(1);
40
- }
41
-
42
- const config = {
43
- componentsDir: response.componentsDir
44
- };
45
-
46
- await fs.writeFile(
47
- path.join(process.cwd(), 'components.json'),
48
- JSON.stringify(config, null, 2)
49
- );
50
-
51
- console.log(pc.green(`\n✔ Configuration saved to components.json`));
52
- console.log(`\nYou can now run ${pc.cyan('npx dhil-ui add <component>')} to start building.`);
53
- });
54
-
55
- // --- ADD COMMAND ---
56
- program
57
- .command('add <componentId>')
58
- .description('Add a component to your project')
59
- .action(async (componentId) => {
60
- const spinner = ora(`Fetching ${componentId}...`).start();
61
-
62
- try {
63
- // 1. Fetch from Supabase
64
- const { data: component, error } = await supabase
65
- .from('components')
66
- .select(`
67
- id, name, tech_stack,
68
- component_versions (
69
- code_tsx, dependencies
70
- )
71
- `)
72
- .eq('id', componentId)
73
- .single();
74
-
75
- if (error || !component) {
76
- throw new Error(`Component not found or API error: ${error?.message || ''}`);
77
- }
78
-
79
- const version = component.component_versions[0];
80
- if (!version || !version.code_tsx) {
81
- throw new Error('No source code available for this component.');
82
- }
83
-
84
- spinner.text = `Installing ${component.name}...`;
85
-
86
- // 2. Determine target directory
87
- let targetDir = 'components/ui';
88
- try {
89
- const configRaw = await fs.readFile(path.join(process.cwd(), 'components.json'), 'utf-8');
90
- const config = JSON.parse(configRaw);
91
- if (config.componentsDir) {
92
- targetDir = config.componentsDir;
93
- }
94
- } catch (err) {
95
- // Default to components/ui if no config
96
- }
97
-
98
- // Ensure directory exists
99
- const absoluteTargetDir = path.join(process.cwd(), targetDir);
100
- await fs.mkdir(absoluteTargetDir, { recursive: true });
101
-
102
- // 3. Write File
103
- // Format filename (e.g. "Colorful 3D Text" -> "Colorful3DText.tsx")
104
- const fileName = component.name.replace(/[^a-zA-Z0-9]/g, '') + '.tsx';
105
- const filePath = path.join(absoluteTargetDir, fileName);
106
-
107
- await fs.writeFile(filePath, version.code_tsx);
108
-
109
- spinner.succeed(pc.green(`Added ${pc.bold(component.name)} to ${targetDir}/${fileName}`));
110
-
111
- // 4. Check dependencies
112
- if (version.dependencies && version.dependencies.length > 0) {
113
- console.log(pc.yellow(`\n⚠ Please ensure you have the following dependencies installed:`));
114
- console.log(pc.cyan(` npm install ${version.dependencies.join(' ')}`));
115
- }
116
-
117
- } catch (err) {
118
- spinner.fail(pc.red(err.message));
119
- process.exit(1);
120
- }
121
- });
122
-
123
- program.parse();