-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFileEmitStep.cs
More file actions
43 lines (35 loc) · 1.11 KB
/
Copy pathFileEmitStep.cs
File metadata and controls
43 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Tools.Services;
namespace GeneralUpdate.Tools.Pipeline.Steps;
public class FileEmitStep : IConfigStep
{
private readonly string? _outputDir;
public FileEmitStep(string? outputDir = null)
{
_outputDir = outputDir;
}
public string Name => "Emit manifest file";
public Task<PipelineContext> ExecuteAsync(PipelineContext ctx, CancellationToken ct)
{
var json = ManifestGeneratorService.GenerateJson(ctx.Manifest);
var dir = _outputDir ?? AppContext.BaseDirectory;
if (string.IsNullOrWhiteSpace(dir))
{
ctx.Errors.Add("No output directory available to write manifest.");
return Task.FromResult(ctx);
}
var path = Path.Combine(dir, "generalupdate.manifest.json");
try
{
File.WriteAllText(path, json);
}
catch (System.Exception ex)
{
ctx.Errors.Add($"Failed to write manifest to {path}: {ex.Message}");
}
return Task.FromResult(ctx);
}
}