Build.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.IO;
  3. using System.IO.Compression;
  4. using System.Media;
  5. using System.Net.Http;
  6. using System.Threading.Tasks;
  7. using Nuke.Common;
  8. using Nuke.Common.Execution;
  9. using Nuke.Common.IO;
  10. using Nuke.Common.ProjectModel;
  11. using Nuke.Common.Tools.DotNet;
  12. using static Nuke.Common.IO.FileSystemTasks;
  13. using static Nuke.Common.Tools.DotNet.DotNetTasks;
  14. [UnsetVisualStudioEnvironmentVariables]
  15. class Build : NukeBuild
  16. {
  17. public static int Main() => Execute<Build>(x => x.Publish);
  18. [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
  19. readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
  20. [Solution] readonly Solution Solution;
  21. AbsolutePath OutputDirectory => RootDirectory / "output";
  22. AbsolutePath SourceDirectory => RootDirectory / "src";
  23. AbsolutePath LibPath => SourceDirectory / "Website/wwwroot/lib";
  24. AbsolutePath FontAwesomePath => SourceDirectory / "Website/wwwroot/lib/fontawesome";
  25. private void DeleteExistingFontAwesome()
  26. {
  27. if (Directory.Exists(FontAwesomePath))
  28. Directory.Delete(FontAwesomePath, true);
  29. }
  30. Target Clean => _ => _
  31. .Before(Restore)
  32. .Executes(() =>
  33. {
  34. DeleteExistingFontAwesome();
  35. EnsureCleanDirectory(OutputDirectory);
  36. });
  37. private async Task DownloadFontAwesome() {
  38. const string fontAwesomeVersion = "6.4.0";
  39. const string zipName = $"fontawesome-free-{fontAwesomeVersion}-web";
  40. var client = new HttpClient();
  41. var response = await client.GetAsync($"https://use.fontawesome.com/releases/v{fontAwesomeVersion}/{zipName}.zip");
  42. var memory = new MemoryStream();
  43. await response.Content.CopyToAsync(memory);
  44. var zip = new ZipArchive(memory);
  45. zip.ExtractToDirectory(LibPath);
  46. Directory.Move(LibPath / zipName, FontAwesomePath);
  47. }
  48. Target Restore => _ => _
  49. .DependsOn(Clean)
  50. .Executes(() => {
  51. DownloadFontAwesome().Wait();
  52. DotNetRestore(s => s
  53. .SetProjectFile(Solution));
  54. });
  55. Target Compile => _ => _
  56. .DependsOn(Restore)
  57. .Executes(() =>
  58. {
  59. DotNetBuild(s => s
  60. .SetProjectFile(Solution)
  61. .SetConfiguration(Configuration)
  62. .EnableNoRestore());
  63. });
  64. Target Test => _ => _
  65. .DependsOn(Compile)
  66. .Executes(() =>
  67. {
  68. DotNetTest(s => s
  69. .SetProjectFile(Solution)
  70. .EnableNoRestore());
  71. });
  72. Target Publish => _ => _
  73. .DependsOn(Test)
  74. .Executes(() =>{
  75. DotNetPublish(s => s
  76. .SetProject(SourceDirectory / "Website/Website.csproj")
  77. .SetConfiguration(Configuration)
  78. .SetOutput(OutputDirectory));
  79. });
  80. }