Skip to content

Commit

Permalink
gen
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Aug 30, 2024
1 parent 34670f2 commit 62323bd
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 45 deletions.
9 changes: 9 additions & 0 deletions dev/compojure_api_dev/expand_kondo_feature.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns compojure-api-dev.expand-kondo-feature)

(defn visit-forms-in-file [file]
{:pre [(string? file)]}
(spit (str/replace "\n" new-forms)
file))

(defn -main [& files]
(run! visit-forms-in-file files))
7 changes: 6 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@
[criterium "0.4.5"]]
:ring {:handler examples.thingie/app
:reload-paths ["src" "examples/thingie/src"]}
:source-paths ["examples/thingie/src" "examples/thingie/dev-src"]
:source-paths ["examples/thingie/src"
"examples/thingie/dev-src"
"dev"]
:main examples.server}
:expand-kondo-feature {:source-paths ["dev"]
:dependencies [[org.clojure/tools.reader "1.5.0"]
[org.clojure/tools.namespace "1.5.0"]]}
:perf {:jvm-opts ^:replace ["-server"
"-Xmx4096m"
"-Dclojure.compiler.direct-linking=true"]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns compojure.api.common
#?@(:bb []
#?@(:default []
:default [(:require [linked.core :as linked])]))

(defn plain-map?
Expand Down Expand Up @@ -52,7 +52,7 @@
x
y))

