Skip to content

Carrot.Data.Scaffold.Compilers.Sinks.FileSystem

net

Compiler sink that writes generated scaffold output files to the local filesystem.

Installation

xml
<ProjectReference Include="..\Carrot.Data.Scaffold.Compilers.Sinks.FileSystem\Carrot.Data.Scaffold.Compilers.Sinks.FileSystem.csproj" />

Architecture

How It Works

ScaffoldCompilerSinkFileSystem extends ScaffoldCompilerSink<ScaffoldCompilerSinkFileSystemOptions> and implements Write(bundle).

For each ScaffoldCompilerManifestBundleItem in the bundle:

  1. Resolves the absolute file path from FileSystem.ExecutingAssemblyDirectoryGitRoot + the renderer output's relative path
  2. Ensures the target directory exists (creates it if missing)
  3. Writes the content string to the file via File.WriteAllText
  4. Records the folder in the returned ScaffoldCompilerManifestSink

When DryRun is true, Write returns null immediately - no files are touched.

Options

  • Enabled (default true) - master switch; when false, the sink is skipped entirely via the IfEnabled pattern
  • DryRun (default false) - when true, the sink reports as enabled but does not write any files

Dependencies

DependencyKind
Carrot.Data.Scaffold.Compilersproject (compiler pipeline framework)

Build

bash
dotnet build

Usage Guide

Sink that writes generated scaffold code to the local filesystem.

Getting Started

csharp
using Carrot.Data.Scaffold;
using Carrot.Data.Scaffold.Domain;

scaffold.Compiler(compiler =>
{
    compiler
        .AddModule<MyGraphRoot, MyModule>()
        .SinkToFileSystem()
        .Build();
});

Common Patterns

1. Default (enabled, writes files)

csharp
compiler.SinkToFileSystem();

2. With options

csharp
compiler.SinkToFileSystem(options =>
{
    options.Enabled = true;
    options.DryRun  = false;
});

3. Dry run mode

csharp
compiler.SinkToFileSystem(options =>
{
    options.DryRun = true;  // sink is enabled but writes nothing
});

4. Manual registration (without extension)

csharp
compiler.SinkTo<ScaffoldCompilerSinkFileSystem, ScaffoldCompilerSinkFileSystemOptions>(options =>
{
    options.Enabled = true;
});

Tips / Gotchas

  • Enabled by default - unlike some sinks, Enabled defaults to true and DryRun defaults to false, so SinkToFileSystem() with no options will write files.
  • Paths resolve from git root - all file paths are resolved relative to FileSystem.ExecutingAssemblyDirectoryGitRoot. The renderer output's FolderRelative determines the target directory.
  • Directories are created automatically - if the target folder doesn't exist, it is created before writing.
  • DryRun still counts as enabled - IfEnabled() returns the sink even when DryRun is true. The bundle loop runs, but Write returns null without touching disk. This means metadata sinks will still see the module, but no manifest sink result is recorded.

Carrot