clay library
Core library for Clay — config, transforms, generation, and validation.
Clay turns runnable reference projects into Mason brick templates using
comment-based annotation markers in source files and a clay.yaml
config file.
Reference authors mark up files with comment tokens such as
/*remove-start*/, #replace-start#, or <!--partial v header-->.
During generation, markers are resolved and removed from the output tree.
See the annotation reference for full marker syntax, comment flavors, and examples.
Classes
- AnnotationIssue
- A single annotation validation problem in a reference file.
- ClayConfig
-
Parsed
clay.yamlconfiguration. -
ClayConfigCopyWith<
$R, $In extends ClayConfig, $Out> - ClayConfigMapper
- ClayEnvironment
-
Semver environment constraints declared in
clay.yaml. -
ClayEnvironmentCopyWith<
$R, $In extends ClayEnvironment, $Out> - ClayEnvironmentMapper
- DiscoveredClayConfig
-
Result of locating
clay.yamland its project root. - LineDeletion
- Line ranges to drop from a specific target file.
-
LineDeletionCopyWith<
$R, $In extends LineDeletion, $Out> - LineDeletionMapper
- LineRange
- An inclusive, zero-based line range within a target file.
-
LineRangeCopyWith<
$R, $In extends LineRange, $Out> - LineRangeMapper
- Replacement
- A regex replacement applied to file paths and contents.
-
ReplacementCopyWith<
$R, $In extends Replacement, $Out> - ReplacementMapper
Mixins
Extensions
-
ClayConfigValueCopy
on ObjectCopyWith<
$R, ClayConfig, $Out> -
ClayEnvironmentValueCopy
on ObjectCopyWith<
$R, ClayEnvironment, $Out> -
LineDeletionValueCopy
on ObjectCopyWith<
$R, LineDeletion, $Out> -
LineRangeValueCopy
on ObjectCopyWith<
$R, LineRange, $Out> -
ReplacementValueCopy
on ObjectCopyWith<
$R, Replacement, $Out>
Constants
-
binaryContentBasenames
→ const Set<
String> - Basenames copied to output without text transforms.
-
binaryContentExtensions
→ const Set<
String> - File extensions copied to output without text transforms.
- clayConfigFileName → const String
- Filename for the Clay project config at the project root.
- clayCoreVersion → const String
- The Clay core library version.
Functions
-
assertClayCompatible(
ClayConfig config) → void -
Throws ClayIncompatibleException when
configis not compatible with Clay. -
assertPreviewPathIsFile(
String resolvedFilePath, {FileSystemEntityType resolveEntityType(String path)?}) → void -
Throws when
resolvedFilePathdoes not refer to a readable file. -
collectClayConfigSearchPaths(
{required String startDir}) → List< String> -
Collects candidate
clay.yamlpaths when walking up fromstartDir. -
discoverClayConfig(
{String? configPath, String? cwd}) → DiscoveredClayConfig -
Discovers
clay.yamlusing an explicitconfigPathor walk-up fromcwd. -
expandIgnorePattern(
String pattern) → List< String> -
Expands a gitignore-style
patterninto glob patterns for matching. -
generateTemplate(
{required ClayConfig config, required String referencePath, required String targetPath, void onIgnoredFile(String relativePath)?}) → Future< void> -
Copies
referencePathtotargetPathand appliesconfigtransforms. -
ignorePatternValidationError(
String pattern) → String? -
Returns an error message when
patternis invalid for ignore matching. -
isClayConfigCompatibleWithClay(
ClayConfig config) → bool -
Returns whether
configis compatible with the current Clay library version. -
loadClayConfig(
{required String configPath, ClayConfig parseConfigMapForTesting(Map< String, dynamic> map)?}) → Future<ClayConfig> -
Loads and parses
clay.yamlfromconfigPath. -
loadPreviewPartials(
Directory targetDir) → Map< String, List< int> > - Loads partial files created during annotation resolution.
-
matchesIgnorePattern(
{required String relativePath, required String pattern}) → bool -
Returns whether
relativePathmatches a single gitignore-stylepattern. -
matchesIgnorePatterns(
{required String relativePath, required List< String> patterns}) → bool -
Returns whether
relativePathis excluded bypatterns. -
parsePreviewVars(
String? raw) → Map< String, dynamic> -
Parses
key=valuepairs from a comma-separated CLI value. -
previewReferenceFile(
{required String filePath, required String referencePath, required ClayConfig config, required bool templateOnly, Map< String, dynamic> vars = const {}}) → Future<String> -
Transforms
filePathunderreferencePathand optionally renders Mason vars. -
relativePathWithinRoot(
{required String rootDirectory, required String absolutePath}) → String? -
Returns the normalized path of
absolutePathrelative torootDirectory. -
resolvePathFromProjectRoot(
{required String projectRoot, required String path}) → String -
Resolves
pathrelative toprojectRoot, or returns the normalizedpathwhen it is absolute. -
resolveReferenceContent(
{required String content, required String targetRelativePath, required String targetAbsolutePath, required ClayConfig config}) → String -
Applies the annotation and
configtransforms tocontentas if it lived attargetRelativePathundertargetAbsolutePath. -
resolveReferenceFilePath(
{required String filePath, required String referencePath}) → String -
Resolves
filePathto an absolute path underreferencePath. -
resolveReferencePath(
{required String projectRoot, required ClayConfig config, String? cliOverride}) → String - Resolves the reference directory path.
-
resolveTargetPath(
{required String projectRoot, required ClayConfig config, String? cliOverride}) → String - Resolves the target directory path.
-
shouldIgnoreAtRoot(
{required String rootDirectory, required String absolutePath, required List< String> patterns}) → bool -
Returns whether
absolutePathunderrootDirectoryis excluded bypatterns. -
shouldSkipBinaryContent(
String path) → bool -
Whether
pathshould bypass the annotation transform pipeline. -
validateAnnotations(
{required Directory referenceDir}) → List< AnnotationIssue> -
Recursively validates annotation markers under
referenceDir. -
validateIgnorePatterns(
List< String> patterns) → void -
Validates
patternsfor ignore matching.
Exceptions / Errors
- ClayConfigException
-
Thrown when
clay.yamlcannot be loaded or parsed. - ClayConfigNotFoundException
-
Thrown when
clay.yamlcannot be discovered. - ClayIncompatibleException
-
Thrown when the running Clay version does not satisfy
environment.clay. - GenerationException
- Thrown when template generation cannot proceed.
- PreviewException
- Thrown when preview cannot proceed.
- ValidationException
- Thrown when annotation validation cannot proceed.