Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 #87: Copy web resources into site directory #88

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/sika.core/Components/FileSystemWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,26 @@

namespace sika.core.Components;

public class FileSystemWriter(Project project) : ILinker
public class FileSystemWriter : ILinker, IDisposable
{
private readonly Project _project;

public FileSystemWriter(Project project)
{
_project = project;

var siteDir = new DirectoryInfo(_project.Info.SiteDirectory);
if (!siteDir.Exists)
siteDir.Create();
}

public bool IsSynchronous => true;

public bool CanExecute(PageTree tree) => true;

public async Task CompileAsync(PageTree tree)
{
var fullname = Path.Combine(project.Info.SiteDirectory, tree.GetFullPath());
var fullname = Path.Combine(_project.Info.SiteDirectory, tree.GetFullPath());

if (tree.Content is PageLeafData leaf)
{
Expand All @@ -43,4 +54,20 @@ public async Task CompileAsync(PageTree tree)
dir.Create();
}
}

public void Dispose()
{
var siteDir = new DirectoryInfo(_project.Info.SiteDirectory);
CopyDirectory(new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot")), siteDir);
}

private static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
{
if (!destination.Exists)
destination.Create();
foreach (var file in source.EnumerateFiles())
file.CopyTo(Path.Combine(destination.FullName, file.Name), true);
foreach (var sub in source.EnumerateDirectories())
CopyDirectory(sub, destination.CreateSubdirectory(sub.Name));
}
}
13 changes: 2 additions & 11 deletions src/sika/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ async Task<int> CreateProject(string[] args)
var data = new Json().Serialize(project);

var file = new FileInfo("sika.json");
var siteDir = new DirectoryInfo("site");
var layoutDir = new DirectoryInfo("layout");
var postDir = new DirectoryInfo("post");
if (file.Exists)
Expand All @@ -66,12 +65,6 @@ async Task<int> CreateProject(string[] args)
return -1;
}

if (siteDir.Exists)
{
Console.Error.WriteLine("Couldn't create folder: There is already site folder (site/)");
return -1;
}

if (layoutDir.Exists)
{
Console.Error.WriteLine("Couldn't create folder: There is already layout folder (layout/)");
Expand All @@ -88,9 +81,6 @@ async Task<int> CreateProject(string[] args)
await using var sw = new StreamWriter(fs, Encoding.UTF8);
sw.Write(data);

siteDir.Create();


layoutDir.Create();
await File.WriteAllTextAsync("layout/default.cshtml", await ReadResourceAsync("sika.Resources.default.cshtml"));

Expand Down Expand Up @@ -127,7 +117,8 @@ async Task<int> BuildProject(string[] args)
var tree = new PageTree();
tree.Initialize(new DirectoryInfo(project.Info.PostDirectory));

ILinker[] passes = [
ILinker[] passes =
[
new YamlPreprocessor(),
new RazorLinker(tree, project),
new GoogleSitemapLinker(project),
Expand Down
2 changes: 1 addition & 1 deletion src/sika/sika.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<PreserveCompilationContext>true</PreserveCompilationContext>

<AssemblyVersion>3.0.1</AssemblyVersion>
<AssemblyVersion>3.0.2</AssemblyVersion>

<PackAsTool>true</PackAsTool>
<ToolCommandName>sika</ToolCommandName>
Expand Down
Loading