This repository was archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtemplates.cake
More file actions
136 lines (121 loc) · 5.1 KB
/
templates.cake
File metadata and controls
136 lines (121 loc) · 5.1 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
130
131
132
133
134
135
136
#addin nuget:?package=Cake.Git&version=0.16.1
#addin nuget:?package=Cake.Handlebars&version=0.2.0
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Build-Templates");
var configuration = Argument("configuration", "Release");
var model = new {
source = "generated by yeoman using generator-cake",
cake = new {
version = "0.21.1",
target = "netstandard1.6;net46",
frosting = new {
context = "<%= settingsType %>",
lifetime = "<%= lifetimeType %>",
tasks = new[] {
new {
name = "Default",
skipRun = true,
runBody = $"// If you don't inherit from FrostingTask<MySettings>{Environment.NewLine} // the standard ICakeContext will be provided.{Environment.NewLine}",
dependencies = new[] { "<%= taskName %>" }
},
new {
name = "<%= taskName %>",
skipRun = false,
runBody = "", // this is needed for anonymous types to not bork out. Templates don't *need* this property
dependencies = new string[0] // as above
}
}
}
},
project = new {},
test = new {}
};
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
if (DirectoryExists("./.templates")) {
CleanTemplatesDirectory("./.templates");
}
// CreateDirectory("./.templates");
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clone")
.Does(() => {
GitClone(
"https://github.com/cake-build/pantry.git",
"./.templates"
);
});
Task("Render-Script-Template")
.IsDependentOn("Clone")
.Does(() => {
var template = RenderTemplateFromFile("./.templates/template/build.cake.hbs", model);
WriteTemplateToFile(template, "./generators/app/templates/build.cake");
});
Task("Render-Config-Template")
.IsDependentOn("Clone")
.Does(() => {
var template = RenderTemplateFromFile("./.templates/template/cake.config.hbs", model);
WriteTemplateToFile(template, "./generators/config/templates/cake.config");
});
Task("Render-Bootstrapper-Templates")
.IsDependentOn("Clone")
.Does(() => {
var template = RenderTemplateFromFile("./.templates/template/build.ps1.hbs", model);
WriteTemplateToFile(template, "./generators/bootstrapper/templates/build.ps1");
var bTemplate = RenderTemplateFromFile("./.templates/template/build.sh.hbs", model);
WriteTemplateToFile(bTemplate, "./generators/bootstrapper/templates/build.sh");
});
Task("Render-Frosting-Templates")
.IsDependentOn("Clone")
.Does(() => {
Information("Rendering the Context template");
var context = RenderTemplateFromFile("./.templates/template/frosting/Context.cs.hbs", model);
WriteTemplateToFile(context, "./generators/frosting/templates/context.cs");
Information("Rendering the Lifetime template");
var lifetime = RenderTemplateFromFile("./.templates/template/frosting/Lifetime.cs.hbs", model);
WriteTemplateToFile(lifetime, "./generators/frosting/templates/lifetime.cs");
Information("Rendering the Program template");
var program = RenderTemplateFromFile("./.templates/template/frosting/Program.cs.hbs", model);
WriteTemplateToFile(program, "./generators/frosting/templates/program.cs");
Information("Rendering the Task templates");
var tasksTemplate = RenderTemplateFromFile("./.templates/template/frosting/Tasks/Tasks.cs.hbs", model);
WriteTemplateToFile(tasksTemplate, "./generators/frosting/templates/task.cs");
/* The loop below will generate single-file task templates only. See Pantry README for more info.
foreach (var task in model.cake.frosting.tasks) {
Information("Rendering the template for Task '{0}'", task.name ?? "unknown");
var taskTemplate = RenderTemplateFromFile("./.templates/template/frosting/Tasks/Task.cs.hbs", task);
WriteTemplateToFile(taskTemplate, "./generators/frosting/templates/" + (task.name.Contains("<%") ? "task.cs" : (task.name + ".cs")));
} */
});
Task("Build-Templates")
.IsDependentOn("Render-Script-Template")
.IsDependentOn("Render-Config-Template")
.IsDependentOn("Render-Bootstrapper-Templates")
.IsDependentOn("Render-Frosting-Templates");
RunTarget(target);
void WriteTemplateToFile(string template, FilePath targetFile) {
using (var writer = new StreamWriter(Context.FileSystem.GetFile(targetFile).OpenWrite())) {
writer.Write(template);
}
}
void CleanTemplatesDirectory(DirectoryPath templateDirectoryPath) {
var files = GetFiles(templateDirectoryPath + "/**/*");
foreach(var file in files) {
System.IO.File.SetAttributes(file.FullPath, FileAttributes.Normal);
}
DeleteDirectory(templateDirectoryPath, new DeleteDirectorySettings { Force = true, Recursive = true });
}