aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lua/mason-scripts/utils.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lua/mason-scripts/utils.lua')
-rw-r--r--scripts/lua/mason-scripts/utils.lua30
1 files changed, 21 insertions, 9 deletions
diff --git a/scripts/lua/mason-scripts/utils.lua b/scripts/lua/mason-scripts/utils.lua
index 771d419a..e29a9364 100644
--- a/scripts/lua/mason-scripts/utils.lua
+++ b/scripts/lua/mason-scripts/utils.lua
@@ -1,3 +1,5 @@
+local _ = require "mason-core.functional"
+local Path = require "mason-core.path"
local fs = require "mason-core.fs"
local M = {}
@@ -7,15 +9,25 @@ local M = {}
---@param contents string
---@param flags string
function M.write_file(path, contents, flags)
- fs.async.write_file(
- path,
- table.concat({
- "-- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.",
- "-- stylua: ignore start",
- contents,
- }, "\n"),
- flags
- )
+ local header = _.cond {
+ { _.matches "%.md$", _.always { "<!--- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY. -->" } },
+ {
+ _.matches "%.lua$",
+ _.always {
+ "-- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.",
+ "-- stylua: ignore start",
+ },
+ },
+ { _.T, _.always { "// THIS FILE IS GENERATED. DO NOT EDIT MANUALLY." } },
+ }(path)
+ fs.async.write_file(path, _.join("\n", _.concat(header, { contents })), flags)
+end
+
+---@param path string
+---@return string
+function M.rel_path(path)
+ local script_path = debug.getinfo(2, "S").source:sub(2):match "(.*/)"
+ return Path.concat { script_path, path }
end
return M