smart-registry 0.6.0-canary.0 → 0.6.0-canary.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.
Files changed (2) hide show
  1. package/dist/bin/index.js +15 -14
  2. package/package.json +1 -2
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 D=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var _=(t,i,r)=>i in t?q(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r,x=(t,i)=>{for(var r in i||(i={}))U.call(i,r)&&_(t,r,i[r]);if(D)for(var r of D(i))Z.call(i,r)&&_(t,r,i[r]);return t},S=(t,i)=>B(t,T(i));import k from"node:fs";import $ from"node:path";import{parseArgs as K}from"node:util";import j from"node:fs";import G from"strip-json-comments";var J=async()=>{let t={},i=["registry","components","src/components"];if(j.existsSync("tsconfig.json")){let r=await j.promises.readFile("tsconfig.json","utf8"),{compilerOptions:a}=JSON.parse(G(r,{trailingCommas:!0}));if(a.paths){t=Object.entries(a.paths).reduce((s,[e,[o]])=>(s[e.replace(/\*$/,"")]=o.replace(/^\.\//,"").replace(/\*$/,""),s),{});for(let s of i)j.existsSync(s)&&(t["@/"]=s==="src/components"?"src/":"");if(!Object.keys(t).includes("@/"))throw new Error("No alias key '@/' found in compilerOptions.paths!");return t}}for(let r of i)if(j.existsSync(r))return t["@/"]=r==="src/components"?"src/":"",t;throw new Error("Could not resolve aliases!")};import C from"node:fs";import w from"node:path";import{glob as H}from"tinyglobby";var P=t=>{if(w.extname(t)!=="")return t.replace(process.cwd()+w.sep,"");{let r=t.split(/\/|\\/).slice(0,-1).join(w.sep);if(r=r.replace(/\/\//g,"/"),!C.existsSync(r))return"";let a=C.readdirSync(r);a=a.map(e=>r+w.sep+e);let s=a.find(e=>e.startsWith(t+"."));return s=s||a.find(e=>e.startsWith(t+"/index.")),(s==null?void 0:s.replace(process.cwd()+w.sep,""))||""}},F=async({patterns:t=["**",".**"],cwd:i=w.resolve(process.cwd()),ignore:r=[]}={})=>(t=Array.isArray(t)?t:[t],r=Array.isArray(r)?r:[r],t=t.map(s=>s.endsWith("*")?s:s+"**"),await H(t,{cwd:i,ignore:r.filter(s=>!t.includes(s))}));import M from"node:fs";import v from"node:path";import V from"node:path";var f=(t,i={})=>{var a;t=i.aliases?t.replace(i.aliases["@/"],""):t,t=t.replace(process.cwd()+V.sep,"");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":((a=r.match(/^(blocks|components\/ui|components|hooks|lib|utils|helpers)/))==null?void 0:a[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").replace("helpers","registry:lib"))||"registry:file",name:r.replace(/^(blocks|components\/ui|components|hooks|lib|utils|helpers)\//,"").replace(/\.[^\/.]+$/,""),import:"@/"+r.replace(process.cwd()+V.sep,"").replace(/\.[^/.]+$/,""),target:r,path:t}};var I=(t,i)=>Object.entries(i).sort(([a],[s])=>s.length-a.length).reduce((a,[s,e])=>a.replace(s,e),t),N=async(t,i={})=>{let{aliases:r={},resolved:a=new Set}=i,s={dependencies:[],files:[],content:{}};for(let e of t){if(e=e.replace(process.cwd()+v.sep,""),a.has(e))continue;a.add(e),s.files.push(e),s.content[e]=s.content[e]||await M.promises.readFile(e,"utf8");let o=s.content[e].match(/import\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]/g);if(!o)continue;let n=o.map(h=>{var p;return(p=h.match(/['"](.*)['"]/))==null?void 0:p[1]});for(let h of n)if(Object.keys(r).some(c=>h.startsWith(c))){let c=I(h,r);c=P(c),c&&!s.files.includes(c)&&s.files.push(c)}else if(h.startsWith(".")){let c=v.resolve(v.dirname(e),h);c=P(c),c&&!s.files.includes(c)&&s.files.push(c)}else{let c=["fs","path","util"],m=h.split("/").slice(0,2).join("/");m=m.startsWith("@")?m:m.split("/")[0],/^[a-zA-Z0-9@/-]+$/.test(m)&&!c.includes(m)&&!s.dependencies.includes(m)&&s.dependencies.push(m)}}for(let e of s.files){let o=await N([e],{aliases:r,resolved:a});o.dependencies.forEach(n=>{s.dependencies.includes(n)||s.dependencies.push(n)}),o.files.forEach(n=>{s.files.includes(n)||s.files.push(n)}),s.content[e]=o.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,o=>{var p,c,m;let n=(p=o.match(/['"](.*)['"]/))==null?void 0:p[1];if(Object.keys(r).some(u=>n.startsWith(u))){let u=I(n,r),y=(c=f(u,{aliases:r}))==null?void 0:c.import;return o.replace(n,y)}else if(n.startsWith(".")){let u=v.resolve(v.dirname(e),n),y=(m=f(u,{aliases:r}))==null?void 0:m.import;return o.replace(n,y)}else return o});return s.dependencies.sort(),s.files.sort((e,o)=>f(e,{aliases:r}).target.localeCompare(f(o,{aliases:r}).target)),s.files.sort((e,o)=>{let n=["registry:file","registry:block","registry:component","registry:ui","registry:hook","registry:lib"],h=f(e,{aliases:r}).type,p=f(o,{aliases:r}).type;return n.indexOf(h)-n.indexOf(p)}),s};var A="smart-registry",W="0.6.0-canary.0";var E={name:"Neeraj Dalal",email:"admin@nrjdalal.com",url:"https://nrjdalal.com"};var z=`Version:
3
- ${A}@${W}
2
+ var G=Object.defineProperty,H=Object.defineProperties;var K=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var P=(i,e,s)=>e in i?G(i,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[e]=s,y=(i,e)=>{for(var s in e||(e={}))L.call(e,s)&&P(i,s,e[s]);if(N)for(var s of N(e))Q.call(e,s)&&P(i,s,e[s]);return i},R=(i,e)=>H(i,K(e));import D from"node:fs";import d from"node:path";import{parseArgs as re}from"node:util";import F from"node:fs";import E from"node:path";import X from"strip-json-comments";var _=async i=>{let e={},s=["tsconfig.json","jsconfig.json"].find(o=>F.existsSync(E.resolve(i,o)));if(s){let o=await F.promises.readFile(E.resolve(i,s),"utf8"),{compilerOptions:t}=JSON.parse(X(o,{trailingCommas:!0}));t.paths&&(e=Object.entries(t.paths).reduce((n,[r,[a]])=>(r.endsWith("*")&&a.endsWith("*")&&(n[r.replace(/\*$/,"")]=a.replace(/\*$/,"")),n),{}))}return e["@/"]||(e["@/"]=F.existsSync(E.resolve(i,"src"))?"./src/":"./"),e=Object.entries(e).sort(([o],[t])=>t.length-o.length).reduce((o,[t,n])=>(o[t]=n,o),{}),e};import I from"node:fs";import Y from"node:path";var J=async i=>{let e=Y.resolve(i,"registry.json"),s={$schema:"https://ui.shadcn.com/schema/registry.json",name:"nrjdalal",homepage:"https://nrjdalal.com",items:[]};return I.existsSync(e)&&(s=y({},JSON.parse(await I.promises.readFile(e,"utf8")))),s};import M from"node:fs";import V from"node:path";import{glob as Z}from"tinyglobby";var u=async({cwd:i,patterns:e=["**",".**"],ignore:s=[]})=>{e=Array.isArray(e)?e:[e],e=e.map(t=>t.replace(/^'|'$/g,"").replace(/^"|"$/g,"").trim()),e=[...e,...e.flatMap(t=>t.includes("*")?[]:[t+".**",t+"**"])],e=e.filter(Boolean),s=typeof s=="string"?s.split(",").map(t=>t.trim()):s,s=s.filter(Boolean);let o=await Z(e,{cwd:i,ignore:s.filter(t=>!e.includes(t))});if(!o.length)for(let t of e)try{let n=V.resolve(i,t),r=await M.promises.stat(n);if(r.isDirectory()){let a=(await M.promises.readdir(n)).map(c=>V.resolve(t,c));o.push(...a)}else r.isFile()&&o.push(t)}catch(n){continue}return o};var C=["registry/**",["blocks/**","components/**","helpers/**","hooks/**","lib/**","ui/**","utils/**"],["src/blocks/**","src/components/**","src/helpers/**","src/hooks/**","src/lib/**","src/ui/**","src/utils/**"]];var B=async({cwd:i,patterns:e,ignore:s})=>{let o=[];if(e.length)o=await u({cwd:i,patterns:e,ignore:s});else for(let t of C)if(o=await u({cwd:i,patterns:t,ignore:s}),o.length)break;if(!o.length)throw new Error("No files/directories found to build the registry from!");return o};import q from"node:fs";import z from"node:path";var x={imports:/import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+[\s\S]+?from\s+['"][^'"]+['"]/g};var S=async({cwd:i,aliases:e,filepaths:s,resolved:o})=>{o=o!=null?o:new Set;let t={dependencies:[],files:[],content:{}};for(let n of s){if(o.has(n))continue;o.add(n),t.files.push(n),t.content[n]||(t.content[n]=await q.promises.readFile(z.resolve(i,n),"utf8"));let{dependencies:r,files:a,transformations:c}=await T({cwd:i,aliases:e,filepath:n,content:t.content[n]});t.content[n]=t.content[n].replace(x.imports,l=>{let h=l.match(/['"](.*)['"]/);return h&&c[h[1]]?l.replace(h[1],c[h[1]].import):l}),a.forEach(l=>t.files.push(l)),r.forEach(l=>t.dependencies.push(l))}for(let n of t.files){let{dependencies:r,files:a,content:c}=await S({cwd:i,aliases:e,filepaths:[n],resolved:o});t.content[n]||(t.content[n]=c[n]||await q.promises.readFile(z.resolve(i,n),"utf8")),a.forEach(l=>t.files.push(l)),r.forEach(l=>t.dependencies.push(l))}return t.dependencies=[...new Set(t.dependencies)].sort(),t.files=[...new Set(t.files)].sort(),t};import O from"node:path";import ee from"node:path";var f=({cwd:i,aliases:e,filepath:s})=>{var t;for(let n in e)s=s.replace(e[n].replaceAll("./","").replaceAll("../",""),"");let o=s.startsWith("registry/")?s.replace(/^registry\//,"").replace(/^(?:([^\/]*)\/)?blocks\//,(n,r)=>`blocks/${r?r+"/":""}`).replace(/^(?:([^\/]*)\/)?components\/ui\//,(n,r)=>`${r?r+"/":""}ui/`).replace(/^(?:([^\/]*)\/)?components\//,(n,r)=>`components/${r?r+"/":""}`).replace(/^(?:([^\/]*)\/)?hooks\//,(n,r)=>`hooks/${r?r+"/":""}`).replace(/^(?:([^\/]*)\/)?lib\//,(n,r)=>`lib/${r?r+"/":""}`).replace(/^(?:([^\/]*)\/)?ui\//,(n,r)=>`components/ui/${r?r+"/":""}`).replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,""):s.replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,"");return{type:o.endsWith("page.tsx")?"registry:page":((t=o.match(/^(blocks|components\/ui|components|hooks|lib|utils|helpers)/))==null?void 0:t[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").replace("helpers","registry:lib"))||"registry:file",name:o.replace(/^(blocks|components\/ui|components|hooks|lib|utils|helpers)\//,"").replace(/\.[^\/.]+$/,"").replace(/\/index$/,"").replace(/\/route$/,"").replace(/\/\[.*\]$/,""),import:"@/"+o.replace(i+ee.sep,"").replace(/\.[^/.]+$/,"").replace(/\/index$/,""),target:o,path:s}};var te=async({cwd:i,current:e,aliases:s})=>{e=e.replace(new RegExp(`^${Object.keys(s).find(t=>e.startsWith(t.replace(/\.\//g,"").replace(/\.\.\//g,"")))}`),s[Object.keys(s).find(t=>e.startsWith(t.replace(/\.\//g,"").replace(/\.\.\//g,"")))]),e=e.replace(/\.\//g,"").replace(/\.\.\//g,"");let o=await u({cwd:i,patterns:e});return e=o.find(t=>t.startsWith(e+"."))||o.find(t=>t.startsWith(e+"/index"))||e,e.replace(i+"/","")},se=async({cwd:i,filepath:e,current:s})=>{s=O.relative(i,O.resolve(i,O.dirname(e),s));let o=await u({cwd:i,patterns:s});return s=o.find(t=>t.startsWith(s+"."))||o.find(t=>t.startsWith(s+"/index"))||s,s.replace(i+"/","")},T=async({cwd:i,aliases:e,filepath:s,content:o})=>{let t={dependencies:[],files:[],transformations:{}},n=o.match(x.imports)||[];if(!n.length)return t;n=n.map(r=>{var a;return(a=r.match(/['"](.*)['"]/))==null?void 0:a[1].replace(/\/\//g,"/")});for(let r of n){let a=r;Object.keys(e).some(l=>r.startsWith(l.replace(/\.\//g,"").replace(/\.\.\//g,"")))?(r=await te({cwd:i,aliases:e,current:r}),t.transformations[a]=f({cwd:i,aliases:e,filepath:r}),t.files.push(r)):r.startsWith(".")?(r=await se({cwd:i,filepath:s,current:r}),t.transformations[a]=f({cwd:i,aliases:e,filepath:r}),t.files.push(r)):r.startsWith("@")?t.dependencies.push(r.split("/").slice(0,2).join("/")):t.dependencies.push(r.replace(/\/.*/,""))}return t};var w="smart-registry",A="0.6.0-canary.0";var $={name:"Neeraj Dalal",email:"admin@nrjdalal.com",url:"https://nrjdalal.com"};var U=`Version:
3
+ ${w}@${A}
4
4
 
5
5
  Usage:
6
- $ ${A} [options]
6
+ $ ${w} [options] [files/directories] ...
7
+
8
+ Arguments:
9
+ files/directories files or directories to build the registry from (optional)
7
10
 
8
11
  Options:
9
- -f, --files Files to build the registry from
10
- -d, --directories Directories to build the registry from
11
- -i, --ignore Endings/Extensions to ignore (comma separated)
12
- e.g. -i ".spec.ts, .test.ts, demo.tsx"
13
- -v, --version Display version
14
- -h, --help Display help
12
+ -o, --output <path> destination directory for json files (default: "./public/r")
13
+ -c, --cwd <cwd> the working directory (default: "./")
14
+ -v, --version display version
15
+ -h, --help display help
15
16
 
16
17
  Author:
17
- ${E.name} <${E.email}> (${E.url})`,L=t=>{try{return K(t)}catch(i){throw new Error(`Error parsing arguments: ${i.message}`)}},Q=async()=>{var t,i,r,a,s;try{let{positionals:e,values:o}=L({allowPositionals:!0,options:{cwd:{type:"string",short:"c"},ignore:{type:"string",multiple:!0,short:"i"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});e.length||(o.version&&(console.log(`${A}@${W}`),process.exit(0)),o.help&&(console.log(z),process.exit(0)));let n=[],h=$.resolve(o.cwd||process.cwd());if(e.length)n=await F({patterns:e,cwd:h,ignore:o.ignore});else{for(let d of["registry/**","components/**","src/components/**"])if(n=await F({patterns:d,cwd:h,ignore:o.ignore}),n.length)break;if(!n.length)throw new Error("No files found in the registry, components, or src/components directories")}let p=await J(),c=$.resolve(process.cwd(),"registry.json"),m={};k.existsSync(c)&&(m=JSON.parse(await k.promises.readFile(c,"utf8")));let u=S(x({},m),{items:[]}),y=[];for(let d of n)if(!((t=o.ignore)!=null&&t.flatMap(g=>g.split(",").map(b=>b.trim())).some(g=>d.endsWith(g))))try{let g=await N([d,...((a=(r=(i=m.items)==null?void 0:i.find(l=>l.name===f(d,{aliases:p}).name))==null?void 0:r.files)==null?void 0:a.map(l=>l.path))||[]],{aliases:p}),b=x(S(x({$schema:"https://ui.shadcn.com/schema/registry-item.json",name:f(d,{aliases:p}).name,type:f(d,{aliases:p}).type||"registry:file"},g.dependencies.length&&{dependencies:g.dependencies}),{files:g.files.map(l=>({type:f(l,{aliases:p}).type||"registry:file",target:f(l,{aliases:p}).target||l,content:g.content[l],path:l}))}),Object.fromEntries(Object.entries(((s=m.items)==null?void 0:s.find(l=>l.name===f(d,{aliases:p}).name))||{}).filter(([l])=>!["$schema","name","type","files"].includes(l)))),O=$.resolve(process.cwd(),"public/r",b.name+".json");console.log(`- ${d.padEnd(Math.max(...n.map(l=>l.length))+2," ")} ${g.dependencies.length?"\u{1F4E6}"+String(g.dependencies.length).padEnd(2," "):" "} ${g.files.length-1?"\u{1F4C4}"+String(g.files.length).padEnd(2," "):" "} ${O.replace(process.cwd()+"/","")}`),await k.promises.mkdir($.dirname(O),{recursive:!0}),await k.promises.writeFile(O,JSON.stringify(b,null,2)+`
18
- `),b.files.forEach(l=>delete l.content),u.items.push(b)}catch(g){y.push(d+": "+g.message);continue}u.items.sort((d,g)=>d.name.localeCompare(g.name)),await k.promises.writeFile($.resolve(process.cwd(),"public/registry.json"),JSON.stringify(u,null,2)+`
19
- `),y.length&&(console.log(),y.forEach(d=>console.error(`\x1B[31m- ${d}\x1B[0m`))),process.exit(0)}catch(e){console.error(z),console.error(`
20
- ${e.message}
21
- `),process.exit(1)}};Q();
18
+ ${$.name} <${$.email}> (${$.url})`,ie=i=>{try{return re(i)}catch(e){throw new Error(`Error parsing arguments: ${e.message}`)}},oe=async()=>{var i,e,s,o,t;try{let{positionals:n,values:r}=ie({allowPositionals:!0,options:{cwd:{type:"string",short:"c"},ignore:{type:"string",short:"i",default:""},output:{type:"string",short:"o",default:"public/r"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});n.length||(r.version&&(console.log(`${w}@${A}`),process.exit(0)),r.help&&(console.log(U),process.exit(0)));let a=d.resolve((i=r.cwd)!=null?i:process.cwd()),c=await _(a),l=await J(a),h=await B({cwd:a,patterns:n,ignore:r.ignore}),v=[],j=R(y({},l),{items:[]});for(let g of h)try{let m=await S({cwd:a,aliases:c,filepaths:[g,...((o=(s=(e=l.items)==null?void 0:e.find(p=>p.name===f({cwd:a,aliases:c,filepath:g}).name))==null?void 0:s.files)==null?void 0:o.map(p=>p.path))||[]]}),b=y(R(y({$schema:"https://ui.shadcn.com/schema/registry-item.json",name:f({cwd:a,aliases:c,filepath:g}).name,type:f({cwd:a,aliases:c,filepath:g}).type||"registry:file"},m.dependencies.length&&{dependencies:m.dependencies}),{files:m.files.map(p=>({type:f({cwd:a,aliases:c,filepath:p}).type||"registry:file",target:f({cwd:a,aliases:c,filepath:p}).target||p,content:m.content[p],path:p}))}),Object.fromEntries(Object.entries(((t=l.items)==null?void 0:t.find(p=>p.name===f({cwd:a,aliases:c,filepath:g}).name))||{}).filter(([p])=>!["$schema","name","type","files"].includes(p)))),k=d.resolve(a,r.output,b.name+".json");console.log(`- ${d.relative(process.cwd(),d.resolve(a,g)).padEnd(Math.max(...h.map(p=>d.relative(process.cwd(),d.resolve(a,p)).length))+2," ")} ${m.dependencies.length?"\u{1F4E6}"+String(m.dependencies.length).padEnd(2," "):" "} ${m.files.length-1?"\u{1F4C4}"+String(m.files.length).padEnd(2," "):" "} ${d.relative(process.cwd(),k)}`),await D.promises.mkdir(d.dirname(k),{recursive:!0}),await D.promises.writeFile(k,JSON.stringify(b,null,2)+`
19
+ `),b.files.forEach(p=>delete p.content),j.items.push(b)}catch(m){v.push(g+": "+m.message);continue}j.items.sort((g,m)=>g.name.localeCompare(m.name)),await D.promises.writeFile(d.resolve(a,r.output,"registry.json"),JSON.stringify(j,null,2)+`
20
+ `),v.length&&(console.log(),v.forEach(g=>console.error(`\x1B[31m- ${g}\x1B[0m`))),process.exit(0)}catch(n){console.error(U),console.error(`
21
+ ${n.message}
22
+ `),process.exit(1)}};oe();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-registry",
3
- "version": "0.6.0-canary.0",
3
+ "version": "0.6.0-canary.2",
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"
@@ -22,7 +22,6 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "build": "tsup",
25
- "cli": "bash scripts/cli.sh",
26
25
  "dev": "tsup --watch",
27
26
  "prepare": "if [ \"$NODE_ENV\" != \"production\" ]; then npx simple-git-hooks; fi",
28
27
  "publish:latest": "NODE_ENV=production changeset publish",