Skip to content

Commit 06f1920

Browse files
authored
NPM Release (#40)
* adjust for NPM release * update usage in README and landing page * add squint build snapshot with import-from-CDN demo
1 parent 93fde4d commit 06f1920

File tree

13 files changed

+5110
-28
lines changed

13 files changed

+5110
-28
lines changed

.github/workflows/main.yml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,47 @@ jobs:
2929
yarn squint compile
3030
node dist/nextjournal/clojure_mode_tests.mjs
3131
32+
squint:
33+
name: Static App / Squint Build
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: 🛎 Checkout
37+
uses: actions/checkout@v2
38+
39+
- name: 🔐 Google Auth
40+
uses: google-github-actions/auth@v0
41+
with:
42+
credentials_json: ${{ secrets.GCLOUD_SERVICE_KEY }}
43+
44+
- name: 🔧 Setup Google Cloud SDK
45+
uses: google-github-actions/setup-gcloud@v0.3.0
46+
47+
- name: 🔧 Install java
48+
uses: actions/setup-java@v1
49+
with:
50+
java-version: '11.0.7'
51+
52+
- name: 🔧 Install clojure
53+
uses: DeLaGuardo/setup-clojure@master
54+
with:
55+
bb: 'latest'
56+
57+
- name: 🔎 Build Squint static CDN Demo
58+
run: bb squint:demo:build
59+
60+
- name: 📠 Copy static build to bucket under SHA
61+
run: gsutil cp -r public gs://nextjournal-snapshots/clojure-mode/squint-build/${{ github.sha }}
62+
63+
- name: ✅ Add link to Clojure Mode Squint Demo
64+
uses: Sibz/github-status-action@v1
65+
with:
66+
authToken: ${{secrets.GITHUB_TOKEN}}
67+
context: 'CI / Static App / Squint'
68+
description: 'Ready'
69+
state: 'success'
70+
sha: ${{github.event.pull_request.head.sha || github.sha}}
71+
target_url: https://snapshots.nextjournal.com/clojure-mode/squint-build/${{ github.sha }}/squint-cdn-demo
72+
3273
snapshot:
3374
name: Static App / Build
3475
runs-on: ubuntu-latest
@@ -53,18 +94,14 @@ jobs:
5394
uses: DeLaGuardo/setup-clojure@master
5495
with:
5596
cli: '1.10.3.943'
97+
5698
- name: 🧶 Yarn Install
5799
run: yarn install
58100

59101
- name: 🧶 Yarn Build
60102
run: |
61103
yarn build
62104
63-
- name: 🧶 Squint build
64-
run: |
65-
yarn squint compile
66-
yarn vite:build
67-
68105
- name: 📠 Copy static build to bucket under SHA
69106
run: gsutil cp -r public gs://nextjournal-snapshots/clojure-mode/build/${{ github.sha }}
70107

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
.cpcache
66
public/js
77
public/livedoc/js
8+
public/squint-cdn-demo
9+
squint-demo/node_modules
810
node_modules
911
public/test
1012
*.iml
1113
out
1214
dist
15+
**/.DS_Store

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ Enabling a decent Clojure/Script editor experience in the browser. Built for and
3535
{:deps {io.github.nextjournal/clojure-mode {:git/sha "<SHA>"}}}
3636
```
3737

38+
### Use it from [NPM](https://www.npmjs.com/package/@nextjournal/clojure-mode)
39+
40+
```js
41+
import { default_extensions, complete_keymap } from '@nextjournal/clojure-mode';
42+
import { EditorView, drawSelection, keymap } from '@codemirror/view';
43+
import { EditorState } from '@codemirror/state';
44+
45+
let extensions = [keymap.of(complete_keymap),
46+
...default_extensions
47+
];
48+
49+
let state = EditorState.create({doc: "... some clojure code...",
50+
extensions: extensions });
51+
let editorElt = document.querySelector('#editor');
52+
let editor = new EditorView({state: state,
53+
parent: editorElt,
54+
extensions: extensions });
55+
```
56+
3857
## 🛠 Development Setup
3958

4059
* Install JS dependencies: `yarn install`

bb.edn

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
:task (shell {:std :inherit :err :inherit}
3737
"yarn build")}
3838

39-
watch-cljs (shell "yarn run squint watch")
39+
watch-cljs (shell "yarn watch")
40+
41+
squint:watch-cljs (shell "yarn run squint watch")
4042

4143
yarn-install:squint-dev (do
4244
(shell "yarn add squint-cljs@link:../squint")
@@ -49,7 +51,19 @@
4951
vite:build {:depends [yarn-install]
5052
:task (shell "yarn vite:build")}
5153

52-
-dev {:depends [vite:dev watch-cljs]}
54+
squint:build {:task (shell "yarn squint compile")}
55+
56+
publish {:depends [squint:build]
57+
:doc "Publish to NPM, do `npm login` manually first to authenticate your shell."
58+
:task (shell "npm publish")}
59+
60+
squint:demo:build {:task (do (shell {:dir "squint-demo"} "npm install")
61+
(shell {:dir "squint-demo"} "npx jspm link index.html -o index.html --cache no-cache")
62+
(fs/create-dirs "public/squint-cdn-demo")
63+
(fs/copy "squint-demo/index.mjs" "public/squint-cdn-demo/index.mjs" {:replace-existing true})
64+
(fs/copy "squint-demo/index.html" "public/squint-cdn-demo/index.html" {:replace-existing true}))}
65+
66+
-dev {:depends [vite:dev squint:watch-cljs watch-cljs]}
5367

5468
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."
5569
;; :depends [compile]

demo/src/deps.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{:npm-deps
22
{"react" "^17.0.2"
33
"react-dom" "^17.0.2"
4-
"framer-motion" "^6.2.8"}}
4+
"framer-motion" "^6.2.8"
5+
"@codemirror/lang-javascript" "^6.0.0"}}

demo/src/nextjournal/clojure_mode/demo.cljs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns nextjournal.clojure-mode.demo
22
(:require ["@codemirror/commands" :refer [history historyKeymap]]
33
["@codemirror/language" :refer [foldGutter syntaxHighlighting defaultHighlightStyle]]
4+
["@codemirror/lang-javascript" :refer [javascript]]
45
["@codemirror/state" :refer [EditorState]]
56
["@codemirror/view" :as view :refer [EditorView]]
67
["react" :as react]
@@ -174,11 +175,33 @@
174175
[:td.px-3.py-1.align-top.text-sm]
175176
[:td.px-3.py-1.align-top]])]))))])
176177

178+
(defn js-syntax [source]
179+
(r/with-let [!view (r/atom nil)
180+
mount! (fn [el]
181+
(when el
182+
(reset! !view (new EditorView
183+
(j/obj :parent el
184+
:state (.create EditorState (j/obj :doc source
185+
:extensions (to-array [(javascript (j/obj))
186+
(syntaxHighlighting defaultHighlightStyle)
187+
(.. EditorState -readOnly (of true))
188+
(foldGutter)
189+
theme]))))))))]
190+
[:div
191+
[:div {:class "rounded-md mb-0 text-sm monospace overflow-auto relative border shadow-lg bg-white" :ref mount! :style {:max-height 410}}]]
192+
(finally
193+
(j/call @!view :destroy))))
194+
177195
(defn ^:dev/after-load render []
178196
(rdom/render [samples] (js/document.getElementById "editor"))
179197
(.. (js/document.querySelectorAll "[clojure-mode]")
180198
(forEach #(when-not (.-firstElementChild %)
181199
(rdom/render [editor (str/trim (.-innerHTML %))] %))))
200+
201+
(.. (js/document.querySelectorAll "[js-mode]")
202+
(forEach #(when-not (.-firstElementChild %)
203+
(rdom/render [js-syntax (str/trim (.-innerHTML %))] %))))
204+
182205
(let [mapping (key-mapping)]
183206
(.. (js/document.querySelectorAll ".mod,.alt,.ctrl")
184207
(forEach #(when-let [k (get mapping (.-innerHTML %))]

package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ "name": "@nextjournal/clojure-mode",
22
"files": ["dist"],
3-
"version": "0.1.0-rc2",
3+
"version": "0.1.0",
44
"license": "EPL-2.0",
55
"repository": {
66
"type": "git",
@@ -20,18 +20,6 @@
2020
"@lezer/highlight": "^1.0.0",
2121
"@lezer/lr": "^1.0.0",
2222
"@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",
3523
"squint-cljs": "0.3.36",
3624
"w3c-keyname": "^2.2.4"
3725
},
@@ -47,10 +35,23 @@
4735
"vite:build": "yarn vite build --config vite.config.js public/squint"
4836
},
4937
"devDependencies": {
38+
"@codemirror/lang-javascript": "^6.0.0",
5039
"@nextjournal/clojure-mode": "link:.",
40+
"d3-require": "^1.2.4",
41+
"emoji-regex": "^10.0.0",
42+
"framer-motion": "^6.2.8",
43+
"katex": "^0.12.0",
44+
"markdown-it": "12.3.2",
45+
"markdown-it-block-image": "0.0.3",
46+
"markdown-it-sidenote": "https://github.com/gerwitz/markdown-it-sidenote#aa5de8ce3168b7d41cb33c3aed071a5f41ce0083",
47+
"markdown-it-texmath": "0.9.1",
48+
"markdown-it-toc-done-right": "4.2.0",
49+
"punycode": "2.1.1",
50+
"react": "^17.0.2",
51+
"react-dom": "^17.0.2",
52+
"rollup-plugin-analyzer": "^4.0.0",
5153
"shadow-cljs": "2.19.5",
52-
"vite": "^4.4.9",
53-
"rollup-plugin-analyzer": "^4.0.0"
54+
"vite": "^4.4.9"
5455
},
5556
"exports": {
5657
".": "dist/nextjournal/clojure_mode.mjs"

public/index.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,39 @@ <h2 class="text-center text-3xl font-bold mt-0 mb-12">
208208
<div class="bg-alt py-12 px-6">
209209
<div id="use-it" class="mx-auto max-w-4xl">
210210
<h2 class="mt-0 mb-8 text-3xl font-bold text-center">
211-
<a href="#use-it" class="near-black">📦 Use it in your project</a>
211+
<a href="#use-it" class="near-black">📦 Use it in your clojure project</a>
212212
</h2>
213213
<pre clojure-mode="true" class="max-w-4xl mx-auto">
214214
{:deps {nextjournal/clojure-mode {:git/url "https://github.com/nextjournal/clojure-mode"
215215
:sha "SHA"}}}
216216
</pre>
217217
</div>
218218
</div>
219+
<div class="bg-alt py-12 px-6">
220+
<div id="npm" class="mx-auto max-w-4xl">
221+
<h2 class="mt-0 mb-8 text-3xl font-bold text-center">
222+
<a href="#npm" class="near-black">📦 Use it from NPM</a>
223+
</h2>
224+
<pre js-mode="true" class="max-w-4xl">
225+
import { default_extensions, complete_keymap } from '@nextjournal/clojure-mode'
226+
import { EditorView, drawSelection, keymap } from '@codemirror/view'
227+
import { EditorState } from '@codemirror/state'
228+
229+
let extensions = [keymap.of(complete_keymap),
230+
...default_extensions]
231+
232+
let state = EditorState.create({doc: "... some clojure code...",
233+
extensions: extensions })
234+
235+
let editorElt = document.querySelector('#editor')
236+
let editor = new EditorView({state: state,
237+
parent: editorElt,
238+
extensions: extensions})
239+
240+
</pre>
241+
</div>
242+
</div>
243+
219244
<div id="embed-it" class="bg-alt py-12 px-6">
220245
<div class="mx-auto max-w-4xl">
221246
<h2 class="mt-0 mb-8 text-3xl font-bold text-center">

0 commit comments

Comments
 (0)