Add lein-cljsbuild and adapt datascript's release-js vehicle.

This commit is contained in:
Nick Alexander 2016-07-05 18:13:29 -07:00
parent 55baa1685d
commit f2365646d2
12 changed files with 127 additions and 22 deletions

6
.gitignore vendored
View file

@ -15,9 +15,11 @@
/.nrepl-port
/checkouts/
/classes/
/lib/
/target/
/node_modules/
/out/
/target/
pom.xml
pom.xml.asc
/.cljs_node_repl/
/release-js/datomish.js
/release-js/datomish.bare.js

View file

@ -80,6 +80,8 @@ npm install
brew install rlwrap
```
Run `lein cljsbuild auto advanced` to generate JavaScript into `target/`.
### Starting a ClojureScript REPL from the terminal
```
@ -127,3 +129,18 @@ Now you can use `:Eval`, `cqc`, and friends to evaluate code. Fireplace should c
```
:Connect nrepl://localhost:62385
```
### Preparing an NPM release
The intention is that the `release-js/` directory is roughly the shape of an npm-ready JavaScript package.
To generate a require/import-ready `release-js/datomish.js`, run
```
lein cljsbuild once release
```
To verify that importing into Node.js succeeds, run
```
node release-js/test
```
Many thanks to ([David Nolen](https://github.com/swannodette)) and ([Nikita Prokopov](https://github.com/tonsky)) for demonstrating how to package ClojureScript for distribution via npm.

View file

@ -1,6 +0,0 @@
(require 'cljs.build.api)
(cljs.build.api/build "src"
{:main 'datomish.core
:output-to "main.js"
:target :nodejs})

View file

@ -6,19 +6,13 @@
},
"version": "0.1.0-SNAPSHOT",
"description": "A persistent, embedded knowledge base inspired by Datomic and DataScript.",
"main": "index.js",
"dependencies": {
"source-map-support": "ncalexan/node-source-map-support#fileUrls-plus",
"sqlite3": "mossop/node-sqlite3#v3.1.4.1",
"thenify-all": "^1.6.0",
"ws": "1.1.1"
},
"devDependencies": {},
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"devDependencies": {
},
"repository": {
"type": "git",
@ -29,5 +23,7 @@
"bugs": {
"url": "https://github.com/mozilla/datomish/issues"
},
"homepage": "https://github.com/mozilla/datomish#readme"
"homepage": "https://github.com/mozilla/datomish#readme",
"main": "./datomish.js",
"files": ["datomish.js"]
}

View file

@ -3,7 +3,41 @@
:url "https://github.com/mozilla/datomish"
:license {:name "Mozilla Public License Version 2.0"
:url "https://github.com/mozilla/datomish/blob/master/LICENSE"}
:dependencies [[org.clojure/clojurescript "1.9.89"]
[org.clojure/clojure "1.8.0"]]
:cljsbuild {:builds [{:id "release"
:source-paths ["src"]
:assert false
:compiler {:output-to "release-js/datomish.bare.js"
:optimizations :advanced
:pretty-print false
:elide-asserts true
:output-wrapper false
:parallel-build true}
:notify-command ["release-js/wrap_bare.sh"]}
]}
:profiles {:dev {:dependencies [[com.cemerick/piggieback "0.2.1"]
[org.clojure/tools.nrepl "0.2.10"]]
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}}
:dependencies [[org.clojure/clojurescript "1.9.89"]])
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
:source-paths []
:plugins [[lein-cljsbuild "1.1.2"]]
:cljsbuild {:builds [{:id "advanced"
:source-paths ["src"]
:compiler {
:output-to "target/datomish.js"
:optimizations :advanced
:source-map "target/datomish.js.map"
:pretty-print true
:recompile-dependents false
:parallel-build true
}}
]}
}
}
:clean-targets ^{:protect false} ["target"
"release-js/datomish.bare.js"
"release-js/datomish.js"]
)

5
release-js/README.md Normal file
View file

@ -0,0 +1,5 @@
# Datomish
Datomish is a persistent, embedded knowledge base. It's written in ClojureScript, and draws heavily on [DataScript](https://github.com/tonsky/datascript) and [Datomic](http://datomic.com).
For more info, check out the [project page](https://github.com/mozila/datomish).

View file

@ -0,0 +1,2 @@
var d = require('./datomish');
console.log(d.q("[:find ?e ?v :where [?e \"name\" ?v] {:x :y}]"));

7
release-js/wrap_bare.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
set -e
(cat release-js/wrapper.prefix; cat release-js/datomish.bare.js; cat release-js/wrapper.suffix) > release-js/datomish.js
echo "Packed release-js/datomish.js"

29
release-js/wrapper.prefix Normal file
View file

@ -0,0 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
// Datomish 0.1.0-SNAPSHOT
(function (definition) {
// This file will function properly as a <script> tag, or a module
// using CommonJS and NodeJS or RequireJS module formats.
// Wrapper gratefully adapted from:
// https://github.com/kriskowal/q/blob/v1/q.js
// https://github.com/swannodette/mori/blob/master/support/wrapper.js
// https://github.com/tonsky/datascript/blob/master/release-js/wrapper.js
// CommonJS
if (typeof exports === "object") {
module.exports = definition();
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(definition);
// <script>
} else {
datascript = definition();
}
})(function () {
return function () {

View file

@ -0,0 +1,6 @@
;return this.datomish.js;
}.call({});
});

View file

@ -2,11 +2,13 @@
(require 'cljs.build.api)
(require 'cljs.repl.node)
(cljs.build.api/build "src"
(cljs.build.api/build
"src"
{:main 'datomish.core
:output-to "out/main.js"
:output-to "target/datomish.js"
:verbose true})
(cljs.repl/repl (cljs.repl.node/repl-env)
(cljs.repl/repl
(cljs.repl.node/repl-env)
:watch "src"
:output-dir "out")
:output-dir "target")

11
src/datomish/js.cljs Normal file
View file

@ -0,0 +1,11 @@
(ns datomish.js
(:refer-clojure :exclude [])
(:require
[datomish.core :as d]
[cljs.reader]))
;; Public API.
(defn ^:export q [query & sources]
(let [query (cljs.reader/read-string query)]
(clj->js query)))