-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'create/sitefox-nbb/' from commit '07e61ee42f64979767c6dc68b6ff68…
…1fddfc3fc8' git-subtree-dir: create/sitefox-nbb git-subtree-mainline: 38aa41f git-subtree-split: 07e61ee
- Loading branch information
Showing
11 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.*.swp | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Set up a ClojureScript web server in one command using | ||
[sitefox](https://github.com/chr15m/sitefox) | ||
and [nbb](https://github.com/borkdude/nbb). | ||
|
||
```shell | ||
npm create sitefox-nbb mywebsite | ||
cd mywebsite | ||
npm run serve | ||
``` | ||
|
||
Then open `server.cljs` in your editor and start hacking. | ||
When `server.cljs` is modified the server will automatically reload routes. 👍 | ||
|
||
To serve the live version without file watcher reloading: | ||
|
||
``` | ||
npm run serve-live | ||
``` | ||
|
||
See the [sitefox documentation](https://github.com/chr15m/sitefox#batteries-included) for details on what you can do next. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env node | ||
|
||
const args = process.argv.slice(2); | ||
const execSync = require('child_process').execSync; | ||
const fs = require('fs-extra'); | ||
const replace = require('replace-in-file'); | ||
|
||
const name = args[0]; | ||
const dir = name && args[0].replace(/-/g, '_'); | ||
|
||
if (name) { | ||
console.log("Creating", name); | ||
fs.copySync(__dirname + "/template", name); | ||
fs.moveSync(name + "/gitignore", name + "/.gitignore"); | ||
replace.sync({ | ||
"files": [ | ||
args[0] + "/**/**", | ||
], | ||
"from": "NAME", | ||
"to": name, | ||
"countMatches": true, | ||
}); | ||
console.log("Running npm install"); | ||
execSync("npm install", {"cwd": name, "stdio": ["inherit", "inherit", "inherit"]}); | ||
console.log("\nOk, you are ready to roll:\n$ cd " + name + "\n$ npm run serve\n\nThen edit server.cljs\n"); | ||
} else { | ||
console.log("Usage: " + process.argv[1] + " APP-NAME"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "create-sitefox-nbb", | ||
"description": "Set up a ClojureScript web server in one command with sitefox and nbb.", | ||
"repository": "https://github.com/chr15m/create-sitefox-nbb", | ||
"version": "0.0.7", | ||
"bin": { | ||
"create-sitefox-nbb": "index.js" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^9.0.1", | ||
"replace-in-file": "^6.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{:lint-as {promesa.core/let clojure.core/let}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{;; this deps.edn enables clojure-lsp features | ||
:paths ["."] | ||
:deps | ||
{io.github.chr15m/sitefox {:git/tag "v0.0.1" :git/sha "b5520678b9fbf5919878a75750bb4d792c9eb8e2"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.*.swp | ||
logs | ||
database.sqlite | ||
.clj-kondo/.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "NAME", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"nbb": "0.3.9", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"sitefox": "chr15m/sitefox" | ||
}, | ||
"devDependencies": { | ||
"browser-sync": "^2.27.7", | ||
"fast-glob": "^3.2.11", | ||
"filewatcher": "^3.0.1" | ||
}, | ||
"scripts": { | ||
"serve": "DEV=1 nbb --classpath ${VIRTUAL_ENV:=.}/node_modules/sitefox/src/ server.cljs", | ||
"serve-live": "nbb --classpath ${VIRTUAL_ENV:=.}/node_modules/sitefox/src/ server.cljs", | ||
"repl": "DEV=1 nbb --classpath ${VIRTUAL_ENV:=.}/node_modules/sitefox/src/ nrepl-server :port 1338" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Sitefox HTML template merge example</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" type="text/css" href="/style.css" > | ||
</head> | ||
<body> | ||
<main> | ||
<p><div class="spinner spin"></div></p> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
html, body, #app, #loading { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
max-width: 100%; | ||
width: 800px; | ||
font-family: Helvetica, Arial, sans-serif; | ||
margin: auto; | ||
} | ||
|
||
#loading { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
#loading div { | ||
animation: spin 0.33s linear infinite; | ||
width: 48px; | ||
height: 48px; | ||
border-radius: 24px; | ||
border: 3px solid transparent; | ||
border-left: 3px solid silver; | ||
border-right: 3px solid silver; | ||
} | ||
|
||
@keyframes spin { | ||
0% { transform: rotate(0deg); } | ||
100% { transform: rotate(360deg); } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(ns webserver | ||
(:require | ||
["fs" :as fs] | ||
[promesa.core :as p] | ||
[nbb.core :refer [*file*]] | ||
["browser-sync" :as browser-sync] | ||
["fast-glob$default" :as fg] | ||
[sitefox.web :as web] | ||
[sitefox.util :refer [env]] | ||
[sitefox.html :refer [render-into]] | ||
[sitefox.reloader :refer [nbb-reloader]] | ||
[sitefox.tracebacks :refer [install-traceback-emailer]])) | ||
|
||
(when-let [admin-email (env "ADMIN_EMAIL")] | ||
(install-traceback-emailer admin-email)) | ||
|
||
(def template (fs/readFileSync "public/index.html")) | ||
|
||
(defn component-main [] | ||
[:div | ||
[:h1 "Your Sitefox site"] | ||
[:p "Welcome to your new sitefox site. | ||
The code for this site is in " [:code "server.cljs"] "."] | ||
[:p "Check out " | ||
[:a {:href "https://github.com/chr15m/sitefox#batteries-included"} "the documentation"] | ||
" to start building."]]) | ||
|
||
(defn setup-routes [app] | ||
(web/reset-routes app) | ||
(.get app "/" | ||
(fn [_req res] | ||
(->> (render-into template "main" [component-main]) | ||
(.send res)))) | ||
(web/static-folder app "/" "public")) | ||
|
||
(defonce init | ||
(p/let [self *file* | ||
[app host port] (web/start) | ||
sync-options {:files ["public/**/**"] | ||
:proxy (str host ":" port)} | ||
watch-files (fg #js [self "src/**/*.cljs" "public/*"]) | ||
bs (when (env "DEV") (browser-sync/init nil (clj->js sync-options)))] | ||
(setup-routes app) | ||
(nbb-reloader watch-files (fn [] | ||
(setup-routes app) | ||
(when bs (.reload bs)))) | ||
(print "Serving at" (str host ":" port)))) |