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