You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.6 KiB

  1. # read SelfConfig, remove wierd bits, load it, load Newtonsoft, and turn it into a schema
  2. $newtonsoftLoc = "$(Get-Location)/nuget/Newtonsoft.Json.12.0.2/lib/netstandard2.0/Newtonsoft.Json.dll"
  3. $newtonsoftSchemaLoc = "$(Get-Location)/nuget/Newtonsoft.Json.Schema.3.0.11/lib/netstandard2.0/Newtonsoft.Json.Schema.dll"
  4. $selfConfigLoc = "../IPA.Loader/Config/SelfConfig.cs"
  5. if (!(Test-Path "nuget" -PathType Container)) {
  6. nuget install Newtonsoft.Json -Version 12.0.2 -source https://api.nuget.org/v3/index.json -o "$(Get-Location)/nuget"
  7. nuget install Newtonsoft.Json.Schema -Version 3.0.11 -source https://api.nuget.org/v3/index.json -o "$(Get-Location)/nuget"
  8. }
  9. & docfx metadata
  10. if ((Test-Path $newtonsoftLoc -PathType Leaf) -and (Test-Path $selfConfigLoc -PathType Leaf)) {
  11. # The files we need exist, lets do this!
  12. # First load Newtonsoft
  13. Add-Type -Path $newtonsoftLoc
  14. Add-Type -Path $newtonsoftSchemaLoc
  15. # Read and parse special directives from SelfConfig
  16. function ProcessLines {
  17. begin {
  18. $inIgnoreSection = $false
  19. $ignoreNext = 0
  20. }
  21. process {
  22. if ( $_ -match "^\s*//\s+([A-Z]+):\s*(?:section)?\s+(.+)\s*$" ) {
  23. $Begin = ($Matches[1] -eq "BEGIN")
  24. $End = ($Matches[1] -eq "END")
  25. $Line = ($Matches[1] -eq "LINE")
  26. switch ($Matches[2]) {
  27. "ignore" {
  28. if ($Begin) { $inIgnoreSection = $true }
  29. if ($End) { $inIgnoreSection = $false }
  30. if ($Line) { $ignoreNext = 2 }
  31. }
  32. }
  33. }
  34. if ($inIgnoreSection) { "" }
  35. elseif ($ignoreNext -gt 0) { $ignoreNext = $ignoreNext - 1; "" }
  36. else { $_ }
  37. }
  38. }
  39. function Merge-Lines {
  40. begin { $str = "" }
  41. process { $str = $str + "`n" + $_ }
  42. end { $str }
  43. }
  44. function FilterDef {
  45. process { $_ -replace "internal", "public" }
  46. }
  47. Add-Type -TypeDefinition (Get-Content $selfConfigLoc | ProcessLines | Merge-Lines | FilterDef) -ReferencedAssemblies $newtonsoftLoc,"netstandard"
  48. # type will be [IPA.Config.SelfConfig]
  49. # Generate schema
  50. $schemagen = New-Object -TypeName Newtonsoft.Json.Schema.Generation.JSchemaGenerator
  51. $schemagen.DefaultRequired = [Newtonsoft.Json.Required]::Always
  52. $schema = $schemagen.Generate([IPA.Config.SelfConfig])
  53. $schema.ToString() | Out-File "other_api/config/_schema.json"
  54. }
  55. & docfx build --globalMetadataFiles link_branch.json @Args
  56. if ($lastexitcode -ne 0) {
  57. throw [System.Exception] "docfx build failed with exit code $lastexitcode."
  58. }