nachui 1.0.4 → 1.0.6
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/dist/index.js +16 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import*as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
`+
|
|
6
|
-
|
|
7
|
-
`+
|
|
8
|
-
|
|
9
|
-
`+
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
import*as R from"@clack/prompts";import{Command as le}from"commander";import M from"kleur";import*as i from"@clack/prompts";import w from"kleur";import{execSync as ce}from"child_process";import F from"fs";import z from"path";var O="https://api-nach-ui.vercel.app/api/v1",x={async getComponents(){let e=await fetch(`${O}/registry`);if(!e.ok)throw new Error("Error connecting to the API.");return e.json()},async getComponent(e){let n=await fetch(`${O}/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(`${O}/themes/${e}`);if(!n.ok)throw new Error("Failed to fetch styles");return n.json()},async getThemes(){let e=await fetch(`${O}/themes`);if(!e.ok)throw new Error("Error connecting to the API.");return e.json()}};import q from"fs";import H from"path";function J(){let e=process.cwd();return q.existsSync(H.join(e,"pnpm-lock.yaml"))?"pnpm":q.existsSync(H.join(e,"yarn.lock"))?"yarn":q.existsSync(H.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 Y(e){let n=i.spinner(),t=z.join(process.cwd(),"nachui.json");if(!F.existsSync(t)){i.log.error(w.red("Error: nachui.json not found. Please run 'nachui init' first."));return}let h=JSON.parse(F.readFileSync(t,"utf-8"));n.start(`Searching for ${w.cyan(e)} in the registry...`);try{let d=await x.getComponent(e);n.stop(`Component ${w.green(e)} found.`);let p=h.aliases.components.replace("@/","src/"),r=z.join(process.cwd(),p),C=z.join(r,`${e}.tsx`);if(F.existsSync(r)||F.mkdirSync(r,{recursive:!0}),F.writeFileSync(C,d.code),i.note(w.gray(`Location: ${C}`),"Component installed"),d.dependencies&&d.dependencies.length>0){let k=z.join(process.cwd(),"package.json");if(F.existsSync(k)){let g=JSON.parse(F.readFileSync(k,"utf-8")),G={...g.dependencies,...g.devDependencies},u=d.dependencies.filter(T=>!G[T]);if(u.length>0){i.log.warn(`Missing dependencies: ${w.yellow(u.join(", "))}`);let T=await i.confirm({message:"Do you want to install missing dependencies?",initialValue:!0});if(T&&!i.isCancel(T)){let P=i.spinner();P.start("Installing dependencies...");try{let I=J(),E=V(I,u);ce(E,{stdio:"inherit"}),P.stop(w.green("Dependencies installed successfully."))}catch{P.stop(w.red("Failed to install dependencies.")),i.log.error("Please run the command manually.")}}}else i.log.info(w.green("\u2713 All dependencies are already present."))}}i.outro(w.bgGreen().black(" NachUI ")+" Component ready to use!")}catch{n.stop(w.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 $ from"kleur";import{execSync as pe}from"child_process";import s from"fs";import l from"path";async function Z(){o.intro($.bgCyan().black(" NachUI - Initialization "));let e=o.spinner(),n=process.cwd();try{e.start("Fetching available themes...");let t=await x.getThemes();e.stop($.green("Themes loaded."));let h=await o.select({message:"Select a theme for your project:",options:t.map(c=>({value:c,label:c.charAt(0).toUpperCase()+c.slice(1)})),initialValue:"default"});if(o.isCancel(h)){o.cancel("Operation cancelled.");return}e.start(`Downloading ${$.cyan(h)} assets...`);let{css:d,config:p,utils:r}=await x.getTheme(h);e.stop($.green(`Assets for ${h} ready.`));let k=["next.config.mjs","next.config.js","next.config.ts"].some(c=>s.existsSync(l.join(n,c))),g="";k?g=["src/app/globals.css","app/globals.css","src/pages/globals.css","pages/globals.css"].find(f=>s.existsSync(l.join(n,f)))||(s.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=>s.existsSync(l.join(n,f)))||(s.existsSync(l.join(n,"src"))?"src/index.css":"index.css");let G={...p,tailwind:{...p.tailwind,css:g}};s.writeFileSync(l.join(n,"nachui.json"),JSON.stringify(G,null,2));let u=l.join(n,g),T=d.replace(/@import\s+['"]tailwindcss['"];\n/g,"").replace(/@source\s+['"][^'"]+['"];\n/g,""),P="/* NachUI Tokens */",I='@import "tailwindcss";',E=`${P}
|
|
3
|
+
${T}`;if(s.existsSync(u)){let c=s.readFileSync(u,"utf8");if(c.includes(P)){let f=c.split(P),b=(f[0].includes(I)?f[0].trim():I+`
|
|
4
|
+
|
|
5
|
+
`+f[0].trim())+`
|
|
6
|
+
|
|
7
|
+
`+E;s.writeFileSync(u,b.trim())}else{let f=await o.confirm({message:`Existing styles detected in ${g}. Do you want to wipe them and apply NachUI reset?`,initialValue:!0});if(f&&!o.isCancel(f))s.writeFileSync(u,I+`
|
|
8
|
+
|
|
9
|
+
`+E),o.log.info($.blue("CSS file cleaned and NachUI tokens applied."));else{let b=c.includes(I)?"":I+`
|
|
10
|
+
|
|
11
|
+
`;s.writeFileSync(u,b+c.trim()+`
|
|
12
|
+
|
|
13
|
+
`+E)}}}else s.mkdirSync(l.dirname(u),{recursive:!0}),s.writeFileSync(u,I+`
|
|
14
|
+
|
|
15
|
+
`+E);let Q=l.join(n,"index.css");k&&s.existsSync(Q)&&g!=="index.css"&&s.unlinkSync(Q);let se=p.aliases.utils.replace("@/","src/")+".ts",W=l.join(n,se);s.existsSync(l.dirname(W))||s.mkdirSync(l.dirname(W),{recursive:!0}),s.writeFileSync(W,r);let re=["clsx","tailwind-merge"],X=l.join(n,"package.json");if(s.existsSync(X)){let c=JSON.parse(s.readFileSync(X,"utf-8")),f={...c.dependencies,...c.devDependencies},A=re.filter(b=>!f[b]);if(A.length>0){let b=await o.confirm({message:`Install missing dependencies: ${A.join(", ")}?`,initialValue:!0});if(b&&!o.isCancel(b)){let _=o.spinner();_.start("Installing...");try{let ie=J(),ae=V(ie,A);pe(ae,{stdio:"ignore"}),_.stop($.green("Installed."))}catch{_.stop($.red("Failed."))}}}}o.note(`Theme: ${h}
|
|
16
|
+
Styles: ${g}`,"Setup Successful"),o.outro($.bgGreen().black(" NachUI ")+" Ready!")}catch(t){e.stop($.red("Init failed.")),console.error(t)}}import*as j from"@clack/prompts";import U from"kleur";async function ee(){let e=j.spinner();e.start("Consulting NachUI registry...");try{let n=await x.getComponents();if(e.stop("Registry loaded successfully."),n.length===0){j.log.warn("There are no components in the registry yet.");return}console.log(""),j.log.step(U.cyan("Available components:")),n.forEach(t=>{console.log(` ${U.green("\u2192")} ${U.bold(t.name)} ${U.gray(`(${t.slug})`)}`),t.dependencies.length>0&&console.log(` ${U.dim(`Deps: ${t.dependencies.join(", ")}`)}`)}),console.log(""),j.note(`To install one, run:
|
|
17
|
+
${U.cyan("pnpm dlx nachui add <slug>")}`,"Tip")}catch{e.stop(U.red("Error connecting to the API.")),j.log.error("Make sure the API is running on the correct port.")}}import*as m from"@clack/prompts";import L from"fs";import S from"kleur";import K from"path";var ne=async e=>{let n=m.spinner(),t=K.resolve(process.cwd(),"src","components","ui"),h=e.endsWith(".tsx")?e:`${e}.tsx`,d=K.join(t,h),p=K.join(t,e);n.start(`Searching for ${S.cyan(e)}...`);try{let r="",C=!1;if(L.existsSync(d)?r=d:L.existsSync(p)&&L.lstatSync(p).isDirectory()&&(r=p,C=!0),r){n.stop(S.yellow(`Found: ${r}`));let k=await m.confirm({message:`Are you sure you want to delete ${S.red(e)}?`});if(m.isCancel(k)||!k){m.outro(S.gray("Operation cancelled."));return}C?L.rmSync(r,{recursive:!0,force:!0}):L.rmSync(r,{force:!0}),await new Promise(g=>setTimeout(g,100)),m.log.success(`${S.green("\u2713")} ${S.bold(e)} deleted.`),m.outro(S.bgRed().black(" NachUI ")+" Clean up complete.")}else n.stop(S.red("Error: Component not found.")),m.outro("Check the name and try again.")}catch(r){n.stop(S.red("Failed to delete.")),m.log.error(`Detail: ${r instanceof Error?r.message:String(r)}`)}};import*as a from"@clack/prompts";import y from"kleur";import B from"fs";import te from"path";async function oe(e){let n=a.spinner(),t=te.join(process.cwd(),"nachui.json");if(!B.existsSync(t)){a.log.error(y.red("Error: nachui.json not found. Please run 'nachui init' first."));return}let d=JSON.parse(B.readFileSync(t,"utf-8")).aliases.components.replace("@/","src/"),p=te.join(process.cwd(),d,`${e}.tsx`);if(!B.existsSync(p)){a.log.error(y.red(`The component "${e}" is not installed in ${d}.`)),a.log.info(`Try using: ${y.cyan(`nachui add ${e}`)}`);return}n.start(`Fetching latest code for ${y.cyan(e)}...`);try{let r=await x.getComponent(e);n.stop(`Latest version of ${y.green(e)} fetched.`);let C=await a.confirm({message:`Update ${y.bold(e)}? This will ${y.red("overwrite")} your local changes.`,initialValue:!1});if(a.isCancel(C)||!C){a.outro(y.yellow("Update cancelled."));return}B.writeFileSync(p,r.code),a.note(y.gray(`Location: ${p}`),"Update successful"),a.outro(y.bgBlue().white(" NachUI ")+" Component updated to the latest registry version.")}catch{n.stop(y.red("Error updating.")),a.log.error("Check your internet connection or if the component slug is correct.")}}var D=new le;D.name("nachui").description("NachUI CLI - Add, update, remove and list components").version("0.0.1");D.command("init").description("Initialize NachUI in your project").action(async()=>{console.log(""),R.intro(M.bgCyan().black(" NachUI CLI ")),await Z()});D.command("add").description("Add a component to your project").argument("<component>","component slug").action(async e=>{console.log(""),R.intro(M.bgCyan().black(" NachUI CLI ")),await Y(e)});D.command("list").description("List all available components").action(async()=>{console.log(""),R.intro(M.bgCyan().black(" NachUI CLI ")),await ee()});D.command("update").description("Update an installed component").argument("<component>","component slug").action(async e=>{console.log(""),R.intro(M.bgCyan().black(" NachUI CLI ")),await oe(e)});D.command("remove").description("Remove an installed component").argument("<component>","component slug").action(async e=>{console.log(""),R.intro(M.bgCyan().black(" NachUI CLI ")),await ne(e)});D.parse();
|