Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hermanussen/Fairy
A source generator that generates C# code based on Sitecore Content Serialization (SCS) .yml files.
https://github.com/hermanussen/Fairy
csharp-sourcegenerator sitecore
Last synced: about 1 month ago
JSON representation
A source generator that generates C# code based on Sitecore Content Serialization (SCS) .yml files.
- Host: GitHub
- URL: https://github.com/hermanussen/Fairy
- Owner: hermanussen
- License: mit
- Created: 2021-01-30T12:29:34.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-31T16:15:56.000Z (almost 4 years ago)
- Last Synced: 2024-08-01T22:43:56.533Z (4 months ago)
- Topics: csharp-sourcegenerator, sitecore
- Language: C#
- Homepage:
- Size: 1.49 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- csharp-source-generators - Fairy - ![stars](https://img.shields.io/github/stars/hermanussen/Fairy?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/hermanussen/Fairy?style=flat-square&cacheSeconds=86400) generates C# code based on Sitecore Content Serialization (SCS) `.yml` files. (Source Generators / Other)
- RSCG_Examples - Fairy
README
# Fairy
A source generator that generates C# code based on Sitecore Content Serialization (SCS) `.yml` files.
![publish to nuget](https://github.com/hermanussen/Fairy/workflows/publish%20to%20nuget/badge.svg) [![Nuget](https://img.shields.io/nuget/v/Fairy)](https://www.nuget.org/packages/Fairy/) [![Nuget](https://img.shields.io/nuget/dt/Fairy?label=nuget%20downloads)](https://www.nuget.org/packages/Fairy/) [![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2Fknifecore%2F)](https://twitter.com/knifecore)
> :warning: This package is highly experimental! It has not been tested very well.
> :warning: Visual Studio does not support generated code very well in < .NET 5 projects, and Sitecore needs a 4.x full framework version. This results in errors when editing (though it DOES work when building).
## Installation
1. Ensure that you have .NET 5 installed. It does not have to be used in your project, but you do need it for the source generator to work.
2. Install the NuGet package in your project. Run the following command in the NuGet package manager console
```
Install-Package Fairy
```
3. Ensure the SCS `.yml` files that you want to generate code for are added as `AdditionalFiles` in your `.csproj` file. E.g.:
```xml
```
4. You can now use the generated classes in your code. Reference the following namespace to get to them.
```csharp
using Templates;
```## Use your own Scriban template instead of the default one
If you have specific needs for the generated code, you can easily create a [Scriban](https://github.com/scriban/scriban) template to replace the default one. All you have to do is:
1. Create a file named `FairyTemplate.sbntxt` and place it in the root of your project.
2. Ensure that the file is included in the `AdditionalFiles` for your project (the same way that you include your json files).
3. Copy the contents of the [default template](Fairy/FairyTemplate.sbntxt), paste them in the file and save. Or find a template you like under [the templates that are used for testing](Fairy.Tests/Templates/)
4. Change the template in any way you want, and you should observe the changes when you build your project.## Viewing generated source files
Because of the Visual Studio issue that is mentioned in the warning above, it may be helpful to view the generated source files. If you add the following to your project file, you can see the generated files in the `obj\GeneratedFiles` folder.
```xml
true
$(BaseIntermediateOutputPath)\GeneratedFiles```
## More
It was based on ideas and code from:
- [Leprechaun](https://github.com/blipson89/Leprechaun) - code generation tool for Sitecore
- [Helixbase](https://github.com/muso31/Helixbase) - used mainly for testing
- [RainbowDataAnalyzer](https://github.com/hermanussen/RainbowDataAnalyzer) (my own project)
- [JsonByExampleGenerator](https://github.com/hermanussen/JsonByExampleGenerator/) (my own project)