aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha/composer.lua
blob: 47929794d47584e240c350b4ce78d42c6a5fe6a3 (plain)
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
local M = {}

local function get_composer_file()
    if vim.fn.findfile("composer.json") ~= "" then
        return vim.fn.json_decode(vim.fn.readfile(vim.fn.getcwd() .. "/composer.json"))
    end

    if vim.fn.findfile("master/composer.json") ~= "" then
        return vim.fn.json_decode(vim.fn.readfile(vim.fn.getcwd() .. "/master/composer.json"))
    end

    return nil
end

M.query = function (path)
    local target = get_composer_file()

    if target == nil then
        return nil
    end

    for _, part in ipairs(path) do
        target = target[part]
        if target == nil then
            return nil
        end
    end

    return target
end

return M