GithubHelp home page GithubHelp logo

omnyway-labs / re-frame-template Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 3.0 399 KB

Tools.deps clj-new style clj-template for creating re-frame projects with shadow-cljs

License: Other

Clojure 91.46% Emacs Lisp 0.46% JavaScript 3.91% HTML 4.17%

re-frame-template's Introduction

re-frame-template

Clojars Project

A Clojure tools.deps template for quickly creating a re-frame application scaffold (client only). It only takes you 60 seconds to create your first re-frame app and to start editting it.

Provides a way to pick and choose what "extras" are included into your application. Extras like libraries which do routing, debugging and CSS.

This is a translation of the Leiningen based template from day8 to use the seancorfield/clj-new template mechanism for tools.deps style builds. It does not have all the options the original had as I did not know how to use them or translate them to deps.edn style.

The following are not included:

  • garden
  • less
  • route (secretary)
  • handler (compojure)

Pull Requests welcome!

Will be adding reitit

Basic Usage

The base template includes:

Set up an alias for clj-new

    {:aliases
     {:new {:extra-deps {seancorfield/clj-new
                         {:mvn/version "1.0.199"}}
            :main-opts ["-m" "clj-new.create"]}}
     ...}

Using from Clojars

The easiest way is to use clj-new and this template from Clojars. To create an application with just the base template, use this commandline:

clj -A:new re-frame-template <myname/project-name>

where you might, for example, substitute my-github-name/my-killer-app for the <myname/project-name> bit or, perhaps, my-github-name/an-early-masterpiece.

By default this will try to write the output to the path myname/project-name. If you want it to just go to project-name or some other arbitrary name you can append at the end -o project-name or whatever name you want.

Troubleshooting note: for <project-name> don't use cljs. That name will confuse the compiler (long story) and you will later see errors like cljs.core.init is not a function.

From a local clone of the template repo

Clone this repo locally and then you can use it this way:

clj -A:new  <path-to-re-frame-template repo>::re-frame-template <myname/project-name>

Extras

The optional extras (aka profiles) include:

To add a profile to the base template, just append its name (let's use +re-com as an example):

clj -A:new  <path-to-re-frame-template repo>::re-frame-template <myname/project-name> +re-com

Any combination of profiles can be added at once:

clj -A:new  <path-to-re-frame-template repo>::re-frame-template <myname/project-name> +re-com +test +10x

Note: to assist debugging, you'll want to include either +10x or +re-frisk

Start Cider from Emacs (if using +cider):

Refer to the shadow-cljs Emacs / CIDER documentation.

The mentioned dir-local.el file is created by this template.

Run application:

Retrieve dependencies (can take a while the first time):

yarn install  # or npm install

Then run:

shadow-cljs -A dev watch app

Wait a bit, perhaps 20 seconds, keeping an eye out for a sign the compile has finished, then browse to http://localhost:8280.

To see other available shadow-cljs commands run:

shadow-cljs --help

Setting Up Your Browser

So, you now have the application running.

Before you start developing, you should tweak two settings within your browser's devtools. These are one-time actions (for each browser and laptop you use). I'll assume Chrome for the purposes of further explanation:

  1. Open devtools. Press press F12 or Ctrl-Shift-i (actually there's a variety of ways)
  2. Open devtool's "Setting" Panel. Press F1. (Careful. Not the Setting panel for Chrome itself!! The Settings panel for devtools)
  3. Under the "Network" heading, tick the option "Disable cache (while DevTools is open)". You don't want shadow-clj's attempts at reloading to be defeated by caching.
  4. Under the "Console" heading, tick the option "Enable custom formatters". This allows cljs-devtools to perform its magic.
  5. Close Settings. Close Devtools.
  6. Reopen Devtools

settings

Open 10x Panel (if using +10x):

To use re-frame-10x for debugging your app:

  1. click on the application, minimal through it is, to give it "input focus" (you want to be sure that any key presses are going to your new app)
  2. press Ctrl-H and you should see the re-frame-10x panel appear on the right side of the window

Sometimes achieving Step 1 on a really simple app - one without widgets - can be fiddly, because the browser itself hogs "input focus" and grabs all the keystrokes (like Ctrl-H) which don't then make it through to your app. You may need to be determined and creative with Step 1. I have every confidence in you.

Hot Reloading Is Now Go

If you now edit files, like perhaps /src/cljs/<project-name>/views.cljs, shadow-clj will automatically recompile your changes and "hot load" them into your running app, without your app needing to be re-started. The resulting fast, iterative workflow tends to make you very productive, and is cherished by those lucky enough to experience it.

debug?:

In project-name.config, there is a variable called debug?, which defaults to true in the dev build, and false in the prod build.

If, for example, you wrap your printlns with a when block as shown below, then you will get logs printed to the browser's console for the dev build and not the prod build.

(when config/debug?
  (println "dev mode"))

Run tests (if using +test):

Install karma and headless chrome

npm install -g karma-cli

And then run your tests

shadow-cljs -A prod compile karma-test
karma start --single-run --reporters junit,dots

Production Build

To compile clojurescript to javascript:

shadow-cljs -A prod release app

Other Templates

Backend Options

More re-frame

Looking for more re-frame inspiration, templates or example applications? See the external resources docs page.

Building the template repo itself

Build a deployable jar of this template:

$ clojure -A:jar

Install it locally:

$ clojure -A:install

Deploy it to Clojars -- needs CLOJARS_USERNAME and CLOJARS_PASSWORD environment variables:

$ clojure -A:deploy

Contributing

Contributions are welcomed! To add a new profile, this is what I'd recommend:

  1. Add a file with the name of the profile here
  2. Look at the existing options in that folder for inspiration for what to include in that file
  3. Update project.clj with the profile
  4. Add any new files here and use the {{ var-name }} syntax as needed
  5. Update the README that will result when the template is used, as well as the top-level README for re-frame-template itself
  6. In a terminal, at the root of re-frame-template, run clj -A:install
  7. Locally test that your profile works, clj -A:new <path-to-re-frame-template repo>::re-frame-template <myname/project-name> +<profile-name>

License

The MIT License (MIT)

clj-new implementation by: Copyright (c) 2020 Robert Berger

Based on the original lein template version by: day8:

The MIT License (MIT)

Copyright © 2015 Matthew Jaoudi
Copyright © 2015 Dylan Paris
Copyright © 2015 Michael Thompson
Copyright © 2015 Markku Rontu
Copyright © 2016 Daniel Compton
Copyright © 2019 Isaac Johnston

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.

re-frame-template's People

Contributors

rberger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

re-frame-template's Issues

No longer works with JDK 15+

I wanted to use this to learn Clojure and Re-Frame but the instructions in the README fail due to an issue with shadow-cljs and JDK 17 -- the version recommended by https://clojure.org/guides/install_clojure#java -- with the following error:

[:failed-to-compare "^16.13.0" "16.9.0" #error {
 :cause "Cannot invoke \"Object.getClass()\" because \"target\" is null"
 :via
 [{:type java.lang.NullPointerException
   :message "Cannot invoke \"Object.getClass()\" because \"target\" is null"
   :at [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]}]

I made a fix for this in #1 and tested using a clean Docker container running Ubuntu. Happy to discuss and make any requested changes!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.