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