-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cake
More file actions
129 lines (105 loc) · 3.76 KB
/
build.cake
File metadata and controls
129 lines (105 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var target = Argument("target", "CopyModToRW");
var configuration = Argument("configuration", "Debug");
var rainWorldPath = Argument("rainWorldPath", string.Empty);
var projectName = Argument("project", "tvardero.DearDevTools");
Task("Clean")
.Does(() =>
{
var projectPath = $"./src/{projectName}";
var outputPath = $"./dist/{projectName}";
DotNetClean(projectPath);
if (DirectoryExists(outputPath))
{
CleanDirectory(outputPath);
}
Information($"Cleaned project output");
});
Task("PackMod")
.IsDependentOn("Clean")
.Does(() =>
{
var projectPath = $"./src/{projectName}";
var outputPath = $"./dist/{projectName}";
var pluginsPath = $"{outputPath}/plugins";
DotNetPublish(projectPath, new DotNetPublishSettings
{
Configuration = configuration,
OutputDirectory = pluginsPath
});
Information($"Built and copied .dll files");
var assetsSource = MakeAbsolute(new DirectoryPath($"{projectPath}/Assets"));
var assetsTarget = MakeAbsolute(new DirectoryPath($"{outputPath}/"));
var assetSourceFiles = GetFiles($"{assetsSource}/**/*");
Information(assetsSource);
Information(assetsTarget);
foreach (FilePath file in assetSourceFiles)
{
var targetFilePath = new FilePath(file.ToString().Replace(assetsSource.ToString(), assetsTarget.ToString()));
CreateDirectory(targetFilePath.GetDirectory()); // Ensure directory exists
CopyFile(file, targetFilePath);
}
Information($"Done packing the mod");
});
Task("CopyModToRW")
.IsDependentOn("PackMod")
.Does(() =>
{
rainWorldPath = rainWorldPath?.Trim();
if (string.IsNullOrEmpty(rainWorldPath))
{
rainWorldPath = EnvironmentVariable("RAINWORLD_PATH");
rainWorldPath = rainWorldPath?.Trim();
}
if (string.IsNullOrEmpty(rainWorldPath))
{
rainWorldPath = ReadEnvFile("RAINWORLD_PATH");
rainWorldPath = rainWorldPath?.Trim();
}
if (string.IsNullOrEmpty(rainWorldPath))
throw new Exception("Rain World installation path is required. Specify it with --rainWorldPath argument, "
+ "RAINWORLD_PATH environment variable or with .env or .env.local file.");
var rainWorldModsPath = $"{rainWorldPath}/RainWorld_Data/StreamingAssets/mods";
var modPath = $"{rainWorldModsPath}/{projectName}";
if (!DirectoryExists(modPath))
{
CreateDirectory(modPath);
}
else
{
CleanDirectory(modPath);
}
var outputPath = $"./dist/{projectName}";
CopyDirectory(outputPath, modPath);
Information($"Copied packed mod to {modPath}");
});
RunTarget(target);
// Helper method to read environment variable from .env files
string ReadEnvFile(string key)
{
var envFiles = new[] { ".env.local", ".env" };
foreach (var envFile in envFiles)
{
if (FileExists(envFile))
{
var lines = System.IO.File.ReadAllLines(envFile);
foreach (var line in lines)
{
if (string.IsNullOrWhiteSpace(line) || line.TrimStart().StartsWith("#"))
continue;
var parts = line.Split(new[] { '=' }, 2);
if (parts.Length == 2 && parts[0].Trim() == key)
{
var value = parts[1].Trim();
// Remove surrounding quotes if present
if ((value.StartsWith("\"") && value.EndsWith("\"")) ||
(value.StartsWith("'") && value.EndsWith("'")))
{
value = value.Substring(1, value.Length - 2);
}
return value;
}
}
}
}
return null;
}