smart-registry 0.5.3 → 0.5.5

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/bin/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- var z=Object.defineProperty,q=Object.defineProperties;var B=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var J=(t,i,r)=>i in t?z(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r,$=(t,i)=>{for(var r in i||(i={}))T.call(i,r)&&J(t,r,i[r]);if(_)for(var r of _(i))U.call(i,r)&&J(t,r,i[r]);return t},E=(t,i)=>q(t,B(i));import v from"node:fs";import S from"node:path";import{parseArgs as K}from"node:util";import F from"node:fs";import Z from"strip-json-comments";var C=async()=>{let t={};if(F.existsSync("tsconfig.json")){let r=await F.promises.readFile("tsconfig.json","utf8"),{compilerOptions:n}=JSON.parse(Z(r,{trailingCommas:!0}));if(n.paths){if(t=Object.entries(n.paths).reduce((s,[e,[a]])=>(s[e.replace(/\*$/,"")]=a.replace(/^\.\//,"").replace(/\*$/,""),s),{}),!Object.keys(t).includes("@/"))throw new Error("No alias key '@/' found in compilerOptions.paths!");return console.log(t),t}}let i=["registry","components","src/components"];for(let r of i)if(F.existsSync(r))return t["@/"]=r==="src/components"?"src/":"",t;throw new Error("Could not resolve aliases!")};import j from"node:fs";import k from"node:path";import{glob as G}from"tinyglobby";var R=t=>{if(k.extname(t)!=="")return t;{let r=t.split(/\/|\\/).slice(0,-1).join(k.sep);if(!j.existsSync(r))return"";let n=j.readdirSync(r);n=n.map(e=>r+k.sep+e);let s=n.find(e=>e.startsWith(t+"."));return s=s==null?void 0:s.replace(process.cwd()+k.sep,""),s||""}},V=async({patterns:t=["**",".**"],ignore:i=[]}={})=>{if(t=Array.isArray(t)?t:[t],i=Array.isArray(i)?i:[i],j.existsSync(".gitignore")){let r=(await j.promises.readFile(".gitignore","utf8")).split(`
3
- `).map(n=>n.trim()).filter(n=>n&&!n.startsWith("#")).map(n=>n.replace(/^\//,""));i=i.concat(r)}return await G(t,{ignore:i.filter(r=>!t.includes(r))})};import M from"node:fs";import x from"node:path";import H from"node:path";var d=(t,i={})=>{var n;t=i.aliases?t.replace(i.aliases["@/"],""):t;let r=t.startsWith("registry/")?t.replace(/^registry\//,"").replace(/^(?:([^\/]*)\/)?blocks\//,(s,e)=>`blocks/${e?e+"/":""}`).replace(/^(?:([^\/]*)\/)?components\/ui\//,(s,e)=>`${e?e+"/":""}ui/`).replace(/^(?:([^\/]*)\/)?components\//,(s,e)=>`components/${e?e+"/":""}`).replace(/^(?:([^\/]*)\/)?hooks\//,(s,e)=>`hooks/${e?e+"/":""}`).replace(/^(?:([^\/]*)\/)?lib\//,(s,e)=>`lib/${e?e+"/":""}`).replace(/^(?:([^\/]*)\/)?ui\//,(s,e)=>`components/ui/${e?e+"/":""}`).replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,""):t.replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,"");return{type:r.endsWith("page.tsx")?"registry:page":((n=r.match(/^(blocks|components\/ui|components|hooks|lib|utils)/))==null?void 0:n[1].replace("blocks","registry:block").replace("components/ui","registry:ui").replace("components","registry:component").replace("hooks","registry:hook").replace("lib","registry:lib").replace("utils","registry:lib"))||"registry:file",name:r.replace(/^(blocks|components\/ui|components|hooks|lib|utils)\//,"").replace(/\.[^\/.]+$/,""),import:"@/"+r.replace(process.cwd()+H.sep,"").replace(/\.[^/.]+$/,""),target:r,path:t}};var w=(t,i)=>Object.entries(i).sort(([n],[s])=>s.length-n.length).reduce((n,[s,e])=>n.replace(s,e),t),N=async(t,i={})=>{let{aliases:r={},resolved:n=new Set}=i,s={dependencies:[],files:[],content:{}};for(let e of t){if(n.has(e))continue;n.add(e),s.files.push(e),s.content[e]=s.content[e]||await M.promises.readFile(e,"utf8");let a=s.content[e].match(/import\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]/g);if(!a)continue;let o=a.map(f=>{var h;return(h=f.match(/['"](.*)['"]/))==null?void 0:h[1]});for(let f of o)if(Object.keys(r).some(c=>f.startsWith(c))){let c=w(f,r);c=R(c),c&&!s.files.includes(c)&&s.files.push(c)}else if(f.startsWith(".")){let c=x.resolve(x.dirname(e),f);c=R(c),c&&!s.files.includes(c)&&s.files.push(c)}else{let c=["fs","path","util"],g=f.split("/").slice(0,2).join("/");g=g.startsWith("@")?g:g.split("/")[0],/^[a-zA-Z0-9@/-]+$/.test(g)&&!c.includes(g)&&!s.dependencies.includes(g)&&s.dependencies.push(g)}}for(let e of s.files){let a=await N([e],{aliases:r,resolved:n});a.dependencies.forEach(o=>{s.dependencies.includes(o)||s.dependencies.push(o)}),a.files.forEach(o=>{s.files.includes(o)||s.files.push(o)}),s.content[e]=a.content[e]||await M.promises.readFile(e,"utf8")}for(let e of s.files)s.content[e]=s.content[e].replace(/import\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]/g,a=>{var h,c,g;let o=(h=a.match(/['"](.*)['"]/))==null?void 0:h[1];if(Object.keys(r).some(u=>o.startsWith(u))){let u=w(o,r),y=(c=d(u,{aliases:r}))==null?void 0:c.import;return a.replace(o,y)}else if(o.startsWith(".")){let u=x.resolve(x.dirname(e),o),y=(g=d(u,{aliases:r}))==null?void 0:g.import;return a.replace(o,y)}else return a});return s.dependencies.sort(),s.files.sort((e,a)=>d(e,{aliases:r}).target.localeCompare(d(a,{aliases:r}).target)),s.files.sort((e,a)=>{let o=["registry:file","registry:block","registry:component","registry:ui","registry:hook","registry:lib"],f=d(e,{aliases:r}).type,h=d(a,{aliases:r}).type;return o.indexOf(f)-o.indexOf(h)}),s};var A="smart-registry",D="0.5.3";var O={name:"Neeraj Dalal",email:"admin@nrjdalal.com",url:"https://nrjdalal.com"};var I=`Version:
4
- ${A}@${D}
2
+ var q=Object.defineProperty,B=Object.defineProperties;var T=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var C=(r,i,s)=>i in r?q(r,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[i]=s,$=(r,i)=>{for(var s in i||(i={}))U.call(i,s)&&C(r,s,i[s]);if(J)for(var s of J(i))Z.call(i,s)&&C(r,s,i[s]);return r},F=(r,i)=>B(r,T(i));import v from"node:fs";import S from"node:path";import{parseArgs as L}from"node:util";import R from"node:fs";import G from"strip-json-comments";var M=async()=>{let r={};if(R.existsSync("tsconfig.json")){let s=await R.promises.readFile("tsconfig.json","utf8"),{compilerOptions:o}=JSON.parse(G(s,{trailingCommas:!0}));if(o.paths){if(r=Object.entries(o.paths).reduce((t,[e,[n]])=>(t[e.replace(/\*$/,"")]=n.replace(/^\.\//,"").replace(/\*$/,""),t),{}),!Object.keys(r).includes("@/"))throw new Error("No alias key '@/' found in compilerOptions.paths!");return r}}let i=["registry","components","src/components"];for(let s of i)if(R.existsSync(s))return r["@/"]=s==="src/components"?"src/":"",r;throw new Error("Could not resolve aliases!")};import j from"node:fs";import k from"node:path";import{glob as H}from"tinyglobby";var W=r=>{if(k.extname(r)!=="")return r;{let s=r.split(/\/|\\/).slice(0,-1).join(k.sep);if(s=s.replace(/\/\//g,"/"),!j.existsSync(s))return"";let o=j.readdirSync(s);o=o.map(e=>s+k.sep+e);let t=o.find(e=>e.startsWith(r+"."));return t=t==null?void 0:t.replace(process.cwd()+k.sep,""),t||""}},V=async({patterns:r=["**",".**"],ignore:i=[]}={})=>{if(r=Array.isArray(r)?r:[r],i=Array.isArray(i)?i:[i],j.existsSync(".gitignore")){let s=(await j.promises.readFile(".gitignore","utf8")).split(`
3
+ `).map(o=>o.trim()).filter(o=>o&&!o.startsWith("#")).map(o=>o.replace(/^\//,""));i=i.concat(s)}return await H(r,{ignore:i.filter(s=>!r.includes(s))})};import I from"node:fs";import x from"node:path";import K from"node:path";var f=(r,i={})=>{var o;r=i.aliases?r.replace(i.aliases["@/"],""):r;let s=r.startsWith("registry/")?r.replace(/^registry\//,"").replace(/^(?:([^\/]*)\/)?blocks\//,(t,e)=>`blocks/${e?e+"/":""}`).replace(/^(?:([^\/]*)\/)?components\/ui\//,(t,e)=>`${e?e+"/":""}ui/`).replace(/^(?:([^\/]*)\/)?components\//,(t,e)=>`components/${e?e+"/":""}`).replace(/^(?:([^\/]*)\/)?hooks\//,(t,e)=>`hooks/${e?e+"/":""}`).replace(/^(?:([^\/]*)\/)?lib\//,(t,e)=>`lib/${e?e+"/":""}`).replace(/^(?:([^\/]*)\/)?ui\//,(t,e)=>`components/ui/${e?e+"/":""}`).replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,""):r.replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,"");return{type:s.endsWith("page.tsx")?"registry:page":((o=s.match(/^(blocks|components\/ui|components|hooks|lib|utils)/))==null?void 0:o[1].replace("blocks","registry:block").replace("components/ui","registry:ui").replace("components","registry:component").replace("hooks","registry:hook").replace("lib","registry:lib").replace("utils","registry:lib"))||"registry:file",name:s.replace(/^(blocks|components\/ui|components|hooks|lib|utils)\//,"").replace(/\.[^\/.]+$/,""),import:"@/"+s.replace(process.cwd()+K.sep,"").replace(/\.[^/.]+$/,""),target:s,path:r}};var w=(r,i)=>Object.entries(i).sort(([o],[t])=>t.length-o.length).reduce((o,[t,e])=>o.replace(t,e),r),N=async(r,i={})=>{let{aliases:s={},resolved:o=new Set}=i,t={dependencies:[],files:[],content:{}};for(let e of r){if(o.has(e))continue;o.add(e),t.files.push(e),t.content[e]=t.content[e]||await I.promises.readFile(e,"utf8");let n=t.content[e].match(/import\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]/g);if(!n)continue;let a=n.map(l=>{var h;return(h=l.match(/['"](.*)['"]/))==null?void 0:h[1]});for(let l of a)if(Object.keys(s).some(p=>l.startsWith(p))){let p=w(l,s);p=W(p),p&&!t.files.includes(p)&&t.files.push(p)}else if(l.startsWith(".")){let p=x.resolve(x.dirname(e),l);p=W(p),p&&!t.files.includes(p)&&t.files.push(p)}else{let p=["fs","path","util"],d=l.split("/").slice(0,2).join("/");d=d.startsWith("@")?d:d.split("/")[0],/^[a-zA-Z0-9@/-]+$/.test(d)&&!p.includes(d)&&!t.dependencies.includes(d)&&t.dependencies.push(d)}}for(let e of t.files){let n=await N([e],{aliases:s,resolved:o});n.dependencies.forEach(a=>{t.dependencies.includes(a)||t.dependencies.push(a)}),n.files.forEach(a=>{t.files.includes(a)||t.files.push(a)}),t.content[e]=n.content[e]||await I.promises.readFile(e,"utf8")}for(let e of t.files)t.content[e]=t.content[e].replace(/import\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]/g,n=>{var h,p,d;let a=(h=n.match(/['"](.*)['"]/))==null?void 0:h[1];if(Object.keys(s).some(u=>a.startsWith(u))){let u=w(a,s),b=(p=f(u,{aliases:s}))==null?void 0:p.import;return n.replace(a,b)}else if(a.startsWith(".")){let u=x.resolve(x.dirname(e),a),b=(d=f(u,{aliases:s}))==null?void 0:d.import;return n.replace(a,b)}else return n});return t.dependencies.sort(),t.files.sort((e,n)=>f(e,{aliases:s}).target.localeCompare(f(n,{aliases:s}).target)),t.files.sort((e,n)=>{let a=["registry:file","registry:block","registry:component","registry:ui","registry:hook","registry:lib"],l=f(e,{aliases:s}).type,h=f(n,{aliases:s}).type;return a.indexOf(l)-a.indexOf(h)}),t};var A="smart-registry",_="0.5.4";var O={name:"Neeraj Dalal",email:"admin@nrjdalal.com",url:"https://nrjdalal.com"};var z=`Version:
4
+ ${A}@${_}
5
5
 
6
6
  Usage:
7
7
  $ ${A} [options]
@@ -9,12 +9,13 @@ Usage:
9
9
  Options:
10
10
  -f, --files Files to build the registry from
11
11
  -d, --directories Directories to build the registry from
12
+ -i, --ignore Extensions to ignore
12
13
  -v, --version Display version
13
14
  -h, --help Display help
14
15
 
15
16
  Author:
16
- ${O.name} <${O.email}> (${O.url})`,L=t=>{try{return K(t)}catch(i){throw new Error(`Error parsing arguments: ${i.message}`)}},Q=async()=>{var t,i,r,n;try{let{positionals:s,values:e}=L({allowPositionals:!0,options:{files:{type:"string",multiple:!0,short:"f"},directories:{type:"string",multiple:!0,short:"d"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});s.length||(e.version&&(console.log(`${A}@${D}`),process.exit(0)),e.help&&(console.log(I),process.exit(0)));let a={files:e.files||[],directories:e.directories||[]},o=await C(),f=await V();if(!a.files.length&&!a.directories.length){let l=["registry","components"].map(p=>o["@/"]+p).find(p=>f.some(b=>b.startsWith(p+"/")));if(l)a.directories.push(l);else throw new Error("Neither registry nor components directory found")}let h=[...a.files.map(l=>w(l,o)),...a.directories.flatMap(l=>f.filter(p=>p.startsWith(w(l,o)+"/")))],c=S.resolve(process.cwd(),"registry.json"),g={};v.existsSync(c)&&(g=JSON.parse(await v.promises.readFile(c,"utf8")));let u=E($({},g),{items:[]}),y=[];for(let l of h)try{let p=await N([l,...((r=(i=(t=g.items)==null?void 0:t.find(m=>m.name===d(l,{aliases:o}).name))==null?void 0:i.files)==null?void 0:r.map(m=>m.path))||[]],{aliases:o}),b=$(E($({$schema:"https://ui.shadcn.com/schema/registry-item.json",name:d(l,{aliases:o}).name,type:d(l,{aliases:o}).type||"registry:file"},p.dependencies.length&&{dependencies:p.dependencies}),{files:p.files.map(m=>({type:d(m,{aliases:o}).type||"registry:file",target:d(m,{aliases:o}).target||m,content:p.content[m],path:m}))}),Object.fromEntries(Object.entries(((n=g.items)==null?void 0:n.find(m=>m.name===d(l,{aliases:o}).name))||{}).filter(([m])=>!["$schema","name","type","files"].includes(m)))),P=S.resolve(process.cwd(),"public/r",b.name+".json");console.log(`- ${l.padEnd(Math.max(...h.map(m=>m.length))+2," ")} ${p.dependencies.length?"\u{1F4E6}"+String(p.dependencies.length).padEnd(2," "):" "} ${p.files.length-1?"\u{1F4C4}"+String(p.files.length).padEnd(2," "):" "} ${P.replace(process.cwd()+"/","")}`),await v.promises.mkdir(S.dirname(P),{recursive:!0}),await v.promises.writeFile(P,JSON.stringify(b,null,2)+`
17
- `),b.files.forEach(m=>delete m.content),u.items.push(b)}catch(p){y.push(l+": "+p.message);continue}u.items.sort((l,p)=>l.name.localeCompare(p.name)),await v.promises.writeFile(S.resolve(process.cwd(),"public/registry.json"),JSON.stringify(u,null,2)+`
18
- `),y.length&&(console.log(),y.forEach(l=>console.error(`\x1B[31m- ${l}\x1B[0m`))),process.exit(0)}catch(s){console.error(I),console.error(`
19
- ${s.message}
20
- `),process.exit(1)}};Q();
17
+ ${O.name} <${O.email}> (${O.url})`,Q=r=>{try{return L(r)}catch(i){throw new Error(`Error parsing arguments: ${i.message}`)}},X=async()=>{var r,i,s,o,t;try{let{positionals:e,values:n}=Q({allowPositionals:!0,options:{files:{type:"string",multiple:!0,short:"f"},directories:{type:"string",multiple:!0,short:"d"},ignore:{type:"string",multiple:!0,short:"i"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});e.length||(n.version&&(console.log(`${A}@${_}`),process.exit(0)),n.help&&(console.log(z),process.exit(0)));let a={files:n.files||[],directories:n.directories||[]},l=await M(),h=await V();if(!a.files.length&&!a.directories.length){let m=["registry","components"].map(c=>l["@/"]+c).find(c=>h.some(y=>y.startsWith(c+"/")));if(m)a.directories.push(m);else throw new Error("Neither registry nor components directory found")}let p=[...a.files.map(m=>w(m,l)),...a.directories.flatMap(m=>h.filter(c=>c.startsWith(w(m,l)+"/")))],d=S.resolve(process.cwd(),"registry.json"),u={};v.existsSync(d)&&(u=JSON.parse(await v.promises.readFile(d,"utf8")));let b=F($({},u),{items:[]}),E=[];for(let m of p)if(!((r=n.ignore)!=null&&r.flatMap(c=>c.split(",").map(y=>y.trim())).some(c=>m.endsWith(c))))try{let c=await N([m,...((o=(s=(i=u.items)==null?void 0:i.find(g=>g.name===f(m,{aliases:l}).name))==null?void 0:s.files)==null?void 0:o.map(g=>g.path))||[]],{aliases:l}),y=$(F($({$schema:"https://ui.shadcn.com/schema/registry-item.json",name:f(m,{aliases:l}).name,type:f(m,{aliases:l}).type||"registry:file"},c.dependencies.length&&{dependencies:c.dependencies}),{files:c.files.map(g=>({type:f(g,{aliases:l}).type||"registry:file",target:f(g,{aliases:l}).target||g,content:c.content[g],path:g}))}),Object.fromEntries(Object.entries(((t=u.items)==null?void 0:t.find(g=>g.name===f(m,{aliases:l}).name))||{}).filter(([g])=>!["$schema","name","type","files"].includes(g)))),P=S.resolve(process.cwd(),"public/r",y.name+".json");console.log(`- ${m.padEnd(Math.max(...p.map(g=>g.length))+2," ")} ${c.dependencies.length?"\u{1F4E6}"+String(c.dependencies.length).padEnd(2," "):" "} ${c.files.length-1?"\u{1F4C4}"+String(c.files.length).padEnd(2," "):" "} ${P.replace(process.cwd()+"/","")}`),await v.promises.mkdir(S.dirname(P),{recursive:!0}),await v.promises.writeFile(P,JSON.stringify(y,null,2)+`
18
+ `),y.files.forEach(g=>delete g.content),b.items.push(y)}catch(c){E.push(m+": "+c.message);continue}b.items.sort((m,c)=>m.name.localeCompare(c.name)),await v.promises.writeFile(S.resolve(process.cwd(),"public/registry.json"),JSON.stringify(b,null,2)+`
19
+ `),E.length&&(console.log(),E.forEach(m=>console.error(`\x1B[31m- ${m}\x1B[0m`))),process.exit(0)}catch(e){console.error(z),console.error(`
20
+ ${e.message}
21
+ `),process.exit(1)}};X();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-registry",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "A zero-configuration (no registry.json required), shadcn add / open in v0 compatible registry builder.",
5
5
  "keywords": [
6
6
  "smart-registry"