Pārlūkot izejas kodu

ported from lein to figwheel-main

Harlan Iverson 5 gadi atpakaļ
vecāks
revīzija
847b9eb1d1

+ 3 - 3
.gitignore

@@ -1,7 +1,6 @@
-/resources/public/js/compiled/**
-figwheel_server.log
 pom.xml
 *jar
+*~
 /lib/
 /classes/
 /out/
@@ -11,4 +10,5 @@ pom.xml
 .lein-plugins/
 .repl
 .nrepl-port
-*~
+.cpcache/
+.rebel_readline_history

+ 7 - 17
README.md

@@ -1,4 +1,4 @@
-# pos-demo
+# pos-demo.core
 
 FIXME: Write a one-line description of your library/project.
 
@@ -6,13 +6,12 @@ FIXME: Write a one-line description of your library/project.
 
 FIXME: Write a paragraph about the library/project and highlight its goals.
 
-## Setup
+## Development
 
 To get an interactive development environment run:
 
-    lein figwheel
+    clojure -A:fig:build
 
-and open your browser at [localhost:3449](http://localhost:3449/).
 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:
@@ -23,25 +22,16 @@ and you should see an alert in the browser window.
 
 To clean all compiled files:
 
-    lein clean
+    rm -rf target/public
 
 To create a production build run:
 
-    lein do clean, cljsbuild once min
-
-And open your browser in `resources/public/index.html`. You will not
-get live reloading, nor a REPL. 
-
-To serve the prodction build on most machines:
-
-```
-cd resources/public
-python -m SimpleHTTPServer 3449
-```
+	rm -rf target/public
+	clojure -A:fig:min
 
 
 ## License
 
-Copyright © 2014 FIXME
+Copyright © 2018 FIXME
 
 Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

+ 15 - 0
deps.edn

@@ -0,0 +1,15 @@
+{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
+                 org.clojure/clojurescript {:mvn/version "1.10.520"}
+                 org.clojure/core.async {:mvn/version  "0.4.500"}
+                 reagent {:mvn/version "0.8.1"}
+                 ;ring {:mvn/version "1.7.1"}
+                 cljs-http {:mvn/version "0.1.46"}}        
+        
+ :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" pos-demo.test-runner]}}}

+ 4 - 0
dev.cljs.edn

@@ -0,0 +1,4 @@
+^{:watch-dirs ["test" "src"]
+  :css-dirs ["resources/public/css"]
+  :auto-testing true}
+{:main pos-demo.core}

+ 0 - 42
dev/user.clj

@@ -1,42 +0,0 @@
-(ns user
-  (:require
-   [figwheel-sidecar.repl-api :as f]))
-
-;; user is a namespace that the Clojure runtime looks for and
-;; loads if its available
-
-;; You can place helper functions in here. This is great for starting
-;; and stopping your webserver and other development services
-
-;; The definitions in here will be available if you run "lein repl" or launch a
-;; Clojure repl some other way
-
-;; You have to ensure that the libraries you :require are listed in your dependencies
-
-;; Once you start down this path
-;; you will probably want to look at
-;; tools.namespace https://github.com/clojure/tools.namespace
-;; and Component https://github.com/stuartsierra/component
-
-
-(defn fig-start
-  "This starts the figwheel server and watch based auto-compiler."
-  []
-  ;; this call will only work as long as your :cljsbuild and
-  ;; :figwheel configurations are at the top level of your project.clj
-  ;; and are not spread across different lein profiles
-
-  ;; otherwise you can pass a configuration into start-figwheel! manually
-  (f/start-figwheel!))
-
-(defn fig-stop
-  "Stop the figwheel server and watch based auto-compiler."
-  []
-  (f/stop-figwheel!))
-
-;; if you are in an nREPL environment you will need to make sure you
-;; have setup piggieback for this to work
-(defn cljs-repl
-  "Launch a ClojureScript REPL that is connected to your build and host environment."
-  []
-  (f/cljs-repl))

+ 31 - 0
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 pos-demo.core/web-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"
+}

+ 0 - 99
project.clj

@@ -1,99 +0,0 @@
-(defproject pos-demo "0.1.0-SNAPSHOT"
-  :description "FIXME: write this!"
-  :url "http://example.com/FIXME"
-  :license {:name "Eclipse Public License"
-            :url "http://www.eclipse.org/legal/epl-v10.html"}
-
-  ;:min-lein-version "2.9.1"
-
-  :dependencies [[org.clojure/clojure "1.10.0"]
-                 [org.clojure/clojurescript "1.10.520"]
-                 [org.clojure/core.async  "0.4.500"]
-                 [reagent "0.8.1"]
-                 [ring "1.7.1"]
-                 [cljs-http "0.1.46"]
-                 [org.clojure/core.async "0.4.500"]]
-
-  :plugins [[lein-figwheel "0.5.19"]
-            [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]]
-
-  :source-paths ["src"]
-
-  :cljsbuild {:builds
-              [{:id "dev"
-                :source-paths ["src"]
-
-                ;; The presence of a :figwheel configuration here
-                ;; will cause figwheel to inject the figwheel client
-                ;; into your build
-                :figwheel {:on-jsload "pos-demo.core/on-js-reload"
-                           ;; :open-urls will pop open your application
-                           ;; in the default browser once Figwheel has
-                           ;; started and compiled your application.
-                           ;; Comment this out once it no longer serves you.
-                           :open-urls ["http://localhost:3449/index.html"]}
-
-                :compiler {:main pos-demo.core
-                           :asset-path "js/compiled/out"
-                           :output-to "resources/public/js/compiled/pos_demo.js"
-                           :output-dir "resources/public/js/compiled/out"
-                           :source-map-timestamp true
-                           ;; To console.log CLJS data-structures make sure you enable devtools in Chrome
-                           ;; https://github.com/binaryage/cljs-devtools
-                           :preloads [devtools.preload]}}
-               ;; This next build is a compressed minified build for
-               ;; production. You can build this with:
-               ;; lein cljsbuild once min
-               {:id "min"
-                :source-paths ["src"]
-                :compiler {:output-to "resources/public/js/compiled/pos_demo.js"
-                           :main pos-demo.core
-                           :optimizations :advanced
-                           :pretty-print false}}]}
-
-  :figwheel {;; :http-server-root "public" ;; default and assumes "resources"
-             ;; :server-port 3449 ;; default
-             ;; :server-ip "127.0.0.1"
-
-             :css-dirs ["resources/public/css"] ;; watch and update CSS
-
-             ;; Start an nREPL server into the running figwheel process
-             ;; :nrepl-port 7888
-
-             ;; Server Ring Handler (optional)
-             ;; if you want to embed a ring handler into the figwheel http-kit
-             ;; server, this is for simple ring servers, if this
-
-             ;; doesn't work for you just run your own server :) (see lein-ring)
-
-             :ring-handler pos-demo.core/web-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.
-             ;; that script will have to take a file path and a line number
-             ;; ie. in  ~/bin/myfile-opener
-             ;; #! /bin/sh
-             ;; emacsclient -n +$2 $1
-             ;;
-             ;; :open-file-command "myfile-opener"
-
-             ;; if you are using emacsclient you can just use
-             ;; :open-file-command "emacsclient"
-
-             ;; if you want to disable the REPL
-             ;; :repl false
-
-             ;; to configure a different figwheel logfile path
-             ;; :server-logfile "tmp/logs/figwheel-logfile.log"
-
-             ;; to pipe all the output to the repl
-             ;; :server-logfile false
-             }
-
-  :profiles {:dev {:dependencies [[binaryage/devtools "0.9.10"]
-                                  [figwheel-sidecar "0.5.19"]]
-                   ;; need to add dev source path here to get user.clj loaded
-                   :source-paths ["src" "dev"]
-                   ;; need to add the compliled assets to the :clean-targets
-                   :clean-targets ^{:protect false} ["resources/public/js/compiled"
-                                                     :target-path]}})

+ 2 - 4
resources/public/index.html

@@ -8,9 +8,7 @@
   </head>
   <body>
     <div id="app">
-      <h2>Loading application. Thanks for your patience.</h2>
-      <p>Debugging information is available in the developer console.</p>
-    </div>
-    <script src="js/compiled/pos_demo.js" type="text/javascript"></script>
+    </div> <!-- end of app div -->
+    <script src="cljs-out/dev-main.js" type="text/javascript"></script>
   </body>
 </html>

+ 7 - 0
resources/public/test.html

@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <h1>Test host page</h1>
+    <script src="cljs-out/test-main.js" type="text/javascript"></script>
+  </body>
+</html>

+ 10 - 0
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 pos-demo.test-runner}

+ 4 - 0
test/pos_demo/core_test.cljs

@@ -0,0 +1,4 @@
+(ns pos-demo.core-test
+    (:require
+     [cljs.test :refer-macros [deftest is testing]]
+     [pos-demo.core :as core]))

+ 9 - 0
test/pos_demo/test_runner.cljs

@@ -0,0 +1,9 @@
+;; This test runner is intended to be run from the command line
+(ns pos-demo.test-runner
+  (:require
+    ;; require all the namespaces that you want to test
+    [pos-demo.core-test]
+    [figwheel.main.testing :refer [run-tests-async]]))
+
+(defn -main [& args]
+  (run-tests-async 5000))