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.

72 lines
2.8 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+([a-zA-Z]+)(?:\s+(\d+))?\s*$" ) {
  23. $Begin = ($Matches[1] -eq "BEGIN")
  24. $End = ($Matches[1] -eq "END")
  25. $Line = ($Matches[1] -eq "LINE")
  26. $Num = if ($Matches[3].length -gt 0) { [int]($Matches[3]) } else { 1 }
  27. switch ($Matches[2]) {
  28. "ignore" {
  29. if ($Begin) { $inIgnoreSection = $true }
  30. if ($End) { $inIgnoreSection = $false }
  31. if ($Line) { $ignoreNext = $Num + 1 }
  32. }
  33. }
  34. }
  35. if ($inIgnoreSection) { "" }
  36. elseif ($ignoreNext -gt 0) { $ignoreNext = $ignoreNext - 1; return "" }
  37. else { $_ }
  38. }
  39. }
  40. function Merge-Lines {
  41. begin { $str = "" }
  42. process { $str = $str + "`n" + $_ }
  43. end { $str }
  44. }
  45. function FilterDef {
  46. process { $_ -replace "internal", "public" }
  47. }
  48. Add-Type -TypeDefinition (Get-Content $selfConfigLoc | ProcessLines | Merge-Lines | FilterDef) -ReferencedAssemblies $newtonsoftLoc,"netstandard"
  49. # type will be [IPA.Config.SelfConfig]
  50. # Generate schema
  51. $schemagen = New-Object -TypeName Newtonsoft.Json.Schema.Generation.JSchemaGenerator
  52. $schemagen.DefaultRequired = [Newtonsoft.Json.Required]::Always
  53. $schema = $schemagen.Generate([IPA.Config.SelfConfig])
  54. $schema.ToString() | Out-File "other_api/config/_schema.json"
  55. }
  56. & docfx build --globalMetadataFiles link_branch.json @Args
  57. if ($lastexitcode -ne 0) {
  58. throw [System.Exception] "docfx build failed with exit code $lastexitcode."
  59. }