Skip to content

staticview CLI

The sv command adds @staticview/ui components to your project, creates and builds your own components, and generates their docs, types, and browser support report.

Installation

Terminal window
npm install @staticview/cli

Usage

Terminal window
npx sv <command> [options]
npx sv help <command>

Running from code

Each command has an execute…Command function that takes the command options in camelCase, like --out-name as outName.

import { executeBuildCommand } from "@staticview/cli";
await executeBuildCommand({ include: ["src/components/**/*.ts"] });

Options:

--help, -h optional

Show the commands and the options of the CLI.

Subcommands:

add, copy

Copy components from the @staticview/ui package into your project. The command asks for --outdir, --components, and --type when you leave them out.

Options:

--list, -l optional

List the component names that --components takes.

--type, -t <raw|minified> optional

raw copies the source files of each component, to change or to build with sv build, and minified copies one built and minified script, ready to load.

--outdir, -o <directory> optional

The directory that gets one folder for each component.

--components, -n <components> optional

The component names, separated by commas, as --list prints them.

Example:

Terminal window
--components accordion,alert,dialog

--overwrite, -f optional

Whether to overwrite the files of a component that is already in --outdir. Without it, the command stops with an error at the first such component.

default: false

--cwd optional

The directory that a relative --outdir resolves against.

default: cwd


docs, generate-docs

Generate docs from the source of web components: a Markdown page for each component, VS Code HTML custom data, a custom elements manifest, and JetBrains web-types.

Options:

--include, -i <patterns>

Glob patterns, separated by |, of the component files.

Example:

Terminal window
--include "src/components/**/*.{ts,js}|dist/**/*.js"

--ignore, -g <patterns> optional

Glob patterns, separated by |, of the files to skip.

default: ["**/*.d.ts","**/*-types.ts"]

Example:

Terminal window
--ignore "**/*.d.ts"

--markdown, --md optional

Whether to write a Markdown page for each component.

default: true

Example:

Terminal window
--no-markdown

--markdown-outdir, --md-out <directory> optional

The directory of the Markdown pages. Without it, each page goes next to its component file.

--markdown-name, --md-name <fileName> optional

The file name of each Markdown page, where {fileName} stands for the component file name without its extension and {tagName} for the tag name.

default: "{tagName}.md"

--html-data optional

Whether to write the HTML custom data file to list in the html.customData setting of VS Code.

default: true

Example:

Terminal window
--no-html-data

--html-data-out <file-path> optional

The path of the VS Code HTML custom data file.

default: "custom.html-data.json"

--manifest optional

Whether to write the custom elements manifest.

default: true

Example:

Terminal window
--no-manifest

--manifest-out <file-path> optional

The path of the custom elements manifest.

default: "custom-elements.json"

--web-types optional

Whether to write the web-types file for JetBrains IDEs.

default: true

Example:

Terminal window
--no-web-types

--web-types-out <file-path> optional

The path of the web-types file.

default: "web-types.json"

--cwd optional

The directory that the patterns and the relative output paths resolve against.

default: cwd


types

Generate the TypeScript types of the component tags for each framework.

Options:

--include, -i <patterns>

Glob patterns, separated by |, of the component files.

--ignore, -g <patterns> optional

Glob patterns, separated by |, of the files to skip.

default: ["**/*.d.ts","**/*-types.ts"]

--outdir, -o <directory> optional

The directory that gets a folder for each framework, with a file for each component and an index file that imports them all. Without it, each component file gets a <framework>-types file next to it for each framework.

--out-ext, -e <extension> optional

The extension of the type files.

default: "d.ts"

--frameworks, -f <frameworks>

The frameworks to generate types for, separated by commas, or all.
Valid values: "all", "react", "react18", "preact", "solid", "svelte", "vue", "qwik", "astro", "jsxDom", "dom", "global".

Example:

Terminal window
--frameworks react,svelte

--flat optional

With --outdir, write one <framework>-types file for each framework with all components, in place of a folder for each framework.

default: false

Example:

Terminal window
--flat

--jsdoc optional

Whether to copy the docs of each component into its types as JSDoc comments, for the editor to show on hover.

default: true

Example:

Terminal window
--no-jsdoc

--cwd optional

The directory that the patterns and a relative --outdir resolve against.

default: cwd


browser-support

Generate a report of the browsers that the web components work in, as JSON and Markdown.

Options:

--include, -i <patterns>

Glob patterns, separated by |, of the component files.

Example:

Terminal window
--include "src/components/**/*.ts"

--ignore, -g <patterns> optional

Glob patterns, separated by |, of the files to skip.

default: ["**/*.d.ts","**/*-types.ts"]

Example:

Terminal window
--ignore "**/*.test.ts"

--tsconfig <file-path> optional

The tsconfig that the component scripts compile with. The search for .browser-support.json and the browserslist config starts in its directory.

default: "tsconfig.json"

--json optional

Whether to write the JSON report.

default: true

Example:

Terminal window
--no-json

--json-out <file-path> optional

The path of the JSON report.

default: "BROWSER-SUPPORT.json"

--markdown, --md optional

Whether to write the Markdown report.

