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 +9 -8
- package/package.json +1 -1
package/dist/bin/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`).map(
|
|
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,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})`,
|
|
17
|
-
`),
|
|
18
|
-
`),
|
|
19
|
-
${
|
|
20
|
-
`),process.exit(1)}};
|
|
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();
|