Skip to content

Commit 8680b0d

Browse files
committed
Update versions sorting
1 parent 8af0103 commit 8680b0d

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

src-cljc/playground/utils/utils.cljc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns playground.utils.utils
22
(:require [clojure.string :as string]
3-
[version-clj.core :as version-clj]
3+
[version-clj.core :as version-clj :refer [version-compare]]
44
#?(:cljs
55
[cljs-time.coerce :as c]
66
:clj
@@ -33,9 +33,16 @@
3333
(filter released-or-8-version? versions))
3434

3535

36-
(defn sort-versions [versions]
37-
(sort (comp - #(version-clj/version-compare %1 %2))
38-
versions))
36+
(defn sort-versions
37+
([key versions]
38+
(let [replace-fn (fn [version]
39+
;; v8 -> 8.999.999
40+
(string/replace version #"^v(\d+)" "$1.999.999"))
41+
compare-fn (fn [v1 v2]
42+
(version-compare (replace-fn v2) (replace-fn v1)))]
43+
(sort-by key compare-fn versions)))
44+
([versions]
45+
(sort-versions identity versions)))
3946

4047

4148
(defn replace-urls [version-name scripts]

src/playground/data/config.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns playground.data.config
22
(:require [cheshire.core :as json]
33
[clj-http.client :as http]
4-
[version-clj.core :as version-clj]))
4+
[playground.utils.utils :as utils]))
55

66

77
;; Declarations
@@ -43,5 +43,6 @@
4343

4444

4545
(defn add-anychart-versions [versions]
46-
(sort (comp - #(version-clj/version-compare %1 %2))
47-
(distinct (concat versions @*anychart-versions))))
46+
(-> (concat versions @*anychart-versions)
47+
distinct
48+
utils/sort-versions))

src/playground/db/request.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
[camel-snake-kebab.core :as kebab]
77
[camel-snake-kebab.extras :as kebab-extra]
88
[playground.utils.utils :as utils]
9-
[version-clj.core :as version-clj]
109
[clojure.java.jdbc :as jdbc]
1110
[mpg.core :as mpg]))
1211

@@ -139,21 +138,23 @@
139138
(def versions (sql {:name sql-versions
140139
:row-fn underscore->dash
141140
:result-set-fn (fn [versions]
142-
(sort (comp - #(version-clj/version-compare (:name %1) (:name %2))) versions))}))
141+
(utils/sort-versions :name versions))}))
143142

144143

145144
(def versions-by-repo-name (sql {:name sql-versions-by-repo-name
146145
:row-fn underscore->dash
147146
:result-set-fn (fn [versions]
148-
(sort (comp - #(version-clj/version-compare %1 %2))
149-
(map :name versions)))}))
147+
(->> versions
148+
(map :name)
149+
utils/sort-versions))}))
150150

151151

152152
(def versions-by-repos-names (sql {:name sql-versions-by-repos-names
153153
:row-fn underscore->dash
154154
:result-set-fn (fn [versions]
155-
(sort (comp - #(version-clj/version-compare %1 %2))
156-
(map :name versions)))}))
155+
(->> versions
156+
(map :name)
157+
utils/sort-versions))}))
157158

158159

159160
(def versions-repos (sql {:name sql-versions-repos
@@ -172,8 +173,7 @@
172173

173174
(defn last-version [db data]
174175
(let [versions (versions db data)
175-
last-version (first (sort (comp - #(version-clj/version-compare (:name %1) (:name %2)))
176-
versions))]
176+
last-version (first (utils/sort-versions :name versions))]
177177
last-version))
178178

179179
;; =====================================================================================================================

src/playground/web/middleware.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(ns playground.web.middleware
22
(:require [playground.db.request :as db-req]
33
[playground.web.helpers :refer :all]
4-
[version-clj.core :as version-clj :refer [version-compare]]
54
[playground.web.auth :as auth]
65
[playground.data.tags :as data-tags]
76
[playground.web.utils :as web-utils]))

0 commit comments

Comments
 (0)