From 05e70bc283471d27c905383a02185934a68ab496 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 28 Jul 2022 00:03:24 +0200 Subject: docs: generate server-mapping.md (#13) --- scripts/lua/mason-scripts/utils.lua | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 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 771d419..49a20df 100644 --- a/scripts/lua/mason-scripts/utils.lua +++ b/scripts/lua/mason-scripts/utils.lua @@ -1,21 +1,36 @@ local fs = require "mason-core.fs" +local _ = require "mason-core.functional" local M = {} ---@async ---@param path string ---@param contents string ----@param flags 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 "%.lua$", + _.always { + "-- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.", + "-- stylua: ignore start", + }, + }, + { + _.matches "%.md$", + _.always { + "", + }, + }, + { + _.T, + _.always { + "# THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.", + }, + }, + }, path) + + fs.async.write_file(path, table.concat(_.concat(header, { contents }), "\n"), flags) end return M -- cgit v1.2.3-70-g09d2