Prise en main
Quick start
Build dsfc from source, write a three-file package, check it, run its example and generate code.
1. Build dsfc
There is no release: build the compiler from source. You need Git and the Rust toolchain
pinned in the repository (rust-toolchain.toml, Rust 1.100.0); rustup installs it on first use.
git clone https://github.com/dsf-design/dsf.git
cd dsf
cargo build --release -p dsfc
./target/release/dsfc --version
# dsfc 0.1.0
The commands below assume dsfc is on your PATH (for example,
export PATH="$PWD/target/release:$PATH").
2. Write a package
A package is a directory. Its manifest, design-system.dsf, names the package and lists
the other source files, in order.
hello/
├── design-system.dsf
├── tokens.dsf
└── badge.dsf
# hello/design-system.dsf
design_system "hello" {
language_version = "0.1"
version = "0.1.0"
sources = ["tokens.dsf", "badge.dsf"]
}
Tokens are typed values. Without a resolver, top-level groups form the token tree.
# hello/tokens.dsf
group "color" {
type = "color"
token "accent" {
value = hex("#2459d6")
}
token "on-accent" {
value = hex("#ffffff")
}
}
group "space" {
type = "dimension"
token "base" {
value = dp(8)
}
}
A component declares its contract and its view. The example at the end is executable.
# hello/badge.dsf
component "Badge" {
description = "A short status label."
property "label" {
type = "string"
}
view {
stack "root" {
padding = insets(token.space.base / 2, token.space.base)
radius = "full"
background = token.color.accent
foreground = token.color.on-accent
text "label" {
value = prop.label
max_lines = 1
}
}
}
}
example "badge-padding" {
component = component.Badge
props = {
label = "New"
}
expect {
node "root" {
padding = insets(dp(4), dp(8))
}
}
}
3. Check
dsfc check hello
checked manifest, sources, syntax, tokens, components, behavior, accessibility, contrast, layout, rules, assets, examples; not checked: capabilities (no target named: pass --target <name>, or --config <dsf.hcl>)
3 tokens resolved in 1 permutation(s)
check always lists the stages it did not run, so a clean result never implies more than it
verified. Name the targets you will generate to check their capabilities too: each target is
produced in memory, exactly as build produces it, and nothing is written.
dsfc check hello --target swiftui --target angular
checked manifest, sources, syntax, tokens, components, behavior, accessibility, contrast, layout, rules, assets, examples, capabilities (swiftui, angular)
capabilities of swiftui: 6 native, 0 custom, 0 approximated, 0 fallback, 0 unsupported
capabilities of angular: 4 native, 0 custom, 0 approximated, 0 fallback, 0 unsupported
3 tokens resolved in 1 permutation(s)
Errors print as file:line:column: severity ID: message; see
Diagnostics.
4. Run the examples
dsfc test hello
test badge-padding ... ok
1 passed, 0 failed, 0 not run
5. Generate one target
dsfc build hello --target swiftui --output generated/swiftui
generated 6 file(s) for swiftui in generated/swiftui
The output is a Swift package: Package.swift, Sources/Hello/DSBadge.swift, tokens, and
Tests/HelloTests/ExampleTests.swift generated from the example. The other targets are
angular, dtcg and docs. Each output directory also gets dsf-build.json, which lists
the files and how each capability was realized. Nothing is written when an error is reported.
6. One command for every target
Next to hello/, add a project file:
# dsf.hcl
version = 1
package = "hello"
target "swiftui" {
output = "generated/swiftui"
}
target "angular" {
output = "generated/angular"
}
target "dtcg" {
output = "generated/tokens"
}
target "docs" {
output = "generated/docs"
options = { title = "Hello" }
palette = { accent = "color.accent", on-accent = "color.on-accent" }
}
dsfc generate
generated 6 file(s) for swiftui in generated/swiftui
generated 9 file(s) for angular in generated/angular
generated 1 file(s) for dtcg in generated/tokens
generated 4 file(s) for docs in generated/docs
Open generated/docs/index.html: the documentation of your package, themed with its own
accent color.
Next
- Every option of
dsf.hcl: Project configuration. - Learn the language, starting with Tokens and contexts.