-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cake
78 lines (66 loc) · 2.83 KB
/
build.cake
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
#addin nuget:?package=Cake.Incubator&version=8.0.0
using System.Diagnostics;
using System.Linq;
using System.Threading;
var target = Argument("target", "Run");
var config = Argument("configuration", "Release");
var userArgs = Argument("args", "");
var projectFile = Argument("project", GetFiles("**/*.csproj").FirstOrDefault());
var project = ParseProject(projectFile, config);
var outputPath = project.OutputPaths.FirstOrDefault();
var zipOutputPath = $"{outputPath.GetParent()}/{project.AssemblyName}.zip";
var tinyLifeDir = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/Tiny Life";
Task("Clean").Does(() => {
EnsureDirectoryDoesNotExist($"bin/{config}");
EnsureDirectoryDoesNotExist($"{tinyLifeDir}/Mods/_Dev");
});
Task("Build").Does(() => {
DotNetBuild(projectFile.FullPath, new DotNetBuildSettings {
Configuration = config
});
});
Task("Zip").IsDependentOn("Build").Does(() => {
Zip(outputPath, zipOutputPath, GetFiles($"{outputPath}/**/*"));
Information($"Created zip archive {zipOutputPath}");
});
Task("CopyToMods").IsDependentOn("Zip").Does(() => {
var dir = $"{tinyLifeDir}/Mods/_Dev";
EnsureDirectoryExists(dir);
CopyFileToDirectory(zipOutputPath, dir);
});
Task("Run").IsDependentOn("CopyToMods").Does(() => {
// start the tiny life process
var exeDir = System.IO.File.ReadAllText($"{tinyLifeDir}/GameDir");
var process = Process.Start(new ProcessStartInfo($"{exeDir}/Tiny Life") {
Arguments = $"-v --skip-splash --skip-preloads --debug-saves --ansi {userArgs}",
RedirectStandardOutput = true,
RedirectStandardError = true
});
// make sure the output buffers (which we ignore) don't fill up
process.BeginOutputReadLine();
process.BeginErrorReadLine();
// we wait a bit to make sure the process has generated a new log file
Thread.Sleep(1000);
// attach to the newest log file
var logsDir = $"{tinyLifeDir}/Logs";
var log = System.IO.Directory.EnumerateFiles(logsDir).OrderByDescending(System.IO.File.GetCreationTime).FirstOrDefault();
if (log != null) {
using (var stream = new FileStream(log, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
using (var reader = new StreamReader(stream)) {
var lastPos = 0L;
do {
if (stream.Length > lastPos) {
stream.Seek(lastPos, SeekOrigin.Begin);
string line;
while ((line = reader.ReadLine()) != null)
Information(line);
lastPos = stream.Position;
}
Thread.Sleep(10);
} while (!process.HasExited);
}
}
}
Information($"Tiny Life exited with exit code {process.ExitCode}");
});
RunTarget(target);