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.

65 lines
2.3 KiB

  1. # read SelfConfig, remove wierd bits, load it, load Newtonsoft, and turn it into a schema
  2. $newtonsoftLoc = "$(pwd)/nuget/Newtonsoft.Json.12.0.2/lib/netstandard2.0/Newtonsoft.Json.dll"
  3. $newtonsoftSchemaLoc = "$(pwd)/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 "$(pwd)/nuget"
  7. nuget install Newtonsoft.Json.Schema -Version 3.0.11 -source https://api.nuget.org/v3/index.json -o "$(pwd)/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 Process-Lines {
  17. begin {
  18. $inIgnoreSection = $false
  19. }
  20. process {
  21. if ( $_ -match "^\s*//\s+([A-Z]+):\s+section\s+(.+)\s*$" ) {
  22. $Begin = ($Matches[1] -eq "BEGIN")
  23. $End = ($Matches[1] -eq "END")
  24. switch ($Matches[2]) {
  25. "ignore" {
  26. if ($Begin) { $inIgnoreSection = $true }
  27. if ($End) { $inIgnoreSection = $false }
  28. }
  29. }
  30. }
  31. if ($inIgnoreSection) { "" }
  32. else { $_ }
  33. }
  34. }
  35. function Merge-Lines {
  36. begin { $str = "" }
  37. process { $str = $str + "`n" + $_ }
  38. end { $str }
  39. }
  40. function Filter-Def {
  41. process { $_ -replace "internal", "public" }
  42. }
  43. Add-Type -TypeDefinition (Get-Content $selfConfigLoc | Process-Lines | Merge-Lines | Filter-Def) -ReferencedAssemblies $newtonsoftLoc,"netstandard"
  44. # type will be [IPA.Config.SelfConfig]
  45. # Generate schema
  46. $schemagen = New-Object -TypeName Newtonsoft.Json.Schema.Generation.JSchemaGenerator
  47. $schema = $schemagen.Generate([IPA.Config.SelfConfig])
  48. $schema.ToString() | Out-File "other_api/config/_schema.json"
  49. }
  50. & docfx build --globalMetadataFiles link_branch.json @Args
  51. if ($lastexitcode -ne 0) {
  52. throw [System.Exception] "docfx build failed with exit code $lastexitcode."
  53. }