-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-project
executable file
·85 lines (66 loc) · 1.89 KB
/
new-project
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -e
NAME="example"
if [ ! -z $1 ]; then
NAME="$1"
fi
DEPSEDN=$(cat <<EOF
{:deps {org.clojure/clojure {:mvn/version "1.10.3"}
ring/ring-core {:mvn/version "1.8.2"}
ring/ring-jetty-adapter {:mvn/version "1.8.2"}
com.bhauman/figwheel-main {:mvn/version "0.2.12"}
reagent/reagent {:mvn/version "1.0.0"}}
;; setup some development paths
:paths ["src/clj" "src/cljc" "src/cljs" "target" "resources"]
;; setup a helpful alias to start the build
:aliases {:dev {:extra-deps {nrepl/nrepl {:mvn/version "0.8.2"}
cider/piggieback {:mvn/version "0.5.2"}
clj-kondo/clj-kondo {:mvn/version "2021.04.23"}}
:extra-paths ["dev"]}
:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.0.829"}}
:extra-paths ["test/clj" "test/cljs"]}
:build-dev {:main-opts ["-m" "figwheel.main" "-b" "dev" "-r"]}
:build {:main-opts ["-m" "figwheel.main" "-bo" "release"]}}}
EOF
)
MAKEFILE=$(cat <<EOF
.PHONY: all test clean
clean:
rm -rf target/*
repl:
clojure -M:nrepl:dev:test
lint:
clojure -M:dev -m clj-kondo.main --lint src/**
test:
clojure -M:test -m kaocha.runner
build:
mkdir -p ./target/public
cp -r ./resources/public/* ./target/public
clojure -M:build
EOF
)
CORE=$(cat <<EOF
(ns $NAME.core
(:require [ring.adapter.jetty :refer [run-jetty]]))
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello $NAME World"})
(defn -main
[& args]
(run-jetty handler {:port 8080}))
EOF
)
echo "Creating new project $NAME"
cd ~/src
if [ ! -d ~/src/$NAME ]; then
mkdir $NAME
cd ~/src/$NAME
echo "$DEPSEDN" > deps.edn
echo "$MAKEFILE" > Makefile
underscore_name=${NAME//-/_}
mkdir -p ./src/clj/$underscore_name
echo "$CORE" > ./src/clj/$underscore_name/core.clj
else
echo "~/src/$NAME already exists"
fi