Documentation
¶
Overview ¶
Package kitadd makes a library kit from a package in one command (`harnessly design kit add npm:<package>` or `shadcn:<registry>`) and brings it to a new version of the package (`kit update`): the package's exports built into one browser script on the page's React, props read from its types, its CSS variables as tokens, a card per component. What the files say that a person wrote (what a component is for, when not to use it, samples, token usage) is kept on every later run; what comes from the package is rebuilt, and the run says what changed.
Index ¶
- Constants
- func ApplyProbe(folder, title string, vars []ProbeVar) (int, error)
- func DefaultID(s Source) string
- func DropSamples(folder, ns, root string, failed map[string]string) error
- func ReadSource(folder string) (Source, *Options, error)
- func RetrySamples(folder string, ids []string, attempt int) ([]string, error)
- func RunSandboxHelper(args []string) error
- func SafeNpmSpec(spec string) bool
- func SandboxAvailable() bool
- func Verified(src Source) bool
- type Analysis
- type Export
- type Options
- type ProbeVar
- type PropChange
- type Report
- type Source
- type TypeProp
Constants ¶
const KitRootID = "KitRoot"
KitRootID is the provider a kit made by `kit add` gets when the package needs a provider to draw anything and the provider needs props a board cannot give (a theme object, a design system value): a small component the bundle carries, which wraps its children in the package's own provider with the package's default theme. It is also where the theme object is read from: window.__kitTheme.
const SandboxHelperArg = "__kit-confine"
SandboxHelperArg is the first argument of the helper process.
const SourceFile = "_harnessly/kit-source.json"
SourceFile records where the kit was made from, so `kit update` can make it again from a newer version.
Variables ¶
This section is empty.
Functions ¶
func ApplyProbe ¶
ApplyProbe adds to the kit's tokens what its stylesheets could not give: the custom properties the browser read (theme objects in JavaScript, values made of others) that tokens.json has not got yet. A token that is there is left as it is: its alias and its usage are better than a resolved copy. It returns how many tokens were added.
func DropSamples ¶
DropSamples takes the sample and variants away from components that do not draw alone (the render's verdict, by id → why), says why in their todo and in README.md, and leaves everything else as it is. The live preview and `kit check --render` then skip them.
func ReadSource ¶
ReadSource is the source a kit folder was made from (for `kit update`).
func RetrySamples ¶
RetrySamples changes the first sample of the components in ids for one more try at drawing them alone (attempt 1, 2, 3): 1 opens what can be opened and gives children a text; 2 also fills the label-like props; 3 puts two plain entries into every list prop. It reports the ids it changed; a component the attempt has nothing new for is left out, so the caller stops trying it.
func RunSandboxHelper ¶
RunSandboxHelper is the helper's main: `--net none|ports [--port N]… [--rw P]… [--ro P]… -- command args`. It does not return when it succeeds.
func SafeNpmSpec ¶
SafeNpmSpec is whether spec is a plain package (name[@version or range]) npm may be asked to install.
func SandboxAvailable ¶
func SandboxAvailable() bool
SandboxAvailable says whether a sandboxed run can be made on this machine.
Types ¶
type Export ¶
type Export struct {
Kind string `json:"kind"` // component or other
File string `json:"file,omitempty"` // the file that declares it, relative to the entry
Pos int `json:"pos,omitempty"` // where in that file: parts are drawn in the order they are written
Description string `json:"description,omitempty"`
Props []TypeProp `json:"props,omitempty"`
}
Export is one export: a component with its props, or something else (a hook, a function, a constant).
type Options ¶
type Options struct {
Source Source
Folder string // the kit folder (one theme): made when missing, updated when it holds this kit
ID string // the kit id; from the package name when empty
Namespace string // the window global; from the id when empty
Title string
Version string // a shadcn kit's version (a registry has none); an npm kit takes the package's
Root string // an npm kit's provider every board wraps its content in; found by itself when empty
React string // "19" for a kit that needs React 19 on the page; found from the package when empty
DraftOn bool // `--draft`: call `claude -p` on this machine for the cards the docs leave empty (off by default: it uses the machine's login)
NoDraft bool // no `claude -p` drafts for cards the package's own docs leave empty
CSS []string
License string // PrimeNG 22+: the PrimeUI license key (from the safe); empty = no key
Registry string // npm: --registry
From string // a folder with node_modules already installed: nothing is installed (offline, tests)
WorkDir string // the build folder; the user cache when empty
Cwd string // where the command runs: its .npmrc is used
// NoInstallScripts makes a package that asks for an install script (preinstall, install, postinstall) an error
// with the reason, not a silent skip: npm never runs scripts here (--ignore-scripts), and a kit that needs one
// would be half built. Set for a package an HTTP request names.
NoInstallScripts bool
// Sandbox runs npm and node under Landlock and seccomp (sandbox.go) and installs from a checked lock file: for a
// package an HTTP request names, or any package not yet trusted.
Sandbox bool
// SandboxHelper is the helper's command line up to the arguments it takes (this binary and SandboxHelperArg).
SandboxHelper []string
// AllowedHosts are the registry hosts a sandboxed install may fetch from, besides registry.npmjs.org and Registry's.
AllowedHosts []string
Log io.Writer
Npm func(dir string, args ...string) error // runs npm; exec when nil
Node func(dir string, args ...string) ([]byte, error) // runs node; exec when nil
Fetch func(loc string) ([]byte, error) // reads a registry address or file; http/disk when nil
Draft func(prompt string) (string, error) // writes card drafts from the package's docs (claude -p); exec when nil
}
Options say what to make the kit from and where.
type ProbeVar ¶
type ProbeVar struct {
Name string // with the leading --
Value string // resolved: calc(), color-mix() and var() chains are values
Dark string
}
ProbeVar is a CSS custom property a browser read from the kit drawn: see design.ProbeKit.
type PropChange ¶
type PropChange struct {
Component string `json:"component"`
Added []string `json:"added,omitempty"`
Removed []string `json:"removed,omitempty"`
Changed []string `json:"changed,omitempty"`
}
PropChange is how one component's props changed between the kit and the new version.
type Report ¶
type Report struct {
Source string `json:"source"`
Package string `json:"package,omitempty"`
Version string `json:"version"`
Previous string `json:"previous,omitempty"` // the kit's version before an update
Folder string `json:"folder"`
Components int `json:"components"`
Parts int `json:"parts"`
Providers int `json:"providers"`
Tokens int `json:"tokens"`
Added []string `json:"added,omitempty"`
Removed []string `json:"removed,omitempty"`
Changed []PropChange `json:"changed,omitempty"`
NotCarried []string `json:"notCarried,omitempty"` // what could not be read automatically, with why
ToWrite []string `json:"toWrite,omitempty"` // what a person writes next
Wrote []string `json:"wrote"`
}
Report is what a run did, for a person: what came in, what changed since the last run, what could not be read.
type Source ¶
type Source struct {
Kind string // npm or shadcn
Package string // npm: the package name
Version string // npm: the version asked for ("" = the newest)
Base string // shadcn: the registry (a folder or an address); "" = shadcn/ui itself
}
Source is what a kit is made from: an npm package or a shadcn registry.
func ParseSource ¶
ParseSource reads npm:<package>[@<version>] or shadcn:<registry>.