Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from johan-v-r/arg-options
Browse files Browse the repository at this point in the history
Arg options
  • Loading branch information
johan-v-r authored Feb 19, 2021
2 parents 7265c99 + 4b89628 commit 1728325
Show file tree
Hide file tree
Showing 19 changed files with 203 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,5 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/src/LibSassBuilder.Tests/*.css
*.css
package/tool/*
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ Build | NuGet Package | .NET Global Tool

`LibSassBuilder` NuGet package adds a build task to compile Sass files to `.css`. It's compatible with both MSBuild (VS) and `dotnet build`.

No configuration is required, it will compile the files implicitly on project build.
No configuration is required, it will compile the files implicitly on project build.

Optionally provide arguments (see _Options_ below):
```xml
<PropertyGroup>
<LibSassBuilderArgs>.\Pages -e temp</LibSassBuilderArgs>
</PropertyGroup>
```

## [.NET Global Tool](https://www.nuget.org/packages/LibSassBuilder-Tool)

Expand All @@ -24,14 +31,22 @@ dotnet tool install --global LibSassBuilder-Tool

Use:
```
lsb [optional-path]
lsb [optional-path] [options]
lsb --help
```

> Files in the following directories are excluded by default:
> - `bin`
> - `obj`
> - `logs`
> - `node_modules`

## Options

```
-e, --exclude (Default: bin obj logs node_modules) Specify explicit directories to exclude. Overrides the default.
--help Display this help screen.
--version Display version information.
value pos. 0 Directory in which to run. Defaults to current directory.
```

___

Expand Down
2 changes: 1 addition & 1 deletion package/LibSassBuilder.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>LibSassBuilder</id>
<version>1.4.0</version>
<version>1.5.0</version>
<title>LibSassBuilder</title>
<summary>Auto build task to compile .scss/.sass files to .css</summary>
<authors>Johan van Rensburg</authors>
Expand Down
7 changes: 7 additions & 0 deletions package/build/LibSassBuilder.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- https://natemcmaster.com/blog/2017/11/11/build-tools-in-nuget/ -->
<PropertyGroup>
<SassExe Condition=" '$(SassExe)'=='' ">$(MSBuildThisFileDirectory)../tool/LibSassBuilder.dll</SassExe>
<LibSassBuilderArgs Condition=" '$(LibSassBuilderArgs)'=='' "></LibSassBuilderArgs>
</PropertyGroup>
</Project>
7 changes: 1 addition & 6 deletions package/build/LibSassBuilder.targets
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- https://natemcmaster.com/blog/2017/11/11/build-tools-in-nuget/ -->
<PropertyGroup>
<SassExe Condition=" '$(SassExe)'=='' ">$(MSBuildThisFileDirectory)../tool/LibSassBuilder.dll</SassExe>
</PropertyGroup>

<Target Name="SassBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet &quot;$(SassExe)&quot;" />
<Exec Command="dotnet &quot;$(SassExe)&quot; $(LibSassBuilderArgs)" />
</Target>
</Project>
30 changes: 30 additions & 0 deletions src/LibSassBuilder.DirectoryTests/DirectoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.IO;
using Xunit;

namespace LibSassBuilder.DirectoryTests
{
// This project is configured to run LibSassBuilder in LibSassBuilder.DirectoryTests.csproj within ./logs directory
public class DirectoryTests
{
private readonly string _fileDirectory;

public DirectoryTests()
{
_fileDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
}

[Fact]
public void ExplicitDirectoryTest()
{
var barFile = Path.Join(_fileDirectory, "foo/bar.css");
var binFile = Path.Join(_fileDirectory, "logs/bin/bin-file.css");
var logsFile = Path.Join(_fileDirectory, "logs/logs-file.css");

Assert.False(File.Exists(barFile)); // not in ./logs directory
Assert.False(File.Exists(binFile)); // inside ./logs, but excluded by default nested bin folder
Assert.True(File.Exists(logsFile)); // inside ./logs

File.Delete(logsFile);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet run --project ../LibSassBuilder ./logs" />
</Target>

</Project>
3 changes: 3 additions & 0 deletions src/LibSassBuilder.DirectoryTests/foo/bar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: black;
}
2 changes: 2 additions & 0 deletions src/LibSassBuilder.DirectoryTests/logs/bin/bin-file.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
body {
}
2 changes: 2 additions & 0 deletions src/LibSassBuilder.DirectoryTests/logs/logs-file.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
body {
}
30 changes: 30 additions & 0 deletions src/LibSassBuilder.ExcludeTests/ExcludeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.IO;
using Xunit;

namespace LibSassBuilder.ExcludeTests
{
// This project is configured to run LibSassBuilder in LibSassBuilder.DirectoryTests.csproj excluding foo & bar directories
public class ExcludeTests
{
private readonly string _fileDirectory;

public ExcludeTests()
{
_fileDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
}

[Fact]
public void ExcludeFooFilesTest()
{
var fooFile = Path.Join(_fileDirectory, "foo/foo.css");
var barFile = Path.Join(_fileDirectory, "bar/bar.css");
var testFile = Path.Join(_fileDirectory, "test.css");

Assert.False(File.Exists(fooFile)); // excluded foo
Assert.False(File.Exists(barFile)); // excluded bar
Assert.True(File.Exists(testFile));

File.Delete(testFile);
}
}
}
26 changes: 26 additions & 0 deletions src/LibSassBuilder.ExcludeTests/LibSassBuilder.ExcludeTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet run --project ../LibSassBuilder -e foo bar" />
</Target>

</Project>
3 changes: 3 additions & 0 deletions src/LibSassBuilder.ExcludeTests/bar/bar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: black;
}
3 changes: 3 additions & 0 deletions src/LibSassBuilder.ExcludeTests/foo/foo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: black;
}
3 changes: 3 additions & 0 deletions src/LibSassBuilder.ExcludeTests/test.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: black;
}
14 changes: 13 additions & 1 deletion src/LibSassBuilder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ VisualStudioVersion = 16.0.30709.132
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibSassBuilder", "LibSassBuilder\LibSassBuilder.csproj", "{0DB56568-9B61-47C7-9B3A-74AD4B3EEC9A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibSassBuilder.Tests", "LibSassBuilder.Tests\LibSassBuilder.Tests.csproj", "{6401A537-4B7B-42F8-A515-67240B4C0F0C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibSassBuilder.Tests", "LibSassBuilder.Tests\LibSassBuilder.Tests.csproj", "{6401A537-4B7B-42F8-A515-67240B4C0F0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibSassBuilder.DirectoryTests", "LibSassBuilder.DirectoryTests\LibSassBuilder.DirectoryTests.csproj", "{F51D398C-D259-4539-8EE4-E037B213F3C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibSassBuilder.ExcludeTests", "LibSassBuilder.ExcludeTests\LibSassBuilder.ExcludeTests.csproj", "{16069D4E-516D-4DE6-A0E7-D2429E1F7485}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,6 +25,14 @@ Global
{6401A537-4B7B-42F8-A515-67240B4C0F0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6401A537-4B7B-42F8-A515-67240B4C0F0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6401A537-4B7B-42F8-A515-67240B4C0F0C}.Release|Any CPU.Build.0 = Release|Any CPU
{F51D398C-D259-4539-8EE4-E037B213F3C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F51D398C-D259-4539-8EE4-E037B213F3C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F51D398C-D259-4539-8EE4-E037B213F3C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F51D398C-D259-4539-8EE4-E037B213F3C6}.Release|Any CPU.Build.0 = Release|Any CPU
{16069D4E-516D-4DE6-A0E7-D2429E1F7485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16069D4E-516D-4DE6-A0E7-D2429E1F7485}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16069D4E-516D-4DE6-A0E7-D2429E1F7485}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16069D4E-516D-4DE6-A0E7-D2429E1F7485}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 2 additions & 1 deletion src/LibSassBuilder/LibSassBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.4.0</Version>
<Version>1.5.0</Version>
<TargetFramework>net5.0</TargetFramework>
<PackAsTool>true</PackAsTool>
<PackageId>LibSassBuilder-Tool</PackageId>
Expand All @@ -18,6 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="LibSassHost" Version="1.3.2" />
<PackageReference Include="LibSassHost.Native.linux-x64" Version="1.3.2" />
<PackageReference Include="LibSassHost.Native.osx-x64" Version="1.3.2" />
Expand Down
14 changes: 14 additions & 0 deletions src/LibSassBuilder/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using CommandLine;
using System.Collections.Generic;

namespace LibSassBuilder
{
public class Options
{
[Value(0, Required = false, HelpText = "Directory in which to run. Defaults to current directory.")]
public string Directory { get; set; } = System.IO.Directory.GetCurrentDirectory();

[Option('e', "exclude", Required = false, HelpText = "Specify explicit directories to exclude. Overrides the default.", Default = new[] { "bin", "obj", "logs", "node_modules" })]
public IEnumerable<string> ExcludedDirectories { get; set; }
}
}
29 changes: 13 additions & 16 deletions src/LibSassBuilder/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LibSassHost;
using CommandLine;
using LibSassHost;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -9,25 +10,21 @@ namespace LibSassBuilder
{
class Program
{
private static readonly List<string> _excludedDirectories = new List<string>
{
"bin",
"obj",
"logs",
"node_modules"
};

static async Task Main(string[] args)
{
var searchDirectory = args.Length > 0 ? args[0] : Directory.GetCurrentDirectory();
Console.WriteLine($"Sass compile directory: {searchDirectory}");
await Parser.Default.ParseArguments<Options>(args)
.WithNotParsed(e => Environment.Exit(1))
.WithParsedAsync(async o =>
{
Console.WriteLine($"Sass compile directory: {o.Directory}");
await CompileDirectoriesAsync(searchDirectory);
await CompileDirectoriesAsync(o.Directory, o.ExcludedDirectories);
Console.WriteLine("Sass files compiled");
Console.WriteLine("Sass files compiled");
});
}

static async Task CompileDirectoriesAsync(string directory)
static async Task CompileDirectoriesAsync(string directory, IEnumerable<string> excludedDirectories)
{
var sassFiles = Directory.EnumerateFiles(directory)
.Where(file => file.EndsWith(".scss", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".sass", StringComparison.OrdinalIgnoreCase));
Expand All @@ -37,10 +34,10 @@ static async Task CompileDirectoriesAsync(string directory)
var subDirectories = Directory.EnumerateDirectories(directory);
foreach (var subDirectory in subDirectories)
{
if (_excludedDirectories.Any(dir => subDirectory.EndsWith(dir, StringComparison.OrdinalIgnoreCase)))
if (excludedDirectories.Any(dir => subDirectory.EndsWith(dir, StringComparison.OrdinalIgnoreCase)))
continue;

await CompileDirectoriesAsync(subDirectory);
await CompileDirectoriesAsync(subDirectory, excludedDirectories);
}
}

Expand Down

0 comments on commit 1728325

Please sign in to comment.