# HG changeset patch # User alys # Date 2018-09-26 04:07:02 # Node ID 5847e68f6afb4f79fe6b91ef39375562becd3dfb Initial working version. diff --git a/.hgignore b/.hgignore new file mode 100644 --- /dev/null +++ b/.hgignore @@ -0,0 +1,15 @@ +syntax: glob +pom.xml +pom.xml.asc +*.jar +*.class +.gitignore +.git/** +node_modules/* + +syntax: regexp +^.nrepl-port +^.lein-.* +^target/ +^classes/ +^checkouts/ diff --git a/project.clj b/project.clj new file mode 100644 --- /dev/null +++ b/project.clj @@ -0,0 +1,38 @@ +(defproject project-checkup "0.1.0-SNAPSHOT" + :description "FIXME: write description" + :url "http://example.com/FIXME" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + :dependencies [[org.clojure/clojure "1.8.0"] + [org.clojure/clojurescript "1.9.521"] + ; [andare "0.9.0"] + [org.clojure/core.async "0.4.474"] + + ] + + :plugins [[lein-cljsbuild "1.1.5"]] + + :cljsbuild {:builds [{:id "development" + :source-paths ["src"] + :compiler {:main project-checkup.core + :output-to "package/index.js" + :target :nodejs + :output-dir "target/development" + :install-deps true + :optimizations :none + :pretty-print true + :parallel-build true}} + {:id "optimized" + :source-paths ["src"] + :compiler {:main project-checkup.core + :output-to "package/index.js" + :target :nodejs + :output-dir "target/optimized" + ;; :externs ["externs.js"] + :install-deps true + :optimizations :advanced + :pretty-print true + :parallel-build true}}]} + :main ^:skip-aot project-checkup.core + :target-path "target/%s" + :profiles {:uberjar {:aot :all}}) diff --git a/src/project_checkup/core.clj b/src/project_checkup/core.clj new file mode 100755 --- /dev/null +++ b/src/project_checkup/core.clj @@ -0,0 +1,90 @@ +#!/usr/bin/env lumo +(ns project-checkup.core + (:gen-class) + (:require [clojure.java.shell :as shell] + [clojure.string :as string])) + +(defn get-extension [path] (re-find #"\.[a-zA-Z]+" path)) + +(defn gather-project-info + "Creates a dictionary of project information" + [] + (let [files (set (map str (file-seq (clojure.java.io/file "."))))] + {:files files + :extensions (frequencies (map get-extension files )) + :path (:out (shell/sh "pwd")) + :untracked-files (string/split (:out (shell/sh "hg" "st" "-u" "-n")) #"\n") })) + +(defn color [color string] + (let [color-sequence (case color + :green "\u001B[32m" + :yellow "\u001B[33m" + :blue "\u001B[34m" + ) + reset "\u001B[m" ] + (str color-sequence string reset)) ) + + +(defn check-vcs [project] + (let [{files :files } project] + (boolean (some #{"./.git" "./.hg"} files)) )) + +(defn check-readme [project] + (let [{files :files } project] + (boolean (some #{"./README.md" "./README.txt" "./README.mkd"} files)) )) + +(defn check-untracked [project] + (let [{untracked :untracked-files } project] + (= (count untracked) 0)) ) + +(defn check-taskpaper [project] + (let [{extensions :extensions } project] + (>= (get ".taskpaper" extensions 0) 1) )) + +(def checks [{:name "Has VCS" + :description "" + :function check-vcs + :level :error + :follow-up "Initialize a repository." } + {:name "Always True" + :function #(or true %) + :level :error + :follow-up "This is a bug." } + {:name "Has Untracked" + :description "" + :function check-untracked + :level :warning + :follow-up "Commit or ignore files from 'hg st -u'." } + {:name "No Todo" + :function check-taskpaper + :description "" + :level :suggestion + :follow-up "Add a todo file using Taskpaper." } + {:name "Has Readme" + :function check-readme + :description "Readme exists" + :level :suggestion + :follow-up "Add a README." } ]) + +(defn perform-check [check project] + (let [{check-name :name function :function follow-up :follow-up + level :level } check + result (function project) + false-color (case level + :suggestion :blue + :warning :yellow + :error :red + :red) ] + {:name check-name + :result result + :output (if result + (color :green (str "✓" check-name " passed!")) + (str check-name (color false-color " failed! ") "\n\tFollow up: " follow-up))})) + + +(defn -main + "I don't do a whole lot ... yet." + [& args] + (doseq [check checks] + (println (:output (perform-check check (gather-project-info) )))) + (shutdown-agents) )