-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.cake
145 lines (132 loc) · 4.54 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#addin nuget:?package=Cake.Npm&version=2.0.0
var target = Argument("Target", "Default");
var configuration =
HasArgument("Configuration") ? Argument<string>("Configuration") :
EnvironmentVariable("Configuration", "Release");
var artefactsDirectory = Directory("./Artefacts");
var frontendDirectory = GetDirectories("Source/DotnetNewUI/Frontend").First();
var frontendDistDirectory = GetDirectories("Source/DotnetNewUI/Frontend/dist").FirstOrDefault();
Task("Clean")
.Description("Cleans the artefacts, bin and obj directories.")
.Does(() =>
{
if (frontendDistDirectory != null) {
CleanDirectory(frontendDistDirectory);
}
CleanDirectory(artefactsDirectory);
DeleteDirectories(GetDirectories("**/bin"), new DeleteDirectorySettings() { Force = true, Recursive = true });
DeleteDirectories(GetDirectories("**/obj"), new DeleteDirectorySettings() { Force = true, Recursive = true });
});
Task("RestoreNPM")
.Description("Restores NPM packages.")
.Does(() =>
{
NpmCi(x => x.FromPath(frontendDirectory));
});
Task("BuildNPM")
.Description("Builds the NPM project.")
.IsDependentOn("RestoreNPM")
.Does(() =>
{
NpmRunScript("build", x => x.FromPath(frontendDirectory));
});
Task("Restore")
.Description("Restores NuGet packages.")
.Does(() =>
{
DotNetRestore();
});
Task("Build")
.Description("Builds the solution.")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetBuild(
".",
new DotNetBuildSettings()
{
Configuration = configuration,
NoRestore = true,
});
});
Task("Test")
.Description("Runs unit tests and outputs test results to the artefacts directory.")
.DoesForEach(
GetFiles("./Tests/**/*.csproj"),
project =>
{
DotNetTest(
project.ToString(),
new DotNetTestSettings()
{
Blame = true,
Collectors = new string[] { "Code Coverage", "XPlat Code Coverage" },
Configuration = configuration,
Loggers = new string[]
{
$"trx;LogFilePrefix={project.GetFilenameWithoutExtension()}",
$"junit;LogFileName={project.GetFilenameWithoutExtension()}_{{framework}}.xml",
$"html;LogFilePrefix={project.GetFilenameWithoutExtension()}",
},
NoBuild = true,
NoRestore = true,
ResultsDirectory = artefactsDirectory,
});
});
Task("Pack")
.Description("Creates NuGet packages and outputs them to the artefacts directory.")
.Does(() =>
{
DotNetPack(
".",
new DotNetPackSettings()
{
Configuration = configuration,
IncludeSymbols = true,
MSBuildSettings = new DotNetMSBuildSettings()
{
ContinuousIntegrationBuild = !BuildSystem.IsLocalBuild,
},
NoBuild = true,
NoRestore = true,
OutputDirectory = artefactsDirectory,
});
});
Task("Install")
.Description("Install the dotnet tool globally.")
.Does(() =>
{
StartProcess("powershell", new ProcessSettings().WithArguments(x => x.Append("./ClearCache.ps1")));
StartProcess(
"dotnet",
new ProcessSettings()
.WithArguments(x => x
.Append("tool")
.Append("install")
.Append("--global")
.Append("--no-cache")
.AppendSwitch("--add-source", "./Artefacts")
.Append("new-ui")));
});
Task("Uninstall")
.Description("Uninstall the dotnet tool globally.")
.Does(() =>
{
StartProcess(
"dotnet",
new ProcessSettings()
.WithArguments(x => x
.Append("tool")
.Append("uninstall")
.Append("--global")
.Append("new-ui")));
});
Task("Default")
.Description("Cleans, restores NuGet packages, builds the solution, runs unit tests and then creates NuGet packages.")
.IsDependentOn("Clean")
.IsDependentOn("RestoreNPM")
.IsDependentOn("BuildNPM")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Pack");
RunTarget(target);