diff --git a/.github/workflows/gen-list.yml b/.github/workflows/gen-list.yml index 6b85da0..ca97f88 100644 --- a/.github/workflows/gen-list.yml +++ b/.github/workflows/gen-list.yml @@ -17,11 +17,12 @@ jobs: uses: actions/checkout@v2 # Now we can execute a babashka script from our # repository - - name: babashka-script - uses: tzafrirben/babashka-docker-action@v0.3 - id: bb_script + - name: setup babashka + uses: turtlequeue/setup-babashka@v1.5.0 with: - bb_src: 'scripts/gen-list.clj' + babashka-version: 1.1.173 + - name: gen-list + run: bb scripts/gen-list.clj - name: Create Pull Request id: cpr uses: peter-evans/create-pull-request@v5-beta @@ -39,5 +40,4 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} - merge-method: squash - + merge-method: squash \ No newline at end of file diff --git a/scripts/gen-list.clj b/scripts/gen-list.clj index d50db40..d6c9e72 100644 --- a/scripts/gen-list.clj +++ b/scripts/gen-list.clj @@ -1,53 +1,35 @@ (require '[cheshire.core :as json]) - -(defn directory [name] + +(defn directory [name] (io/file (str "./" name))) -(defn makeLink [lang name] - (str "https://raw.githubusercontent.com/sern-handler/awesome-plugins/main/" lang "/" name)) - -(defn nameNoExtension [name] - (subs name 0 (- (.length name) 3)) - ) -(def JavaScript - ( ->> - (directory "JavaScript") - file-seq - (filter #( .isFile %)) - (map #( .getName %)) - doall - )) +(defn make-link [lang] + (fn [name] (str "https://raw.githubusercontent.com/sern-handler/awesome-plugins/main/" lang "/" name))) + +(defn name-without-extension [name] + (if-let [last-dot-index (str/last-index-of name ".")] + (subs name 0 last-dot-index) + name)) + +(defn file-names [dir-name] + (->> + (directory dir-name) + file-seq + (filter #(.isFile %)) + (map #(.getName %)))) + + +(defn file-links-and-basenames [dir] + (let [base-link (make-link dir)] + (mapv #(zipmap [:link :name] ((juxt base-link name-without-extension) %)) + (file-names dir)))) + +(def file-info-map (juxt keyword file-links-and-basenames)) + +(def json + (into {} (map file-info-map ["JavaScript" "TypeScript"]))) -(def TypeScript - ( ->> - (directory "TypeScript") - file-seq - (filter #( .isFile %)) - (map #( .getName %)) - doall - )) - -(println "Found Files:") -(run! println (map nameNoExtension TypeScript) ) - - -(def JSMap - (into [] (for [x JavaScript] - { :link (makeLink "JavaScript" x) :name (nameNoExtension x) } - )) -) - -(def TSMap - (into [] (for [x TypeScript] - { :link (makeLink "TypeScript" x) :name (nameNoExtension x) } - )) -) - -(def Json - { :TypeScript TSMap :JavaScript JSMap } -) - -(json/generate-stream Json (io/writer "pluginlist.json") { :pretty true }) +(json/generate-stream json (io/writer "pluginlist.json") { :pretty true }) (println "\nGenerated Plugins!")