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
npm install @staticview/cliUsage
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:
--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:
--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:
--ignore "**/*.d.ts"--markdown, --md optional
Whether to write a Markdown page for each component.
default: true
Example:
--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:
--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:
--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:
--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:
--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:
--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:
--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:
--include "src/components/**/*.ts"--ignore, -g <patterns> optional
Glob patterns, separated by |, of the files to skip.
default: ["**/*.d.ts","**/*-types.ts"]
Example:
--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:
--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:
--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:
--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:
minifyCustomPropertyValuesdrops the spaces in custom property values and shortens their numbers.removeMathOperatorSpacesdrops the spaces around*and/.useBooleanMediaFeatureswrites media features like(forced-colors: active)as(forced-colors).useShortTransparentColorwritestransparentas#0000in color properties.
--minify-js runs these trims:
useGlobalParseFunctionsreplacesNumber.parseFloatandNumber.parseIntwith the global functions.useNumbersForDomBooleanswrites1and0fortrueandfalsewhere the DOM reads a boolean.removeUnreachableSwitchDefaultremoves adefault:that only throws, in theswitchofattributeChangedCallbackor withsatisfies never.replaceStringSwitchWithIfChainreplaces aswitchon a variable whose cases are all strings with anifchain.inlineEventFactoriesmoves a static_eventsfactory that has one caller into that call.privatizeUnderscoreMembersturns class members named with one leading underscore into private members.inlinePrivateFieldAliasesreplaces a local that holds a private field with the field.inlineSingleUseArrowFieldsmoves an arrow in a private field into the one call that passes it.inlineSingleUseLocalsmoves the value of a local that code reads once into that read.moveConstructorIntoFieldmoves the constructor body of a component into a last private field.removeFalsyFieldInitializersremoves afalseornullfield value that code cannot tell fromundefined.hoistStaticPrivateFieldsmoves the static private and underscore fields of a class into variables above it.hoistStaticPrivateMethodsdoes the same for static methods, which turn into arrow functions.defineReflectedPropertiesInLoopreplaces the getter and setter pairs that only reflect an attribute with one loop that defines them.declareConstantsWithLetdeclares eachconstthat no code writes to aslet.
--minify-html runs these trims:
useCommasInSvgNumberswrites the numbers of SVGviewBoxanddwith commas.omitImpliedEndTagsremoves 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.