default: true

Example:

Terminal window
--no-markdown

--markdown-out, --md-out <file-path> optional

The path of the Markdown report.

default: "BROWSER-SUPPORT.md"

--cwd optional

The directory that the patterns, --tsconfig, and the report paths resolve against.

default: cwd


create

Create a new component from the @staticview/ui template, as a .ts, .html, .css, and .md file named after the last folder of --outdir.

Options:

--ask, -a optional

Whether to ask for --outdir and --tag-name when you leave them out.

--outdir, -o <directory> optional

The folder of the new component, which must not exist yet. Required unless --ask is set.

Example:

Terminal window
--outdir src/components/accordion

--tag-name, -t <tag-name> optional

The tag name of the component, made of lowercase letters, digits, and hyphens and starting with sv-. Required unless --ask is set.


build

Build each component file into one script with its HTML and CSS inlined.

A file with a value import or export is an ES module, and it builds without --iife, --minify-css-classes, and --minify-css-variables.

Options:

--include, -i <patterns>

Glob patterns, separated by |, of the component files.

--ignore, -g <patterns> optional

Glob patterns, separated by |, of the files to skip.

default: ["**/*.d.ts","**/*-types.ts"]

--out-dir <directory> optional

The directory of the built scripts. Without it, each script goes next to its component file.

--out-name <fileName> optional

The file name of each built script, where {fileName} stands for the component file name without its extensions.

default: "{fileName}.min.js"

--production, --prod optional

Sets the default of --minify.

default: true

--iife optional

Whether to wrap the component in a block that runs only where HTMLElement exists. With it, importing the component during server-side rendering does nothing instead of throwing, and a script that is not an ES module keeps its top-level names out of the global scope.

default: true

--minify optional

Sets the default of --minify-js, --minify-css, --minify-css-classes, --minify-css-variables, and --minify-html.

--minify-js optional

Whether to minify the component script with oxc-minify, then @swc/core.

--minify-css optional

Whether to minify the embedded CSS with the cssnano advanced preset.

--minify-html optional

Whether to minify the inline SVG of the embedded HTML with svgo, and the HTML with html-minifier-terser.

--minify-css-classes optional

Whether to shorten the class names in the embedded CSS and HTML and in the component script. Give a class name that the script builds at runtime an ignored prefix, like _, because the build cannot rename it and logs a warning.

--minify-css-classes-ignore-prefix <prefix> optional

Prefixes, separated by |, of the class names that --minify-css-classes leaves as they are.

default: ["_"]

--minify-css-variables optional

Whether to shorten the custom property names in the embedded CSS and in the component script. Give an ignored prefix to a custom property that a style attribute in the embedded HTML uses or that the script names at runtime, because the build cannot rename it there.

--minify-css-variables-ignore-prefix <prefix> optional

Prefixes, separated by |, of the custom properties that --minify-css-variables leaves as they are, like the public ones that a page sets. A prefix has no leading --.

default: ["sv-","_"]

--disabled-trims <trims> optional

Trims to skip, separated by |. A trim is a small output saving that the minifiers do not make, and it runs when its minifier runs.

--minify-css runs these trims:

  • minifyCustomPropertyValues drops the spaces in custom property values and shortens their numbers.
  • removeMathOperatorSpaces drops the spaces around * and /.
  • useBooleanMediaFeatures writes media features like (forced-colors: active) as (forced-colors).
  • useShortTransparentColor writes transparent as #0000 in color properties.

--minify-js runs these trims:

  • useGlobalParseFunctions replaces Number.parseFloat and Number.parseInt with the global functions.
  • useNumbersForDomBooleans writes 1 and 0 for true and false where the DOM reads a boolean.
  • removeUnreachableSwitchDefault removes a default: that only throws, in the switch of attributeChangedCallback or with satisfies never.
  • replaceStringSwitchWithIfChain replaces a switch on a variable whose cases are all strings with an if chain.
  • inlineEventFactories moves a static _events factory that has one caller into that call.
  • privatizeUnderscoreMembers turns class members named with one leading underscore into private members.
  • inlinePrivateFieldAliases replaces a local that holds a private field with the field.
  • inlineSingleUseArrowFields moves an arrow in a private field into the one call that passes it.
  • inlineSingleUseLocals moves the value of a local that code reads once into that read.
  • moveConstructorIntoField moves the constructor body of a component into a last private field.
  • removeFalsyFieldInitializers removes a false or null field value that code cannot tell from undefined.
  • hoistStaticPrivateFields moves the static private and underscore fields of a class into variables above it.
  • hoistStaticPrivateMethods does the same for static methods, which turn into arrow functions.
  • defineReflectedPropertiesInLoop replaces the getter and setter pairs that only reflect an attribute with one loop that defines them.
  • declareConstantsWithLet declares each const that no code writes to as let.

--minify-html runs these trims:

  • useCommasInSvgNumbers writes the numbers of SVG viewBox and d with commas.
  • omitImpliedEndTags removes the end tags and self-closing slashes that the HTML parser implies.

default: []


help <command>

Show the options of a command.

Arguments:

command

The command to show help for.