Building
Now that you've carefully reviewed how to build a template tree and are familiar with the rules, let's move on to the main stage - building a plugin.
- Download the .NET SDK 8.
- Clone the ScyScaff repository.
- Create a solution and a new Class Library project using .NET CLI:
dotnet new sln
dotnew new classlib -o PluginName
dotnet sln add PluginName/PluginName.csproj
- Open the created PluginName.csproj file and add the highlighted lines:
- Lines from 4 to 6 are necessary to enable dynamic loading of our plugin.
- Lines from 10 to 18 add references to the ScyScaff project itself, from which we take the necessary interfaces. It's important to note that the Include fields (lines 10 and 15) may have a different relative path to the ScyScaff projects, adjust it if needed.
- Lines from 20 to 22 add a rule where the TemplateTree folder in the same directory as our .csproj file will be copied to the output build.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ScyScaff\ScyScaff.Core\ScyScaff.Core.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\ScyScaff\ScyScaff.Docker\ScyScaff.Docker.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<Content Include="./TemplateTree/**/*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
- As noted in step 4.3, you'll need to create a Template Tree folder in the same directory as your .csproj file, this is where you'll place all your template tree contents.
- Create a PluginName.cs file in the folder with your .csproj. Choose the interface you need (IFrameworkTemplatePlugin, IDashboardTemplatePlugin, IGlobalWorkerTemplatePlugin) and implement its fields:
public class PluginNameFramework : IFrameworkTemplatePlugin
{
// Fields required for any plugin:
public string Name => "plugin-name";
public Dictionary<string, string[]> SupportedFlags { get; } = new()
{
// If you specify a list without an asterisk, then only one of the listed values will be allowed to be used in the configuration.
{ "Logging", new[] { "elk", "graylog" } },
// If you add just an asterisk, the configuration will allow any value.
{ "CustomParameterWithAnyValue", new[] { "*" } }
};
// Fields required for IFrameworkTemplatePlugin:
public string[] SupportedAuth { get; } = { "example-auth" };
public string[] SupportedDatabases { get; } = { "example-db" };
}
- Add the templates you need to the TemplateTree folder. Example:
├── PluginName.csproj
├── PluginName.cs
└── TemplateTree/
├── models/
│ ├── [...modelIterator...]
│ └── {{ model.key }}.js.liquid
└── app.js.liquid
- Compile the project using .NET CLI:
dotnet build
- Navigate to the folder with the compiled contents (the "bin" folder in your project directory) and create a metadata.json file:
- In the PluginType field - Specify the type of plugin you've made (FrameworkPlugin, DashboardPlugin, GlobalWorkerPlugin).
- In the ExecutablePath field - Specify the relative path to the main DLL file.
{
"PluginType": "FrameworkPlugin",
"ExecutablePath": "./PluginName.dll"
}
- Copy all DLL files, metadata.json, and the TemplateTree folder and paste it into the user plugins folder of ScyScaff.
- On Windows - This is "%appdata%/scyscaff/".
- On Linux - This is "home/.config/scyscaff/".
- On MacOS - This is "/users/username/.config/scyscaff/".
- It is important to copy absolutely all DLL files, since there may be several of them if, for example, you installed a library.
- Create a configuration file with settings pointing to your plugin:
Auth: example-auth
Services:
Products:
Framework: plugin-name
Database: example-db
Models:
Category:
Title: string
Description: string
- Run Scaffolder and enjoy! ;)
Output:
└── TestProjectName.Products/
├── Models/
│ ├── Title.js
│ └── Description.js
└── app.js
This is just a superficial description of the possibilities. For more complex tasks, refer to Events and Docker integration capabilities.