smart-registry 0.5.8 → 0.6.0-canary.0
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 -8
- package/package.json +2 -2
package/dist/bin/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
${S}@${_}
|
|
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}
|
|
5
4
|
|
|
6
5
|
Usage:
|
|
7
|
-
$ ${
|
|
6
|
+
$ ${A} [options]
|
|
8
7
|
|
|
9
8
|
Options:
|
|
10
9
|
-f, --files Files to build the registry from
|
|
@@ -15,8 +14,8 @@ Options:
|
|
|
15
14
|
-h, --help Display help
|
|
16
15
|
|
|
17
16
|
Author:
|
|
18
|
-
${E.name} <${E.email}> (${E.url})`,
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
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(`
|
|
21
20
|
${e.message}
|
|
22
|
-
`),process.exit(1)}};
|
|
21
|
+
`),process.exit(1)}};Q();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smart-registry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-canary.0",
|
|
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,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsup",
|
|
25
|
-
"cli": "
|
|
25
|
+
"cli": "bash scripts/cli.sh",
|
|
26
26
|
"dev": "tsup --watch",
|
|
27
27
|
"prepare": "if [ \"$NODE_ENV\" != \"production\" ]; then npx simple-git-hooks; fi",
|
|
28
28
|
"publish:latest": "NODE_ENV=production changeset publish",
|