simpyui 0.1.2 → 0.2.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 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as
|
|
3
|
-
`)}function
|
|
4
|
-
|
|
5
|
-
`));let o=await R(` ${c("Component directory")}`,"src/components/ui"),t=await O(` ${c("Use TypeScript?")}`,!0);j({componentDir:o,typescript:t}),console.log(),console.log(g(" \u2713 Created simpyui.json")),console.log(n(` Components will be added to: ${o}/`)),console.log(),console.log(` ${c("Next step:")} Run ${i("npx simpyui add button")} to add your first component.`),console.log()}function te(){b(),console.log(` ${c("Available components:")}
|
|
6
|
-
`);let e={};for(let o of Object.values(p)){let t=se(o.slug);e[t]||(e[t]=[]),e[t].push(o)}for(let[o,t]of Object.entries(e)){console.log(` ${c(i(o))}`);for(let r of t){let s=r.dependencies.length?n(` \u2192 ${r.dependencies.join(", ")}`):"";console.log(` ${g("\u2022")} ${c(r.slug.padEnd(16))} ${n(r.description)}${s}`)}console.log()}console.log(n(` Total: ${U.length} components`)),console.log(),console.log(` ${n("Usage:")} ${i("npx simpyui add <name>")}`),console.log()}function se(e){return{button:"General",card:"General",badge:"General",avatar:"General",input:"Inputs",toggle:"Inputs",accordion:"Data Display",tabs:"Data Display",progress:"Data Display",skeleton:"Data Display",modal:"Feedback",toast:"Feedback",alert:"Feedback",tooltip:"Overlay","social-stories":"Animation"}[e]||"Other"}async function _(e){b();let o=P(),t=e.includes("--all"),r=e.filter(l=>!l.startsWith("-")),s=[];if(t)s=[...U],console.log(` Adding ${c("all")} ${i(String(s.length))} components...
|
|
7
|
-
`);else if(r.length===0)console.log(m(" \u2717 Please specify component name(s).")),console.log(),console.log(` ${n("Usage:")} ${i("npx simpyui add button card modal")}`),console.log(` ${n(" ")} ${i("npx simpyui add --all")}`),console.log(),console.log(` ${n("Run")} ${i("npx simpyui list")} ${n("to see all available components.")}`),console.log(),process.exit(1);else{let l=r.filter(a=>!p[a]);l.length>0&&(console.log(m(` \u2717 Unknown component(s): ${l.join(", ")}`)),console.log(),console.log(` ${n("Run")} ${i("npx simpyui list")} ${n("to see all available components.")}`),console.log(),process.exit(1)),s=r}let d=new Set;function h(l){if(d.has(l))return;let a=p[l];if(a){for(let f of a.internal)h(f);d.add(l)}}for(let l of s)h(l);s=[...d];let $=new Set;for(let l of s)for(let a of p[l].dependencies)$.add(a);let x=F(),C=[...$].filter(l=>!x.has(l)),N=B("Downloading components..."),T=0,v=0;for(let l of s){let a=p[l];for(let f of a.files){let Z=`${M}/${f}`,D=f.split("/").pop(),ce=o.typescript?"":D.replace(".tsx",".jsx"),q=o.typescript?D:D.replace(".tsx",".jsx"),A=J(process.cwd(),o.componentDir,q);if(z(A)){v++;continue}try{let w=await L(Z);o.typescript||(w=ie(w)),V(oe(A),{recursive:!0}),ee(A,w),T++}catch(w){N.stop(m(` \u2717 Failed to download ${f}`)),console.log(n(` ${w.message}`))}}}N.stop(g(` \u2713 Downloaded ${T} file(s)`)+(v?n(` (${v} already existed)`):"")),C.length>0?(console.log(),console.log(` ${c("Installing dependencies:")} ${i(C.join(", "))}`),H(C),console.log(g(" \u2713 Dependencies installed"))):$.size>0&&console.log(n(" \u2713 All dependencies already installed")),console.log(),console.log(g(" Done! ")+n("Components added:"));for(let l of s){let a=p[l],f=a.files[0].split("/").pop();console.log(` ${g("\u2022")} ${c(a.name)} \u2192 ${n(`${o.componentDir}/${f}`)}`)}console.log(),s.includes("button")&&(console.log(n(" Import example:")),console.log(i(` import Button from './${o.componentDir}/button'`)),console.log())}function ie(e){return e.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,`
|
|
2
|
+
import{existsSync as Z,mkdirSync as ce,writeFileSync as le}from"node:fs";import{join as q,dirname as ae}from"node:path";import{existsSync as p,readFileSync as E,writeFileSync as M,mkdirSync as Y}from"node:fs";import{execSync as ee}from"node:child_process";import{join as a,dirname as oe}from"node:path";var l=e=>`\x1B[1m${e}\x1B[0m`,u=e=>`\x1B[32m${e}\x1B[0m`,r=e=>`\x1B[36m${e}\x1B[0m`,k=e=>`\x1B[33m${e}\x1B[0m`,f=e=>`\x1B[31m${e}\x1B[0m`,t=e=>`\x1B[2m${e}\x1B[0m`;var G="simpyui.json";function h(){let e=process.cwd();return p(a(e,"next.config.js"))||p(a(e,"next.config.mjs"))||p(a(e,"next.config.ts"))?"nextjs":p(a(e,"vite.config.js"))||p(a(e,"vite.config.ts"))||p(a(e,"vite.config.mjs"))?"vite":"unknown"}function I(){switch(h()){case"nextjs":return{componentDir:"components/ui",utilsDir:"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 R(){let e=a(process.cwd(),G);if(!p(e))return null;try{let o=JSON.parse(E(e,"utf-8"));if(!o.utilsDir){let n=h();o.utilsDir=n==="nextjs"?"lib":"src/lib"}return o}catch{return null}}function U(e){let o=a(process.cwd(),G);M(o,JSON.stringify(e,null,2)+`
|
|
3
|
+
`)}function te(){return p(a(process.cwd(),"package.json"))}function T(){te()||(console.log(f(" \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 e=R();if(!e){let o=h(),n=I();return console.log(t(` Detected ${o==="nextjs"?"Next.js":o==="vite"?"Vite":"React"} project`)),console.log(t(" Creating simpyui.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(),U(n),n}return e}var ne=`import { clsx, type ClassValue } from "clsx"
|
|
4
|
+
import { twMerge } from "tailwind-merge"
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
export function cn(...inputs: ClassValue[]) {
|
|
7
|
+
return twMerge(clsx(inputs))
|
|
8
|
+
}
|
|
9
|
+
`,se=`import { clsx } from "clsx"
|
|
10
|
+
import { twMerge } from "tailwind-merge"
|
|
11
|
+
|
|
12
|
+
export function cn(...inputs) {
|
|
13
|
+
return twMerge(clsx(inputs))
|
|
14
|
+
}
|
|
15
|
+
`;function H(e){let o=e.typescript?"ts":"js",n=a(process.cwd(),e.utilsDir,`utils.${o}`),i=[];if(!p(n)){Y(oe(n),{recursive:!0}),M(n,e.typescript?ne:se),console.log(u(" \u2713 Created ")+t(`${e.utilsDir}/utils.${o}`));let s=v();s.has("clsx")||i.push("clsx"),s.has("tailwind-merge")||i.push("tailwind-merge")}return i}function ie(){let e=process.cwd();return p(a(e,"bun.lockb"))||p(a(e,"bun.lock"))?"bun":p(a(e,"pnpm-lock.yaml"))?"pnpm":p(a(e,"yarn.lock"))?"yarn":"npm"}function re(e,o){let n=o.join(" ");switch(e){case"bun":return`bun add ${n}`;case"pnpm":return`pnpm add ${n}`;case"yarn":return`yarn add ${n}`;default:return`npm install ${n}`}}function B(e){if(e.length===0)return;let o=ie(),n=re(o,e);console.log(t(` $ ${n}`));try{ee(n,{stdio:"pipe",cwd:process.cwd()})}catch{console.log(k(` \u26A0 Failed to install. Run manually: ${n}`))}}function v(){let e=a(process.cwd(),"package.json");if(!p(e))return new Set;try{let o=JSON.parse(E(e,"utf-8"));return new Set([...Object.keys(o.dependencies||{}),...Object.keys(o.devDependencies||{})])}catch{return new Set}}async function _(e){let o=await fetch(e);if(!o.ok)throw new Error(`Failed to fetch ${e} (${o.status})`);return o.text()}function J(e){let o=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],n=0,i=setInterval(()=>{process.stdout.write(`\r${r(o[n++%o.length])} ${e}`)},80);return{stop(s){clearInterval(i),process.stdout.write(`\r${s||""}
|
|
16
|
+
`)}}}async function S(e,o=""){let n=o?` ${t(`(${o})`)}`:"";return process.stdout.write(`${e}${n}: `),new Promise(i=>{let s="";process.stdin.setEncoding("utf-8"),process.stdin.resume(),process.stdin.once("data",g=>{s=g.trim(),process.stdin.pause(),i(s||o)})})}async function F(e,o=!0){let i=await S(`${e} ${t(`[${o?"Y/n":"y/N"}]`)}`);return i?i.toLowerCase().startsWith("y"):o}var W="https://raw.githubusercontent.com/AbhishekS04/SimpyUI/main/src/registry",m={button:{name:"Button",slug:"button",files:["button/button.tsx"],dependencies:["framer-motion"],internal:[],description:"Animated button with multiple variants and sizes."},card:{name:"Card",slug:"card",files:["card/card.tsx"],dependencies:["framer-motion"],internal:[],description:"Versatile card container with hover and glow effects."},badge:{name:"Badge",slug:"badge",files:["badge/badge.tsx"],dependencies:["framer-motion"],internal:[],description:"Small status indicators with colorful variants."},avatar:{name:"Avatar",slug:"avatar",files:["avatar/avatar.tsx"],dependencies:["framer-motion"],internal:[],description:"User avatar with image support and fallback initials."},input:{name:"Input",slug:"input",files:["input/input.tsx"],dependencies:[],internal:[],description:"Styled text input with label and error states."},toggle:{name:"Toggle",slug:"toggle",files:["toggle/toggle.tsx"],dependencies:["framer-motion"],internal:[],description:"Smooth animated toggle switch."},accordion:{name:"Accordion",slug:"accordion",files:["accordion/accordion.tsx"],dependencies:["framer-motion","react-icons"],internal:[],description:"Collapsible content sections with smooth animations."},tabs:{name:"Tabs",slug:"tabs",files:["tabs/tabs.tsx"],dependencies:["framer-motion"],internal:[],description:"Animated tab navigation with smooth underline indicator."},progress:{name:"Progress",slug:"progress",files:["progress/progress.tsx"],dependencies:["framer-motion"],internal:[],description:"Animated progress bar with multiple colors and sizes."},skeleton:{name:"Skeleton",slug:"skeleton",files:["skeleton/skeleton.tsx"],dependencies:["framer-motion"],internal:[],description:"Animated loading placeholder with pulsing effect."},modal:{name:"Modal",slug:"modal",files:["modal/modal.tsx"],dependencies:["framer-motion","react-icons"],internal:[],description:"Animated dialog with backdrop blur."},toast:{name:"Toast",slug:"toast",files:["toast/toast.tsx"],dependencies:["framer-motion","react-icons"],internal:[],description:"Notification toast with animated entrance."},alert:{name:"Alert",slug:"alert",files:["alert/alert.tsx"],dependencies:["framer-motion","react-icons"],internal:[],description:"Contextual alert banners with icons."},tooltip:{name:"Tooltip",slug:"tooltip",files:["tooltip/tooltip.tsx"],dependencies:[],internal:[],description:"Hover tooltip with multiple positions."},"social-stories":{name:"Social Stories",slug:"social-stories",files:["social-stories/social-stories.tsx"],dependencies:["framer-motion","lucide-react"],internal:[],description:"Instagram/LinkedIn-style stories viewer with progress bars and video support."}},N=Object.keys(m);function j(){console.log(),console.log(l(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(l(r(" \u2502 SimpyUI CLI \u2502"))),console.log(l(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 pe(){j(),R()&&(await F(k(" simpyui.json already exists. Overwrite?"),!1)||(console.log(t(" Cancelled.")),process.exit(0)));let o=h(),n=I();console.log(t(` Detected ${l(o==="nextjs"?"Next.js":o==="vite"?"Vite":"React")} project
|
|
17
|
+
`));let s=await S(` ${l("Component directory")}`,n.componentDir),g=await S(` ${l("Utils directory")}`,n.utilsDir),$=await F(` ${l("Use TypeScript?")}`,!0);U({componentDir:s,utilsDir:g,typescript:$}),console.log(),console.log(u(" \u2713 Created simpyui.json")),console.log(t(` Components \u2192 ${s}/`)),console.log(t(` Utils \u2192 ${g}/`)),console.log(),console.log(` ${l("Next step:")} Run ${r("npx simpyui@latest add button")} to add your first component.`),console.log()}function ge(){j(),console.log(` ${l("Available components:")}
|
|
18
|
+
`);let e={};for(let o of Object.values(m)){let n=de(o.slug);e[n]||(e[n]=[]),e[n].push(o)}for(let[o,n]of Object.entries(e)){console.log(` ${l(r(o))}`);for(let i of n){let s=i.dependencies.length?t(` \u2192 ${i.dependencies.join(", ")}`):"";console.log(` ${u("\u2022")} ${l(i.slug.padEnd(16))} ${t(i.description)}${s}`)}console.log()}console.log(t(` Total: ${N.length} components`)),console.log(),console.log(` ${t("Usage:")} ${r("npx simpyui add <name>")}`),console.log()}function de(e){return{button:"General",card:"General",badge:"General",avatar:"General",input:"Inputs",toggle:"Inputs",accordion:"Data Display",tabs:"Data Display",progress:"Data Display",skeleton:"Data Display",modal:"Feedback",toast:"Feedback",alert:"Feedback",tooltip:"Overlay","social-stories":"Animation"}[e]||"Other"}async function z(e){j();let o=T(),n=e.includes("--all"),i=e.filter(c=>!c.startsWith("-")),s=[];if(n)s=[...N],console.log(` Adding ${l("all")} ${r(String(s.length))} components...
|
|
19
|
+
`);else if(i.length===0)console.log(f(" \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 c=i.filter(d=>!m[d]);c.length>0&&(console.log(f(` \u2717 Unknown component(s): ${c.join(", ")}`)),console.log(),console.log(` ${t("Run")} ${r("npx simpyui list")} ${t("to see all available components.")}`),console.log(),process.exit(1)),s=i}let g=new Set;function $(c){if(g.has(c))return;let d=m[c];if(d){for(let y of d.internal)$(y);g.add(c)}}for(let c of s)$(c);s=[...g];let x=new Set;for(let c of s)for(let d of m[c].dependencies)x.add(d);let w=H(o);for(let c of w)x.add(c);let K=v(),D=[...x].filter(c=>!K.has(c)),O=J("Downloading components..."),L=0,C=0;for(let c of s){let d=m[c];for(let y of d.files){let Q=`${W}/${y}`,P=y.split("/").pop(),xe=o.typescript?"":P.replace(".tsx",".jsx"),X=o.typescript?P:P.replace(".tsx",".jsx"),A=q(process.cwd(),o.componentDir,X);if(Z(A)){C++;continue}try{let b=await _(Q);o.typescript||(b=me(b)),ce(ae(A),{recursive:!0}),le(A,b),L++}catch(b){O.stop(f(` \u2717 Failed to download ${y}`)),console.log(t(` ${b.message}`))}}}O.stop(u(` \u2713 Downloaded ${L} file(s)`)+(C?t(` (${C} already existed)`):"")),D.length>0?(console.log(),console.log(` ${l("Installing dependencies:")} ${r(D.join(", "))}`),B(D),console.log(u(" \u2713 Dependencies installed"))):x.size>0&&console.log(t(" \u2713 All dependencies already installed")),console.log(),console.log(u(" Done! ")+t("Components added:"));for(let c of s){let d=m[c],y=d.files[0].split("/").pop();console.log(` ${u("\u2022")} ${l(d.name)} \u2192 ${t(`${o.componentDir}/${y}`)}`)}console.log(),s.includes("button")&&(console.log(t(" Import example:")),console.log(r(` import Button from './${o.componentDir}/button'`)),console.log())}function me(e){return e.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,`
|
|
20
|
+
|
|
21
|
+
`)}function ue(e){j();let o=T(),n=e.filter(i=>!i.startsWith("-"));n.length===0&&(console.log(f(" \u2717 Specify a component name.")),process.exit(1));for(let i of n){let s=m[i];if(!s){console.log(f(` \u2717 Unknown component: ${i}`));continue}let g=s.files[0].split("/").pop(),$=q(process.cwd(),o.componentDir,g);if(Z($)?console.log(k(` \u25CF ${s.name}`),t("\u2014 already exists")):console.log(u(` + ${s.name}`),t(`\u2192 ${o.componentDir}/${g}`)),s.dependencies.length>0){let x=v();for(let w of s.dependencies)x.has(w)?console.log(t(` \u2713 ${w} (installed)`)):console.log(r(` + ${w} (will install)`))}console.log()}}function V(){j(),console.log(` ${l("Usage:")} simpyui ${r("<command>")} ${t("[options]")}`),console.log(),console.log(` ${l("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(` ${l("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 fe(){let e=process.argv.slice(2),o=e[0];switch(o){case"init":await pe();break;case"add":await z(e.slice(1));break;case"list":case"ls":ge();break;case"diff":ue(e.slice(1));break;case"help":case"--help":case"-h":case void 0:V();break;default:m[o]?await z(e):(console.log(f(`
|
|
10
22
|
Unknown command: ${o}
|
|
11
|
-
`)),
|
|
23
|
+
`)),V())}}fe().catch(e=>{console.error(f(`
|
|
12
24
|
Error: ${e.message}
|
|
13
25
|
`)),process.exit(1)});
|