simpyui 0.2.5 → 1.0.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/dist/index.js +20 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as
|
|
3
|
-
`)}function
|
|
2
|
+
import{existsSync as to,mkdirSync as ho,writeFileSync as jo,readFileSync as So}from"node:fs";import{join as Y,dirname as Co}from"node:path";import{existsSync as m,readFileSync as U,writeFileSync as C,mkdirSync as ao}from"node:fs";import{execSync as po}from"node:child_process";import{join as g,dirname as go}from"node:path";var d=o=>`\x1B[1m${o}\x1B[0m`,y=o=>`\x1B[32m${o}\x1B[0m`,r=o=>`\x1B[36m${o}\x1B[0m`,j=o=>`\x1B[33m${o}\x1B[0m`,$=o=>`\x1B[31m${o}\x1B[0m`,t=o=>`\x1B[2m${o}\x1B[0m`;var q="components.json";function k(){let o=process.cwd();return m(g(o,"next.config.js"))||m(g(o,"next.config.mjs"))||m(g(o,"next.config.ts"))?"nextjs":m(g(o,"vite.config.js"))||m(g(o,"vite.config.ts"))||m(g(o,"vite.config.mjs"))?"vite":"unknown"}function M(){switch(k()){case"nextjs":return{componentDir:"src/components/ui",utilsDir:"src/lib",typescript:!0};case"vite":return{componentDir:"src/components/ui",utilsDir:"src/lib",typescript:!0};default:return{componentDir:"src/components/ui",utilsDir:"src/lib",typescript:!0}}}function G(){let o=g(process.cwd(),q);if(!m(o))return null;try{let e=JSON.parse(U(o,"utf-8"));if(!e.utilsDir){let n=k();e.utilsDir="src/lib"}return e}catch{return null}}function _(o){let e=g(process.cwd(),q);C(e,JSON.stringify(o,null,2)+`
|
|
3
|
+
`)}function fo(){return m(g(process.cwd(),"package.json"))}function H(){fo()||(console.log($(" \u2717 No package.json found in current directory.")),console.log(),console.log(t(" Run this inside a React project:")),console.log(r(" npx create-next-app@latest my-app")),console.log(t(" or")),console.log(r(" npm create vite@latest my-app")),console.log(),process.exit(1));let o=G();if(!o){let e=k(),n=M();return console.log(t(` Detected ${e==="nextjs"?"Next.js":e==="vite"?"Vite":"React"} project`)),console.log(t(" Creating components.json with defaults:")),console.log(t(` components \u2192 ${n.componentDir}`)),console.log(t(` utils \u2192 ${n.utilsDir}`)),console.log(t(` typescript \u2192 ${n.typescript}`)),console.log(),_(n),n}return o}var mo=`import { clsx, type ClassValue } from "clsx"
|
|
4
4
|
import { twMerge } from "tailwind-merge"
|
|
5
5
|
|
|
6
6
|
export function cn(...inputs: ClassValue[]) {
|
|
7
7
|
return twMerge(clsx(inputs))
|
|
8
8
|
}
|
|
9
|
-
`,
|
|
9
|
+
`,uo=`import { clsx } from "clsx"
|
|
10
10
|
import { twMerge } from "tailwind-merge"
|
|
11
11
|
|
|
12
12
|
export function cn(...inputs) {
|
|
13
13
|
return twMerge(clsx(inputs))
|
|
14
14
|
}
|
|
15
|
-
`;function
|
|
16
|
-
`);
|
|
17
|
-
${
|
|
15
|
+
`;function K(o){let e=o.typescript?"ts":"js",n=g(process.cwd(),o.utilsDir,`utils.${e}`),c=[];if(!m(n)){ao(go(n),{recursive:!0}),C(n,o.typescript?mo:uo),console.log(y(" \u2713 Created ")+t(`${o.utilsDir}/utils.${e}`));let s=A();s.has("clsx")||c.push("clsx"),s.has("tailwind-merge")||c.push("tailwind-merge")}return c}var yo={brand:{50:"#f0f4ff",100:"#dbe4ff",200:"#bac8ff",300:"#91a7ff",400:"#748ffc",500:"#5c7cfa",600:"#4c6ef5",700:"#4263eb",800:"#3b5bdb",900:"#364fc7"},dark:{50:"#C1C2C5",100:"#A6A7AB",200:"#909296",300:"#5C5F66",400:"#373A40",500:"#2C2E33",600:"#25262B",700:"#1A1B1E",800:"#141517",900:"#101113"}};function Q(){let o=process.cwd(),e=["tailwind.config.js","tailwind.config.ts","tailwind.config.mjs","tailwind.config.cjs"],n="";for(let p of e)if(m(g(o,p))){n=p;break}if(!n){console.log(j(" \u26A0 No tailwind.config found \u2014 skipping color injection")),console.log(t(" Add brand & dark color scales manually (see docs)"));return}let c=g(o,n),s=U(c,"utf-8");if(s.includes("brand:")&&s.includes("dark:"))return;let i=[];s.includes("brand:")||i.push("brand"),s.includes("dark:")||i.push("dark");let a="";for(let p of i){let f=yo[p],w=Object.entries(f).map(([x,h])=>` ${x}: '${h}'`).join(`,
|
|
16
|
+
`);a+=` ${p}: {
|
|
17
|
+
${w},
|
|
18
18
|
},
|
|
19
|
-
`}if(s.includes("colors:")&&s.includes("extend:")){let
|
|
20
|
-
${
|
|
19
|
+
`}if(s.includes("colors:")&&s.includes("extend:")){let p=s.replace(/(colors\s*:\s*\{)/,`$1
|
|
20
|
+
${a}`);C(c,p),console.log(y(" \u2713 Added ")+t(`${i.join(" & ")} colors \u2192 ${n}`))}else if(s.includes("extend:")){let p=s.replace(/(extend\s*:\s*\{)/,`$1
|
|
21
21
|
colors: {
|
|
22
|
-
${
|
|
22
|
+
${a} },`);C(c,p),console.log(y(" \u2713 Added ")+t(`${i.join(" & ")} colors \u2192 ${n}`))}else console.log(j(" \u26A0 Could not auto-inject colors into "+n)),console.log(t(" Add brand & dark color scales manually (see docs)"))}var $o=`
|
|
23
23
|
/* ============ SimpyUI Glow Effects ============ */
|
|
24
24
|
.glow {
|
|
25
25
|
box-shadow: 0 0 60px rgba(0, 150, 255, 0.15);
|
|
@@ -28,14 +28,16 @@ ${y} },`);S(i,d),console.log(f(" \u2713 Added ")+t(`${l.join(" & ")} color
|
|
|
28
28
|
.glow-sm {
|
|
29
29
|
box-shadow: 0 0 30px rgba(0, 150, 255, 0.1);
|
|
30
30
|
}
|
|
31
|
-
`;function
|
|
32
|
-
`)}}}async function
|
|
33
|
-
|
|
34
|
-
`)
|
|
35
|
-
`);
|
|
31
|
+
`;function X(){let o=process.cwd(),e=["src/index.css","src/globals.css","src/app/globals.css","app/globals.css","styles/globals.css","src/styles/globals.css"],n="";for(let i of e)if(m(g(o,i))){n=i;break}if(!n)return;let c=g(o,n),s=U(c,"utf-8");s.includes(".glow-sm")||s.includes("SimpyUI Glow Effects")||(C(c,s+$o),console.log(y(" \u2713 Added ")+t(`glow utilities \u2192 ${n}`)))}function wo(){let o=process.cwd();return m(g(o,"bun.lockb"))||m(g(o,"bun.lock"))?"bun":m(g(o,"pnpm-lock.yaml"))?"pnpm":m(g(o,"yarn.lock"))?"yarn":"npm"}function xo(o,e){let n=e.join(" ");switch(o){case"bun":return`bun add ${n}`;case"pnpm":return`pnpm add ${n}`;case"yarn":return`yarn add ${n}`;default:return`npm install ${n}`}}function oo(o){if(o.length===0)return;let e=wo(),n=xo(e,o);console.log(t(` $ ${n}`));try{po(n,{stdio:"pipe",cwd:process.cwd()})}catch{console.log(j(` \u26A0 Failed to install. Run manually: ${n}`))}}function A(){let o=g(process.cwd(),"package.json");if(!m(o))return new Set;try{let e=JSON.parse(U(o,"utf-8"));return new Set([...Object.keys(e.dependencies||{}),...Object.keys(e.devDependencies||{})])}catch{return new Set}}async function F(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to fetch ${o} (${e.status})`);return e.text()}function D(o){let e=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],n=0,c=setInterval(()=>{process.stdout.write(`\r${r(e[n++%e.length])} ${o}`)},80);return{stop(s){clearInterval(c),process.stdout.write(`\r${s||""}
|
|
32
|
+
`)}}}async function O(o,e=""){let n=e?` ${t(`(${e})`)}`:"";return process.stdout.write(`${o}${n}: `),new Promise(c=>{let s="";process.stdin.setEncoding("utf-8"),process.stdin.resume(),process.stdin.once("data",i=>{s=i.trim(),process.stdin.pause(),c(s||e)})})}async function J(o,e=!0){let c=await O(`${o} ${t(`[${e?"Y/n":"y/N"}]`)}`);return c?c.toLowerCase().startsWith("y"):e}var bo="https://raw.githubusercontent.com/AbhishekS04/SimpyUI/main/registry.json",B=null;async function v(){if(B)return B;try{let o=await F(bo),e=JSON.parse(o);return B=e,e}catch(o){console.log($(`
|
|
33
|
+
\u2717 Failed to fetch component registry from GitHub.`)),console.log(t(` ${o.message}`)),console.log(t(` Check your internet connection and try again.
|
|
34
|
+
`)),process.exit(1)}}function P(){console.log(),console.log(d(r(" \u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E"))),console.log(d(r(" \u2502 SimpyUI CLI \u2502"))),console.log(d(r(" \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"))),console.log()}async function ko(){P(),G()&&(await J(j(" components.json already exists. Overwrite?"),!1)||(console.log(t(" Cancelled.")),process.exit(0)));let e=k(),n=M();console.log(t(` Detected ${d(e==="nextjs"?"Next.js":e==="vite"?"Vite":"React")} project
|
|
35
|
+
`));let s=await O(` ${d("Component directory")}`,n.componentDir),i=await O(` ${d("Utils directory")}`,n.utilsDir),a=await J(` ${d("Use TypeScript?")}`,!0);_({componentDir:s,utilsDir:i,typescript:a}),console.log(),console.log(y(" \u2713 Created components.json")),console.log(t(` Components \u2192 ${s}/`)),console.log(t(` Utils \u2192 ${i}/`)),console.log(),console.log(` ${d("Next step:")} Run ${r("npx simpyui@latest add button")} to add your first component.`),console.log()}async function Do(){P();let o=D("Fetching component registry..."),{components:e}=await v();o.stop(),console.log(` ${d("Available components:")}
|
|
36
|
+
`);let n={};for(let s of Object.values(e)){let i=s.category||"Other";n[i]||(n[i]=[]),n[i].push(s)}for(let[s,i]of Object.entries(n)){console.log(` ${d(r(s))}`);for(let a of i){let p=Object.entries(e).find(([,w])=>w===a)?.[0]||"",f=a.dependencies.length?t(` \u2192 ${a.dependencies.join(", ")}`):"";console.log(` ${y("\u2022")} ${d(p.padEnd(18))} ${t(a.description)}${f}`)}console.log()}let c=Object.keys(e).length;console.log(t(` Total: ${c} components`)),console.log(),console.log(` ${t("Usage:")} ${r("npx simpyui add <name>")}`),console.log()}async function eo(o){P();let e=H(),n=D("Fetching component registry..."),{baseUrl:c,components:s}=await v(),i=Object.keys(s);n.stop();let a=o.includes("--all"),p=o.filter(l=>!l.startsWith("-")),f=[];if(a)f=[...i],console.log(` Adding ${d("all")} ${r(String(f.length))} components...
|
|
37
|
+
`);else if(p.length===0)console.log($(" \u2717 Please specify component name(s).")),console.log(),console.log(` ${t("Usage:")} ${r("npx simpyui add button card modal")}`),console.log(` ${t(" ")} ${r("npx simpyui add --all")}`),console.log(),console.log(` ${t("Run")} ${r("npx simpyui list")} ${t("to see all available components.")}`),console.log(),process.exit(1);else{let l=p.filter(u=>!s[u]);l.length>0&&(console.log($(` \u2717 Unknown component(s): ${l.join(", ")}`)),console.log(),console.log(` ${t("Run")} ${r("npx simpyui list")} ${t("to see all available components.")}`),console.log(),process.exit(1)),f=p}let w=new Set;function x(l){if(w.has(l))return;let u=s[l];if(u){for(let b of u.internal)x(b);w.add(l)}}for(let l of f)x(l);f=[...w];let h=new Set;for(let l of f)for(let u of s[l].dependencies)h.add(u);let so=K(e);for(let l of so)h.add(l);Q(),X();let co=A(),N=[...h].filter(l=>!co.has(l)),W=D("Downloading components..."),V=0,L=0;for(let l of f){let u=s[l];for(let b of u.files){let ro=`${c}/${b}`,Z=b.split("/").pop(),lo=e.typescript?Z:Z.replace(".tsx",".jsx"),T=Y(process.cwd(),e.componentDir,lo);if(to(T)){L++;continue}try{let S=await F(ro);e.typescript||(S=vo(S)),ho(Co(T),{recursive:!0}),jo(T,S),V++}catch(S){W.stop($(` \u2717 Failed to download ${b}`)),console.log(t(` ${S.message}`))}}}W.stop(y(` \u2713 Downloaded ${V} file(s)`)+(L?t(` (${L} already existed)`):"")),N.length>0?(console.log(),console.log(` ${d("Installing dependencies:")} ${r(N.join(", "))}`),oo(N),console.log(y(" \u2713 Dependencies installed"))):h.size>0&&console.log(t(" \u2713 All dependencies already installed")),console.log(),console.log(y(" Done! ")+t("Components added:"));for(let l of f){let u=s[l],b=u.files[0].split("/").pop();console.log(` ${y("\u2022")} ${d(u.name)} \u2192 ${t(`${e.componentDir}/${b}`)}`)}console.log();let z=f[0],R=s[z],E=R.files[0].split("/").pop().replace(".tsx","").replace(".jsx",""),io=Y(process.cwd(),e.componentDir,R.files[0].split("/").pop()),I="";try{let l=So(io,"utf-8"),u=R.name.replace(/\s+/g,"");l.includes("export default")?I=`import ${u} from "@/${e.componentDir}/${E}"`:I=`import { ${u} } from "@/${e.componentDir}/${E}"`}catch{I=`import ${R.name.replace(/\s+/g,"")} from "@/${e.componentDir}/${E}"`}console.log(t(" Import:")),console.log(r(` ${I}`)),console.log(),console.log(t(` Docs \u2192 ${r(`https://simpyui.vercel.app/components/${z}`)}`)),console.log()}function vo(o){return o.replace(/: string/g,"").replace(/: number/g,"").replace(/: boolean/g,"").replace(/: ReactNode/g,"").replace(/: React\.ReactNode/g,"").replace(/<[A-Z]\w+Props>/g,"").replace(/interface \w+ \{[^}]*\}/gs,"").replace(/type \w+ = [^;\n]+;?/g,"").replace(/export type \w+ = [^;\n]+;?/g,"").replace(/export interface \w+ \{[^}]*\}/gs,"").replace(/import \{ type \w+[\s\S]*?\} from/g,"import {").replace(/import type \{[^}]*\} from '[^']+'\n?/g,"").replace(/, type \w+/g,"").replace(/as const/g,"").replace(/<HTMLMotionProps<'[^']*'>>/g,"").replace(/Omit<\w+<'[^']*'>,\s*'[^']*'>/g,"").replace(/Record<\w+,\s*\w+>/g,"").replace(/\.tsx/g,".jsx").replace(/\n{3,}/g,`
|
|
36
38
|
|
|
37
|
-
`)}function
|
|
38
|
-
Unknown command: ${
|
|
39
|
-
`)),
|
|
40
|
-
Error: ${
|
|
39
|
+
`)}async function Po(o){P();let e=H(),n=D("Fetching component registry..."),{components:c}=await v();n.stop();let s=o.filter(i=>!i.startsWith("-"));s.length===0&&(console.log($(" \u2717 Specify a component name.")),process.exit(1));for(let i of s){let a=c[i];if(!a){console.log($(` \u2717 Unknown component: ${i}`));continue}let p=a.files[0].split("/").pop(),f=Y(process.cwd(),e.componentDir,p);if(to(f)?console.log(j(` \u25CF ${a.name}`),t("\u2014 already exists")):console.log(y(` + ${a.name}`),t(`\u2192 ${e.componentDir}/${p}`)),a.dependencies.length>0){let w=A();for(let x of a.dependencies)w.has(x)?console.log(t(` \u2713 ${x} (installed)`)):console.log(r(` + ${x} (will install)`))}console.log()}}function no(){P(),console.log(` ${d("Usage:")} simpyui ${r("<command>")} ${t("[options]")}`),console.log(),console.log(` ${d("Commands:")}`),console.log(` ${r("init")} Configure SimpyUI for your project`),console.log(` ${r("add")} ${t("<name>")} Add component(s) to your project`),console.log(` ${r("add --all")} Add all components at once`),console.log(` ${r("list")} List all available components`),console.log(` ${r("diff")} ${t("<name>")} Preview what would be added`),console.log(` ${r("help")} Show this help message`),console.log(),console.log(` ${d("Examples:")}`),console.log(t(" $ npx simpyui init")),console.log(t(" $ npx simpyui add button")),console.log(t(" $ npx simpyui add button card modal toast")),console.log(t(" $ npx simpyui add --all")),console.log()}async function Ro(){let o=process.argv.slice(2),e=o[0];switch(e){case"init":await ko();break;case"add":await eo(o.slice(1));break;case"list":case"ls":await Do();break;case"diff":await Po(o.slice(1));break;case"help":case"--help":case"-h":case void 0:no();break;default:try{let{components:n}=await v();if(n[e]){await eo(o);break}}catch{}console.log($(`
|
|
40
|
+
Unknown command: ${e}
|
|
41
|
+
`)),no()}}Ro().catch(o=>{console.error($(`
|
|
42
|
+
Error: ${o.message}
|
|
41
43
|
`)),process.exit(1)});
|