tom_build_base_v2 library
tom_build_base v2 - Unified CLI framework for workspace traversal.
This library provides:
- Structured traversal configuration (
TraversalInfo) - Automatic folder scanning and nature detection
- Filter pipelines for flexible project selection
- Type-safe command context (CommandContext)
Quick Start
import 'package:tom_build_base/tom_build_base_v2.dart';
void main() async {
await BuildBase.traverse(
info: ProjectTraversalInfo(
scan: '.',
recursive: true,
executionRoot: Directory.current.path,
),
run: (ctx) async {
print('Processing: ${ctx.name}');
return true;
},
);
}
Classes
- AnchorWalker
- Walks up the directory tree to find "anchor" directories.
- AnsiColors
- ANSI color codes for terminal output.
- BaseTraversalInfo
- Base class for traversal configuration.
- BoundaryFinding
- One finding of a BoundaryReport: a broken boundary or a broken rule.
- BoundaryReport
- The outcome of checkContextBoundaries.
- BoundedContext
- One bounded context of a ContextBoundaryRules.
- BuildBase
- Main entry point for workspace traversal.
- BuildkitFolder
- Buildkit configuration nature: the project file.
- BuildOrderComputer
- Computes build order for Dart projects using topological sort.
- BuildOrderCycle
- One dependency cycle: a strongly connected group of projects.
- BuildOrderEdge
- A dependency of one project on another, as the build order sees it.
- BuildOrderResult
- Outcome of a build-order computation.
- BuildRunnerFolder
- Build runner (build.yaml) nature.
- CallbackExecutor
- Callback-based command executor.
- CFolder
-
C project nature: a
Makefile/CMakeLists.txtwith C sources (.c) and no C++ sources. - CliArgParser
- Parser for command-line arguments.
- CliArgs
- Parsed command-line arguments.
- CommandContext
- Context provided to commands during execution.
- CommandDefinition
- Definition of a command within a multi-command tool.
- CommandExecutor
- Base class for command executors.
- CompletionGenerator
- Generates shell completion scripts from tool definitions.
- ConsoleMarkdownSink
-
A StringSink that applies
.toConsole()to every line written. - ContextBoundaryRules
-
The rules of a package, read from its
buildkit.yaml. - CppFolder
-
C++ project nature: a
Makefile/CMakeLists.txtwith C++ sources (.cpp,.cc,.cxx,.hpp, ...). - DartConsoleFolder
- Dart console application nature.
- DartDirective
- One directive: its kind, the URIs it names (a conditional import names more than one) and the 1-based line of its first URI.
- DartExecutor
- Executor that invokes a Dart function for each project.
- DartPackageFolder
- Dart package nature (library).
- DartProjectFolder
- Base class for Dart project natures.
- ExecutePlaceholderContext
- Context for resolving execute command placeholders.
- ExecutePlaceholderResolver
- Resolves placeholders in command strings for execute commands.
- FilterPipeline
- Applies filters to folder lists based on TraversalInfo configuration.
- FlutterProjectFolder
- Flutter project nature.
- FolderContext
- A scanned folder with its detected natures.
- FolderScanner
- Scans directories and builds a list of FsFolders.
- FolderSorter
- Sorts folders based on traversal configuration.
- FsFolder
- Filesystem folder during scanning (minimal info).
- GitFolder
- Git repository nature.
- GitRepoFinder
- Finds git repositories under a given root.
- GitTraversalInfo
- Configuration for git repository traversal.
- GoFolder
-
Go project nature: a
go.mod. - HelpGenerator
- Generates help text from tool and command definitions.
- HelpTopic
-
A named help topic that can be shown via
tool help <name>. - ItemResult
- Result for a single processed item (folder/project).
- JavaFolder
-
Java project nature: a
pom.xml,build.gradleorbuild.gradle.kts. - JavaScriptFolder
-
JavaScript project nature: a
package.jsonwithout atsconfig.json. - LanguageDetector
- Detects the non-Dart language natures of a folder from its project files (LanguageProjectFolder and its subtypes, TypeScript excepted: the NatureDetector creates that one with the VS Code natures).
- LanguageProjectFolder
- A project in one of the SOM runtime languages other than Dart, detected by its project file: TypeScript, JavaScript, Python, Java, Go, Rust, C and C++.
- ListExecutor
- No-op executor that just lists folders.
- MkLinkExecutor
- Generic cross-platform symbolic-link executor.
- NativeProjectFolder
-
A C or C++ project: a
MakefileorCMakeLists.txtbeside the sources that decide the language (CFolder, CppFolder). - NatureDetector
- Detects and creates folder natures based on filesystem markers.
- Navigation features supported by a tool.
- NestedToolExecutor
- Executor that delegates to an external tool binary.
- OptionDefinition
- Definition of a CLI option.
- OutputSpec
-
A parsed
--output <format>[:<file>]specification. - PerCommandArgs
- Per-command arguments for multi-command tools.
- PipelineCommandPrefixParser
- PipelineCommandSpec
- PipelineDefinition
- PipelineOptionResolver
- PipelineStepConfig
- ProcessingResult
- Result of a traversal operation.
- ProjectTraversalInfo
- Configuration for project-based traversal.
- ProjectVersionFile
- The version field of a project file: read it, and write a new one with the rest of the file as it was.
- PubCacheIntegrity
- Checks that every hosted package a project has locked is really in the pub cache.
- PubCacheProblem
- One locked package that the pub cache cannot supply.
- PythonFolder
-
Python project nature: a
pyproject.toml,setup.pyorsetup.cfg. - RepositoryIdLookup
- Lookup helper for repository IDs.
- RunFolder
- Base class for folder natures detected during execution.
- RustFolder
-
Rust project nature: a
Cargo.toml. - ScanResults
- Result of workspace scanning with nature detection.
- ShellExecutor
- Executor that runs a shell command in each folder.
- SyncExecutor
- Synchronous callback-based executor.
- TomBuildFolder
-
Tom project configuration nature (
tom_project.yaml). - TomBuildMasterFolder
- Tom build master configuration nature.
- ToolDefinition
- Definition of a CLI tool for buildkit and similar applications.
- ToolDefinitionSerializer
- Serializes a ToolDefinition tree to YAML format.
- ToolPipelineConfig
- ToolPipelineConfigLoader
- ToolPipelineExecutor
- ToolResult
- Result of running a tool or command.
- ToolRunner
- Runs tools based on their definitions.
- ToolWiringEntry
- Describes how a nested tool is wired into a host tool.
- TraversalDefaults
- Traversal defaults loaded from buildkit_master.yaml navigation section.
- TypeScriptFolder
- TypeScript project nature.
- VsCodeExtensionFolder
- VS Code extension nature.
- WiringLoader
- Loads and resolves nested tool wiring for a host tool.
- WiringResult
- Result of loading and resolving wired tool definitions.
- Parsed navigation options for workspace traversal.
- WorkspaceScanner
- Scans workspace directories and detects folder natures.
Enums
- DartDirectiveKind
- The kind of a DartDirective.
- ExecutionMode
- Represents the execution mode for a tool.
- GitTraversalMode
- Git traversal order mode.
- GitTraversalOrder
- Git traversal order when both inner-first and outer-first are valid.
- JavaBuildTool
- The build tool of a JavaFolder.
- NativeBuildSystem
- The build system of a C or C++ project.
- OptionType
- Type of option value.
- OutputFormat
- Supported CLI output formats.
- PipelineCommandPrefix
- PubCacheProblemKind
- How a locked package fails to be usable from the pub cache.
- ShellType
- Shell type for completion scripts.
- SpecialCommandResult
- Result of checking for special commands.
- ToolMode
- Mode in which a tool can operate.
- WiringMode
- Mode for how a nested tool is wired into a host tool.
Extensions
-
CommandListOps
on List<
CommandDefinition> - Extension methods for manipulating command lists.
- ToolDefinitionCompletion on ToolDefinition
- Extension to generate completions.
Constants
-
commonOptions
→ const List<
OptionDefinition> - Common options for all tools.
-
defaultHelpTopics
→ const List<
HelpTopic> - All built-in help topics that apply to every tool.
- definesHelpTopic → const HelpTopic
- Help topic documenting the defines system.
-
gitTraversalOptions
→ const List<
OptionDefinition> - Standard options for git traversal.
-
kAlwaysSkipDirectories
→ const Set<
String> - Directories that should always be skipped during recursive scanning.
- kBoundariesSection → const String
-
The
buildkit.yamlkey the rules are read from. - kBuildkitGroupYaml → const String
- The file that marks a directory as a project group.
- kBuildkitMasterYaml → const String
- Filename for the workspace-level buildkit configuration.
- kBuildkitSkipYaml → const String
- Filename for the buildkit skip marker.
- kConsoleMarkdownZoneKey → const Symbol
- Zone-local key that indicates console_markdown rendering is active.
- kTomCodeWorkspace → const String
- Filename of a VS Code workspace file that once marked the workspace root.
- kTomSkipYaml → const String
- Filename for the global skip marker (all tools).
-
languageProjectFiles
→ const List<
String> - Project files that make a folder a project in one of the non-Dart languages, apart from C / C++ (see isProjectFolder).
- macrosHelpTopic → const HelpTopic
- Help topic documenting the macro system.
-
masterYamlHelpTopics
→ const List<
HelpTopic> -
Help topics for tools that use a
{tool}_master.yamlconfiguration file. - pipelinesHelpTopic → const HelpTopic
- Help topic documenting pipeline configuration.
- placeholdersHelpTopic → const HelpTopic
- Help topic documenting placeholder and environment variable usage.
-
projectTraversalOptions
→ const List<
OptionDefinition> - Standard options for project traversal.
- wiringHelpTopic → const HelpTopic
- Help topic documenting nested tool wiring.
Properties
- isConsoleMarkdownActive → bool
-
Returns
trueif the current zone already applies console_markdown.no setter
Functions
-
Add standard navigation options to an
ArgParser. -
cargoIdentity(
String text) → ProjectIdentity -
Name and version of a
Cargo.toml's[package]. -
checkContextBoundaries(
String projectPath, {ContextBoundaryRules? rules, bool? includeTests}) → BoundaryReport -
Checks the package at
projectPathagainst itsboundaries:rules (ruleswhen given, else read from itsbuildkit.yaml).includeTestsoverrides the rules'tests:flag. -
currentToolOriginLine(
) → String - toolOriginLine for the process running now.
-
decodeProcessOutput(
Object? raw) → String - Decode raw process output as UTF-8, tolerating malformed byte sequences.
-
describeUnmatchedGroups(
List< String> groups, {required String scanRoot}) → String - The error message for ProcessingResult.unmatchedGroups, worded like describeUnmatchedProjectPatterns.
-
describeUnmatchedProjectPatterns(
List< String> patterns, {required String scanRoot}) → String - The error message for ProcessingResult.unmatchedProjectPatterns.
-
enableUtf8Console(
) → void - Switch the process to UTF-8 console output so non-ASCII tool output renders correctly.
-
expandMacros(
List< String> args, Map<String, String> macros) → List<String> - Expand macros in argument list.
-
findWorkspaceRoot(
String startPath) → String -
The workspace root of
startPath(findWorkspaceRootOrNull), orstartPathitself when it is not inside a workspace. -
findWorkspaceRootOrNull(
String startPath) → String? -
The workspace root: the nearest directory at or above
startPaththat holdsbuildkit_master.yaml, or null when there is none. -
generatePlainCommandHelp(
ToolDefinition tool, CommandDefinition cmd) → String - Generate plain-text help for a command (no ANSI colors).
-
generatePlainToolHelp(
ToolDefinition tool) → String - Generate plain-text tool help (no ANSI colors).
-
getExecutionModesHelpLines(
) → List< String> - Returns execution modes explanation lines.
-
getRequiredArgCount(
String macroValue) → int - Get the number of required arguments for a macro.
-
goModulePath(
String text) → String? -
The module path of a
go.mod. -
handleSpecialCommands(
List< String> args, ToolDefinition tool, {void printer(String)?, String toolHelpGenerator(ToolDefinition)?, String commandHelpGenerator(ToolDefinition, CommandDefinition)?, String versionGenerator(ToolDefinition)?}) → SpecialCommandResult - Check for and handle special commands (help, version).
-
isBinaryOnPath(
String binary) → bool - Check if a binary is available on the system PATH.
-
isFlutterPackage(
String directory) → bool -
Whether the package in
directoryis a Flutter package (pubspecDeclaresFlutterSdk on itspubspec.yaml). A missing or unreadable pubspec is not one. -
isHelpCommand(
List< String> args) → bool - Check if the first argument is a help command.
-
isProjectFolder(
String dir) → bool -
Whether
diris a project folder of any language the build tools know: apubspec.yaml, one of languageProjectFiles, or a make / CMake file beside C or C++ sources. -
isVersionCommand(
List< String> args) → bool - Check if the first argument is a version command.
-
isWorkspaceBoundary(
String dirPath) → bool - Check if a directory is a workspace boundary (contains buildkit_master.yaml).
-
killProcessTree(
int pid) → Future< void> -
Kills the process
pidand every process it started, children before parents, with SIGKILL (taskkill /T /Fon Windows). -
nativeSourceLanguages(
String dir) → Set< String> -
The native languages whose sources lie in
diror up to three levels below it:cfor.cfiles,cppfor C++ sources and headers. A.hheader says neither. -
packageScripts(
Map< String, dynamic> json) → Map<String, String> -
The
scriptsof apackage.jsonobject. -
Parse navigation options from
ArgResults. -
pomIdentity(
String text) → ProjectIdentity -
The project's own
<artifactId>and<version>of apom.xml. -
preprocessRootFlag(
List< String> args) → (List<String> , bool) - Preprocess command-line arguments to handle special -R behavior.
-
printExecutionModesHelp(
) → void - Prints execution modes explanation to stdout.
-
projectGroupsOf(
String projectPath, String executionRoot) → Set< String> -
The names of the groups the project at
projectPathbelongs to. -
pubspecDeclaresFlutterSdk(
Object? pubspec) → bool -
Whether a parsed
pubspec.yamlpubspecdeclares the Flutter SDK as a dependency: -
pyprojectIdentity(
String text) → ProjectIdentity -
Name and version of a
pyproject.toml:[project], else[tool.poetry]. -
readPackageJson(
File file) → Map< String, dynamic> -
The JSON object of a
package.json, or an empty map when it does not parse. -
resolveBinary(
String binary) → String - Platform-aware binary resolution and checking utilities.
-
resolveDartExecutable(
{String? resolvedExecutable, Map< String, String> ? environment, bool exists(String path)?}) → String -
The
dartexecutable to use when a tool needs to spawn an SDK command. -
resolveExecutionRoot(
required String currentDir}) → String - Determine the execution root based on navigation args.
-
runBinary(
String binary, List< String> args, String workingDirectory) → Future<ProcessResult> - Run a binary with the given arguments in a working directory.
-
runBinaryStreaming(
String binary, List< String> args, String workingDirectory) → Future<int> - Run a binary with streaming output directly to stdout/stderr.
-
runWithConsoleMarkdown<
T> (Future< T> body(), {void onError(Object error, StackTrace stack)?}) → Future<T> -
Run
bodyinside a Dart zone that automatically renders console_markdown syntax in everyprint()call. -
runWithConsoleMarkdownSync<
T> (T body(), {void onError(Object error, StackTrace stack)?}) → T - Synchronous variant of runWithConsoleMarkdown for tools that don't need async (rarely used — prefer the async version).
-
scanDartDirectives(
String source) → List< DartDirective> -
The directives of
source, in order. -
scanForDartProjects(
String dir, {bool recursive = false, bool includeTestProjects = false, bool verbose = false}) → List< String> - Scan a directory for Dart projects (directories containing pubspec.yaml).
-
tomlTableStrings(
String text, String table) → Map< String, String> -
The string values of one table of a TOML document (
[project],[package],[tool.poetry]):key = "value"/key = 'value'lines, comments and other value types ignored. Enough for a project file's name and version; not a TOML parser. -
toolOriginLine(
{required String resolvedExecutable, required Uri script}) → String -
The origin line for a run whose executable is
resolvedExecutableand whose entry point isscript. -
unmatchedGroups(
Iterable< String> projectPaths, List<String> groups, String executionRoot) → List<String> -
The
groupsthat no project inprojectPathsbelongs to, in the order given and each once. -
validateProjectPathsExist(
List< String> projectPatterns, String executionRoot) → String? -
Validate that every path-style, non-glob
--projectpattern resolves to an existing directory underexecutionRoot. -
validateProjectPathsWithinRoot(
List< String> projectPatterns, String executionRoot) → String? -
Validate that no absolute
--projectpattern points outsideexecutionRoot. -
validateScanPathWithinRoot(
String scan, String executionRoot) → String? -
Validate that the
--scanpath does not point outsideexecutionRoot.
Typedefs
- ProjectIdentity = ({String? name, String? version})
- A project's name and version as its project file states them.
Exceptions / Errors
- MacroExpansionException
- Exception thrown when macro expansion fails.
- UnresolvedPlaceholderException
- Exception thrown when a placeholder cannot be resolved.