nachui 1.0.2 → 1.0.3
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.es.md +52 -0
- package/README.md +52 -0
- package/dist/index.js +9 -8
- package/package.json +1 -1
package/README.es.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# NachUI CLI
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | [Español]
|
|
4
|
+
|
|
5
|
+
La Interfaz de Línea de Comandos oficial para el ecosistema NachUI. Diseñada para ayudarte a integrar, administrar y actualizar primitivas de React de alta fidelidad directamente en el código de tu proyecto sin complicaciones.
|
|
6
|
+
|
|
7
|
+
## Stack Tecnológico
|
|
8
|
+
|
|
9
|
+
- **Framework de CLI**: [Commander](https://github.com/tj/commander.js)
|
|
10
|
+
- **Prompts Interactivos**: [@clack/prompts](https://github.com/natemoo-re/clack)
|
|
11
|
+
- **Estilos de Consola**: [Kleur](https://github.com/lukeed/kleur)
|
|
12
|
+
- **Validación de Datos**: [Zod](https://zod.dev/)
|
|
13
|
+
|
|
14
|
+
## Características Clave
|
|
15
|
+
|
|
16
|
+
### 1. Integración Radicalmente Simple
|
|
17
|
+
|
|
18
|
+
Inicializa NachUI en tu entorno de trabajo, configura tu proyecto y agrega componentes de React diseñados a la perfección directamente en tu código fuente. Tú eres el dueño del código.
|
|
19
|
+
|
|
20
|
+
### 2. Flujo de Trabajo Optimizado
|
|
21
|
+
|
|
22
|
+
Administra el ciclo de vida completo de tus componentes desde la terminal: lista las primitivas disponibles, agrega nuevas, actualiza las existentes de manera sencilla, o elimina las que ya no necesitas.
|
|
23
|
+
|
|
24
|
+
### 3. Prioridad a la Experiencia del Desarrollador
|
|
25
|
+
|
|
26
|
+
Construido con prompts interactivos elegantes, validación de errores útil y comandos intuitivos que respetan tu tiempo.
|
|
27
|
+
|
|
28
|
+
## Uso
|
|
29
|
+
|
|
30
|
+
Puedes ejecutar el CLI directamente a través de `npx` (o tu gestor de paquetes preferido) sin necesidad de instalarlo globalmente.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Inicializar NachUI en tu proyecto
|
|
34
|
+
npx nachui init
|
|
35
|
+
|
|
36
|
+
# Agregar un componente específico
|
|
37
|
+
npx nachui add button
|
|
38
|
+
|
|
39
|
+
# Listar todos los componentes disponibles
|
|
40
|
+
npx nachui list
|
|
41
|
+
|
|
42
|
+
# Actualizar un componente instalado
|
|
43
|
+
npx nachui update button
|
|
44
|
+
|
|
45
|
+
# Eliminar un componente instalado
|
|
46
|
+
npx nachui remove button
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Arquitectura
|
|
50
|
+
|
|
51
|
+
- `src/commands`: Contiene todas las acciones del CLI (`init`, `add`, `list`, `update`, `remove`).
|
|
52
|
+
- `src/index.ts`: El punto de entrada principal que procesa y ejecuta los comandos mediante `commander`.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# NachUI CLI
|
|
2
|
+
|
|
3
|
+
[English] | [Español](./README.es.md)
|
|
4
|
+
|
|
5
|
+
The official Command Line Interface for the NachUI ecosystem. Designed to help you seamlessly integrate, manage, and update high-fidelity React primitives directly into your codebase.
|
|
6
|
+
|
|
7
|
+
## Tech Stack
|
|
8
|
+
|
|
9
|
+
- **CLI Framework**: [Commander](https://github.com/tj/commander.js)
|
|
10
|
+
- **Interactive Prompts**: [@clack/prompts](https://github.com/natemoo-re/clack)
|
|
11
|
+
- **Console Styling**: [Kleur](https://github.com/lukeed/kleur)
|
|
12
|
+
- **Data Validation**: [Zod](https://zod.dev/)
|
|
13
|
+
|
|
14
|
+
## Key Features
|
|
15
|
+
|
|
16
|
+
### 1. Radically Simple Integration
|
|
17
|
+
|
|
18
|
+
Initialize NachUI in your workspace, configure your environment, and add beautifully crafted React components directly to your source files. You own the code.
|
|
19
|
+
|
|
20
|
+
### 2. Streamlined Workflow
|
|
21
|
+
|
|
22
|
+
Manage your complete component lifecycle from the terminal: list available primitives, add new ones, seamlessly update existing ones, or remove those you no longer need.
|
|
23
|
+
|
|
24
|
+
### 3. Developer Experience First
|
|
25
|
+
|
|
26
|
+
Built with gorgeous interactive prompts, helpful validation, and intuitive commands that respect your time.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
You can run the CLI directly via `npx` (or your package manager of choice) without installing it globally.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Initialize NachUI in your project
|
|
34
|
+
npx nachui init
|
|
35
|
+
|
|
36
|
+
# Add a specific component
|
|
37
|
+
npx nachui add button
|
|
38
|
+
|
|
39
|
+
# List all available components
|
|
40
|
+
npx nachui list
|
|
41
|
+
|
|
42
|
+
# Update an installed component
|
|
43
|
+
npx nachui update button
|
|
44
|
+
|
|
45
|
+
# Remove an installed component
|
|
46
|
+
npx nachui remove button
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Architecture
|
|
50
|
+
|
|
51
|
+
- `src/commands`: Contains all CLI action logic (`init`, `add`, `list`, `update`, `remove`).
|
|
52
|
+
- `src/index.ts`: The main entry point parsing terminal instructions via `commander`.
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import*as
|
|
2
|
+
import*as D from"@clack/prompts";import{Command as ae}from"commander";import L from"kleur";import*as i from"@clack/prompts";import C from"kleur";import{execSync as re}from"child_process";import I from"fs";import z from"path";var J="https://api-nach-ui.vercel.app/api/v1",$={async getComponents(){let e=await fetch(`${J}/registry`);if(!e.ok)throw new Error("Error connecting to the API.");return e.json()},async getComponent(e){let n=await fetch(`${J}/registry/${e}`);if(!n.ok)throw n.status===404?new Error(`Component "${e}" does not exist in the registry.`):new Error("Error connecting to the API.");return n.json()},async getTheme(e="default"){let n=await fetch(`${J}/themes/${e}`);if(!n.ok)throw new Error("Failed to fetch styles");return n.json()},async getThemes(){let e=await fetch(`${J}/themes`);if(!e.ok)throw new Error("Error connecting to the API.");return e.json()}};import W from"fs";import _ from"path";function B(){let e=process.cwd();return W.existsSync(_.join(e,"pnpm-lock.yaml"))?"pnpm":W.existsSync(_.join(e,"yarn.lock"))?"yarn":W.existsSync(_.join(e,"bun.lockb"))?"bun":"npm"}function V(e,n){let t=n.join(" ");switch(e){case"pnpm":return`pnpm add ${t}`;case"yarn":return`yarn add ${t}`;case"bun":return`bun add ${t}`;default:return`npm install ${t}`}}async function Q(e){let n=i.spinner(),t=z.join(process.cwd(),"nachui.json");if(!I.existsSync(t)){i.log.error(C.red("Error: nachui.json not found. Please run 'nachui init' first."));return}let y=JSON.parse(I.readFileSync(t,"utf-8"));n.start(`Searching for ${C.cyan(e)} in the registry...`);try{let d=await $.getComponent(e);n.stop(`Component ${C.green(e)} found.`);let p=y.aliases.components.replace("@/","src/"),s=z.join(process.cwd(),p),h=z.join(s,`${e}.tsx`);if(I.existsSync(s)||I.mkdirSync(s,{recursive:!0}),I.writeFileSync(h,d.code),i.note(C.gray(`Location: ${h}`),"Component installed"),d.dependencies&&d.dependencies.length>0){let g=z.join(process.cwd(),"package.json");if(I.existsSync(g)){let U=JSON.parse(I.readFileSync(g,"utf-8")),S={...U.dependencies,...U.devDependencies},j=d.dependencies.filter(w=>!S[w]);if(j.length>0){i.log.warn(`Missing dependencies: ${C.yellow(j.join(", "))}`);let w=await i.confirm({message:"Do you want to install missing dependencies?",initialValue:!0});if(w&&!i.isCancel(w)){let E=i.spinner();E.start("Installing dependencies...");try{let M=B(),R=V(M,j);re(R,{stdio:"inherit"}),E.stop(C.green("Dependencies installed successfully."))}catch{E.stop(C.red("Failed to install dependencies.")),i.log.error("Please run the command manually.")}}}else i.log.info(C.green("\u2713 All dependencies are already present."))}}i.outro(C.bgGreen().black(" NachUI ")+" Component ready to use!")}catch{n.stop(C.red("Error getting the component.")),i.log.error("Make sure the slug is correct or the API is online.")}}import*as o from"@clack/prompts";import c from"kleur";import{execSync as ie}from"child_process";import r from"fs";import l from"path";async function X(){o.intro(c.bgCyan().black(" NachUI - Initialization "));let e=o.spinner(),n=process.cwd();try{e.start("Fetching available themes...");let t=await $.getThemes();e.stop(c.green("Themes loaded."));let y=await o.select({message:"Select a theme for your project:",options:t.map(f=>({value:f,label:f.charAt(0).toUpperCase()+f.slice(1)})),initialValue:"default"});if(o.isCancel(y)){o.cancel("Operation cancelled.");return}e.start(`Downloading ${c.cyan(y)} assets...`);let{css:d,config:p,utils:s}=await $.getTheme(y);e.stop(c.green(`Assets for ${y} ready.`));let h=r.existsSync(l.join(n,"next.config.mjs"))||r.existsSync(l.join(n,"next.config.js")),g="";h?g=["src/app/globals.css","app/globals.css","src/pages/globals.css","pages/globals.css"].find(F=>r.existsSync(l.join(n,F)))||(r.existsSync(l.join(n,"src"))?"src/app/globals.css":"app/globals.css"):g=["src/index.css","index.css","src/main.css","main.css"].find(F=>r.existsSync(l.join(n,F)))||(r.existsSync(l.join(n,"src"))?"src/index.css":"index.css");let U={...p,tailwind:{...p.tailwind,css:g}};r.writeFileSync(l.join(n,"nachui.json"),JSON.stringify(U,null,2));let S=l.join(n,g),j=d.replace(/@source\s+['"][^'"]+['"];\n/g,""),w="/* NachUI Tokens */",E=`
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
${
|
|
6
|
-
|
|
4
|
+
${w}
|
|
5
|
+
${j}`;if(r.existsSync(S)){let f=r.readFileSync(S,"utf8");if(!f.includes(w))r.appendFileSync(S,E);else{let T=f.split(w)[0]+w+`
|
|
6
|
+
`+j;r.writeFileSync(S,T.trim()),o.log.info(c.blue("Styles updated in your existing CSS file."))}}else r.mkdirSync(l.dirname(S),{recursive:!0}),r.writeFileSync(S,`${w}
|
|
7
|
+
${j}`);let M=p.aliases.utils.replace("@/","src/")+".ts",R=l.join(n,M);r.existsSync(l.dirname(R))||r.mkdirSync(l.dirname(R),{recursive:!0}),r.writeFileSync(R,s);let te=["clsx","tailwind-merge"],K=l.join(n,"package.json");if(r.existsSync(K)){let f=JSON.parse(r.readFileSync(K,"utf-8")),F={...f.dependencies,...f.devDependencies},T=te.filter(O=>!F[O]);if(T.length>0){o.log.warn(`Missing required utilities: ${c.yellow(T.join(", "))}`);let O=await o.confirm({message:"Install clsx and tailwind-merge?",initialValue:!0});if(O&&!o.isCancel(O)){let q=o.spinner();q.start("Installing core dependencies...");try{let oe=B(),se=V(oe,T);ie(se,{stdio:"ignore"}),q.stop(c.green("Core dependencies installed."))}catch{q.stop(c.red("Failed to install automatically.")),o.log.info(`Please run manually: ${c.cyan(`npm install ${T.join(" ")}`)}`)}}}}o.note(`Theme: ${c.cyan(y)}
|
|
7
8
|
Config: nachui.json
|
|
8
|
-
Styles: ${
|
|
9
|
-
Utils: ${
|
|
10
|
-
Details:`),
|
|
11
|
-
${
|
|
9
|
+
Styles: ${g}
|
|
10
|
+
Utils: ${M}`,"Setup complete"),o.outro(c.bgGreen().black(" NachUI ")+" Ready! Try adding a component: "+c.cyan("nachui add button"))}catch(t){e.stop(c.red("Init failed.")),console.error(c.red(`
|
|
11
|
+
Details:`),t)}}import*as k from"@clack/prompts";import v from"kleur";async function Y(){let e=k.spinner();e.start("Consulting NachUI registry...");try{let n=await $.getComponents();if(e.stop("Registry loaded successfully."),n.length===0){k.log.warn("There are no components in the registry yet.");return}console.log(""),k.log.step(v.cyan("Available components:")),n.forEach(t=>{console.log(` ${v.green("\u2192")} ${v.bold(t.name)} ${v.gray(`(${t.slug})`)}`),t.dependencies.length>0&&console.log(` ${v.dim(`Deps: ${t.dependencies.join(", ")}`)}`)}),console.log(""),k.note(`To install one, run:
|
|
12
|
+
${v.cyan("pnpm dlx nachui add <slug>")}`,"Tip")}catch{e.stop(v.red("Error connecting to the API.")),k.log.error("Make sure the API is running on the correct port.")}}import*as m from"@clack/prompts";import A from"fs";import x from"kleur";import H from"path";var Z=async e=>{let n=m.spinner(),t=H.resolve(process.cwd(),"src","components","ui"),y=e.endsWith(".tsx")?e:`${e}.tsx`,d=H.join(t,y),p=H.join(t,e);n.start(`Searching for ${x.cyan(e)}...`);try{let s="",h=!1;if(A.existsSync(d)?s=d:A.existsSync(p)&&A.lstatSync(p).isDirectory()&&(s=p,h=!0),s){n.stop(x.yellow(`Found: ${s}`));let g=await m.confirm({message:`Are you sure you want to delete ${x.red(e)}?`});if(m.isCancel(g)||!g){m.outro(x.gray("Operation cancelled."));return}h?A.rmSync(s,{recursive:!0,force:!0}):A.rmSync(s,{force:!0}),await new Promise(U=>setTimeout(U,100)),m.log.success(`${x.green("\u2713")} ${x.bold(e)} deleted.`),m.outro(x.bgRed().black(" NachUI ")+" Clean up complete.")}else n.stop(x.red("Error: Component not found.")),m.outro("Check the name and try again.")}catch(s){n.stop(x.red("Failed to delete.")),m.log.error(`Detail: ${s instanceof Error?s.message:String(s)}`)}};import*as a from"@clack/prompts";import u from"kleur";import G from"fs";import ee from"path";async function ne(e){let n=a.spinner(),t=ee.join(process.cwd(),"nachui.json");if(!G.existsSync(t)){a.log.error(u.red("Error: nachui.json not found. Please run 'nachui init' first."));return}let d=JSON.parse(G.readFileSync(t,"utf-8")).aliases.components.replace("@/","src/"),p=ee.join(process.cwd(),d,`${e}.tsx`);if(!G.existsSync(p)){a.log.error(u.red(`The component "${e}" is not installed in ${d}.`)),a.log.info(`Try using: ${u.cyan(`nachui add ${e}`)}`);return}n.start(`Fetching latest code for ${u.cyan(e)}...`);try{let s=await $.getComponent(e);n.stop(`Latest version of ${u.green(e)} fetched.`);let h=await a.confirm({message:`Update ${u.bold(e)}? This will ${u.red("overwrite")} your local changes.`,initialValue:!1});if(a.isCancel(h)||!h){a.outro(u.yellow("Update cancelled."));return}G.writeFileSync(p,s.code),a.note(u.gray(`Location: ${p}`),"Update successful"),a.outro(u.bgBlue().white(" NachUI ")+" Component updated to the latest registry version.")}catch{n.stop(u.red("Error updating.")),a.log.error("Check your internet connection or if the component slug is correct.")}}var N=new ae;N.name("nachui").description("NachUI CLI - Add, update, remove and list components").version("0.0.1");N.command("init").description("Initialize NachUI in your project").action(async()=>{console.log(""),D.intro(L.bgCyan().black(" NachUI CLI ")),await X()});N.command("add").description("Add a component to your project").argument("<component>","component slug").action(async e=>{console.log(""),D.intro(L.bgCyan().black(" NachUI CLI ")),await Q(e)});N.command("list").description("List all available components").action(async()=>{console.log(""),D.intro(L.bgCyan().black(" NachUI CLI ")),await Y()});N.command("update").description("Update an installed component").argument("<component>","component slug").action(async e=>{console.log(""),D.intro(L.bgCyan().black(" NachUI CLI ")),await ne(e)});N.command("remove").description("Remove an installed component").argument("<component>","component slug").action(async e=>{console.log(""),D.intro(L.bgCyan().black(" NachUI CLI ")),await Z(e)});N.parse();
|