Skip to content

Commit

Permalink
feat(cli/templates) add clojurescript
Browse files Browse the repository at this point in the history
  • Loading branch information
just-sultanov committed Sep 19, 2022
1 parent 2972a91 commit d9f392a
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/clojurescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"create-tauri-app": patch
"create-tauri-app-js": patch
---

Add `clojurescript` template.
1 change: 1 addition & 0 deletions .scripts/generate-templates-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const nodeJsTemplates = [
"next-ts",
"preact",
"preact-ts",
"clojurescript"
];

const matrixConfig = [
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Currently supported template presets include:
- `next-ts`
- `preact`
- `preact-ts`
- `clojurescript`

You can use `.` for the project name to scaffold in the current directory.

Expand Down
28 changes: 28 additions & 0 deletions packages/cli/fragments/_assets_/cljs.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
}
7 changes: 7 additions & 0 deletions packages/cli/fragments/fragment-clojurescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Tauri + ClojureScript

This template should help get you started developing with Tauri and ClojureScript + shadow-cljs.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
13 changes: 13 additions & 0 deletions packages/cli/fragments/fragment-clojurescript/_cta_manifest_
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019-2022 Tauri Programme within The Commons Conservancy
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

beforeDevCommand = {{pkg_manager_run_command}} dev
beforeBuildCommand = {{pkg_manager_run_command}} build
devPath = http://localhost:3000
distDir = ../dist
withGlobalTauri = true

[files]
cljs.svg = public/cljs.svg
tauri.svg = public/tauri.svg
23 changes: 23 additions & 0 deletions packages/cli/fragments/fragment-clojurescript/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
.cpcache
.clj-kondo/.cache
.shadow-cljs
target
11 changes: 11 additions & 0 deletions packages/cli/fragments/fragment-clojurescript/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{:paths ["src/main/clojure"]

:deps {reagent/reagent {:mvn/version "1.1.1"
:exclusions [cljsjs/react
cljsjs/react-dom
cljsjs/react-dom-server]}}

:aliases {:develop {:extra-deps {thheller/shadow-cljs {:mvn/version "2.20.1"}
binaryage/devtools {:mvn/version "1.0.6"}}}

:test {:extra-paths ["src/test/clojure"]}}}
22 changes: 22 additions & 0 deletions packages/cli/fragments/fragment-clojurescript/karma.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = function (config) {
config.set({
singleRun: true,
browsers: ["ChromeHeadlessNoSandbox"],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: "ChromeHeadless",
flags: ["--no-sandbox"],
},
},
basePath: "target",
files: ["test/js/ci.js"],
frameworks: ["cljs-test"],
plugins: ["karma-cljs-test", "karma-chrome-launcher"],
colors: true,
logLevel: config.LOG_INFO,
client: {
args: ["shadow.test.karma.init"],
singleRun: true,
},
});
};
28 changes: 28 additions & 0 deletions packages/cli/fragments/fragment-clojurescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "{{package_name}}",
"private": true,
"version": "0.0.0",
"scripts": {
"shadow:watch": "npx shadow-cljs watch app test",
"shadow:build": "npx shadow-cljs release app",
"test:build": "npx shadow-cljs compile ci",
"test:run": "npx karma start karma.config.js --single-run",
"clean": "rm -rf ./public/js ./target",
"dev": "npm run clean && npm run shadow:watch",
"test": "npm run clean && npm run test:build && npm run test:run",
"build": "npm run clean && npm run shadow:build",
"tauri": "tauri"
},
"devDependencies": {
"@tauri-apps/cli": "^1.0.5",
"karma": "^6.4.0",
"karma-chrome-launcher": "^3.1.1",
"karma-cljs-test": "^0.1.0",
"shadow-cljs": "^2.20.1"
},
"dependencies": {
"@tauri-apps/api": "^1.0.5",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
}
14 changes: 14 additions & 0 deletions packages/cli/fragments/fragment-clojurescript/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/cljs.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + ClojureScript</title>
</head>

<body>
<div id="root"></div>
<script src="/js/main.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions packages/cli/fragments/fragment-clojurescript/shadow-cljs.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{:deps {:aliases [:develop :test]}

:nrepl {:init-ns user}

:dev-http {3000 "public"
3001 "target/test"}

:build-defaults {:closure-defines {goog.DEBUG true}
:compiler-options {:output-feature-set :es-next}}

:builds {:app {:target :browser
:output-dir "public/js"
:asset-path "/js"
:modules {:main {:init-fn app.core/-main}}
:devtools {:preloads [devtools.preload]}
:dev {:external-config {:devtools/config {:features-to-install [:formatters :hints]}}}}

:test {:target :browser-test
:test-dir "target/test"
:devtools {}}

:ci {:target :karma
:output-to "target/test/js/ci.js"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(ns app.core
(:require
[goog.dom :as gdom]
[reagent.dom :as dom]))


(defn square
[x]
(* x x))


(defn mount-root
"Mount root component."
{:dev/after-load true}
[]
(some->>
(gdom/getElement "root")
(dom/render [:h1 "Welcome to Tauri!"])))


(defn -main
"Application entry point."
{:export true}
[& _args]
(mount-root))
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns app.core-test
(:require
[app.core :as sut]
[cljs.test :as t :include-macros true]))


(t/deftest square-test
(t/testing "dummy test"
(t/is (= 4 (sut/square 2)))))
1 change: 1 addition & 0 deletions packages/cli/src/package_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl PackageManager {
Template::NextTs,
Template::Preact,
Template::PreactTs,
Template::ClojureScript
],
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum Template {
NextTs,
Preact,
PreactTs,
ClojureScript
}

impl Default for Template {
Expand All @@ -58,6 +59,7 @@ impl<'a> Template {
Template::Preact,
Template::PreactTs,
Template::VanillaTs,
Template::ClojureScript
];

pub fn post_init_info(&self, pkg_manager: PackageManager) -> Option<String> {
Expand Down Expand Up @@ -241,6 +243,7 @@ impl Display for Template {
Template::NextTs => write!(f, "next-ts"),
Template::Preact => write!(f, "preact"),
Template::PreactTs => write!(f, "preact-ts"),
Template::ClojureScript => write!(f, "clojurescript")
}
}
}
Expand All @@ -265,6 +268,7 @@ impl FromStr for Template {
"preact" => Ok(Template::Preact),
"preact-ts" => Ok(Template::PreactTs),
"vanilla-ts" => Ok(Template::VanillaTs),
"clojurescript" => Ok(Template::ClojureScript),
_ => Err("Invalid template".to_string()),
}
}
Expand Down

0 comments on commit d9f392a

Please sign in to comment.