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.

81 lines
3.0 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. $ipaRoot = "../IPA"
  6. if (!(Test-Path "nuget" -PathType Container)) {
  7. nuget install Newtonsoft.Json -Version 12.0.2 -source https://api.nuget.org/v3/index.json -o "$(Get-Location)/nuget"
  8. nuget install Newtonsoft.Json.Schema -Version 3.0.11 -source https://api.nuget.org/v3/index.json -o "$(Get-Location)/nuget"
  9. }
  10. & docfx metadata
  11. if ((Test-Path $newtonsoftLoc -PathType Leaf) -and (Test-Path $selfConfigLoc -PathType Leaf)) {
  12. # The files we need exist, lets do this!
  13. # First load Newtonsoft
  14. Add-Type -Path $newtonsoftLoc
  15. Add-Type -Path $newtonsoftSchemaLoc
  16. # Read and parse special directives from SelfConfig
  17. function ProcessLines {
  18. begin {
  19. $inIgnoreSection = $false
  20. $ignoreNext = 0
  21. }
  22. process {
  23. if ( $_ -match "^\s*//\s+([A-Z]+):\s*(?:section)?\s+([a-zA-Z]+)(?:\s+(\d+))?\s*$" ) {
  24. $Begin = ($Matches[1] -eq "BEGIN")
  25. $End = ($Matches[1] -eq "END")
  26. $Line = ($Matches[1] -eq "LINE")
  27. $Num = if ($Matches[3].length -gt 0) { [int]($Matches[3]) } else { 1 }
  28. switch ($Matches[2]) {
  29. "ignore" {
  30. if ($Begin) { $inIgnoreSection = $true }
  31. if ($End) { $inIgnoreSection = $false }
  32. if ($Line) { $ignoreNext = $Num + 1 }
  33. }
  34. }
  35. }
  36. if ($inIgnoreSection) { "" }
  37. elseif ($ignoreNext -gt 0) { $ignoreNext = $ignoreNext - 1; return "" }
  38. else { $_ }
  39. }
  40. }
  41. function Merge-Lines {
  42. begin { $str = "" }
  43. process { $str = $str + "`n" + $_ }
  44. end { $str }
  45. }
  46. function FilterDef {
  47. process { $_ -replace "internal", "public" }
  48. }
  49. Add-Type -TypeDefinition (Get-Content $selfConfigLoc | ProcessLines | Merge-Lines | FilterDef) -ReferencedAssemblies $newtonsoftLoc,"netstandard"
  50. # type will be [IPA.Config.SelfConfig]
  51. # Generate schema
  52. $schemagen = New-Object -TypeName Newtonsoft.Json.Schema.Generation.JSchemaGenerator
  53. $schemagen.DefaultRequired = [Newtonsoft.Json.Required]::Always
  54. $schema = $schemagen.Generate([IPA.Config.SelfConfig])
  55. $schema.ToString() | Out-File "other_api/config/_schema.json"
  56. }
  57. $ipaExe = "$ipaRoot/bin/Release/IPA.exe"
  58. # generate IPA.exe args file
  59. if (-not (Test-Path $ipaExe -PathType Leaf)) {
  60. msbuild -p:Configuration=Release -p:Platform=AnyCPU "$ipaRoot/IPA.csproj"
  61. }
  62. & $ipaExe --help > .\articles\_ipa_command_line.txt
  63. & docfx build --globalMetadataFiles link_branch.json @Args
  64. if ($lastexitcode -ne 0) {
  65. throw [System.Exception] "docfx build failed with exit code $lastexitcode."
  66. }