From d1c860da4b89fd29a45decfb490c79748d954493 Mon Sep 17 00:00:00 2001 From: William Boman Date: Sun, 7 Aug 2022 18:31:20 +0200 Subject: feat: generate PACKAGES.md (#265) --- scripts/lua/mason-scripts/utils.lua | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'scripts/lua/mason-scripts/utils.lua') 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 { "" } }, + { + _.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 -- cgit v1.2.3-70-g09d2