Build.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.IO;
  2. using Nuke.Common;
  3. using Nuke.Common.Execution;
  4. using Nuke.Common.ProjectModel;
  5. using Nuke.Common.Tools.DotNet;
  6. using static Nuke.Common.IO.FileSystemTasks;
  7. using static Nuke.Common.IO.PathConstruction;
  8. using static Nuke.Common.Tools.DotNet.DotNetTasks;
  9. [CheckBuildProjectConfigurations]
  10. [UnsetVisualStudioEnvironmentVariables]
  11. class Build : NukeBuild {
  12. public static int Main() => Execute<Build>(x => x.CopyFiles);
  13. [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
  14. readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
  15. [Solution] readonly Solution Solution;
  16. AbsolutePath SourceDirectory => RootDirectory / "src";
  17. AbsolutePath OutputDirectory => RootDirectory / "output";
  18. AbsolutePath ComponentDirectory => RootDirectory / "output/Components";
  19. Target Clean => _ => _
  20. .Before(Restore)
  21. .Executes(() => {
  22. EnsureCleanDirectory(OutputDirectory);
  23. });
  24. Target Restore => _ => _
  25. .Executes(() => {
  26. DotNetRestore(s => s
  27. .SetProjectFile(Solution));
  28. });
  29. Target Compile => _ => _
  30. .DependsOn(Restore)
  31. .Executes(() => {
  32. DotNetBuild(s => s
  33. .SetProjectFile(Solution)
  34. .SetConfiguration(Configuration)
  35. .EnableNoRestore());
  36. });
  37. Target Test => _ => _
  38. .DependsOn(Compile)
  39. .Executes(() => {
  40. DotNetTest(s => s
  41. .SetProjectFile(Solution)
  42. .EnableNoRestore());
  43. });
  44. Target Publish => _ => _
  45. .DependsOn(Test)
  46. .Executes(() => {
  47. DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer").SetConfiguration(Configuration).SetOutput(OutputDirectory));
  48. DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer.Daemon").SetConfiguration(Configuration).SetOutput(OutputDirectory));
  49. DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer.Components").SetConfiguration(Configuration).SetOutput(ComponentDirectory));
  50. DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer.MQTT").SetConfiguration(Configuration).SetOutput(ComponentDirectory));
  51. DotNetPublish(settings => settings.SetProject(SourceDirectory / "HAServer.InfluxDB").SetConfiguration(Configuration).SetOutput(ComponentDirectory));
  52. File.Delete(OutputDirectory / "HAServer.dll.config");
  53. });
  54. private static void CopyDirectory(string source, string destination) {
  55. var dir = new DirectoryInfo(source);
  56. if (!dir.Exists)
  57. throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + source);
  58. var dirs = dir.GetDirectories();
  59. if (!Directory.Exists(destination))
  60. Directory.CreateDirectory(destination);
  61. var files = dir.GetFiles();
  62. foreach (var file in files) {
  63. var temppath = Path.Combine(destination, file.Name);
  64. file.CopyTo(temppath, true);
  65. }
  66. foreach (var subdir in dirs) {
  67. var temppath = Path.Combine(destination, subdir.Name);
  68. CopyDirectory(subdir.FullName, temppath);
  69. }
  70. }
  71. Target CopyFiles => _ => _
  72. .DependsOn(Publish)
  73. .Executes(() => {
  74. CopyDirectory(SourceDirectory / "HAServer/WebUI", OutputDirectory / "WebUI");
  75. File.Copy("has.service", OutputDirectory / "has.service", true);
  76. });
  77. }