regpick 0.9.0 → 0.9.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.
@@ -0,0 +1 @@
1
+ import{t as e}from"./index.mjs";import{n as t,t as n}from"./result-Dmv-uoQK.mjs";import{i as r,r as i}from"./config-BadTCZSR.mjs";import{n as a,t as o}from"./registry-DaJzKZm-.mjs";import s from"node:path";import*as c from"valibot";import l from"node:crypto";function u(e){return e.replace(/\\/g,`/`)}function d(r,i,a){let o=`${s.resolve(r)}${s.sep}`,c=s.resolve(i);return a?t(void 0):c!==s.resolve(r)&&!c.startsWith(o)?n(e(`ValidationError`,`Refusing to write outside project: ${c}`)):t(void 0)}function f(e,n,r,i){let a=n.type||e.type||`registry:file`,o=i.targetsByType?.[a],c=i.preferManifestTarget!==!1,l=s.basename(n.path||`${e.name}.txt`),f;f=c&&n.target?n.target:o?s.join(o,l):n.target?n.target:s.join(`src`,l);let p=s.resolve(r,f),m=d(r,p,!!i.allowOutsideProject);return m.ok?t({absoluteTarget:p,relativeTarget:u(s.relative(r,p))}):m}function p(e){return[...new Set(e.filter(Boolean))]}function m(e){return{dependencies:p(e.flatMap(e=>e.dependencies||[])),devDependencies:p(e.flatMap(e=>e.devDependencies||[]))}}function h(e,t){let n=new Map,r=[...e],i=[];for(;r.length>0;){let e=r.shift();if(!n.has(e.name)&&(n.set(e.name,e),e.registryDependencies&&e.registryDependencies.length>0))for(let a of e.registryDependencies){if(n.has(a))continue;let e=t.find(e=>e.name===a);e?r.push(e):i.push(a)}}return{resolvedItems:Array.from(n.values()),missingDependencies:p(i)}}function g(e,n,r,i=new Set){let a=[],o=[];for(let t of e)for(let e of t.files){let s=f(t,e,n,r);if(!s.ok)return s;let{absoluteTarget:c,relativeTarget:l}=s.value,u={itemName:t.name,sourceFile:e,absoluteTarget:c,relativeTarget:l};a.push(u),i.has(c)&&o.push(u)}return t({selectedItems:e,plannedWrites:a,dependencyPlan:m(e),conflicts:o})}function _(e,t){let n=e;for(let[e,r]of Object.entries(t.aliases||{})){let t=RegExp(`from ["']${e}(.*?)["']`,`g`);n=n.replace(t,`from "${r}$1"`);let i=RegExp(`import\\(["']${e}(.*?)["']\\)`,`g`);n=n.replace(i,`import("${r}$1")`)}return n}function v(e){return e?String(e).split(`,`).map(e=>e.trim()).filter(Boolean):[]}function y(r,i){let{flags:a}=i.args,o=v(a.select);if(a.all)return t(r);if(o.length){let i=r.filter(e=>o.includes(e.name));return i.length?t(i):n(e(`ValidationError`,`No items matched --select=${String(a.select)}`))}return t(null)}function b(e,t){let n=[];return e.length&&n.push({command:`npm`,args:[`install`,...e]}),t.length&&n.push({command:`npm`,args:[`install`,`-D`,...t]}),n}function x(e,t){let n=[];return e.length&&n.push({command:`yarn`,args:[`add`,...e]}),t.length&&n.push({command:`yarn`,args:[`add`,`-D`,...t]}),n}function S(e,t){let n=[];return e.length&&n.push({command:`pnpm`,args:[`add`,...e]}),t.length&&n.push({command:`pnpm`,args:[`add`,`-D`,...t]}),n}const C={npm:{manager:`npm`,buildInstallCommands:b},yarn:{manager:`yarn`,buildInstallCommands:x},pnpm:{manager:`pnpm`,buildInstallCommands:S}};function w(e){return C[e]}const T=c.object({dependencies:c.optional(c.record(c.string(),c.string()),{}),devDependencies:c.optional(c.record(c.string(),c.string()),{}),peerDependencies:c.optional(c.record(c.string(),c.string()),{})});function E(e){return[...new Set(e.filter(Boolean))]}function D(e,t,n){let r=s.join(t,`package.json`);if(!n.fs.existsSync(r))return{missingDependencies:[],missingDevDependencies:[]};let i=n.fs.readJsonSync(r),a=i.ok?i.value:{},o=c.safeParse(T,a),l=o.success?o.output:{dependencies:{},devDependencies:{},peerDependencies:{}},u={...l.dependencies,...l.devDependencies,...l.peerDependencies},d=E(e.flatMap(e=>e.dependencies||[])),f=E(e.flatMap(e=>e.devDependencies||[]));return{missingDependencies:d.filter(e=>!u[e]),missingDevDependencies:f.filter(e=>!u[e])}}function O(r,i,a,o,s){if(!a.length&&!o.length)return t(void 0);let c=w(i).buildInstallCommands(a,o);for(let t of c)if(s.process.run(t.command,t.args,r).status!==0)return n(e(`InstallError`,`Dependency install failed: ${t.command} ${t.args.join(` `)}`));return t(void 0)}const k=c.object({version:c.optional(c.string()),source:c.optional(c.string()),hash:c.string()}),A=c.object({components:c.record(c.string(),k)});function j(e){return s.join(e,`regpick-lock.json`)}async function M(e,t){let n=j(e);if(!await t.fs.pathExists(n))return{components:{}};let r=t.fs.readJsonSync(n);if(!r.ok)return{components:{}};try{return c.parse(A,r.value)}catch{return{components:{}}}}async function N(e,t,n){let r=j(e);await n.fs.writeJson(r,t,{spaces:2})}function P(e){return l.createHash(`sha256`).update(e).digest(`hex`)}function F(e,t,n){return t&&t!==`auto`?t:n.fs.existsSync(s.join(e,`pnpm-lock.yaml`))?`pnpm`:n.fs.existsSync(s.join(e,`yarn.lock`))?`yarn`:(n.fs.existsSync(s.join(e,`package-lock.json`)),`npm`)}async function I(i,a,o){let s=o[1];if(s)return t(r(s,a));let c=Object.entries(a.registries||{}).map(([e,t])=>({label:`${e} -> ${t}`,value:e}));if(c.length){let o=await i.runtime.prompt.multiselect({message:`Pick registry alias (or cancel and provide URL/path manually)`,options:c,maxItems:1,required:!1});if(await i.runtime.prompt.isCancel(o))return n(e(`UserCancelled`,`Operation cancelled.`));if(Array.isArray(o)&&o.length>0)return t(r(String(o[0]),a))}let l=await i.runtime.prompt.text({message:`Registry URL/path:`,placeholder:`https://example.com/registry.json`});return await i.runtime.prompt.isCancel(l)?n(e(`UserCancelled`,`Operation cancelled.`)):t(String(l))}function L(e){return e.map(e=>({value:e.name,label:`${e.name} (${e.type||`registry:file`})`,hint:e.description||`${e.files.length} file(s)`}))}async function R(r,i){if(!i.length)return t([]);let a=await r.runtime.prompt.autocompleteMultiselect({message:`Select items to install`,options:L(i),maxItems:10,required:!0});if(await r.runtime.prompt.isCancel(a))return n(e(`UserCancelled`,`Operation cancelled.`));let o=Array.isArray(a)?a:[],s=new Set(o.map(e=>String(e)));return t(i.filter(e=>s.has(e.name)))}async function z(r){let c=!!r.args.flags.yes,{config:l,configPath:u}=await i(r.cwd);if(!u)return r.runtime.prompt.error(`No regpick.json configuration found. Please run 'init' first.`),n(e(`ValidationError`,`No config file found`));let d=(r.args.positionals[0]===`add`?1:0)+1,f=await I(r,l,r.args.positionals);if(!f.ok)return f;let p=f.value;if(!p)return t({kind:`noop`,message:`No registry source provided.`});let m=await o(p,r.cwd,r.runtime);if(!m.ok)return m;let{items:v}=m.value;if(!v.length)return r.runtime.prompt.warn(`No installable items in registry.`),t({kind:`noop`,message:`No installable items in registry.`});let b=r.args.positionals[d];b&&!r.args.flags.select&&(r.args.flags.select=b);let x=y(v,r),S;if(x.ok&&x.value)S=x.value;else if(x.ok){let e=await R(r,v);if(!e.ok)return e;S=e.value}else return x;let{resolvedItems:C,missingDependencies:w}=h(S,v);S=C;for(let e of w)r.runtime.prompt.warn(`Registry dependency "${e}" not found in current registry.`);if(!S||!S.length)return r.runtime.prompt.warn(`No items selected.`),t({kind:`noop`,message:`No items selected.`});if(!c){let t=await r.runtime.prompt.confirm({message:`Install ${S.length} item(s)?`,initialValue:!0});if(await r.runtime.prompt.isCancel(t)||!t)return n(e(`UserCancelled`,`Operation cancelled.`))}let T=new Set,E=g(S,r.cwd,l);if(!E.ok)return E;let k=E.value;for(let e of k.plannedWrites)await r.runtime.fs.pathExists(e.absoluteTarget)&&T.add(e.absoluteTarget);let A=g(S,r.cwd,l,T);if(!A.ok)return A;let j=A.value,L=[];for(let t of j.plannedWrites)if(T.has(t.absoluteTarget))if(c||l.overwritePolicy===`overwrite`)L.push(t);else if(l.overwritePolicy===`skip`)r.runtime.prompt.warn(`Skipped existing file: ${t.absoluteTarget}`);else{let i=await r.runtime.prompt.select({message:`File exists: ${t.absoluteTarget}`,options:[{value:`overwrite`,label:`Overwrite this file`},{value:`skip`,label:`Skip this file`},{value:`abort`,label:`Abort installation`}]});if(await r.runtime.prompt.isCancel(i)||i===`abort`)return n(e(`UserCancelled`,`Installation aborted by user.`));i===`overwrite`&&L.push(t)}else L.push(t);let{missingDependencies:z,missingDevDependencies:B}=D(S,r.cwd,r.runtime),V=!1;if(z.length||B.length)if(c)V=!0;else{let t=F(r.cwd,l.packageManager,r.runtime),i=[];z.length&&i.push(`dependencies: ${z.join(`, `)}`),B.length&&i.push(`devDependencies: ${B.join(`, `)}`);let a=await r.runtime.prompt.confirm({message:`Install missing packages with ${t}? (${i.join(` | `)})`,initialValue:!0});if(await r.runtime.prompt.isCancel(a))return n(e(`UserCancelled`,`Dependency installation cancelled by user.`));V=!!a,V||r.runtime.prompt.warn(`Skipped dependency installation.`)}let H=0,U=await M(r.cwd,r.runtime),W={};for(let e of L){let t=S.find(t=>t.name===e.itemName);if(!t)continue;let n=await a(e.sourceFile,t,r.cwd,r.runtime);if(!n.ok)return n;let i=_(n.value,l),o=await r.runtime.fs.ensureDir(s.dirname(e.absoluteTarget));if(!o.ok)return o;let c=await r.runtime.fs.writeFile(e.absoluteTarget,i,`utf8`);if(!c.ok)return c;let u=P(i);W[t.name]||(W[t.name]=[]),W[t.name].push(u),H+=1,r.runtime.prompt.success(`Wrote ${e.relativeTarget}`)}if(H>0){for(let[e,t]of Object.entries(W)){let n=P(t.sort().join(``));U.components[e]={source:p,hash:n}}await N(r.cwd,U,r.runtime)}if(V){let e=F(r.cwd,l.packageManager,r.runtime),t=O(r.cwd,e,z,B,r.runtime);if(!t.ok)return t}return r.runtime.prompt.info(`Installed ${S.length} item(s), wrote ${H} file(s).`),t({kind:`success`,message:`Installed ${S.length} item(s), wrote ${H} file(s).`})}export{f as a,_ as i,M as n,N as r,z as runAddCommand,P as t};
@@ -1 +1 @@
1
- import e from"node:path";import t from"node:fs/promises";import{loadConfig as n}from"unconfig";import*as r from"valibot";const i=r.union([r.literal(`prompt`),r.literal(`overwrite`),r.literal(`skip`)]),a=r.union([r.literal(`auto`),r.literal(`npm`),r.literal(`yarn`),r.literal(`pnpm`)]),o=r.object({registries:r.record(r.string(),r.string()),targetsByType:r.record(r.string(),r.string()),aliases:r.optional(r.record(r.string(),r.string()),{}),overwritePolicy:i,packageManager:a,preferManifestTarget:r.boolean(),allowOutsideProject:r.boolean()}),s={registries:{tebra:`./tebra-icon-registry/registry`},targetsByType:{"registry:icon":`src/components/ui/icons`,"registry:component":`src/components/ui`,"registry:file":`src/components/ui`},aliases:{},overwritePolicy:`prompt`,packageManager:`auto`,preferManifestTarget:!0,allowOutsideProject:!1};function c(t){return e.join(t,`regpick.json`)}async function l(e){let{config:t,sources:i}=await n({sources:[{files:[`regpick`,`.regpickrc`,`regpickrc`],extensions:[`json`,`js`,`ts`,`mjs`,`cjs`,``]},{files:`package.json`,extensions:[],rewrite(e){return e?.regpick}}],defaults:s,merge:!0,cwd:e});return{config:r.parse(o,t),configPath:i[0]||null}}async function u(e,n,{overwrite:r=!1}={}){let i=c(e),a=!1;try{await t.access(i),a=!0}catch{}return a&&!r?{filePath:i,written:!1}:(await t.writeFile(i,JSON.stringify(n,null,2),`utf8`),{filePath:i,written:!0})}function d(e,t){return e?t.registries[e]?String(t.registries[e]):e:null}export{u as i,l as n,d as r,c as t};
1
+ import e from"node:path";import t from"node:fs/promises";import{loadConfig as n}from"unconfig";import*as r from"valibot";const i=r.union([r.literal(`prompt`),r.literal(`overwrite`),r.literal(`skip`)]),a=r.union([r.literal(`auto`),r.literal(`npm`),r.literal(`yarn`),r.literal(`pnpm`)]),o=r.object({registries:r.record(r.string(),r.string()),targetsByType:r.record(r.string(),r.string()),aliases:r.optional(r.record(r.string(),r.string()),{}),overwritePolicy:i,packageManager:a,preferManifestTarget:r.boolean(),allowOutsideProject:r.boolean()}),s={registries:{tebra:`./tebra-icon-registry/registry`},targetsByType:{"registry:icon":`src/components/ui/icons`,"registry:component":`src/components/ui`,"registry:file":`src/components/ui`},aliases:{},overwritePolicy:`prompt`,packageManager:`auto`,preferManifestTarget:!0,allowOutsideProject:!1};function c(t){return e.join(t,`regpick.json`)}async function l(e){let{config:t,sources:i}=await n({sources:[{files:[`regpick`,`.regpickrc`,`regpickrc`],extensions:[`json`,`js`,`ts`,`mjs`,`cjs`,``]},{files:`package.json`,extensions:[],rewrite(e){return e?.regpick}}],defaults:s,merge:!0,cwd:e});return{config:r.parse(o,t),configPath:i[0]||null}}async function u(e,n,{overwrite:r=!1}={}){let i=c(e),a=!1;try{await t.access(i),a=!0}catch{}return a&&!r?{filePath:i,written:!1}:(await t.writeFile(i,JSON.stringify(n,null,2),`utf8`),{filePath:i,written:!0})}function d(e,t){return e?t.registries[e]?String(t.registries[e]):e:null}export{u as a,d as i,c as n,l as r,o as t};
package/dist/index.mjs CHANGED
@@ -12,4 +12,4 @@ Options:
12
12
  --select=a,b,c Select explicit item names in add flow
