Doc, skeleton CSS processor
This commit is contained in:
parent
0570c15c38
commit
95724a09e7
8 changed files with 139 additions and 9 deletions
22
Minime.sln
22
Minime.sln
|
@ -3,6 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EEBF5124-1862-4105-B6AB-A9B578B0CA3D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyanbyte.Minime", "src\Nyanbyte.Minime\Nyanbyte.Minime.csproj", "{96F040B9-C9C9-4B1E-ABB5-39DA51BEB00C}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9DA99E16-F65C-466B-9FB3-C59D9E1B31AC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyanbyte.Minime.Test", "test\Nyanbyte.Minime.Test\Nyanbyte.Minime.Test.csproj", "{1E4D89E6-A38C-4E68-9DA2-BF931190696C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -11,4 +19,18 @@ Global
|
|||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{96F040B9-C9C9-4B1E-ABB5-39DA51BEB00C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{96F040B9-C9C9-4B1E-ABB5-39DA51BEB00C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{96F040B9-C9C9-4B1E-ABB5-39DA51BEB00C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{96F040B9-C9C9-4B1E-ABB5-39DA51BEB00C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1E4D89E6-A38C-4E68-9DA2-BF931190696C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{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
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{96F040B9-C9C9-4B1E-ABB5-39DA51BEB00C} = {EEBF5124-1862-4105-B6AB-A9B578B0CA3D}
|
||||
{1E4D89E6-A38C-4E68-9DA2-BF931190696C} = {9DA99E16-F65C-466B-9FB3-C59D9E1B31AC}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
10
README.md
10
README.md
|
@ -1,3 +1,13 @@
|
|||
# Minime
|
||||
|
||||
ASP.NET Core CSS & JS minimization and packing
|
||||
|
||||
## Usage
|
||||
|
||||
Add this to the project uwu~
|
||||
|
||||
```xml
|
||||
<Target Name="Minime" AfterTargets="Build">
|
||||
<MinimeBuildTask />
|
||||
</Target>
|
||||
```
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -9,14 +10,69 @@ public class CssProcessor : IProcessor
|
|||
{
|
||||
internal const string
|
||||
L_COMMENT_OPEN = "/*",
|
||||
L_COMMENT_CLOSE = "*/",
|
||||
L_STRING = "\"",
|
||||
L_STRING_C = "'",
|
||||
L_SEMI = ";";
|
||||
L_COMMENT_CLOSE = "*/";
|
||||
internal const char
|
||||
L_STRING = '"',
|
||||
L_STRING_C = '\'',
|
||||
L_SEMI = ';';
|
||||
|
||||
public Task Execute(FileContext ctx)
|
||||
public async Task Execute(FileContext ctx, CancellationToken cancellation)
|
||||
{
|
||||
var write = ctx.Output;
|
||||
var read = ctx.Input;
|
||||
|
||||
return Task.CompletedTask;
|
||||
bool isQuote = false, isComment = false;
|
||||
|
||||
Memory<char> buf = MemoryPool<char>.Shared.Rent(32 * 1024).Memory;
|
||||
int len = await read.ReadBlockAsync(buf, cancellation);
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
char c = buf.Span[i];
|
||||
|
||||
if (isComment)
|
||||
{
|
||||
if (buf.Slice(i, 2).Span.SequenceEqual(L_COMMENT_CLOSE))
|
||||
{
|
||||
isComment = false;
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case L_STRING or L_STRING_C:
|
||||
isQuote = !isQuote;
|
||||
continue;
|
||||
case ' ':
|
||||
if (!isQuote)
|
||||
continue;
|
||||
await write.WriteAsync(c);
|
||||
break;
|
||||
case '\n':
|
||||
continue;
|
||||
case '/':
|
||||
if (!isQuote)
|
||||
{
|
||||
if (buf.Slice(i, 2).Span.SequenceEqual(L_COMMENT_OPEN))
|
||||
{
|
||||
isComment = true;
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
continue;
|
||||
default:
|
||||
if (isQuote)
|
||||
{
|
||||
await write.WriteAsync(c);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,6 @@ public class FileContext
|
|||
public required string Path { get; init; }
|
||||
public required IBuildEngine BuildEngine { get; init; }
|
||||
public string? OutputPath { get; set; }
|
||||
public StreamReader Reader { get; internal set; } = null!;
|
||||
public StreamWriter Output { get; internal set; } = null!;
|
||||
public StreamReader Input { get; internal set; } = null!;
|
||||
}
|
||||
|
|
|
@ -7,5 +7,5 @@ namespace Nyanbyte.Minime.Processing;
|
|||
|
||||
public interface IProcessor
|
||||
{
|
||||
public Task Execute(FileContext ctx);
|
||||
public Task Execute(FileContext ctx, CancellationToken cancellation);
|
||||
}
|
||||
|
|
1
test/Nyanbyte.Minime.Test/GlobalUsings.cs
Normal file
1
test/Nyanbyte.Minime.Test/GlobalUsings.cs
Normal file
|
@ -0,0 +1 @@
|
|||
global using Xunit;
|
25
test/Nyanbyte.Minime.Test/Nyanbyte.Minime.Test.csproj
Normal file
25
test/Nyanbyte.Minime.Test/Nyanbyte.Minime.Test.csproj
Normal file
|
@ -0,0 +1,25 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
15
test/Nyanbyte.Minime.Test/Processor/CssProcessorTests.cs
Normal file
15
test/Nyanbyte.Minime.Test/Processor/CssProcessorTests.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Nyanbyte.Minime.Test.Processor;
|
||||
|
||||
public class CssProcessorTests
|
||||
{
|
||||
[Fact]
|
||||
public void GeneralCssProcessorTest()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue