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