smart-registry 0.6.5 → 0.7.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/README.md +13 -9
- package/dist/bin/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,10 +76,8 @@ Manual maintenance of `registry.json` files can lead to errors due to missing de
|
|
|
76
76
|
## Table of Contents
|
|
77
77
|
|
|
78
78
|
- [Usage](#usage)
|
|
79
|
-
- [Configure Alias](#configure-alias)
|
|
80
79
|
- [Automatic Detection](#automatic-detection)
|
|
81
|
-
- [
|
|
82
|
-
- [From Specific Directories](#from-specific-directories)
|
|
80
|
+
- [Advanced Usage](#advanced-usage)
|
|
83
81
|
- [How it Works](#how-it-works)
|
|
84
82
|
- [Extending Properties](#extending-properties)
|
|
85
83
|
- [With zero-configuration](#with-zero-configuration)
|
|
@@ -88,6 +86,10 @@ Manual maintenance of `registry.json` files can lead to errors due to missing de
|
|
|
88
86
|
- [External registry dependencies](#external-registry-dependencies)
|
|
89
87
|
- [Specify dependency version](#specify-dependency-version)
|
|
90
88
|
- [Directory Structure](#directory-structure)
|
|
89
|
+
- [For `registry` directory](#for-registry-directory)
|
|
90
|
+
- [For `registry` directory with multiple registries](#for-registry-directory-with-multiple-registries)
|
|
91
|
+
- [For `components` directory](#for-components-directory)
|
|
92
|
+
- [For `components` directory with multiple registries](#for-components-directory-with-multiple-registries)
|
|
91
93
|
|
|
92
94
|
## Usage
|
|
93
95
|
|
|
@@ -99,12 +101,16 @@ If your project contains a `registry`, `components`, or `src/components` directo
|
|
|
99
101
|
npx smart-registry
|
|
100
102
|
```
|
|
101
103
|
|
|
104
|
+
### Advanced Usage
|
|
105
|
+
|
|
106
|
+
You can customize the output directory, working directory, and provide files or directories to build the registry from.
|
|
107
|
+
|
|
102
108
|
```plaintext
|
|
103
109
|
Version:
|
|
104
|
-
|
|
110
|
+
smart-registry@x.y.z
|
|
105
111
|
|
|
106
112
|
Usage:
|
|
107
|
-
$
|
|
113
|
+
$ smart-registry [files/directories] ... [options]
|
|
108
114
|
|
|
109
115
|
Arguments:
|
|
110
116
|
files/directories files or directories to build the registry from (optional)
|
|
@@ -119,12 +125,10 @@ Author:
|
|
|
119
125
|
${author.name} <${author.email}> (${author.url})
|
|
120
126
|
```
|
|
121
127
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
If you want to generate the registry from specific files or directories, you can pass them as arguments.
|
|
128
|
+
e.g. To generate the registry in the `public/r` directory.
|
|
125
129
|
|
|
126
130
|
```bash
|
|
127
|
-
npx smart-registry path/to/file.
|
|
131
|
+
npx smart-registry path/to/file.ext path/to/directory ... --output public/r --cwd .
|
|
128
132
|
```
|
|
129
133
|
|
|
130
134
|
## How it Works
|
package/dist/bin/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var Q=Object.defineProperty,X=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var J=(i,t,s)=>t in i?Q(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s,u=(i,t)=>{for(var s in t||(t={}))Z.call(t,s)&&J(i,s,t[s]);if(I)for(var s of I(t))C.call(t,s)&&J(i,s,t[s]);return i},F=(i,t)=>X(i,Y(t));import _ from"node:fs";import h from"node:path";import{parseArgs as oe}from"node:util";var M=["registry/**",["blocks/**","components/**","helpers/**","hooks/**","lib/**","ui/**","utils/**"],["src/blocks/**","src/components/**","src/helpers/**","src/hooks/**","src/lib/**","src/ui/**","src/utils/**"]],j={default:["$schema","name","homepage","items"],items:{default:["$schema","name","type","description","title","author","dependencies","devDependencies","registryDependencies","files","tailwind","cssVars","meta","docs","categories"],type:{default:["registry:ui","registry:hook","registry:lib","registry:theme","registry:page","registry:file","registry:component","registry:block"]},files:{default:["type","target","content","path"],type:{default:["registry:block","registry:component","registry:file","registry:page","registry:theme","registry:lib","registry:hook","registry:ui"]}}}};import S from"node:fs";import E from"node:path";import ee from"strip-json-comments";var V=async i=>{let t={},s=["tsconfig.json","jsconfig.json"].find(n=>S.existsSync(E.resolve(i,n)));if(s){let n=await S.promises.readFile(E.resolve(i,s),"utf8"),{compilerOptions:e}=JSON.parse(ee(n,{trailingCommas:!0}));e.paths&&(t=Object.entries(e.paths).reduce((r,[o,[a]])=>(o.endsWith("*")&&a.endsWith("*")&&(r[o.replace(/\*$/,"")]=a.replace(/\*$/,"")),r),{}))}return t["@/"]||(t["@/"]=S.existsSync(E.resolve(i,"src"))?"./src/":"./"),t=Object.entries(t).sort(([n],[e])=>e.length-n.length).reduce((n,[e,r])=>(n[e]=r,n),{}),t};import B from"node:fs";import te from"node:path";var q=async i=>{let t=te.resolve(i,"registry.json"),s={$schema:"https://ui.shadcn.com/schema/registry.json",name:"nrjdalal",homepage:"https://nrjdalal.com",items:[]};return B.existsSync(t)&&(s=u({},JSON.parse(await B.promises.readFile(t,"utf8")))),s};import z from"node:fs";import T from"node:path";import{glob as se}from"tinyglobby";var v=async({cwd:i,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 n=await se(t,{cwd:i,ignore:s.filter(e=>!t.includes(e))});if(!n.length)for(let e of t)try{let r=T.resolve(i,e),o=await z.promises.stat(r);if(o.isDirectory()){let a=(await z.promises.readdir(r)).map(g=>T.resolve(e,g));n.push(...a)}else o.isFile()&&n.push(e)}catch(r){continue}return n};var U=async({cwd:i,patterns:t,ignore:s})=>{let n=[];if(t.length)n=await v({cwd:i,patterns:t,ignore:s});else for(let e of M)if(n=await v({cwd:i,patterns:e,ignore:s}),n.length)break;if(!n.length)throw new Error("No files/directories found to build the registry from!");return n};import G from"node:fs";import H from"node:path";var k={imports:/import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+[\s\S]+?from\s+['"][^'"]+['"]/g};var W=async({cwd:i,aliases:t,filepaths:s,resolved:n})=>{n=n!=null?n:new Set;let e={dependencies:[],files:[],content:{}};for(let r of s){if(n.has(r))continue;n.add(r),e.files.push(r),e.content[r]||(e.content[r]=await G.promises.readFile(H.resolve(i,r),"utf8"));let{dependencies:o,files:a,transformations:g}=await K({cwd:i,aliases:t,filepath:r,content:e.content[r]});e.content[r]=e.content[r].replace(k.imports,c=>{let y=c.match(/['"](.*)['"]/);return y&&g[y[1]]?c.replace(y[1],g[y[1]].import):c}),a.forEach(c=>e.files.push(c)),o.forEach(c=>e.dependencies.push(c))}for(let r of e.files){let{dependencies:o,files:a,content:g}=await W({cwd:i,aliases:t,filepaths:[r],resolved:n});e.content[r]||(e.content[r]=g[r]||await G.promises.readFile(H.resolve(i,r),"utf8")),a.forEach(c=>e.files.push(c)),o.forEach(c=>e.dependencies.push(c))}return e.dependencies=[...new Set(e.dependencies)].sort(),e.files=[...new Set(e.files)].sort(),e};import A from"node:path";import re from"node:path";var f=({cwd:i,aliases:t,filepath:s})=>{var r;let n=s;for(let o in t)s=s.replace(t[o].replaceAll("./","").replaceAll("../",""),"");let e=s.startsWith("registry/")?s.replace(/^registry\//,"").replace(/^(?:([^\/]*)\/)?blocks\//,(o,a)=>`blocks/${a?a+"/":""}`).replace(/^(?:([^\/]*)\/)?components\/ui\//,(o,a)=>`${a?a+"/":""}ui/`).replace(/^(?:([^\/]*)\/)?components\//,(o,a)=>`components/${a?a+"/":""}`).replace(/^(?:([^\/]*)\/)?hooks\//,(o,a)=>`hooks/${a?a+"/":""}`).replace(/^(?:([^\/]*)\/)?lib\//,(o,a)=>`lib/${a?a+"/":""}`).replace(/^(?:([^\/]*)\/)?ui\//,(o,a)=>`components/ui/${a?a+"/":""}`).replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,""):s.replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,"");return{type:e.endsWith("page.tsx")?"registry:page":((r=e.match(/^(blocks|components\/ui|components|hooks|lib|utils|helpers)/))==null?void 0:r[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(i+re.sep,"").replace(/\.[^/.]+$/,"").replace(/\/index$/,""),target:n.split("/").length>1?e:`~/${e}`,path:s}};var ie=async({cwd:i,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 n=await v({cwd:i,patterns:t});return t=n.find(e=>e.startsWith(t+"."))||n.find(e=>e.startsWith(t+"/index"))||t,t.replace(i+"/","")},ne=async({cwd:i,filepath:t,current:s})=>{s=A.relative(i,A.resolve(i,A.dirname(t),s));let n=await v({cwd:i,patterns:s});return s=n.find(e=>e.startsWith(s+"."))||n.find(e=>e.startsWith(s+"/index"))||s,s.replace(i+"/","")},K=async({cwd:i,aliases:t,filepath:s,content:n})=>{let e={dependencies:[],files:[],transformations:{}},r=n.match(k.imports)||[];if(!r.length)return e;r=r.map(o=>{var a;return(a=o.match(/['"](.*)['"]/))==null?void 0:a[1].replace(/\/\//g,"/")});for(let o of r){let a=o;Object.keys(t).some(c=>o.startsWith(c.replace(/\.\//g,"").replace(/\.\.\//g,"")))?(o=await ie({cwd:i,aliases:t,current:o}),e.transformations[a]=f({cwd:i,aliases:t,filepath:o}),e.files.push(o)):o.startsWith(".")?(o=await ne({cwd:i,filepath:s,current:o}),e.transformations[a]=f({cwd:i,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 R="smart-registry",P="0.
|
|
2
|
+
var Q=Object.defineProperty,X=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var J=(i,t,s)=>t in i?Q(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s,u=(i,t)=>{for(var s in t||(t={}))Z.call(t,s)&&J(i,s,t[s]);if(I)for(var s of I(t))C.call(t,s)&&J(i,s,t[s]);return i},F=(i,t)=>X(i,Y(t));import _ from"node:fs";import h from"node:path";import{parseArgs as oe}from"node:util";var M=["registry/**",["blocks/**","components/**","helpers/**","hooks/**","lib/**","ui/**","utils/**"],["src/blocks/**","src/components/**","src/helpers/**","src/hooks/**","src/lib/**","src/ui/**","src/utils/**"]],j={default:["$schema","name","homepage","items"],items:{default:["$schema","name","type","description","title","author","dependencies","devDependencies","registryDependencies","files","tailwind","cssVars","meta","docs","categories"],type:{default:["registry:ui","registry:hook","registry:lib","registry:theme","registry:page","registry:file","registry:component","registry:block"]},files:{default:["type","target","content","path"],type:{default:["registry:block","registry:component","registry:file","registry:page","registry:theme","registry:lib","registry:hook","registry:ui"]}}}};import S from"node:fs";import E from"node:path";import ee from"strip-json-comments";var V=async i=>{let t={},s=["tsconfig.json","jsconfig.json"].find(n=>S.existsSync(E.resolve(i,n)));if(s){let n=await S.promises.readFile(E.resolve(i,s),"utf8"),{compilerOptions:e}=JSON.parse(ee(n,{trailingCommas:!0}));e.paths&&(t=Object.entries(e.paths).reduce((r,[o,[a]])=>(o.endsWith("*")&&a.endsWith("*")&&(r[o.replace(/\*$/,"")]=a.replace(/\*$/,"")),r),{}))}return t["@/"]||(t["@/"]=S.existsSync(E.resolve(i,"src"))?"./src/":"./"),t=Object.entries(t).sort(([n],[e])=>e.length-n.length).reduce((n,[e,r])=>(n[e]=r,n),{}),t};import B from"node:fs";import te from"node:path";var q=async i=>{let t=te.resolve(i,"registry.json"),s={$schema:"https://ui.shadcn.com/schema/registry.json",name:"nrjdalal",homepage:"https://nrjdalal.com",items:[]};return B.existsSync(t)&&(s=u({},JSON.parse(await B.promises.readFile(t,"utf8")))),s};import z from"node:fs";import T from"node:path";import{glob as se}from"tinyglobby";var v=async({cwd:i,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 n=await se(t,{cwd:i,ignore:s.filter(e=>!t.includes(e))});if(!n.length)for(let e of t)try{let r=T.resolve(i,e),o=await z.promises.stat(r);if(o.isDirectory()){let a=(await z.promises.readdir(r)).map(g=>T.resolve(e,g));n.push(...a)}else o.isFile()&&n.push(e)}catch(r){continue}return n};var U=async({cwd:i,patterns:t,ignore:s})=>{let n=[];if(t.length)n=await v({cwd:i,patterns:t,ignore:s});else for(let e of M)if(n=await v({cwd:i,patterns:e,ignore:s}),n.length)break;if(!n.length)throw new Error("No files/directories found to build the registry from!");return n};import G from"node:fs";import H from"node:path";var k={imports:/import\s+type\s+[\s\S]+?from\s+['"][^'"]+['"]|import\s+['"][^'"]+['"]|import\s+[\s\S]+?from\s+['"][^'"]+['"]/g};var W=async({cwd:i,aliases:t,filepaths:s,resolved:n})=>{n=n!=null?n:new Set;let e={dependencies:[],files:[],content:{}};for(let r of s){if(n.has(r))continue;n.add(r),e.files.push(r),e.content[r]||(e.content[r]=await G.promises.readFile(H.resolve(i,r),"utf8"));let{dependencies:o,files:a,transformations:g}=await K({cwd:i,aliases:t,filepath:r,content:e.content[r]});e.content[r]=e.content[r].replace(k.imports,c=>{let y=c.match(/['"](.*)['"]/);return y&&g[y[1]]?c.replace(y[1],g[y[1]].import):c}),a.forEach(c=>e.files.push(c)),o.forEach(c=>e.dependencies.push(c))}for(let r of e.files){let{dependencies:o,files:a,content:g}=await W({cwd:i,aliases:t,filepaths:[r],resolved:n});e.content[r]||(e.content[r]=g[r]||await G.promises.readFile(H.resolve(i,r),"utf8")),a.forEach(c=>e.files.push(c)),o.forEach(c=>e.dependencies.push(c))}return e.dependencies=[...new Set(e.dependencies)].sort(),e.files=[...new Set(e.files)].sort(),e};import A from"node:path";import re from"node:path";var f=({cwd:i,aliases:t,filepath:s})=>{var r;let n=s;for(let o in t)s=s.replace(t[o].replaceAll("./","").replaceAll("../",""),"");let e=s.startsWith("registry/")?s.replace(/^registry\//,"").replace(/^(?:([^\/]*)\/)?blocks\//,(o,a)=>`blocks/${a?a+"/":""}`).replace(/^(?:([^\/]*)\/)?components\/ui\//,(o,a)=>`${a?a+"/":""}ui/`).replace(/^(?:([^\/]*)\/)?components\//,(o,a)=>`components/${a?a+"/":""}`).replace(/^(?:([^\/]*)\/)?hooks\//,(o,a)=>`hooks/${a?a+"/":""}`).replace(/^(?:([^\/]*)\/)?lib\//,(o,a)=>`lib/${a?a+"/":""}`).replace(/^(?:([^\/]*)\/)?ui\//,(o,a)=>`components/ui/${a?a+"/":""}`).replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,""):s.replace(/\/default\//,"/").replace(/\.\.\//g,"").replace(/\.\//g,"");return{type:e.endsWith("page.tsx")?"registry:page":((r=e.match(/^(blocks|components\/ui|components|hooks|lib|utils|helpers)/))==null?void 0:r[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(i+re.sep,"").replace(/\.[^/.]+$/,"").replace(/\/index$/,""),target:n.split("/").length>1?e:`~/${e}`,path:s}};var ie=async({cwd:i,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 n=await v({cwd:i,patterns:t});return t=n.find(e=>e.startsWith(t+"."))||n.find(e=>e.startsWith(t+"/index"))||t,t.replace(i+"/","")},ne=async({cwd:i,filepath:t,current:s})=>{s=A.relative(i,A.resolve(i,A.dirname(t),s));let n=await v({cwd:i,patterns:s});return s=n.find(e=>e.startsWith(s+"."))||n.find(e=>e.startsWith(s+"/index"))||s,s.replace(i+"/","")},K=async({cwd:i,aliases:t,filepath:s,content:n})=>{let e={dependencies:[],files:[],transformations:{}},r=n.match(k.imports)||[];if(!r.length)return e;r=r.map(o=>{var a;return(a=o.match(/['"](.*)['"]/))==null?void 0:a[1].replace(/\/\//g,"/")});for(let o of r){let a=o;Object.keys(t).some(c=>o.startsWith(c.replace(/\.\//g,"").replace(/\.\.\//g,"")))?(o=await ie({cwd:i,aliases:t,current:o}),e.transformations[a]=f({cwd:i,aliases:t,filepath:o}),e.files.push(o)):o.startsWith(".")?(o=await ne({cwd:i,filepath:s,current:o}),e.transformations[a]=f({cwd:i,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 R="smart-registry",P="0.7.0";var O={name:"Neeraj Dalal",email:"admin@nrjdalal.com",url:"https://nrjdalal.com"};var L=`Version:
|
|
3
3
|
${R}@${P}
|
|
4
4
|
|
|
5
5
|
Usage:
|