commit 6e190f6bb071e4cb05385dd85f16e09a8117f796 Author: gered Date: Tue Dec 14 21:16:49 2021 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c53038e --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/target +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port +.hgignore +.hg/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2347d9c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2021 Gered King + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a573b5 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Leiningen Template: Simple Clojure App + +A Leiningen template intended for creating new Clojure CLI app or tool projects using a simplified / stripped-down base. + +This template primarily exists for my own personal use, so some stuff is definitely more oriented towards +my own particular preferences regarding setup and organization of a Clojure project. + +## Usage + +```text +$ lein new net.gered/simple-app [your-project-name-here] +``` + +The resulting project starts up via a `main` function and during startup expects to be able to read an EDN configuration file +located in the current working directory called `config.edn`. + +The project can be run simply by: + +```text +$ lein run +``` + +A nREPL server will be started which can be connected to on port 4000 (configured via the aforementioned `config.edn`). + +## License + +Copyright © 2021 Gered King + +Distributed under the the MIT License. See LICENSE for more details. diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..9470f9e --- /dev/null +++ b/project.clj @@ -0,0 +1,7 @@ +(defproject net.gered/lein-template.simple-app "0.1.0-SNAPSHOT" + :description "Simple Clojure non-web application project template." + :url "https://github.com/gered/simple-app-template" + :license {:name "MIT License" + :url "http://opensource.org/licenses/MIT"} + + :eval-in-leiningen true) diff --git a/resources/leiningen/new/simple_app/config.edn b/resources/leiningen/new/simple_app/config.edn new file mode 100644 index 0000000..d73cfd1 --- /dev/null +++ b/resources/leiningen/new/simple_app/config.edn @@ -0,0 +1 @@ +{:nrepl {:port 4000}} \ No newline at end of file diff --git a/resources/leiningen/new/simple_app/gitignore b/resources/leiningen/new/simple_app/gitignore new file mode 100644 index 0000000..278bb6d --- /dev/null +++ b/resources/leiningen/new/simple_app/gitignore @@ -0,0 +1,17 @@ +.DS_Store +/target +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port +.settings/ +.project +.classpath +.idea/ +*.iml +*.ipr +*.iws diff --git a/resources/leiningen/new/simple_app/project.clj b/resources/leiningen/new/simple_app/project.clj new file mode 100644 index 0000000..f25a33c --- /dev/null +++ b/resources/leiningen/new/simple_app/project.clj @@ -0,0 +1,30 @@ +(defproject {{name}} "0.1.0-SNAPSHOT" + + :description "FIXME: write description" + :url "http://example.com/FIXME" + :license {:name "MIT License" + :url "http://opensource.org/licenses/MIT"} + + :dependencies [[ch.qos.logback/logback-classic "1.2.7"] + [cprop "0.1.19"] + [mount "0.1.16"] + [nrepl "0.9.0"] + [org.clojure/clojure "1.10.0"] + [org.clojure/tools.logging "1.2.1"]] + + :main {{root-ns}}.core + + :repl-options {:init-ns {{root-ns}}.core} + + :profiles {:dev {:source-paths ["env/dev/src"] + :resource-paths ["env/dev/resources"] + :dependencies [[pjstadig/humane-test-output "0.11.0"]] + :injections [(require 'pjstadig.humane-test-output) + (pjstadig.humane-test-output/activate!)]} + + :uberjar {:source-paths ["env/prod/src"] + :resource-paths ["env/prod/resources"] + :omit-source true + :aot :all}} + + :aliases {"uberjar" ["do" ["clean"] ["uberjar"]]}) diff --git a/resources/leiningen/new/simple_app/resources/logback.xml b/resources/leiningen/new/simple_app/resources/logback.xml new file mode 100644 index 0000000..0e58a40 --- /dev/null +++ b/resources/leiningen/new/simple_app/resources/logback.xml @@ -0,0 +1,12 @@ + + + + + %d{ISO8601} %-5p [%c] - %m%n + + + + + + + diff --git a/resources/leiningen/new/simple_app/src/root_ns/core.clj b/resources/leiningen/new/simple_app/src/root_ns/core.clj new file mode 100644 index 0000000..2ce35e3 --- /dev/null +++ b/resources/leiningen/new/simple_app/src/root_ns/core.clj @@ -0,0 +1,34 @@ +(ns {{root-ns}}.core + (:gen-class) + (:require + [clojure.tools.logging :as log] + [cprop.core :refer [load-config]] + [mount.core :as mount :refer [defstate]] + [nrepl.server :as nrepl])) + +;; +;; TODO: other app stuff goes here ... +;; + +(defstate ^{:on-reload :noop} config + :start + (do + (log/info "Loading config.edn") + (load-config :file "config.edn"))) + +(defstate ^{:on-reload :noop} repl-server + :start + (let [{:keys [port bind socket]} (:nrepl config) + server (nrepl/start-server :port port :bind bind :socket socket)] + (log/info "Started nREPL server:" (:server-socket server)) + server) + :stop + (when repl-server + (log/info "Stopping nREPL server") + (nrepl/stop-server repl-server))) + +(defn -main + [& args] + (log/info "{{name}} is starting up ...") + (mount/start-with-args args) + (log/info "Ready!")) diff --git a/resources/leiningen/new/simple_app/test/root_ns/core_test.clj b/resources/leiningen/new/simple_app/test/root_ns/core_test.clj new file mode 100644 index 0000000..1f829a5 --- /dev/null +++ b/resources/leiningen/new/simple_app/test/root_ns/core_test.clj @@ -0,0 +1,4 @@ +(ns {{root-ns}}.core-test + (:require + [clojure.test :refer :all] + [{{root-ns}}.core :refer :all])) diff --git a/src/leiningen/new/simple_app.clj b/src/leiningen/new/simple_app.clj new file mode 100644 index 0000000..b5e3bcf --- /dev/null +++ b/src/leiningen/new/simple_app.clj @@ -0,0 +1,26 @@ +(ns leiningen.new.simple-app + (:require + [leiningen.new.templates :as t] + [leiningen.core.main :as main])) + +(def render (t/renderer "simple_app")) + +(defn simple-app + [name] + (let [data {:name name + :sanitized (t/sanitize name) + :root-ns (t/sanitize-ns name) + :root-ns-path (t/name-to-path name)}] + (main/info (str "Creating new project via net.gered/simple-app called \"" name "\" ...")) + (t/->files + data + "env/dev/resources" + "env/dev/src" + "env/prod/resources" + "env/prod/src" + ["resources/logback.xml" (render "resources/logback.xml" data)] + ["src/{{root-ns-path}}/core.clj" (render "src/root_ns/core.clj" data)] + ["test/{{root-ns-path}}/core_test.clj" (render "test/root_ns/core_test.clj" data)] + [".gitignore" (render "gitignore" data)] + ["config.edn" (render "config.edn" data)] + ["project.clj" (render "project.clj" data)])))