juas.dev 1.0.0 → 1.1.0
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 +118 -0
- package/bin/juas.js +91 -0
- package/package.json +50 -17
- package/src/commands/add.js +263 -0
- package/src/commands/init.js +52 -0
- package/src/commands/list.js +56 -0
- package/src/commands/login.js +351 -0
- package/src/commands/logout.js +25 -0
- package/src/commands/search.js +52 -0
- package/src/commands/whoami.js +119 -0
- package/src/lib/authApi.js +67 -0
- package/src/lib/config.js +48 -0
- package/src/lib/credentials.js +164 -0
- package/src/lib/deps.js +55 -0
- package/src/lib/logger.js +22 -0
- package/src/lib/supabase.js +81 -0
- package/index.js +0 -123
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
## Authentication & Access Verification
|
|
29
|
+
|
|
30
|
+
Free components can be installed anonymously. To verify your subscription tier, credit balance, or download **Pro / Lifetime** components via CLI, authenticate once:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Interactive browser login (loopback OAuth)
|
|
34
|
+
npx juas.dev login
|
|
35
|
+
|
|
36
|
+
# Headless / CI token login (recommended for servers & CI pipelines)
|
|
37
|
+
npx juas.dev login --token juas_user_your_key_here
|
|
38
|
+
|
|
39
|
+
# Verify your account, subscription tier, credits, and optional component access
|
|
40
|
+
npx juas.dev whoami
|
|
41
|
+
npx juas.dev whoami --check aurora-shader-card
|
|
42
|
+
|
|
43
|
+
# Clear local CLI credentials (~/.juas/credentials.json)
|
|
44
|
+
npx juas.dev logout
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
You can also pass `JUAS_API_TOKEN` as an environment variable or `--token <key>` per command.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# 1. Authenticate (optional for free components, required for Pro)
|
|
55
|
+
npx juas.dev login
|
|
56
|
+
|
|
57
|
+
# 2. Initialise (creates juas.config.json)
|
|
58
|
+
npx juas.dev init
|
|
59
|
+
|
|
60
|
+
# 3. Verify plan or component access
|
|
61
|
+
npx juas.dev whoami --check liquid-glass-button
|
|
62
|
+
|
|
63
|
+
# 4. Add a component by its slug
|
|
64
|
+
npx juas.dev add liquid-glass-button
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Commands
|
|
70
|
+
|
|
71
|
+
| Command | Description |
|
|
72
|
+
|---------|-------------|
|
|
73
|
+
| `npx juas.dev login` | Sign in via browser to authorize the CLI |
|
|
74
|
+
| `npx juas.dev login --token <key>` | Authenticate non-interactively with an API key |
|
|
75
|
+
| `npx juas.dev whoami` | Inspect signed-in account, tier, and credit balance |
|
|
76
|
+
| `npx juas.dev whoami --check <slug>` | Verify whether you can unlock `<slug>` via CLI |
|
|
77
|
+
| `npx juas.dev logout` | Remove saved local CLI credentials |
|
|
78
|
+
| `npx juas.dev init` | Set up juas in your project |
|
|
79
|
+
| `npx juas.dev add <slug>` | Install a component by slug (Free or unlocked Pro) |
|
|
80
|
+
| `npx juas.dev list` | Browse all available components |
|
|
81
|
+
| `npx juas.dev list --category buttons` | Filter by category |
|
|
82
|
+
| `npx juas.dev search "glass button"` | Search by name or tag |
|
|
83
|
+
| `npx juas.dev add <slug> --dry-run` | Preview without writing files |
|
|
84
|
+
| `npx juas.dev add <slug> --no-deps` | Skip npm dependency install |
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Configuration — `juas.config.json`
|
|
89
|
+
|
|
90
|
+
Created automatically by `npx juas.dev init`:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"outputDir": "src/components/juas",
|
|
95
|
+
"typescript": true,
|
|
96
|
+
"framework": "react"
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Requirements
|
|
103
|
+
|
|
104
|
+
- **Node.js** 18+
|
|
105
|
+
- **React** 18+
|
|
106
|
+
- **Tailwind CSS** v3 / v4 (recommended)
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Browse Components
|
|
111
|
+
|
|
112
|
+
Visit **[juas.dev](https://juas.dev)** to explore all available components.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
MIT — [juas.dev](https://juas.dev)
|
package/bin/juas.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ============================================================
|
|
3
|
+
// juas CLI — entry point
|
|
4
|
+
// npx juas.dev init
|
|
5
|
+
// npx juas.dev add <slug>
|
|
6
|
+
// npx juas.dev list
|
|
7
|
+
// npx juas.dev 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 { cmdLogin } from "../src/commands/login.js";
|
|
19
|
+
import { cmdLogout } from "../src/commands/logout.js";
|
|
20
|
+
import { cmdSearch } from "../src/commands/search.js";
|
|
21
|
+
import { cmdWhoami } from "../src/commands/whoami.js";
|
|
22
|
+
|
|
23
|
+
// ── Read version from package.json ──────────────────────────
|
|
24
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const pkg = JSON.parse(readFileSync(path.join(__dirname, "../package.json"), "utf-8"));
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.name("juas")
|
|
29
|
+
.description("Official CLI for juas.dev — install beautiful UI components into your project.")
|
|
30
|
+
.version(pkg.version, "-v, --version");
|
|
31
|
+
|
|
32
|
+
// ── juas init ───────────────────────────────────────────────
|
|
33
|
+
program
|
|
34
|
+
.command("init")
|
|
35
|
+
.description("Initialize juas in your project (creates juas.config.json)")
|
|
36
|
+
.option("--ts", "Use TypeScript (default)", true)
|
|
37
|
+
.option("--js", "Use JavaScript")
|
|
38
|
+
.option("--dir <dir>", "Component output directory", "src/components/juas")
|
|
39
|
+
.action(cmdInit);
|
|
40
|
+
|
|
41
|
+
// ── juas login ───────────────────────────────────────────────
|
|
42
|
+
program
|
|
43
|
+
.command("login")
|
|
44
|
+
.description("Authenticate CLI with your juas.dev account")
|
|
45
|
+
.option("--token <key>", "Authenticate with an existing Juas API key (CI/headless)")
|
|
46
|
+
.option("--no-browser", "Prompt for API key manually without opening a browser")
|
|
47
|
+
.option("--web-url <url>", "Override juas.dev base URL")
|
|
48
|
+
.action(cmdLogin);
|
|
49
|
+
|
|
50
|
+
// ── juas logout ──────────────────────────────────────────────
|
|
51
|
+
program
|
|
52
|
+
.command("logout")
|
|
53
|
+
.description("Remove saved local juas.dev credentials")
|
|
54
|
+
.action(cmdLogout);
|
|
55
|
+
|
|
56
|
+
// ── juas whoami ──────────────────────────────────────────────
|
|
57
|
+
program
|
|
58
|
+
.command("whoami")
|
|
59
|
+
.description("Verify current account identity, plan tier, credits, and access")
|
|
60
|
+
.option("--check <slug>", "Verify download entitlement for a specific component slug")
|
|
61
|
+
.option("--token <key>", "Verify a specific token without reading ~/.juas")
|
|
62
|
+
.option("--web-url <url>", "Override juas.dev base URL")
|
|
63
|
+
.option("--json", "Output machine-readable JSON")
|
|
64
|
+
.action(cmdWhoami);
|
|
65
|
+
|
|
66
|
+
// ── juas add <slug> ──────────────────────────────────────────
|
|
67
|
+
program
|
|
68
|
+
.command("add <slug>")
|
|
69
|
+
.description("Add a component by its slug from juas.dev")
|
|
70
|
+
.option("--dir <dir>", "Override output directory")
|
|
71
|
+
.option("--token <key>", "Authenticate this request with a specific token")
|
|
72
|
+
.option("--no-deps", "Skip installing npm dependencies")
|
|
73
|
+
.option("--dry-run", "Preview what would be written without writing files")
|
|
74
|
+
.action(cmdAdd);
|
|
75
|
+
|
|
76
|
+
// ── juas list ────────────────────────────────────────────────
|
|
77
|
+
program
|
|
78
|
+
.command("list")
|
|
79
|
+
.description("List all available components on juas.dev")
|
|
80
|
+
.option("--category <cat>", "Filter by category")
|
|
81
|
+
.option("--json", "Output raw JSON")
|
|
82
|
+
.action(cmdList);
|
|
83
|
+
|
|
84
|
+
// ── juas search <query> ──────────────────────────────────────
|
|
85
|
+
program
|
|
86
|
+
.command("search <query>")
|
|
87
|
+
.description("Search components by name, tag or description")
|
|
88
|
+
.option("--json", "Output raw JSON")
|
|
89
|
+
.action(cmdSearch);
|
|
90
|
+
|
|
91
|
+
program.parseAsync(process.argv);
|
package/package.json
CHANGED
|
@@ -1,17 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "juas.dev",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "CLI for juas.dev components",
|
|
5
|
-
"
|
|
6
|
-
"bin": {
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "juas.dev",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Official CLI for juas.dev — install beautiful UI components directly into your React project as source files.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"juas": "bin/juas.js",
|
|
8
|
+
"juas.dev": "bin/juas.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"src",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "node bin/juas.js",
|
|
17
|
+
"test": "node bin/juas.js --version"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"juas",
|
|
21
|
+
"juas.dev",
|
|
22
|
+
"ui",
|
|
23
|
+
"components",
|
|
24
|
+
"cli",
|
|
25
|
+
"react",
|
|
26
|
+
"tailwindcss",
|
|
27
|
+
"design-system",
|
|
28
|
+
"shadcn",
|
|
29
|
+
"source-first"
|
|
30
|
+
],
|
|
31
|
+
"author": "dhileepkumar",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"commander": "^13.1.0",
|
|
35
|
+
"fs-extra": "^11.3.0",
|
|
36
|
+
"ora": "^8.2.0",
|
|
37
|
+
"picocolors": "^1.1.1"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18.0.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/dhiluxui/juas.dev"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://juas.dev"
|
|
50
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// commands/add.js — `juas add <slug>`
|
|
3
|
+
// ============================================================
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import ora from "ora";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import pc from "picocolors";
|
|
8
|
+
import { fetchCliComponent } from "../lib/authApi.js";
|
|
9
|
+
import { loadConfig } from "../lib/config.js";
|
|
10
|
+
import { getActiveToken } from "../lib/credentials.js";
|
|
11
|
+
import { detectPackageManager, getMissingPackages, installDependencies } from "../lib/deps.js";
|
|
12
|
+
import { logger } from "../lib/logger.js";
|
|
13
|
+
import { fetchComponentBySlug } from "../lib/supabase.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fetches component payload from the Worker CLI gateway (supporting Pro, Credit,
|
|
17
|
+
* and Free tiers) with a safe free-only anon Supabase fallback on transport errors.
|
|
18
|
+
*/
|
|
19
|
+
async function resolveComponentPayload(slug, token, baseUrl) {
|
|
20
|
+
try {
|
|
21
|
+
const gatewayRes = await fetchCliComponent(slug, { token, baseUrl });
|
|
22
|
+
if (gatewayRes.status === 404) {
|
|
23
|
+
return { notFound: true };
|
|
24
|
+
}
|
|
25
|
+
if (gatewayRes.ok && gatewayRes.data) {
|
|
26
|
+
const payload = gatewayRes.data;
|
|
27
|
+
if (payload.status === "locked") {
|
|
28
|
+
return {
|
|
29
|
+
locked: true,
|
|
30
|
+
component: { name: payload.name, slug: payload.slug, pricing_tier: payload.pricingTier },
|
|
31
|
+
message: payload.message,
|
|
32
|
+
unlockUrl: payload.unlockUrl,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (payload.status === "unlocked") {
|
|
36
|
+
return {
|
|
37
|
+
unlocked: true,
|
|
38
|
+
component: {
|
|
39
|
+
name: payload.name,
|
|
40
|
+
slug: payload.slug,
|
|
41
|
+
description: payload.description,
|
|
42
|
+
pricing_tier: payload.pricingTier || "free",
|
|
43
|
+
project_files: payload.projectFiles,
|
|
44
|
+
},
|
|
45
|
+
version: {
|
|
46
|
+
code_tsx: payload.code,
|
|
47
|
+
code_css: payload.codeCss || "",
|
|
48
|
+
dependencies: payload.dependencies || [],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
// Fallback strictly for free components if edge gateway is unreachable
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const direct = await fetchComponentBySlug(slug);
|
|
58
|
+
if (!direct) {
|
|
59
|
+
return { notFound: true };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { component, version } = direct;
|
|
63
|
+
if (component.pricing_tier && component.pricing_tier !== "free") {
|
|
64
|
+
return {
|
|
65
|
+
locked: true,
|
|
66
|
+
component,
|
|
67
|
+
message: token
|
|
68
|
+
? "Could not verify Pro entitlement cleanly against gateway."
|
|
69
|
+
: "Authentication required for Pro components. Run `npx juas.dev login`.",
|
|
70
|
+
unlockUrl: `https://juas.dev/component/${slug}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { unlocked: true, component, version };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function cmdAdd(slug, options) {
|
|
78
|
+
logger.banner();
|
|
79
|
+
|
|
80
|
+
const cwd = process.cwd();
|
|
81
|
+
const config = await loadConfig(cwd);
|
|
82
|
+
const outDir = path.resolve(cwd, options.dir || config.outputDir || "src/components/juas");
|
|
83
|
+
const { token, baseUrl } = getActiveToken(options.token);
|
|
84
|
+
|
|
85
|
+
// ── Fetch component from Juas CLI Gateway ───────────────────
|
|
86
|
+
const spinner = ora(`Fetching ${pc.bold(slug)} from juas.dev…`).start();
|
|
87
|
+
|
|
88
|
+
let resolved;
|
|
89
|
+
try {
|
|
90
|
+
resolved = await resolveComponentPayload(slug, token, baseUrl);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
spinner.fail("Network error.");
|
|
93
|
+
logger.error(err.message);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (resolved.notFound) {
|
|
98
|
+
spinner.fail(`Component "${slug}" not found on juas.dev.`);
|
|
99
|
+
logger.blank();
|
|
100
|
+
logger.info(`Search available components: ${pc.bold("npx juas.dev search " + slug)}`);
|
|
101
|
+
logger.info(`Browse all: ${pc.underline("https://juas.dev")}`);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (resolved.locked) {
|
|
106
|
+
const compName = resolved.component?.name || slug;
|
|
107
|
+
spinner.fail(`"${compName}" requires a Pro license or 1 credit to unlock source.`);
|
|
108
|
+
if (resolved.message) {
|
|
109
|
+
logger.warn(resolved.message);
|
|
110
|
+
}
|
|
111
|
+
if (!token) {
|
|
112
|
+
logger.info(`Sign in via CLI: ${pc.bold("npx juas.dev login")}`);
|
|
113
|
+
} else {
|
|
114
|
+
logger.info(`Check entitlement: ${pc.bold("npx juas.dev whoami --check " + slug)}`);
|
|
115
|
+
}
|
|
116
|
+
logger.info(`Unlock on web: ${pc.underline(resolved.unlockUrl || "https://juas.dev/component/" + slug)}`);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const { component, version } = resolved;
|
|
121
|
+
const projectFiles = parseProjectFiles(component.project_files);
|
|
122
|
+
const projectFileEntries = Object.entries(projectFiles);
|
|
123
|
+
|
|
124
|
+
if (!version?.code_tsx && projectFileEntries.length === 0) {
|
|
125
|
+
spinner.fail(`"${slug}" has no source code yet. It may still be processing.`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
spinner.succeed(`Found ${pc.bold(component.name)}`);
|
|
130
|
+
|
|
131
|
+
// ── Build file paths ────────────────────────────────────────
|
|
132
|
+
const useTs = config.typescript !== false;
|
|
133
|
+
const ext = useTs ? ".tsx" : ".jsx";
|
|
134
|
+
const compDir = path.resolve(outDir, slug);
|
|
135
|
+
const tsxFile = path.join(compDir, `${toPascalCase(slug)}${ext}`);
|
|
136
|
+
const cssFile = path.join(compDir, `${toPascalCase(slug)}.css`);
|
|
137
|
+
|
|
138
|
+
const safeMultiFiles = projectFileEntries
|
|
139
|
+
.map(([rawRel, content]) => ({ target: resolveSafeChildPath(compDir, rawRel), content }))
|
|
140
|
+
.filter((entry) => entry.target && typeof entry.content === "string");
|
|
141
|
+
|
|
142
|
+
if (options.dryRun) {
|
|
143
|
+
logger.blank();
|
|
144
|
+
logger.warn("Dry run — no files written.");
|
|
145
|
+
if (safeMultiFiles.length > 0) {
|
|
146
|
+
safeMultiFiles.forEach((f) => logger.label("Would write", f.target));
|
|
147
|
+
} else {
|
|
148
|
+
logger.label("Would write TSX", tsxFile);
|
|
149
|
+
if (version?.code_css) logger.label("Would write CSS", cssFile);
|
|
150
|
+
}
|
|
151
|
+
logger.blank();
|
|
152
|
+
showUsageSnippet(slug);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ── Write files ────────────────────────────────────────────
|
|
157
|
+
const fileSpinner = ora("Writing component files…").start();
|
|
158
|
+
try {
|
|
159
|
+
await fs.ensureDir(compDir);
|
|
160
|
+
if (safeMultiFiles.length > 0) {
|
|
161
|
+
for (const f of safeMultiFiles) {
|
|
162
|
+
await fs.outputFile(f.target, f.content, "utf-8");
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
await fs.outputFile(tsxFile, version.code_tsx, "utf-8");
|
|
166
|
+
if (version?.code_css?.trim()) {
|
|
167
|
+
await fs.outputFile(cssFile, version.code_css, "utf-8");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
fileSpinner.succeed("Files written.");
|
|
171
|
+
} catch (err) {
|
|
172
|
+
fileSpinner.fail("Failed to write files.");
|
|
173
|
+
logger.error(err.message);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ── Install missing npm dependencies ──────────────────────
|
|
178
|
+
const declaredDeps = version?.dependencies ?? [];
|
|
179
|
+
|
|
180
|
+
if (declaredDeps.length && options.deps !== false) {
|
|
181
|
+
const missing = getMissingPackages(declaredDeps, cwd);
|
|
182
|
+
if (missing.length) {
|
|
183
|
+
const pm = detectPackageManager(cwd);
|
|
184
|
+
const depSpinner = ora(
|
|
185
|
+
`Installing ${missing.length} dependenc${missing.length > 1 ? "ies" : "y"} via ${pm}…`
|
|
186
|
+
).start();
|
|
187
|
+
try {
|
|
188
|
+
installDependencies(missing, cwd);
|
|
189
|
+
depSpinner.succeed("Dependencies installed.");
|
|
190
|
+
} catch {
|
|
191
|
+
depSpinner.fail("Dependency install failed — install manually.");
|
|
192
|
+
logger.warn(`Run: ${pc.bold(pm + " install " + missing.join(" "))}`);
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
logger.success("All dependencies already installed.");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ── Summary ────────────────────────────────────────────────
|
|
200
|
+
logger.blank();
|
|
201
|
+
logger.divider();
|
|
202
|
+
logger.success(pc.bold(`${component.name} installed!`));
|
|
203
|
+
logger.divider();
|
|
204
|
+
logger.blank();
|
|
205
|
+
if (safeMultiFiles.length > 0) {
|
|
206
|
+
safeMultiFiles.forEach((f) => logger.label("File", path.relative(cwd, f.target)));
|
|
207
|
+
} else {
|
|
208
|
+
logger.label("File", path.relative(cwd, tsxFile));
|
|
209
|
+
if (version?.code_css?.trim()) logger.label("CSS", path.relative(cwd, cssFile));
|
|
210
|
+
}
|
|
211
|
+
if (component.description) logger.label("About", component.description);
|
|
212
|
+
logger.blank();
|
|
213
|
+
showUsageSnippet(slug);
|
|
214
|
+
logger.blank();
|
|
215
|
+
logger.info(`View on web: ${pc.underline("https://juas.dev/component/" + slug)}`);
|
|
216
|
+
logger.blank();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// ── Helpers ──────────────────────────────────────────────────
|
|
220
|
+
|
|
221
|
+
function parseProjectFiles(raw) {
|
|
222
|
+
let obj = raw;
|
|
223
|
+
if (typeof obj === "string" && obj.trim().startsWith("{")) {
|
|
224
|
+
try {
|
|
225
|
+
obj = JSON.parse(obj);
|
|
226
|
+
} catch {
|
|
227
|
+
return {};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return {};
|
|
231
|
+
const out = {};
|
|
232
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
233
|
+
const content =
|
|
234
|
+
typeof v === "string" ? v : v && typeof v === "object" ? v.code || v.content : "";
|
|
235
|
+
if (typeof content === "string" && content.length > 0) {
|
|
236
|
+
out[k] = content;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function resolveSafeChildPath(rootDir, rawRel) {
|
|
243
|
+
const cleaned = String(rawRel || "").replace(/^[/\\]+/, "").replace(/\\/g, "/");
|
|
244
|
+
if (!cleaned || cleaned.includes("\0")) return null;
|
|
245
|
+
const resolved = path.resolve(rootDir, cleaned);
|
|
246
|
+
if (!resolved.startsWith(rootDir + path.sep)) return null;
|
|
247
|
+
return resolved;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function toPascalCase(str) {
|
|
251
|
+
return str
|
|
252
|
+
.split(/[-_\s]+/)
|
|
253
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
254
|
+
.join("");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function showUsageSnippet(slug) {
|
|
258
|
+
const pascal = toPascalCase(slug);
|
|
259
|
+
console.log(pc.dim(" Usage:"));
|
|
260
|
+
console.log(pc.cyan(` import { ${pascal} } from "./${slug}/${pascal}";`));
|
|
261
|
+
console.log();
|
|
262
|
+
console.log(pc.cyan(` <${pascal} />`));
|
|
263
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// commands/init.js
|
|
3
|
+
// npx juas.dev 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.dev 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.dev 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.dev add <slug>")}`);
|
|
55
|
+
logger.blank();
|
|
56
|
+
}
|