0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-18 21:06:11 -05:00
penpot/common/app/common/version.cljc
2021-04-12 16:49:43 +02:00

51 lines
1.2 KiB
Clojure

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) UXBOX Labs SL
(ns app.common.version
"A version parsing helper."
(:require
[app.common.data :as d]
[cuerdas.core :as str]))
(def version-re #"^(([A-Za-z]+)\-?)?((\d+)\.(\d+)\.(\d+))(\-?((alpha|prealpha|beta|rc|dev)(\d+)?))?(\-?(\d+))?(\-?g(\w+))$")
(defn parse
[data]
(cond
(= data "%version%")
{:full "develop"
:branch "develop"
:base "0.0.0"
:main "0.0"
:major "0"
:minor "0"
:patch "0"
:modifier nil
:commit nil
:commit-hash nil}
(string? data)
(let [result (re-find version-re data)
major (get result 4)
minor (get result 5)
patch (get result 6)
base (get result 3)
main (str/fmt "%s.%s" major minor)
branch (get result 2)]
{:full data
:base base
:main main
:major major
:minor minor
:patch patch
:branch branch
:modifier (get result 8)
:commit (get result 12)
:commit-hash (get result 14)})
:else nil))