setup.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env luajit
  2. local name = "hello_world"
  3. local title = "Hello World"
  4. local description = "Example mod."
  5. local min_minetest_version = 5.6
  6. local depends = "default"
  7. local optional_depends = ""
  8. local author = "luarocks"
  9. local readme = ([[# %s
  10. %s
  11. ---
  12. This mod was created in [Rustroot Forge].
  13. All my mods uses [Luanti LSP-API] annotations, [StyLua] and [Luacheck].
  14. [Rustroot Forge]: https://notabug.org/rr
  15. [Luanti LSP-API]: https://notabug.org/rr/luanti_lsp_api
  16. [StyLua]: https://github.com/JohnnyMorganz/StyLua
  17. [Luacheck]: https://github.com/mpeterv/luacheck
  18. ]]):format(title, description)
  19. local mod_conf = ([[name = %s
  20. title = %s
  21. description = %s
  22. min_minetest_version = %s
  23. # Optional
  24. depends = %s
  25. optional_depends = %s
  26. author = %s]]):format(
  27. name,
  28. title,
  29. description,
  30. min_minetest_version,
  31. depends,
  32. optional_depends,
  33. author
  34. )
  35. local template = ([[# textdomain: %s
  36. %s=
  37. %s=
  38. ]]):format(name, title, description)
  39. local file = io.open("README.md", "w")
  40. if not file then error "failed to open mod.conf for writing" end
  41. file:write(readme)
  42. file:close()
  43. file = io.open("mod.conf", "w")
  44. if not file then error "failed to open mod.conf for writing" end
  45. file:write(mod_conf)
  46. file:close()
  47. if not os.execute "mkdir locale" then error "failed to create directory" end
  48. file = io.open("locale/template.txt", "w")
  49. if not file then error "failed to create file locale/template.txt" end
  50. file:write(template)
  51. file:close()
  52. local path = ("locale/%s.ru.tr"):format(name)
  53. file = io.open(path, "w")
  54. if not file then error(("failed to create file " .. path)) end
  55. file:write(template)
  56. file:close()
  57. local function remove_dir(dir_path)
  58. local os_name = package.config:sub(1, 1)
  59. if os_name == "/" then
  60. os.execute('rm -rf "' .. dir_path .. '"')
  61. else
  62. os.execute('rmdir /S /Q "' .. dir_path .. '"')
  63. end
  64. end
  65. remove_dir ".git"
  66. os.remove "setup.lua"
  67. os.execute "git init"
  68. os.execute "git add ."
  69. os.execute 'git commit -m "Init"'