#?(:bb nil
#?(:default nil
:default
(defn fifo-memoize [f size]
"Returns a memoized version of a referentially transparent f. The
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
;; :bb reader feature assumes clj-kondo
(ns compojure.api.core
(:require [compojure.api.meta :as meta]
#?@(:bb []
#?@(:default []
:default [[compojure.api.async]
[compojure.core :as compojure]])
[compojure.api.routes #?(:bb :as-alias :default :as) routes]
[compojure.api.middleware #?(:bb :as-alias :default :as) mw]))
[compojure.api.routes #?(:default :as-alias :default :as) routes]
[compojure.api.middleware #?(:default :as-alias :default :as) mw]))

(defn ring-handler
"Creates vanilla ring-handler from any invokable thing (e.g. compojure-api route)"
Expand All @@ -17,7 +16,7 @@
(defn routes
"Create a Ring handler by combining several handlers into one."
[& handlers]
#?(:bb (throw (ex-info "Not supported in bb"))
#?(:default (throw (ex-info "Not supported in bb"))
:default (let [handlers (seq (keep identity (flatten handlers)))]
(routes/map->Route
{:childs (vec handlers)
Expand All @@ -43,7 +42,7 @@
"Routes without route-documentation. Can be used to wrap routes,
not satisfying compojure.api.routes/Routing -protocol."
[& handlers]
#?(:bb (throw (ex-info "Not supported in bb"))
#?(:default (throw (ex-info "Not supported in bb"))
:default (let [handlers (keep identity handlers)]
(routes/map->Route {:handler (meta/routing handlers)}))))

Expand All @@ -70,7 +69,7 @@
{:style/indent 1
:supercedes "middleware"}
[middleware & body]
#?(:bb (throw (ex-info "Not supported in bb"))
#?(:default (throw (ex-info "Not supported in bb"))
:default
(let [handler (apply routes body)
x-handler (compojure/wrap-routes handler (mw/compose-middleware middleware))]
Expand All @@ -79,13 +78,13 @@
{:childs [handler]
:handler x-handler}))))

(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env :kondo-rule? #?(:bb true :default false)}))
(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env :kondo-rule? #?(:default true :default false)}))

(defmacro GET {:style/indent 2} [& args] (meta/restructure :get args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro HEAD {:style/indent 2} [& args] (meta/restructure :head args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro PATCH {:style/indent 2} [& args] (meta/restructure :patch args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro DELETE {:style/indent 2} [& args] (meta/restructure :delete args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro OPTIONS {:style/indent 2} [& args] (meta/restructure :options args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro POST {:style/indent 2} [& args] (meta/restructure :post args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro PUT {:style/indent 2} [& args] (meta/restructure :put args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro GET {:style/indent 2} [& args] (meta/restructure :get args #?(:default {:kondo-rule? true} :default nil)))
(defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args #?(:default {:kondo-rule? true} :default nil)))
(defmacro HEAD {:style/indent 2} [& args] (meta/restructure :head args #?(:default {:kondo-rule? true} :default nil)))
(defmacro PATCH {:style/indent 2} [& args] (meta/restructure :patch args #?(:default {:kondo-rule? true} :default nil)))
(defmacro DELETE {:style/indent 2} [& args] (meta/restructure :delete args #?(:default {:kondo-rule? true} :default nil)))
(defmacro OPTIONS {:style/indent 2} [& args] (meta/restructure :options args #?(:default {:kondo-rule? true} :default nil)))
(defmacro POST {:style/indent 2} [& args] (meta/restructure :post args #?(:default {:kondo-rule? true} :default nil)))
(defmacro PUT {:style/indent 2} [& args] (meta/restructure :put args #?(:default {:kondo-rule? true} :default nil)))
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
swagger (-> (dissoc :swagger) (rsc/deep-merge swagger))))

(defn restructure [method [path arg & args] {:keys [context? kondo-rule?]}]
#?(:bb (assert kondo-rule?)
#?(:default (assert kondo-rule?)
:default nil)
(let [[options body] (extract-parameters args true)
[path-string lets arg-with-request arg] (destructure-compojure-api-request path arg)
Expand Down
5 changes: 0 additions & 5 deletions scripts/regen-kondo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ rm -r resources/clj-kondo.exports
mkdir -p resources/clj-kondo.exports/metosin/compojure-api/compojure/api

bb -f ./scripts/regen_kondo_config.clj

# rename to .clj
cp src/compojure/api/common.cljc resources/clj-kondo.exports/metosin/compojure-api/compojure/api/common.clj
cp src/compojure/api/core.cljc resources/clj-kondo.exports/metosin/compojure-api/compojure/api/core.clj
cp src/compojure/api/meta.cljc resources/clj-kondo.exports/metosin/compojure-api/compojure/api/meta.clj
13 changes: 12 additions & 1 deletion scripts/regen_kondo_config.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#!/usr/bin/env bb

(ns regen-kondo-config)
(ns regen-kondo-config
(:require [clojure.string :as str]))

(def renames
;; rename to .clj
{"src/compojure/api/common.cljc" "resources/clj-kondo.exports/metosin/compojure-api/compojure/api/common.clj"
"src/compojure/api/core.cljc" "resources/clj-kondo.exports/metosin/compojure-api/compojure/api/core.clj"
"src/compojure/api/meta.cljc" "resources/clj-kondo.exports/metosin/compojure-api/compojure/api/meta.clj"})


(defn -main [& args]
(doseq [[from to] renames]
(spit to
(str/replace (slurp from) ":clj-kondo" ":default")))
(spit "resources/clj-kondo.exports/metosin/compojure-api/config.edn"
'{:hooks
{:macroexpand
Expand Down
4 changes: 2 additions & 2 deletions src/compojure/api/common.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns compojure.api.common
#?@(:bb []
#?@(:clj-kondo []
:default [(:require [linked.core :as linked])]))

(defn plain-map?
Expand Down Expand Up @@ -52,7 +52,7 @@
x
y))

#?(:bb nil
#?(:clj-kondo nil
:default
(defn fifo-memoize [f size]
"Returns a memoized version of a referentially transparent f. The
Expand Down
31 changes: 15 additions & 16 deletions src/compojure/api/core.cljc
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
;; :bb reader feature assumes clj-kondo
(ns compojure.api.core
(:require [compojure.api.meta :as meta]
#?@(:bb []
#?@(:clj-kondo []
:default [[compojure.api.async]
[compojure.core :as compojure]])
[compojure.api.routes #?(:bb :as-alias :default :as) routes]
[compojure.api.middleware #?(:bb :as-alias :default :as) mw]))
[compojure.api.routes #?(:clj-kondo :as-alias :default :as) routes]
[compojure.api.middleware #?(:clj-kondo :as-alias :default :as) mw]))

(defn ring-handler
"Creates vanilla ring-handler from any invokable thing (e.g. compojure-api route)"
Expand All @@ -17,7 +16,7 @@
(defn routes
"Create a Ring handler by combining several handlers into one."
[& handlers]
#?(:bb (throw (ex-info "Not supported in bb"))
#?(:clj-kondo (throw (ex-info "Not supported in bb"))
:default (let [handlers (seq (keep identity (flatten handlers)))]
(routes/map->Route
{:childs (vec handlers)
Expand All @@ -43,7 +42,7 @@
"Routes without route-documentation. Can be used to wrap routes,
not satisfying compojure.api.routes/Routing -protocol."
[& handlers]
#?(:bb (throw (ex-info "Not supported in bb"))
#?(:clj-kondo (throw (ex-info "Not supported in bb"))
:default (let [handlers (keep identity handlers)]
(routes/map->Route {:handler (meta/routing handlers)}))))

Expand All @@ -70,7 +69,7 @@
{:style/indent 1
:supercedes "middleware"}
[middleware & body]
#?(:bb (throw (ex-info "Not supported in bb"))
#?(:clj-kondo (throw (ex-info "Not supported in bb"))
:default
(let [handler (apply routes body)
x-handler (compojure/wrap-routes handler (mw/compose-middleware middleware))]
Expand All @@ -79,13 +78,13 @@
{:childs [handler]
:handler x-handler}))))

(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env :kondo-rule? #?(:bb true :default false)}))
(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env :kondo-rule? #?(:clj-kondo true :default false)}))

(defmacro GET {:style/indent 2} [& args] (meta/restructure :get args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro HEAD {:style/indent 2} [& args] (meta/restructure :head args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro PATCH {:style/indent 2} [& args] (meta/restructure :patch args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro DELETE {:style/indent 2} [& args] (meta/restructure :delete args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro OPTIONS {:style/indent 2} [& args] (meta/restructure :options args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro POST {:style/indent 2} [& args] (meta/restructure :post args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro PUT {:style/indent 2} [& args] (meta/restructure :put args #?(:bb {:kondo-rule? true} :default nil)))
(defmacro GET {:style/indent 2} [& args] (meta/restructure :get args #?(:clj-kondo {:kondo-rule? true} :default nil)))
(defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args #?(:clj-kondo {:kondo-rule? true} :default nil)))
(defmacro HEAD {:style/indent 2} [& args] (meta/restructure :head args #?(:clj-kondo {:kondo-rule? true} :default nil)))
(defmacro PATCH {:style/indent 2} [& args] (meta/restructure :patch args #?(:clj-kondo {:kondo-rule? true} :default nil)))
(defmacro DELETE {:style/indent 2} [& args] (meta/restructure :delete args #?(:clj-kondo {:kondo-rule? true} :default nil)))
(defmacro OPTIONS {:style/indent 2} [& args] (meta/restructure :options args #?(:clj-kondo {:kondo-rule? true} :default nil)))
(defmacro POST {:style/indent 2} [& args] (meta/restructure :post args #?(:clj-kondo {:kondo-rule? true} :default nil)))
(defmacro PUT {:style/indent 2} [& args] (meta/restructure :put args #?(:clj-kondo {:kondo-rule? true} :default nil)))
2 changes: 1 addition & 1 deletion src/compojure/api/meta.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
swagger (-> (dissoc :swagger) (rsc/deep-merge swagger))))

(defn restructure [method [path arg & args] {:keys [context? kondo-rule?]}]
#?(:bb (assert kondo-rule?)
#?(:clj-kondo (assert kondo-rule?)
:default nil)
(let [[options body] (extract-parameters args true)
[path-string lets arg-with-request arg] (destructure-compojure-api-request path arg)
Expand Down

0 comments on commit 62323bd

Please sign in to comment.