Skip to content

Commit

Permalink
Allow to control if code is emitted (#3445)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Apr 7, 2021
1 parent 49f6279 commit 5004098
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Expand Up @@ -32,7 +32,7 @@ public void WriteDocument(ClientGeneratorContext context, SourceDocument documen
documentName,
SourceText.From(document.SourceText, Encoding.UTF8));

if (context.OutputFiles)
if (context.OutputFiles && context.Settings.EmitGeneratedCode)
{
context.FileNames.Add(fileName);
WriteFile(fileName, document.SourceText);
Expand Down
Expand Up @@ -12,6 +12,7 @@ public class SingleFileDocumentWriter : IDocumentWriter
private StringBuilder _content = new();
private GeneratorExecutionContext? _execution;
private string? _fileName;
private bool _emitCode;

public void WriteDocument(ClientGeneratorContext context, SourceDocument document)
{
Expand All @@ -27,6 +28,7 @@ public void WriteDocument(ClientGeneratorContext context, SourceDocument documen
_fileName = IOPath.Combine(
context.OutputDirectory,
$"{context.Settings.Name}.StrawberryShake.cs");
_emitCode = context.Settings.EmitGeneratedCode;
context.FileNames.Add(_fileName);
}

Expand All @@ -47,7 +49,7 @@ public void Flush()
IOPath.GetFileName(_fileName),
SourceText.From(_content.ToString(), Encoding.UTF8));

if (_fileName is not null)
if (_emitCode && _fileName is not null)
{
string directory = IOPath.GetDirectoryName(_fileName);

Expand Down
Expand Up @@ -25,6 +25,8 @@ public class StrawberryShakeSettings

public bool NoStore { get; set; }

public bool EmitGeneratedCode { get; set; } = true;

public StrawberryShakeSettingsRecords? Records { get; set; }

public List<StrawberryShakeTransportSettings>? TransportProfiles { get; set; }
Expand Down

0 comments on commit 5004098

Please sign in to comment.