Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
TargetGenerator.cs
1using System.Linq;
2using System;
3using System.IO;
4using Newtonsoft.Json;
5using Newtonsoft.Json.Linq;
6using Nuke.Common.IO;
7using Nuke.Common;
8using Microsoft.CodeAnalysis;
9using Microsoft.CodeAnalysis.CSharp;
10using Microsoft.CodeAnalysis.CSharp.Syntax;
11
13{
14 public record TargetModel(
15 string Name, string? Copyright,
16 UnrealProject Project
17 ) : CommonModelBase(Name, Copyright);
18
20 {
21 protected TargetModel? Model;
22 public string TemplateSubfolder => "Target";
23
24 public void Generate(AbsolutePath templatesPath, AbsolutePath currentFolder, string name)
25 {
26 var project = new UnrealProject(currentFolder);
27 Model = new(
28 Name: name,
29 Copyright: Unreal.ReadCopyrightFromProject(project.Folder!),
30 Project: project
31 );
32
33 if(!Directory.Exists(templatesPath / TemplateSubfolder))
34 templatesPath = DefaultTemplateFolder;
35
36 var templateDir = templatesPath / TemplateSubfolder;
37
38 RenderFolder(templateDir, currentFolder, Model);
39
40 var srcFolder = currentFolder / "Source";
41 Directory.CreateDirectory(srcFolder);
42
43 new ModuleGenerator()
44 .SetAddToTarget(true)
45 .Generate(templatesPath, srcFolder, name);
46 }
47
48 protected void CheckInsideSourceFolder(AbsolutePath currentFolder)
49 {
50 if(!currentFolder.ToString().Contains("Source", StringComparison.InvariantCultureIgnoreCase))
51 {
52 throw new InvalidOperationException(
53 $"{currentFolder} doesn't contain a Source folder. Unreal Engine requires Module to be inside the project or plugin Source folder."
54 );
55 }
56 }
57 }
58}
static void RenderFolder(AbsolutePath templateRoot, AbsolutePath destinationFolder, object model, AbsolutePath? currentFolder=null)
Render scriban templated scaffoldings and files to destination folder.
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