2
0

system.kt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2019-2021 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  8. */
  9. package net.mamoe.mirai.dokka
  10. import kotlinx.serialization.json.Json
  11. import java.io.File
  12. val pages = File("mirai-dokka/pages")
  13. val json = Json {
  14. prettyPrint = true
  15. prettyPrintIndent = " "
  16. }
  17. private val FileDevNull = File(
  18. if (System.getProperty("os.name")
  19. .startsWith("Windows")
  20. ) "NUL" else "/dev/null"
  21. )
  22. fun system(cmd: String) {
  23. val rsp = ProcessBuilder(cmd).inheritIO().start().waitFor()
  24. if (rsp != 0) error("Exec return $rsp, $cmd")
  25. }
  26. fun exec(vararg cmd: String) {
  27. val rsp = ProcessBuilder(*cmd).inheritIO().start().waitFor()
  28. if (rsp != 0) error("Exec return $rsp, ${cmd.joinToString(" ")}")
  29. }
  30. fun repoexec(
  31. vararg cmd: String,
  32. nooutput: Boolean = false,
  33. ) {
  34. val rsp = ProcessBuilder(*cmd)
  35. .inheritIO()
  36. .directory(pages)
  37. .also { builder ->
  38. if (nooutput) {
  39. builder.redirectOutput(ProcessBuilder.Redirect.to(FileDevNull))
  40. }
  41. }
  42. .start()
  43. .waitFor()
  44. if (rsp != 0) error("Exec return $rsp, ${cmd.joinToString(" ")}")
  45. }