No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

index.js 1.9 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const fs = require("fs")
  2. const path = require("path")
  3. const translator = require("./translator")
  4. const oauthBlockBuilder = require("./oauth")
  5. const indent = require("./helpers").indent
  6. const START_MARKER = "// Begin Swagger UI call region"
  7. const END_MARKER = "// End Swagger UI call region"
  8. const targetPath = path.normalize(process.cwd() + "/" + process.argv[2])
  9. const originalHtmlContent = fs.readFileSync(targetPath, "utf8")
  10. const startMarkerIndex = originalHtmlContent.indexOf(START_MARKER)
  11. const endMarkerIndex = originalHtmlContent.indexOf(END_MARKER)
  12. const beforeStartMarkerContent = originalHtmlContent.slice(0, startMarkerIndex)
  13. const afterEndMarkerContent = originalHtmlContent.slice(
  14. endMarkerIndex + END_MARKER.length
  15. )
  16. if (startMarkerIndex < 0 || endMarkerIndex < 0) {
  17. console.error("ERROR: Swagger UI was unable to inject Docker configuration data!")
  18. console.error("! This can happen when you provide custom HTML to Swagger UI.")
  19. console.error("! ")
  20. console.error("! In order to solve this, add the `Begin Swagger UI call region`")
  21. console.error("! and `End Swagger UI call region` markers to your HTML.")
  22. console.error("! See the repository for an example:")
  23. console.error("! https://github.com/swagger-api/swagger-ui/blob/02758b8125dbf38763cfd5d4f91c7c803e9bd0ad/dist/index.html#L40-L54")
  24. console.error("! ")
  25. console.error("! If you're seeing this message and aren't using custom HTML,")
  26. console.error("! this message may be a bug. Please file an issue:")
  27. console.error("! https://github.com/swagger-api/swagger-ui/issues/new/choose")
  28. process.exit(0)
  29. }
  30. fs.writeFileSync(
  31. targetPath,
  32. `${beforeStartMarkerContent}
  33. ${START_MARKER}
  34. const ui = SwaggerUIBundle({
  35. ${indent(translator(process.env, { injectBaseConfig: true }), 8, 2)}
  36. })
  37. ${indent(oauthBlockBuilder(process.env), 6, 2)}
  38. ${END_MARKER}
  39. ${afterEndMarkerContent}`
  40. )