summaryrefslogtreecommitdiff
path: root/script/version.lua
blob: fa17856459b26dc59cd0eaaa515b42648372d7cd (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
local fsu = require 'fs-utility'

local function loadVersion()
    local changelog = fsu.loadFile(ROOT / 'changelog.md')
    if not changelog then
        return
    end

    local version, pos = changelog:match '%#%# (%d+%.%d+%.%d+)()'
    if not version then
        return
    end

    if not changelog:find('^[\r\n]+`', pos) then
        version = version .. '-dev'
    end
    return version
end

local m = {}

function m.getVersion()
    if not m.version then
        m.version = loadVersion() or '<Unknown>'
    end

    return m.version
end

return m