simpyui 0.2.1 → 0.2.2
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 +10 -10
- 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 Y,mkdirSync as de,writeFileSync as me,readFileSync as fe}from"node:fs";import{join as M,dirname as ue}from"node:path";import{existsSync as g,readFileSync as B,writeFileSync as J,mkdirSync as se}from"node:fs";import{execSync as ie}from"node:child_process";import{join as a,dirname as re}from"node:path";var l=e=>`\x1B[1m${e}\x1B[0m`,f=e=>`\x1B[32m${e}\x1B[0m`,r=e=>`\x1B[36m${e}\x1B[0m`,S=e=>`\x1B[33m${e}\x1B[0m`,u=e=>`\x1B[31m${e}\x1B[0m`,t=e=>`\x1B[2m${e}\x1B[0m`;var W="components.json";function h(){let e=process.cwd();return g(a(e,"next.config.js"))||g(a(e,"next.config.mjs"))||g(a(e,"next.config.ts"))?"nextjs":g(a(e,"vite.config.js"))||g(a(e,"vite.config.ts"))||g(a(e,"vite.config.mjs"))?"vite":"unknown"}function U(){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 F(){let e=a(process.cwd(),W);if(!g(e))return null;try{let o=JSON.parse(B(e,"utf-8"));if(!o.utilsDir){let n=h();o.utilsDir=n==="nextjs"?"lib":"src/lib"}return o}catch{return null}}function T(e){let o=a(process.cwd(),W);J(o,JSON.stringify(e,null,2)+`
|
|
3
|
+
`)}function ce(){return g(a(process.cwd(),"package.json"))}function O(){ce()||(console.log(u(" \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=F();if(!e){let o=h(),n=U();return console.log(t(` Detected ${o==="nextjs"?"Next.js":o==="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(),T(n),n}return e}var le=`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
|
+
`,ae=`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
|
-
`)}}}async function
|
|
17
|
-
`));let s=await
|
|
18
|
-
`);let e={};for(let o of Object.values(m)){let n
|
|
19
|
-
`);else if(i.length===0)console.log(
|
|
15
|
+
`;function z(e){let o=e.typescript?"ts":"js",n=a(process.cwd(),e.utilsDir,`utils.${o}`),i=[];if(!g(n)){se(re(n),{recursive:!0}),J(n,e.typescript?le:ae),console.log(f(" \u2713 Created ")+t(`${e.utilsDir}/utils.${o}`));let s=k();s.has("clsx")||i.push("clsx"),s.has("tailwind-merge")||i.push("tailwind-merge")}return i}function pe(){let e=process.cwd();return g(a(e,"bun.lockb"))||g(a(e,"bun.lock"))?"bun":g(a(e,"pnpm-lock.yaml"))?"pnpm":g(a(e,"yarn.lock"))?"yarn":"npm"}function ge(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 V(e){if(e.length===0)return;let o=pe(),n=ge(o,e);console.log(t(` $ ${n}`));try{ie(n,{stdio:"pipe",cwd:process.cwd()})}catch{console.log(S(` \u26A0 Failed to install. Run manually: ${n}`))}}function k(){let e=a(process.cwd(),"package.json");if(!g(e))return new Set;try{let o=JSON.parse(B(e,"utf-8"));return new Set([...Object.keys(o.dependencies||{}),...Object.keys(o.devDependencies||{})])}catch{return new Set}}async function Z(e){let o=await fetch(e);if(!o.ok)throw new Error(`Failed to fetch ${e} (${o.status})`);return o.text()}function q(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 C(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",d=>{s=d.trim(),process.stdin.pause(),i(s||o)})})}async function L(e,o=!0){let i=await C(`${e} ${t(`[${o?"Y/n":"y/N"}]`)}`);return i?i.toLowerCase().startsWith("y"):o}var K="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."}},E=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 xe(){j(),F()&&(await L(S(" components.json already exists. Overwrite?"),!1)||(console.log(t(" Cancelled.")),process.exit(0)));let o=h(),n=U();console.log(t(` Detected ${l(o==="nextjs"?"Next.js":o==="vite"?"Vite":"React")} project
|
|
17
|
+
`));let s=await C(` ${l("Component directory")}`,n.componentDir),d=await C(` ${l("Utils directory")}`,n.utilsDir),$=await L(` ${l("Use TypeScript?")}`,!0);T({componentDir:s,utilsDir:d,typescript:$}),console.log(),console.log(f(" \u2713 Created components.json")),console.log(t(` Components \u2192 ${s}/`)),console.log(t(` Utils \u2192 ${d}/`)),console.log(),console.log(` ${l("Next step:")} Run ${r("npx simpyui@latest add button")} to add your first component.`),console.log()}function ye(){j(),console.log(` ${l("Available components:")}
|
|
18
|
+
`);let e={};for(let o of Object.values(m)){let n=$e(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(` ${f("\u2022")} ${l(i.slug.padEnd(16))} ${t(i.description)}${s}`)}console.log()}console.log(t(` Total: ${E.length} components`)),console.log(),console.log(` ${t("Usage:")} ${r("npx simpyui add <name>")}`),console.log()}function $e(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 Q(e){j();let o=O(),n=e.includes("--all"),i=e.filter(c=>!c.startsWith("-")),s=[];if(n)s=[...E],console.log(` Adding ${l("all")} ${r(String(s.length))} components...
|
|
19
|
+
`);else if(i.length===0)console.log(u(" \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(p=>!m[p]);c.length>0&&(console.log(u(` \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 d=new Set;function $(c){if(d.has(c))return;let p=m[c];if(p){for(let y of p.internal)$(y);d.add(c)}}for(let c of s)$(c);s=[...d];let x=new Set;for(let c of s)for(let p of m[c].dependencies)x.add(p);let w=z(o);for(let c of w)x.add(c);let ee=k(),P=[...x].filter(c=>!ee.has(c)),G=q("Downloading components..."),H=0,A=0;for(let c of s){let p=m[c];for(let y of p.files){let te=`${K}/${y}`,R=y.split("/").pop(),je=o.typescript?"":R.replace(".tsx",".jsx"),ne=o.typescript?R:R.replace(".tsx",".jsx"),N=M(process.cwd(),o.componentDir,ne);if(Y(N)){A++;continue}try{let b=await Z(te);o.typescript||(b=we(b)),de(ue(N),{recursive:!0}),me(N,b),H++}catch(b){G.stop(u(` \u2717 Failed to download ${y}`)),console.log(t(` ${b.message}`))}}}G.stop(f(` \u2713 Downloaded ${H} file(s)`)+(A?t(` (${A} already existed)`):"")),P.length>0?(console.log(),console.log(` ${l("Installing dependencies:")} ${r(P.join(", "))}`),V(P),console.log(f(" \u2713 Dependencies installed"))):x.size>0&&console.log(t(" \u2713 All dependencies already installed")),console.log(),console.log(f(" Done! ")+t("Components added:"));for(let c of s){let p=m[c],y=p.files[0].split("/").pop();console.log(` ${f("\u2022")} ${l(p.name)} \u2192 ${t(`${o.componentDir}/${y}`)}`)}console.log();let _=s[0],D=m[_],I=D.files[0].split("/").pop().replace(".tsx","").replace(".jsx",""),oe=M(process.cwd(),o.componentDir,D.files[0].split("/").pop()),v="";try{let c=fe(oe,"utf-8"),p=D.name.replace(/\s+/g,"");c.includes("export default")?v=`import ${p} from "@/${o.componentDir}/${I}"`:v=`import { ${p} } from "@/${o.componentDir}/${I}"`}catch{v=`import ${D.name.replace(/\s+/g,"")} from "@/${o.componentDir}/${I}"`}console.log(t(" Import:")),console.log(r(` ${v}`)),console.log(),console.log(t(` Docs \u2192 ${r(`https://simpyui.vercel.app/components/${_}`)}`)),console.log()}function we(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
20
|
|
|
21
|
-
`)}function
|
|
21
|
+
`)}function be(e){j();let o=O(),n=e.filter(i=>!i.startsWith("-"));n.length===0&&(console.log(u(" \u2717 Specify a component name.")),process.exit(1));for(let i of n){let s=m[i];if(!s){console.log(u(` \u2717 Unknown component: ${i}`));continue}let d=s.files[0].split("/").pop(),$=M(process.cwd(),o.componentDir,d);if(Y($)?console.log(S(` \u25CF ${s.name}`),t("\u2014 already exists")):console.log(f(` + ${s.name}`),t(`\u2192 ${o.componentDir}/${d}`)),s.dependencies.length>0){let x=k();for(let w of s.dependencies)x.has(w)?console.log(t(` \u2713 ${w} (installed)`)):console.log(r(` + ${w} (will install)`))}console.log()}}function X(){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 he(){let e=process.argv.slice(2),o=e[0];switch(o){case"init":await xe();break;case"add":await Q(e.slice(1));break;case"list":case"ls":ye();break;case"diff":be(e.slice(1));break;case"help":case"--help":case"-h":case void 0:X();break;default:m[o]?await Q(e):(console.log(u(`
|
|
22
22
|
Unknown command: ${o}
|
|
23
|
-
`)),
|
|
23
|
+
`)),X())}}he().catch(e=>{console.error(u(`
|
|
24
24
|
Error: ${e.message}
|
|
25
25
|
`)),process.exit(1)});
|