summaryrefslogtreecommitdiffstats
path: root/scripts/lua/mason-scripts/utils.lua
blob: ee6ab10a64c45020a2d1d9ed0aa17392b03a7a2b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local _ = require "mason-core.functional"
local fs = require "mason-core.fs"

local M = {}

---@async
---@param path string
---@param contents string
---@param flags string?
function M.write_file(path, contents, flags)
    local header = _.cond({
        {
            _.matches "%.lua$",
            _.always {
                "-- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.",
                "-- stylua: ignore start",
            },
        },
        {
            _.matches "%.md$",
            _.always {
                "<!--- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY. -->",
            },
        },
        {
            _.matches "doc/.+%.txt$",
            _.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