Remove NPM dependency

This commit is contained in:
Robert Marshall 2023-06-24 10:30:57 +01:00
parent 9e7545e729
commit 9c1314cd97
8 changed files with 36 additions and 63 deletions

View file

@ -1,4 +1,9 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Media;
using System.Net.Http;
using System.Threading.Tasks;
using Nuke.Common;
using Nuke.Common.Execution;
using Nuke.Common.IO;
@ -19,17 +24,39 @@ class Build : NukeBuild
AbsolutePath OutputDirectory => RootDirectory / "output";
AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath LibPath => SourceDirectory / "Website/wwwroot/lib";
AbsolutePath FontAwesomePath => SourceDirectory / "Website/wwwroot/lib/fontawesome";
Target Clean => _ => _
private void DeleteExistingFontAwesome()
{
if (Directory.Exists(FontAwesomePath))
Directory.Delete(FontAwesomePath, true);
}
Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
DeleteExistingFontAwesome();
EnsureCleanDirectory(OutputDirectory);
});
private async Task DownloadFontAwesome() {
const string fontAwesomeVersion = "6.4.0";
const string zipName = $"fontawesome-free-{fontAwesomeVersion}-web";
var client = new HttpClient();
var response = await client.GetAsync($"https://use.fontawesome.com/releases/v{fontAwesomeVersion}/{zipName}.zip");
var memory = new MemoryStream();
await response.Content.CopyToAsync(memory);
var zip = new ZipArchive(memory);
zip.ExtractToDirectory(LibPath);
Directory.Move(LibPath / zipName, FontAwesomePath);
}
Target Restore => _ => _
.Executes(() =>
{
.DependsOn(Clean)
.Executes(() => {
DownloadFontAwesome().Wait();
DotNetRestore(s => s
.SetProjectFile(Solution));
});