smart-registry 0.5.5 → 0.5.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/bin/index.js CHANGED
@@ -1,21 +1,22 @@
1
1
  #!/usr/bin/env node
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}@${_}
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,t)=>i in r?q(r,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[i]=t,x=(r,i)=>{for(var t in i||(i={}))U.call(i,t)&&C(r,t,i[t]);if(J)for(var t of J(i))Z.call(i,t)&&C(r,t,i[t]);return r},R=(r,i)=>B(r,T(i));import v from"node:fs";import O from"node:path";import{parseArgs as L}from"node:util";import $ from"node:fs";import G from"strip-json-comments";var M=async()=>{let r={},i=["registry","components","src/components"];if($.existsSync("tsconfig.json")){let t=await $.promises.readFile("tsconfig.json","utf8"),{compilerOptions:o}=JSON.parse(G(t,{trailingCommas:!0}));if(o.paths){r=Object.entries(o.paths).reduce((s,[e,[n]])=>(s[e.replace(/\*$/,"")]=n.replace(/^\.\//,"").replace(/\*$/,""),s),{});for(let s of i)$.existsSync(s)&&(r["@/"]=s==="src/components"?"src/":"");if(!Object.keys(r).includes("@/"))throw new Error("No alias key '@/' found in compilerOptions.paths!");return r}}for(let t of i)if($.existsSync(t))return r["@/"]=t==="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 t=r.split(/\/|\\/).slice(0,-1).join(k.sep);if(t=t.replace(/\/\//g,"/"),!j.existsSync(t))return"";let o=j.readdirSync(t);o=o.map(e=>t+k.sep+e);let s=o.find(e=>e.startsWith(r+"."));return s=s==null?void 0:s.replace(process.cwd()+k.sep,""),s||""}},V=async({patterns:r=["**",".**"],ignore:i=[]}={})=>{if(r=Array.isArray(r)?r:[r],i=Array.isArray(i)?i:[i],j.existsSync(".gitignore")){let t=(await j.promises.readFile(".gitignore","utf8")).split(`
3
+ `).map(o=>o.trim()).filter(o=>o&&!o.startsWith("#")).map(o=>o.replace(/^\//,""));i=i.concat(t)}return await H(r,{ignore:i.filter(t=>!r.includes(t))})};import I from"node:fs";import A from"node:path";import K from"node:path";var f=(r,i={})=>{var o;r=i.aliases?r.replace(i.aliases["@/"],""):r;let t=r.startsWith("registry/")?r.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,""):r.replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,"");return{type:t.endsWith("page.tsx")?"registry:page":((o=t.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:t.replace(/^(blocks|components\/ui|components|hooks|lib|utils)\//,"").replace(/\.[^\/.]+$/,""),import:"@/"+t.replace(process.cwd()+K.sep,"").replace(/\.[^/.]+$/,""),target:t,path:r}};var w=(r,i)=>Object.entries(i).sort(([o],[s])=>s.length-o.length).reduce((o,[s,e])=>o.replace(s,e),r),N=async(r,i={})=>{let{aliases:t={},resolved:o=new Set}=i,s={dependencies:[],files:[],content:{}};for(let e of r){if(o.has(e))continue;o.add(e),s.files.push(e),s.content[e]=s.content[e]||await I.promises.readFile(e,"utf8");let n=s.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(t).some(p=>l.startsWith(p))){let p=w(l,t);p=W(p),p&&!s.files.includes(p)&&s.files.push(p)}else if(l.startsWith(".")){let p=A.resolve(A.dirname(e),l);p=W(p),p&&!s.files.includes(p)&&s.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)&&!s.dependencies.includes(d)&&s.dependencies.push(d)}}for(let e of s.files){let n=await N([e],{aliases:t,resolved:o});n.dependencies.forEach(a=>{s.dependencies.includes(a)||s.dependencies.push(a)}),n.files.forEach(a=>{s.files.includes(a)||s.files.push(a)}),s.content[e]=n.content[e]||await I.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,n=>{var h,p,d;let a=(h=n.match(/['"](.*)['"]/))==null?void 0:h[1];if(Object.keys(t).some(u=>a.startsWith(u))){let u=w(a,t),b=(p=f(u,{aliases:t}))==null?void 0:p.import;return n.replace(a,b)}else if(a.startsWith(".")){let u=A.resolve(A.dirname(e),a),b=(d=f(u,{aliases:t}))==null?void 0:d.import;return n.replace(a,b)}else return n});return s.dependencies.sort(),s.files.sort((e,n)=>f(e,{aliases:t}).target.localeCompare(f(n,{aliases:t}).target)),s.files.sort((e,n)=>{let a=["registry:file","registry:block","registry:component","registry:ui","registry:hook","registry:lib"],l=f(e,{aliases:t}).type,h=f(n,{aliases:t}).type;return a.indexOf(l)-a.indexOf(h)}),s};var S="smart-registry",_="0.5.5";var E={name:"Neeraj Dalal",email:"admin@nrjdalal.com",url:"https://nrjdalal.com"};var z=`Version:
4
+ ${S}@${_}
5
5
 
6
6
  Usage:
7
- $ ${A} [options]
7
+ $ ${S} [options]
8
8
 
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
+ -i, --ignore Endings/Extensions to ignore (comma separated)
13
+ e.g. -i ".spec.ts, .test.ts, demo.tsx"
13
14
  -v, --version Display version
14
15
  -h, --help Display help
15
16
 
16
17
  Author:
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(`
18
+ ${E.name} <${E.email}> (${E.url})`,Q=r=>{try{return L(r)}catch(i){throw new Error(`Error parsing arguments: ${i.message}`)}},X=async()=>{var r,i,t,o,s;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(`${S}@${_}`),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=O.resolve(process.cwd(),"registry.json"),u={};v.existsSync(d)&&(u=JSON.parse(await v.promises.readFile(d,"utf8")));let b=R(x({},u),{items:[]}),P=[];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=(t=(i=u.items)==null?void 0:i.find(g=>g.name===f(m,{aliases:l}).name))==null?void 0:t.files)==null?void 0:o.map(g=>g.path))||[]],{aliases:l}),y=x(R(x({$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(((s=u.items)==null?void 0:s.find(g=>g.name===f(m,{aliases:l}).name))||{}).filter(([g])=>!["$schema","name","type","files"].includes(g)))),F=O.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," "):" "} ${F.replace(process.cwd()+"/","")}`),await v.promises.mkdir(O.dirname(F),{recursive:!0}),await v.promises.writeFile(F,JSON.stringify(y,null,2)+`
19
+ `),y.files.forEach(g=>delete g.content),b.items.push(y)}catch(c){P.push(m+": "+c.message);continue}b.items.sort((m,c)=>m.name.localeCompare(c.name)),await v.promises.writeFile(O.resolve(process.cwd(),"public/registry.json"),JSON.stringify(b,null,2)+`
20
+ `),P.length&&(console.log(),P.forEach(m=>console.error(`\x1B[31m- ${m}\x1B[0m`))),process.exit(0)}catch(e){console.error(z),console.error(`
20
21
  ${e.message}
21
22
  `),process.exit(1)}};X();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-registry",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
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"