-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.cake
200 lines (162 loc) · 5.97 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#addin nuget:?package=Cake.FileHelpers&version=6.0.0
var target = Argument<string>("target", "Default");
var project = Argument<string>("project", "ChickAndPaddy");
var @namespace = Argument<string>("namspace", "ChickAndPaddy");
var feature = Argument<string>("feature", "FeatureX");
var model = Argument<string>("model", string.Empty);
var forced = Argument<bool>("forced", false);
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
const string FEATURE_FODLER_PATH_TEMPLATE="./src/{0}/Features/{1}";
Task("popup")
.Does(() =>
{
var page = Argument<string>("popup", string.Empty);
if (string.IsNullOrWhiteSpace(page)) {
page = Argument<string>("name");
}
var featureFolderPath = string.Format(FEATURE_FODLER_PATH_TEMPLATE, project, feature);
Information("Feature folder path: " + featureFolderPath);
if (!DirectoryExists(featureFolderPath)) {
CreateDirectory(featureFolderPath);
}
var pagesFolderPath = $"{featureFolderPath}/Popups";
if (!DirectoryExists(pagesFolderPath)) {
CreateDirectory(pagesFolderPath);
}
var pageXamlFilePath = $"{pagesFolderPath}/{page}Popup.xaml";
if (!forced && FileExists(pageXamlFilePath)) {
Warning($"Popup {page}Popup exists!!!!!");
return;
}
Information($"\n>> Generate >> {page}Popup.xaml");
FileWriteText($"{pagesFolderPath}/{page}Popup.xaml", $@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<app:BasePage
xmlns=""http://schemas.microsoft.com/dotnet/2021/maui""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
xmlns:app=""clr-namespace:{@namespace}""
x:Class=""{@namespace}.{page}Popup""
x:DataType=""app:{page}PopupViewModel""
Title=""{page}"">
<VerticalStackLayout>
<Label
Text=""This is {page}!""
VerticalOptions=""Center""
HorizontalOptions=""Center"" />
</VerticalStackLayout>
</app:BasePage>");
Information($"\n>> Generate >> {page}Popup.xaml.cs");
FileWriteText($"{pagesFolderPath}/{page}Popup.xaml.cs", $@"namespace {@namespace};
public partial class {page}Popup
{{
public {page}Popup({page}PopupViewModel vm)
{{
InitializeComponent();
BindingContext = vm;
}}
}}");
Information($"\n>> Generate >> {page}PopupViewModel.cs");
FileWriteText($"{pagesFolderPath}/{page}PopupViewModel.cs", $@"namespace {@namespace};
public partial class {page}PopupViewModel : NavigationAwareBaseViewModel
{{
public {page}PopupViewModel(
IAppNavigator appNavigator
) : base(appNavigator)
{{
}}
}}");
});
Task("page")
.Does(() =>
{
var page = Argument<string>("page", string.Empty);
if (string.IsNullOrWhiteSpace(page)) {
page = Argument<string>("name");
}
var featureFolderPath = string.Format(FEATURE_FODLER_PATH_TEMPLATE, project, feature);
Information("Feature folder path: " + featureFolderPath);
if (!DirectoryExists(featureFolderPath)) {
CreateDirectory(featureFolderPath);
}
var pagesFolderPath = $"{featureFolderPath}/Pages";
if (!DirectoryExists(pagesFolderPath)) {
CreateDirectory(pagesFolderPath);
}
var pageXamlFilePath = $"{pagesFolderPath}/{page}Page.xaml";
if (!forced && FileExists(pageXamlFilePath)) {
Warning($"Page {page}Page exists!!!!!");
return;
}
Information($"\n>> Generate >> {page}Page.xaml");
FileWriteText($"{pagesFolderPath}/{page}Page.xaml", $@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<app:BasePage
xmlns=""http://schemas.microsoft.com/dotnet/2021/maui""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
xmlns:app=""clr-namespace:{@namespace}""
x:Class=""{@namespace}.{page}Page""
x:DataType=""app:{page}PageViewModel""
Title=""{page}"">
<VerticalStackLayout>
<Label
Text=""This is {page}!""
VerticalOptions=""Center""
HorizontalOptions=""Center"" />
</VerticalStackLayout>
</app:BasePage>");
Information($"\n>> Generate >> {page}Page.xaml.cs");
FileWriteText($"{pagesFolderPath}/{page}Page.xaml.cs", $@"namespace {@namespace};
public partial class {page}Page
{{
public {page}Page({page}PageViewModel vm)
{{
InitializeComponent();
BindingContext = vm;
}}
}}");
Information($"\n>> Generate >> {page}PageViewModel.cs");
FileWriteText($"{pagesFolderPath}/{page}PageViewModel.cs", $@"namespace {@namespace};
public partial class {page}PageViewModel : NavigationAwareBaseViewModel
{{
public {page}PageViewModel(
IAppNavigator appNavigator
) : base(appNavigator)
{{
}}
}}");
});
Task("model")
.Does(() =>
{
var name = Argument<string>("model", string.Empty);
if (string.IsNullOrWhiteSpace(name)) {
name = Argument<string>("name");
}
var form = Argument<bool>("form", false);
var featureFolderPath = string.Format(FEATURE_FODLER_PATH_TEMPLATE, project, feature);
Information("Feature folder path: " + featureFolderPath);
if (!DirectoryExists(featureFolderPath)) {
CreateDirectory(featureFolderPath);
}
var modelsFolderPath = $"{featureFolderPath}/Models";
if (!DirectoryExists(modelsFolderPath)) {
CreateDirectory(modelsFolderPath);
}
var modelSuffix = form ? "FormModel" : "Model";
var modelFilePath = $"{modelsFolderPath}/{name}{modelSuffix}.cs";
if (!forced && FileExists(modelFilePath)) {
Warning($"Model {name}{modelSuffix} exists!!!!!");
return;
}
Information($"\n>> Generate >> {name}{modelSuffix}.cs");
FileWriteText($"{modelsFolderPath}/{name}{modelSuffix}.cs", $@"namespace {@namespace};
public partial class {name}{modelSuffix} : Base{modelSuffix}
{{
}}");
});
Task("Default")
.IsDependentOn("page");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);