ccclock — cord cutters clock — is a clock for "cord cutters" who miss the always correct clock on their cable tv box. Weather data is sourced from the everaging the OpenWeather API, and written in ClojureScript using: re-frame.
The current version is now powered by openweather.org and requires a free account and api key.
- Architecture: Single Page Application (SPA)
- Languages
- Front end is ClojureScript with (re-frame)
- CSS compilation is Garden with Spade
- Dependencies
- Build tools
- CLJS compilation, dependency management, REPL, & hot reload:
shadow-cljs
- Test framework: cljs.test
- Test runner: Karma
- CLJS compilation, dependency management, REPL, & hot reload:
- Development tools
- Debugging: CLJS DevTools,
re-frame-10x
, - Emacs integration: CIDER
- Linter: clj-kondo
- Debugging: CLJS DevTools,
/
: project config files.clj-kondo/
: lint config and cache files (cache files are not tracked; see.gitignore
)dev/
: source files compiled only with the dev profileuser.cljs
: symbols for use during development in the ClojureScript REPL
resources/public/
: SPA root directory; dev / prod profile depends on the most recent buildindex.html
: SPA home page- Dynamic SPA content rendered in the following
div
:<div id="app"></div>
- Customizable; add headers, footers, links to other scripts and styles, etc.
- Dynamic SPA content rendered in the following
- Generated directories and files
- Created on build with either the dev or prod profile
js/compiled/
: compiled CLJS (shadow-cljs
)- Not tracked in source control; see
.gitignore
- Not tracked in source control; see
src/ccclock/styles.cljs
: CSS compilation source file (ClojureScript, Garden)src/ccclock/
: SPA source files (ClojureScript, re-frame)core.cljs
: contains the SPA entry point,init
test/ccclock/
: test files (ClojureScript, cljs.test)- Only namespaces ending in
-test
(files*_test.cljs
) are compiled and sent to the test runner
- Only namespaces ending in
.github/workflows/
: contains the github actions pipelines.test.yaml
: Pipeline for testing.
Use your preferred editor or IDE that supports Clojure/ClojureScript development. See Clojure tools for some popular options.
- Install JDK 8 or later (Java Development Kit)
- Install Node.js (JavaScript runtime environment) which should include NPM or if your Node.js installation does not include NPM also install it.
- Install Chrome or
Chromium version 59 or later
(headless test environment)
- For Chromium, set the
CHROME_BIN
environment variable in your shell to the command that launches Chromium. For example, in Ubuntu, add the following line to your.bashrc
:export CHROME_BIN=chromium-browser
- For Chromium, set the
- Install clj-kondo (linter)
- Clone this repo and open a terminal in the
ccclock
project root directory - (Optional) Setup lint cache:
clj-kondo --lint "$(npx shadow-cljs classpath)"
- Setup linting in your editor
Browser caching should be disabled when developer tools are open to prevent interference with
shadow-cljs
hot reloading.
Custom formatters must be enabled in the browser before CLJS DevTools can display ClojureScript data in the console in a more readable way.
- Open DevTools (Linux/Windows:
F12
orCtrl-Shift-I
; macOS:⌘-Option-I
) - Open DevTools Settings (Linux/Windows:
?
orF1
; macOS:?
orFn+F1
) - Select
Preferences
in the navigation menu on the left, if it is not already selected - Under the
Network
heading, enable theDisable cache (while DevTools is open)
option - Under the
Console
heading, enable theEnable custom formatters
option
- Open Developer Tools (Linux/Windows:
F12
orCtrl-Shift-I
; macOS:⌘-Option-I
) - Open Developer Tools Settings
(Linux/macOS/Windows:
F1
) - Under the
Advanced settings
heading, enable theDisable HTTP Cache (when toolbox is open)
option
Unfortunately, Firefox does not yet support custom formatters in their devtools. For updates, follow the enhancement request in their bug tracker: 1262914 - Add support for Custom Formatters in devtools.
cp config-dev-example.edn config-dev.edn
Edit the config values as necessary in the config-dev.edn
; you will need a OpenWeather API key.
Then start the api with the command below. See the following Emacs section to run the API live with hot-reloading of changes.
clj -M:run
Connect to the browser REPL:
M-x cider-jack-in
Evaluate restart-server
to run the API in the REPL instead of runnning it via the commandline; re-evaluate this function to hot-reload any changes during development.
Start a temporary local web server, build the app with the dev
profile, and serve the app,
browser test runner and karma test runner with hot reload:
npm install
npx shadow-cljs watch app
Please be patient; it may take over 20 seconds to see any output, and over 40 seconds to complete.
When [:app] Build completed
appears in the output, browse to
http://localhost:8280/.
shadow-cljs
will automatically push ClojureScript code
changes to your browser on save. To prevent a few common issues, see
Hot Reload in ClojureScript: Things to avoid.
Opening the app in your browser starts a ClojureScript browser REPL, to which you may now connect.
Connect to the browser REPL:
M-x cider-jack-in-cljs
See
Shadow CLJS User's Guide: Emacs/CIDER
for more information. Note that the mentioned .dir-locals.el
file has already
been created for you.
See the re-frame-template README for Calva instuctions. See also https://calva.io for Calva documentation.
See
Shadow CLJS User's Guide: Editor Integration.
Note that npm run watch
runs npx shadow-cljs watch
for you, and that this project's running build ids is
app
, browser-test
, karma-test
, or the keywords :app
, :browser-test
, :karma-test
in a Clojure context.
Alternatively, search the web for info on connecting to a shadow-cljs
ClojureScript browser REPL
from your editor and configuration.
For example, in Vim / Neovim with fireplace.vim
- Open a
.cljs
file in the project to activatefireplace.vim
- In normal mode, execute the
Piggieback
command with this project's running build id,:app
::Piggieback :app
-
Connect to the
shadow-cljs
nREPL:lein repl :connect localhost:8777
The REPL prompt,
shadow.user=>
, indicates that is a Clojure REPL, not ClojureScript. -
In the REPL, switch the session to this project's running build id,
:app
:(shadow.cljs.devtools.api/nrepl-select :app)
The REPL prompt changes to
cljs.user=>
, indicating that this is now a ClojureScript REPL. -
See
user.cljs
for symbols that are immediately accessible in the REPL without needing torequire
.
Build the app with the prod
profile, start a temporary local web server, launch headless
Chrome/Chromium, run tests, and stop the web server:
npm install
npm run ci
Please be patient; it may take over 15 seconds to see any output, and over 25 seconds to complete.
Or, for auto-reload:
npm install
npm run watch
Then in another terminal:
karma start
See a list of shadow-cljs CLI
actions:
npx shadow-cljs --help
Please be patient; it may take over 10 seconds to see any output. Also note that some actions shown may not actually be supported, outputting "Unknown action." when run.
Run a shadow-cljs action on this project's build id (without the colon, just app
):
npx shadow-cljs <action> app
The debug?
variable in config.cljs
defaults to true
in
dev
builds, and false
in prod
builds.
Use debug?
for logging or other tasks that should run only on dev
builds:
(ns ccclock.example
(:require [ccclock.config :as config])
(when config/debug?
(println "This message will appear in the browser console only on dev builds."))
Run clj -M:ancient
to get a full report of both Clojure and ClojureScript dependencies.
Build the app with the prod
profile:
./build-prod.sh
This script runs the following, which produces a jar file that runs the backend and serves up the frontend.
npm install && npm run release
CCCLOCK_ENV=prod clj -T:build uberjar
Set OPENWEATHER_API_KEY=<your api key>
in your production environment, and run the jar.
To run it manually in prod run the following.
OPENWEATHER_API_KEY=<your api key> java -jar target/ccclock-standalone.jar
To deploy to a raspberry pi, I recommend the following:
- have rc.local launch your production jar
- set to boot to desktop and launch chromium in kiosk mode launching http://localhost:8000/index.html
Your browser may sit with a "cannot load page" or other such error for a couple minutes if it opens before the jvm launches your jar.