@slabui/cli 0.0.0-stage → 0.1.0
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/CHANGELOG.md +20 -0
- package/LICENSE +59 -0
- package/README.md +14 -2
- package/dist/cli.mjs +65 -0
- package/dist/index.d.mts +449 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +61 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @slabui/cli
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#70](https://github.com/slabui/ui/pull/70) [`51f3d2a`](https://github.com/slabui/ui/commit/51f3d2aac979a6b9394c6554aeabfb2f0aadb924) Thanks [@andrefelipeschulle](https://github.com/andrefelipeschulle)! - `slabui mcp init` configura vários editores e agentes de uma vez: sem `--client`, mostra uma lista de seleção múltipla com os clientes encontrados no projeto já marcados; com `--client`, aceita vários, separados por vírgula ou repetidos (`--client claude,cursor`). As instruções para o agente são perguntadas uma vez, e cada arquivo é gravado uma vez só.
|
|
8
|
+
|
|
9
|
+
## 0.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#44](https://github.com/slabui/ui/pull/44) [`a03fb1e`](https://github.com/slabui/ui/commit/a03fb1e6cfaae16d96167545da30e368cf1335ce) Thanks [@andrefelipeschulle](https://github.com/andrefelipeschulle)! - Primeira versão pública dos pacotes da SlabUI:
|
|
14
|
+
|
|
15
|
+
- `slabui`: o comando que se usa no projeto (`npx slabui init`, `npx slabui add button`). Instala o `@slabui/cli`, que traz o `init`, `add`, `update`, `outdated`, `diff`, `search`, `info`, `login`/`logout` e `mcp`.
|
|
16
|
+
- `@slabui/mcp`: o servidor MCP do registry da SlabUI. Roda na máquina do desenvolvedor (`npx -y @slabui/mcp`, por stdio) e é o mesmo que responde em `https://slabui.com/mcp`.
|
|
17
|
+
- `@slabui/theme-react`: o editor de tema ao vivo e os plugins do Vite e do Next, que gravam as variáveis no CSS do projeto.
|
|
18
|
+
- `@slabui/theme-core`: o tema da SlabUI como variáveis CSS (ler, gravar e validar) e o atributo do tema ativo no `<html>`.
|
|
19
|
+
|
|
20
|
+
A documentação fica em https://slabui.com/docs.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
SlabUI Software License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BrainyLab Desenvolvimento de Software LTDA.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
This license applies to the slabui, @slabui/cli, @slabui/mcp,
|
|
7
|
+
@slabui/theme-core and @slabui/theme-react packages (the "Software").
|
|
8
|
+
|
|
9
|
+
1. Grant
|
|
10
|
+
|
|
11
|
+
Subject to the terms of this license, BrainyLab grants you a worldwide,
|
|
12
|
+
non-exclusive, non-transferable, royalty-free license to install and run
|
|
13
|
+
the Software, in unmodified form, in any project, including commercial
|
|
14
|
+
projects and projects used to build other tools and products.
|
|
15
|
+
|
|
16
|
+
Output produced by running the Software (such as configuration files and
|
|
17
|
+
the files it writes into your project) is not covered by this license. Files
|
|
18
|
+
installed from a registry are covered by that registry's own license.
|
|
19
|
+
|
|
20
|
+
2. Restrictions
|
|
21
|
+
|
|
22
|
+
You may not:
|
|
23
|
+
|
|
24
|
+
a. modify, adapt, translate or create derivative works of the Software;
|
|
25
|
+
b. copy, redistribute, sublicense, sell, rent or lease the Software, alone
|
|
26
|
+
or as part of another package, except as an unmodified dependency
|
|
27
|
+
installed from the official npm package;
|
|
28
|
+
c. reverse engineer, decompile or disassemble the Software, except to the
|
|
29
|
+
extent applicable law expressly permits it despite this restriction;
|
|
30
|
+
d. remove or alter any copyright or license notice in the Software.
|
|
31
|
+
|
|
32
|
+
3. Ownership
|
|
33
|
+
|
|
34
|
+
The Software is licensed, not sold. BrainyLab keeps all rights, title and
|
|
35
|
+
interest in the Software not expressly granted in this license.
|
|
36
|
+
|
|
37
|
+
4. Termination
|
|
38
|
+
|
|
39
|
+
This license ends automatically if you breach its terms. On termination,
|
|
40
|
+
you must stop using the Software and delete your copies of it.
|
|
41
|
+
|
|
42
|
+
5. No warranty
|
|
43
|
+
|
|
44
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
45
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
46
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
47
|
+
|
|
48
|
+
6. Limitation of liability
|
|
49
|
+
|
|
50
|
+
IN NO EVENT SHALL BRAINYLAB OR ITS CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
|
|
51
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
52
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
53
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
54
|
+
|
|
55
|
+
7. Governing law
|
|
56
|
+
|
|
57
|
+
This license is governed by the laws of the Federative Republic of Brazil.
|
|
58
|
+
Any dispute arising from it will be settled in the courts of the judicial
|
|
59
|
+
district where BrainyLab has its registered office.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @slabui/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The SlabUI CLI, installed and run by the [`slabui`](https://www.npmjs.com/package/slabui)
|
|
4
|
+
command: `init`, `add`, `update`, `outdated`, `diff`, `search`, `info`, `login`
|
|
5
|
+
and `mcp`. Use it through `slabui`; you don't need to install this package
|
|
6
|
+
yourself.
|
|
7
|
+
|
|
8
|
+
[](https://slabui.com/docs/cli/installation)
|
|
9
|
+
|
|
10
|
+
Commands, options and guides are in the
|
|
11
|
+
[documentation](https://slabui.com/docs/cli/installation).
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
Released under the [SlabUI Software License](./LICENSE).
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import e from"node:path";import{Command as t,Option as n}from"commander";import r from"postcss";import{access as i,lstat as a,mkdir as o,readFile as s,realpath as c,rm as l,writeFile as u}from"node:fs/promises";import{createHash as d,randomBytes as f}from"node:crypto";import{z as p}from"zod";import{homedir as m,hostname as h}from"node:os";import{createPathsMatcher as g,parseTsconfig as _}from"get-tsconfig";import{applyEdits as v,modify as y,parse as b}from"jsonc-parser";import x from"semver";import{spawn as S}from"node:child_process";import*as C from"@clack/prompts";import{createTwoFilesPatch as ee}from"diff";import w from"minisearch";import{createServer as te}from"node:http";import{merge as ne}from"node-diff3";var T=`0.1.0`,re=`The SlabUI CLI: add, update and compare items from versioned component registries`;const ie=/^[a-z0-9][a-z0-9-]*$/i;function ae(e){return ie.test(e)}function oe(e,t=!1){if(!ae(e))throw Error(`Invalid theme name: "${e}"`);return`:root[data-slabui-theme="${e}"]${t?`.dark`:``}`}const se=/^\s*(oklch|oklab|lch|lab|hsla?|rgba?|hwb|color)\(|^\s*#[0-9a-f]{3,8}\s*$/i;async function ce(e,t,{base:n,overwrite:i=!1,shouldRemove:a,theme:o}={}){let s=r.parse(e),c=[],l=[],u=e=>o?e:le(e),d=u(t),f=n?u(n):void 0;for(let e of[`theme`,`light`,`dark`]){let t=d[e]??{},n=f?.[e]??{},u=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(n)]);if(u.size===0)continue;let p=fe(s,e,o);for(let d of u){let u=t[d],f=n[d],m=p?.nodes?.find(e=>e.type===`decl`&&e.prop===`--${d}`),h=m?.value,g=t=>c.push({group:e,name:d,action:t});if(u===void 0){if(h===void 0)continue;a&&await a(e,d)?(m?.remove(),g(`removed`)):(l.push(`--${d} (${e}) was removed in the new version; kept in the CSS.`),g(`kept`))}else if(h===void 0){if(f!==void 0){g(`kept`);continue}p??=pe(s,e,o),p.raws.semicolon=!0,p.raws.after=`
|
|
3
|
+
`,p.append(r.decl({prop:`--${d}`,value:u,raws:{before:`
|
|
4
|
+
`}})),g(`added`)}else he(h,u)?g(`unchanged`):i||f!==void 0&&he(h,f)?(m.value=u,g(`updated`)):(l.push(`--${d} (${e}) has a custom value in the CSS (${h}); kept instead of ${u}.`),g(`kept`))}}return!o&&Object.keys(d.dark??{}).length>0&&me(s),{css:s.toString(),changes:c,warnings:l}}function le(e){let t={...e.theme};for(let n of[e.light,e.dark])for(let[e,r]of Object.entries(n??{}))se.test(r)&&t[`color-${e}`]===void 0&&(t[`color-${e}`]=`var(--${e})`);return{...e,...Object.keys(t).length>0&&{theme:t}}}function ue(e,t){return t?oe(t,e===`dark`):e===`light`?`:root`:`.dark`}const de=e=>e.replace(/["'\s]/g,``);function fe(e,t,n){return e.nodes.find(e=>t===`theme`?e.type===`atrule`&&e.name===`theme`&&e.params.trim()===`inline`:e.type===`rule`&&de(e.selector)===de(ue(t,n)))}function pe(e,t,n){let i=t===`theme`?r.atRule({name:`theme`,params:`inline`}):r.rule({selector:ue(t,n)});return i.raws={before:e.nodes.length>0?`
|
|
5
|
+
|
|
6
|
+
`:``,between:` `,after:`
|
|
7
|
+
`,semicolon:!0},e.append(i),i}function me(e){if(e.nodes.some(e=>e.type===`atrule`&&e.name===`custom-variant`&&e.params.trim().startsWith(`dark`)))return;let t=r.atRule({name:`custom-variant`,params:`dark (&:is(.dark *))`}),n=e.nodes.filter(e=>e.type===`atrule`&&e.name===`import`).at(-1);n?(t.raws={before:`
|
|
8
|
+
|
|
9
|
+
`},n.after(t)):(t.raws={before:``},e.prepend(t))}function he(e,t){return e.replace(/\s+/g,` `).trim()===t.replace(/\s+/g,` `).trim()}const ge={theme:{"font-sans":`var(--font-sans)`,"font-heading":`var(--font-heading)`,"font-mono":`var(--font-mono)`,"radius-sm":`calc(var(--radius) * 0.6)`,"radius-md":`calc(var(--radius) * 0.8)`,"radius-lg":`var(--radius)`,"radius-xl":`calc(var(--radius) * 1.4)`,"radius-2xl":`calc(var(--radius) * 1.8)`,"radius-3xl":`calc(var(--radius) * 2.2)`,"radius-4xl":`calc(var(--radius) * 2.6)`,"breakpoint-3xl":`1600px`,"breakpoint-4xl":`2000px`,"text-xxs":`0.625rem`,"text-2xxs":`0.688rem`,"text-2xs":`0.813rem`,"text-2xs--line-height":`calc(1.125 / 0.813)`,"text-2sm":`0.938rem`,"text-2sm--line-height":`calc(1.625 / 0.938)`,spacing:`var(--spacing)`,"focus-size":`calc(var(--focus-size))`,"focus-offset":`var(--focus-offset)`,"color-destructive":`var(--danger)`},light:{spacing:`0.25rem`,radius:`0.65rem`,background:`oklch(1 0 0)`,foreground:`oklch(0.145 0 0)`,card:`oklch(1 0 0)`,"card-foreground":`oklch(0.145 0 0)`,popover:`oklch(1 0 0)`,"popover-foreground":`oklch(0.145 0 0)`,muted:`oklch(0.97 0 0)`,"muted-foreground":`oklch(0.556 0 0)`,accent:`oklch(0.97 0 0)`,"accent-foreground":`oklch(0.205 0 0)`,border:`oklch(0.922 0 0)`,input:`oklch(0.922 0 0)`,ring:`oklch(0.708 0 0)`,"chart-1":`oklch(0.646 0.222 41.116)`,"chart-2":`oklch(0.6 0.118 184.704)`,"chart-3":`oklch(0.398 0.07 227.392)`,"chart-4":`oklch(0.828 0.189 84.429)`,"chart-5":`oklch(0.769 0.188 70.08)`,sidebar:`oklch(0.985 0 0)`,"sidebar-foreground":`oklch(0.145 0 0)`,"sidebar-primary":`oklch(0.205 0 0)`,"sidebar-primary-foreground":`oklch(0.985 0 0)`,"sidebar-accent":`oklch(0.97 0 0)`,"sidebar-accent-foreground":`oklch(0.205 0 0)`,"sidebar-border":`oklch(0.922 0 0)`,"sidebar-ring":`oklch(0.708 0 0)`,primary:`oklch(70% 0.1435 227.76)`,"primary-foreground":`oklch(0.985 0 0)`,secondary:`oklch(0.97 0 0)`,"secondary-foreground":`oklch(0.205 0 0)`,danger:`oklch(0.577 0.245 27.325)`,"danger-foreground":`oklch(0.985 0 0)`,success:`oklch(0.728 0.125 139.6)`,"success-foreground":`oklch(0.985 0 0)`,warning:`oklch(0.784 0.181 44.7)`,"warning-foreground":`oklch(0.985 0 0)`,inverted:`oklch(0.205 0 0)`,"inverted-foreground":`oklch(0.97 0 0)`,focus:`oklch(0.7 0.181 44.7)`,"focus-size":`2.5px`,"focus-offset":`2px`,table:`oklch(0.94 0 0 / 65%)`,"table-content":`oklch(1 0 0)`,"table-hover":`oklch(0.98 0 0 / 10%)`},dark:{background:`oklch(0.145 0 0)`,foreground:`oklch(0.985 0 0)`,card:`oklch(0.205 0 0)`,"card-foreground":`oklch(0.985 0 0)`,popover:`oklch(0.205 0 0)`,"popover-foreground":`oklch(0.985 0 0)`,secondary:`oklch(0.269 0 0)`,"secondary-foreground":`oklch(0.985 0 0)`,muted:`oklch(0.269 0 0)`,"muted-foreground":`oklch(0.708 0 0)`,accent:`oklch(0.269 0 0)`,"accent-foreground":`oklch(0.985 0 0)`,border:`oklch(1 0 0 / 10%)`,input:`oklch(1 0 0 / 15%)`,ring:`oklch(0.556 0 0)`,"chart-1":`oklch(0.488 0.243 264.376)`,"chart-2":`oklch(0.696 0.17 162.48)`,"chart-3":`oklch(0.769 0.188 70.08)`,"chart-4":`oklch(0.627 0.265 303.9)`,"chart-5":`oklch(0.645 0.246 16.439)`,sidebar:`oklch(0.205 0 0)`,"sidebar-foreground":`oklch(0.985 0 0)`,"sidebar-primary":`oklch(0.488 0.243 264.376)`,"sidebar-primary-foreground":`oklch(0.985 0 0)`,"sidebar-accent":`oklch(0.269 0 0)`,"sidebar-accent-foreground":`oklch(0.985 0 0)`,"sidebar-border":`oklch(1 0 0 / 10%)`,"sidebar-ring":`oklch(0.556 0 0)`,primary:`oklch(66% 0.1435 227.76)`,"primary-foreground":`oklch(0.985 0 0)`,danger:`oklch(0.704 0.191 22.216)`,"danger-foreground":`oklch(0.985 0 0)`,success:`oklch(0.728 0.125 139.6)`,"success-foreground":`oklch(0.985 0 0)`,warning:`oklch(0.784 0.181 44.7)`,"warning-foreground":`oklch(0.985 0 0)`,inverted:`oklch(0.922 0 0)`,"inverted-foreground":`oklch(0.205 0 0)`,focus:`oklch(0.7 0.181 44.7)`,table:`oklch(0.265 0 0)`,"table-content":`oklch(0.205 0 0)`,"table-hover":`oklch(0.22 0 0)`}},_e=ce;function ve(e){let t=[[`added`,`added`,`added`],[`updated`,`updated`,`updated`],[`kept`,`kept`,`kept`],[`removed`,`removed`,`removed`]].flatMap(([t,n,r])=>{let i=e.filter(e=>e.action===t).length;return i===0?[]:[`${i} ${i===1?n:r}`]});return t.length===0?void 0:`CSS variables: ${t.join(`, `)}.`}const E=`slabui.json`,D={namespace:`@slabui`,url:`https://slabui.com/r`},ye={command:`x-slabui-command`,optOut:`x-slabui-telemetry`},be=[`ui`,`component`,`lib`,`hook`,`util`,`style`,`file`,`theme`,`block`,`example`],xe=[`free`,`pro`],O=`SLABUI_TOKEN`,k=[`claude`,`cursor`,`vscode`,`zed`,`codex`];function A(t=process.env,n=process.platform,r=m()){let i=n===`win32`?e.join(t.APPDATA??e.join(r,`AppData/Roaming`),`slabui`):e.join(t.XDG_CONFIG_HOME||e.join(r,`.config`),`slabui`);return e.join(i,`credentials.json`)}async function Se(e=A()){try{let{token:t}=JSON.parse(await s(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function Ce(t,n=A()){await o(e.dirname(n),{recursive:!0}),await u(n,`${JSON.stringify({token:t})}\n`,{mode:384})}async function we(e=A()){let t=await Se(e)!==void 0;return await l(e,{force:!0}),t}async function Te({registryUrl:e,token:t,fetch:n=globalThis.fetch,headers:r={}}){let i=`${e.replace(/\/+$/,``)}/whoami.json`,a=await n(i,{headers:{...r,authorization:`Bearer ${t.trim()}`},signal:AbortSignal.timeout(15e3)});if(a.status===401)return null;if(!a.ok)throw Error(`Error ${a.status} while fetching ${i}.`);let o=await a.json();return{...o,access:o.access??[]}}function Ee(){return f(24).toString(`base64url`)}function De({registryUrl:e,callback:t,state:n,client:r,host:i=h()}){let a=new URL(`/cli/authorize`,new URL(e).origin);return a.searchParams.set(`callback`,t),a.searchParams.set(`state`,n),a.searchParams.set(`client`,r),a.searchParams.set(`host`,i.replace(/\.local$/,``).slice(0,60)),a.toString()}var j=class extends Error{name=`SlabUIError`};const M=p.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),Oe=p.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),N=p.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),ke=p.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),P=p.enum(be),Ae=p.enum(xe),je=p.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),Me=p.object({registry:p.array(je).default([]),npm:p.array(p.string().min(1)).default([]),npmDev:p.array(p.string().min(1)).default([])}),Ne=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],Pe=[e=>e.files.length>0||e.cssVars!==void 0,{message:`the item needs files or cssVars`,path:[`files`]}],Fe=p.object({path:p.string().min(1),kind:P,target:p.string().min(1).optional()}).refine(...Ne),Ie=p.object({path:p.string().min(1),kind:P,target:p.string().min(1).optional(),content:p.string()}).refine(...Ne),Le=p.record(p.string(),p.string()),Re=p.object({theme:Le.optional(),light:Le.optional(),dark:Le.optional()}),ze={name:M,kind:P,title:p.string().min(1).optional(),description:p.string().min(1),dependencies:Me.prefault({}),cssVars:Re.optional()},Be=p.object({$schema:p.string().optional(),schemaVersion:p.literal(1),...ze,version:N,files:p.array(Ie).default([])}).refine(...Pe);p.object({...ze,categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:Ae.optional(),inferDependencies:p.boolean().optional(),files:p.array(Fe).default([])}).refine(...Pe);const Ve=p.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),He=p.object({hash:ke,path:Ve}),Ue=p.object({kind:P,title:p.string().min(1).optional(),description:p.string().min(1),categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:Ae.optional(),dependencies:Me.prefault({}),tokens:p.array(p.string().min(1)).optional(),latest:N,versions:p.record(N,He)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),We=p.object({$schema:p.string().optional(),schemaVersion:p.literal(2),namespace:Oe.optional(),homepage:p.url().optional(),mcp:p.url().optional(),license:p.url().optional(),items:p.record(M,Ue)});let Ge;function Ke(e){Ge=e}function qe(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function Je(e,t=Ge){let n={"user-agent":`slabui/${T}`};return qe(e)?n[ye.optOut]=`off`:t&&(n[ye.command]=t),n}const Ye=/* @__PURE__ */ new Map;function Xe(e){return Ye.get(e)}function F(e,{fetch:t=globalThis.fetch,env:n=process.env,command:r,savedToken:i=()=>Se()}={}){let a=e.url.replace(/\/+$/,``),o={...Je(n,r),...Qe(e.headers,n)},s;async function c(t){let r=Object.keys(o).some(e=>e.toLowerCase()===`authorization`);if(!e.isDefault||r)return{};let a=(e.token===void 0?void 0:$e(e.token,`"token" in slabui.json`,n))||n.SLABUI_TOKEN||await i();if(!a)throw new j(`"${t}" is a Pro item. Run "slabui login" or set ${O} to install it.`);return{authorization:`Bearer ${a}`}}async function l(n,{extraHeaders:r={},pro:i}={}){let a;try{a=await t(n,{headers:{...o,...r},signal:AbortSignal.timeout(3e4)})}catch{throw new j(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new j(`The token was refused while fetching the Pro item "${i}". Run "slabui login" again or check ${O}.`);if(i!==void 0&&e.isDefault&&a.status===403)throw new j(`Your token does not give access to the Pro item "${i}". Check your SlabUI Pro subscription.`);if(a.status===401||a.status===403)throw new j(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new j(`Not found: ${n}.`);if(!a.ok)throw new j(`Error ${a.status} while fetching ${n}.`);return new Uint8Array(await a.arrayBuffer())}function u(e,t,n,r){let i;try{i=JSON.parse(new TextDecoder().decode(t))}catch{throw new j(`${e} is not valid JSON.`)}r?.(e,i);let a=n.safeParse(i);if(!a.success)throw new j(`${e} does not match the expected format:\n${p.prettifyError(a.error)}`);return a.data}async function d(){let t=`${a}/registry.json`,n=u(t,await l(t),We,Ze);return Ye.set(e.namespace,n),n}function f(){return s??=d().catch(e=>{throw s=void 0,e}),s}return{index:f,async item(t,n){let r=(await f()).items[t];if(r===void 0)throw new j(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new j(`Version ${n} of "${t}" does not exist in the "${e.namespace}" registry.`);let o=`${a}/${i.path}`,s=r.access===`pro`?await l(o,{extraHeaders:await c(t),pro:t}):await l(o);if(et(s)!==i.hash)throw new j(`${o} does not match the hash in the index. The file may have been changed on the server.`);let d=u(o,s,Be);if(d.name!==t||d.version!==n)throw new j(`${o} contains ${d.name}@${d.version}, not ${t}@${n}.`);return d}}}function Ze(e,t,n=`The registry needs to be published again in the current format.`){let r=t&&typeof t==`object`&&`schemaVersion`in t?t.schemaVersion:void 0;if(typeof r==`number`&&r!==2)throw r>2?new j(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new j(`${e} uses format ${r}, which is no longer supported. ${n}`)}function Qe(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,$e(n,`the "${e}" header`,t)]))}function $e(e,t,n){return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,r)=>{let i=n[r];if(i===void 0)throw new j(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function et(e){return`sha256-${d(`sha256`).update(e).digest(`base64`)}`}async function I(t,n){let r=e=>new j(`Path "${n}" refused: ${e}.`);if(n===``)throw r(`it is empty`);if(n.includes(`\0`))throw r(`it contains a null character`);if(n.includes(`\\`))throw r(`use / as the separator`);if(e.posix.isAbsolute(n)||e.win32.isAbsolute(n))throw r(`it is absolute`);let i=e.resolve(t),o=e.resolve(i,n);if(o===i)throw r(`it points to the project root`);if(!tt(i,o))throw r(`it leaves the project root`);let s=await nt(o);if(s===o&&(await a(o)).isSymbolicLink())throw r(`the target is a symbolic link`);let l=await c(i),u=await c(s).catch(()=>{throw r(`it goes through a broken symbolic link`)});if(!tt(l,u))throw r(`it goes through a symbolic link outside the project`);return e.join(u,e.relative(s,o))}function tt(t,n){let r=e.relative(t,n);return r===``||r!==`..`&&!r.startsWith(`..${e.sep}`)&&!e.isAbsolute(r)}async function nt(t){let n=t;for(;;)try{return await a(n),n}catch(t){if(t.code!==`ENOENT`)throw t;n=e.dirname(n)}}const rt=p.object({version:N,files:p.array(p.string().min(1))}),it=p.object({$schema:p.string().optional(),token:p.string().min(1).optional(),css:p.string().min(1).optional(),aliases:p.object({components:p.string().min(1),ui:p.string().min(1),lib:p.string().min(1),hooks:p.string().min(1),utils:p.string().min(1),styles:p.string().min(1)}),items:p.record(M,rt).default({})}),at=[`tsconfig.json`,`jsconfig.json`],ot=[`app/globals.css`,`src/app/globals.css`,`styles/globals.css`,`src/styles/globals.css`,`app/global.css`,`src/index.css`,`src/styles.css`];async function L(e){return i(e).then(()=>!0,()=>!1)}async function R(t){for(let n of at){let r=e.join(t,n);if(await L(r))try{return{path:r,config:_(r)}}catch(e){throw new j(`Could not read ${n}: ${e.message}`)}}throw new j(`No tsconfig.json or jsconfig.json in ${t}. slabui uses its "paths" to resolve the aliases.`)}function z(e){let t=Object.keys(e.config.compilerOptions?.paths??{}).filter(e=>e.endsWith(`/*`));return(t.find(e=>e===`@/*`)??t.find(e=>e===`~/*`)??t[0])?.slice(0,-1)}function B(t,n,r){if(r===void 0)return;let i=z(t),a=i!==void 0&&r.startsWith(i)?V(t,r):void 0;return a===void 0?r:e.relative(n,a).split(e.sep).join(`/`)}function V(e,t){return g(e)?.(t)[0]}async function st(t){for(let n of ot)if(await L(e.join(t,n)))return n}async function H(t){let n=e.join(t,E),r=await s(n,`utf8`).catch(()=>void 0);if(r===void 0)throw new j(`${E} not found in ${t}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new j(`${E} is not valid JSON.`)}let a=it.safeParse(i);if(!a.success)throw new j(`${E} has errors:\n${p.prettifyError(a.error)}`);return a.data}async function ct(t,n){await u(e.join(t,E),`${JSON.stringify(n,null,2)}\n`)}function lt(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function ut(t){return await L(e.join(t,`src`))?`src`:`.`}async function dt(t,{folder:n}={}){let{path:r}=await R(t),i=e.resolve(t,n??await ut(t)),a=[r],o=[],c=b(await s(r,`utf8`)).references??[];for(let t of c){let n=e.resolve(e.dirname(r),t.path),i=n.endsWith(`.json`)?n:e.join(n,`tsconfig.json`);/app/.test(e.basename(i))&&await L(i)&&a.push(i)}for(let t of a){let n=await s(t,`utf8`),r=b(n);if(r.compilerOptions?.paths)continue;let a=e.resolve(e.dirname(t),r.compilerOptions?.baseUrl??`.`),c=e.relative(a,i).split(e.sep).join(`/`),l=c?`./${c}/*`:`./*`,d=n.match(/\n( +|\t)"/)?.[1]??` `,f=y(n,[`compilerOptions`,`paths`,`@/*`],[l],{formattingOptions:{insertSpaces:!d.startsWith(` `),tabSize:d.startsWith(` `)?1:d.length}});await u(t,v(n,f)),o.push(t)}return o}const U=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.cts`,`.mjs`],ft=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,pt=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function mt(t){return e.posix.extname(t)===`.css`}function ht(e,t){return e.replace(pt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function gt(t){return U.includes(e.posix.extname(t))}function _t(e,t){return e.replace(ft,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function vt(e,t){return[e,...U.map(t=>`${e}${t}`),...U.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function yt(t){let n=e.posix.extname(t);return U.includes(n)?t.slice(0,-n.length):t}function W(e){let t=e;if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)throw new j(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==D.namespace)throw new j(`"${e}" is not from the SlabUI registry. Only SlabUI items can be installed.`);t=t.slice(n+1)}let n=t.indexOf(`@`),r=n===-1?t:t.slice(0,n),i=n===-1?void 0:t.slice(n+1);if(!M.safeParse(r).success)throw new j(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||x.validRange(i)===null))throw new j(`"${i}" is not a valid version or range.`);return{name:r,...i!==void 0&&{range:i}}}function G(e){return e.name}function K(e,t=process.env){return{namespace:D.namespace,url:t.SLABUI_REGISTRY_URL||D.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function bt(e,t){if(e.range===void 0)return t.latest;let n=Object.keys(t.versions),r=x.maxSatisfying(n,e.range);if(r===null)throw new j(`No version of "${G(e)}" satisfies "${e.range}". Available: ${x.sort(n).join(`, `)}.`);return r}const xt={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function St(t,n){if(t.target!==void 0){let r=t.target;return wt((r.startsWith(z(n.tsconfig)??`\0`)?V(n.tsconfig,r):void 0)??e.resolve(n.root,r),n)}if(!(t.kind in xt))throw new j(`Files with kind "${t.kind}" cannot be installed by add yet (${t.path}).`);let r=n.aliases[xt[t.kind]],i=t.kind===`style`&&t.path.split(`/`).slice(1).join(`/`)||e.posix.basename(t.path),a=lt(r)?e.resolve(n.root,r,i):V(n.tsconfig,`${r}/${i}`);if(a===void 0)throw new j(`Alias "${r}" does not match any "paths" in the tsconfig.`);return wt(a,n)}function Ct(t,n,r){let i=z(r.tsconfig),a=i===void 0?void 0:V(r.tsconfig,`${i}__slabui__`)?.slice(0,-10),o=e.resolve(r.root,t);if(i!==void 0&&a!==void 0&&o.startsWith(a))return`${i}${yt(e.relative(a,o).split(e.sep).join(`/`))}`;let s=e.posix.relative(e.posix.dirname(n),t);return s.startsWith(`.`)||(s=`./${s}`),yt(s)}function wt(t,n){return e.relative(n.root,t).split(e.sep).join(`/`)}function q(e){return e.kind===`block`||e.kind===`example`}function Tt(e,t,n){return q(e)?At(e,n):new Map(e.files.map(e=>[e.path,St(e,t)]))}function Et(e,t){return[e,...t.dependencies.registry.map(e=>G(W(e)))]}async function Dt(e,{config:t,context:n,destinations:r,clientFor:i}){for(let a of e)for(let e of a.dependencies.registry){let a=W(e),o=G(a),s=t.items[o];if(r.has(o)||s===void 0)continue;let c=i(K(t.token));r.set(o,Tt(await c.item(a.name,s.version),n))}}function Ot(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=mt(e.path);if(!gt(e.path)&&!s)return e.content;let c=Et(t,n),l=e=>{if(e===`slabui:css`){if(a.css===void 0){o.push(`"${t}": ${r} uses the global CSS, but "css" is not set in slabui.json.`);return}return kt(a.css,r)}if(!e.startsWith(`@/registry/`))return;let n=e.slice(11);for(let e of c){let t=i.get(e),o=t&&vt(n,new Set(t.keys()));if(o){let e=t.get(o);return s?kt(e,r):Ct(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?ht(e.content,l):_t(e.content,l)}function kt(t,n){let r=e.posix.relative(e.posix.dirname(n),t);return r.startsWith(`.`)?r:`./${r}`}function At(t,n){let r=t.files.map(t=>e.posix.dirname(t.path).split(`/`)),i=[];for(let[e,t]of(r[0]??[]).entries())if(r.every(n=>n[e]===t))i.push(t);else break;let a=i.join(`/`),o=e.posix.normalize(n.split(e.sep).join(`/`));return new Map(t.files.map(t=>[t.path,e.posix.join(o,e.posix.relative(a,t.path))]))}const jt=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function Mt(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?{name:e}:{name:e.slice(0,t),range:e.slice(t+1)||void 0}}async function Nt(t){let n=(await Pt(t))?.packageManager?.split(`@`)[0];if(n&&[`pnpm`,`npm`,`yarn`,`bun`].includes(n))return n;let r=e.resolve(t);for(;;){for(let[t,n]of jt)if(await L(e.join(r,t)))return n;let t=e.dirname(r);if(t===r)return`npm`;r=t}}async function Pt(t){let n=await s(e.join(t,`package.json`),`utf8`).catch(()=>void 0);return n===void 0?void 0:JSON.parse(n)}async function Ft(e,{npm:t,npmDev:n}){let r=await Pt(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=Mt(e),o=i[n];if(o===void 0){t.includes(e)||t.push(e);return}let s=x.minVersion(o);r&&s&&!x.satisfies(s,r)&&a.conflicts.push({spec:e,installed:o})};for(let e of new Set(t))o(e,a.install);for(let e of new Set(n))o(e,a.installDev);return a}function It(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function Lt(e,t,n,r){if(n.length===0)return;let[i,a]=It(t,n,r);await new Promise((t,n)=>{let r=S(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new j(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new j(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function Rt(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await Ft(e,t);for(let{spec:e,installed:t}of a.conflicts)n&&await n(`The project has ${t}, but ${e} is required. Update it?`)?a.install.push(e):i.push(`Kept ${Mt(e).name}@${t}; the item requires ${e}.`);let o=[...a.install,...a.installDev];if(o.length===0)return[];if(r)return i.push(`Packages not installed (--skip-install): ${o.join(` `)}`),[];let s=await Nt(e);return await Lt(e,s,a.install,!1),await Lt(e,s,a.installDev,!0),o}async function zt({refs:e,config:t,createClient:n=e=>F(e)}){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=[],s=/* @__PURE__ */ new Set,c=[];function l(e){let t=r.get(e.namespace);return t===void 0&&(t=n(e),r.set(e.namespace,t)),t}async function u(e,n){let r=G(e),d=i.get(r)??[];d.push({range:e.range,by:n}),i.set(r,d);let f=t.items[r];if(f!==void 0){let e=d.filter(({range:e})=>e&&!x.satisfies(f.version,e));if(e.length===0)s.add(r);else for(let{range:t,by:n}of e)c.push(`"${r}" is installed at ${f.version}, but ${n?`"${n}"`:`the request`} requires ${t}. Run "slabui update ${r}".`);return}let p=a.get(r);if(p&&d.every(({range:e})=>Bt(p,e)))return;let m=K(t.token),h=l(m),g=(await h.index()).items[e.name];if(g===void 0)throw new j(`Item "${e.name}" does not exist in the "${m.namespace}" registry.`);let _=Object.keys(g.versions),v=d.flatMap(({range:e})=>e?[e]:[]),y=v.length===0?g.latest:x.rsort(_.filter(e=>v.every(t=>x.satisfies(e,t))))[0]??null;if(y===null)throw new j(`No version of "${r}" satisfies every request: ${d.map(({range:e,by:t})=>`${e??`latest`} (${t??`requested`})`).join(`, `)}. Available: ${x.sort(_).join(`, `)}.`);let b=await h.item(e.name,y);a.set(r,{key:r,registry:m,item:b});for(let e of b.dependencies.registry)await u(W(e),r);o.includes(r)||o.push(r)}for(let t of e)await u(W(t));return{items:o.map(e=>a.get(e)),installed:[...s],warnings:c}}function Bt(e,t){return t===void 0||x.satisfies(e.item.version,t)}const Vt=ge;async function Ht(t,n){let r=await I(t,n),i=await s(r,`utf8`).catch(()=>void 0),a=await _e(i??`@import "tailwindcss";
|
|
10
|
+
|
|
11
|
+
@layer base {
|
|
12
|
+
* {
|
|
13
|
+
@apply border-border outline-ring/50;
|
|
14
|
+
}
|
|
15
|
+
body {
|
|
16
|
+
@apply bg-background text-foreground;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`,Vt);return(i===void 0||a.css!==i)&&(await o(e.dirname(r),{recursive:!0}),await u(r,a.css)),{created:i===void 0,changes:a.changes}}async function Ut(e,t,n,r,i){if(t===void 0)return i.warnings.push(`"${n}": has CSS variables, but "css" is not set in slabui.json; add them to your CSS manually.`),[];let a=await I(e,t),o=await s(a,`utf8`).catch(()=>void 0);o===void 0&&(await Ht(e,t),i.warnings.push(`${t} did not exist; it was created with the default template.`),o=await s(a,`utf8`));let c=await _e(o,r,i);return i.warnings.push(...c.warnings.map(e=>`"${n}": ${e}`)),c.css!==o&&await u(a,c.css),c.changes}async function Wt({root:t,refs:n,overwrite:r=!1,skipInstall:i=!1,confirm:a,path:s,askPath:c,createClient:l=e=>F(e)}){let d=await H(t),f=await R(t),p={root:t,aliases:d.aliases,tsconfig:f,css:B(f,t,d.css)},m=/* @__PURE__ */ new Map,h=e=>{let t=m.get(e.namespace);return t===void 0&&(t=l(e),m.set(e.namespace,t)),t},g=Object.keys(d.items).length===0,_=await zt({refs:n,config:d,createClient:h}),v=[..._.warnings],y=_.items.filter(({item:e})=>q(e)),b=s;if(y.length>0&&b===void 0){let e=y.map(({key:e})=>e);if(c===void 0)throw new j(`${e.map(e=>`"${e}"`).join(`, `)} ${e.length>1?`are blocks or examples`:`is a block or example`}: pass the folder with --path.`);b=await c(e)}let x=/* @__PURE__ */ new Map;for(let{key:e,item:t}of _.items)x.set(e,Tt(t,p,b));await Dt(_.items.map(({item:e})=>e),{config:d,context:p,destinations:x,clientFor:h});let S=/* @__PURE__ */ new Map;for(let[e,t]of Object.entries(d.items))for(let n of t.files)S.set(n,e);let C=[];for(let{key:n}of _.items)for(let r of x.get(n)?.values()??[])if(await I(t,r),await L(e.join(t,r))){let e=S.get(r);C.push(e?`${r} (from "${e}")`:r)}if(C.length>0&&!r){let e=C.map(e=>` ${e}`).join(`
|
|
20
|
+
`);if(!(a&&await a(`These files already exist and will be overwritten:\n${e}\nContinue?`)))throw new j(`These files already exist in the project:\n${e}\nUse --overwrite to overwrite them.`)}let ee=[],w=[];for(let{key:n,item:i}of _.items){let a=x.get(n);for(let r of i.files){let s=a.get(r.path),c=Ot(r,{key:n,item:i,destination:s,destinations:x,context:p,warnings:v}),l=await I(t,s);await o(e.dirname(l),{recursive:!0}),await u(l,c)}i.cssVars!==void 0&&w.push(...await Ut(t,p.css,n,i.cssVars,{overwrite:r,warnings:v}));let s=[...a.values()];q(i)||(d.items[n]={version:i.version,files:s}),ee.push({key:n,version:i.version,files:s,block:q(i)})}await ct(t,d);let te=await Rt(t,{npm:_.items.flatMap(({item:e})=>e.dependencies.npm),npmDev:_.items.flatMap(({item:e})=>e.dependencies.npmDev)},{confirm:a,skipInstall:i,warnings:v}),ne=[],T=_.items[0]?.registry;if(g&&T!==void 0){let e=(await h(T).index()).license;e!==void 0&&ne.push({namespace:T.namespace,url:e})}return{added:ee,installed:_.installed,packages:te,cssChanges:w,licenses:ne,warnings:v}}function J(e){return!e&&!!(process.stdin.isTTY&&process.stdout.isTTY)}function Y(e){if(C.isCancel(e))throw C.cancel(`Cancelled.`),new j(`Operation cancelled.`);return e}async function X(e,t=``){return Y(await C.text({message:e,initialValue:t}))}async function Z(e,t=!0){return Y(await C.confirm({message:e,initialValue:t}))}async function Gt(e,t){return Y(await C.select({message:e,options:t}))}async function Kt(e,t,n=[]){return Y(await C.multiselect({message:e,options:t,initialValues:n,required:!0}))}const qt=new t(`add`).description(`Installs items and their dependencies (default: latest version)`).argument(`<items...>`,`e.g. button, button@1.1.0, @acme/table`).option(`-y, --yes`,`never prompt; fail instead of overwriting`).option(`-o, --overwrite`,`overwrite existing files`).option(`--skip-install`,`skip installing npm packages`).option(`--path <dir>`,`folder for blocks and examples`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let r=J(n.yes),i=await Wt({root:e.resolve(n.cwd),refs:t,overwrite:n.overwrite,skipInstall:n.skipInstall,path:n.path,confirm:r?Z:void 0,askPath:r?e=>X(`Where should ${e.join(`, `)} be installed? (relative to the project root)`,`components`):void 0});for(let{key:e,version:t,files:n,block:r}of i.added){console.log(`+ ${e}@${t}${r?` (copied, not tracked in items)`:``}`);for(let e of n)console.log(` ${e}`)}for(let e of i.installed)console.log(`= ${e} (already installed)`);i.packages.length>0&&console.log(`Installed packages: ${i.packages.join(` `)}`);let a=ve(i.cssChanges);a&&console.log(a);for(let{namespace:e,url:t}of i.licenses)console.log(`Items from ${e} are licensed under ${t}`);for(let e of i.warnings)console.warn(`warning: ${e}`)});function Jt(e,t,n,r=!1){if(n.range!==void 0)return{version:bt(n,e)};if(r)return{version:e.latest};let i=bt({...n,range:`${x.major(t)}.x`},{...e,versions:{...e.versions,[t]:{hash:``,path:``}}}),a=x.gt(t,i)?t:i;return{version:a,newerMajor:x.major(e.latest)>x.major(a)?e.latest:void 0}}async function Yt({key:t,version:n,major:r,config:i,context:a,clientFor:o}){let c=W(n?`${t}@${n}`:t),l=c.name,u=i.items[l];if(u===void 0)throw new j(`"${l}" is not installed. Blocks and examples are not updated; for other items, use "slabui add ${l}".`);let d=K(i.token),f=o(d),p=(await f.index()).items[c.name];if(p===void 0)throw new j(`Item "${c.name}" no longer exists in the "${d.namespace}" registry.`);let m=Jt(p,u.version,c,r),h=await f.item(c.name,u.version),g=m.version===u.version?h:await f.item(c.name,m.version),_=[],v=async e=>{let t=/* @__PURE__ */ new Map([[l,Tt(e,a)]]);await Dt([e],{config:i,context:a,destinations:t,clientFor:o});let n=t.get(l);return new Map(e.files.map(r=>{let i=n.get(r.path);return[i,Xt(Ot(r,{key:l,item:e,destination:i,destinations:t,context:a,warnings:_}))]}))},y=await v(h),b=await v(g),x=[.../* @__PURE__ */ new Set([...y.keys(),...b.keys()])];return{key:l,registry:d,base:h,remote:g,files:await Promise.all(x.map(async t=>{let n=await s(e.join(a.root,t),`utf8`).then(Xt).catch(()=>void 0);return{destination:t,base:y.get(t),remote:b.get(t),local:n}})),newerMajor:m.newerMajor,warnings:_}}function Xt(e){return e.replace(/\r\n/g,`
|
|
21
|
+
`)}async function Zt({root:e,ref:t,local:n=!1,major:r,createClient:i=e=>F(e)}){let a=await H(e),o=await R(e),s={root:e,aliases:a.aliases,tsconfig:o,css:B(o,e,a.css)},[c,l]=Qt(t),u=await Yt({key:c,version:l,major:r,config:a,context:s,clientFor:i}),d=n?`base`:`local`,f=n?`local`:`remote`,p=u.files.flatMap(e=>{let t=e[d]??``,r=e[f]??``;return t===r?[]:[ee(`a/${e.destination}`,`b/${e.destination}`,t,r,n?u.base.version:`local`,n?`local`:u.remote.version)]});return{comparison:u,patches:p,changed:p.length>0}}function Qt(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?[e,void 0]:[e.slice(0,t),e.slice(t+1)]}const $t=new t(`diff`).description(`Shows the difference between the local and the remote version`).argument(`<item>`,`installed item (optional version: button@2)`).option(`--local`,`show only what changed in the project (base → local)`).option(`--major`,`compare with the latest version, even in another major`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let{comparison:r,patches:i,changed:a}=await Zt({root:e.resolve(n.cwd),ref:t,local:n.local,major:n.major}),{key:o,base:s,remote:c,newerMajor:l}=r;for(let e of r.warnings)console.warn(`warning: ${e}`);a||console.log(n.local?`${o}: no local changes since ${s.version}.`:`${o}: local matches ${c.version}.`);for(let e of i)process.stdout.write(e);l&&!n.local&&console.log(`\n${o}@${l} is available (new major): slabui diff ${o} --major`),a&&(process.exitCode=1)});function en(e,t,{type:n}={}){let r=/* @__PURE__ */ new Map,i=new w({fields:[`name`,`title`,`description`,`categories`,`keywords`,`kind`],searchOptions:{boost:{name:4,title:3,keywords:2,categories:1.5},fuzzy:.2,prefix:!0,combineWith:`AND`}});for(let{namespace:t,isDefault:a,index:o}of e)for(let[e,s]of Object.entries(o.items)){if(n!==void 0&&s.kind!==n)continue;let o=a?e:`${t}/${e}`;r.set(o,{key:o,name:e,namespace:t,entry:s}),i.add({id:o,name:`${e} ${e.replaceAll(`-`,` `)}`,title:s.title??``,description:s.description,categories:(s.categories??[]).join(` `),keywords:(s.keywords??[]).join(` `),kind:s.kind})}return i.search(t).map(({id:e,score:t})=>({...r.get(e),score:t}))}const tn=e=>F(e);async function nn(t){return await L(e.join(t,`slabui.json`))?H(t):void 0}async function rn({root:e,term:t,type:n,createClient:r=tn}){let i=K((await nn(e))?.token);try{let e=await r(i).index();return{results:en([{namespace:i.namespace,isDefault:!0,index:e}],t,{type:n}),warnings:[]}}catch(e){return{results:[],warnings:[`"${i.namespace}": ${e.message}`]}}}async function an({root:e,ref:t,createClient:n=tn}){let r=await nn(e),i=W(t),a=K(r?.token),o=n(a),s=(await o.index()).items[i.name];if(s===void 0)throw new j(`Item "${i.name}" does not exist in the "${a.namespace}" registry.`);let c=await o.item(i.name,bt(i,s)),l=G(i),u;if(r!==void 0){let t={root:e,aliases:r.aliases,tsconfig:await R(e)};u=c.files.map(e=>{try{return St(e,t)}catch{return e.path}})}return{key:l,registry:a,entry:s,item:c,installed:r?.items[l]?.version,destinations:u}}const on=new t(`info`).description(`Shows versions, files and dependencies of an item`).argument(`<item>`,`item name, e.g. button, button@1.1.0, @acme/table`).option(`--json`,`print as JSON`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let r=await an({root:e.resolve(n.cwd),ref:t}),{item:i,entry:a}=r;if(n.json){console.log(JSON.stringify(r,null,2));return}let o=x.rsort(Object.keys(a.versions)).map(e=>[e,e===a.latest?`(latest)`:``,e===r.installed?`(installed)`:``].filter(Boolean).join(` `)),{registry:s,npm:c,npmDev:l}=i.dependencies;console.log(`${r.key}@${i.version} (${i.kind}${a.access===`pro`?`, pro`:``}, ${r.registry.namespace})`),i.title&&console.log(i.title),console.log(i.description),a.docs&&console.log(`Docs: ${a.docs}`),console.log(`\nVersions:\n${o.map(e=>` ${e}`).join(`
|
|
22
|
+
`)}`),r.installed||console.log(`
|
|
23
|
+
Not installed in this project.`),console.log(`
|
|
24
|
+
Files:`),i.files.forEach((e,t)=>{let n=r.destinations?.[t];console.log(` ${e.path}${n?` → ${n}`:``}`)});for(let[e,t]of[[`Registry dependencies`,s],[`npm packages`,c],[`npm dev packages`,l]])t.length>0&&console.log(`\n${e}:\n${t.map(e=>` ${e}`).join(`
|
|
25
|
+
`)}`)});async function sn(e){let t=z(await R(e));if(t===void 0)throw new j(`The tsconfig has no alias in "paths" (e.g. "@/*": ["./*"]). slabui uses it to place files and write imports.`);return{aliases:{components:`${t}components`,ui:`${t}components/ui`,lib:`${t}lib`,hooks:`${t}hooks`,utils:`${t}utils`,styles:`${t}styles`},...await cn(e,`${t}styles`)}}async function cn(e,t){let n=await st(e);return n===void 0?{css:`${t}/globals.css`,cssDetected:!1}:{css:n,cssDetected:!0}}async function ln({root:t,aliases:n,css:r,force:i=!1}){if(!i&&await L(e.join(t,`slabui.json`)))throw new j(`${E} already exists. Use --force to create it again.`);let a=await R(t);for(let[e,t]of Object.entries(n))if(!lt(t)&&V(a,t)===void 0)throw new j(`Alias "${t}" (${e}) does not match any "paths" in the tsconfig.`);let o={$schema:`https://slabui.com/schema.json`,...r&&{css:r},aliases:n,items:{}};return await ct(t,o),o}const un=new t(`init`).description(`Creates ${E} at the project root`).option(`-y, --yes`,`use the detected values without prompting`).option(`-f, --force`,`overwrite an existing ${E}`).option(`--no-template`,`do not create or complete the global CSS with the default template`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async t=>{let n=e.resolve(t.cwd),r=J(t.yes);if(r&&C.intro(`slabui init`),z(await R(n))===void 0){if(r&&!await Z(`The tsconfig has no alias in "paths". Create "@/*" (used for file locations and imports)?`)){C.cancel(`Nothing was created. Add an alias to "paths" (e.g. "@/*": ["./src/*"]) and run init again.`);return}let t=await ut(n),i=[{value:`src`,label:`./src (@/components → src/components)`},{value:`.`,label:`./ (@/components → components)`}],a=await dt(n,{folder:r?await Gt(`Where should "@/*" point?`,[...i.filter(({value:e})=>e===t),...i.filter(({value:e})=>e!==t)]):t});for(let t of a)console.log(`${e.relative(n,t)}: added "@/*" to "paths".`);await dn(n)&&console.log('Vite does not read "paths" by default: add `resolve: { tsconfigPaths: true }` to vite.config (or the vite-tsconfig-paths plugin).')}let i=await sn(n),{aliases:a,css:o}=i,s=t.template;r&&(a={components:await X(`Components alias`,a.components),ui:await X(`UI components alias`,a.ui),lib:await X(`Lib alias`,a.lib),hooks:await X(`Hooks alias`,a.hooks),utils:await X(`Utils alias`,a.utils),styles:await X(`Styles alias`,a.styles)},o=await X(`Global CSS file (empty if none)`,i.cssDetected?i.css:(await cn(n,a.styles)).css)||void 0,o&&s&&(s=await Z(`Add the default theme to ${o}? (creates the file if needed)`))),await ln({root:n,aliases:a,css:o,force:t.force}),console.log(`${E} created in ${n}.`);let c=B(await R(n),n,o);if(c&&s){let{created:e,changes:t}=await Ht(n,c),r=t.filter(({action:e})=>e===`added`).length;console.log(e?`${c}: created with the default template.`:`${c}: default template applied (${r} variables added).`)}});async function dn(t){for(let n of[`ts`,`mts`,`js`,`mjs`,`cjs`])if(await L(e.join(t,`vite.config.${n}`)))return!0;return!1}async function fn({token:e,fetch:t=globalThis.fetch,env:n=process.env,file:r=A(n)}){let i=K(void 0,n),a;try{a=await Te({registryUrl:i.url,token:e,fetch:t,headers:Je(n,`login`)})}catch(e){throw e instanceof Error&&e.message.startsWith(`Error 404`)?new j(`${i.url} does not support login.`):new j(e instanceof Error&&e.message.startsWith(`Error `)?e.message:`Could not reach ${i.url}.`)}if(a===null)throw new j(`Invalid token. Check it and try again.`);return await Ce(e.trim(),r),{account:a,url:i.url,file:r}}async function pn({root:e,onUrl:t,timeout:n=3e5,...r}){let i=K(void 0,r.env),a=Ee();return fn({root:e,token:await new Promise((e,r)=>{let o=te((t,n)=>{let i=new URL(t.url??`/`,`http://127.0.0.1`);if(i.pathname!==`/callback`||i.searchParams.get(`state`)!==a){n.writeHead(404).end();return}let o=i.searchParams.get(`token`);n.writeHead(200,{"content-type":`text/html; charset=utf-8`}),n.end(hn(o?`Signed in. You can close this tab and go back to the terminal.`:`Sign-in cancelled. You can close this tab.`)),c(()=>o?e(o):r(new j(`Sign-in was cancelled in the browser.`)))}),s=setTimeout(()=>c(()=>r(new j(`Timed out waiting for the browser sign-in.`))),n);function c(e){clearTimeout(s),o.close(),e()}o.once(`error`,r),o.listen(0,`127.0.0.1`,()=>{let{port:e}=o.address();t(De({registryUrl:i.url,callback:`http://127.0.0.1:${e}/callback`,state:a,client:`SlabUI CLI`}))})}),...r})}function mn(e){let[t,n]=process.platform===`darwin`?[`open`,[e]]:process.platform===`win32`?[`cmd`,[`/c`,`start`,``,e]]:[`xdg-open`,[e]];try{S(t,n,{stdio:`ignore`,detached:!0}).on(`error`,()=>{}).unref()}catch{}}function hn(e){return`<!doctype html><meta charset="utf-8"><title>SlabUI</title><body style="font:16px system-ui;display:grid;place-items:center;height:100vh;margin:0"><p>${e}</p></body>`}const gn=new t(`login`).description(`Signs in to your SlabUI account in the browser (or saves a --token)`).option(`--token <token>`,`save this token instead of using the browser`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async t=>{let n=e.resolve(t.cwd);if(t.token===void 0&&!process.stdout.isTTY)throw new j(`Pass the token with --token or set ${O}.`);let{account:r,url:i,file:a}=t.token===void 0?await pn({root:n,onUrl:e=>{console.log(`Opening the browser to sign in. If it does not open, visit:\n ${e}\n`),mn(e)}}):await fn({root:n,token:t.token}),o=r.name?` as ${r.name}`:``,s=r.access.includes(`pro`)?`Pro`:`Free`;console.log(`Logged in to ${i}${o} (${r.plan??s}).`),s===`Free`&&console.log(`Pro items need a subscription: https://slabui.com/pricing`),console.log(`Token saved in ${a}`)}),_n=new t(`logout`).description(`Removes the token saved by slabui login`).action(async()=>{console.log(await we()?`Logged out.`:`No token was saved; nothing to do.`)}),vn=`Bearer \${${O}}`;function yn(e){return Object.keys(e).some(e=>e.toLowerCase()===`authorization`)?e:{...e,Authorization:vn}}const bn={claude:`.mcp.json`,cursor:`.cursor/mcp.json`,vscode:`.vscode/mcp.json`,zed:`.zed/settings.json`},xn=[[`.mcp.json`,`claude`],[`.claude`,`claude`],[`.cursor`,`cursor`],[`.vscode`,`vscode`],[`.zed`,`zed`],[`.codex`,`codex`]];function Sn(e){let t=[];for(let n of e.flatMap(e=>e.split(`,`))){let e=n.trim();if(e!==``){if(!k.includes(e))throw new j(`Unknown client "${e}" (${k.join(`, `)}).`);t.includes(e)||t.push(e)}}return t}async function Cn(t){let n=[];for(let[r,i]of xn)!n.includes(i)&&await L(e.join(t,r))&&n.push(i);return n}async function wn({root:e,url:t,createClient:n=e=>F(e)}){let r=K((await H(e)).token),i=r.namespace.slice(1),a=yn(r.headers);if(t!==void 0)return{servers:[{name:i,url:t,headers:a}],warnings:[]};try{let e=(await n(r).index()).mcp;return e===void 0?{servers:[],warnings:[`The "${r.namespace}" registry has no MCP server.`]}:{servers:[{name:i,url:e,headers:a}],warnings:[]}}catch(e){return{servers:[],warnings:[`"${r.namespace}": ${e.message}`]}}}async function Tn(t,n,r){if(n===`zed`)return On(t,r);if(n===`codex`)return{snippet:kn(r)};let i=bn[n],a=e.join(t,i),c=await s(a,`utf8`).catch(()=>void 0),l={};if(c!==void 0&&c.trim()!==``)try{l=JSON.parse(c)}catch{throw new j(`${i} is not valid JSON; fix it before running mcp init.`)}let d=n===`vscode`?`servers`:`mcpServers`,f=l[d]??{};for(let e of r)f[e.name]=En(n,e);return l[d]=f,await o(e.dirname(a),{recursive:!0}),await u(a,`${JSON.stringify(l,null,2)}\n`),{file:i}}function En(e,{url:t,headers:n}){let r=Dn(n,e===`claude`?"${$1}":"${env:$1}",e);return{...e!==`cursor`&&{type:`http`},url:t,...Object.keys(r).length>0&&{headers:r}}}function Dn(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e,r===vn&&n===`claude`?`Bearer \${${O}:-}`:r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,t)]))}async function On(t,n){let r=bn.zed,i=e.join(t,r),a=await s(i,`utf8`).catch(()=>``)||`{}
|
|
26
|
+
`,c=[],l=b(a,c,{allowTrailingComma:!0});if(c.length>0||typeof l!=`object`||!l||Array.isArray(l))throw new j(`${r} is not valid JSON; fix it before running mcp init.`);let d=[];for(let e of n){let{name:t,url:n}=e,i=Object.fromEntries(Object.entries(e.headers).filter(([,e])=>e!==vn));Object.keys(i).length<Object.keys(e.headers).length&&d.push(`${r}: to read Pro items in "${t}", add the header "Authorization": "Bearer <your token>".`);let o={url:n,...Object.keys(i).length>0&&{headers:i}};a=v(a,y(a,[`context_servers`,t],o,{formattingOptions:{insertSpaces:!0,tabSize:2}})),Object.values(i).some(e=>/\$\{\w+\}/.test(e))&&d.push(`${r}: replace the \${VAR} values in the headers of "${t}" with the real values.`)}return await o(e.dirname(i),{recursive:!0}),await u(i,a.endsWith(`
|
|
27
|
+
`)?a:`${a}\n`),{file:r,warnings:d}}function kn(e){return e.map(({name:e,url:t,headers:n})=>{let r=[`[mcp_servers.${e}]`,`url = ${JSON.stringify(t)}`],i=[],a=[];for(let[e,t]of Object.entries(n)){let n=/^Bearer \$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(t),o=/^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(t);e.toLowerCase()===`authorization`&&n?r.push(`bearer_token_env_var = ${JSON.stringify(n[1])}`):o?a.push(`${JSON.stringify(e)} = ${JSON.stringify(o[1])}`):i.push(`${JSON.stringify(e)} = ${JSON.stringify(t)}`)}return i.length>0&&r.push(`http_headers = { ${i.join(`, `)} }`),a.length>0&&r.push(`env_http_headers = { ${a.join(`, `)} }`),r.join(`
|
|
28
|
+
`)}).join(`
|
|
29
|
+
|
|
30
|
+
`).replace(/^/,`# In ~/.codex/config.toml (or .codex/config.toml in a trusted project):
|
|
31
|
+
`)}const Q={claude:`CLAUDE.md`,cursor:`.cursor/rules/slabui.mdc`,vscode:`.github/copilot-instructions.md`,zed:`AGENTS.md`,codex:`AGENTS.md`},An=`<!-- slabui:start -->`,jn=`<!-- slabui:end -->`;function Mn(e){return Q[e]}function Nn(e){let t=/* @__PURE__ */ new Set;return e.filter(e=>!t.has(Q[e])&&(t.add(Q[e]),!0))}function Pn(e){return`## UI registry (slabui)
|
|
32
|
+
|
|
33
|
+
UI components, blocks and examples in this project come from the versioned
|
|
34
|
+
SlabUI registry, managed by the \`slabui\` CLI. The installed items and their
|
|
35
|
+
versions are listed under \`items\` in \`slabui.json\`.
|
|
36
|
+
|
|
37
|
+
${e.map(({name:e,url:t})=>`MCP server: \`${e}\` (${t}).`).join(`
|
|
38
|
+
`)}
|
|
39
|
+
|
|
40
|
+
- Before writing a component from scratch, search the registry with
|
|
41
|
+
\`slabui search <query>\` or the \`search_items\` MCP tool.
|
|
42
|
+
- Install with \`slabui add <item>\` (blocks and examples need \`--path <dir>\`).
|
|
43
|
+
Never copy an item's code by hand: \`slabui add\` also installs its
|
|
44
|
+
dependencies, rewrites imports to the project's aliases and records the
|
|
45
|
+
version.
|
|
46
|
+
- Installed files can be edited. To move to a newer version, run
|
|
47
|
+
\`slabui diff <item>\` to see what changed and \`slabui update <item>\`, which
|
|
48
|
+
merges the new version with the local changes (3-way merge). Do not
|
|
49
|
+
overwrite installed files with a newer version by hand.
|
|
50
|
+
- Use \`get_item\` and \`diff_versions\` from the MCP server to read an item's
|
|
51
|
+
code or compare versions without installing it.
|
|
52
|
+
- Items marked \`pro\` need a SlabUI Pro subscription: \`slabui login\` for the
|
|
53
|
+
CLI, and \`SLABUI_TOKEN\` in the environment for the MCP server.
|
|
54
|
+
- Claude Code: \`slabui add skill\` installs the SlabUI skill
|
|
55
|
+
(\`.claude/skills/slabui\`); \`slabui update skill\` keeps it current.
|
|
56
|
+
`}async function Fn(t,n,r){let i=Q[n],a=e.join(t,i),c=Pn(r),l;if(n===`cursor`)l=`---\ndescription: Installing and updating UI components with the slabui CLI\nalwaysApply: true\n---\n\n${c}`;else{let e=`${An}\n${c}${jn}\n`,t=await s(a,`utf8`).catch(()=>void 0),n=t?.indexOf(An)??-1,r=t?.indexOf(jn,n)??-1;if(t===void 0||t.trim()===``)l=e;else if(n!==-1&&r!==-1){let i=t.slice(r+19).replace(/^\n/,``);l=`${t.slice(0,n)}${e}${i}`}else l=`${t.replace(/\n*$/,``)}\n\n${e}`}return await o(e.dirname(a),{recursive:!0}),await u(a,l),{file:i}}const In={claude:`Claude Code (.mcp.json)`,cursor:`Cursor (.cursor/mcp.json)`,vscode:`VS Code (.vscode/mcp.json)`,zed:`Zed (.zed/settings.json)`,codex:`Codex (snippet for config.toml)`},Ln=new t(`init`).description(`Adds the SlabUI MCP server to an editor or agent`).option(`--client <clients>`,`editors or agents, repeated or comma-separated (${k.join(`, `)})`,(e,t=[])=>[...t,e]).option(`--url <url>`,`MCP URL for the default registry (e.g. a local server)`).option(`--instructions`,`write instructions for the agent (CLAUDE.md, AGENTS.md…)`).option(`--no-instructions`,`skip the instructions for the agent`).option(`-y, --yes`,`never prompt`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async t=>{let n=e.resolve(t.cwd),r=Sn(t.client??[]);if(r.length===0){if(!J(t.yes))throw new j(`Pass the clients with --client (${k.join(`, `)}), e.g. --client claude,cursor.`);let e=await Cn(n);r=await Kt(`Which editors or agents should get the MCP servers?`,[...e,...k.filter(t=>!e.includes(t))].map(t=>({value:t,label:`${In[t]}${e.includes(t)?` (detected)`:``}`})),e)}let{servers:i,warnings:a}=await wn({root:n,url:t.url});for(let e of a)console.warn(`warning: ${e}`);if(i.length===0)throw new j(`The SlabUI registry has no MCP server.`);for(let e of r){let t=await Tn(n,e,i);for(let e of t.warnings??[])console.warn(`warning: ${e}`);t.file&&console.log(`${t.file}: ${i.map(({name:e,url:t})=>`${e} → ${t}`).join(`, `)}`),t.snippet&&console.log(t.snippet)}let o=Nn(r);if(t.instructions??(!J(t.yes)||await Z(`Add instructions for the agent to ${o.map(Mn).join(`, `)}?`)))for(let e of o){let{file:t}=await Fn(n,e,i);console.log(`${t}: instructions for the agent`)}}),Rn=new t(`mcp`).description(`Integration with editors and agents through MCP`).addCommand(Ln);async function zn({root:e,refs:t=[],createClient:n=e=>F(e)}){let r=await H(e),i=t.length>0?[...new Set(t.map(e=>G(W(e))))]:Object.keys(r.items);for(let e of i)if(r.items[e]===void 0)throw new j(`"${e}" is not installed. Blocks and examples are not tracked in ${E}.`);return i.length===0?[]:Bn(r,i,await n(K(r.token)).index())}function Bn(e,t,n){return t.flatMap(t=>{let r=W(t),i=e.items[t];if(i===void 0)return[];let a=i.version,o=n.items[r.name];if(o===void 0)return[{key:t,registry:n.namespace??D.namespace,current:a,status:`missing`}];let s=Jt(o,a,{...r,range:void 0}).version,c=o.latest,l=a in o.versions?x.gt(s,a)||x.gt(c,a)?`outdated`:`current`:`unknown-version`;return[{key:t,registry:n.namespace??D.namespace,current:a,wanted:s,latest:c,status:l}]})}const Vn=[`Item`,`Current`,`Wanted`,`Latest`,`Registry`],Hn=new t(`outdated`).description(`Lists installed items that have newer versions`).argument(`[items...]`,`items to check (default: all)`).option(`--all`,`also list items that are up to date`).option(`--json`,`print as JSON (all items, with their status)`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let r=await zn({root:e.resolve(n.cwd),refs:t});if(r.some(e=>e.status!==`current`)&&(process.exitCode=1),n.json){console.log(JSON.stringify(r,null,2));return}for(let e of r)e.status===`missing`?console.warn(`warning: "${e.key}" no longer exists in the "${e.registry}" registry.`):e.status===`unknown-version`&&console.warn(`warning: ${e.key}@${e.current} is no longer in the "${e.registry}" registry index.`);let i=r.filter(e=>e.wanted!==void 0&&(n.all||e.status!==`current`));if(i.length>0&&console.log(Un(i)),!r.some(e=>e.status===`outdated`)){console.log(`Everything is up to date.`);return}console.log("\nRun `slabui update` to get the Wanted versions.");let a=r.filter(e=>e.latest!==void 0&&e.wanted!==void 0&&x.major(e.latest)>x.major(e.wanted));for(let{key:e}of a)console.log(`Run \`slabui update ${e} --major\` to get the Latest.`)});function Un(e){let t=[[...Vn],...e.map(({key:e,current:t,wanted:n,latest:r,registry:i})=>[e,t,n??``,r??``,i])],n=Vn.map((e,n)=>Math.max(...t.map(e=>e[n].length)));return t.map(e=>e.map((e,t)=>e.padEnd(n[t])).join(` `).trimEnd()).join(`
|
|
57
|
+
`)}const Wn=new t(`search`).description(`Searches items in the SlabUI registry`).argument(`<termo>`,`text to search for`).addOption(new n(`--type <kind>`,`filter by item kind`).choices(be)).option(`-n, --limit <n>`,`maximum number of results`,`10`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let{results:r,warnings:i}=await rn({root:e.resolve(n.cwd),term:t,type:n.type});for(let e of i)console.warn(`warning: ${e}`);if(r.length===0)console.log(`No items found for "${t}".`);else for(let{key:e,entry:t}of r.slice(0,Number(n.limit))){let n=t.access===`pro`?`, pro`:``;console.log(`${e}@${t.latest} (${t.kind}${n})`),console.log(` ${t.description}`)}}),Gn={a:`local`,o:`base`,b:`remote`};async function Kn({root:e,refs:t,major:n=!1,overwrite:r=!1,skipInstall:i=!1,confirm:a,resolveConflict:o,createClient:s=e=>F(e)}){let c=await H(e),l=await R(e),u={root:e,aliases:c.aliases,tsconfig:l,css:B(l,e,c.css)},d=/* @__PURE__ */ new Map,f=e=>{let t=d.get(e.namespace);return t===void 0&&(t=s(e),d.set(e.namespace,t)),t},p={updated:[],upToDate:[],conflicts:[],added:[],packages:[],cssChanges:[],warnings:[]},m=(t.length>0?t:Object.keys(c.items)).map(e=>Qt(e)),h=/* @__PURE__ */ new Set,g=/* @__PURE__ */ new Set,_=[],v=[];for(;m.length>0;){let[t,i]=m.shift();if(h.has(t))continue;h.add(t);let s=await Yt({key:t,version:i,major:n,config:c,context:u,clientFor:f});p.warnings.push(...s.warnings),s.newerMajor&&p.warnings.push(`${s.key}@${s.newerMajor} is available (new major): slabui update ${s.key} --major`);let{base:l,remote:d}=s;if(d.version===l.version){p.upToDate.push(s.key);continue}let y=[];for(let t of s.files){let n=await qn(t,{root:e,overwrite:r,confirm:a,resolveConflict:o,warnings:p.warnings});y.push({destination:t.destination,status:n}),n===`conflict`&&p.conflicts.push(t.destination)}(d.cssVars!==void 0||l.cssVars!==void 0)&&p.cssChanges.push(...await Ut(e,u.css,s.key,d.cssVars??{},{base:l.cssVars??{},warnings:p.warnings,shouldRemove:r?async()=>!0:a&&((e,t)=>a(`--${t} (${e}) was removed in the new version of "${s.key}". Remove it from the CSS?`))})),c.items[s.key]={version:d.version,files:s.files.filter(e=>e.remote!==void 0).map(e=>e.destination)},p.updated.push({key:s.key,from:l.version,to:d.version,files:y});for(let e of d.dependencies.registry){let t=W(e),n=G(t),r=c.items[n];r===void 0?g.add(e):t.range!==void 0&&!x.satisfies(r.version,t.range)&&m.push([n,t.range])}_.push(...d.dependencies.npm),v.push(...d.dependencies.npmDev)}if(await ct(e,c),g.size>0){let t=await Wt({root:e,refs:[...g],overwrite:r,skipInstall:i,confirm:a,createClient:f});p.added=t.added.map(({key:e})=>e),p.packages.push(...t.packages),p.warnings.push(...t.warnings)}return p.packages.push(...await Rt(e,{npm:_,npmDev:v},{confirm:a,skipInstall:i,warnings:p.warnings})),p}async function qn({destination:t,base:n,remote:r,local:i},{root:a,overwrite:s,confirm:c,resolveConflict:d,warnings:f}){let p=await I(a,t),m=async t=>{await o(e.dirname(p),{recursive:!0}),await u(p,t)};if(r===void 0)return i===void 0?`removed`:i===n||s||c!==void 0&&await c(`${t} was removed in the new version, but has local changes. Delete it?`)?(await l(p),`removed`):(f.push(`${t} was removed in the new version; kept because it has local changes.`),`kept`);if(n===void 0)return i===r?`unchanged`:i!==void 0&&!(s||c!==void 0&&await c(`${t} is new in this version, but already exists in the project. Overwrite it?`))?(f.push(`${t} already exists in the project and was not overwritten (--overwrite).`),`kept`):(await m(r),`added`);if(i===r)return`unchanged`;if(i===void 0||i===n)return i===void 0&&f.push(`${t} was missing from the project and was recreated.`),await m(r),`updated`;let h=ne(i.split(`
|
|
58
|
+
`),n.split(`
|
|
59
|
+
`),r.split(`
|
|
60
|
+
`),{label:Gn});if(!h.conflict)return await m(h.result.join(`
|
|
61
|
+
`)),`merged`;let g=d?await d(t):`markers`;return g===`local`?`kept`:g===`remote`?(await m(r),`updated`):(await m(h.result.join(`
|
|
62
|
+
`)),`conflict`)}const Jn={unchanged:`unchanged`,updated:`updated`,merged:`merged with local changes`,conflict:`CONFLICT (markers in the file)`,added:`created`,removed:`removed`,kept:`kept`},Yn=new t(`update`).description(`Updates items to a new version (3-way merge)`).argument(`[items...]`,`items to update (default: all); e.g. button@2`).option(`--major`,`allow updating to a new major`).option(`-y, --yes`,`never prompt; conflicts keep the markers`).option(`-o, --overwrite`,`overwrite and delete files without prompting`).option(`--skip-install`,`skip installing npm packages`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let r=J(n.yes),i=await Kn({root:e.resolve(n.cwd),refs:t,major:n.major,overwrite:n.overwrite,skipInstall:n.skipInstall,confirm:r?Z:void 0,resolveConflict:r?e=>Gt(`Conflict in ${e}. What should be done?`,[{value:`markers`,label:`Keep the markers and resolve in the editor`},{value:`local`,label:`Keep the local version`},{value:`remote`,label:`Use the remote version (discards local changes)`}]):void 0});for(let{key:e,from:t,to:n,files:r}of i.updated){console.log(`↑ ${e}: ${t} → ${n}`);for(let{destination:e,status:t}of r)console.log(` ${e}: ${Jn[t]}`)}for(let e of i.added)console.log(`+ ${e} (new dependency)`);i.updated.length===0&&i.added.length===0&&console.log(`Everything is up to date.`),i.packages.length>0&&console.log(`Installed packages: ${i.packages.join(` `)}`);let a=ve(i.cssChanges);a&&console.log(a);for(let e of i.warnings)console.warn(`warning: ${e}`);i.conflicts.length>0&&(console.error(`\nResolve the conflicts (look for "<<<<<<< local"):\n${i.conflicts.map(e=>` ${e}`).join(`
|
|
63
|
+
`)}`),process.exitCode=1)}),Xn=`slabui`,Zn=`https://registry.npmjs.org/-/package/${Xn}/dist-tags`,Qn=864e5,$n={pnpm:`pnpm add -D`,npm:`npm install -D`,yarn:`yarn add -D`,bun:`bun add -d`};function er({env:e=process.env,argv:t=process.argv,tty:n=!!(process.stdout.isTTY&&process.stderr.isTTY)}={}){let r=e.CI!==void 0&&e.CI!==``&&e.CI!==`false`;return n&&!r&&e.SLABUI_NO_UPDATE_CHECK!==`1`&&!t.includes(`--json`)}function tr(t=process.env,n=process.platform,r=m()){let i=n===`darwin`?e.join(r,`Library/Caches/slabui`):n===`win32`?e.join(t.LOCALAPPDATA??e.join(r,`AppData/Local`),`slabui/Cache`):e.join(t.XDG_CACHE_HOME||e.join(r,`.cache`),`slabui`);return e.join(i,`update-check.json`)}async function nr(e){try{return JSON.parse(await s(e,`utf8`))}catch{return{}}}async function rr(t,n){try{let r=await nr(t);n(r),await o(e.dirname(t),{recursive:!0}),await u(t,`${JSON.stringify(r)}\n`)}catch{}}async function ir({file:e,fetch:t=globalThis.fetch,now:n=Date.now(),signal:r}){let i=(await nr(e)).cli;if(i&&n-i.checkedAt<Qn)return i.latest;let a;try{let e=await t(Zn,{signal:r}),n=await e.json();e.ok&&typeof n.latest==`string`&&(a=x.valid(n.latest)??void 0)}catch{}if(!r?.aborted)return await rr(e,e=>{e.cli={checkedAt:n,latest:a}}),a}function ar(e,t,n){if(t!==void 0&&x.gt(t,e))return`Update available: slabui ${e} → ${t}\nRun: ${$n[n]??$n.npm} ${Xn}@latest`}async function or({root:t,file:n,now:r=Date.now(),indexOf:i=Xe}){if(!await L(e.join(t,`slabui.json`)))return;let a=(await nr(n)).projects?.[t];if(a!==void 0&&r-a<Qn)return;let o=await H(t),s=i(K().namespace);if(s===void 0)return;let c=Bn(o,Object.keys(o.items),s).filter(e=>e.status===`outdated`).length;if(c!==0)return await rr(n,e=>{e.projects={...e.projects,[t]:r}}),c===1?"1 installed item has a newer version. Run `slabui outdated` to see it.":`${c} installed items have newer versions. Run \`slabui outdated\` to see them.`}const sr=/* @__PURE__ */ new Set([`add`,`info`,`search`]),cr=Date.now(),lr=er(),ur=tr(),dr=new AbortController,fr=lr?ir({file:ur,signal:dr.signal}).catch(()=>void 0):void 0;let $;const pr=new t(`slabui`).description(re).version(T,`-v, --version`).addCommand(un).addCommand(qt).addCommand(Yn).addCommand(Hn).addCommand($t).addCommand(Wn).addCommand(on).addCommand(gn).addCommand(_n).addCommand(Rn).hook(`preAction`,(e,t)=>{Ke(`${t.parent?.parent?`${t.parent.name()} `:``}${t.name()}`)}).hook(`postAction`,(t,n)=>{let{cwd:r}=n.opts();$={name:n.name(),root:e.resolve(r??`.`)}});try{await pr.parseAsync()}catch(e){console.error(e instanceof j?e.message:e),process.exitCode=1}lr&&await mr().catch(()=>{});async function mr(){let e=[];if($&&sr.has($.name)){let t=await or({root:$.root,file:ur});t&&e.push(t)}let t=Math.max(0,cr+1e3-Date.now()),n,r=await Promise.race([fr,new Promise(e=>{n=setTimeout(()=>e(void 0),t)})]);clearTimeout(n),dr.abort();let i=ar(T,r,await Nt($?.root??process.cwd()));i&&e.push(i),e.length>0&&console.error(`\n${e.join(`
|
|
64
|
+
|
|
65
|
+
`)}`)}export{};
|