using Faithlife.Build;
using static Faithlife.Build.DotNetRunner;

internal static class Build
{
	public static int Main(string[] args) => BuildRunner.Execute(args, build =>
	{
		var artifactDirOption = build.AddOption("--artifact-dir <directory>", "Artifact directory", defaultValue: "artifacts");

		var dotNetSettings = new DotNetBuildSettings();

		build.AddDotNetTargets(dotNetSettings);

		build.Target("deployment-package")
			.DependsOn("test")
			.Describe("Creates the deployment package")
			.Does(() =>
			{
				var projectPath = Path.Combine("src", "Twain.Web", "Twain.Web.csproj");

				if (artifactDirOption.Value != null)
					DeleteDirectory(artifactDirOption.Value);

				RunDotNet(new[]
					{
						"publish", projectPath,
						"-c", dotNetSettings.GetConfiguration(),
						"-o", artifactDirOption.Value,
						dotNetSettings.GetPlatformArg(),
						"--no-build",
						dotNetSettings.GetVerbosityArg(),
						dotNetSettings.GetMaxCpuCountArg()
					});
			});
	});
}
