aboutsummaryrefslogtreecommitdiff
path: root/src/Commands/BuildCommand.cs
blob: c1d9828948d66584d707321d3fa7faff9acd311a (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Threading;
using System.Threading.Tasks;

using Typin.Console;
using Typin.Attributes;

using VNLib.Tools.Build.Executor.Model;
using VNLib.Tools.Build.Executor.Constants;

namespace VNLib.Tools.Build.Executor.Commands
{

    [Command("build", Description = "Executes a build operation in pipeline")]
    public class BuildCommand(BuildPipeline pipeline, ConfigManager bm) : BaseCommand(pipeline, bm)
    {

        [CommandOption("no-delay", 'S', Description = "Skips any built-in delay/wait")]
        public bool SkipDelay { get; set; } = false;

        public override async ValueTask ExecStepsAsync(IConsole console)
        {
            CancellationToken cancellation = console.GetCancellationToken();

            console.Output.WriteLine("Starting build pipeline. Checking for source code changes");

            if (Force)
            {
                console.WithForegroundColor(ConsoleColor.Yellow, static o => o.Output.WriteLine("Forcing build step"));
            }

            //Check for source code changes
            bool changed = await pipeline.CheckForChangesAsync();

            //continue build
            if (!Force && !changed)
            {
                console.WithForegroundColor(ConsoleColor.Green, static o => o.Output.WriteLine("No source code changes detected. Skipping build step"));
                return;
            }

            if (Confirm)
            { 
                console.Output.WriteLine("Press any key to continue...");
                await console.Input.ReadLineAsync(cancellation);
                cancellation.ThrowIfCancellationRequested();
            }
            else if(!SkipDelay)
            {
                //wait for 10 seconds
                for (int i = 10; i > 0; i--)
                {
                    string seconds = i > 1 ? "seconds" : "second";
                    console.Output.WriteLine($"Starting build step in {i} {seconds}");
                    await Task.Delay(1000, cancellation);                
                }
            }

            await pipeline.DoStepBuild(Force);

            console.WithForegroundColor(ConsoleColor.Green, static o => o.Output.WriteLine("Build completed successfully"));
        }

        public override IFeedManager[] Feeds => [];
    }
}