Let people try a CLI for real without installing anything: a static page that boots a Node.js sandbox (WebContainers) in the visitor's browser and opens a real shell, with the project's own code and sample data mounted.
npm install --save-dev @soleone/showcase-terminal
showcase-terminal --serve # builds demo/browser into dist/browser, serves it on 127.0.0.1:4321
showcase-terminal path/to/recipe --out dist/demoIt is one way to give a CLI the live demo that showcase grades S, and it reads the project's facts from the same showcase.json. It doesn't need showcase installed.
Keep the recipe folder in the project itself (demo/browser/ by default), so the project owns its sample data and stand-ins. Relative paths in it resolve from the recipe folder. It holds terminal.json:
project: the project folder. Title, pitch and repo come from itsshowcase.json, and the page's disclosure line is written fromdemo.externals(each stand-in'snote).mount: target path in the sandbox →{ from, include }.frommay use~and$VARS;includelimits the top-level entries copied. Binary files (images, loops) are mounted too.env: values may use~(the sandbox home, always/home/demo) and$PATH(costs one extra process at boot; write the PATH out instead).setup: commands run before the shell opens, e.g. seeding sample data dated relative to today. Until they finish, a spinner stands in for the prompt and keys typed in the terminal are dropped, so nothing ends up in front ofstart.start: a command typed into the shell once setup is done, to open the program right away (e.g. a TUI). The visitor sees it run and can run it again after quitting.onTheme: a command run whenever the visitor picks a theme. Before it runs, the page writes~/.config/showcase/theme.jsonwith the theme's colors and the full terminal palette (palette, as hex), so a program that draws its own colors can follow the page. The file is also written once beforesetup.welcome,hints(buttons that type a command),seed(a browser module that adds files computed at visit time, such as dates relative to today), and overrides fortitle,pitch,repo,disclosure,defaultTheme(a name fromthemes.json, default the first).skin: a folder or URL with the page's look,themes.json(palettes, same shape aspage/themes.json)skin.css(fonts and other touches, loaded after the page's styles) andskin.js(a theme picker, below). Any of them may be left out. Without a skin the page is plain: a dark and a light theme and system fonts.
The output is static: index.html, files.json, terminal.json, themes.json, skin.css, skin.js when the skin has one, fonts/ and a vercel.json with the COOP/COEP headers the sandbox needs.
The terminal font is JetBrainsMono Nerd Font Mono, self-hosted as WOFF2 (about 600 KB per weight) so CLI icons render. page/fonts/build.sh rebuilds it from a pinned Nerd Fonts release, keeping the Basic Multilingual Plane and dropping the Material Design plane.
Sandbox quirks found so far:
- Mounted files are not executable;
chmodthem from a setup script (one process is faster than several setup commands). - Extensionless ES modules exit silently, so command shims are CommonJS that
import()the real entry point. - A top-level
for awaitfails to parse; read streams with events. - Model calls: point the project at a stand-in (a setting that names the model command) that returns canned output, so nothing leaves the browser.
WebContainers is free for personal and open-source use; check the StackBlitz license before using it commercially.
The page has a theme picker when there is more than one theme (the choice is remembered in the visitor's browser). A theme colors the page and the terminal's 16 ANSI colors together, so whatever the CLI prints follows it; the bright colors are derived from the normal ones.
A skin can bring its own picker as skin.js, an ES module whose default export the page calls once the terminal is up, instead of drawing its dropdown:
export default function ({ themes, current, apply, mount }) {
// themes: the entries of themes.json; current: the one in use
// apply(theme): recolors the page and the terminal, tells the sandbox (onTheme) and remembers the choice
// mount: an empty element in the page header for the picker's button
}The page keeps its state where a theme kit can read it: data-theme on <html> is the theme's name, data-mode and the dark class its mode. Its own colors are the CSS variables --page, --ink, --ink-strong, --ink-muted, --highlight, --surface, --line and --terminal.
From code:
import { buildTerminal, serveTerminal } from "@soleone/showcase-terminal";
await buildTerminal("demo/browser", "dist/browser");Deploy the output folder to any static host that can set the COOP/COEP headers. On Vercel the generated vercel.json sets them: vercel deploy --prod from the folder.
MIT