@@ -1,13 +1,13 @@ | |||||
(ns gen.core | (ns gen.core | ||||
(:require [clojure.string :as str] | (:require [clojure.string :as str] | ||||
[clj-yaml.core :as yaml] | [clj-yaml.core :as yaml] | ||||
[scan.lang.php.laravel5.scan :as laravel5])) | |||||
[scan.lang.php.laravel5])) | |||||
(def | (def | ||||
^{} | ^{} | ||||
run | run | ||||
(fn [args] | (fn [args] | ||||
(laravel5/routes (first args)) | |||||
(scan.lang.php.laravel5/routes (first args)) | |||||
#_(println | #_(println | ||||
(yaml/generate-string | (yaml/generate-string | ||||
{"openapi" "3.0.0" | {"openapi" "3.0.0" | ||||
@@ -39,5 +39,9 @@ | |||||
:indicator-indent 1 | :indicator-indent 1 | ||||
:flow-style :block})))) | :flow-style :block})))) | ||||
(comment | |||||
) | |||||
(defn -main [& argv] | (defn -main [& argv] | ||||
(prn (run argv))) | (prn (run argv))) |
@@ -0,0 +1,47 @@ | |||||
(ns scan.lang.php.laravel5 | |||||
(:require [clojure.string :as str] | |||||
[clojure.java.io :as io])) | |||||
(def | |||||
^{} | |||||
load-method-signature! | |||||
(fn [route] | |||||
(cond (.exists (io/file (:ctl route))) | |||||
(let [src (slurp (:ctl route))] | |||||
(->> | |||||
(-> (re-pattern (str "function " (:act route) "\\((.*)\\)")) | |||||
(re-find src) | |||||
last | |||||
(or "") | |||||
(str/split #",")) | |||||
(map str/trim) | |||||
(filter (fn [e] (not (str/includes? e "Request")))) | |||||
(into []))) | |||||
:else nil))) | |||||
(def | |||||
^{} | |||||
routes | |||||
(fn [project-path] | |||||
(map (fn [route] | |||||
(assoc route | |||||
:signature | |||||
(load-method-signature! route))) | |||||
(let [route-file (str project-path "/routes/web.php")] | |||||
(filter | |||||
(fn [e] | |||||
(not (nil? e))) | |||||
(map | |||||
(fn [hit] | |||||
(let [[_ verb raw-params] hit | |||||
params (map (fn [e] (str/trim (str/escape e {\' ""}))) (str/split raw-params #",")) | |||||
[route ctl] params] | |||||
(if ctl | |||||
{:verb verb | |||||
:path route | |||||
:ctl (str project-path "/app/Http/Controllers/" (str/replace (str/replace ctl #"\@(.*)" ".php") "\\" "/")) | |||||
:act (str/replace ctl #"(.*)\@" "")} | |||||
nil))) | |||||
(re-seq | |||||
#"router->(.*)\((.*)\)" | |||||
(slurp route-file)))))))) |
@@ -1,18 +0,0 @@ | |||||
(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)))))) |