xfcmd
Script runner, CLI and VS Code support for .xfcmd scripts: short, readable sentences that scaffold FSCSS projects, check and enable component packages, and automate repeat work from npm scripts, CI and your editor.
say "Creating a starter project"
create file starter/styles/theme.fscss with:
$primary: #0BCEAE;
.btn { bg: $primary!; }
end
set entry {file}
compile
One package, two ways to use it:
- CLI and library from npm:
npm install -g xfcmd
- VS Code extension from this same repo: syntax highlighting, snippets, live diagnostics and run commands. It bundles the CLI, so there is nothing else to install.
The same sentence format runs inside the FSCSS IDE. Scripts, commands and package hooks live in the xfcmds/ folder of the FSCSS repo.
CLI
xfcmd run <file|command> run a script file, or a command from the registry
xfcmd check [files...|-] parse and lint scripts (no files: every .xfcmd here, - reads stdin)
xfcmd eval <sentence> run one sentence
xfcmd list registry commands, package hooks and local scripts
xfcmd libs [query|on|refresh] list or search components
xfcmd libck <name> load and check a package, then offer to enable it
xfcmd libon <name> enable a package (runs its enable script)
xfcmd liboff <name> disable a package (runs its disable script)
| Option |
Meaning |
--cwd <dir> |
workspace folder (default: current folder) |
--dry-run |
show what would happen, change nothing |
--var key=value |
set a script variable, repeatable (use it as {key}) |
--registry <dir\|url> |
use another registry (default: the FSCSS repo xfcmds/ folder) |
--compiler <module> |
FSCSS compiler module (default: fscss from node_modules) |
--fscss-version <v> |
compiler version used for package range checks |
--open <command> |
open created files in an editor, for example --open code |
--scope <ids> |
language scope for generated VS Code snippets |
-y, --yes |
answer yes to prompts |
--force |
enable a package even when checks failed |
--strict |
check: treat warnings as errors |
--json |
check, list: machine readable output |
Exit codes: 0 ok, 1 a script, check or package step failed, 2 usage error.
Examples
xfcmd run starter # registry command: theme, page and script in starter/
xfcmd run ./scripts/setup.xfcmd --dry-run # see what a script would do first
xfcmd check # lint every .xfcmd file in the project
xfcmd libck st-core --yes # check a package and enable it
xfcmd run setup.xfcmd --var name=billing # use {name} inside the script
What a script can do
Scripts are plain sentences. They are parsed completely before anything runs, and they are never evaluated as JavaScript.
| Sentence |
Effect |
say "text", warn "text", error "text" |
print |
create file <path> with: ... end |
create a file from the lines up to end (never overwrites) |
create file <path> with "text" |
create a file from one string |
open file <path>, set entry <path> |
choose the active and the entry file |
add import <name> |
add @import((*) from name) to the active FSCSS file |
compile, compile all |
compile with the installed FSCSS compiler into dist/ |
add snippet <key> "<title>" as "<body>" |
write a VS Code snippet to .vscode/xfcmd.code-snippets |
add snippets for helpers |
one snippet per helper of the package being enabled |
run command "<command>" |
compile run all preview ls open new libs clear theme routes deps resolve only |
wait <n> ms |
pause, up to 3000 ms |
Variables filled in at run time: {name} {version} {author} {description} {license} {repo} {import} {helpers} {fscss} {file}.
Safety, built in:
- File writes stay inside the workspace folder.
../ and absolute paths are refused.
- Existing files are kept, never overwritten.
- At most 200 sentences per script.
--dry-run changes nothing.
- Remote scripts and packages are fetched from
raw.githubusercontent.com only.
VS Code extension
Install the extension, open any .xfcmd file, and you get:
- syntax highlighting, including
create file ... with: blocks highlighted as the language of the file being created, and folding for them
- snippets for every sentence
- live diagnostics from
xfcmd check, using the unsaved buffer
- xfcmd: Run this script (also a play button in the editor title), Dry run, Check, and Run a command from the registry, with output in the xfcmd output channel
| Setting |
Default |
Meaning |
xfcmd.command |
empty |
empty uses the bundled CLI. Set xfcmd or npx xfcmd to use your own install |
xfcmd.checkOnType |
true |
check while typing |
xfcmd.extraArgs |
[] |
extra arguments for run commands, for example ["--registry", "./xfcmds"] |
xfcmd.command and xfcmd.extraArgs are machine scoped, so a project cannot change what the extension runs. Scripts do not run in untrusted workspaces. Checking and highlighting still work there. Arguments are passed as an array, never through a shell string, so file names with spaces or quotes are safe.
Requires VS Code 1.85 or newer.
Tasks and problems
The extension contributes a problem matcher, so CLI output shows up in the Problems panel from a task:
{
"version": "2.0.0",
"tasks": [{
"label": "xfcmd check",
"type": "shell",
"command": "npx xfcmd check",
"problemMatcher": "$xfcmd"
}]
}
CI
- run: npx xfcmd check --strict
Library
import { parse, runText, mkCtx, NodeHost } from 'xfcmd';
const { steps, errors, warnings } = parse(text);
const host = new NodeHost({ root: process.cwd(), dryRun: true });
await runText(text, mkCtx(null), host);
The runner talks to a host object, so you can run the same scripts against something other than the disk. The FSCSS IDE does exactly that in the browser. Subpath imports: xfcmd/parser, xfcmd/runner, xfcmd/node-host, xfcmd/pkg, xfcmd/cli.
Layout
bin/xfcmd.js CLI entry
src/ parser, runner, Node host, package client, file system model, CLI
vscode/ extension entry (extension.cjs), grammar, snippets, language configuration
test/ node:test suites, fixtures
src/vfs.js is the same file system module the FSCSS IDE uses. Keep the two copies in sync.
Develop
npm test # parser, runner, host, CLI, extension and packaging tests
npm run pack:npm # list what the npm tarball contains
npm run package:vsix
Node 18.17 or newer. No runtime dependencies.
Release
- Update
version in package.json and add a section to CHANGELOG.md.
npm test
- Commit, tag
v<version>, push the tag. The release workflow checks the tag matches package.json, runs the tests, publishes to npm and builds the .vsix. It publishes to the Marketplace when the VSCE_PAT secret exists.
Manual publishing works too: npm publish --access public, then npx @vscode/vsce publish.
Known limits
compile needs an FSCSS compiler that exposes process(text). Install fscss, or pass --compiler. Local @import paths are passed to the compiler as data: URIs, so the compiler must treat data: as a remote source.
- Preview is IDE only. In the CLI,
preview compiles instead.
- still working on it.
License
MIT