Skip to main content

Module scaffold

Module scaffold 

Source
Expand description

Project-mode scaffolding framework + bock.project config-table parsing.

This module is the foundation for project-mode output (spec §20.6.2). It provides two things:

  1. Config parsing + validation. ScaffoldConfig::from_project_toml parses the per-target [targets.<T>] (deep) and [targets.<T>.scaffolding] (shallow) tables in bock.project, and validates every supplied value against the v1-supported variant matrix in §20.6.2. An unknown value is a ScaffoldError that names the documented options for that target. Fields left unset stay None — target-appropriate defaults are applied later (by S6 per-target scaffolders), not here.

  2. The Scaffolder abstraction. A Scaffolder takes the parsed per-target TargetScaffoldConfig plus the already-emitted module tree and produces additional OutputFiles — manifests, README first-contact instructions, formatter/linter configs, transpiled test files. scaffolder_for returns the per-target implementation.

Mode gating lives in the build driver, not here. bock build runs the scaffolder only in the default (project) mode, never under --source-only (spec §20.6.2: source mode emits “no manifests, scaffolding, or entry-point wiring”).

§Scope (S5 framework → S6a manifests → S6b enrichment)

S5 shipped the framework + config plumbing + mode gating; S6a relocated the minimal run-affordance manifests here. S6b (this stage) fills each per-target Scaffolder body with the full project-mode scaffolding:

  • a rich manifest referencing the selected/default test framework (package.json + tsconfig.json; pyproject.toml; Cargo.toml; go.mod),
  • a formatter config where applicable (Prettier for js/ts unless formatter=none; Black/Ruff in pyproject.toml; rustfmt/gofmt are universal/always-on, no config),
  • an opt-in linter config (shallow — emitted ONLY when [targets.<T>.scaffolding].linter is set),
  • a README first-contact honoring the package-manager hint.

Unset fields take the §20.6.2 target-appropriate defaults: js/ts → Vitest + Prettier + npm; python → pytest + Black + pip; rust → cargo test + rustfmt; go → stdlib testing + gofmt.

Deferred to S7 (NOT done here): the transpiled @test files (Vitest/Jest/pytest/cargo test/go test test code) and the formatter-clean --check release gate. S6b only sets up manifests/configs that reference the framework.

The v1-supported variant matrix (§20.6.2):

TargetTest frameworkFormatterLinterPackage manager
jsvitest (def), jestprettier (def), noneeslintnpm (def), pnpm, yarn
tsvitest (def), jestprettier (def), noneeslintnpm (def), pnpm, yarn
pythonpytest (def), unittestblack (def), ruff, noneruff, pylintpip (def), poetry, uv
rust(cargo test, universal)(rustfmt, universal)clippy(cargo only)
go(stdlib, universal)(gofmt, universal)golangci-lint(go mod only)

Rust/Go formatters and test frameworks are universal and always-on, so test_framework/formatter are not user-selectable for those targets; supplying them is a validation error.

Structs§

ScaffoldConfig
Validated scaffolding configuration for all five built-in targets.
ScaffoldContext
Context handed to a Scaffolder: the validated per-target config plus the module tree already emitted by codegen.
TargetScaffoldConfig
Typed, validated per-target scaffolding configuration.

Enums§

ScaffoldError
An error parsing or validating the bock.project scaffolding config.

Constants§

SCAFFOLD_TARGETS
Canonical target ids the config tables key on, matching crate::profile::TargetProfile ids and bock build target selection.

Traits§

Scaffolder
Produces project-mode scaffolding files for one target.

Functions§

effective_test_framework
The effective test framework for target given its validated config, applying the §20.6.2 target-appropriate default for any unset choice.
run_scaffolder
Run the per-target scaffolder and return its files, dropping any that collide with paths the codegen tree already emitted.
scaffolder_for
Returns the Scaffolder for target, or None for an unknown target id.