using System.IO; using Nuke.Common; using Nuke.Common.Execution; using Nuke.Common.ProjectModel; using Nuke.Common.Tools.DotNet; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.PathConstruction; using static Nuke.Common.Tools.DotNet.DotNetTasks; [CheckBuildProjectConfigurations] [UnsetVisualStudioEnvironmentVariables] class Build : NukeBuild { public static int Main() => Execute(x => x.CopyFiles); [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; [Solution] readonly Solution Solution; AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath OutputDirectory => RootDirectory / "output"; AbsolutePath ComponentDirectory => RootDirectory / "output/Components"; Target Clean => _ => _ .Before(Restore) .Executes(() => { EnsureCleanDirectory(OutputDirectory); }); Target Restore => _ => _ .Executes(() => { DotNetRestore(s => s .SetProjectFile(Solution)); }); Target Compile => _ => _ .DependsOn(Restore) .Executes(() => { DotNetBuild(s => s .SetProjectFile(Solution) .SetConfiguration(Configuration) .EnableNoRestore()); }); Target Test => _ => _ .DependsOn(Compile) .Executes(() => { DotNetTest(s => s .SetProjectFile(Solution) .EnableNoRestore()); }); Target Publish => _ => _ .DependsOn(Test) .Executes(() => { DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer").SetConfiguration(Configuration).SetOutput(OutputDirectory)); DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer.Daemon").SetConfiguration(Configuration).SetOutput(OutputDirectory)); DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer.Components").SetConfiguration(Configuration).SetOutput(ComponentDirectory)); DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer.MQTT").SetConfiguration(Configuration).SetOutput(ComponentDirectory)); DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer.InfluxDB").SetConfiguration(Configuration).SetOutput(ComponentDirectory)); File.Delete(OutputDirectory / "HAServer.dll.config"); }); private static void CopyDirectory(string source, string destination) { var dir = new DirectoryInfo(source); if (!dir.Exists) throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + source); var dirs = dir.GetDirectories(); if (!Directory.Exists(destination)) Directory.CreateDirectory(destination); var files = dir.GetFiles(); foreach (var file in files) { var temppath = Path.Combine(destination, file.Name); file.CopyTo(temppath, true); } foreach (var subdir in dirs) { var temppath = Path.Combine(destination, subdir.Name); CopyDirectory(subdir.FullName, temppath); } } Target CopyFiles => _ => _ .DependsOn(Publish) .Executes(() => { CopyDirectory(SourceDirectory / "HAServer/WebUI", OutputDirectory / "WebUI"); File.Copy("has.service", OutputDirectory / "has.service", true); }); }