-
Notifications
You must be signed in to change notification settings - Fork 21
/
BuildApiReference.proj
238 lines (185 loc) · 9.61 KB
/
BuildApiReference.proj
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="BuildApiReference" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="MSBuild.Community.Tasks.FileUpdate" AssemblyFile="Tools\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll" />
<PropertyGroup>
<CodeFactoryLocation>$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll</CodeFactoryLocation>
<CodeFactoryLocation Condition="Exists('$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll')">$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll</CodeFactoryLocation>
</PropertyGroup>
<UsingTask TaskName="ReplaceAndLowerUrls" TaskFactory="CodeTaskFactory" AssemblyFile="$(CodeFactoryLocation)" >
<ParameterGroup>
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Text.RegularExpressions"/>
<Using Namespace="System.IO"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
for (int i = 0; i < this.Files.Length; i++)
{
ITaskItem item = this.Files[i];
string path = item.GetMetadata("FullPath");
string text = File.ReadAllText(path);
text = Regex.Replace(
text,
"href=\"(?!http(s)?:)([^\"]+)\\.+html([?#][^\"]*)?\"",
m => "href=\"" + m.Groups[2].Value.ToLower() + m.Groups[3].Value + "\"",
RegexOptions.Singleline | RegexOptions.IgnoreCase);
File.WriteAllText(path, text);
this.Log.LogMessage(MessageImportance.Normal, string.Format("Updated urls in file '{0}'", path));
}
]]>
</Code>
</Task>
</UsingTask>
<UsingTask TaskName="ReplaceAndLowerSitemapUrls" TaskFactory="CodeTaskFactory" AssemblyFile="$(CodeFactoryLocation)" >
<ParameterGroup>
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Text.RegularExpressions"/>
<Using Namespace="System.IO"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
for (int i = 0; i < this.Files.Length; i++)
{
ITaskItem item = this.Files[i];
string path = item.GetMetadata("FullPath");
string text = File.ReadAllText(path);
text = Regex.Replace(
text,
"<loc>([^<]+)\\.+html</loc>",
m => "<loc>" + m.Groups[1].Value.ToLower() + "</loc>",
RegexOptions.Singleline | RegexOptions.IgnoreCase);
File.WriteAllText(path, text);
this.Log.LogMessage(MessageImportance.Normal, string.Format("Updated sitemap urls in file '{0}'", path));
}
]]>
</Code>
</Task>
</UsingTask>
<PropertyGroup>
<BuildApiReferenceDependsOn>
CheckRequiredProperties;
PrepareProperties;
InitializeBinariesFiles;
CopyLatestBinaries;
CopyAssetsAPIFiles;
CreateDocfxJson;
RestoreNugetAPISolution;
BuildAPISolution;
ProcessSitemap;
ProcessHtmlFiles;
DeleteDocFxFavicon;
CopyAPIHtmlFilesToSiteFolder
</BuildApiReferenceDependsOn>
</PropertyGroup>
<Target Name="BuildApiReference" DependsOnTargets="$(BuildApiReferenceDependsOn)"/>
<Target Name="CheckRequiredProperties">
<Error Condition=" '$(LatestBinariesPath)' == '' " Text="LatestBinariesPath is not defined (Ex. \\telerik.com\distributions\OfficialReleases\XAML\2018_R3\2018_R3_Official)"/>
<Error Condition=" '$(DocsRepoName)' == '' " Text="DocsRepoName is not defined (Ex. winforms-docs)"/>
<Error Condition=" '$(DocumentationBaseUrl)' == '' " Text="DocumentationBaseUrl is not defined (Ex. https://docs.telerik.com/devtools/document-processing)"/>
<Error Condition=" '$(DocsRepoApiAssetsFolder)' == '' " Text="DocsRepoApiAssetsFolder is not defined (Ex. _assetsApi)"/>
<Message Text="DEBUG INFO: LatestBinariesPath -> $(LatestBinariesPath)" />
<Message Text="DEBUG INFO: DocsRepoName -> $(DocsRepoName)" />
<Message Text="DEBUG INFO: DocumentationBaseUrl -> $(DocumentationBaseUrl)" />
<Message Text="DEBUG INFO: DocsRepoApiAssetsFolder -> $(DocsRepoApiAssetsFolder)" />
</Target>
<Target Name="PrepareProperties">
<PropertyGroup>
<!--Tools-->
<ToolsFolder>$(MsBuildProjectDirectory)\Tools</ToolsFolder>
<NugetTool>$(ToolsFolder)\Nuget.exe</NugetTool>
<!--Folder properties-->
<BuildApiRootFolder>$(MsBuildProjectDirectory)\BuildAPI</BuildApiRootFolder>
<BuildApiSrcFolder>$(BuildApiRootFolder)\src</BuildApiSrcFolder>
<SourceFolder>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\..'))</SourceFolder>
<DocsSeedRoot>$([System.IO.Path]::GetFullPath('$(BuildApiRootFolder)'))\..\..\</DocsSeedRoot>
<FavIconPath>$(DocsSeedRoot)\favicon.ico</FavIconPath>
<DocsRepoName Condition="'$(DocsRepoName)' == '' ">Xamarin-Forms-docs</DocsRepoName>
<DocsFolder>$(SourceFolder)\$(DocsRepoName)</DocsFolder>
<DocsRepoApiAssetsFolder Condition="'$(DocsRepoApiAssetsFolder)' == '' ">_assets</DocsRepoApiAssetsFolder>
<DocsAssets>$(DocsFolder)\$(DocsRepoApiAssetsFolder)</DocsAssets>
<LatestBinariesFile>$(DocsAssets)\Binaries.txt</LatestBinariesFile>
<TopNavigationHtmlSource>$(DocsFolder)\_includes\top-nav.html</TopNavigationHtmlSource>
<TopNavigationHtmlDestination>$(BuildApiRootFolder)\docfx-tmpl\src\partials\navbar.tmpl.partial</TopNavigationHtmlDestination>
<!--Docfx properties-->
<DocfxJsonGeneratorPath>$(ToolsFolder)\GenerateDocFxJsonTool\DocFxJsonModifier.exe</DocfxJsonGeneratorPath>
<DocfxFile>$(MsBuildProjectDirectory)\docfx.json</DocfxFile>
<FilterApi Condition=" '$(HasApiFilter)' == 'true' ">true</FilterApi>
<SiteOutputFolder Condition=" '$(SiteOutputFolder)' == '' ">_site</SiteOutputFolder>
<!--Build Api solution-->
<BuildApiSolutionName>$(MsBuildProjectDirectory)\BuildAPI.sln</BuildApiSolutionName>
<!--Output properties-->
<OutputFolder>$(BuildApiRootFolder)\_site</OutputFolder>
<SitemapFile>$(OutputFolder)\sitemap.xml</SitemapFile>
<ApiOutputFolder>$(OutputFolder)\api</ApiOutputFolder>
<ApiStylesOutputFolder>$(OutputFolder)\styles</ApiStylesOutputFolder>
<DocsRepoOutputFolder>$(DocsFolder)\$(SiteOutputFolder)</DocsRepoOutputFolder>
<!--Build Configurations-->
<BuildConfiguration>Release</BuildConfiguration>
<BuildPlatform>Any CPU</BuildPlatform>
</PropertyGroup>
</Target>
<Target Name="InitializeBinariesFiles">
<ReadLinesFromFile Condition="Exists('$(LatestBinariesFile)')"
File="$(LatestBinariesFile)" >
<Output
TaskParameter="Lines"
ItemName="BinariesNames"/>
</ReadLinesFromFile>
<ItemGroup Condition="Exists('$(LatestBinariesFile)')">
<Binaries Include="$(LatestBinariesPath)\**\%(BinariesNames.Identity)"/>
</ItemGroup>
<ItemGroup Condition="!Exists('$(LatestBinariesFile)')">
<Binaries Include="$(LatestBinariesPath)\*.dll;
$(LatestBinariesPath)\*.xml"/>
</ItemGroup>
</Target>
<Target Name="CopyLatestBinaries">
<Copy SourceFiles="%(Binaries.FullPath)" DestinationFiles="@(Binaries->'$(BuildApiSrcFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<Target Name="CopyAssetsAPIFiles">
<Copy SourceFiles="$(TopNavigationHtmlSource)" DestinationFiles="$(TopNavigationHtmlDestination)" />
<ItemGroup>
<DocsAssets Include="$(DocsAssets)\**\*.*"/>
</ItemGroup>
<Message Text="DEBUG INFO: DocsAssets=$(DocsAssets)" />
<Copy SourceFiles="@(DocsAssets)" DestinationFolder="$(BuildApiRootFolder)\%(RecursiveDir)" />
</Target>
<Target Name="CreateDocfxJson">
<Message Text="DEBUG INFO: FilterApi=$(FilterApi)" />
<Exec Command='$(DocfxJsonGeneratorPath) $(DocumentationBaseUrl) $(FilterApi)'></Exec>
<Copy SourceFiles='$(DocfxFile)' DestinationFolder='$(BuildApiRootFolder)' />
</Target>
<Target Name="RestoreNugetAPISolution">
<Exec Command="$(NugetTool) restore $(BuildApiSolutionName)" />
</Target>
<Target Name="BuildAPISolution">
<MSBuild Projects="$(BuildApiSolutionName)" Properties="Configuration=$(BuildConfiguration);Platform=$(BuildPlatform)" Targets="Rebuild" />
</Target>
<Target Name="ProcessSitemap">
<Message Text="DEBUG INFO: SitemapFile=$(SitemapFile)" />
<FileUpdate Files="$(SitemapFile)" Regex="(<lastmod>)(\d{4}-\d{2}-\d{2})(.*?)(<\/lastmod>)" ReplacementText="$1$2$4" />
<ReplaceAndLowerSitemapUrls Files="$(SitemapFile)" />
<Copy SourceFiles='$(SitemapFile)' DestinationFolder='$(ApiOutputFolder)' />
</Target>
<Target Name="ProcessHtmlFiles">
<ItemGroup>
<HtmlApiFiles Include="$(ApiOutputFolder)\*.html" />
</ItemGroup>
<ReplaceAndLowerUrls Files="@(HtmlApiFiles)" />
</Target>
<Target Name="CopyAPIHtmlFilesToSiteFolder">
<ItemGroup>
<ApiFiles Include="$(ApiOutputFolder)\*.*" />
<ApiStyleFiles Include="$(ApiStylesOutputFolder)\*.*" />
</ItemGroup>
<Copy SourceFiles='@(ApiFiles)' DestinationFolder='$(DocsRepoOutputFolder)\api' />
<Copy SourceFiles='@(ApiStyleFiles)' DestinationFolder='$(DocsRepoOutputFolder)\styles' />
</Target>
<Target Name="DeleteDocFxFavicon">
<Delete Files="$(BuildApiRootFolder)\_site\favicon.ico" />
<Copy SourceFiles="$(FavIconPath)" DestinationFolder="$(BuildApiRootFolder)\_site\" />
<Copy SourceFiles="$(FavIconPath)" DestinationFolder="$(DocsRepoOutputFolder)" />
</Target>
</Project>