├── .github └── FUNDING.yml ├── src └── leiningen │ └── new │ ├── figwheel_main │ ├── style.css │ ├── test-page.html │ ├── dev.cljs.edn │ ├── gitignore │ ├── package.json │ ├── test.cljs │ ├── test-runner.cljs │ ├── test.cljs.edn │ ├── bare-index.html │ ├── user.clj │ ├── deps.edn │ ├── figwheel-main.edn │ ├── README.md │ ├── project.clj │ ├── core.cljs │ └── index.html │ └── figwheel_main.clj ├── _config.yml ├── .gitignore ├── project.clj ├── assets └── css │ └── style.scss ├── README.md └── LICENSE /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [bhauman] 2 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/style.css: -------------------------------------------------------------------------------- 1 | /* some style */ 2 | 3 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal 2 | show_downloads: false 3 | logo: https://s3.amazonaws.com/bhauman-blog-images/figwheel_image.png 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | pom.xml 5 | pom.xml.asc 6 | *.jar 7 | *.class 8 | /.lein-* 9 | /.nrepl-port 10 | hello_world 11 | hello-world 12 | \.\#* 13 | \#* 14 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/test-page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Test host page

5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/dev.cljs.edn: -------------------------------------------------------------------------------- 1 | ^{:watch-dirs ["test" "src"] 2 | :css-dirs ["resources/public/css"] 3 | :auto-testing true 4 | {{#npm-bundle?}}:auto-bundle :webpack{{/npm-bundle?}} } 5 | {:main {{namespace}}} 6 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/gitignore: -------------------------------------------------------------------------------- 1 | pom.xml 2 | *jar 3 | /lib/ 4 | /classes/ 5 | /out/ 6 | /target/ 7 | .lein-deps-sum 8 | .lein-repl-history 9 | .lein-plugins/ 10 | .repl 11 | .nrepl-port 12 | .cpcache/ 13 | .rebel_readline_history -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "webpack": "^4.43.0", 4 | "webpack-cli": "^3.3.11" 5 | }{{#reactdep?}}, 6 | "dependencies": { 7 | "react": "^16.13.1", 8 | "react-dom": "^16.13.1" 9 | }{{/reactdep?}} 10 | } 11 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/test.cljs: -------------------------------------------------------------------------------- 1 | (ns {{namespace}}-test 2 | (:require 3 | [cljs.test :refer-macros [deftest is testing]] 4 | [{{namespace}} :refer [multiply]])) 5 | 6 | (deftest multiply-test 7 | (is (= (* 1 2) (multiply 1 2)))) 8 | 9 | (deftest multiply-test-2 10 | (is (= (* 75 10) (multiply 10 75)))) 11 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/test-runner.cljs: -------------------------------------------------------------------------------- 1 | ;; This test runner is intended to be run from the command line 2 | (ns {{test-runner-ns}} 3 | (:require 4 | ;; require all the namespaces that you want to test 5 | [{{namespace}}-test] 6 | [figwheel.main.testing :refer [run-tests-async]])) 7 | 8 | (defn -main [& args] 9 | (run-tests-async 5000)) 10 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject figwheel-main/lein-template "0.2.12" 2 | :description "A Leinigen template for figwheel" 3 | :url "https://github.com/bhauman/figwheel-main-template" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | :scm { :name "git" 7 | :url "https://github.com/bhauman/figwheel-main-template"} 8 | :eval-in-leiningen true) 9 | -------------------------------------------------------------------------------- /assets/css/style.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | @import "{{ site.theme }}"; 5 | 6 | 7 | header { 8 | position: relative; 9 | width: 200px; 10 | } 11 | 12 | header h1 { 13 | display: none; 14 | } 15 | 16 | section { 17 | width:600px; 18 | } 19 | 20 | a:focus { 21 | font-weight: normal; 22 | } 23 | 24 | a:hover { 25 | font-weight: normal; 26 | } 27 | 28 | footer { 29 | display: none; 30 | } 31 | 32 | .hithere { 33 | color:red; 34 | } -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/test.cljs.edn: -------------------------------------------------------------------------------- 1 | ^{ 2 | ;; use an alternative landing page for the tests so that we don't 3 | ;; launch the application 4 | :open-url "http://[[server-hostname]]:[[server-port]]/test.html" 5 | 6 | ;; uncomment to launch tests in a headless environment 7 | ;; you will have to figure out the path to chrome on your system 8 | ;; :launch-js ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "--headless" "--disable-gpu" "--repl" :open-url] 9 | } 10 | {:main {{test-runner-ns}}} 11 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/bare-index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/user.clj: -------------------------------------------------------------------------------- 1 | (ns user) 2 | 3 | ;; user is a namespace that the Clojure runtime looks for and 4 | ;; loads if its available 5 | 6 | ;; You can place helper functions in here. This is great for starting 7 | ;; and stopping your webserver and other development services 8 | 9 | ;; The definitions in here will be available if you run "clj -Acljs" or launch a 10 | ;; Clojure repl some other way 11 | 12 | (defn fig-start 13 | "This starts the figwheel build" 14 | [] 15 | (require 'figwheel.main) 16 | ;; otherwise you can pass a configuration into start-figwheel! manually 17 | (figwheel.main/start "dev")) 18 | 19 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/deps.edn: -------------------------------------------------------------------------------- 1 | {:deps {org.clojure/clojure {:mvn/version "1.10.0"} 2 | org.clojure/clojurescript {:mvn/version "1.10.773"}{{#react?}}{{^npm-bundle?}} 3 | cljsjs/react {:mvn/version "16.4.1-0"} 4 | cljsjs/react-dom {:mvn/version "16.4.1-0"}{{/npm-bundle?}} 5 | sablono/sablono {:mvn/version "0.8.6"}{{/react?}}{{#reagent?}} 6 | reagent/reagent {:mvn/version "0.10.0" {{#npm-bundle?}}:exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server]{{/npm-bundle?}}}{{/reagent?}}{{#rum?}} 7 | rum/rum {:mvn/version "0.12.3"}{{/rum?}}} 8 | :paths ["src" "resources"] 9 | :aliases {:fig {:extra-deps 10 | {com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"} 11 | com.bhauman/figwheel-main {:mvn/version "0.2.11"}} 12 | :extra-paths ["target" "test"]} 13 | :build {:main-opts ["-m" "figwheel.main" "-b" "dev" "-r"]} 14 | :min {:main-opts ["-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]} 15 | :test {:main-opts ["-m" "figwheel.main" "-co" "test.cljs.edn" "-m" "{{test-runner-ns}}"]}}} 16 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/figwheel-main.edn: -------------------------------------------------------------------------------- 1 | ;; Figwheel-main configuration options see: https://figwheel.org/config-options 2 | ;; these will be overriden by the metadata config options in dev.cljs.edn build file 3 | { 4 | ;; Set the server port https://figwheel.org/config-options#ring-server-options 5 | ;; :ring-server-options {:port 9500} 6 | 7 | {{#deps?}};; Target directory https://figwheel.org/config-options#target-dir 8 | ;; you may want to set this to resources if you are using Leiningen 9 | ;; :target-dir "resources"{{/deps?}}{{^deps?}};; Change the target directory from the "target" to "resources" 10 | ;; https://figwheel.org/config-options#target-dir 11 | :target-dir "resources"{{/deps?}} 12 | 13 | ;; Server Ring Handler (optional) https://figwheel.org/docs/ring-handler.html 14 | ;; If you want to embed a ring handler into the figwheel server, this 15 | ;; is for simple ring servers 16 | ;; :ring-handler hello_world.server/handler 17 | 18 | ;; To be able to open files in your editor from the heads up display 19 | ;; you will need to put a script on your path. This script will have 20 | ;; to take a file path and a line number ie. 21 | ;; in ~/bin/myfile-opener: 22 | ;; 23 | ;; #! /bin/sh 24 | ;; emacsclient -n +$2:$3 $1 25 | ;; 26 | ;; :open-file-command "myfile-opener" 27 | 28 | ;; if you are using emacsclient you can just use 29 | ;; :open-file-command "emacsclient" 30 | 31 | ;; Logging output gets printed to the REPL, if you want to redirect it to a file: 32 | ;; :log-file "figwheel-main.log" 33 | } 34 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/README.md: -------------------------------------------------------------------------------- 1 | # {{name}} 2 | 3 | FIXME: Write a one-line description of your library/project. 4 | 5 | ## Overview 6 | 7 | FIXME: Write a paragraph about the library/project and highlight its goals. 8 | 9 | ## Development 10 | 11 | {{#deps?}} 12 | To get an interactive development environment run: 13 | 14 | clojure -A:fig:build 15 | 16 | This will auto compile and send all changes to the browser without the 17 | need to reload. After the compilation process is complete, you will 18 | get a Browser Connected REPL. An easy way to try it is: 19 | 20 | (js/alert "Am I connected?") 21 | 22 | and you should see an alert in the browser window. 23 | 24 | To clean all compiled files: 25 | 26 | rm -rf target/public 27 | 28 | To create a production build run: 29 | 30 | rm -rf target/public 31 | clojure -A:fig:min 32 | {{/deps?}} 33 | {{^deps?}} 34 | To get an interactive development environment run: 35 | 36 | lein fig:build 37 | 38 | This will auto compile and send all changes to the browser without the 39 | need to reload. After the compilation process is complete, you will 40 | get a Browser Connected REPL. An easy way to try it is: 41 | 42 | (js/alert "Am I connected?") 43 | 44 | and you should see an alert in the browser window. 45 | 46 | To clean all compiled files: 47 | 48 | lein clean 49 | 50 | To create a production build run: 51 | 52 | lein clean 53 | lein fig:min 54 | {{/deps?}} 55 | 56 | 57 | ## License 58 | 59 | Copyright © 2018 FIXME 60 | 61 | Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version. 62 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/project.clj: -------------------------------------------------------------------------------- 1 | (defproject {{ raw-name }} "0.1.0-SNAPSHOT" 2 | :description "FIXME: write this!" 3 | :url "http://example.com/FIXME" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | 7 | :min-lein-version "2.7.1" 8 | 9 | :dependencies [[org.clojure/clojure "1.10.0"] 10 | [org.clojure/clojurescript "1.10.773"]{{#react?}} 11 | {{^npm-bundle?}}[cljsjs/react "16.4.1-0"] 12 | [cljsjs/react-dom "16.4.1-0"]{{/npm-bundle?}} 13 | [sablono "0.8.6"]{{/react?}}{{#reagent?}} 14 | [reagent "0.10.0" {{#npm-bundle?}} :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server]{{/npm-bundle?}}]{{/reagent?}}{{#rum?}} 15 | [rum "0.12.3"]{{/rum?}}] 16 | 17 | :source-paths ["src"] 18 | 19 | :aliases {"fig" [{{^windows?}}"trampoline" {{/windows?}}"run" "-m" "figwheel.main"] 20 | "fig:build" [{{^windows?}}"trampoline" {{/windows?}}"run" "-m" "figwheel.main" "-b" "dev" "-r"] 21 | "fig:min" ["run" "-m" "figwheel.main" "-O" "advanced" "-bo" "dev"] 22 | "fig:test" ["run" "-m" "figwheel.main" "-co" "test.cljs.edn" "-m" "{{test-runner-ns}}"]} 23 | 24 | :profiles {:dev {:dependencies [[com.bhauman/figwheel-main "0.2.12"]{{^windows?}} 25 | [com.bhauman/rebel-readline-cljs "0.1.4"]{{/windows?}}] 26 | {{#deps?}}:clean-targets ^{:protect false} [:target-path "resources/public/cljs-out"]{{/deps?}} 27 | {{^deps?}}:resource-paths ["target"] 28 | ;; need to add the compiled assets to the :clean-targets 29 | :clean-targets ^{:protect false} ["target"]{{/deps?}}}}) 30 | 31 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/core.cljs: -------------------------------------------------------------------------------- 1 | (ns ^:figwheel-hooks {{namespace}} 2 | (:require 3 | [goog.dom :as gdom]{{#react?}} 4 | [react :as react] 5 | [react-dom :as react-dom] 6 | [sablono.core :as sab :include-macros true]{{/react?}}{{#reagent?}} 7 | [reagent.core :as reagent :refer [atom]] 8 | [reagent.dom :as rdom]{{/reagent?}}{{#rum?}} 9 | [rum.core :as rum]{{/rum?}})) 10 | 11 | (println "This text is printed from src/{{main-file-path}}.cljs. Go ahead and edit it and see reloading in action.") 12 | 13 | (defn multiply [a b] (* a b)) 14 | 15 | ;; define your app data so that it doesn't get over-written on reload 16 | (defonce app-state (atom {:text "Hello world!"})) 17 | 18 | (defn get-app-element [] 19 | (gdom/getElement "app")) 20 | {{#react?}} 21 | (defn hello-world [state] 22 | (sab/html [:div 23 | [:h1 (:text @state)] 24 | [:h3 "Edit this in src/{{nested-dirs}}.cljs and watch it change!"]])) 25 | 26 | (defn mount [el] 27 | (react-dom/render (hello-world app-state) el)) 28 | {{/react?}}{{#reagent?}} 29 | (defn hello-world [] 30 | [:div 31 | [:h1 (:text @app-state)] 32 | [:h3 "Edit this in src/{{nested-dirs}}.cljs and watch it change!"]]) 33 | 34 | (defn mount [el] 35 | (rdom/render [hello-world] el)) 36 | {{/reagent?}}{{#rum?}} 37 | (rum/defc hello-world [] 38 | [:div 39 | [:h1 (:text @app-state)] 40 | [:h3 "Edit this in src/{{nested-dirs}}.cljs and watch it change!"]]) 41 | 42 | (defn mount [el] 43 | (rum/mount (hello-world) el)) 44 | {{/rum?}} 45 | 46 | {{#framework?}} 47 | (defn mount-app-element [] 48 | (when-let [el (get-app-element)] 49 | (mount el))) 50 | 51 | ;; conditionally start your application based on the presence of an "app" element 52 | ;; this is particularly helpful for testing this ns without launching the app 53 | (mount-app-element){{/framework?}} 54 | 55 | ;; specify reload hook with ^;after-load metadata 56 | (defn ^:after-load on-reload []{{#framework?}} 57 | (mount-app-element){{/framework?}} 58 | ;; optionally touch your app-state to force rerendering depending on 59 | ;; your application 60 | ;; (swap! app-state update-in [:__figwheel_counter] inc) 61 | ) 62 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |
Template Generated Index.html
27 |
28 |
29 | Figwheel Main 30 | CLJS 31 | Cheatsheet 32 | Synonyms 33 |
34 |
35 | 36 |
37 | 43 |
44 |

Welcome to the template generated index.html

45 | 46 |
47 |

TLDR: you can find and edit this file at resources/public/index.html

48 |
49 | 50 |

This page is currently hosting your application code and REPL (Read 51 | Eval Print Loop). As you change your code and save it, the 52 | changed code will be hot loaded into this browser page.

53 | 54 |

If you return to the terminal where you launched figwheel and enter 55 | valid ClojureScript code at the cljs.user=> prompt, the code will be 56 | compiled to Javascript and evaluated in the JavaScript environment on 57 | this page.

58 | 59 |

If you close this page the REPL will cease to function.

60 | 61 |

Editing this index.html

62 | 63 |

When you view the content of resources/public/index.html there will 64 | be comments that show you how to remove this initial content. It is 65 | important that you keep the final <script> tag that requires your compiled 66 | ClojureScript code.

67 |
68 |
69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # figwheel.main template 2 | 3 | A template generator that will produce a minimal ClojureScript project 4 | that includes 5 | [figwheel.main](https://figwheel.org) 6 | tooling. 7 | 8 | ## Abridged Usage Examples 9 | 10 | Already an expert? Can't stand to read more information? Assuming you have [lein](https://github.com/technomancy/leiningen) or [clj-new](https://github.com/seancorfield/clj-new) installed, you can use one of the following commands: 11 | 12 | ```shell 13 | clj -X:new clj-new/create :template figwheel-main :name yourname/hello-world :args '["+npm-bundle","--reagent"]' # or --rum, --react or nothing 14 | ``` 15 | 16 | or 17 | 18 | ```shell 19 | lein new figwheel-main hello-world.core -- +npm-bundle --reagent # or --rum, --react or nothing 20 | ``` 21 | 22 | ## Overview 23 | 24 | The `figwheel-main` template is intended to get you up and running 25 | with a no-frills ClojureScript project initialized with the 26 | ClojureScript React framework of your choosing. It is intended to work 27 | equally well with 28 | [Leiningen](https://github.com/technomancy/leiningen) or 29 | [clj-new](https://github.com/seancorfield/clj-new). 30 | 31 | ## Usage 32 | 33 | #### Using clj-new 34 | 35 | Make sure you have 36 | [installed the Clojure CLI tools](https://clojure.org/guides/getting_started#_clojure_installer_and_cli_tools) 37 | and are running the latest version. 38 | 39 | Also, ensure you have installed [clj-new](https://github.com/seancorfield/clj-new) as detailed [here](https://github.com/seancorfield/clj-new#getting-started) 40 | 41 | clj -X:new create :template figwheel-main :name yourname/hello-world :args '["--reagent"]' 42 | 43 | #### Using lein 44 | 45 | Make sure you have the 46 | [latest version of Leiningen installed](https://github.com/technomancy/leiningen#installation). 47 | 48 | lein new figwheel-main hello-world.core -- --reagent 49 | 50 | ### Options 51 | 52 | Takes a **name** and possibly a single **framework** option with the 53 | form `--framework` and any number of **attribute** options of the form 54 | `+attribute` and produces a minimal ClojureScript project that 55 | includes Figwheel Main tooling 56 | 57 | The initial **name** option is intended to be the name of your initial 58 | project namespace. Here are some examples of valid project names: 59 | 60 | hello.core 61 | my.group/dominate.world 62 | 63 | The framework options are: 64 | 65 | --react which adds a minimal React/Sablono application in core.cljs 66 | --reagent which adds a minimal Reagent application in core.cljs 67 | --rum which adds a minimal Rum application in core.cljs 68 | --om which adds a minimal Om application in core.cljs 69 | 70 | The attribute options are: 71 | 72 | +npm-bundle which sets up a build that utilizes npm modules 73 | +deps which generates a deps.edn (a default when used with clj-new) 74 | +lein which generates a project.clj (a default when used with lein) 75 | +bare-index which generates an index without any annoyingly helpful content 76 | 77 | Only one **framework** option can be specified at a time. If no 78 | framework option is specified, nothing but a print statment is added 79 | to the generated ClojureScript code. 80 | 81 | Examples: 82 | 83 | lein new figwheel-main hello-world.core -- +deps +npm-bundle --react 84 | 85 | clj -X:new create :template figwheel-main :name yourname/hello-world :args '["+bare-index","+lein","--react"]' 86 | 87 | # Compiling the generated project 88 | 89 | > When using `+npm-bundle` you must run `npm install` before building your project 90 | 91 | ### With a CLI tools project 92 | 93 | To get an interactive development environment change into the project 94 | root (the directory just created) and execute: 95 | 96 | clojure -A:fig:build 97 | 98 | After the compilation process is complete, and a browser has popped 99 | open the compiled project in your browser, you will get a ClojureScript 100 | REPL prompt that is connected to the browser. 101 | 102 | An easy way to verify this is: 103 | 104 | cljs.user=> (js/alert "Am I connected?") 105 | 106 | and you should see an alert in the browser window. 107 | 108 | You can also supply arguments to `figwheel.main` like so: 109 | 110 | clojure -A:fig -b dev -r 111 | 112 | To clean all compiled files: 113 | 114 | rm -rf target/public 115 | 116 | To create a production build: 117 | 118 | rm -rf target/public 119 | clojure -A:fig:min 120 | 121 | ### With Leiningen based project 122 | 123 | To get an interactive development environment change into the project 124 | root (the directory just created) and execute: 125 | 126 | lein fig:build 127 | 128 | After the compilation process is complete, and a browser has popped 129 | open the compiled project in your browser, you will get a ClojureScript 130 | REPL prompt that is connected to the browser. 131 | 132 | An easy way to verify this is: 133 | 134 | cljs.user=> (js/alert "Am I connected?") 135 | 136 | and you should see an alert in the browser window. 137 | 138 | You can also supply arguments to `figwheel.main` like so: 139 | 140 | lein fig -- -b dev -r 141 | 142 | To clean all compiled files: 143 | 144 | lein clean 145 | 146 | To create a production build: 147 | 148 | lein clean 149 | lein fig:min 150 | 151 | # Testing 152 | 153 | Your initial tests are in the `test` directory. You will have tests 154 | that are updated live with each file change if you open a tab to 155 | `http://localhost:9500/figwheel-extra-main/auto-testing` 156 | 157 | You can run your tests from the command line with: 158 | 159 | clj -A:fig:test 160 | 161 | or with `lein`: 162 | 163 | lein fig:test 164 | 165 | ## Questions? 166 | 167 | See the [`figwheel.main` documentation](https://figwheel.org) 168 | 169 | Hit me up on the [Clojurians Slack](http://clojurians.net/) on the `#figwheel-main` channel. 170 | 171 | ## License 172 | 173 | Copyright © 2018 Bruce Hauman 174 | 175 | Distributed under the Eclipse Public License either version 1.0 or (at 176 | your option) any later version. 177 | -------------------------------------------------------------------------------- /src/leiningen/new/figwheel_main.clj: -------------------------------------------------------------------------------- 1 | (ns leiningen.new.figwheel-main 2 | (:require [leiningen.new.templates :refer [renderer project-name 3 | ->files sanitize-ns name-to-path 4 | multi-segment]] 5 | [leiningen.core.main :as main] 6 | [clojure.java.io :as io] 7 | [clojure.string :as string])) 8 | 9 | (def render (renderer "figwheel-main")) 10 | 11 | (def supported-frameworks ["reagent" "rum" "react"]) 12 | 13 | (def framework-opts (set (map #(str "--" %) supported-frameworks))) 14 | 15 | (def supported-attributes #{"lein" "bare-index" "deps" "npm-bundle"}) 16 | 17 | (def attribute-opts (set (map #(str "+" %) supported-attributes))) 18 | 19 | ;; I copy this levenshtein impl everywhere 20 | (defn- next-row 21 | [previous current other-seq] 22 | (reduce 23 | (fn [row [diagonal above other]] 24 | (let [update-val (if (= other current) 25 | diagonal 26 | (inc (min diagonal above (peek row))))] 27 | (conj row update-val))) 28 | [(inc (first previous))] 29 | (map vector previous (next previous) other-seq))) 30 | 31 | (defn- levenshtein 32 | [sequence1 sequence2] 33 | (peek 34 | (reduce (fn [previous current] (next-row previous current sequence2)) 35 | (map #(identity %2) (cons nil sequence2) (range)) 36 | sequence1))) 37 | 38 | (defn- similar [ky ky2] 39 | (let [dist (levenshtein (str ky) (str ky2))] 40 | (when (<= dist 2) dist))) 41 | 42 | (defn similar-options [opt] 43 | (second (first (sort-by first 44 | (filter first (map (juxt (partial similar opt) identity) 45 | (concat framework-opts attribute-opts))))))) 46 | 47 | (defn parse-opts [opts] 48 | (reduce (fn [accum opt] 49 | (cond 50 | (framework-opts opt) (assoc accum :framework (keyword (subs opt 2))) 51 | (attribute-opts opt) (update accum :attributes 52 | (fnil conj #{}) 53 | (keyword (subs opt 1))) 54 | :else 55 | (let [suggestion (similar-options opt)] 56 | (throw 57 | (ex-info (format "Unknown option '%s' %s" 58 | opt 59 | (str 60 | (when suggestion 61 | (format "\n --> Perhaps you intended to use the '%s' option?" suggestion)))) 62 | {:opts opts 63 | ::error true}))))) 64 | {} opts)) 65 | 66 | (defn in-clj? [] 67 | (resolve 'clj-new.helpers/create)) 68 | 69 | (defn test-runner-ns [main-ns] 70 | (string/join "." [(first (string/split main-ns #"\.")) "test-runner"])) 71 | 72 | (defn windows? [] 73 | (.contains (string/lower-case (System/getProperty "os.name")) "windows")) 74 | 75 | (defn opts-data [n {:keys [framework attributes]}] 76 | (let [to-att #(keyword (str (name %) "?")) 77 | main-ns (multi-segment (sanitize-ns n)) 78 | test-run-ns (test-runner-ns main-ns) 79 | inclj (in-clj?) 80 | data (cond-> {:raw-name n 81 | :name (project-name n) 82 | :namespace main-ns 83 | :test-runner-ns test-run-ns 84 | :test-runner-dirs (name-to-path test-run-ns) 85 | :lein? (not inclj) 86 | :deps? (boolean inclj) 87 | :windows? (windows?) 88 | :main-file-path (-> (name-to-path main-ns) 89 | (string/replace "\\" "/")) 90 | :nested-dirs (name-to-path main-ns)} 91 | framework 92 | (-> 93 | (assoc (to-att :framework) true) 94 | (assoc (to-att framework) true)) 95 | (not-empty attributes) (#(reduce 96 | (fn [accum att] 97 | (assoc accum (to-att att) true)) 98 | % attributes)))] 99 | (cond-> data 100 | (and (or (:react? data) 101 | (:reagent? data)) 102 | (:npm-bundle? data)) 103 | (assoc :reactdep? true)))) 104 | 105 | (defn figwheel-main 106 | "Takes a name and possibly a single framework option with the form 107 | --framework and any number of attribute options of the form 108 | +attribute and produces a minimal ClojureScript project that 109 | includes Figwheel Main tooling 110 | 111 | The framework options are: 112 | --react which adds a minimal React/Sablono application in core.cljs 113 | --reagent which adds a minimal Reagent application in core.cljs 114 | --rum which adds a minimal Rum application in core.cljs 115 | --om which adds a minimal Om application in core.cljs 116 | 117 | The attribute options are: 118 | +deps which generates a deps.edn (a default when used with clj-new) 119 | +lein which generates a project.clj (a default when used with lein) 120 | +bare-index which generates an index without any annoyingly helpful content 121 | 122 | Only one **framework** option can be` specified at a time. If no 123 | framework option is specified, nothing but a print statment is added 124 | to the generated ClojureScript code." 125 | [name & opts] 126 | (do 127 | (when (#{"figwheel" "cljs"} name) 128 | (main/abort 129 | (format 130 | (str "Cannot name a figwheel project %s the namespace will clash.\n" 131 | "Please choose a different name, maybe \"tryfig\"?") 132 | (pr-str name)))) 133 | (try 134 | (let [parsed-opts (parse-opts opts) 135 | data (opts-data name parsed-opts) 136 | base-files [["README.md" (render "README.md" data)] 137 | ["figwheel-main.edn" (render "figwheel-main.edn" data)] 138 | ["dev.cljs.edn" (render "dev.cljs.edn" data)] 139 | ["test.cljs.edn" (render "test.cljs.edn" data)] 140 | ["src/{{nested-dirs}}.cljs" (render "core.cljs" data)] 141 | ["resources/public/css/style.css" (render "style.css" data)] 142 | ["resources/public/test.html" (render "test-page.html" data)] 143 | [".gitignore" (render "gitignore" data)] 144 | ["test/{{nested-dirs}}_test.cljs" (render "test.cljs" data)] 145 | ["test/{{test-runner-dirs}}.cljs" (render "test-runner.cljs" data)] 146 | ["test/{{test-runner-dirs}}.cljs" (render "test-runner.cljs" data)] 147 | ] 148 | files (cond-> base-files 149 | (:lein? data) 150 | (conj ["project.clj" (render "project.clj" data)]) 151 | (:deps? data) 152 | (conj ["deps.edn" (render "deps.edn" data)]) 153 | (:npm-bundle? data) 154 | (conj ["package.json" (render "package.json" data)]) 155 | (and (not (:bare-index? data)) 156 | (not (:framework? data))) 157 | (conj ["resources/public/index.html" (render "index.html" data)]) 158 | (or (:bare-index? data) 159 | (:framework? data)) 160 | (conj ["resources/public/index.html" (render "bare-index.html" data)]))] 161 | (main/info (format (str "Generating fresh figwheel-main project.\n" 162 | " To get started:\n" 163 | " --> Change into the '%s' directory\n" 164 | (if (:npm-bundle? data) 165 | " --> IMPORTANT: run 'npm install'\n") 166 | " --> Start build with '%s'\n") 167 | (:name data) 168 | (if (:deps? data) 169 | "clojure -M:fig:build" 170 | "lein fig:build"))) 171 | (apply ->files data files) 172 | ;; ensure target directory 173 | (.mkdirs (io/file (:name data) "target" "public"))) 174 | (catch clojure.lang.ExceptionInfo t 175 | (if (-> t ex-data ::error) 176 | (main/warn (.getMessage t)) 177 | (throw t)))))) 178 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 4 | 5 | 1. DEFINITIONS 6 | 7 | "Contribution" means: 8 | 9 | a) in the case of the initial Contributor, the initial code and 10 | documentation distributed under this Agreement, and 11 | 12 | b) in the case of each subsequent Contributor: 13 | 14 | i) changes to the Program, and 15 | 16 | ii) additions to the Program; 17 | 18 | where such changes and/or additions to the Program originate from and are 19 | distributed by that particular Contributor. A Contribution 'originates' from 20 | a Contributor if it was added to the Program by such Contributor itself or 21 | anyone acting on such Contributor's behalf. Contributions do not include 22 | additions to the Program which: (i) are separate modules of software 23 | distributed in conjunction with the Program under their own license 24 | agreement, and (ii) are not derivative works of the Program. 25 | 26 | "Contributor" means any person or entity that distributes the Program. 27 | 28 | "Licensed Patents" mean patent claims licensable by a Contributor which are 29 | necessarily infringed by the use or sale of its Contribution alone or when 30 | combined with the Program. 31 | 32 | "Program" means the Contributions distributed in accordance with this 33 | Agreement. 34 | 35 | "Recipient" means anyone who receives the Program under this Agreement, 36 | including all Contributors. 37 | 38 | 2. GRANT OF RIGHTS 39 | 40 | a) Subject to the terms of this Agreement, each Contributor hereby grants 41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 42 | reproduce, prepare derivative works of, publicly display, publicly perform, 43 | distribute and sublicense the Contribution of such Contributor, if any, and 44 | such derivative works, in source code and object code form. 45 | 46 | b) Subject to the terms of this Agreement, each Contributor hereby grants 47 | Recipient a non-exclusive, worldwide, royalty-free patent license under 48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 49 | transfer the Contribution of such Contributor, if any, in source code and 50 | object code form. This patent license shall apply to the combination of the 51 | Contribution and the Program if, at the time the Contribution is added by the 52 | Contributor, such addition of the Contribution causes such combination to be 53 | covered by the Licensed Patents. The patent license shall not apply to any 54 | other combinations which include the Contribution. No hardware per se is 55 | licensed hereunder. 56 | 57 | c) Recipient understands that although each Contributor grants the licenses 58 | to its Contributions set forth herein, no assurances are provided by any 59 | Contributor that the Program does not infringe the patent or other 60 | intellectual property rights of any other entity. Each Contributor disclaims 61 | any liability to Recipient for claims brought by any other entity based on 62 | infringement of intellectual property rights or otherwise. As a condition to 63 | exercising the rights and licenses granted hereunder, each Recipient hereby 64 | assumes sole responsibility to secure any other intellectual property rights 65 | needed, if any. For example, if a third party patent license is required to 66 | allow Recipient to distribute the Program, it is Recipient's responsibility 67 | to acquire that license before distributing the Program. 68 | 69 | d) Each Contributor represents that to its knowledge it has sufficient 70 | copyright rights in its Contribution, if any, to grant the copyright license 71 | set forth in this Agreement. 72 | 73 | 3. REQUIREMENTS 74 | 75 | A Contributor may choose to distribute the Program in object code form under 76 | its own license agreement, provided that: 77 | 78 | a) it complies with the terms and conditions of this Agreement; and 79 | 80 | b) its license agreement: 81 | 82 | i) effectively disclaims on behalf of all Contributors all warranties and 83 | conditions, express and implied, including warranties or conditions of title 84 | and non-infringement, and implied warranties or conditions of merchantability 85 | and fitness for a particular purpose; 86 | 87 | ii) effectively excludes on behalf of all Contributors all liability for 88 | damages, including direct, indirect, special, incidental and consequential 89 | damages, such as lost profits; 90 | 91 | iii) states that any provisions which differ from this Agreement are offered 92 | by that Contributor alone and not by any other party; and 93 | 94 | iv) states that source code for the Program is available from such 95 | Contributor, and informs licensees how to obtain it in a reasonable manner on 96 | or through a medium customarily used for software exchange. 97 | 98 | When the Program is made available in source code form: 99 | 100 | a) it must be made available under this Agreement; and 101 | 102 | b) a copy of this Agreement must be included with each copy of the Program. 103 | 104 | Contributors may not remove or alter any copyright notices contained within 105 | the Program. 106 | 107 | Each Contributor must identify itself as the originator of its Contribution, 108 | if any, in a manner that reasonably allows subsequent Recipients to identify 109 | the originator of the Contribution. 110 | 111 | 4. COMMERCIAL DISTRIBUTION 112 | 113 | Commercial distributors of software may accept certain responsibilities with 114 | respect to end users, business partners and the like. While this license is 115 | intended to facilitate the commercial use of the Program, the Contributor who 116 | includes the Program in a commercial product offering should do so in a 117 | manner which does not create potential liability for other Contributors. 118 | Therefore, if a Contributor includes the Program in a commercial product 119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend 120 | and indemnify every other Contributor ("Indemnified Contributor") against any 121 | losses, damages and costs (collectively "Losses") arising from claims, 122 | lawsuits and other legal actions brought by a third party against the 123 | Indemnified Contributor to the extent caused by the acts or omissions of such 124 | Commercial Contributor in connection with its distribution of the Program in 125 | a commercial product offering. The obligations in this section do not apply 126 | to any claims or Losses relating to any actual or alleged intellectual 127 | property infringement. In order to qualify, an Indemnified Contributor must: 128 | a) promptly notify the Commercial Contributor in writing of such claim, and 129 | b) allow the Commercial Contributor tocontrol, and cooperate with the 130 | Commercial Contributor in, the defense and any related settlement 131 | negotiations. The Indemnified Contributor may participate in any such claim 132 | at its own expense. 133 | 134 | For example, a Contributor might include the Program in a commercial product 135 | offering, Product X. That Contributor is then a Commercial Contributor. If 136 | that Commercial Contributor then makes performance claims, or offers 137 | warranties related to Product X, those performance claims and warranties are 138 | such Commercial Contributor's responsibility alone. Under this section, the 139 | Commercial Contributor would have to defend claims against the other 140 | Contributors related to those performance claims and warranties, and if a 141 | court requires any other Contributor to pay any damages as a result, the 142 | Commercial Contributor must pay those damages. 143 | 144 | 5. NO WARRANTY 145 | 146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON 147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER 148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR 149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A 150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the 151 | appropriateness of using and distributing the Program and assumes all risks 152 | associated with its exercise of rights under this Agreement , including but 153 | not limited to the risks and costs of program errors, compliance with 154 | applicable laws, damage to or loss of data, programs or equipment, and 155 | unavailability or interruption of operations. 156 | 157 | 6. DISCLAIMER OF LIABILITY 158 | 159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION 162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY 166 | OF SUCH DAMAGES. 167 | 168 | 7. GENERAL 169 | 170 | If any provision of this Agreement is invalid or unenforceable under 171 | applicable law, it shall not affect the validity or enforceability of the 172 | remainder of the terms of this Agreement, and without further action by the 173 | parties hereto, such provision shall be reformed to the minimum extent 174 | necessary to make such provision valid and enforceable. 175 | 176 | If Recipient institutes patent litigation against any entity (including a 177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself 178 | (excluding combinations of the Program with other software or hardware) 179 | infringes such Recipient's patent(s), then such Recipient's rights granted 180 | under Section 2(b) shall terminate as of the date such litigation is filed. 181 | 182 | All Recipient's rights under this Agreement shall terminate if it fails to 183 | comply with any of the material terms or conditions of this Agreement and 184 | does not cure such failure in a reasonable period of time after becoming 185 | aware of such noncompliance. If all Recipient's rights under this Agreement 186 | terminate, Recipient agrees to cease use and distribution of the Program as 187 | soon as reasonably practicable. However, Recipient's obligations under this 188 | Agreement and any licenses granted by Recipient relating to the Program shall 189 | continue and survive. 190 | 191 | Everyone is permitted to copy and distribute copies of this Agreement, but in 192 | order to avoid inconsistency the Agreement is copyrighted and may only be 193 | modified in the following manner. The Agreement Steward reserves the right to 194 | publish new versions (including revisions) of this Agreement from time to 195 | time. No one other than the Agreement Steward has the right to modify this 196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The 197 | Eclipse Foundation may assign the responsibility to serve as the Agreement 198 | Steward to a suitable separate entity. Each new version of the Agreement will 199 | be given a distinguishing version number. The Program (including 200 | Contributions) may always be distributed subject to the version of the 201 | Agreement under which it was received. In addition, after a new version of 202 | the Agreement is published, Contributor may elect to distribute the Program 203 | (including its Contributions) under the new version. Except as expressly 204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or 205 | licenses to the intellectual property of any Contributor under this 206 | Agreement, whether expressly, by implication, estoppel or otherwise. All 207 | rights in the Program not expressly granted under this Agreement are 208 | reserved. 209 | 210 | This Agreement is governed by the laws of the State of Washington and the 211 | intellectual property laws of the United States of America. No party to this 212 | Agreement will bring a legal action under this Agreement more than one year 213 | after the cause of action arose. Each party waives its rights to a jury trial 214 | in any resulting litigation. 215 | --------------------------------------------------------------------------------