From 4b2b93eed55f6fec14636a001b80dc7c72d11291 Mon Sep 17 00:00:00 2001 From: anonymous Date: Sun, 28 Aug 2022 11:55:38 +0200 Subject: [PATCH] route parsing for laravel --- deps.edn | 3 ++ main.hs | 1 - src/main/clj/gen/core.clj | 43 ++++++++++++++++++++++++++++ src/main/clj/scan/lang/php/laravel5/scan.clj | 18 ++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 deps.edn delete mode 100644 main.hs create mode 100644 src/main/clj/gen/core.clj create mode 100644 src/main/clj/scan/lang/php/laravel5/scan.clj diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000..5c1459c --- /dev/null +++ b/deps.edn @@ -0,0 +1,3 @@ +{:paths ["src/main/clj"] + :deps {org.clojure/clojure {:mvn/version "1.10.3"} + clj-commons/clj-yaml {:mvn/version "0.7.0"}}} \ No newline at end of file diff --git a/main.hs b/main.hs deleted file mode 100644 index cfa89ae..0000000 --- a/main.hs +++ /dev/null @@ -1 +0,0 @@ --- x \ No newline at end of file diff --git a/src/main/clj/gen/core.clj b/src/main/clj/gen/core.clj new file mode 100644 index 0000000..456fc57 --- /dev/null +++ b/src/main/clj/gen/core.clj @@ -0,0 +1,43 @@ +(ns gen.core + (:require [clojure.string :as str] + [clj-yaml.core :as yaml] + [scan.lang.php.laravel5.scan :as laravel5])) + +(def + ^{} + run + (fn [args] + (laravel5/routes (first args)) + #_(println + (yaml/generate-string + {"openapi" "3.0.0" + :info + {:version 1 + :title "thing" + :license + {:name "MIT"}} + :servers + [{:url "thing"}] + :paths + {"/pets" + {:get + {:parameters + [{:name "limit" + :in "query" + :description "aaaaaaaa" + :required false + :schema + {:type "integer" + :format "int32"}}]}} + "/lists" + {:get + {:responses + {"200" + {:description "ok"}}}}} + :spec {:lorem "ipsum" :thing true}} + :dumper-options {:indent 2 + :indicator-indent 1 + :flow-style :block})))) + +(defn -main [& argv] + (prn (run argv))) \ No newline at end of file diff --git a/src/main/clj/scan/lang/php/laravel5/scan.clj b/src/main/clj/scan/lang/php/laravel5/scan.clj new file mode 100644 index 0000000..dd8faac --- /dev/null +++ b/src/main/clj/scan/lang/php/laravel5/scan.clj @@ -0,0 +1,18 @@ +(ns scan.lang.php.laravel5.scan + (:require [clojure.string :as str])) + +(def + ^{} + routes + (fn [project-path] + (let [route-file (str project-path "/routes/web.php")] + (map (fn [hit] + (let [[_ verb raw-params] hit + params (map (fn [e] (str/trim (str/escape e {\' ""}))) (str/split raw-params #",")) + [route ctl] params] + {:verb verb + :route route + :ctl ctl})) + (re-seq + #"router->(.*)\((.*)\)" + (slurp route-file))))))