Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
PluginGenerator.cs
1using System.Linq;
2using System;
3using System.IO;
4using Newtonsoft.Json;
5using Newtonsoft.Json.Linq;
6using Nuke.Common.IO;
7using Nuke.Common;
8
10{
11 public record PluginModel(
12 string Name, string? Copyright,
13 string UeVersion, UnrealProject Project
14 ) : CommonModelBase(Name, Copyright);
15
17 {
18 protected PluginModel? Model;
19 public string TemplateSubfolder => "Plugin";
20
21 public void Generate(AbsolutePath templatesPath, AbsolutePath currentFolder, string name, EngineVersion ueVersion)
22 {
23 var project = new UnrealProject(currentFolder);
24 Model = new(
25 Name: name,
26 Copyright: Unreal.ReadCopyrightFromProject(project.Folder!),
27 Project: project,
28 UeVersion: ueVersion.VersionMinor
29 );
30
31 var projectMainPluginsFolder = project.Folder / "Plugins";
32 var pluginsFolder = currentFolder.ToString().Contains(projectMainPluginsFolder)
33 ? currentFolder
34 : projectMainPluginsFolder;
35
36 if(!Directory.Exists(pluginsFolder))
37 Directory.CreateDirectory(pluginsFolder);
38
39 if(Directory.Exists(pluginsFolder / name))
40 {
41 throw new InvalidOperationException($"The plugin folder of {name} already exists in project plugins.");
42 }
43
44 if(!Directory.Exists(templatesPath / TemplateSubfolder))
45 templatesPath = DefaultTemplateFolder;
46
47 var templateDir = templatesPath / TemplateSubfolder;
48
49 RenderFolder(templateDir, pluginsFolder / name, Model);
50
51 var srcFolder = pluginsFolder / name / "Source";
52 Directory.CreateDirectory(srcFolder);
53
54 new ModuleGenerator().Generate(templatesPath, srcFolder, name);
55 }
56 }
57}
static void RenderFolder(AbsolutePath templateRoot, AbsolutePath destinationFolder, object model, AbsolutePath? currentFolder=null)
Render scriban templated scaffoldings and files to destination folder.
High level representation of an Unreal Engine version.
string VersionMinor
Only the Major.Minor version components, with extra information trimmed.
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
Definition Unreal.cs:24
static string ReadCopyrightFromProject(AbsolutePath projectFolder)
Read copyright info from the project's DefaultGame.ini
Definition Unreal.cs:321