smart-registry 0.7.0 → 0.7.2
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 +7 -3
- package/dist/bin/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,6 +101,8 @@ If your project contains a `registry`, `components`, or `src/components` directo
|
|
|
101
101
|
npx smart-registry
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
+

|
|
105
|
+
|
|
104
106
|
### Advanced Usage
|
|
105
107
|
|
|
106
108
|
You can customize the output directory, working directory, and provide files or directories to build the registry from.
|
|
@@ -125,12 +127,14 @@ Author:
|
|
|
125
127
|
${author.name} <${author.email}> (${author.url})
|
|
126
128
|
```
|
|
127
129
|
|
|
128
|
-
e.g. To generate the registry in the `
|
|
130
|
+
e.g. To generate the registry in the `json` directory from some file and directory at the working directory (`apps/www`).
|
|
129
131
|
|
|
130
132
|
```bash
|
|
131
|
-
npx smart-registry path/to/file.ext path/to/directory ... --output
|
|
133
|
+
npx smart-registry path/to/file.ext path/to/directory ... --output json --cwd apps/www
|
|
132
134
|
```
|
|
133
135
|
|
|
136
|
+
- cwd is useful when working with monorepos or multiple projects.
|
|
137
|
+
|
|
134
138
|
## How it Works
|
|
135
139
|
|
|
136
140
|
Let's take the following directory structure to understand how `Smart Registry` works.
|
|
@@ -161,7 +165,7 @@ public/
|
|
|
161
165
|
|
|
162
166
|
## Extending Properties
|
|
163
167
|
|
|
164
|
-
You can add/extend the generated `public/registry.json` and `public/r/<registry-item>.json` files by creating a `registry.json` file in the root of your project. The properties in this file will be merged with the generated properties.
|
|
168
|
+
You can add/extend the generated `public/r/registry.json` and `public/r/<registry-item>.json` files by creating a `registry.json` file in the root of your project. The properties in this file will be merged with the generated properties.
|
|
165
169
|
|
|
166
170
|
We will consider the dialog component with the following directory structure to demonstrate the extension of properties.
|
|
167
171
|
|
package/dist/bin/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var Q=Object.defineProperty,X=Object.defineProperties;var Y=Object.getOwnPropert
|
|
|
3
3
|
${R}@${P}
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
|
-
$ ${R} [
|
|
6
|
+
$ ${R} [files/directories] ... [options]
|
|
7
7
|
|
|
8
8
|
Arguments:
|
|
9
9
|
files/directories files or directories to build the registry from (optional)
|
|
@@ -15,7 +15,7 @@ Options:
|
|
|
15
15
|
-h, --help display help
|
|
16
16
|
|
|
17
17
|
Author:
|
|
18
|
-
${O.name} <${O.email}> (${O.url})`,ae=i=>{try{return oe(i)}catch(t){throw new Error(`Error parsing arguments: ${t.message}`)}},pe=async()=>{var i,t,s;try{let{positionals:n,values:e}=ae({allowPositionals:!0,options:{
|
|
18
|
+
${O.name} <${O.email}> (${O.url})`,ae=i=>{try{return oe(i)}catch(t){throw new Error(`Error parsing arguments: ${t.message}`)}},pe=async()=>{var i,t,s;try{let{positionals:n,values:e}=ae({allowPositionals:!0,options:{output:{type:"string",short:"o",default:"public/r"},cwd:{type:"string",short:"c"},ignore:{type:"string",short:"i",default:""},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});n.length||(e.version&&(console.log(`${R}@${P}`),process.exit(0)),e.help&&(console.log(L),process.exit(0)));let r=h.resolve((i=e.cwd)!=null?i:process.cwd()),o=await V(r),a=await q(r),g=await U({cwd:r,patterns:n,ignore:e.ignore}),c=[],y=F(u({},a),{items:[]});for(let m of g)try{let l=((t=a.items)==null?void 0:t.find(p=>p.name===f({cwd:r,aliases:o,filepath:m}).name))||{},d=await W({cwd:r,aliases:o,filepaths:[m,...((s=l==null?void 0:l.files)==null?void 0:s.map(p=>p.path))||[]]}),w={dependencies:[...new Set([...d.dependencies,...(l==null?void 0:l.dependencies)||[]])].sort(),devDependencies:[...new Set([...(l==null?void 0:l.devDependencies)||[]])].sort(),registryDependencies:[...new Set([...(l==null?void 0:l.registryDependencies)||[]])].sort()},b=u(F(u(u(u({$schema:"https://ui.shadcn.com/schema/registry-item.json",name:f({cwd:r,aliases:o,filepath:m}).name,type:f({cwd:r,aliases:o,filepath:m}).type||"registry:file"},w.dependencies.length&&{dependencies:w.dependencies}),w.devDependencies.length&&{devDependencies:w.devDependencies}),w.registryDependencies.length&&{registryDependencies:w.registryDependencies}),{files:d.files.map(p=>({type:f({cwd:r,aliases:o,filepath:p}).type||"registry:file",target:f({cwd:r,aliases:o,filepath:p}).target||p,content:d.content[p],path:p})).sort((p,x)=>{let $=j.items.files.type.default;return $.indexOf(p.type)-$.indexOf(x.type)})}),Object.fromEntries(Object.entries(l).filter(([p])=>!["$schema","name","type","dependencies","devDependencies","registryDependencies","files"].includes(p))));b=Object.keys(b).sort((p,x)=>{let $=j.items.default;return $.indexOf(p)-$.indexOf(x)}).reduce((p,x)=>(p[x]=b[x],p),{});let D=h.resolve(r,e.output,b.name+".json");console.log(`- ${h.relative(process.cwd(),h.resolve(r,m)).padEnd(Math.max(...g.map(p=>h.relative(process.cwd(),h.resolve(r,p)).length))+2," ")} ${d.dependencies.length?"\u{1F4E6}"+String(d.dependencies.length).padEnd(2," "):" "} ${d.files.length-1?"\u{1F4C4}"+String(d.files.length).padEnd(2," "):" "} ${h.relative(process.cwd(),D)}`),await _.promises.mkdir(h.dirname(D),{recursive:!0}),await _.promises.writeFile(D,JSON.stringify(b,null,2)+`
|
|
19
19
|
`),b.files.forEach(p=>delete p.content),y.items.push(b)}catch(l){c.push(m+": "+l.message);continue}y.items.sort((m,l)=>m.name.localeCompare(l.name)).sort((m,l)=>{let d=j.items.type.default;return d.indexOf(m.type)-d.indexOf(l.type)}),await _.promises.writeFile(h.resolve(r,e.output,"registry.json"),JSON.stringify(y,null,2)+`
|
|
20
20
|
`),c.length&&(console.log(),c.forEach(m=>console.error(`\x1B[31m- ${m}\x1B[0m`))),process.exit(0)}catch(n){console.error(L),console.error(`
|
|
21
21
|
${n.message}
|