smart-registry 0.5.0 → 0.5.3
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/README.md +1 -25
- package/dist/bin/index.js +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,33 +91,9 @@ Manual maintenance of `registry.json` files can lead to errors due to missing de
|
|
|
91
91
|
|
|
92
92
|
## Usage
|
|
93
93
|
|
|
94
|
-
### Configure Alias
|
|
95
|
-
|
|
96
|
-
Add the following alias to your `tsconfig.json` file.
|
|
97
|
-
|
|
98
|
-
```diff
|
|
99
|
-
{
|
|
100
|
-
"compilerOptions": {
|
|
101
|
-
"baseUrl": ".",
|
|
102
|
-
+ "paths": {
|
|
103
|
-
+ "@/*": ["./src/*"] or ["./*"]
|
|
104
|
-
+ }
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
94
|
### Automatic Detection
|
|
110
95
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
| Alias | Path | Directory (Required) |
|
|
114
|
-
| ----- | --------- | -------------------------- |
|
|
115
|
-
| `@/*` | `./src/*` | `src/components` |
|
|
116
|
-
| `@/*` | `./*` | `components` or `registry` |
|
|
117
|
-
|
|
118
|
-
<br/>
|
|
119
|
-
|
|
120
|
-
Then, run the following command:
|
|
96
|
+
If your project contains a `registry`, `components`, or `src/components` directory, `Smart Registry` will automatically detect and generate the necessary registry files. For more details, refer to the [directory structure](#directory-structure) section.
|
|
121
97
|
|
|
122
98
|
```bash
|
|
123
99
|
npx smart-registry
|
package/dist/bin/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var z=Object.defineProperty,q=Object.defineProperties;var B=Object.getOwnPropertyDescriptors;var
|
|
3
|
-
`).map(n=>n.trim()).filter(n=>n&&!n.startsWith("#")).map(n=>n.replace(/^\//,""));i=i.concat(
|
|
4
|
-
${A}@${
|
|
2
|
+
var z=Object.defineProperty,q=Object.defineProperties;var B=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var J=(t,i,r)=>i in t?z(t,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[i]=r,$=(t,i)=>{for(var r in i||(i={}))T.call(i,r)&&J(t,r,i[r]);if(_)for(var r of _(i))U.call(i,r)&&J(t,r,i[r]);return t},E=(t,i)=>q(t,B(i));import v from"node:fs";import S from"node:path";import{parseArgs as K}from"node:util";import F from"node:fs";import Z from"strip-json-comments";var C=async()=>{let t={};if(F.existsSync("tsconfig.json")){let r=await F.promises.readFile("tsconfig.json","utf8"),{compilerOptions:n}=JSON.parse(Z(r,{trailingCommas:!0}));if(n.paths){if(t=Object.entries(n.paths).reduce((s,[e,[a]])=>(s[e.replace(/\*$/,"")]=a.replace(/^\.\//,"").replace(/\*$/,""),s),{}),!Object.keys(t).includes("@/"))throw new Error("No alias key '@/' found in compilerOptions.paths!");return console.log(t),t}}let i=["registry","components","src/components"];for(let r of i)if(F.existsSync(r))return t["@/"]=r==="src/components"?"src/":"",t;throw new Error("Could not resolve aliases!")};import j from"node:fs";import k from"node:path";import{glob as G}from"tinyglobby";var R=t=>{if(k.extname(t)!=="")return t;{let r=t.split(/\/|\\/).slice(0,-1).join(k.sep);if(!j.existsSync(r))return"";let n=j.readdirSync(r);n=n.map(e=>r+k.sep+e);let s=n.find(e=>e.startsWith(t+"."));return s=s==null?void 0:s.replace(process.cwd()+k.sep,""),s||""}},V=async({patterns:t=["**",".**"],ignore:i=[]}={})=>{if(t=Array.isArray(t)?t:[t],i=Array.isArray(i)?i:[i],j.existsSync(".gitignore")){let r=(await j.promises.readFile(".gitignore","utf8")).split(`
|
|
3
|
+
`).map(n=>n.trim()).filter(n=>n&&!n.startsWith("#")).map(n=>n.replace(/^\//,""));i=i.concat(r)}return await G(t,{ignore:i.filter(r=>!t.includes(r))})};import M from"node:fs";import x from"node:path";import H from"node:path";var d=(t,i={})=>{var n;t=i.aliases?t.replace(i.aliases["@/"],""):t;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":((n=r.match(/^(blocks|components\/ui|components|hooks|lib|utils)/))==null?void 0:n[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:r.replace(/^(blocks|components\/ui|components|hooks|lib|utils)\//,"").replace(/\.[^\/.]+$/,""),import:"@/"+r.replace(process.cwd()+H.sep,"").replace(/\.[^/.]+$/,""),target:r,path:t}};var w=(t,i)=>Object.entries(i).sort(([n],[s])=>s.length-n.length).reduce((n,[s,e])=>n.replace(s,e),t),N=async(t,i={})=>{let{aliases:r={},resolved:n=new Set}=i,s={dependencies:[],files:[],content:{}};for(let e of t){if(n.has(e))continue;n.add(e),s.files.push(e),s.content[e]=s.content[e]||await M.promises.readFile(e,"utf8");let a=s.content[e].match(/import\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]/g);if(!a)continue;let o=a.map(f=>{var h;return(h=f.match(/['"](.*)['"]/))==null?void 0:h[1]});for(let f of o)if(Object.keys(r).some(c=>f.startsWith(c))){let c=w(f,r);c=R(c),c&&!s.files.includes(c)&&s.files.push(c)}else if(f.startsWith(".")){let c=x.resolve(x.dirname(e),f);c=R(c),c&&!s.files.includes(c)&&s.files.push(c)}else{let c=["fs","path","util"],g=f.split("/").slice(0,2).join("/");g=g.startsWith("@")?g:g.split("/")[0],/^[a-zA-Z0-9@/-]+$/.test(g)&&!c.includes(g)&&!s.dependencies.includes(g)&&s.dependencies.push(g)}}for(let e of s.files){let a=await N([e],{aliases:r,resolved:n});a.dependencies.forEach(o=>{s.dependencies.includes(o)||s.dependencies.push(o)}),a.files.forEach(o=>{s.files.includes(o)||s.files.push(o)}),s.content[e]=a.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,a=>{var h,c,g;let o=(h=a.match(/['"](.*)['"]/))==null?void 0:h[1];if(Object.keys(r).some(u=>o.startsWith(u))){let u=w(o,r),y=(c=d(u,{aliases:r}))==null?void 0:c.import;return a.replace(o,y)}else if(o.startsWith(".")){let u=x.resolve(x.dirname(e),o),y=(g=d(u,{aliases:r}))==null?void 0:g.import;return a.replace(o,y)}else return a});return s.dependencies.sort(),s.files.sort((e,a)=>d(e,{aliases:r}).target.localeCompare(d(a,{aliases:r}).target)),s.files.sort((e,a)=>{let o=["registry:file","registry:block","registry:component","registry:ui","registry:hook","registry:lib"],f=d(e,{aliases:r}).type,h=d(a,{aliases:r}).type;return o.indexOf(f)-o.indexOf(h)}),s};var A="smart-registry",D="0.5.3";var O={name:"Neeraj Dalal",email:"admin@nrjdalal.com",url:"https://nrjdalal.com"};var I=`Version:
|
|
4
|
+
${A}@${D}
|
|
5
5
|
|
|
6
6
|
Usage:
|
|
7
7
|
$ ${A} [options]
|
|
@@ -13,8 +13,8 @@ Options:
|
|
|
13
13
|
-h, --help Display help
|
|
14
14
|
|
|
15
15
|
Author:
|
|
16
|
-
${O.name} <${O.email}> (${O.url})`,
|
|
17
|
-
`),b.files.forEach(m=>delete m.content),u.items.push(b)}catch(p){y.push(l+": "+p.message);continue}u.items.sort((l,p)=>l.name.localeCompare(p.name)),await
|
|
16
|
+
${O.name} <${O.email}> (${O.url})`,L=t=>{try{return K(t)}catch(i){throw new Error(`Error parsing arguments: ${i.message}`)}},Q=async()=>{var t,i,r,n;try{let{positionals:s,values:e}=L({allowPositionals:!0,options:{files:{type:"string",multiple:!0,short:"f"},directories:{type:"string",multiple:!0,short:"d"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});s.length||(e.version&&(console.log(`${A}@${D}`),process.exit(0)),e.help&&(console.log(I),process.exit(0)));let a={files:e.files||[],directories:e.directories||[]},o=await C(),f=await V();if(!a.files.length&&!a.directories.length){let l=["registry","components"].map(p=>o["@/"]+p).find(p=>f.some(b=>b.startsWith(p+"/")));if(l)a.directories.push(l);else throw new Error("Neither registry nor components directory found")}let h=[...a.files.map(l=>w(l,o)),...a.directories.flatMap(l=>f.filter(p=>p.startsWith(w(l,o)+"/")))],c=S.resolve(process.cwd(),"registry.json"),g={};v.existsSync(c)&&(g=JSON.parse(await v.promises.readFile(c,"utf8")));let u=E($({},g),{items:[]}),y=[];for(let l of h)try{let p=await N([l,...((r=(i=(t=g.items)==null?void 0:t.find(m=>m.name===d(l,{aliases:o}).name))==null?void 0:i.files)==null?void 0:r.map(m=>m.path))||[]],{aliases:o}),b=$(E($({$schema:"https://ui.shadcn.com/schema/registry-item.json",name:d(l,{aliases:o}).name,type:d(l,{aliases:o}).type||"registry:file"},p.dependencies.length&&{dependencies:p.dependencies}),{files:p.files.map(m=>({type:d(m,{aliases:o}).type||"registry:file",target:d(m,{aliases:o}).target||m,content:p.content[m],path:m}))}),Object.fromEntries(Object.entries(((n=g.items)==null?void 0:n.find(m=>m.name===d(l,{aliases:o}).name))||{}).filter(([m])=>!["$schema","name","type","files"].includes(m)))),P=S.resolve(process.cwd(),"public/r",b.name+".json");console.log(`- ${l.padEnd(Math.max(...h.map(m=>m.length))+2," ")} ${p.dependencies.length?"\u{1F4E6}"+String(p.dependencies.length).padEnd(2," "):" "} ${p.files.length-1?"\u{1F4C4}"+String(p.files.length).padEnd(2," "):" "} ${P.replace(process.cwd()+"/","")}`),await v.promises.mkdir(S.dirname(P),{recursive:!0}),await v.promises.writeFile(P,JSON.stringify(b,null,2)+`
|
|
17
|
+
`),b.files.forEach(m=>delete m.content),u.items.push(b)}catch(p){y.push(l+": "+p.message);continue}u.items.sort((l,p)=>l.name.localeCompare(p.name)),await v.promises.writeFile(S.resolve(process.cwd(),"public/registry.json"),JSON.stringify(u,null,2)+`
|
|
18
18
|
`),y.length&&(console.log(),y.forEach(l=>console.error(`\x1B[31m- ${l}\x1B[0m`))),process.exit(0)}catch(s){console.error(I),console.error(`
|
|
19
19
|
${s.message}
|
|
20
|
-
`),process.exit(1)}};
|
|
20
|
+
`),process.exit(1)}};Q();
|