officialpackages.nim 810 B

12345678910111213141516171819202122
  1. import std/[strformat, paths, dirs, envvars]
  2. from std/os import execShellCmd
  3. proc exec*(cmd: string, errorcode: int = QuitFailure, additionalPath = "") =
  4. let prevPath = getEnv("PATH")
  5. if additionalPath.len > 0:
  6. var absolute = Path(additionalPath)
  7. if not absolute.isAbsolute:
  8. absolute = getCurrentDir() / absolute
  9. echo("Adding to $PATH: ", string(absolute))
  10. putEnv("PATH", (if prevPath.len > 0: prevPath & PathSep else: "") & string(absolute))
  11. echo(cmd)
  12. if execShellCmd(cmd) != 0: quit("FAILURE", errorcode)
  13. putEnv("PATH", prevPath)
  14. proc gitClonePackages*(names: seq[string]) =
  15. if not dirExists(Path"pkgs"):
  16. createDir(Path"pkgs")
  17. for name in names:
  18. if not dirExists(Path"pkgs" / Path(name)):
  19. exec fmt"git clone https://github.com/nim-lang/{name} pkgs/{name}"