13
13
  --yes Skip confirmation prompts where safe
14
14
  --help Show this help
15
- `)}async function s(){let n=new AbortController,i=e=>{n.signal.aborted||n.abort(e),e instanceof Error&&console.error(t(`red`,`\n[Fatal Error] ${e.message}`)),process.exit(1)};process.on(`SIGINT`,()=>i()),process.on(`SIGTERM`,()=>i()),process.on(`uncaughtException`,i),process.on(`unhandledRejection`,e=>i(e instanceof Error?e:Error(String(e))));let s=a(process.argv.slice(2)),l=s.positionals[0];if(!l||s.flags.help){o();return}let{createRuntimePorts:u}=await import(`./ports-Cr6fDIR9.mjs`),d=u({signal:n.signal});if(!l||s.flags.help){o();return}let f={cwd:s.flags.cwd?e.resolve(process.cwd(),String(s.flags.cwd)):process.cwd(),args:s,runtime:d};d.prompt.intro(t(`cyan`,`regpick`));try{let e;if(l===`init`)e=await import(`./init-v_ycOf8A.mjs`).then(e=>e.runInitCommand(f));else if(l===`list`)e=await import(`./list-fuT3LlGZ.mjs`).then(e=>e.runListCommand(f));else if(l===`add`)e=await import(`./add-DTgZRyi9.mjs`).then(e=>e.runAddCommand(f));else if(l===`update`)e=await import(`./update-Bvs7BJaD.mjs`).then(e=>e.runUpdateCommand(f));else if(l===`pack`)e=await import(`./pack-C5oJjxLv.mjs`).then(e=>e.runPackCommand(f));else{d.prompt.error(`Unknown command: ${l}`),o(),process.exitCode=1;return}if(!e.ok){c(e.error,d.prompt.error),d.prompt.outro(t(`red`,`Failed.`)),process.exitCode=1;return}if(e.value.kind===`noop`){d.prompt.outro(t(`yellow`,e.value.message));return}d.prompt.outro(t(`green`,`Done.`))}catch(e){c(r(e),d.prompt.error),d.prompt.outro(t(`red`,`Failed.`)),process.exitCode=1}}function c(e,t){if(e.kind===`UserCancelled`){t(e.message);return}t(`[${e.kind}] ${e.message}`)}s();export{n as t};
15
+ `)}async function s(){let n=new AbortController,i=e=>{n.signal.aborted||n.abort(e),e instanceof Error&&console.error(t(`red`,`\n[Fatal Error] ${e.message}`)),process.exit(1)};process.on(`SIGINT`,()=>i()),process.on(`SIGTERM`,()=>i()),process.on(`uncaughtException`,i),process.on(`unhandledRejection`,e=>i(e instanceof Error?e:Error(String(e))));let s=a(process.argv.slice(2)),l=s.positionals[0];if(!l||s.flags.help){o();return}let{createRuntimePorts:u}=await import(`./ports-Cr6fDIR9.mjs`),d=u({signal:n.signal});if(!l||s.flags.help){o();return}let f={cwd:s.flags.cwd?e.resolve(process.cwd(),String(s.flags.cwd)):process.cwd(),args:s,runtime:d};d.prompt.intro(t(`cyan`,`regpick`));try{let e;if(l===`init`)e=await import(`./init-BRDg97Sb.mjs`).then(e=>e.runInitCommand(f));else if(l===`list`)e=await import(`./list-1P-o5ol8.mjs`).then(e=>e.runListCommand(f));else if(l===`add`)e=await import(`./add-BBUGaxdg.mjs`).then(e=>e.runAddCommand(f));else if(l===`update`)e=await import(`./update-Dd7qRfMw.mjs`).then(e=>e.runUpdateCommand(f));else if(l===`pack`)e=await import(`./pack-C5oJjxLv.mjs`).then(e=>e.runPackCommand(f));else{d.prompt.error(`Unknown command: ${l}`),o(),process.exitCode=1;return}if(!e.ok){c(e.error,d.prompt.error),d.prompt.outro(t(`red`,`Failed.`)),process.exitCode=1;return}if(e.value.kind===`noop`){d.prompt.outro(t(`yellow`,e.value.message));return}d.prompt.outro(t(`green`,`Done.`))}catch(e){c(r(e),d.prompt.error),d.prompt.outro(t(`red`,`Failed.`)),process.exitCode=1}}function c(e,t){if(e.kind===`UserCancelled`){t(e.message);return}t(`[${e.kind}] ${e.message}`)}s();export{n as t};
@@ -0,0 +1 @@
1
+ import{t as e}from"./index.mjs";import{n as t,t as n}from"./result-Dmv-uoQK.mjs";import{a as r,n as i,r as a,t as o}from"./config-BadTCZSR.mjs";import*as s from"valibot";function c(e,t){return e?`cancelled`:t?`overwrite`:`keep`}async function l(l){let u=i(l.cwd),d=await l.runtime.fs.stat(u);if(d.ok){let r=await l.runtime.prompt.confirm({message:`${u} already exists. Overwrite?`,initialValue:!1}),i=c(await l.runtime.prompt.isCancel(r),!!r);if(i===`cancelled`)return n(e(`UserCancelled`,`Operation cancelled.`));if(i===`keep`)return l.runtime.prompt.info(`Keeping existing configuration.`),t({kind:`noop`,message:`Keeping existing configuration.`})}let{config:f}=await a(l.cwd),p=!!l.args.flags.yes,m=p?`auto`:await l.runtime.prompt.select({message:`Jakiego menedżera pakietów używasz?`,options:[{value:`auto`,label:`Auto (wykrywanie)`},{value:`npm`,label:`npm`},{value:`yarn`,label:`yarn`},{value:`pnpm`,label:`pnpm`}]}),h=await l.runtime.prompt.isCancel(m);if(!p&&h)return n(e(`UserCancelled`,`Operation cancelled.`));let g=p?`src/components/ui`:await l.runtime.prompt.text({message:`W jakim folderze trzymasz komponenty UI?`,placeholder:`src/components/ui`}),_=await l.runtime.prompt.isCancel(g);if(!p&&_)return n(e(`UserCancelled`,`Operation cancelled.`));let v=p?`prompt`:await l.runtime.prompt.select({message:`Czy chcesz nadpisywać pliki automatycznie, czy wolisz być pytany?`,options:[{value:`prompt`,label:`Pytaj (prompt)`},{value:`overwrite`,label:`Zawsze nadpisuj (overwrite)`},{value:`skip`,label:`Pomijaj nadpisywanie (skip)`}]}),y=await l.runtime.prompt.isCancel(v);if(!p&&y)return n(e(`UserCancelled`,`Operation cancelled.`));let b={...f,packageManager:String(m),overwritePolicy:String(v),targetsByType:{...f.targetsByType,"registry:component":String(g||`src/components/ui`),"registry:file":String(g||`src/components/ui`),"registry:icon":`${String(g||`src/components/ui`)}/icons`}},x=s.parse(o,b);try{await r(l.cwd,x,{overwrite:!0})}catch(t){let r=`Failed to write config file: ${t instanceof Error?t.message:String(t)}`;return l.runtime.prompt.error(r),n(e(`RuntimeError`,r))}return l.runtime.prompt.success(`${d.ok?`Overwrote`:`Created`} ${u}`),t({kind:`success`,message:`${d.ok?`Overwrote`:`Created`} ${u}`})}export{l as runInitCommand};
@@ -0,0 +1 @@
1
+ import{t as e}from"./index.mjs";import{n as t,t as n}from"./result-Dmv-uoQK.mjs";import{r}from"./config-BadTCZSR.mjs";import{t as i}from"./registry-DaJzKZm-.mjs";function a(e,t){return e?t[e]?String(t[e]):e:null}function o(e,t){let n=a(e,t);if(n)return{source:n,requiresPrompt:!1};let r=Object.keys(t)[0];return r?{source:a(r,t),requiresPrompt:!1}:{source:null,requiresPrompt:!0}}function s(e){let t=e.type||`registry:file`,n=Array.isArray(e.files)?e.files.length:0;return`${e.name} (${t}, files: ${n})`}async function c(a){let{config:c}=await r(a.cwd),l=o(a.args.positionals[1],c.registries),u=l.source;if(l.requiresPrompt){let t=await a.runtime.prompt.text({message:`Registry URL/path:`,placeholder:`https://example.com/registry.json`});if(await a.runtime.prompt.isCancel(t))return n(e(`UserCancelled`,`Operation cancelled.`));u=String(t)}if(!u)return t({kind:`noop`,message:`No registry source provided.`});let d=await i(u,a.cwd,a.runtime);if(!d.ok)return d;let{items:f}=d.value;if(!f.length)return a.runtime.prompt.warn(`No items found in registry.`),t({kind:`noop`,message:`No items found in registry.`});a.runtime.prompt.info(`Found ${f.length} items.`);for(let e of f)console.log(`- ${s(e)}`);return t({kind:`success`,message:`Listed ${f.length} item(s).`})}export{c as runListCommand};
@@ -0,0 +1 @@
1
+ import{t as e}from"./index.mjs";import{n as t,t as n}from"./result-Dmv-uoQK.mjs";import r from"node:path";import*as i from"valibot";import{fileURLToPath as a}from"node:url";const o=i.object({path:i.optional(i.string()),target:i.optional(i.string()),type:i.optional(i.string(),`registry:file`),content:i.optional(i.string()),url:i.optional(i.string())}),s=i.object({name:i.optional(i.string(),`unnamed-item`),title:i.optional(i.string()),description:i.optional(i.string(),``),type:i.optional(i.string(),`registry:file`),dependencies:i.optional(i.array(i.string()),[]),devDependencies:i.optional(i.array(i.string()),[]),registryDependencies:i.optional(i.array(i.string()),[]),files:i.optional(i.array(o),[])});i.object({type:i.union([i.literal(`http`),i.literal(`file`),i.literal(`directory`)]),baseUrl:i.optional(i.string()),baseDir:i.optional(i.string())});function c(e,t){let n=i.parse(s,e),r=n.name===`unnamed-item`&&n.title?n.title:n.name,a=n.title??r,o=n.files.map(e=>({...e,type:e.type===`registry:file`&&n.type!==`registry:file`?n.type:e.type}));return{...n,name:r,title:a,files:o,sourceMeta:t}}const l=i.object({url:i.optional(i.string()),href:i.optional(i.string()),path:i.optional(i.string()),files:i.optional(i.unknown())}),u=i.object({items:i.array(i.union([i.record(i.string(),i.unknown()),l]))});function d(e){let t=i.safeParse(u,e);return t.success?t.output.items.map(e=>{let t=e;return`files`in t&&Array.isArray(t.files)?null:typeof t.url==`string`?t.url:typeof t.href==`string`?t.href:typeof t.path==`string`?t.path:null}).filter(e=>!!e):[]}const f=i.object({files:i.array(i.unknown())});function p(r,a){try{if(Array.isArray(r))return t(r.filter(e=>!!(e&&typeof e==`object`)).map(e=>c(e,a)));let o=i.safeParse(u,r);return o.success?t(o.output.items.filter(e=>`files`in e&&Array.isArray(e.files)).map(e=>c(e,a))):i.safeParse(f,r).success?t([c(r,a)]):n(e(`RegistryError`,`Unsupported manifest structure.`))}catch(t){return i.isValiError(t)?n(e(`ValidationError`,`Manifest validation failed: ${t.message}`)):n(e(`RegistryError`,`Failed to parse manifest`))}}function m(e){return/^https?:\/\//i.test(e)}function h(e){return e.includes(`github.com`)?e.replace(/^https?:\/\/github\.com\//,`https://raw.githubusercontent.com/`).replace(/\/(blob|tree)\//,`/`):e}function g(e){return/^file:\/\//i.test(e)}function _(e,t){return new URL(t,e).toString()}async function v(i,a,o){let s=p(i,a);if(!i||typeof i!=`object`||Array.isArray(i))return s;let l=d(i);if(!l.length)return s;let u=s.ok?s.value:[],f=[];for(let t of l){let i;if(m(t)){let e=await o.http.getJson(t);if(!e.ok)return n(e.error);i=e.value}else if(a.type===`http`&&a.baseUrl){let e=await o.http.getJson(_(a.baseUrl,t));if(!e.ok)return n(e.error);i=e.value}else if((a.type===`file`||a.type===`directory`)&&a.baseDir){let s=await o.fs.readFile(r.resolve(a.baseDir,t),`utf8`);if(!s.ok)return n(s.error);try{i=JSON.parse(s.value)}catch{return n(e(`RegistryError`,`Invalid JSON: ${t}`))}}else{let a=await o.fs.readFile(r.resolve(t),`utf8`);if(!a.ok)return n(a.error);try{i=JSON.parse(a.value)}catch{return n(e(`RegistryError`,`Invalid JSON: ${t}`))}}i&&typeof i==`object`&&f.push(c(i,a))}return t([...u,...f])}async function y(e,i){let a=r.resolve(e),o=await i.fs.readdir(a);if(!o.ok)return n(o.error);let s=o.value.filter(e=>e.endsWith(`.json`)),l=[];for(let e of s){let t=r.join(a,e),o=await i.fs.readFile(t,`utf8`);if(!o.ok)return n(o.error);let s;try{s=JSON.parse(o.value)}catch{continue}!s||typeof s!=`object`||!(`files`in s)||!Array.isArray(s.files)||l.push(c(s,{type:`directory`,baseDir:a}))}return t(l)}async function b(i,o,s){if(!i)return n(e(`ValidationError`,`Registry source is required.`));let c=m(i)||g(i)?h(i):r.resolve(o,i);if(m(c)){let e=await s.http.getJson(c);if(!e.ok)return n(e.error);let r=c.endsWith(`/`)?c:c.replace(/[^/]*$/,``),i=await v(e.value,{type:`http`,baseUrl:r},s);return i.ok?t({items:i.value,source:c}):n(i.error)}let l=g(c)?a(new URL(c)):r.resolve(c),u=await s.fs.stat(l);if(!u.ok)return n(e(`RegistryError`,`Registry source not found: ${i}`));if(u.value.isDirectory()){let e=await y(l,s);return e.ok?t({items:e.value,source:l}):n(e.error)}let d=await s.fs.readFile(l,`utf8`);if(!d.ok)return n(d.error);let f;try{f=JSON.parse(d.value)}catch(t){return n(e(`RegistryError`,`Failed to parse registry JSON.`,t))}let p=await v(f,{type:`file`,baseDir:r.dirname(l)},s);return p.ok?t({items:p.value,source:l}):n(p.error)}async function x(i,a,o,s){if(typeof i.content==`string`)return t(i.content);let c=i.url||i.path;if(!c)return n(e(`ValidationError`,`File entry in "${a.name}" is missing both content and path/url.`));let l=m(c)?h(c):c;if(m(l))return await s.http.getText(l);if(a.sourceMeta.type===`http`&&a.sourceMeta.baseUrl){let e=_(a.sourceMeta.baseUrl,l);return await s.http.getText(e)}let u=a.sourceMeta.baseDir&&!r.isAbsolute(c)?r.resolve(a.sourceMeta.baseDir,c):r.resolve(o,c);return await s.fs.readFile(u,`utf8`)}export{x as n,b as t};
@@ -1,2 +1,2 @@
1
- import{n as e}from"./result-Dmv-uoQK.mjs";import{n as t}from"./config-DBCWbzyr.mjs";import{n,t as r}from"./registry-Ccy74Ba7.mjs";import{a as i,i as a,n as o,r as s,t as c}from"./add-DTgZRyi9.mjs";import l from"node:path";import{styleText as u}from"node:util";function d(e){let t={};for(let n of Object.keys(e.components)){let r=e.components[n].source;r&&(t[r]||(t[r]=[]),t[r].push(n))}return t}function f(t,n,r,o,s,l){let u=[],d=[];for(let{file:e,content:t}of r){let r=a(t,l);u.push(r);let o=i(n,e,s,l);if(!o.ok)return o;d.push({target:o.value.absoluteTarget,content:r})}let f=c(u.sort().join(``));return e({itemName:t,status:f===o?`up-to-date`:`requires-diff-prompt`,newHash:f,files:d})}async function p(e,t){let n=await import(`diff`).then(({diffLines:n})=>n(e,t));for(let e of n){let t=e.added?`green`:e.removed?`red`:`gray`,n=e.added?`+ `:e.removed?`- `:` `,r=e.value.replace(/\n$/,``).split(`
1
+ import{n as e}from"./result-Dmv-uoQK.mjs";import{r as t}from"./config-BadTCZSR.mjs";import{n,t as r}from"./registry-DaJzKZm-.mjs";import{a as i,i as a,n as o,r as s,t as c}from"./add-BBUGaxdg.mjs";import l from"node:path";import{styleText as u}from"node:util";function d(e){let t={};for(let n of Object.keys(e.components)){let r=e.components[n].source;r&&(t[r]||(t[r]=[]),t[r].push(n))}return t}function f(t,n,r,o,s,l){let u=[],d=[];for(let{file:e,content:t}of r){let r=a(t,l);u.push(r);let o=i(n,e,s,l);if(!o.ok)return o;d.push({target:o.value.absoluteTarget,content:r})}let f=c(u.sort().join(``));return e({itemName:t,status:f===o?`up-to-date`:`requires-diff-prompt`,newHash:f,files:d})}async function p(e,t){let n=await import(`diff`).then(({diffLines:n})=>n(e,t));for(let e of n){let t=e.added?`green`:e.removed?`red`:`gray`,n=e.added?`+ `:e.removed?`- `:` `,r=e.value.replace(/\n$/,``).split(`
2
2
  `);for(let e of r)console.log(u(t,`${n}${e}`))}}async function m(i){let a=await o(i.cwd,i.runtime);if(Object.keys(a.components).length===0)return i.runtime.prompt.info(`No components installed. Nothing to update.`),e({kind:`noop`,message:`No components to update.`});let{config:c}=await t(i.cwd),m=d(a),h=0;for(let[e,t]of Object.entries(m)){let o=await r(e,i.cwd,i.runtime);if(!o.ok){i.runtime.prompt.warn(`Failed to load registry ${e}`);continue}let s=o.value.items;for(let e of t){let t=s.find(t=>t.name===e);if(!t)continue;let r=[];for(let e of t.files){let a=await n(e,t,i.cwd,i.runtime);a.ok&&r.push({file:e,content:a.value})}let o=a.components[e].hash,d=f(e,t,r,o,i.cwd,c);if(!d.ok)continue;let m=d.value;if(m.status===`requires-diff-prompt`){i.runtime.prompt.info(`Update available for ${e}`);let t=await i.runtime.prompt.select({message:`What do you want to do with ${e}?`,options:[{value:`diff`,label:`Show diff`},{value:`update`,label:`Update`},{value:`skip`,label:`Skip`}]});if(await i.runtime.prompt.isCancel(t)||t===`skip`)continue;if(t===`diff`){for(let e of m.files){let t=await i.runtime.fs.readFile(e.target,`utf8`),n=t.ok?t.value:``;console.log(u(`bold`,`\nDiff for ${e.target}:`)),await p(n,e.content)}let t=await i.runtime.prompt.confirm({message:`Update ${e} now?`,initialValue:!0});if(await i.runtime.prompt.isCancel(t)||!t)continue}for(let e of m.files){let t=await i.runtime.fs.ensureDir(l.dirname(e.target));if(!t.ok)return t;let n=await i.runtime.fs.writeFile(e.target,e.content,`utf8`);if(!n.ok)return n}a.components[e].hash=m.newHash,h++,i.runtime.prompt.success(`Updated ${e}`)}}}return h>0?(await s(i.cwd,a,i.runtime),e({kind:`success`,message:`Updated ${h} components.`})):e({kind:`noop`,message:`All components are up to date.`})}export{m as runUpdateCommand};
package/package.json CHANGED
@@ -1,45 +1,46 @@
1
1
  {
2
2
  "name": "regpick",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Lightweight CLI for selecting and installing registry entries.",
5
- "type": "module",
6
- "main": "./dist/index.mjs",
7
- "exports": {
8
- ".": "./dist/index.mjs"
9
- },
10
- "files": [
11
- "dist",
12
- "bin",
13
- "regpick.config.schema.json"
14
- ],
15
5
  "keywords": [
16
6
  "cli",
17
- "component-registry",
18
7
  "component-library",
19
- "developer-tool",
8
+ "component-registry",
9
+ "components",
10
+ "copy",
20
11
  "design-system",
12
+ "developer-tool",
21
13
  "frontend-tooling",
22
14
  "icon-registry",
15
+ "package-installer",
23
16
  "react-components",
17
+ "registry",
24
18
  "shadcn",
25
19
  "shadcn-ui",
26
20
  "svg-icons",
27
21
  "tailwind",
28
- "ui-components",
29
- "package-installer",
30
- "registry",
31
- "components",
32
- "copy"
22
+ "ui-components"
33
23
  ],
34
- "author": "",
35
24
  "license": "MIT",
25
+ "author": "",
36
26
  "bin": {
37
27
  "regpick": "./bin/regpick.js"
38
28
  },
29
+ "files": [
30
+ "dist",
31
+ "bin",
32
+ "regpick.config.schema.json"
33
+ ],
34
+ "type": "module",
35
+ "main": "./dist/index.mjs",
36
+ "exports": {
37
+ ".": "./dist/index.mjs"
38
+ },
39
39
  "scripts": {
40
40
  "docs:dev": "npm run dev --prefix website",
41
41
  "docs:build": "npm run build --prefix website",
42
42
  "build": "tsdown",
43
+ "fmt": "oxfmt",
43
44
  "lint": "oxlint src",
44
45
  "test": "vitest run",
45
46
  "test:ui": "vitest --ui",
@@ -54,9 +55,6 @@
54
55
  "validate:tebra": "node ./dist/index.mjs list ../../tebra-icon-registry/registry",
55
56
  "prepare": "husky"
56
57
  },
57
- "engines": {
58
- "node": ">=20.12.0"
59
- },
60
58
  "dependencies": {
61
59
  "@clack/prompts": "^1.0.1",
62
60
  "diff": "^8.0.3",
@@ -71,6 +69,7 @@
71
69
  "@types/node": "^24.3.0",
72
70
  "@vitest/coverage-v8": "^4.0.18",
73
71
  "husky": "^9.1.7",
72
+ "oxfmt": "^0.35.0",
74
73
  "oxlint": "^1.50.0",
75
74
  "release-it": "^19.2.4",
76
75
  "tsdown": "^0.21.0-beta.2",
@@ -78,5 +77,8 @@
78
77
  "typescript": "^5.9.2",
79
78
  "vite-tsconfig-paths": "^6.1.1",
80
79
  "vitest": "^4.0.18"
80
+ },
81
+ "engines": {
82
+ "node": ">=20.12.0"
81
83
  }
82
84
  }
@@ -1 +0,0 @@
1
- import{t as e}from"./index.mjs";import{n as t,t as n}from"./result-Dmv-uoQK.mjs";import{n as r,r as i}from"./config-DBCWbzyr.mjs";import{n as a,t as o}from"./registry-Ccy74Ba7.mjs";import s from"node:path";import*as c from"valibot";import l from"node:crypto";function u(e){return e.replace(/\\/g,`/`)}function d(r,i,a){let o=`${s.resolve(r)}${s.sep}`,c=s.resolve(i);return a?t(void 0):c!==s.resolve(r)&&!c.startsWith(o)?n(e(`ValidationError`,`Refusing to write outside project: ${c}`)):t(void 0)}function f(e,n,r,i){let a=n.type||e.type||`registry:file`,o=i.targetsByType?.[a],c=i.preferManifestTarget!==!1,l=s.basename(n.path||`${e.name}.txt`),f;f=c&&n.target?n.target:o?s.join(o,l):n.target?n.target:s.join(`src`,l);let p=s.resolve(r,f),m=d(r,p,!!i.allowOutsideProject);return m.ok?t({absoluteTarget:p,relativeTarget:u(s.relative(r,p))}):m}function p(e){return[...new Set(e.filter(Boolean))]}function m(e){return{dependencies:p(e.flatMap(e=>e.dependencies||[])),devDependencies:p(e.flatMap(e=>e.devDependencies||[]))}}function h(e,t){let n=new Map,r=[...e],i=[];for(;r.length>0;){let e=r.shift();if(!n.has(e.name)&&(n.set(e.name,e),e.registryDependencies&&e.registryDependencies.length>0))for(let a of e.registryDependencies){if(n.has(a))continue;let e=t.find(e=>e.name===a);e?r.push(e):i.push(a)}}return{resolvedItems:Array.from(n.values()),missingDependencies:p(i)}}function g(e,n,r,i=new Set){let a=[],o=[];for(let t of e)for(let e of t.files){let s=f(t,e,n,r);if(!s.ok)return s;let{absoluteTarget:c,relativeTarget:l}=s.value,u={itemName:t.name,sourceFile:e,absoluteTarget:c,relativeTarget:l};a.push(u),i.has(c)&&o.push(u)}return t({selectedItems:e,plannedWrites:a,dependencyPlan:m(e),conflicts:o})}function _(e,t){let n=e;for(let[e,r]of Object.entries(t.aliases||{})){let t=RegExp(`from ["']${e}(.*?)["']`,`g`);n=n.replace(t,`from "${r}$1"`);let i=RegExp(`import\\(["']${e}(.*?)["']\\)`,`g`);n=n.replace(i,`import("${r}$1")`)}return n}function v(e){return e?String(e).split(`,`).map(e=>e.trim()).filter(Boolean):[]}function y(r,i){let{flags:a}=i.args,o=v(a.select);if(a.all)return t(r);if(o.length){let i=r.filter(e=>o.includes(e.name));return i.length?t(i):n(e(`ValidationError`,`No items matched --select=${String(a.select)}`))}return t(null)}function b(e,t){let n=[];return e.length&&n.push({command:`npm`,args:[`install`,...e]}),t.length&&n.push({command:`npm`,args:[`install`,`-D`,...t]}),n}function x(e,t){let n=[];return e.length&&n.push({command:`yarn`,args:[`add`,...e]}),t.length&&n.push({command:`yarn`,args:[`add`,`-D`,...t]}),n}function S(e,t){let n=[];return e.length&&n.push({command:`pnpm`,args:[`add`,...e]}),t.length&&n.push({command:`pnpm`,args:[`add`,`-D`,...t]}),n}const C={npm:{manager:`npm`,buildInstallCommands:b},yarn:{manager:`yarn`,buildInstallCommands:x},pnpm:{manager:`pnpm`,buildInstallCommands:S}};function w(e){return C[e]}function T(e){return[...new Set(e.filter(Boolean))]}function E(e,t,n){let r=s.join(t,`package.json`);if(!n.fs.existsSync(r))return{missingDependencies:[],missingDevDependencies:[]};let i=n.fs.readJsonSync(r),a=i.ok?i.value:{},o={...a.dependencies||{},...a.devDependencies||{},...a.peerDependencies||{}},c=T(e.flatMap(e=>e.dependencies||[])),l=T(e.flatMap(e=>e.devDependencies||[]));return{missingDependencies:c.filter(e=>!o[e]),missingDevDependencies:l.filter(e=>!o[e])}}function D(r,i,a,o,s){if(!a.length&&!o.length)return t(void 0);let c=w(i).buildInstallCommands(a,o);for(let t of c)if(s.process.run(t.command,t.args,r).status!==0)return n(e(`InstallError`,`Dependency install failed: ${t.command} ${t.args.join(` `)}`));return t(void 0)}const O=c.object({components:c.record(c.string(),c.object({version:c.optional(c.string()),source:c.optional(c.string()),hash:c.string()}))});function k(e){return s.join(e,`regpick-lock.json`)}async function A(e,t){let n=k(e);if(!await t.fs.pathExists(n))return{components:{}};let r=t.fs.readJsonSync(n);if(!r.ok)return{components:{}};try{return c.parse(O,r.value)}catch{return{components:{}}}}async function j(e,t,n){let r=k(e);await n.fs.writeJson(r,t,{spaces:2})}function M(e){return l.createHash(`sha256`).update(e).digest(`hex`)}function N(e,t,n){return t&&t!==`auto`?t:n.fs.existsSync(s.join(e,`pnpm-lock.yaml`))?`pnpm`:n.fs.existsSync(s.join(e,`yarn.lock`))?`yarn`:(n.fs.existsSync(s.join(e,`package-lock.json`)),`npm`)}async function P(r,a,o){let s=o[1];if(s)return t(i(s,a));let c=Object.entries(a.registries||{}).map(([e,t])=>({label:`${e} -> ${t}`,value:e}));if(c.length){let o=await r.runtime.prompt.multiselect({message:`Pick registry alias (or cancel and provide URL/path manually)`,options:c,maxItems:1,required:!1});if(await r.runtime.prompt.isCancel(o))return n(e(`UserCancelled`,`Operation cancelled.`));if(Array.isArray(o)&&o.length>0)return t(i(String(o[0]),a))}let l=await r.runtime.prompt.text({message:`Registry URL/path:`,placeholder:`https://example.com/registry.json`});return await r.runtime.prompt.isCancel(l)?n(e(`UserCancelled`,`Operation cancelled.`)):t(String(l))}function F(e){return e.map(e=>({value:e.name,label:`${e.name} (${e.type||`registry:file`})`,hint:e.description||`${e.files.length} file(s)`}))}async function I(r,i){if(!i.length)return t([]);let a=await r.runtime.prompt.autocompleteMultiselect({message:`Select items to install`,options:F(i),maxItems:10,required:!0});if(await r.runtime.prompt.isCancel(a))return n(e(`UserCancelled`,`Operation cancelled.`));let o=Array.isArray(a)?a:[],s=new Set(o.map(e=>String(e)));return t(i.filter(e=>s.has(e.name)))}async function L(i){let c=!!i.args.flags.yes,{config:l,configPath:u}=await r(i.cwd);if(!u)return i.runtime.prompt.error(`No regpick.json configuration found. Please run 'init' first.`),n(e(`ValidationError`,`No config file found`));let d=(i.args.positionals[0]===`add`?1:0)+1,f=await P(i,l,i.args.positionals);if(!f.ok)return f;let p=f.value;if(!p)return t({kind:`noop`,message:`No registry source provided.`});let m=await o(p,i.cwd,i.runtime);if(!m.ok)return m;let{items:v}=m.value;if(!v.length)return i.runtime.prompt.warn(`No installable items in registry.`),t({kind:`noop`,message:`No installable items in registry.`});let b=i.args.positionals[d];b&&!i.args.flags.select&&(i.args.flags.select=b);let x=y(v,i),S=x.ok&&x.value?x:await I(i,v);if(!S.ok)return S;let C=S.value,{resolvedItems:w,missingDependencies:T}=h(C,v);C=w;for(let e of T)i.runtime.prompt.warn(`Registry dependency "${e}" not found in current registry.`);if(!C||!C.length)return i.runtime.prompt.warn(`No items selected.`),t({kind:`noop`,message:`No items selected.`});if(!c){let t=await i.runtime.prompt.confirm({message:`Install ${C.length} item(s)?`,initialValue:!0});if(await i.runtime.prompt.isCancel(t)||!t)return n(e(`UserCancelled`,`Operation cancelled.`))}let O=new Set,k=g(C,i.cwd,l);if(!k.ok)return k;let F=k.value;for(let e of F.plannedWrites)await i.runtime.fs.pathExists(e.absoluteTarget)&&O.add(e.absoluteTarget);let L=g(C,i.cwd,l,O);if(!L.ok)return L;let R=L.value,z=[];for(let t of R.plannedWrites)if(O.has(t.absoluteTarget))if(c||l.overwritePolicy===`overwrite`)z.push(t);else if(l.overwritePolicy===`skip`)i.runtime.prompt.warn(`Skipped existing file: ${t.absoluteTarget}`);else{let r=await i.runtime.prompt.select({message:`File exists: ${t.absoluteTarget}`,options:[{value:`overwrite`,label:`Overwrite this file`},{value:`skip`,label:`Skip this file`},{value:`abort`,label:`Abort installation`}]});if(await i.runtime.prompt.isCancel(r)||r===`abort`)return n(e(`UserCancelled`,`Installation aborted by user.`));r===`overwrite`&&z.push(t)}else z.push(t);let{missingDependencies:B,missingDevDependencies:V}=E(C,i.cwd,i.runtime),H=!1;if(B.length||V.length)if(c)H=!0;else{let t=N(i.cwd,l.packageManager,i.runtime),r=[];B.length&&r.push(`dependencies: ${B.join(`, `)}`),V.length&&r.push(`devDependencies: ${V.join(`, `)}`);let a=await i.runtime.prompt.confirm({message:`Install missing packages with ${t}? (${r.join(` | `)})`,initialValue:!0});if(await i.runtime.prompt.isCancel(a))return n(e(`UserCancelled`,`Dependency installation cancelled by user.`));H=!!a,H||i.runtime.prompt.warn(`Skipped dependency installation.`)}let U=0,W=await A(i.cwd,i.runtime),G={};for(let e of z){let t=C.find(t=>t.name===e.itemName);if(!t)continue;let n=await a(e.sourceFile,t,i.cwd,i.runtime);if(!n.ok)return n;let r=_(n.value,l),o=await i.runtime.fs.ensureDir(s.dirname(e.absoluteTarget));if(!o.ok)return o;let c=await i.runtime.fs.writeFile(e.absoluteTarget,r,`utf8`);if(!c.ok)return c;let u=M(r);G[t.name]||(G[t.name]=[]),G[t.name].push(u),U+=1,i.runtime.prompt.success(`Wrote ${e.relativeTarget}`)}if(U>0){for(let[e,t]of Object.entries(G)){let n=M(t.sort().join(``));W.components[e]={source:p,hash:n}}await j(i.cwd,W,i.runtime)}if(H){let e=N(i.cwd,l.packageManager,i.runtime),t=D(i.cwd,e,B,V,i.runtime);if(!t.ok)return t}return i.runtime.prompt.info(`Installed ${C.length} item(s), wrote ${U} file(s).`),t({kind:`success`,message:`Installed ${C.length} item(s), wrote ${U} file(s).`})}export{f as a,_ as i,A as n,j as r,L as runAddCommand,M as t};
@@ -1 +0,0 @@
1
- import{t as e}from"./index.mjs";import{n as t,t as n}from"./result-Dmv-uoQK.mjs";import{i as r,n as i,t as a}from"./config-DBCWbzyr.mjs";function o(e,t){return e?`cancelled`:t?`overwrite`:`keep`}async function s(s){let c=a(s.cwd),l=await s.runtime.fs.stat(c);if(l.ok){let r=await s.runtime.prompt.confirm({message:`${c} already exists. Overwrite?`,initialValue:!1}),i=o(await s.runtime.prompt.isCancel(r),!!r);if(i===`cancelled`)return n(e(`UserCancelled`,`Operation cancelled.`));if(i===`keep`)return s.runtime.prompt.info(`Keeping existing configuration.`),t({kind:`noop`,message:`Keeping existing configuration.`})}let{config:u}=await i(s.cwd),d=!!s.args.flags.yes,f=d?`auto`:await s.runtime.prompt.select({message:`Jakiego menedżera pakietów używasz?`,options:[{value:`auto`,label:`Auto (wykrywanie)`},{value:`npm`,label:`npm`},{value:`yarn`,label:`yarn`},{value:`pnpm`,label:`pnpm`}]}),p=await s.runtime.prompt.isCancel(f);if(!d&&p)return n(e(`UserCancelled`,`Operation cancelled.`));let m=d?`src/components/ui`:await s.runtime.prompt.text({message:`W jakim folderze trzymasz komponenty UI?`,placeholder:`src/components/ui`}),h=await s.runtime.prompt.isCancel(m);if(!d&&h)return n(e(`UserCancelled`,`Operation cancelled.`));let g=d?`prompt`:await s.runtime.prompt.select({message:`Czy chcesz nadpisywać pliki automatycznie, czy wolisz być pytany?`,options:[{value:`prompt`,label:`Pytaj (prompt)`},{value:`overwrite`,label:`Zawsze nadpisuj (overwrite)`},{value:`skip`,label:`Pomijaj nadpisywanie (skip)`}]}),_=await s.runtime.prompt.isCancel(g);if(!d&&_)return n(e(`UserCancelled`,`Operation cancelled.`));let v={...u,packageManager:String(f),overwritePolicy:String(g),targetsByType:{...u.targetsByType,"registry:component":String(m||`src/components/ui`),"registry:file":String(m||`src/components/ui`),"registry:icon":`${String(m||`src/components/ui`)}/icons`}};try{await r(s.cwd,v,{overwrite:!0})}catch(t){let r=`Failed to write config file: ${t instanceof Error?t.message:String(t)}`;return s.runtime.prompt.error(r),n(e(`RuntimeError`,r))}return s.runtime.prompt.success(`${l.ok?`Overwrote`:`Created`} ${c}`),t({kind:`success`,message:`${l.ok?`Overwrote`:`Created`} ${c}`})}export{s as runInitCommand};
@@ -1 +0,0 @@
1
- import{t as e}from"./index.mjs";import{n as t,t as n}from"./result-Dmv-uoQK.mjs";import{n as r}from"./config-DBCWbzyr.mjs";import{t as i}from"./registry-Ccy74Ba7.mjs";function a(e,t){return e?t[e]?String(t[e]):e:null}function o(e,t){let n=a(e,t);if(n)return{source:n,requiresPrompt:!1};let r=Object.keys(t)[0];return r?{source:a(r,t),requiresPrompt:!1}:{source:null,requiresPrompt:!0}}function s(e){let t=e.type||`registry:file`,n=Array.isArray(e.files)?e.files.length:0;return`${e.name} (${t}, files: ${n})`}async function c(a){let{config:c}=await r(a.cwd),l=o(a.args.positionals[1],c.registries),u=l.source;if(l.requiresPrompt){let t=await a.runtime.prompt.text({message:`Registry URL/path:`,placeholder:`https://example.com/registry.json`});if(await a.runtime.prompt.isCancel(t))return n(e(`UserCancelled`,`Operation cancelled.`));u=String(t)}if(!u)return t({kind:`noop`,message:`No registry source provided.`});let d=await i(u,a.cwd,a.runtime);if(!d.ok)return d;let{items:f}=d.value;if(!f.length)return a.runtime.prompt.warn(`No items found in registry.`),t({kind:`noop`,message:`No items found in registry.`});a.runtime.prompt.info(`Found ${f.length} items.`);for(let e of f)console.log(`- ${s(e)}`);return t({kind:`success`,message:`Listed ${f.length} item(s).`})}export{c as runListCommand};
@@ -1 +0,0 @@
1
- import{t as e}from"./index.mjs";import{n as t,t as n}from"./result-Dmv-uoQK.mjs";import r from"node:path";import*as i from"valibot";import{fileURLToPath as a}from"node:url";const o=i.object({path:i.optional(i.string()),target:i.optional(i.string()),type:i.optional(i.string(),`registry:file`),content:i.optional(i.string()),url:i.optional(i.string())}),s=i.object({name:i.optional(i.string(),`unnamed-item`),title:i.optional(i.string()),description:i.optional(i.string(),``),type:i.optional(i.string(),`registry:file`),dependencies:i.optional(i.array(i.string()),[]),devDependencies:i.optional(i.array(i.string()),[]),registryDependencies:i.optional(i.array(i.string()),[]),files:i.optional(i.array(o),[])});function c(e,t){let n=i.parse(s,e),r=n.name===`unnamed-item`&&n.title?n.title:n.name,a=n.title??r,o=n.files.map(e=>({...e,type:e.type===`registry:file`&&n.type!==`registry:file`?n.type:e.type}));return{...n,name:r,title:a,files:o,sourceMeta:t}}function l(e){return!e||!Array.isArray(e.items)?[]:e.items.filter(e=>!!(e&&typeof e==`object`)).map(e=>Array.isArray(e.files)?null:typeof e.url==`string`?e.url:typeof e.href==`string`?e.href:typeof e.path==`string`?e.path:null).filter(e=>!!e)}function u(r,a){try{return Array.isArray(r)?t(r.filter(e=>!!(e&&typeof e==`object`)).map(e=>c(e,a))):r&&typeof r==`object`&&Array.isArray(r.items)?t(r.items.filter(e=>e&&typeof e==`object`&&Array.isArray(e.files)).map(e=>c(e,a))):r&&typeof r==`object`&&Array.isArray(r.files)?t([c(r,a)]):n(e(`RegistryError`,`Unsupported manifest structure.`))}catch(t){return i.isValiError(t)?n(e(`ValidationError`,`Manifest validation failed: ${t.message}`)):n(e(`RegistryError`,`Failed to parse manifest`))}}function d(e){return/^https?:\/\//i.test(e)}function f(e){return e.includes(`github.com`)?e.replace(/^https?:\/\/github\.com\//,`https://raw.githubusercontent.com/`).replace(/\/(blob|tree)\//,`/`):e}function p(e){return/^file:\/\//i.test(e)}function m(e,t){return new URL(t,e).toString()}async function h(i,a,o){let s=u(i,a);if(!i||typeof i!=`object`||Array.isArray(i))return s;let f=l(i);if(!f.length)return s;let p=s.ok?s.value:[],h=[];for(let t of f){let i;if(d(t)){let e=await o.http.getJson(t);if(!e.ok)return n(e.error);i=e.value}else if(a.type===`http`&&a.baseUrl){let e=await o.http.getJson(m(a.baseUrl,t));if(!e.ok)return n(e.error);i=e.value}else if((a.type===`file`||a.type===`directory`)&&a.baseDir){let s=await o.fs.readFile(r.resolve(a.baseDir,t),`utf8`);if(!s.ok)return n(s.error);try{i=JSON.parse(s.value)}catch{return n(e(`RegistryError`,`Invalid JSON: ${t}`))}}else{let a=await o.fs.readFile(r.resolve(t),`utf8`);if(!a.ok)return n(a.error);try{i=JSON.parse(a.value)}catch{return n(e(`RegistryError`,`Invalid JSON: ${t}`))}}i&&typeof i==`object`&&h.push(c(i,a))}return t([...p,...h])}async function g(e,i){let a=r.resolve(e),o=await i.fs.readdir(a);if(!o.ok)return n(o.error);let s=o.value.filter(e=>e.endsWith(`.json`)),l=[];for(let e of s){let t=r.join(a,e),o=await i.fs.readFile(t,`utf8`);if(!o.ok)return n(o.error);let s;try{s=JSON.parse(o.value)}catch{continue}!s||typeof s!=`object`||!Array.isArray(s.files)||l.push(c(s,{type:`directory`,baseDir:a}))}return t(l)}async function _(i,o,s){if(!i)return n(e(`ValidationError`,`Registry source is required.`));let c=d(i)||p(i)?f(i):r.resolve(o,i);if(d(c)){let e=await s.http.getJson(c);if(!e.ok)return n(e.error);let r=c.endsWith(`/`)?c:c.replace(/[^/]*$/,``),i=await h(e.value,{type:`http`,baseUrl:r},s);return i.ok?t({items:i.value,source:c}):n(i.error)}let l=p(c)?a(new URL(c)):r.resolve(c),u=await s.fs.stat(l);if(!u.ok)return n(e(`RegistryError`,`Registry source not found: ${i}`));if(u.value.isDirectory()){let e=await g(l,s);return e.ok?t({items:e.value,source:l}):n(e.error)}let m=await s.fs.readFile(l,`utf8`);if(!m.ok)return n(m.error);let _;try{_=JSON.parse(m.value)}catch(t){return n(e(`RegistryError`,`Failed to parse registry JSON.`,t))}let v=await h(_,{type:`file`,baseDir:r.dirname(l)},s);return v.ok?t({items:v.value,source:l}):n(v.error)}async function v(i,a,o,s){if(typeof i.content==`string`)return t(i.content);let c=i.url||i.path;if(!c)return n(e(`ValidationError`,`File entry in "${a.name}" is missing both content and path/url.`));let l=d(c)?f(c):c;if(d(l))return await s.http.getText(l);if(a.sourceMeta.type===`http`&&a.sourceMeta.baseUrl){let e=m(a.sourceMeta.baseUrl,l);return await s.http.getText(e)}let u=a.sourceMeta.baseDir&&!r.isAbsolute(c)?r.resolve(a.sourceMeta.baseDir,c):r.resolve(o,c);return await s.fs.readFile(u,`utf8`)}export{v as n,_ as t};