/
build.cake
124 lines (100 loc) · 2.87 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
string target = Argument( "target", "taste" );
const string pretzelExe = "./_pretzel/src/Pretzel/bin/Debug/net6.0/Pretzel.dll";
const string pluginDir = "./_plugins";
const string categoryPlugin = "./_plugins/Pretzel.Categories.dll";
const string extensionPlugin = "./_plugins/Pretzel.SethExtensions.dll";
// ---------------- Tasks ----------------
Task( "taste" )
.Does(
() =>
{
RunPretzel( "taste", false );
}
).Description( "Calls pretzel taste to try the site locally" );
Task( "generate" )
.Does(
() =>
{
EnsureDirectoryExists( "_site" );
CleanDirectory( "_site" );
RunPretzel( "bake", true );
}
).Description( "Builds the site for publishing." );
Task( "build_pretzel" )
.Does(
() =>
{
BuildPretzel();
}
).Description( "Compiles Pretzel" );
Task( "build_all" )
.IsDependentOn( "build_pretzel" )
.IsDependentOn( "taste" );
// ---------------- Functions ----------------
void BuildPretzel()
{
Information( "Building Pretzel..." );
var settings = new DotNetBuildSettings
{
Configuration = "Debug"
};
DotNetBuild( "./_pretzel/src/Pretzel.sln", settings );
EnsureDirectoryExists( pluginDir );
// Move Pretzel.Categories.
{
FilePathCollection files = GetFiles( "./_pretzel/src/Pretzel.Categories/bin/Debug/net6.0/Pretzel.Categories.*" );
CopyFiles( files, Directory( pluginDir ) );
}
// Move Pretzel.SethExtensions
{
FilePathCollection files = GetFiles( "./_pretzel/src/Pretzel.SethExtensions/bin/Debug/net6.0/Pretzel.SethExtensions.*" );
CopyFiles( files, Directory( pluginDir ) );
}
Information( "Building Pretzel... Done!" );
}
void RunPretzel( string argument, bool abortOnFail )
{
CheckPretzelDependency();
bool fail = false;
string onStdOut( string line )
{
if( string.IsNullOrWhiteSpace( line ) )
{
return line;
}
else if( line.StartsWith( "Failed to render template" ) )
{
fail = true;
}
Console.WriteLine( line );
return line;
}
var settings = new ProcessSettings
{
Arguments = ProcessArgumentBuilder.FromString( $"\"{pretzelExe}\" {argument} --debug" ),
Silent = false,
RedirectStandardOutput = abortOnFail,
RedirectedStandardOutputHandler = onStdOut
};
int exitCode = StartProcess( "dotnet", settings );
if( exitCode != 0 )
{
throw new Exception( $"Pretzel exited with exit code: {exitCode}" );
}
if( abortOnFail && fail )
{
throw new Exception( "Failed to render template" );
}
}
void CheckPretzelDependency()
{
if(
( FileExists( pretzelExe ) == false ) ||
( FileExists( categoryPlugin ) == false ) ||
( FileExists( extensionPlugin ) == false )
)
{
BuildPretzel();
}
}
RunTarget( target );