From 84c5d0013d07733f2c51bce002a911b52c8b99f2 Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Sat, 31 Aug 2019 12:57:32 +0200 Subject: [PATCH] examples: generate initial skeleton app for figwheel-main example `clj -A:new figwheel-main dirac-figmain.core -- --react` --- examples/figwheel-main/.gitignore | 13 ++++++ examples/figwheel-main/README.md | 37 +++++++++++++++++ examples/figwheel-main/deps.edn | 14 +++++++ examples/figwheel-main/dev.cljs.edn | 4 ++ examples/figwheel-main/figwheel-main.edn | 31 ++++++++++++++ .../resources/public/css/style.css | 2 + .../figwheel-main/resources/public/index.html | 14 +++++++ .../figwheel-main/resources/public/test.html | 7 ++++ .../figwheel-main/src/dirac_figmain/core.cljs | 40 +++++++++++++++++++ examples/figwheel-main/test.cljs.edn | 10 +++++ .../test/dirac_figmain/core_test.cljs | 10 +++++ .../test/dirac_figmain/test_runner.cljs | 9 +++++ 12 files changed, 191 insertions(+) create mode 100644 examples/figwheel-main/.gitignore create mode 100644 examples/figwheel-main/README.md create mode 100644 examples/figwheel-main/deps.edn create mode 100644 examples/figwheel-main/dev.cljs.edn create mode 100644 examples/figwheel-main/figwheel-main.edn create mode 100644 examples/figwheel-main/resources/public/css/style.css create mode 100644 examples/figwheel-main/resources/public/index.html create mode 100644 examples/figwheel-main/resources/public/test.html create mode 100644 examples/figwheel-main/src/dirac_figmain/core.cljs create mode 100644 examples/figwheel-main/test.cljs.edn create mode 100644 examples/figwheel-main/test/dirac_figmain/core_test.cljs create mode 100644 examples/figwheel-main/test/dirac_figmain/test_runner.cljs diff --git a/examples/figwheel-main/.gitignore b/examples/figwheel-main/.gitignore new file mode 100644 index 0000000000..7c7a95db5e --- /dev/null +++ b/examples/figwheel-main/.gitignore @@ -0,0 +1,13 @@ +pom.xml +*jar +/lib/ +/classes/ +/out/ +/target/ +.lein-deps-sum +.lein-repl-history +.lein-plugins/ +.repl +.nrepl-port +.cpcache/ +.rebel_readline_history diff --git a/examples/figwheel-main/README.md b/examples/figwheel-main/README.md new file mode 100644 index 0000000000..156a4405bd --- /dev/null +++ b/examples/figwheel-main/README.md @@ -0,0 +1,37 @@ +# dirac-figmain.core + +FIXME: Write a one-line description of your library/project. + +## Overview + +FIXME: Write a paragraph about the library/project and highlight its goals. + +## Development + +To get an interactive development environment run: + + clojure -A:fig:build + +This will auto compile and send all changes to the browser without the +need to reload. After the compilation process is complete, you will +get a Browser Connected REPL. An easy way to try it is: + + (js/alert "Am I connected?") + +and you should see an alert in the browser window. + +To clean all compiled files: + + rm -rf target/public + +To create a production build run: + + rm -rf target/public + clojure -A:fig:min + + +## License + +Copyright © 2018 FIXME + +Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version. diff --git a/examples/figwheel-main/deps.edn b/examples/figwheel-main/deps.edn new file mode 100644 index 0000000000..2d00e90bcd --- /dev/null +++ b/examples/figwheel-main/deps.edn @@ -0,0 +1,14 @@ +{:deps {org.clojure/clojure {:mvn/version "1.9.0"} + org.clojure/clojurescript {:mvn/version "1.10.339"} + cljsjs/react {:mvn/version "16.4.1-0"} + cljsjs/react-dom {:mvn/version "16.4.1-0"} + cljsjs/create-react-class {:mvn/version "15.6.3-1"} + sablono {:mvn/version "0.8.4"}} + :paths ["src" "resources"] + :aliases {:fig {:extra-deps + {com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"} + com.bhauman/figwheel-main {:mvn/version "0.1.9"}} + :extra-paths ["target" "test"]} + :build {:main-opts ["-m" "figwheel.main" "-b" "dev" "-r"]} + :min {:main-opts ["-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]} + :test {:main-opts ["-m" "figwheel.main" "-co" "test.cljs.edn" "-m" dirac-figmain.test-runner]}}} diff --git a/examples/figwheel-main/dev.cljs.edn b/examples/figwheel-main/dev.cljs.edn new file mode 100644 index 0000000000..a2851a8b13 --- /dev/null +++ b/examples/figwheel-main/dev.cljs.edn @@ -0,0 +1,4 @@ +^{:watch-dirs ["test" "src"] + :css-dirs ["resources/public/css"] + :auto-testing true} +{:main dirac-figmain.core} diff --git a/examples/figwheel-main/figwheel-main.edn b/examples/figwheel-main/figwheel-main.edn new file mode 100644 index 0000000000..c1117d41e5 --- /dev/null +++ b/examples/figwheel-main/figwheel-main.edn @@ -0,0 +1,31 @@ +;; Figwheel-main configuration options see: https://figwheel.org/config-options +;; these will be overriden by the metadata config options in dev.cljs.edn build file +{ + ;; Set the server port https://figwheel.org/config-options#ring-server-options + ;; :ring-server-options {:port 9500} + + ;; Target directory https://figwheel.org/config-options#target-dir + ;; you may want to set this to resources if you are using Leiningen + ;; :target-dir "resources" + + ;; Server Ring Handler (optional) https://figwheel.org/docs/ring-handler.html + ;; If you want to embed a ring handler into the figwheel server, this + ;; is for simple ring servers + ;; :ring-handler hello_world.server/handler + + ;; To be able to open files in your editor from the heads up display + ;; you will need to put a script on your path. This script will have + ;; to take a file path and a line number ie. + ;; in ~/bin/myfile-opener: + ;; + ;; #! /bin/sh + ;; emacsclient -n +$2:$3 $1 + ;; + ;; :open-file-command "myfile-opener" + + ;; if you are using emacsclient you can just use + ;; :open-file-command "emacsclient" + + ;; Logging output gets printed to the REPL, if you want to redirect it to a file: + ;; :log-file "figwheel-main.log" +} diff --git a/examples/figwheel-main/resources/public/css/style.css b/examples/figwheel-main/resources/public/css/style.css new file mode 100644 index 0000000000..26163d2ee0 --- /dev/null +++ b/examples/figwheel-main/resources/public/css/style.css @@ -0,0 +1,2 @@ +/* some style */ + diff --git a/examples/figwheel-main/resources/public/index.html b/examples/figwheel-main/resources/public/index.html new file mode 100644 index 0000000000..76bbcfd160 --- /dev/null +++ b/examples/figwheel-main/resources/public/index.html @@ -0,0 +1,14 @@ + + + + + + + + + +
+
+ + + diff --git a/examples/figwheel-main/resources/public/test.html b/examples/figwheel-main/resources/public/test.html new file mode 100644 index 0000000000..b08b182dbe --- /dev/null +++ b/examples/figwheel-main/resources/public/test.html @@ -0,0 +1,7 @@ + + + +

