|
7 | 7 | #load @"Tooling.fsx" |
8 | 8 | #load @"Projects.fsx" |
9 | 9 |
|
| 10 | +open Microsoft.FSharp.Reflection |
10 | 11 | open System |
11 | | -open System.IO |
12 | | - |
13 | | -open Fake |
14 | | -open System |
| 12 | +open System.Collections.Generic |
15 | 13 | open System.IO |
16 | 14 | open System.Linq |
17 | 15 | open System.Net |
18 | 16 | open System.Text |
19 | 17 | open System.Text.RegularExpressions |
20 | 18 | open System.Xml |
21 | 19 | open System.Xml.Linq |
| 20 | +open Fake |
22 | 21 | open Fake.Git.CommandHelper |
23 | | - |
24 | 22 | open Paths |
25 | 23 | open Projects |
26 | 24 | open Tooling |
@@ -264,42 +262,64 @@ module Differ = |
264 | 262 | | :? XmlException -> ignore() |
265 | 263 |
|
266 | 264 | let private convertToAsciidoc path first second = |
| 265 | + let createDiffDescription description (writer:TextWriter) = |
| 266 | + let m = Regex.Match(description, "(.*?) changed from (.*?) to (.*).") |
| 267 | + if m.Success then |
| 268 | + let memberType = m.Groups.[1].Value |
| 269 | + let o = m.Groups.[2].Value |
| 270 | + let n = m.Groups.[3].Value |
| 271 | + writer.WriteLine("+") |
| 272 | + writer.WriteLine(sprintf "%s change" memberType) |
| 273 | + writer.WriteLine("+") |
| 274 | + writer.WriteLine("[source,csharp]") |
| 275 | + writer.WriteLine("----") |
| 276 | + writer.WriteLine(sprintf "// before in %s" first) |
| 277 | + writer.WriteLine(sprintf "%s" o) |
| 278 | + writer.WriteLine(sprintf "// now in %s" second) |
| 279 | + writer.WriteLine(sprintf "%s" n) |
| 280 | + writer.WriteLine("----") |
| 281 | + else |
| 282 | + writer.WriteLine(sprintf "%s" description) |
| 283 | + |
267 | 284 | let name = path |> Path.GetFileNameWithoutExtension |
268 | 285 | try |
269 | 286 | let doc = XDocument.Load path |
270 | 287 | let output = Path.ChangeExtension(path, "asciidoc") |
271 | 288 | DeleteFile output |
| 289 | + |
272 | 290 | use file = File.OpenWrite <| output |
273 | 291 | use writer = new StreamWriter(file) |
274 | | - writer.WriteLine(name |> replace "." "-" |> sprintf "[[%s-breaking-changes]]") |
| 292 | + writer.WriteLine(name |> replace "." "-" |> toLower |> sprintf "[[%s-breaking-changes]]") |
275 | 293 | writer.WriteLine(sprintf "== Breaking changes for %s between %s and %s" name first second) |
276 | 294 | writer.WriteLine() |
277 | 295 |
|
278 | 296 | for element in (doc |> descendents "Type") do |
279 | 297 | let typeName = element |> attributeValue "Name" |> replace (sprintf "%s." name) "" |
280 | 298 | let diffType = element |> attributeValue "DiffType" |> convertDiffType |
| 299 | + |
281 | 300 | match diffType with |
282 | | - | Deleted -> writer.WriteLine(sprintf "[float]%s=== `%s` is deleted" Environment.NewLine typeName) |
283 | | - | New -> writer.WriteLine(sprintf "[float]%s=== `%s` is added" Environment.NewLine typeName) |
| 301 | + | Deleted -> writer.WriteLine(sprintf "`%s`:: deleted" typeName) |
| 302 | + | New -> writer.WriteLine(sprintf "`%s`:: added" typeName) |
284 | 303 | | Modified -> |
285 | 304 | let members = Seq.append (element |> elements "Method") (element |> elements "Property") |
286 | 305 | if Seq.isEmpty members |> not then |
287 | | - writer.WriteLine(sprintf "[float]%s=== `%s`" Environment.NewLine typeName) |
| 306 | + writer.WriteLine(sprintf "`%s`::" typeName) |
288 | 307 | for m in members do |
289 | 308 | let memberName = m |> attributeValue "Name" |
290 | 309 | if isNotNullOrEmpty memberName then |
291 | 310 | let diffType = m |> attributeValue "DiffType" |
292 | 311 | if isNotNullOrEmpty diffType then |
293 | 312 | match convertDiffType diffType with |
294 | | - | Deleted -> writer.WriteLine(sprintf "[float]%s==== `%s` is deleted" Environment.NewLine memberName) |
295 | | - | New -> writer.WriteLine(sprintf "[float]%s==== `%s` is added" Environment.NewLine memberName) |
| 313 | + | Deleted -> writer.WriteLine(sprintf " * `%s` deleted" memberName) |
| 314 | + | New -> writer.WriteLine(sprintf " * `%s` added" memberName) |
296 | 315 | | Modified -> |
297 | 316 | match (m.Descendants(XName.op_Implicit "DiffItem") |> Seq.tryHead) with |
298 | 317 | | Some diffItem -> |
299 | | - writer.WriteLine(sprintf "[float]%s==== `%s`" Environment.NewLine memberName) |
| 318 | + writer.WriteLine(sprintf " * `%s`" memberName) |
300 | 319 | let diffDescription = diffItem.Value |
301 | | - writer.WriteLine(Regex.Replace(diffDescription, "changed from (.*?) to (.*).", "changed from `$1` to `$2`.")) |
| 320 | + writer |> createDiffDescription diffDescription |
302 | 321 | | None -> () |
| 322 | + writer.WriteLine() |
303 | 323 | with |
304 | 324 | | :? XmlException -> ignore() |
305 | 325 |
|
|
0 commit comments