regpick 0.9.4 → 0.10.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/add-Bsk3NHKV.mjs +1 -0
- package/dist/config-BjCKahTl.mjs +1 -0
- package/dist/index.mjs +1 -1
- package/dist/init-BTOB3wHB.mjs +1 -0
- package/dist/list-D08qTVwi.mjs +1 -0
- package/dist/lockfile-BdCCiIuT.mjs +1 -0
- package/dist/pack-D0Qeguwh.mjs +1 -0
- package/dist/ports-D5OB8fUl.mjs +1 -0
- package/dist/{registry-CzJU-6q5.mjs → registry-C9Zag4hh.mjs} +1 -1
- package/dist/{result-Dmv-uoQK.mjs → result-mJp6ULEQ.mjs} +1 -1
- package/dist/saga-CJXdVI4r.mjs +1 -0
- package/dist/update-BN9AJKcB.mjs +2 -0
- package/package.json +1 -1
- package/dist/add-DdKm2Ifq.mjs +0 -1
- package/dist/config-BadTCZSR.mjs +0 -1
- package/dist/init-BRDg97Sb.mjs +0 -1
- package/dist/list-vvmSIn82.mjs +0 -1
- package/dist/pack-Xnel4K2o.mjs +0 -1
- package/dist/ports-Cr6fDIR9.mjs +0 -1
- package/dist/update-CBBNRAJE.mjs +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./index.mjs";import{r as t,t as n}from"./result-mJp6ULEQ.mjs";import{a as r}from"./lockfile-BdCCiIuT.mjs";import{a as i,i as a,n as o,r as s,t as c}from"./saga-CJXdVI4r.mjs";import{i as l,r as u}from"./config-BjCKahTl.mjs";import{n as d,t as f}from"./registry-C9Zag4hh.mjs";import p from"node:path";function m(e){return e.replace(/\\/g,`/`)}function h(r,i,a){let o=`${p.resolve(r)}${p.sep}`,s=p.resolve(i);return a?t(void 0):s!==p.resolve(r)&&!s.startsWith(o)?n(e(`ValidationError`,`Refusing to write outside project: ${s}`)):t(void 0)}function g(e,n,r,i){let a=n.type||e.type||`registry:file`,o=i.targetsByType?.[a],s=i.preferManifestTarget!==!1,c=p.basename(n.path||`${e.name}.txt`),l;l=s&&n.target?n.target:o?p.join(o,c):n.target?n.target:p.join(`src`,c);let u=p.resolve(r,l),d=h(r,u,!!i.allowOutsideProject);return d.ok?t({absoluteTarget:u,relativeTarget:m(p.relative(r,u))}):d}function _(e){return[...new Set(e.filter(Boolean))]}function v(e){return{dependencies:_(e.flatMap(e=>e.dependencies||[])),devDependencies:_(e.flatMap(e=>e.devDependencies||[]))}}function y(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:_(i)}}function b(e,n,r,i=new Set){let a=[],o=[];for(let t of e)for(let e of t.files){let s=g(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:v(e),conflicts:o})}function x(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 S(e){return e?String(e).split(`,`).map(e=>e.trim()).filter(Boolean):[]}function C(r,i){let{flags:a}=i.args,o=S(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)}async function w(r){let i=await u(r.cwd);return i.configPath?t(i):(r.runtime.prompt.error(`No regpick.json configuration found. Please run 'init' first.`),n(e(`ValidationError`,`No config file found`)))}async function T(r,i){let a=r.args.positionals[0]===`add`?1:0,o=r.args.positionals[a];if(o)return t(l(o,i));let s=Object.entries(i.registries||{}).map(([e,t])=>({label:`${e} -> ${t}`,value:e}));if(s.length){let a=await r.runtime.prompt.multiselect({message:`Pick registry alias (or cancel and provide URL/path manually)`,options:s,maxItems:1,required:!1});if(await r.runtime.prompt.isCancel(a))return n(e(`UserCancelled`,`Operation cancelled.`));if(Array.isArray(a)&&a.length>0)return t(l(String(a[0]),i))}let c=await r.runtime.prompt.text({message:`Registry URL/path:`,placeholder:`https://example.com/registry.json`});return await r.runtime.prompt.isCancel(c)?n(e(`UserCancelled`,`Operation cancelled.`)):t(String(c))}async function E(r,i){let a=(r.args.positionals[0]===`add`?1:0)+1,o=await f(i,r.cwd,r.runtime);if(!o.ok)return o;let{items:s}=o.value;if(!s.length)return r.runtime.prompt.warn(`No installable items in registry.`),n(e(`ValidationError`,`No installable items in registry.`));let c=r.args.positionals[a];c&&!r.args.flags.select&&(r.args.flags.select=c);let l=C(s,r),u;if(l.ok&&l.value)u=l.value;else if(l.ok){let t=await r.runtime.prompt.autocompleteMultiselect({message:`Select items to install`,options:s.map(e=>({value:e.name,label:`${e.name} (${e.type||`registry:file`})`,hint:e.description||`${e.files.length} file(s)`})),maxItems:10,required:!0});if(await r.runtime.prompt.isCancel(t))return n(e(`UserCancelled`,`Operation cancelled.`));let i=new Set((Array.isArray(t)?t:[]).map(String));u=s.filter(e=>i.has(e.name))}else return n(l.error);if(!u.length)return r.runtime.prompt.warn(`No items selected.`),n(e(`ValidationError`,`No items selected.`));let{resolvedItems:d,missingDependencies:p}=y(u,s);return t({selectedItems:d,missingRegistryDeps:p})}async function D(e,r,a){let o=b(a,e.cwd,r);if(!o.ok)return n(o.error);let s=new Set,c=o.value.plannedWrites;for(let t of c)await e.runtime.fs.pathExists(t.absoluteTarget)&&s.add(t.absoluteTarget);let l=b(a,e.cwd,r,s);if(!l.ok)return n(l.error);let{missingDependencies:u,missingDevDependencies:d}=i(a,e.cwd,e.runtime);return t({selectedItems:a,missingDependencies:u,missingDevDependencies:d,plannedWrites:l.value.plannedWrites,existingTargets:s})}async function O(r,i,o){let s=!!r.args.flags.yes;if(!s){let t=await r.runtime.prompt.confirm({message:`Install ${o.selectedItems.length} item(s)?`,initialValue:!0});if(await r.runtime.prompt.isCancel(t)||!t)return n(e(`UserCancelled`,`Operation cancelled.`))}let c=[];for(let t of o.plannedWrites)if(o.existingTargets.has(t.absoluteTarget))if(s||i.overwritePolicy===`overwrite`)c.push(t);else if(i.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`&&c.push(t)}else c.push(t);let l=!1;if(o.missingDependencies.length||o.missingDevDependencies.length)if(s)l=!0;else{let t=a(r.cwd,i.packageManager,r.runtime),s=[];o.missingDependencies.length&&s.push(`dependencies: ${o.missingDependencies.join(`, `)}`),o.missingDevDependencies.length&&s.push(`devDependencies: ${o.missingDevDependencies.join(`, `)}`);let c=await r.runtime.prompt.confirm({message:`Install missing packages with ${t}? (${s.join(` | `)})`,initialValue:!0});if(await r.runtime.prompt.isCancel(c))return n(e(`UserCancelled`,`Dependency installation cancelled by user.`));l=!!c,l||r.runtime.prompt.warn(`Skipped dependency installation.`)}return t({selectedItems:o.selectedItems,shouldInstallDeps:l,finalWrites:c,dependencyPlan:{dependencies:o.missingDependencies,devDependencies:o.missingDevDependencies}})}async function k(e,r,i){let a=[];for(let t of i.finalWrites){let o=i.selectedItems.find(e=>e.name===t.itemName);if(!o)continue;let s=await d(t.sourceFile,o,e.cwd,e.runtime);if(!s.ok)return n(s.error);let c=x(s.value,r);a.push({absoluteTarget:t.absoluteTarget,finalContent:c,itemName:t.itemName})}return t({...i,hydratedWrites:a})}function A(e,t){let n=[],r=[];for(let i of t.hydratedWrites){n.push(new c(i.absoluteTarget,i.finalContent,e.runtime));let a=t.selectedItems.find(e=>e.name===i.itemName);a&&!r.some(e=>e.name===a.name)&&r.push(a)}return r.length>0&&n.push(new o(r,e.cwd,e.runtime)),t.shouldInstallDeps&&(t.dependencyPlan.dependencies.length>0||t.dependencyPlan.devDependencies.length>0)&&n.push(new s(t.dependencyPlan,e.cwd,e.runtime)),n}async function j(e){let i=await w(e);if(!i.ok)return n(i.error);let a=await T(e,i.value.config);if(!a.ok)return n(a.error);if(!a.value)return t({kind:`noop`,message:`No source provided.`});let o=await E(e,a.value);if(!o.ok)return n(o.error);for(let t of o.value.missingRegistryDeps)e.runtime.prompt.warn(`Registry dependency "${t}" not found in current registry.`);let s=await D(e,i.value.config,o.value.selectedItems);if(!s.ok)return n(s.error);let c=await O(e,i.value.config,s.value);if(!c.ok)return n(c.error);let l=await k(e,i.value.config,c.value);if(!l.ok)return n(l.error);let u=await r(A(e,l.value),(t,n)=>{n===`executing`||(n===`completed`?e.runtime.prompt.success(`[Success] ${t}`):n===`failed`?e.runtime.prompt.error(`[Failed] ${t}`):n===`compensating`?e.runtime.prompt.warn(`[Rollback] ${t}`):n===`interrupted`&&e.runtime.prompt.error(`[Interrupted] Rolling back ${t}`))});return u.ok?(e.runtime.prompt.info(`Installed ${l.value.selectedItems.length} item(s), wrote ${l.value.hydratedWrites.length} file(s).`),t({kind:`success`,message:`Installed ${l.value.selectedItems.length} item(s), wrote ${l.value.hydratedWrites.length} file(s).`})):u}export{g as n,j as runAddCommand,x as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:path";import*as t from"valibot";import"node:fs/promises";import{loadConfig as n}from"unconfig";const r=t.union([t.literal(`prompt`),t.literal(`overwrite`),t.literal(`skip`)]),i=t.union([t.literal(`auto`),t.literal(`npm`),t.literal(`yarn`),t.literal(`pnpm`)]),a=t.object({registries:t.record(t.string(),t.string()),targetsByType:t.record(t.string(),t.string()),aliases:t.optional(t.record(t.string(),t.string()),{}),overwritePolicy:r,packageManager:i,preferManifestTarget:t.boolean(),allowOutsideProject:t.boolean()}),o={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 s(t){return e.join(t,`regpick.json`)}async function c(e){let{config:r,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:o,merge:!0,cwd:e});return{config:t.parse(a,r),configPath:i[0]||null}}function l(e,t){return e?t.registries[e]?String(t.registries[e]):e:null}export{l as i,s as n,c as r,a 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-
|
|
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-D5OB8fUl.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-BTOB3wHB.mjs`).then(e=>e.runInitCommand(f));else if(l===`list`)e=await import(`./list-D08qTVwi.mjs`).then(e=>e.runListCommand(f));else if(l===`add`)e=await import(`./add-Bsk3NHKV.mjs`).then(e=>e.runAddCommand(f));else if(l===`update`)e=await import(`./update-BN9AJKcB.mjs`).then(e=>e.runUpdateCommand(f));else if(l===`pack`)e=await import(`./pack-D0Qeguwh.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{r as t,t as n}from"./result-mJp6ULEQ.mjs";import{a as r}from"./lockfile-BdCCiIuT.mjs";import{t as i}from"./saga-CJXdVI4r.mjs";import{n as a,r as o,t as s}from"./config-BjCKahTl.mjs";import*as c from"valibot";function l(e,t){return e?`cancelled`:t?`overwrite`:`keep`}async function u(e){let n=a(e.cwd),r=(await e.runtime.fs.stat(n)).ok,{config:i}=await o(e.cwd);return t({configPath:n,exists:r,existingConfig:i})}async function d(r,i){if(i.exists){let a=await r.runtime.prompt.confirm({message:`${i.configPath} already exists. Overwrite?`,initialValue:!1}),o=l(await r.runtime.prompt.isCancel(a),!!a);if(o===`cancelled`)return n(e(`UserCancelled`,`Operation cancelled.`));if(o===`keep`)return r.runtime.prompt.info(`Keeping existing configuration.`),t(null)}let a=!!r.args.flags.yes,o=a?`auto`:await r.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`}]}),u=await r.runtime.prompt.isCancel(o);if(!a&&u)return n(e(`UserCancelled`,`Operation cancelled.`));let d=a?`src/components/ui`:await r.runtime.prompt.text({message:`W jakim folderze trzymasz komponenty UI?`,placeholder:`src/components/ui`}),f=await r.runtime.prompt.isCancel(d);if(!a&&f)return n(e(`UserCancelled`,`Operation cancelled.`));let p=a?`prompt`:await r.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)`}]}),m=await r.runtime.prompt.isCancel(p);if(!a&&m)return n(e(`UserCancelled`,`Operation cancelled.`));let h={...i.existingConfig,packageManager:String(o),overwritePolicy:String(p),targetsByType:{...i.existingConfig.targetsByType,"registry:component":String(d||`src/components/ui`),"registry:file":String(d||`src/components/ui`),"registry:icon":`${String(d||`src/components/ui`)}/icons`}};return t({newConfig:c.parse(s,h),configPath:i.configPath,isOverwrite:i.exists})}function f(e,t){let n=JSON.stringify(t.newConfig,null,2);return[new i(t.configPath,n,e.runtime)]}async function p(e){let i=await u(e);if(!i.ok)return n(i.error);let a=await d(e,i.value);if(!a.ok)return n(a.error);if(!a.value)return t({kind:`noop`,message:`Keeping existing configuration.`});let o=await r(f(e,a.value),(t,n)=>{n===`failed`&&e.runtime.prompt.error(`Failed to write config file: ${a.value.configPath}`)});return o.ok?(e.runtime.prompt.success(`${a.value.isOverwrite?`Overwrote`:`Created`} ${a.value.configPath}`),t({kind:`success`,message:`${a.value.isOverwrite?`Overwrote`:`Created`} ${a.value.configPath}`})):o}export{p as runInitCommand};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./index.mjs";import{r as t,t as n}from"./result-mJp6ULEQ.mjs";import{r}from"./config-BjCKahTl.mjs";import{t as i}from"./registry-C9Zag4hh.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}}async function s(e){let{config:n}=await r(e.cwd),i=o(e.args.positionals[1],n.registries);return t({source:i.source,requiresPrompt:i.requiresPrompt})}async function c(r,i){if(!i.requiresPrompt)return t(i.source);let a=await r.runtime.prompt.text({message:`Registry URL/path:`,placeholder:`https://example.com/registry.json`});return await r.runtime.prompt.isCancel(a)?n(e(`UserCancelled`,`Operation cancelled.`)):t(String(a))}async function l(e,n){let r=await i(n,e.cwd,e.runtime);return r.ok?t(r.value.items):r}function u(e){let t=e.type||`registry:file`,n=Array.isArray(e.files)?e.files.length:0;return`${e.name} (${t}, files: ${n})`}function d(e,t){e.runtime.prompt.info(`Found ${t.length} items.`);for(let e of t)console.log(`- ${u(e)}`)}async function f(e){let r=await s(e);if(!r.ok)return n(r.error);let i=await c(e,r.value);if(!i.ok)return n(i.error);if(!i.value)return t({kind:`noop`,message:`No registry source provided.`});let a=await l(e,i.value);if(!a.ok)return n(a.error);let o=a.value;return o.length?(d(e,o),t({kind:`success`,message:`Listed ${o.length} item(s).`})):(e.runtime.prompt.warn(`No items found in registry.`),t({kind:`noop`,message:`No items found in registry.`}))}export{f as runListCommand};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./index.mjs";import{n as t,r as n,t as r}from"./result-mJp6ULEQ.mjs";import i from"node:path";import*as a from"valibot";import o from"node:crypto";async function s(i,a){let o=[],s=!1;return new Promise(async l=>{let u=async()=>{s||(s=!0,a?.(`Interrupted by user (SIGINT). Gracefully rolling back...`,`interrupted`),await c(o,a),process.exit(130))};process.env.NODE_ENV!==`test`&&process.on(`SIGINT`,u);for(let n of i){if(s)break;a?.(n.name,`executing`);let i=await n.execute();if(s)break;if(t(i))return s=!0,a?.(n.name,`failed`),await c(o,a),process.env.NODE_ENV!==`test`&&process.off(`SIGINT`,u),l(r(e(i.error.kind,`Transaction failed at step "${n.name}". Successfully rolled back ${o.length} previous steps.\nOriginal error: ${i.error.message}`,i.error)));a?.(n.name,`completed`),o.push(n)}process.env.NODE_ENV!==`test`&&process.off(`SIGINT`,u),!s&&l(n(void 0))})}async function c(e,n){for(let r=e.length-1;r>=0;r--){let i=e[r];n?.(i.name,`compensating`);let a=await i.compensate();t(a)&&console.error(`[Saga] FATAL: Failed to compensate step "${i.name}":`,a.error.message)}}const l=a.object({version:a.optional(a.string()),source:a.optional(a.string()),hash:a.string()}),u=a.object({components:a.record(a.string(),l)});function d(e){return i.join(e,`regpick-lock.json`)}async function f(e,t){let n=d(e);if(!await t.fs.pathExists(n))return{components:{}};let r=t.fs.readJsonSync(n);if(!r.ok)return{components:{}};try{return a.parse(u,r.value)}catch{return{components:{}}}}async function p(e,t,n){let r=d(e);await n.fs.writeJson(r,t,{spaces:2})}function m(e){return o.createHash(`sha256`).update(e).digest(`hex`)}export{s as a,p as i,d as n,f as r,m as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./index.mjs";import{r as t,t as n}from"./result-mJp6ULEQ.mjs";import{a as r}from"./lockfile-BdCCiIuT.mjs";import{t as i}from"./saga-CJXdVI4r.mjs";import a from"node:path";function o(e){let t=/import\s+[\s\S]*?from\s+["']([^"']+)["']/g,n=/import\(["']([^"']+)["']\)/g,r=new Set,i;for(;(i=t.exec(e))!==null;){let e=i[1];if(!e.startsWith(`.`)&&!e.startsWith(`/`)&&!e.startsWith(`~`)&&!e.startsWith(`@/`)&&!e.startsWith(`@\\`)){let t=e.split(`/`);e.startsWith(`@`)&&t.length>1?r.add(`${t[0]}/${t[1]}`):r.add(t[0])}}for(;(i=n.exec(e))!==null;){let e=i[1];if(!e.startsWith(`.`)&&!e.startsWith(`/`)&&!e.startsWith(`~`)&&!e.startsWith(`@/`)&&!e.startsWith(`@\\`)){let t=e.split(`/`);e.startsWith(`@`)&&t.length>1?r.add(`${t[0]}/${t[1]}`):r.add(t[0])}}return Array.from(r)}function s(e){let t=o(e.content),n=a.relative(e.targetDir,e.path).replace(/\\/g,`/`),r=a.basename(e.path,a.extname(e.path));return{name:r,title:r,description:`Packed component`,type:`registry:component`,dependencies:t,devDependencies:[],registryDependencies:[],files:[{path:n,type:`registry:component`}]}}async function c(e,r){let i=[];async function o(e){let n=await r.runtime.fs.readdir(e);if(!n.ok)return n;let s=await Promise.all(n.value.map(async n=>{let s=a.join(e,n),c=await r.runtime.fs.stat(s);if(!c.ok)return c;if(c.value.isDirectory()){let e=await o(s);if(!e.ok)return e}else (s.endsWith(`.ts`)||s.endsWith(`.tsx`))&&i.push(s);return t(void 0)}));for(let e of s)if(!e.ok)return e;return t(void 0)}let s=await o(e);return s.ok?t(i):n(s.error)}async function l(r){let i=r.args.positionals[1]||`.`,o=a.resolve(r.cwd,i),s=await r.runtime.fs.stat(o);if(!s.ok||!s.value.isDirectory())return n(e(`ValidationError`,`Target is not a directory: ${o}`));r.runtime.prompt.info(`Scanning ${o} for components...`);let l=await c(o,r);return l.ok?t({targetDir:o,files:l.value}):l}async function u(e,r){let i=[],o=await Promise.all(r.files.map(async n=>{let i=await e.runtime.fs.readFile(n,`utf8`);return i.ok?t(s({path:n,content:i.value,targetDir:r.targetDir})):i}));for(let e of o){if(!e.ok)return n(e.error);i.push(e.value)}return t({items:i,outPath:a.join(e.cwd,`registry.json`),fileCount:r.files.length})}function d(e,t){let n={items:t.items},r=JSON.stringify(n,null,2);return[new i(t.outPath,r,e.runtime)]}async function f(e){let i=await l(e);if(!i.ok)return n(i.error);if(i.value.files.length===0)return e.runtime.prompt.warn(`No .ts or .tsx files found.`),t({kind:`noop`,message:`No files found.`});let a=await u(e,i.value);if(!a.ok)return n(a.error);let o=await r(d(e,a.value),(t,n)=>{n===`failed`&&e.runtime.prompt.error(`Failed to write registry file: ${a.value.outPath}`)});return o.ok?(e.runtime.prompt.success(`Packed ${a.value.items.length} components into registry.json`),t({kind:`success`,message:`Generated registry.json`})):o}export{f as runPackCommand};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./index.mjs";import{r as t,t as n}from"./result-mJp6ULEQ.mjs";import r from"node:fs/promises";import{spawnSync as i}from"node:child_process";import a from"node:fs";const o=o=>({fs:{existsSync:e=>a.existsSync(e),pathExists:async e=>{try{return await r.access(e),!0}catch{return!1}},remove:async i=>{try{return await r.rm(i,{recursive:!0,force:!0}),t(void 0)}catch(t){return n(e(`RuntimeError`,`Failed to remove ${i}`,t))}},ensureDir:async i=>{try{return await r.mkdir(i,{recursive:!0}),t(void 0)}catch(t){return n(e(`RuntimeError`,`Failed to ensure directory: ${i}`,t))}},writeFile:async(i,a,o)=>{try{return await r.writeFile(i,a,o),t(void 0)}catch(t){return n(e(`RuntimeError`,`Failed to write file: ${i}`,t))}},readFile:async(i,a)=>{try{return t(await r.readFile(i,a))}catch(t){return n(e(`RuntimeError`,`Failed to read file: ${i}`,t))}},readJsonSync:r=>{try{let e=a.readFileSync(r,`utf8`);return t(JSON.parse(e))}catch(t){return n(e(`RuntimeError`,`Failed to read JSON: ${r}`,t))}},writeJson:async(i,a,o)=>{try{let e=JSON.stringify(a,null,o?.spaces??2);return await r.writeFile(i,e,`utf8`),t(void 0)}catch(t){return n(e(`RuntimeError`,`Failed to write JSON: ${i}`,t))}},stat:async i=>{try{return t(await r.stat(i))}catch(t){return n(e(`RuntimeError`,`Failed to stat path: ${i}`,t))}},readdir:async i=>{try{return t(await r.readdir(i))}catch(t){return n(e(`RuntimeError`,`Failed to read directory: ${i}`,t))}}},http:{getJson:async(r,i=15e3)=>{try{let a=await fetch(r,{signal:AbortSignal.timeout(i)});return a.ok?t(await a.json()):n(e(`RuntimeError`,`HTTP error! status: ${a.status} when fetching JSON from: ${r}`))}catch(t){return n(e(`RuntimeError`,`Failed to fetch JSON from: ${r}`,t))}},getText:async(r,i=15e3)=>{try{let a=await fetch(r,{signal:AbortSignal.timeout(i)});return a.ok?t(await a.text()):n(e(`RuntimeError`,`HTTP error! status: ${a.status} when fetching text from: ${r}`))}catch(t){return n(e(`RuntimeError`,`Failed to fetch text from: ${r}`,t))}}},prompt:{intro:async e=>{let{intro:t}=await import(`@clack/prompts`);return t(e)},outro:async e=>{let{outro:t}=await import(`@clack/prompts`);return t(e)},cancel:async e=>{let{cancel:t}=await import(`@clack/prompts`);return t(e)},isCancel:async e=>{let{isCancel:t}=await import(`@clack/prompts`);return t(e)},info:async e=>{let{log:t}=await import(`@clack/prompts`);return t.info(e)},warn:async e=>{let{log:t}=await import(`@clack/prompts`);return t.warn(e)},error:async e=>{let{log:t}=await import(`@clack/prompts`);return t.error(e)},success:async e=>{let{log:t}=await import(`@clack/prompts`);return t.success(e)},text:async e=>{let{text:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})},confirm:async e=>{let{confirm:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})},select:async e=>{let{select:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})},multiselect:async e=>{let{multiselect:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})},autocompleteMultiselect:async e=>{let{autocompleteMultiselect:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})}},process:{run:(e,t,n)=>i(e,t,{cwd:n,stdio:`inherit`,shell:process.platform===`win32`})}});export{o as createRuntimePorts};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./index.mjs";import{
|
|
1
|
+
import{t as e}from"./index.mjs";import{r as t,t as n}from"./result-mJp6ULEQ.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=await Promise.all(l.map(async i=>{let s;if(m(i)){let e=await o.http.getJson(i);if(!e.ok)return n(e.error);s=e.value}else if(a.type===`http`&&a.baseUrl){let e=await o.http.getJson(_(a.baseUrl,i));if(!e.ok)return n(e.error);s=e.value}else if((a.type===`file`||a.type===`directory`)&&a.baseDir){let t=await o.fs.readFile(r.resolve(a.baseDir,i),`utf8`);if(!t.ok)return n(t.error);try{s=JSON.parse(t.value)}catch{return n(e(`RegistryError`,`Invalid JSON: ${i}`))}}else{let t=await o.fs.readFile(r.resolve(i),`utf8`);if(!t.ok)return n(t.error);try{s=JSON.parse(t.value)}catch{return n(e(`RegistryError`,`Invalid JSON: ${i}`))}}return t(s&&typeof s==`object`?c(s,a):null)})),h=[];for(let e of f){if(!e.ok)return e;e.value&&h.push(e.value)}return t([...u,...h])}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=await Promise.all(s.map(async e=>{let n=r.join(a,e),o=await i.fs.readFile(n,`utf8`);if(!o.ok)return o;let s;try{s=JSON.parse(o.value)}catch{return t(null)}return!s||typeof s!=`object`||!(`files`in s)||!Array.isArray(s.files)?t(null):t(c(s,{type:`directory`,baseDir:a}))})),u=[];for(let e of l){if(!e.ok)return n(e.error);e.value&&u.push(e.value)}return t(u)}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 +1 @@
|
|
|
1
|
-
function e(e){return{ok:!0,value:e}}function t(e){return{ok:!1,error:e}}export{e as
|
|
1
|
+
function e(e){return{ok:!0,value:e}}function t(e){return{ok:!1,error:e}}function n(e){return!e.ok}export{n,e as r,t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./index.mjs";import{n as t,r as n,t as r}from"./result-mJp6ULEQ.mjs";import{i,r as a}from"./lockfile-BdCCiIuT.mjs";import o from"node:path";import*as s from"valibot";function c(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 l(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 u(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 d={npm:{manager:`npm`,buildInstallCommands:c},yarn:{manager:`yarn`,buildInstallCommands:l},pnpm:{manager:`pnpm`,buildInstallCommands:u}};function f(e){return d[e]}const p=s.object({dependencies:s.optional(s.record(s.string(),s.string()),{}),devDependencies:s.optional(s.record(s.string(),s.string()),{}),peerDependencies:s.optional(s.record(s.string(),s.string()),{})});function m(e){return[...new Set(e.filter(Boolean))]}function h(e,t,n){let r=o.join(t,`package.json`);if(!n.fs.existsSync(r))return{missingDependencies:[],missingDevDependencies:[]};let i=n.fs.readJsonSync(r),a=i.ok?i.value:{},c=s.safeParse(p,a),l=c.success?c.output:{dependencies:{},devDependencies:{},peerDependencies:{}},u={...l.dependencies,...l.devDependencies,...l.peerDependencies},d=m(e.flatMap(e=>e.dependencies||[])),f=m(e.flatMap(e=>e.devDependencies||[]));return{missingDependencies:d.filter(e=>!u[e]),missingDevDependencies:f.filter(e=>!u[e])}}function g(t,i,a,o,s){if(!a.length&&!o.length)return n(void 0);let c=f(i).buildInstallCommands(a,o);for(let n of c)if(s.process.run(n.command,n.args,t).status!==0)return r(e(`InstallError`,`Dependency install failed: ${n.command} ${n.args.join(` `)}`));return n(void 0)}function _(e,t,n){return t&&t!==`auto`?t:n.fs.existsSync(o.join(e,`pnpm-lock.yaml`))?`pnpm`:n.fs.existsSync(o.join(e,`yarn.lock`))?`yarn`:(n.fs.existsSync(o.join(e,`package-lock.json`)),`npm`)}var v=class{name=`Install dependencies`;packageJsonSnapshot;lockfileSnapshot;constructor(e,t,n){this.plan=e,this.projectPath=t,this.runtime=n}async execute(){let e=_(this.projectPath,`auto`,this.runtime),n=e===`pnpm`?`pnpm-lock.yaml`:e===`yarn`?`yarn.lock`:`package-lock.json`,r=`${this.projectPath}/package.json`,i=`${this.projectPath}/${n}`,a=await this.runtime.fs.readFile(r,`utf8`);t(a)||(this.packageJsonSnapshot=a.value);let o=await this.runtime.fs.readFile(i,`utf8`);return t(o)||(this.lockfileSnapshot=o.value),g(this.projectPath,e,this.plan.dependencies,this.plan.devDependencies,this.runtime)}async compensate(){let e=`${this.projectPath}/package.json`,t=_(this.projectPath,`auto`,this.runtime),r=t===`pnpm`?`pnpm-lock.yaml`:t===`yarn`?`yarn.lock`:`package-lock.json`,i=`${this.projectPath}/${r}`;return this.packageJsonSnapshot!==void 0&&await this.runtime.fs.writeFile(e,this.packageJsonSnapshot,`utf8`),this.lockfileSnapshot!==void 0&&await this.runtime.fs.writeFile(i,this.lockfileSnapshot,`utf8`),n(void 0)}},y=class{name=`Update lockfile`;priorLockfileState;existedPreviously=!1;constructor(e,t,n){this.itemsToInstall=e,this.projectPath=t,this.runtime=n}async execute(){let e=`${this.projectPath}/regpick-lock.json`;this.existedPreviously=await this.runtime.fs.pathExists(e),this.existedPreviously&&(this.priorLockfileState=await a(this.projectPath,this.runtime),this.priorLockfileState=JSON.parse(JSON.stringify(this.priorLockfileState)));let t=await a(this.projectPath,this.runtime);for(let e of this.itemsToInstall)t.components||={},t.components[e.name]={source:e.sourceMeta?.baseUrl??e.sourceMeta?.baseDir??`unknown`,hash:`pending`};return await i(this.projectPath,t,this.runtime),n(void 0)}async compensate(){let e=`${this.projectPath}/regpick-lock.json`;return!this.existedPreviously&&this.runtime.fs.remove?await this.runtime.fs.remove(e):this.priorLockfileState!==void 0&&await i(this.projectPath,this.priorLockfileState,this.runtime),n(void 0)}},b=class{name;priorContent;existedPreviously=!1;constructor(e,t,n){this.targetPath=e,this.newContent=t,this.runtime=n,this.name=`Write file: ${this.targetPath}`}async execute(){let e=await this.runtime.fs.pathExists(this.targetPath);if(this.existedPreviously=e,e){let e=await this.runtime.fs.readFile(this.targetPath,`utf8`);if(t(e))return r(e.error);this.priorContent=e.value}let n=this.targetPath.substring(0,this.targetPath.lastIndexOf(`/`));return!await this.runtime.fs.pathExists(n)&&this.runtime.fs.ensureDir&&await this.runtime.fs.ensureDir(n),await this.runtime.fs.writeFile(this.targetPath,this.newContent,`utf8`)}async compensate(){if(!this.existedPreviously){if(this.runtime.fs.remove)return await this.runtime.fs.remove(this.targetPath)}else if(this.priorContent!==void 0)return await this.runtime.fs.writeFile(this.targetPath,this.priorContent,`utf8`);return n(void 0)}};export{h as a,_ as i,y as n,v as r,b as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./index.mjs";import{r as t,t as n}from"./result-mJp6ULEQ.mjs";import{a as r,i,n as a,r as o,t as s}from"./lockfile-BdCCiIuT.mjs";import{r as c}from"./config-BjCKahTl.mjs";import{n as l,t as u}from"./registry-C9Zag4hh.mjs";import{n as d,t as f}from"./add-Bsk3NHKV.mjs";import p from"node:path";import{styleText as m}from"node:util";var h=class{name=`Save lockfile`;previousLockfile=null;existedBefore=!1;constructor(e,t,n){this.cwd=e,this.newLockfile=t,this.runtime=n}async execute(){let e=a(this.cwd);if(this.existedBefore=await this.runtime.fs.pathExists(e),this.existedBefore){let e=await o(this.cwd,this.runtime);this.previousLockfile=JSON.parse(JSON.stringify(e))}return await i(this.cwd,this.newLockfile,this.runtime),t(void 0)}async compensate(){if(this.existedBefore&&this.previousLockfile)await i(this.cwd,this.previousLockfile,this.runtime);else{let e=a(this.cwd),t=await this.runtime.fs.remove(e);if(!t.ok)return t}return t(void 0)}},g=class{name;existedBefore=!1;previousContent=null;constructor(e,t,n){this.targetPath=e,this.newContent=t,this.runtime=n,this.name=`Update file ${e}`}async execute(){let e=await this.runtime.fs.readFile(this.targetPath,`utf8`);e.ok?(this.existedBefore=!0,this.previousContent=e.value):this.existedBefore=!1;let n=await this.runtime.fs.ensureDir(p.dirname(this.targetPath));if(!n.ok)return n;let r=await this.runtime.fs.writeFile(this.targetPath,this.newContent,`utf8`);return r.ok?t(void 0):r}async compensate(){if(this.existedBefore&&this.previousContent!==null){let e=await this.runtime.fs.ensureDir(p.dirname(this.targetPath));if(!e.ok)return e;let t=await this.runtime.fs.writeFile(this.targetPath,this.previousContent,`utf8`);if(!t.ok)return t}else{let e=await this.runtime.fs.remove(this.targetPath);if(!e.ok)return e}return t(void 0)}};function _(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 v(e,n,r,i,a,o){let c=[],l=[];for(let{file:e,content:t}of r){let r=f(t,o);c.push(r);let i=d(n,e,a,o);if(!i.ok)return i;l.push({target:i.value.absoluteTarget,content:r})}let u=s(c.sort().join(``));return t({itemName:e,status:u===i?`up-to-date`:`requires-diff-prompt`,newHash:u,files:l})}async function y(r){let[i,a]=await Promise.all([c(r.cwd),o(r.cwd,r.runtime)]);return i.configPath?t({config:i.config,lockfile:a}):(r.runtime.prompt.error(`No regpick.json configuration found. Please run 'init' first.`),n(e(`ValidationError`,`No config file found`)))}async function b(e,n,r){let i=_(r),a=[];for(let[t,o]of Object.entries(i)){let i=await u(t,e.cwd,e.runtime);if(!i.ok){e.runtime.prompt.warn(`Failed to load registry ${t}`);continue}let s=i.value.items;for(let t of o){let i=s.find(e=>e.name===t);if(!i)continue;let o=(await Promise.all(i.files.map(async t=>{let n=await l(t,i,e.cwd,e.runtime);return n.ok?{file:t,content:n.value}:null}))).filter(e=>e!==null),c=r.components[t].hash,u=v(t,i,o,c,e.cwd,n);if(!u.ok)continue;let d=u.value;if(d.status===`requires-diff-prompt`){let n=[];for(let t of d.files){let r=await e.runtime.fs.readFile(t.target,`utf8`);n.push({target:t.target,remoteContent:t.content,localContent:r.ok?r.value:``})}a.push({itemName:t,newHash:d.newHash,files:n})}}}return t(a)}async function x(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
|
+
`);for(let e of r)console.log(m(t,`${n}${e}`))}}async function S(e,n){let r=[];for(let t of n){e.runtime.prompt.info(`Update available for ${t.itemName}`);let n=await e.runtime.prompt.select({message:`What do you want to do with ${t.itemName}?`,options:[{value:`diff`,label:`Show diff`},{value:`update`,label:`Update`},{value:`skip`,label:`Skip`}]});if(!(await e.runtime.prompt.isCancel(n)||n===`skip`)){if(n===`diff`){for(let e of t.files)console.log(m(`bold`,`\nDiff for ${e.target}:`)),await x(e.localContent,e.remoteContent);let n=await e.runtime.prompt.confirm({message:`Update ${t.itemName} now?`,initialValue:!0});if(await e.runtime.prompt.isCancel(n)||!n)continue}r.push(t)}}return t({approvedUpdates:r})}function C(e,t,n){let r=[],i=JSON.parse(JSON.stringify(t));for(let t of n.approvedUpdates){for(let n of t.files)r.push(new g(n.target,n.remoteContent,e.runtime));i.components[t.itemName].hash=t.newHash}return n.approvedUpdates.length>0&&r.push(new h(e.cwd,i,e.runtime)),{sagaSteps:r,updatedLockfile:i}}async function w(e){let i=await y(e);if(!i.ok)return n(i.error);if(Object.keys(i.value.lockfile.components).length===0)return e.runtime.prompt.info(`No components installed. Nothing to update.`),t({kind:`noop`,message:`No components to update.`});let a=await b(e,i.value.config,i.value.lockfile);if(!a.ok)return n(a.error);if(a.value.length===0)return t({kind:`noop`,message:`All components are up to date.`});let o=await S(e,a.value);if(!o.ok)return n(o.error);let s=o.value.approvedUpdates.length;if(s===0)return t({kind:`noop`,message:`No updates approved.`});let{sagaSteps:c}=C(e,i.value.lockfile,o.value),l=await r(c,(t,n)=>{n===`executing`||(n===`completed`?e.runtime.prompt.success(`[Success] ${t}`):n===`failed`?e.runtime.prompt.error(`[Failed] ${t}`):n===`compensating`?e.runtime.prompt.warn(`[Rollback] ${t}`):n===`interrupted`&&e.runtime.prompt.error(`[Interrupted] Rolling back ${t}`))});return l.ok?t({kind:`success`,message:`Updated ${s} components.`}):l}export{w as runUpdateCommand};
|
package/package.json
CHANGED
package/dist/add-DdKm2Ifq.mjs
DELETED
|
@@ -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,r as i}from"./config-BadTCZSR.mjs";import{n as a,t as o}from"./registry-CzJU-6q5.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,A=await Promise.all(k.plannedWrites.map(async e=>await r.runtime.fs.pathExists(e.absoluteTarget)?e.absoluteTarget:null));for(let e of A)e&&T.add(e);let j=g(S,r.cwd,l,T);if(!j.ok)return j;let L=j.value,z=[];for(let t of L.plannedWrites)if(T.has(t.absoluteTarget))if(c||l.overwritePolicy===`overwrite`)z.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`&&z.push(t)}else z.push(t);let{missingDependencies:B,missingDevDependencies:V}=D(S,r.cwd,r.runtime),H=!1;if(B.length||V.length)if(c)H=!0;else{let t=F(r.cwd,l.packageManager,r.runtime),i=[];B.length&&i.push(`dependencies: ${B.join(`, `)}`),V.length&&i.push(`devDependencies: ${V.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.`));H=!!a,H||r.runtime.prompt.warn(`Skipped dependency installation.`)}let U=await M(r.cwd,r.runtime),W={},G=await Promise.all(z.map(async e=>{let n=S.find(t=>t.name===e.itemName);if(!n)return t({ignored:!0});let i=await a(e.sourceFile,n,r.cwd,r.runtime);if(!i.ok)return i;let o=_(i.value,l),c=await r.runtime.fs.ensureDir(s.dirname(e.absoluteTarget));if(!c.ok)return c;let u=await r.runtime.fs.writeFile(e.absoluteTarget,o,`utf8`);if(!u.ok)return u;let d=P(o);return t({ignored:!1,itemName:n.name,relativeTarget:e.relativeTarget,contentHash:d})})),K=0;for(let e of G){if(!e.ok)return e;if(e.value.ignored)continue;let{itemName:t,relativeTarget:n,contentHash:i}=e.value;W[t]||(W[t]=[]),W[t].push(i),K+=1,r.runtime.prompt.success(`Wrote ${n}`)}if(K>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(H){let e=F(r.cwd,l.packageManager,r.runtime),t=O(r.cwd,e,B,V,r.runtime);if(!t.ok)return t}return r.runtime.prompt.info(`Installed ${S.length} item(s), wrote ${K} file(s).`),t({kind:`success`,message:`Installed ${S.length} item(s), wrote ${K} file(s).`})}export{f as a,_ as i,M as n,N as r,z as runAddCommand,P as t};
|
package/dist/config-BadTCZSR.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/init-BRDg97Sb.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/dist/list-vvmSIn82.mjs
DELETED
|
@@ -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"./config-BadTCZSR.mjs";import{t as i}from"./registry-CzJU-6q5.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};
|
package/dist/pack-Xnel4K2o.mjs
DELETED
|
@@ -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";function i(e){let t=/import\s+[\s\S]*?from\s+["']([^"']+)["']/g,n=/import\(["']([^"']+)["']\)/g,r=new Set,i;for(;(i=t.exec(e))!==null;){let e=i[1];if(!e.startsWith(`.`)&&!e.startsWith(`/`)&&!e.startsWith(`~`)&&!e.startsWith(`@/`)&&!e.startsWith(`@\\`)){let t=e.split(`/`);e.startsWith(`@`)&&t.length>1?r.add(`${t[0]}/${t[1]}`):r.add(t[0])}}for(;(i=n.exec(e))!==null;){let e=i[1];if(!e.startsWith(`.`)&&!e.startsWith(`/`)&&!e.startsWith(`~`)&&!e.startsWith(`@/`)&&!e.startsWith(`@\\`)){let t=e.split(`/`);e.startsWith(`@`)&&t.length>1?r.add(`${t[0]}/${t[1]}`):r.add(t[0])}}return Array.from(r)}function a(e){let t=i(e.content),n=r.relative(e.targetDir,e.path).replace(/\\/g,`/`),a=r.basename(e.path,r.extname(e.path));return{name:a,title:a,description:`Packed component`,type:`registry:component`,dependencies:t,devDependencies:[],registryDependencies:[],files:[{path:n,type:`registry:component`}]}}async function o(e,i){let a=[];async function o(e){let n=await i.runtime.fs.readdir(e);if(!n.ok)return n;let s=await Promise.all(n.value.map(async n=>{let s=r.join(e,n),c=await i.runtime.fs.stat(s);if(!c.ok)return c;if(c.value.isDirectory()){let e=await o(s);if(!e.ok)return e}else (s.endsWith(`.ts`)||s.endsWith(`.tsx`))&&a.push(s);return t(void 0)}));for(let e of s)if(!e.ok)return e;return t(void 0)}let s=await o(e);return s.ok?t(a):n(s.error)}async function s(i){let s=i.args.positionals[1]||`.`,c=r.resolve(i.cwd,s),l=await i.runtime.fs.stat(c);if(!l.ok||!l.value.isDirectory())return n(e(`ValidationError`,`Target is not a directory: ${c}`));i.runtime.prompt.info(`Scanning ${c} for components...`);let u=await o(c,i);if(!u.ok)return u;let d=u.value;if(d.length===0)return i.runtime.prompt.warn(`No .ts or .tsx files found.`),t({kind:`noop`,message:`No files found.`});let f=[],p=await Promise.all(d.map(async e=>{let n=await i.runtime.fs.readFile(e,`utf8`);return n.ok?t(a({path:e,content:n.value,targetDir:c})):n}));for(let e of p){if(!e.ok)return n(e.error);f.push(e.value)}let m={items:f},h=r.join(i.cwd,`registry.json`),g=await i.runtime.fs.writeJson(h,m,{spaces:2});return g.ok?(i.runtime.prompt.success(`Packed ${f.length} components into registry.json`),t({kind:`success`,message:`Generated registry.json`})):n(g.error)}export{s as runPackCommand};
|
package/dist/ports-Cr6fDIR9.mjs
DELETED
|
@@ -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:fs/promises";import{spawnSync as i}from"node:child_process";import a from"node:fs";const o=o=>({fs:{existsSync:e=>a.existsSync(e),pathExists:async e=>{try{return await r.access(e),!0}catch{return!1}},ensureDir:async i=>{try{return await r.mkdir(i,{recursive:!0}),t(void 0)}catch(t){return n(e(`RuntimeError`,`Failed to ensure directory: ${i}`,t))}},writeFile:async(i,a,o)=>{try{return await r.writeFile(i,a,o),t(void 0)}catch(t){return n(e(`RuntimeError`,`Failed to write file: ${i}`,t))}},readFile:async(i,a)=>{try{return t(await r.readFile(i,a))}catch(t){return n(e(`RuntimeError`,`Failed to read file: ${i}`,t))}},readJsonSync:r=>{try{let e=a.readFileSync(r,`utf8`);return t(JSON.parse(e))}catch(t){return n(e(`RuntimeError`,`Failed to read JSON: ${r}`,t))}},writeJson:async(i,a,o)=>{try{let e=JSON.stringify(a,null,o?.spaces??2);return await r.writeFile(i,e,`utf8`),t(void 0)}catch(t){return n(e(`RuntimeError`,`Failed to write JSON: ${i}`,t))}},stat:async i=>{try{return t(await r.stat(i))}catch(t){return n(e(`RuntimeError`,`Failed to stat path: ${i}`,t))}},readdir:async i=>{try{return t(await r.readdir(i))}catch(t){return n(e(`RuntimeError`,`Failed to read directory: ${i}`,t))}}},http:{getJson:async(r,i=15e3)=>{try{let a=await fetch(r,{signal:AbortSignal.timeout(i)});return a.ok?t(await a.json()):n(e(`RuntimeError`,`HTTP error! status: ${a.status} when fetching JSON from: ${r}`))}catch(t){return n(e(`RuntimeError`,`Failed to fetch JSON from: ${r}`,t))}},getText:async(r,i=15e3)=>{try{let a=await fetch(r,{signal:AbortSignal.timeout(i)});return a.ok?t(await a.text()):n(e(`RuntimeError`,`HTTP error! status: ${a.status} when fetching text from: ${r}`))}catch(t){return n(e(`RuntimeError`,`Failed to fetch text from: ${r}`,t))}}},prompt:{intro:async e=>{let{intro:t}=await import(`@clack/prompts`);return t(e)},outro:async e=>{let{outro:t}=await import(`@clack/prompts`);return t(e)},cancel:async e=>{let{cancel:t}=await import(`@clack/prompts`);return t(e)},isCancel:async e=>{let{isCancel:t}=await import(`@clack/prompts`);return t(e)},info:async e=>{let{log:t}=await import(`@clack/prompts`);return t.info(e)},warn:async e=>{let{log:t}=await import(`@clack/prompts`);return t.warn(e)},error:async e=>{let{log:t}=await import(`@clack/prompts`);return t.error(e)},success:async e=>{let{log:t}=await import(`@clack/prompts`);return t.success(e)},text:async e=>{let{text:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})},confirm:async e=>{let{confirm:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})},select:async e=>{let{select:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})},multiselect:async e=>{let{multiselect:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})},autocompleteMultiselect:async e=>{let{autocompleteMultiselect:t}=await import(`@clack/prompts`);return t({signal:o?.signal,...e})}},process:{run:(e,t,n)=>i(e,t,{cwd:n,stdio:`inherit`,shell:process.platform===`win32`})}});export{o as createRuntimePorts};
|
package/dist/update-CBBNRAJE.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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-CzJU-6q5.mjs";import{a as i,i as a,n as o,r as s,t as c}from"./add-DdKm2Ifq.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
|
-
`);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=(await Promise.all(t.files.map(async e=>{let r=await n(e,t,i.cwd,i.runtime);return r.ok?{file:e,content:r.value}:null}))).filter(e=>e!==null),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}let n=await Promise.all(m.files.map(async e=>{let t=await i.runtime.fs.ensureDir(l.dirname(e.target));return t.ok?await i.runtime.fs.writeFile(e.target,e.content,`utf8`):t}));for(let e of n)if(!e.ok)return e;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};
|