Test host page

+ + + diff --git a/examples/figwheel-main/src/dirac_figmain/core.cljs b/examples/figwheel-main/src/dirac_figmain/core.cljs new file mode 100644 index 0000000000..804847a8d6 --- /dev/null +++ b/examples/figwheel-main/src/dirac_figmain/core.cljs @@ -0,0 +1,40 @@ +(ns ^:figwheel-hooks dirac-figmain.core + (:require + [goog.dom :as gdom] + [react :as react] + [react-dom :as react-dom] + [sablono.core :as sab :include-macros true])) + +(println "This text is printed from src/dirac_figmain/core.cljs. Go ahead and edit it and see reloading in action.") + +(defn multiply [a b] (* a b)) + + +;; define your app data so that it doesn't get over-written on reload +(defonce app-state (atom {:text "Hello world!"})) + +(defn get-app-element [] + (gdom/getElement "app")) +(defn hello-world [state] + (sab/html [:div + [:h1 (:text @state)] + [:h3 "Edit this in src/dirac_figmain/core.cljs and watch it change!"]])) + +(defn mount [el] + (js/ReactDOM.render (hello-world app-state) el)) + +(defn mount-app-element [] + (when-let [el (get-app-element)] + (mount el))) + +;; conditionally start your application based on the presence of an "app" element +;; this is particularly helpful for testing this ns without launching the app +(mount-app-element) + +;; specify reload hook with ^;after-load metadata +(defn ^:after-load on-reload [] + (mount-app-element) + ;; optionally touch your app-state to force rerendering depending on + ;; your application + ;; (swap! app-state update-in [:__figwheel_counter] inc) +) diff --git a/examples/figwheel-main/test.cljs.edn b/examples/figwheel-main/test.cljs.edn new file mode 100644 index 0000000000..949cbce395 --- /dev/null +++ b/examples/figwheel-main/test.cljs.edn @@ -0,0 +1,10 @@ +^{ + ;; use an alternative landing page for the tests so that we don't + ;; launch the application + :open-url "http://[[server-hostname]]:[[server-port]]/test.html" + + ;; uncomment to launch tests in a headless environment + ;; you will have to figure out the path to chrome on your system + ;; :launch-js ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "--headless" "--disable-gpu" "--repl" :open-url] + } +{:main dirac-figmain.test-runner} diff --git a/examples/figwheel-main/test/dirac_figmain/core_test.cljs b/examples/figwheel-main/test/dirac_figmain/core_test.cljs new file mode 100644 index 0000000000..d734f6c36a --- /dev/null +++ b/examples/figwheel-main/test/dirac_figmain/core_test.cljs @@ -0,0 +1,10 @@ +(ns dirac-figmain.core-test + (:require + [cljs.test :refer-macros [deftest is testing]] + [dirac-figmain.core :refer [multiply]])) + +(deftest multiply-test + (is (= (* 1 2) (multiply 1 2)))) + +(deftest multiply-test-2 + (is (= (* 75 10) (multiply 10 75)))) diff --git a/examples/figwheel-main/test/dirac_figmain/test_runner.cljs b/examples/figwheel-main/test/dirac_figmain/test_runner.cljs new file mode 100644 index 0000000000..b4ffb005e0 --- /dev/null +++ b/examples/figwheel-main/test/dirac_figmain/test_runner.cljs @@ -0,0 +1,9 @@ +;; This test runner is intended to be run from the command line +(ns dirac-figmain.test-runner + (:require + ;; require all the namespaces that you want to test + [dirac-figmain.core-test] + [figwheel.main.testing :refer [run-tests-async]])) + +(defn -main [& args] + (run-tests-async 5000))