Copy to output for version 1.0

This commit is contained in:
Booklordofthedings 2024-12-06 18:14:15 +01:00
parent 9f9cff55fa
commit 31a36815f8
3 changed files with 33 additions and 3 deletions

1
BeefSpace_Lock.toml Normal file
View file

@ -0,0 +1 @@
FileVersion = 1

View file

@ -1,7 +1,5 @@
namespace Example_Website;
using System;
using Aven;
class Program
@ -9,7 +7,8 @@ class Program
public static void Main()
{
Aven aven = scope .();
aven.Register(.Owning(new Example_Website.Index()));
aven.CopyToOutput("../favicon.ico", "favicon.ico");
aven.Register(.Owning(new Index()));
aven.Build();
}
}

View file

@ -9,6 +9,7 @@ using System.Collections;
class Aven
{
private List<Template> _templates = new .() ~ DeleteContainerAndItems!(_);
private Dictionary<String, String> _toCopy = new .() ~ DeleteDictionaryAndKeysAndValues!(_);
private Stopwatch _timer = new .() ~ delete _;
///Registers an instance of a web template
@ -24,6 +25,8 @@ class Aven
return .Err;
}
public void CopyToOutput(StringView path, StringView output) => _toCopy.Add(new .(path), new .(output));
public void Build(StringView outputDir = "./output")
{
_timer.Start();
@ -80,6 +83,33 @@ class Aven
}
Log.Info(scope $"Wrote to file: {outputDir}{page.OutputFile}");
}
Log.Info("Finished page generation");
Log.Info("Copy to output");
for(var cp in _toCopy)
{
String dir = scope .();
if(File.Exists(cp.key))
{
if((cp.value.Contains('/') || cp.value.Contains('\\')) && Path.GetDirectoryPath(cp.value, dir) case .Ok)
Directory.CreateDirectory(scope $"{outputDir}/{dir}").IgnoreError();
if(File.Copy(cp.key, scope $"{outputDir}/{cp.value}") case .Err)
Log.Warn("Unable to copy over file");
}
else if(Directory.Exists(cp.key))
{
if((cp.value.Contains('/') || cp.value.Contains('\\')) && Path.GetDirectoryPath(cp.value, dir) case .Ok)
Directory.CreateDirectory(scope $"{outputDir}/{dir}").IgnoreError();
if(Directory.Copy(cp.key, scope $"{outputDir}/{cp.value}") case .Err)
Log.Warn("Unable to copy over directory");
}
else
Log.Warn("Input file doesnt exist");
}
Log.Info(scope $"Finished generation in: {_timer.ElapsedMilliseconds}ms");
_timer.Reset();