runtime
This commit is contained in:
parent
95724a09e7
commit
b9599c5fa3
14 changed files with 148 additions and 37 deletions
|
@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9DA99E16-F
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyanbyte.Minime.Test", "test\Nyanbyte.Minime.Test\Nyanbyte.Minime.Test.csproj", "{1E4D89E6-A38C-4E68-9DA2-BF931190696C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyanbyte.Minime.Cli", "src\Nyanbyte.Minime.Cli\Nyanbyte.Minime.Cli.csproj", "{79FC08D0-6965-4CA9-9E0E-A8E2A9B5D5F5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -28,9 +30,14 @@ Global
|
|||
{1E4D89E6-A38C-4E68-9DA2-BF931190696C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1E4D89E6-A38C-4E68-9DA2-BF931190696C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1E4D89E6-A38C-4E68-9DA2-BF931190696C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{79FC08D0-6965-4CA9-9E0E-A8E2A9B5D5F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{79FC08D0-6965-4CA9-9E0E-A8E2A9B5D5F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{79FC08D0-6965-4CA9-9E0E-A8E2A9B5D5F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{79FC08D0-6965-4CA9-9E0E-A8E2A9B5D5F5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{96F040B9-C9C9-4B1E-ABB5-39DA51BEB00C} = {EEBF5124-1862-4105-B6AB-A9B578B0CA3D}
|
||||
{1E4D89E6-A38C-4E68-9DA2-BF931190696C} = {9DA99E16-F65C-466B-9FB3-C59D9E1B31AC}
|
||||
{79FC08D0-6965-4CA9-9E0E-A8E2A9B5D5F5} = {EEBF5124-1862-4105-B6AB-A9B578B0CA3D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
18
src/Nyanbyte.Minime.Cli/Nyanbyte.Minime.Cli.csproj
Normal file
18
src/Nyanbyte.Minime.Cli/Nyanbyte.Minime.Cli.csproj
Normal file
|
@ -0,0 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Nyanbyte.Minime\Nyanbyte.Minime.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Build.Locator" Version="1.6.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
22
src/Nyanbyte.Minime.Cli/Program.cs
Normal file
22
src/Nyanbyte.Minime.Cli/Program.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Build.Locator;
|
||||
|
||||
namespace Nyanbyte.Minime.Cli;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
MSBuildLocator.RegisterDefaults();
|
||||
await Execute();
|
||||
}
|
||||
|
||||
public static async Task Execute()
|
||||
{
|
||||
RuntimeManager runtime = new(RuntimeOptions.Default);
|
||||
await runtime.ExecutePlain();
|
||||
}
|
||||
}
|
7
src/Nyanbyte.Minime/Bundling/BundlingContext.cs
Normal file
7
src/Nyanbyte.Minime/Bundling/BundlingContext.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Nyanbyte.Minime.Bundling;
|
||||
|
||||
public class BundlingContext
|
||||
{
|
||||
public StreamWriter Output { get; internal set; } = null!;
|
||||
public StreamReader Input { get; internal set; } = null!;
|
||||
}
|
6
src/Nyanbyte.Minime/Bundling/IBundler.cs
Normal file
6
src/Nyanbyte.Minime/Bundling/IBundler.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace Nyanbyte.Minime.Bundling;
|
||||
|
||||
public interface IBundler
|
||||
{
|
||||
public Task Bundle(BundlingContext ctx, CancellationToken cancellation);
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nyanbyte.Minime;
|
||||
|
||||
public class Minime
|
||||
{
|
||||
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
using Microsoft.Build.Utilities;
|
||||
|
||||
namespace Nyanbyte.Minime;
|
||||
|
||||
public class MinimeBuildTask : Microsoft.Build.Utilities.Task
|
||||
{
|
||||
public override bool Execute()
|
||||
{
|
||||
Log.LogMessage("meow");
|
||||
System.Threading.Tasks.Task.Run(async () =>
|
||||
{
|
||||
RuntimeManager runtime = new(RuntimeOptions.Default);
|
||||
await runtime.Execute(this.BuildEngine);
|
||||
}).Wait();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nyanbyte.Minime.Processing;
|
||||
|
||||
|
@ -16,7 +12,9 @@ public class CssProcessor : IProcessor
|
|||
L_STRING_C = '\'',
|
||||
L_SEMI = ';';
|
||||
|
||||
public async Task Execute(FileContext ctx, CancellationToken cancellation)
|
||||
public string[] AcceptedExtensions => new[] { "css" };
|
||||
|
||||
public async Task Process(ProcessingContext ctx, CancellationToken cancellation)
|
||||
{
|
||||
var write = ctx.Output;
|
||||
var read = ctx.Input;
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nyanbyte.Minime.Processing;
|
||||
|
||||
public interface IProcessor
|
||||
{
|
||||
public Task Execute(FileContext ctx, CancellationToken cancellation);
|
||||
public string[] AcceptedExtensions { get; }
|
||||
public Task Process(ProcessingContext ctx, CancellationToken cancellation);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Build.Framework;
|
||||
|
||||
namespace Nyanbyte.Minime.Processing;
|
||||
|
||||
public class FileContext
|
||||
public class ProcessingContext
|
||||
{
|
||||
public required string Path { get; init; }
|
||||
public required IBuildEngine BuildEngine { get; init; }
|
||||
public IBuildEngine? BuildEngine { get; init; }
|
||||
public string? OutputPath { get; set; }
|
||||
public StreamWriter Output { get; internal set; } = null!;
|
||||
public StreamReader Input { get; internal set; } = null!;
|
6
src/Nyanbyte.Minime/Processing/ProcessingOptions.cs
Normal file
6
src/Nyanbyte.Minime/Processing/ProcessingOptions.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace Nyanbyte.Minime.Processing;
|
||||
|
||||
public class ProcessingOptions
|
||||
{
|
||||
|
||||
}
|
57
src/Nyanbyte.Minime/RuntimeManager.cs
Normal file
57
src/Nyanbyte.Minime/RuntimeManager.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System.Reflection;
|
||||
using Microsoft.Build.Framework;
|
||||
using Nyanbyte.Minime.Processing;
|
||||
|
||||
namespace Nyanbyte.Minime;
|
||||
|
||||
public class RuntimeManager
|
||||
{
|
||||
public RuntimeManager(RuntimeOptions options)
|
||||
{
|
||||
_options = options;
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
private readonly RuntimeOptions _options;
|
||||
|
||||
private Dictionary<string, IProcessor> _processors = null!;
|
||||
|
||||
private void Init()
|
||||
{
|
||||
_processors = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => t.IsAssignableFrom(typeof(IProcessor)) && t.IsClass).Select(t => (IProcessor)Activator.CreateInstance(t)!).SelectMany(m => m.AcceptedExtensions.Select(e => KeyValuePair.Create(e, m))).ToDictionary(k => k.Key, k => k.Value);
|
||||
}
|
||||
|
||||
public async Task ExecutePlain(CancellationToken cancellation = default)
|
||||
{
|
||||
await Execute(default, cancellation);
|
||||
}
|
||||
|
||||
public async Task Execute(IBuildEngine? buildEngine = default, CancellationToken cancellation = default)
|
||||
{
|
||||
Init();
|
||||
|
||||
HashSet<string> files = new();
|
||||
foreach (string f in _options.SearchDirectories)
|
||||
{
|
||||
files.UnionWith(Directory.GetFiles(f, "*", _options.DeepSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
|
||||
}
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (_processors.TryGetValue(Path.GetExtension(file), out var processor))
|
||||
{
|
||||
using StreamReader reader = new(File.OpenRead(file));
|
||||
ProcessingContext ctx = new()
|
||||
{
|
||||
Path = file,
|
||||
BuildEngine = buildEngine,
|
||||
Input = reader
|
||||
};
|
||||
|
||||
await processor.Process(ctx, cancellation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
src/Nyanbyte.Minime/RuntimeOptions.cs
Normal file
13
src/Nyanbyte.Minime/RuntimeOptions.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace Nyanbyte.Minime;
|
||||
|
||||
public record RuntimeOptions
|
||||
{
|
||||
public static RuntimeOptions Default => new()
|
||||
{
|
||||
DeepSearch = true,
|
||||
SearchDirectories = new[] { Environment.CurrentDirectory }
|
||||
};
|
||||
|
||||
public bool DeepSearch { get; init; }
|
||||
public string[] SearchDirectories { get; init; } = null!;
|
||||
}
|
|
@ -1,9 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Nyanbyte.Minime.Test.Processor;
|
||||
|
||||
public class CssProcessorTests
|
||||
|
|
Loading…
Reference in a new issue