@slabui/cli 0.0.0-stage → 0.0.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/CHANGELOG.md +14 -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,14 @@
|
|
|
1
|
+
# @slabui/cli
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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:
|
|
8
|
+
|
|
9
|
+
- `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`.
|
|
10
|
+
- `@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`.
|
|
11
|
+
- `@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.
|
|
12
|
+
- `@slabui/theme-core`: o tema da SlabUI como variáveis CSS (ler, gravar e validar) e o atributo do tema ativo no `<html>`.
|
|
13
|
+
|
|
14
|
+
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 T}from"node-diff3";var E=`0.0.1`,ne=`The SlabUI CLI: add, update and compare items from versioned component registries`;const re=/^[a-z0-9][a-z0-9-]*$/i;function ie(e){return re.test(e)}function ae(e,t=!1){if(!ie(e))throw Error(`Invalid theme name: "${e}"`);return`:root[data-slabui-theme="${e}"]${t?`.dark`:``}`}const oe=/^\s*(oklch|oklab|lch|lab|hsla?|rgba?|hwb|color)\(|^\s*#[0-9a-f]{3,8}\s*$/i;async function se(e,t,{base:n,overwrite:i=!1,shouldRemove:a,theme:o}={}){let s=r.parse(e),c=[],l=[],u=e=>o?e:ce(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=de(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??=fe(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 me(h,u)?g(`unchanged`):i||f!==void 0&&me(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&&pe(s),{css:s.toString(),changes:c,warnings:l}}function ce(e){let t={...e.theme};for(let n of[e.light,e.dark])for(let[e,r]of Object.entries(n??{}))oe.test(r)&&t[`color-${e}`]===void 0&&(t[`color-${e}`]=`var(--${e})`);return{...e,...Object.keys(t).length>0&&{theme:t}}}function le(e,t){return t?ae(t,e===`dark`):e===`light`?`:root`:`.dark`}const ue=e=>e.replace(/["'\s]/g,``);function de(e,t,n){return e.nodes.find(e=>t===`theme`?e.type===`atrule`&&e.name===`theme`&&e.params.trim()===`inline`:e.type===`rule`&&ue(e.selector)===ue(le(t,n)))}function fe(e,t,n){let i=t===`theme`?r.atRule({name:`theme`,params:`inline`}):r.rule({selector:le(t,n)});return i.raws={before:e.nodes.length>0?`
|
|
5
|
+
|
|
6
|
+
`:``,between:` `,after:`
|
|
7
|
+
`,semicolon:!0},e.append(i),i}function pe(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 me(e,t){return e.replace(/\s+/g,` `).trim()===t.replace(/\s+/g,` `).trim()}const he={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)`}},ge=se;function _e(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 D=`slabui.json`,O={namespace:`@slabui`,url:`https://slabui.com/r`},ve={command:`x-slabui-command`,optOut:`x-slabui-telemetry`},ye=[`ui`,`component`,`lib`,`hook`,`util`,`style`,`file`,`theme`,`block`,`example`],be=[`free`,`pro`],k=`SLABUI_TOKEN`,A=[`claude`,`cursor`,`vscode`,`zed`,`codex`];function j(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 xe(e=j()){try{let{token:t}=JSON.parse(await s(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function Se(t,n=j()){await o(e.dirname(n),{recursive:!0}),await u(n,`${JSON.stringify({token:t})}\n`,{mode:384})}async function Ce(e=j()){let t=await xe(e)!==void 0;return await l(e,{force:!0}),t}async function we({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 Te(){return f(24).toString(`base64url`)}function Ee({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 M=class extends Error{name=`SlabUIError`};const N=p.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),De=p.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),P=p.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),Oe=p.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),F=p.enum(ye),ke=p.enum(be),Ae=p.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),je=p.object({registry:p.array(Ae).default([]),npm:p.array(p.string().min(1)).default([]),npmDev:p.array(p.string().min(1)).default([])}),Me=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],Ne=[e=>e.files.length>0||e.cssVars!==void 0,{message:`the item needs files or cssVars`,path:[`files`]}],Pe=p.object({path:p.string().min(1),kind:F,target:p.string().min(1).optional()}).refine(...Me),Fe=p.object({path:p.string().min(1),kind:F,target:p.string().min(1).optional(),content:p.string()}).refine(...Me),I=p.record(p.string(),p.string()),Ie=p.object({theme:I.optional(),light:I.optional(),dark:I.optional()}),Le={name:N,kind:F,title:p.string().min(1).optional(),description:p.string().min(1),dependencies:je.prefault({}),cssVars:Ie.optional()},Re=p.object({$schema:p.string().optional(),schemaVersion:p.literal(1),...Le,version:P,files:p.array(Fe).default([])}).refine(...Ne);p.object({...Le,categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:ke.optional(),inferDependencies:p.boolean().optional(),files:p.array(Pe).default([])}).refine(...Ne);const ze=p.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),Be=p.object({hash:Oe,path:ze}),Ve=p.object({kind:F,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:ke.optional(),dependencies:je.prefault({}),tokens:p.array(p.string().min(1)).optional(),latest:P,versions:p.record(P,Be)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),He=p.object({$schema:p.string().optional(),schemaVersion:p.literal(2),namespace:De.optional(),homepage:p.url().optional(),mcp:p.url().optional(),license:p.url().optional(),items:p.record(N,Ve)});let Ue;function We(e){Ue=e}function Ge(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function Ke(e,t=Ue){let n={"user-agent":`slabui/${E}`};return Ge(e)?n[ve.optOut]=`off`:t&&(n[ve.command]=t),n}const qe=/* @__PURE__ */ new Map;function Je(e){return qe.get(e)}function L(e,{fetch:t=globalThis.fetch,env:n=process.env,command:r,savedToken:i=()=>xe()}={}){let a=e.url.replace(/\/+$/,``),o={...Ke(n,r),...Xe(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:Ze(e.token,`"token" in slabui.json`,n))||n.SLABUI_TOKEN||await i();if(!a)throw new M(`"${t}" is a Pro item. Run "slabui login" or set ${k} 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 M(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new M(`The token was refused while fetching the Pro item "${i}". Run "slabui login" again or check ${k}.`);if(i!==void 0&&e.isDefault&&a.status===403)throw new M(`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 M(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new M(`Not found: ${n}.`);if(!a.ok)throw new M(`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 M(`${e} is not valid JSON.`)}r?.(e,i);let a=n.safeParse(i);if(!a.success)throw new M(`${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),He,Ye);return qe.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 M(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new M(`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(Qe(s)!==i.hash)throw new M(`${o} does not match the hash in the index. The file may have been changed on the server.`);let d=u(o,s,Re);if(d.name!==t||d.version!==n)throw new M(`${o} contains ${d.name}@${d.version}, not ${t}@${n}.`);return d}}}function Ye(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 M(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new M(`${e} uses format ${r}, which is no longer supported. ${n}`)}function Xe(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Ze(n,`the "${e}" header`,t)]))}function Ze(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 M(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function Qe(e){return`sha256-${d(`sha256`).update(e).digest(`base64`)}`}async function R(t,n){let r=e=>new M(`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(!$e(i,o))throw r(`it leaves the project root`);let s=await et(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(!$e(l,u))throw r(`it goes through a symbolic link outside the project`);return e.join(u,e.relative(s,o))}function $e(t,n){let r=e.relative(t,n);return r===``||r!==`..`&&!r.startsWith(`..${e.sep}`)&&!e.isAbsolute(r)}async function et(t){let n=t;for(;;)try{return await a(n),n}catch(t){if(t.code!==`ENOENT`)throw t;n=e.dirname(n)}}const tt=p.object({version:P,files:p.array(p.string().min(1))}),nt=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(N,tt).default({})}),rt=[`tsconfig.json`,`jsconfig.json`],it=[`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 z(e){return i(e).then(()=>!0,()=>!1)}async function B(t){for(let n of rt){let r=e.join(t,n);if(await z(r))try{return{path:r,config:_(r)}}catch(e){throw new M(`Could not read ${n}: ${e.message}`)}}throw new M(`No tsconfig.json or jsconfig.json in ${t}. slabui uses its "paths" to resolve the aliases.`)}function V(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 H(t,n,r){if(r===void 0)return;let i=V(t),a=i!==void 0&&r.startsWith(i)?U(t,r):void 0;return a===void 0?r:e.relative(n,a).split(e.sep).join(`/`)}function U(e,t){return g(e)?.(t)[0]}async function at(t){for(let n of it)if(await z(e.join(t,n)))return n}async function W(t){let n=e.join(t,D),r=await s(n,`utf8`).catch(()=>void 0);if(r===void 0)throw new M(`${D} not found in ${t}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new M(`${D} is not valid JSON.`)}let a=nt.safeParse(i);if(!a.success)throw new M(`${D} has errors:\n${p.prettifyError(a.error)}`);return a.data}async function ot(t,n){await u(e.join(t,D),`${JSON.stringify(n,null,2)}\n`)}function st(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function ct(t){return await z(e.join(t,`src`))?`src`:`.`}async function lt(t,{folder:n}={}){let{path:r}=await B(t),i=e.resolve(t,n??await ct(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 z(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 G=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.cts`,`.mjs`],ut=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,dt=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function ft(t){return e.posix.extname(t)===`.css`}function pt(e,t){return e.replace(dt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function mt(t){return G.includes(e.posix.extname(t))}function ht(e,t){return e.replace(ut,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function gt(e,t){return[e,...G.map(t=>`${e}${t}`),...G.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function _t(t){let n=e.posix.extname(t);return G.includes(n)?t.slice(0,-n.length):t}function K(e){let t=e;if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)throw new M(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==O.namespace)throw new M(`"${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(!N.safeParse(r).success)throw new M(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||x.validRange(i)===null))throw new M(`"${i}" is not a valid version or range.`);return{name:r,...i!==void 0&&{range:i}}}function q(e){return e.name}function J(e,t=process.env){return{namespace:O.namespace,url:t.SLABUI_REGISTRY_URL||O.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function vt(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 M(`No version of "${q(e)}" satisfies "${e.range}". Available: ${x.sort(n).join(`, `)}.`);return r}const yt={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function bt(t,n){if(t.target!==void 0){let r=t.target;return St((r.startsWith(V(n.tsconfig)??`\0`)?U(n.tsconfig,r):void 0)??e.resolve(n.root,r),n)}if(!(t.kind in yt))throw new M(`Files with kind "${t.kind}" cannot be installed by add yet (${t.path}).`);let r=n.aliases[yt[t.kind]],i=t.kind===`style`&&t.path.split(`/`).slice(1).join(`/`)||e.posix.basename(t.path),a=st(r)?e.resolve(n.root,r,i):U(n.tsconfig,`${r}/${i}`);if(a===void 0)throw new M(`Alias "${r}" does not match any "paths" in the tsconfig.`);return St(a,n)}function xt(t,n,r){let i=V(r.tsconfig),a=i===void 0?void 0:U(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}${_t(e.relative(a,o).split(e.sep).join(`/`))}`;let s=e.posix.relative(e.posix.dirname(n),t);return s.startsWith(`.`)||(s=`./${s}`),_t(s)}function St(t,n){return e.relative(n.root,t).split(e.sep).join(`/`)}function Y(e){return e.kind===`block`||e.kind===`example`}function Ct(e,t,n){return Y(e)?Ot(e,n):new Map(e.files.map(e=>[e.path,bt(e,t)]))}function wt(e,t){return[e,...t.dependencies.registry.map(e=>q(K(e)))]}async function Tt(e,{config:t,context:n,destinations:r,clientFor:i}){for(let a of e)for(let e of a.dependencies.registry){let a=K(e),o=q(a),s=t.items[o];if(r.has(o)||s===void 0)continue;let c=i(J(t.token));r.set(o,Ct(await c.item(a.name,s.version),n))}}function Et(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=ft(e.path);if(!mt(e.path)&&!s)return e.content;let c=wt(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 Dt(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&>(n,new Set(t.keys()));if(o){let e=t.get(o);return s?Dt(e,r):xt(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?pt(e.content,l):ht(e.content,l)}function Dt(t,n){let r=e.posix.relative(e.posix.dirname(n),t);return r.startsWith(`.`)?r:`./${r}`}function Ot(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 kt=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function At(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 jt(t){let n=(await Mt(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 kt)if(await z(e.join(r,t)))return n;let t=e.dirname(r);if(t===r)return`npm`;r=t}}async function Mt(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 Nt(e,{npm:t,npmDev:n}){let r=await Mt(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=At(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 Pt(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function Ft(e,t,n,r){if(n.length===0)return;let[i,a]=Pt(t,n,r);await new Promise((t,n)=>{let r=S(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new M(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new M(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function It(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await Nt(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 ${At(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 jt(e);return await Ft(e,s,a.install,!1),await Ft(e,s,a.installDev,!0),o}async function Lt({refs:e,config:t,createClient:n=e=>L(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=q(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})=>Rt(p,e)))return;let m=J(t.token),h=l(m),g=(await h.index()).items[e.name];if(g===void 0)throw new M(`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 M(`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(K(e),r);o.includes(r)||o.push(r)}for(let t of e)await u(K(t));return{items:o.map(e=>a.get(e)),installed:[...s],warnings:c}}function Rt(e,t){return t===void 0||x.satisfies(e.item.version,t)}const zt=he;async function Bt(t,n){let r=await R(t,n),i=await s(r,`utf8`).catch(()=>void 0),a=await ge(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
|
+
`,zt);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 Vt(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 R(e,t),o=await s(a,`utf8`).catch(()=>void 0);o===void 0&&(await Bt(e,t),i.warnings.push(`${t} did not exist; it was created with the default template.`),o=await s(a,`utf8`));let c=await ge(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 Ht({root:t,refs:n,overwrite:r=!1,skipInstall:i=!1,confirm:a,path:s,askPath:c,createClient:l=e=>L(e)}){let d=await W(t),f=await B(t),p={root:t,aliases:d.aliases,tsconfig:f,css:H(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 Lt({refs:n,config:d,createClient:h}),v=[..._.warnings],y=_.items.filter(({item:e})=>Y(e)),b=s;if(y.length>0&&b===void 0){let e=y.map(({key:e})=>e);if(c===void 0)throw new M(`${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,Ct(t,p,b));await Tt(_.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 R(t,r),await z(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 M(`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=Et(r,{key:n,item:i,destination:s,destinations:x,context:p,warnings:v}),l=await R(t,s);await o(e.dirname(l),{recursive:!0}),await u(l,c)}i.cssVars!==void 0&&w.push(...await Vt(t,p.css,n,i.cssVars,{overwrite:r,warnings:v}));let s=[...a.values()];Y(i)||(d.items[n]={version:i.version,files:s}),ee.push({key:n,version:i.version,files:s,block:Y(i)})}await ot(t,d);let te=await It(t,{npm:_.items.flatMap(({item:e})=>e.dependencies.npm),npmDev:_.items.flatMap(({item:e})=>e.dependencies.npmDev)},{confirm:a,skipInstall:i,warnings:v}),T=[],E=_.items[0]?.registry;if(g&&E!==void 0){let e=(await h(E).index()).license;e!==void 0&&T.push({namespace:E.namespace,url:e})}return{added:ee,installed:_.installed,packages:te,cssChanges:w,licenses:T,warnings:v}}function X(e){return!e&&!!(process.stdin.isTTY&&process.stdout.isTTY)}function Ut(e){if(C.isCancel(e))throw C.cancel(`Cancelled.`),new M(`Operation cancelled.`);return e}async function Z(e,t=``){return Ut(await C.text({message:e,initialValue:t}))}async function Q(e,t=!0){return Ut(await C.confirm({message:e,initialValue:t}))}async function Wt(e,t){return Ut(await C.select({message:e,options:t}))}const Gt=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=X(n.yes),i=await Ht({root:e.resolve(n.cwd),refs:t,overwrite:n.overwrite,skipInstall:n.skipInstall,path:n.path,confirm:r?Q:void 0,askPath:r?e=>Z(`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=_e(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 Kt(e,t,n,r=!1){if(n.range!==void 0)return{version:vt(n,e)};if(r)return{version:e.latest};let i=vt({...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 qt({key:t,version:n,major:r,config:i,context:a,clientFor:o}){let c=K(n?`${t}@${n}`:t),l=c.name,u=i.items[l];if(u===void 0)throw new M(`"${l}" is not installed. Blocks and examples are not updated; for other items, use "slabui add ${l}".`);let d=J(i.token),f=o(d),p=(await f.index()).items[c.name];if(p===void 0)throw new M(`Item "${c.name}" no longer exists in the "${d.namespace}" registry.`);let m=Kt(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,Ct(e,a)]]);await Tt([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,Jt(Et(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(Jt).catch(()=>void 0);return{destination:t,base:y.get(t),remote:b.get(t),local:n}})),newerMajor:m.newerMajor,warnings:_}}function Jt(e){return e.replace(/\r\n/g,`
|
|
21
|
+
`)}async function Yt({root:e,ref:t,local:n=!1,major:r,createClient:i=e=>L(e)}){let a=await W(e),o=await B(e),s={root:e,aliases:a.aliases,tsconfig:o,css:H(o,e,a.css)},[c,l]=Xt(t),u=await qt({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 Xt(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?[e,void 0]:[e.slice(0,t),e.slice(t+1)]}const Zt=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 Yt({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 Qt(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 $t=e=>L(e);async function en(t){return await z(e.join(t,`slabui.json`))?W(t):void 0}async function tn({root:e,term:t,type:n,createClient:r=$t}){let i=J((await en(e))?.token);try{let e=await r(i).index();return{results:Qt([{namespace:i.namespace,isDefault:!0,index:e}],t,{type:n}),warnings:[]}}catch(e){return{results:[],warnings:[`"${i.namespace}": ${e.message}`]}}}async function nn({root:e,ref:t,createClient:n=$t}){let r=await en(e),i=K(t),a=J(r?.token),o=n(a),s=(await o.index()).items[i.name];if(s===void 0)throw new M(`Item "${i.name}" does not exist in the "${a.namespace}" registry.`);let c=await o.item(i.name,vt(i,s)),l=q(i),u;if(r!==void 0){let t={root:e,aliases:r.aliases,tsconfig:await B(e)};u=c.files.map(e=>{try{return bt(e,t)}catch{return e.path}})}return{key:l,registry:a,entry:s,item:c,installed:r?.items[l]?.version,destinations:u}}const rn=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 nn({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 an(e){let t=V(await B(e));if(t===void 0)throw new M(`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 on(e,`${t}styles`)}}async function on(e,t){let n=await at(e);return n===void 0?{css:`${t}/globals.css`,cssDetected:!1}:{css:n,cssDetected:!0}}async function sn({root:t,aliases:n,css:r,force:i=!1}){if(!i&&await z(e.join(t,`slabui.json`)))throw new M(`${D} already exists. Use --force to create it again.`);let a=await B(t);for(let[e,t]of Object.entries(n))if(!st(t)&&U(a,t)===void 0)throw new M(`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 ot(t,o),o}const cn=new t(`init`).description(`Creates ${D} at the project root`).option(`-y, --yes`,`use the detected values without prompting`).option(`-f, --force`,`overwrite an existing ${D}`).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=X(t.yes);if(r&&C.intro(`slabui init`),V(await B(n))===void 0){if(r&&!await Q(`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 ct(n),i=[{value:`src`,label:`./src (@/components → src/components)`},{value:`.`,label:`./ (@/components → components)`}],a=await lt(n,{folder:r?await Wt(`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 ln(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 an(n),{aliases:a,css:o}=i,s=t.template;r&&(a={components:await Z(`Components alias`,a.components),ui:await Z(`UI components alias`,a.ui),lib:await Z(`Lib alias`,a.lib),hooks:await Z(`Hooks alias`,a.hooks),utils:await Z(`Utils alias`,a.utils),styles:await Z(`Styles alias`,a.styles)},o=await Z(`Global CSS file (empty if none)`,i.cssDetected?i.css:(await on(n,a.styles)).css)||void 0,o&&s&&(s=await Q(`Add the default theme to ${o}? (creates the file if needed)`))),await sn({root:n,aliases:a,css:o,force:t.force}),console.log(`${D} created in ${n}.`);let c=H(await B(n),n,o);if(c&&s){let{created:e,changes:t}=await Bt(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 ln(t){for(let n of[`ts`,`mts`,`js`,`mjs`,`cjs`])if(await z(e.join(t,`vite.config.${n}`)))return!0;return!1}async function un({token:e,fetch:t=globalThis.fetch,env:n=process.env,file:r=j(n)}){let i=J(void 0,n),a;try{a=await we({registryUrl:i.url,token:e,fetch:t,headers:Ke(n,`login`)})}catch(e){throw e instanceof Error&&e.message.startsWith(`Error 404`)?new M(`${i.url} does not support login.`):new M(e instanceof Error&&e.message.startsWith(`Error `)?e.message:`Could not reach ${i.url}.`)}if(a===null)throw new M(`Invalid token. Check it and try again.`);return await Se(e.trim(),r),{account:a,url:i.url,file:r}}async function dn({root:e,onUrl:t,timeout:n=3e5,...r}){let i=J(void 0,r.env),a=Te();return un({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(pn(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 M(`Sign-in was cancelled in the browser.`)))}),s=setTimeout(()=>c(()=>r(new M(`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(Ee({registryUrl:i.url,callback:`http://127.0.0.1:${e}/callback`,state:a,client:`SlabUI CLI`}))})}),...r})}function fn(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 pn(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 mn=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 M(`Pass the token with --token or set ${k}.`);let{account:r,url:i,file:a}=t.token===void 0?await dn({root:n,onUrl:e=>{console.log(`Opening the browser to sign in. If it does not open, visit:\n ${e}\n`),fn(e)}}):await un({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}`)}),hn=new t(`logout`).description(`Removes the token saved by slabui login`).action(async()=>{console.log(await Ce()?`Logged out.`:`No token was saved; nothing to do.`)}),gn=`Bearer \${${k}}`;function _n(e){return Object.keys(e).some(e=>e.toLowerCase()===`authorization`)?e:{...e,Authorization:gn}}const vn={claude:`.mcp.json`,cursor:`.cursor/mcp.json`,vscode:`.vscode/mcp.json`,zed:`.zed/settings.json`},yn=[[`.mcp.json`,`claude`],[`.claude`,`claude`],[`.cursor`,`cursor`],[`.vscode`,`vscode`],[`.zed`,`zed`],[`.codex`,`codex`]];async function bn(t){let n=[];for(let[r,i]of yn)!n.includes(i)&&await z(e.join(t,r))&&n.push(i);return n}async function xn({root:e,url:t,createClient:n=e=>L(e)}){let r=J((await W(e)).token),i=r.namespace.slice(1),a=_n(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 Sn(t,n,r){if(n===`zed`)return Tn(t,r);if(n===`codex`)return{snippet:En(r)};let i=vn[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 M(`${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]=Cn(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 Cn(e,{url:t,headers:n}){let r=wn(n,e===`claude`?"${$1}":"${env:$1}",e);return{...e!==`cursor`&&{type:`http`},url:t,...Object.keys(r).length>0&&{headers:r}}}function wn(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e,r===gn&&n===`claude`?`Bearer \${${k}:-}`:r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,t)]))}async function Tn(t,n){let r=vn.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 M(`${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!==gn));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 En(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 Dn={claude:`CLAUDE.md`,cursor:`.cursor/rules/slabui.mdc`,vscode:`.github/copilot-instructions.md`,zed:`AGENTS.md`,codex:`AGENTS.md`},On=`<!-- slabui:start -->`,kn=`<!-- slabui:end -->`;function An(e){return Dn[e]}function jn(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 Mn(t,n,r){let i=Dn[n],a=e.join(t,i),c=jn(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=`${On}\n${c}${kn}\n`,t=await s(a,`utf8`).catch(()=>void 0),n=t?.indexOf(On)??-1,r=t?.indexOf(kn,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 Nn={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)`},Pn=new t(`init`).description(`Adds the SlabUI MCP server to an editor or agent`).addOption(new n(`--client <client>`,`editor or agent`).choices(A)).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=t.client;if(r===void 0){if(!X(t.yes))throw new M(`Pass the client with --client (${A.join(`, `)}).`);let e=await bn(n);r=await Wt(`Which editor or agent should get the MCP servers?`,[...e,...A.filter(t=>!e.includes(t))].map(t=>({value:t,label:`${Nn[t]}${e.includes(t)?` (detected)`:``}`})))}let{servers:i,warnings:a}=await xn({root:n,url:t.url});for(let e of a)console.warn(`warning: ${e}`);if(i.length===0)throw new M(`The SlabUI registry has no MCP server.`);let o=await Sn(n,r,i);for(let e of o.warnings??[])console.warn(`warning: ${e}`);if(o.file&&console.log(`${o.file}: ${i.map(({name:e,url:t})=>`${e} → ${t}`).join(`, `)}`),o.snippet&&console.log(o.snippet),t.instructions??(!X(t.yes)||await Q(`Add instructions for the agent to ${An(r)}?`))){let{file:e}=await Mn(n,r,i);console.log(`${e}: instructions for the agent`)}}),Fn=new t(`mcp`).description(`Integration with editors and agents through MCP`).addCommand(Pn);async function In({root:e,refs:t=[],createClient:n=e=>L(e)}){let r=await W(e),i=t.length>0?[...new Set(t.map(e=>q(K(e))))]:Object.keys(r.items);for(let e of i)if(r.items[e]===void 0)throw new M(`"${e}" is not installed. Blocks and examples are not tracked in ${D}.`);return i.length===0?[]:Ln(r,i,await n(J(r.token)).index())}function Ln(e,t,n){return t.flatMap(t=>{let r=K(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??O.namespace,current:a,status:`missing`}];let s=Kt(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??O.namespace,current:a,wanted:s,latest:c,status:l}]})}const Rn=[`Item`,`Current`,`Wanted`,`Latest`,`Registry`],zn=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 In({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(Bn(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 Bn(e){let t=[[...Rn],...e.map(({key:e,current:t,wanted:n,latest:r,registry:i})=>[e,t,n??``,r??``,i])],n=Rn.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 Vn=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(ye)).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 tn({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}`)}}),Hn={a:`local`,o:`base`,b:`remote`};async function Un({root:e,refs:t,major:n=!1,overwrite:r=!1,skipInstall:i=!1,confirm:a,resolveConflict:o,createClient:s=e=>L(e)}){let c=await W(e),l=await B(e),u={root:e,aliases:c.aliases,tsconfig:l,css:H(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=>Xt(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 qt({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 Wn(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 Vt(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=K(e),n=q(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 ot(e,c),g.size>0){let t=await Ht({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 It(e,{npm:_,npmDev:v},{confirm:a,skipInstall:i,warnings:p.warnings})),p}async function Wn({destination:t,base:n,remote:r,local:i},{root:a,overwrite:s,confirm:c,resolveConflict:d,warnings:f}){let p=await R(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=T(i.split(`
|
|
58
|
+
`),n.split(`
|
|
59
|
+
`),r.split(`
|
|
60
|
+
`),{label:Hn});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 Gn={unchanged:`unchanged`,updated:`updated`,merged:`merged with local changes`,conflict:`CONFLICT (markers in the file)`,added:`created`,removed:`removed`,kept:`kept`},Kn=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=X(n.yes),i=await Un({root:e.resolve(n.cwd),refs:t,major:n.major,overwrite:n.overwrite,skipInstall:n.skipInstall,confirm:r?Q:void 0,resolveConflict:r?e=>Wt(`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}: ${Gn[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=_e(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)}),qn=`slabui`,Jn=`https://registry.npmjs.org/-/package/${qn}/dist-tags`,Yn=864e5,Xn={pnpm:`pnpm add -D`,npm:`npm install -D`,yarn:`yarn add -D`,bun:`bun add -d`};function Zn({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 Qn(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 $n(e){try{return JSON.parse(await s(e,`utf8`))}catch{return{}}}async function er(t,n){try{let r=await $n(t);n(r),await o(e.dirname(t),{recursive:!0}),await u(t,`${JSON.stringify(r)}\n`)}catch{}}async function tr({file:e,fetch:t=globalThis.fetch,now:n=Date.now(),signal:r}){let i=(await $n(e)).cli;if(i&&n-i.checkedAt<Yn)return i.latest;let a;try{let e=await t(Jn,{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 er(e,e=>{e.cli={checkedAt:n,latest:a}}),a}function nr(e,t,n){if(t!==void 0&&x.gt(t,e))return`Update available: slabui ${e} → ${t}\nRun: ${Xn[n]??Xn.npm} ${qn}@latest`}async function rr({root:t,file:n,now:r=Date.now(),indexOf:i=Je}){if(!await z(e.join(t,`slabui.json`)))return;let a=(await $n(n)).projects?.[t];if(a!==void 0&&r-a<Yn)return;let o=await W(t),s=i(J().namespace);if(s===void 0)return;let c=Ln(o,Object.keys(o.items),s).filter(e=>e.status===`outdated`).length;if(c!==0)return await er(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 ir=/* @__PURE__ */ new Set([`add`,`info`,`search`]),ar=Date.now(),or=Zn(),sr=Qn(),cr=new AbortController,lr=or?tr({file:sr,signal:cr.signal}).catch(()=>void 0):void 0;let $;const ur=new t(`slabui`).description(ne).version(E,`-v, --version`).addCommand(cn).addCommand(Gt).addCommand(Kn).addCommand(zn).addCommand(Zt).addCommand(Vn).addCommand(rn).addCommand(mn).addCommand(hn).addCommand(Fn).hook(`preAction`,(e,t)=>{We(`${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 ur.parseAsync()}catch(e){console.error(e instanceof M?e.message:e),process.exitCode=1}or&&await dr().catch(()=>{});async function dr(){let e=[];if($&&ir.has($.name)){let t=await rr({root:$.root,file:sr});t&&e.push(t)}let t=Math.max(0,ar+1e3-Date.now()),n,r=await Promise.race([lr,new Promise(e=>{n=setTimeout(()=>e(void 0),t)})]);clearTimeout(n),cr.abort();let i=nr(E,r,await jt($?.root??process.cwd()));i&&e.push(i),e.length>0&&console.error(`\n${e.join(`
|
|
64
|
+
|
|
65
|
+
`)}`)}export{};
|