Skip to content

Commit 93fde4d

Browse files
borkdudezampino
andauthored
Add Squint Target (#39)
Co-authored-by: Andrea Amantini <[email protected]>
1 parent 7b911bf commit 93fde4d

File tree

27 files changed

+1328
-279
lines changed

27 files changed

+1328
-279
lines changed

.bb/tasks.bb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(ns tasks
2+
(:require
3+
[babashka.tasks :refer [shell]]
4+
[clojure.string :as str]))
5+
6+
(defn watch-cljs []
7+
(let [watch (requiring-resolve 'pod.babashka.fswatcher/watch)
8+
ret (watch "src-squint"
9+
(fn [{:keys [type path]}]
10+
(when (and (#{:write :write|chmod :create} type)
11+
(or (str/ends-with? path ".cljs")
12+
(str/ends-with? path ".cljc"))
13+
;; emacs shit:
14+
(not (str/includes? path ".#")))
15+
(shell {:continue true
16+
:err :inherit
17+
:std :inherit} "yarn squint compile --output-dir public/squint/js" path)))
18+
{:recursive true})]
19+
(println (str "Started watching: " ret))
20+
@(promise)))

.clj-kondo/config.edn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{:cljc {:features [:cljs]}
2+
:lint-as {applied-science.js-interop/defn clojure.core/defn
3+
applied-science.js-interop/fn clojure.core/fn
4+
applied-science.js-interop/let clojure.core/let}}

.github/workflows/main.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ jobs:
2121
- name: 🧶 Yarn Install
2222
run: yarn install
2323

24-
- name: 🧪 Run tests
24+
- name: 🧪 Run CLJS tests
2525
run: yarn test
2626

27+
- name: 🧪 Run squint tests
28+
run: |
29+
yarn squint compile
30+
node dist/nextjournal/clojure_mode_tests.mjs
31+
2732
snapshot:
2833
name: Static App / Build
2934
runs-on: ubuntu-latest
@@ -52,7 +57,13 @@ jobs:
5257
run: yarn install
5358

5459
- name: 🧶 Yarn Build
55-
run: yarn build
60+
run: |
61+
yarn build
62+
63+
- name: 🧶 Squint build
64+
run: |
65+
yarn squint compile
66+
yarn vite:build
5667
5768
- name: 📠 Copy static build to bucket under SHA
5869
run: gsutil cp -r public gs://nextjournal-snapshots/clojure-mode/build/${{ github.sha }}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.shadow-cljs
22
.idea
33
.calva
4-
.clj-kondo
4+
.cache
55
.cpcache
6-
.lsp
76
public/js
87
public/livedoc/js
98
node_modules
109
public/test
1110
*.iml
1211
out
12+
dist

bb.edn

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,56 @@
11
{:min-bb-version "0.7.6"
2-
:paths ["bb"]
2+
:paths [".bb"]
3+
:pods {org.babashka/fswatcher {:version "0.0.4"}}
34
:tasks
45
{:requires ([clojure.edn :as edn]
56
[clojure.string :as str]
67
[babashka.deps :as deps]
78
[babashka.fs :as fs]
8-
[babashka.process :as p])
9+
[babashka.process :as p]
10+
[tasks :as t])
911
:init (do
1012
(defn viewer-css-path []
1113
(let [cp (str/trim (with-out-str (deps/clojure ["-A:dev:demo" "-Spath"])))]
12-
(str/trim (:out (shell {:out :string} (str "bb -cp " cp " -e '(println (.getPath (clojure.java.io/resource \"css/viewer.css\")))'")))))))
14+
(str/trim (:out (shell {:out :string} (str "bb -cp " cp " -e '(println (.getPath (clojure.java.io/resource \"css/viewer.css\")))'"))))))
15+
16+
(defn get-paths [ext]
17+
(map str (fs/glob "." (str "{demo,src,collab}/**." (name ext))))))
1318

1419
copy-viewer-css {:doc "Copies viewer stylesheet to resources."
15-
:task (fs/copy (viewer-css-path) "resources/stylesheets/viewer.css" #{:replace-existing})}}}
20+
:task (fs/copy (viewer-css-path) "resources/stylesheets/viewer.css" #{:replace-existing})}
21+
22+
yarn-install (shell "yarn install")
23+
24+
clean (let [paths (get-paths :mjs)]
25+
(println (apply str (interpose "\n" (cons "removing:" paths))))
26+
(doseq [path paths] (fs/delete path)))
27+
28+
#_#_compile {:doc "Use squintjs to compile all cljs files recursively"
29+
:depends [yarn-install]
30+
:task (shell {:std :inherit :err :inherit}
31+
(apply str (cons "yarn squint compile "
32+
(interpose " " (get-paths :cljs)))))}
33+
34+
#_#_build {:doc "Compiles cljs files with squint and builds from mjs sources with vite"
35+
:depends [compile]
36+
:task (shell {:std :inherit :err :inherit}
37+
"yarn build")}
38+
39+
watch-cljs (shell "yarn run squint watch")
40+
41+
yarn-install:squint-dev (do
42+
(shell "yarn add squint-cljs@link:../squint")
43+
(shell {:dir "node_modules/.bin"} "ln -sf" "../squint-cljs/node_cli.js" "squint"))
44+
45+
vite:dev {:doc "Launches vite application"
46+
:depends [yarn-install]
47+
:task (shell "yarn vite:dev")}
48+
49+
vite:build {:depends [yarn-install]
50+
:task (shell "yarn vite:build")}
51+
52+
-dev {:depends [vite:dev watch-cljs]}
53+
54+
dev {:doc "Compiles all cljs to mjs, runs vite in dev and starts a cherry watcher to recompile changed cljs. When run as `bb dev collab` also starts a Y.js collaboration server."
55+
;; :depends [compile]
56+
:task (run '-dev {:parallel true})}}}

deps.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{:deps {applied-science/js-interop {:mvn/version "0.3.3"}
1+
{:paths ["src-shared" "src"]
2+
:deps {applied-science/js-interop {:mvn/version "0.3.3"}
23
org.clojure/clojure {:mvn/version "1.10.3"}
34
org.clojure/clojurescript {:mvn/version "1.10.866"}}
45
:aliases

package.json

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,58 @@
1-
{
2-
"dependencies": {
3-
"@codemirror/autocomplete": "^6.0.2",
4-
"@codemirror/commands": "^6.0.0",
5-
"@codemirror/lang-markdown": "6.0.0",
6-
"@codemirror/language": "^6.1.0",
7-
"@codemirror/lint": "^6.0.0",
8-
"@codemirror/search": "^6.0.0",
9-
"@codemirror/state": "^6.0.1",
10-
"@codemirror/view": "^6.0.2",
11-
"@lezer/common": "^1.0.0",
12-
"@lezer/generator": "^1.0.0",
13-
"@lezer/highlight": "^1.0.0",
14-
"@lezer/lr": "^1.0.0",
15-
"@nextjournal/lezer-clojure": "1.0.0",
16-
"d3-require": "^1.2.4",
17-
"emoji-regex": "^10.0.0",
18-
"framer-motion": "^6.2.8",
19-
"katex": "^0.12.0",
20-
"markdown-it": "12.3.2",
21-
"markdown-it-block-image": "0.0.3",
22-
"markdown-it-sidenote": "gerwitz/markdown-it-sidenote#aa5de8ce3168b7d41cb33c3aed071a5f41ce0083",
23-
"markdown-it-texmath": "0.9.1",
24-
"markdown-it-toc-done-right": "4.2.0",
25-
"punycode": "2.1.1",
26-
"react": "^17.0.2",
27-
"react-dom": "^17.0.2",
28-
"w3c-keyname": "^2.2.4"
29-
},
30-
"scripts": {
31-
"watch": "bb copy-viewer-css && shadow-cljs -A:demo watch demo livedoc test",
32-
"build": "shadow-cljs -A:demo release demo livedoc",
33-
"test": "shadow-cljs -A:dev release ci-test && node out/node-tests.js",
34-
"watch2": "git ls-files | entr yarn test"
35-
},
36-
"devDependencies": {
37-
"shadow-cljs": "2.19.5"
38-
}
1+
{ "name": "@nextjournal/clojure-mode",
2+
"files": ["dist"],
3+
"version": "0.1.0-rc2",
4+
"license": "EPL-2.0",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/nextjournal/clojure-mode"
8+
},
9+
"dependencies": {
10+
"@codemirror/autocomplete": "^6.0.2",
11+
"@codemirror/commands": "^6.0.0",
12+
"@codemirror/lang-markdown": "6.0.0",
13+
"@codemirror/language": "^6.1.0",
14+
"@codemirror/lint": "^6.0.0",
15+
"@codemirror/search": "^6.0.0",
16+
"@codemirror/state": "^6.0.1",
17+
"@codemirror/view": "^6.0.2",
18+
"@lezer/common": "^1.0.0",
19+
"@lezer/generator": "^1.0.0",
20+
"@lezer/highlight": "^1.0.0",
21+
"@lezer/lr": "^1.0.0",
22+
"@nextjournal/lezer-clojure": "1.0.0",
23+
"d3-require": "^1.2.4",
24+
"emoji-regex": "^10.0.0",
25+
"framer-motion": "^6.2.8",
26+
"katex": "^0.12.0",
27+
"markdown-it": "12.3.2",
28+
"markdown-it-block-image": "0.0.3",
29+
"markdown-it-sidenote": "https://github.com/gerwitz/markdown-it-sidenote#aa5de8ce3168b7d41cb33c3aed071a5f41ce0083",
30+
"markdown-it-texmath": "0.9.1",
31+
"markdown-it-toc-done-right": "4.2.0",
32+
"punycode": "2.1.1",
33+
"react": "^17.0.2",
34+
"react-dom": "^17.0.2",
35+
"squint-cljs": "0.3.36",
36+
"w3c-keyname": "^2.2.4"
37+
},
38+
"comments": {
39+
"to run squint as a local dependency:": "bb yarn-install:squint-dev"
40+
},
41+
"scripts": {
42+
"watch": "bb copy-viewer-css && shadow-cljs -A:demo watch demo livedoc test",
43+
"build": "shadow-cljs -A:demo release demo livedoc",
44+
"test": "shadow-cljs -A:dev release ci-test && node out/node-tests.js",
45+
"watch2": "git ls-files | entr yarn test",
46+
"vite:dev": "vite --open -l info --config vite.config.js public/squint",
47+
"vite:build": "yarn vite build --config vite.config.js public/squint"
48+
},
49+
"devDependencies": {
50+
"@nextjournal/clojure-mode": "link:.",
51+
"shadow-cljs": "2.19.5",
52+
"vite": "^4.4.9",
53+
"rollup-plugin-analyzer": "^4.0.0"
54+
},
55+
"exports": {
56+
".": "dist/nextjournal/clojure_mode.mjs"
57+
}
3958
}

0 commit comments

Comments
 (0)