Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jruz committed Aug 17, 2023
0 parents commit 95b15a6
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: npm-publish
run-name: NPM Publish
on:
push:
branches:
- 'main'
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.17.1'
- name: NPM Publish
uses: JS-DevTools/[email protected]
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.clj-kondo
.nrepl-port
.cpcache
.lsp
4 changes: 4 additions & 0 deletions .rtx.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tools]
node = '18.17.1'
clojure = "1.11.1.1403"
java = "temurin-jre-17.0.8+7"
9 changes: 9 additions & 0 deletions .tmuxinator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: svelte-preprocess-cljs
root: .
windows:
- VIM:
layout: even-horizontal
panes:
- nvim
-
- GIT: ssh-agent zsh
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ClojureScript preprocessor for Svelte using Squint

[Counter.svelte](example/src/lib/Counter.svelte)
```svelte
<script lang="cljs">
(def count 0)
(defn increment []
(set! count (inc count)))
</script>
<button on:click={increment}>
count is {count}
</button>
```

## Install

```bash
npm install -D svelte-preprocess-cljs
```

add to `svelte.config.js`

```js
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
import squint from "svelte-preprocess-squint";

export default {
preprocess: [
squint(),
vitePreprocess()
],
}
```
9 changes: 9 additions & 0 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{:paths ["src"]
:tasks
{tmux (shell "tmuxinator local")
shell (shell "nix-shell")
lint (shell "clj-kondo --lang cljs --lint src")
prettier (shell "npx prettier . --write")
squint (shell "npx squint compile src/main.cljs")
build {:depends [squint prettier]}}}

39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "svelte-preprocess-cljs",
"version": "0.0.1",
"description": "ClojureScript preprocessor for Svelte using Squint",
"main": "src/main.mjs",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/jruz/svelte-preprocess-cljs.git"
},
"keywords": [
"clojurescript",
"cljs",
"squint",
"squint-cljs",
"svelte"
],
"author": "jruz",
"license": "ISC",
"dependencies": {
"squint-cljs": "^0.1.16"
},
"devDependencies": {
"prettier": "^3.0.2"
}
}
14 changes: 14 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ pkgs ? import <nixpkgs> { } }:

pkgs.mkShell {
buildInputs = with pkgs;[
rtx
clj-kondo
babashka
joker
rlwrap
];
shellHook = ''
zsh
'';
}
18 changes: 18 additions & 0 deletions src/main.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns main
(:require [squint-cljs.lib.compiler :as squint]))

(defn script
[opts]
(let [content (:content opts)
attributes (:attributes opts)
lang (:lang attributes)]
(when (= lang "cljs")
(try
{:code (squint/compile-string content)}
(catch :default err
(js/console.log err))))))

(defn -main
[opts]
{:name "svelte-preprocess-cljs"
:script (script opts)})
20 changes: 20 additions & 0 deletions src/main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as squint_core from "squint-cljs/core.js";
import { compile_string } from "squint-cljs.lib.compiler";
var script = function (opts) {
let content1 = squint_core.get(opts, "content");
let attributes2 = squint_core.get(opts, "attributes");
let lang3 = squint_core.get(attributes2, "lang");
if (lang3 === "cljs") {
return (function () {
try {
return { code: compile_string(content1) };
} catch (err) {
return console.log(err);
}
})();
}
};
var _main = function (opts) {
return { name: "svelte-plugin-cljs", script: script(opts) };
};
export { script, _main };

0 comments on commit 95b15a6

Please sign in to comment.