-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuild.cake
195 lines (157 loc) · 6.25 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
#addin nuget:?package=Cake.Azure&version=0.3.0
#addin nuget:?package=Cake.Http&version=0.6.1
#addin nuget:?package=Cake.Json&version=3.0.1
#addin nuget:?package=Cake.Powershell&version=0.4.8
#addin nuget:?package=Cake.XdtTransform&version=0.16.0
#addin nuget:?package=Newtonsoft.Json&version=11.0.2
#load "local:?path=CakeScripts/helper-methods.cake"
var target = Argument<string>("Target", "Default");
var configuration = new Configuration();
var cakeConsole = new CakeConsole();
var unicornSyncScript = $"./scripts/Unicorn/Sync.ps1";
var configJsonFile = "cake-config.json";
/*===============================================
================ MAIN TASKS =====================
===============================================*/
Setup(context =>
{
cakeConsole.ForegroundColor = ConsoleColor.Yellow;
var configFile = new FilePath(configJsonFile);
configuration = DeserializeJsonFromFile<Configuration>(configFile);
});
Task("Default")
.WithCriteria(configuration != null)
.IsDependentOn("Clean")
.IsDependentOn("Copy-Sitecore-Lib")
.IsDependentOn("Publish-Website-Projects")
.IsDependentOn("Apply-Xml-Transform")
.IsDependentOn("Modify-Unicorn-Source-Folder")
.IsDependentOn("Publish-Transforms")
.IsDependentOn("Sync-Unicorn")
.IsDependentOn("Deploy-EXM-Campaigns");
Task("Quick-Deploy")
.WithCriteria(configuration != null)
.IsDependentOn("Clean")
.IsDependentOn("Copy-Sitecore-Lib")
.IsDependentOn("Publish-Website-Projects")
.IsDependentOn("Apply-Xml-Transform")
.IsDependentOn("Modify-Unicorn-Source-Folder")
.IsDependentOn("Publish-Transforms");
Task("Initial")
.WithCriteria(configuration != null)
.IsDependentOn("Clean")
.IsDependentOn("Copy-Sitecore-Lib")
.IsDependentOn("Publish-Website-Projects")
.IsDependentOn("Apply-Xml-Transform")
.IsDependentOn("Modify-Unicorn-Source-Folder")
.IsDependentOn("Publish-Transforms")
.IsDependentOn("Sync-Unicorn")
.IsDependentOn("Deploy-EXM-Campaigns")
.IsDependentOn("Rebuild-Core-Index")
.IsDependentOn("Rebuild-Master-Index")
.IsDependentOn("Rebuild-Web-Index");
/*===============================================
================= SUB TASKS =====================
===============================================*/
Task("Clean").Does(() => {
CleanDirectories($"{configuration.SourceFolder}/**/obj");
CleanDirectories($"{configuration.SourceFolder}/**/bin");
});
Task("Copy-Sitecore-Lib").Does(() => {
cakeConsole.WriteLine("Copying Sitecore Libraries");
var commerceLibraries = GetFiles($"{configuration.SitecoreLibrariesPath}\\**\\Sitecore.*").Select(x => x.FullPath).ToList();
CreateFolderIfNotExist(configuration.SitecoreLib);
CopyFiles(commerceLibraries, configuration.SitecoreLib, preserveFolderStructure: true);
});
Task("Publish-Website-Projects")
.IsDependentOn("Build-Solution")
.IsDependentOn("Publish-Foundation-Projects")
.IsDependentOn("Publish-Feature-Projects")
.IsDependentOn("Publish-Project-Projects");
Task("Build-Solution").Does(() => {
MSBuild(configuration.SolutionFile, cfg => InitializeMSBuildSettings(cfg));
});
Task("Publish-Foundation-Projects").Does(() => {
PublishProjects(configuration.FoundationSrcFolder, configuration.WebsiteRoot);
});
Task("Publish-Feature-Projects").Does(() => {
PublishProjects(configuration.FeatureSrcFolder, configuration.WebsiteRoot);
});
Task("Publish-Project-Projects").Does(() => {
PublishProjects(configuration.ProjectSrcFolder, configuration.WebsiteRoot);
});
Task("Apply-Xml-Transform").Does(() => {
var layers = new string[] { configuration.FoundationSrcFolder, configuration.FeatureSrcFolder, configuration.ProjectSrcFolder};
foreach(var layer in layers)
{
Transform(layer);
}
});
Task("Publish-Transforms").Does(() => {
var destination = $@"{configuration.WebsiteRoot}\temp\transforms";
CreateFolderIfNotExist(destination);
try
{
var xdtFolder = $"{configuration.SourceFolder}\\**\\website";
var xdtFiles = GetTransformFiles(xdtFolder).Select(x => x.FullPath).ToList();
CopyFiles(xdtFiles, destination, preserveFolderStructure: true);
}
catch (System.Exception ex)
{
WriteError(ex.Message);
}
});
Task("Modify-Unicorn-Source-Folder").Does(() => {
var zzzDevSettingsFile = File($"{configuration.WebsiteRoot}/App_config/Include/Project/z.HabitatHome.Commerce.Website.DevSettings.config");
var rootXPath = "configuration/sitecore/sc.variable[@name='{0}']/@value";
var sourceFolderXPath = string.Format(rootXPath, "commerce.sourceFolder");
var directoryPath = MakeAbsolute(new DirectoryPath(configuration.UnicornSerializationFolder)).FullPath;
var xmlSetting = new XmlPokeSettings {
Namespaces = new Dictionary<string, string> {
{"patch", @"http://www.sitecore.net/xmlconfig/"}
}
};
XmlPoke(zzzDevSettingsFile, sourceFolderXPath, directoryPath, xmlSetting);
});
Task("Turn-On-Unicorn").Does(() => {
var webConfigFile = File($"{configuration.WebsiteRoot}/web.config");
var xmlSetting = new XmlPokeSettings {
Namespaces = new Dictionary<string, string> {
{"patch", @"http://www.sitecore.net/xmlconfig/"}
}
};
var unicornAppSettingXPath = "configuration/appSettings/add[@key='unicorn:define']/@value";
XmlPoke(webConfigFile, unicornAppSettingXPath, "On", xmlSetting);
});
Task("Sync-Unicorn")
.IsDependentOn("Turn-On-Unicorn")
.Does(() => {
var unicornUrl = configuration.InstanceUrl + "unicorn.aspx";
Information("Sync Unicorn items from url: " + unicornUrl);
var authenticationFile = new FilePath($"{configuration.WebsiteRoot}/App_config/Include/Unicorn/Unicorn.zSharedSecret.config");
var xPath = "/configuration/sitecore/unicorn/authenticationProvider/SharedSecret";
string sharedSecret = XmlPeek(authenticationFile, xPath);
var powerShellSettings = new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args => {
args.Append("secret", sharedSecret)
.Append("url", unicornUrl);
});
StartPowershellFile(unicornSyncScript, powerShellSettings);
});
Task("Deploy-EXM-Campaigns").Does(() => {
var url = $"{configuration.InstanceUrl}utilities/deployemailcampaigns.aspx?apiKey={configuration.MessageStatisticsApiKey}";
string responseBody = HttpGet(url);
Information(responseBody);
});
Task("Rebuild-Core-Index").Does(() => {
RebuildIndex("sitecore_core_index");
});
Task("Rebuild-Master-Index").Does(() => {
RebuildIndex("sitecore_master_index");
});
Task("Rebuild-Web-Index").Does(() => {
RebuildIndex("sitecore_web_index");
});
RunTarget(target);