Skip to content

Commit 2f31f43

Browse files
committed
Merge pull request #15 from yetanalytics/cljx_to_cljc
Cljx to cljc
2 parents 5831b2d + 38e76d5 commit 2f31f43

File tree

25 files changed

+661
-438
lines changed

25 files changed

+661
-438
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pom.xml.asc
99
/.nrepl-port
1010
.DS_Store
1111
/resources/public/xapi_schema.js
12+
.specljs-timestamp

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: clojure
22
script:
3-
- lein spec
4-
- lein cljsbuild once test
3+
- lein ci
54
notifications:
65
webhooks:
76
urls:

README.org

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ You can use xapi-schema to validate statements in real-time [[http://yetanalytic
1818
** Getting Started
1919
1. Add to your project dependencies:
2020
#+BEGIN_SRC clojure
21-
[[com.yetanalytics/xapi-schema "0.1.2"]]
21+
[[com.yetanalytics/xapi-schema "0.1.3-SNAPSHOT"]]
2222
#+END_SRC
2323
2. Require in your project:
2424
#+BEGIN_SRC clojure
2525
(ns your-project.core
26-
(:require [xapi-schema.core :as x]
26+
(:require [xapi-schema.core :as xs]
2727
[xapi-schema.schemata.json :as json]))
2828
#+END_SRC
2929

@@ -143,11 +143,11 @@ xapi_schema.core.validate_statement_data_js(statement_json); // => statement JSO
143143

144144
*** Clojure
145145

146-
=$ lein do cljx, spec= or =$ lein spec-clj= (alias)
146+
=$ lein spec-clj=
147147

148148
*** ClojureScript
149149

150-
=$lein do cljx, cljsbuild once test= or =$ lein spec-cljs= (alias)
150+
=$ lein spec-cljs=
151151

152152
** License
153153

bin/speclj.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
Speclj Runner
3+
4+
Usage:
5+
phantomjs resources/public/specs/speclj.js [auto]
6+
7+
auto: will only run specs updated after the last run. (default: false)
8+
9+
Each run produced/touches a timestamp file, .specljs-timestamp
10+
*/
11+
12+
var outputDir = "target/cljs";
13+
var nsPrefix = "speclj";
14+
var runnerFile = "bin/specs.html";
15+
16+
var fs = require("fs");
17+
var p = require('webpage').create();
18+
var system = require('system');
19+
20+
String.prototype.endsWith = function (suffix) {
21+
return this.indexOf(suffix, this.length - suffix.length) !== -1;
22+
};
23+
String.prototype.startsWith = function (str) {
24+
return this.slice(0, str.length) == str;
25+
};
26+
27+
p.onConsoleMessage = function (x) {
28+
fs.write("/dev/stdout", x, "w");
29+
};
30+
31+
var timestampFile = ".specljs-timestamp";
32+
writeTimestamp = function () {
33+
if(fs.lastModified(timestampFile) != null)
34+
fs.remove(timestampFile);
35+
fs.touch(timestampFile);
36+
};
37+
38+
readTimestamp = function () {
39+
return fs.lastModified(timestampFile);
40+
};
41+
42+
allSpecsFilter = function () {
43+
return true;
44+
};
45+
46+
var autoMode = function () {
47+
return system.args[1] == "auto" && readTimestamp() != null;
48+
};
49+
50+
var logList = function (title, list) {
51+
console.log(title + ":");
52+
for(var i in list)
53+
console.log(i);
54+
};
55+
56+
var relativeRoot = outputDir + "/goog/";
57+
findUpdatedSpecs = function (rdeps, deps) {
58+
var minMillis = readTimestamp().getTime();
59+
var updated = {};
60+
for(var ns in rdeps) {
61+
var file = deps.nameToPath[ns];
62+
var path = relativeRoot + file;
63+
if(fs.lastModified(path).getTime() >= minMillis) {
64+
updated[ns] = true;
65+
}
66+
}
67+
return updated;
68+
};
69+
70+
buildReverseDeps = function (deps) {
71+
var rdeps = {};
72+
for(var ns in deps.nameToPath) {
73+
if(ns.startsWith(nsPrefix)) {
74+
var file = deps.nameToPath[ns];
75+
for(var rdep in deps.requires[file]) {
76+
if(rdep.startsWith(nsPrefix)) {
77+
if(!(rdep in rdeps)) {
78+
rdeps[rdep] = {}
79+
}
80+
rdeps[rdep][ns] = true;
81+
}
82+
}
83+
if(!(ns in rdeps)) {
84+
rdeps[ns] = {}
85+
}
86+
}
87+
}
88+
return rdeps;
89+
};
90+
91+
reduceToSpecs = function (affected) {
92+
var result = {};
93+
for(var ns in affected) {
94+
if(ns.endsWith("_spec")) {
95+
result[ns.replace(/_/g, "-")] = true
96+
}
97+
}
98+
return result;
99+
};
100+
101+
findAffectedSpecs = function () {
102+
var deps = p.evaluate(function () {
103+
return goog.dependencies_;
104+
});
105+
var rdeps = buildReverseDeps(deps);
106+
var updated = findUpdatedSpecs(rdeps, deps);
107+
108+
var result = {};
109+
110+
var walkDeps = function (nses) {
111+
for(var ns in nses) {
112+
if(!(ns in result)) {
113+
result[ns] = true;
114+
walkDeps(rdeps[ns])
115+
}
116+
}
117+
};
118+
walkDeps(updated);
119+
120+
return reduceToSpecs(result);
121+
};
122+
123+
p.open(runnerFile, function (status) {
124+
try {
125+
var specs = autoMode() ? findAffectedSpecs() : null;
126+
127+
var result = p.evaluate(function (specSet) {
128+
return runSpecsPhantom(specSet);
129+
}, specs);
130+
131+
writeTimestamp();
132+
phantom.exit(result);
133+
}
134+
catch(e) {
135+
console.error(e);
136+
phantom.exit(-1);
137+
}
138+
139+
});

bin/specs.html

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="iso-8859-1" content="text/html" http-equiv="Content-Type"/>
5+
<title>Speclj Specs</title>
6+
<!--<script src="../js/es5-shim.js" type="text/javascript"></script>-->
7+
<script src="../target/cljs/goog/base.js" type="text/javascript"></script>
8+
<script src="../target/specs.js" type="text/javascript"></script>
9+
<script type="text/javascript">
10+
String.prototype.endsWith = function (suffix) {
11+
return this.indexOf(suffix, this.length - suffix.length) !== -1;
12+
};
13+
14+
for(var name in goog.dependencies_.nameToPath) {
15+
if(name.endsWith("_spec")) {
16+
goog.require(name)
17+
}
18+
}
19+
20+
runSpecsConfigured = function (color, reporter) {
21+
speclj.run.standard.armed = true;
22+
return speclj.run.standard.run_specs(
23+
cljs.core.keyword("color"), color
24+
, cljs.core.keyword("reporters"), [reporter]
25+
);
26+
};
27+
28+
runSpecs = function () {
29+
runSpecsConfigured(false, "documentation");
30+
}
31+
32+
runSpecsPhantom = function (affectedSpecs) {
33+
if(affectedSpecs != null) {
34+
console.log("Only running affected specs:");
35+
var descriptionAtom = speclj.config.active_runner().descriptions;
36+
cljs.core.swap_BANG_(descriptionAtom, function (descriptions) {
37+
return cljs.core.filter(function (description) {
38+
return description.ns in affectedSpecs;
39+
}, descriptions);
40+
});
41+
cljs.core.doall(cljs.core.map(function (description) {
42+
console.log(" ", description.ns);
43+
}, cljs.core.deref(descriptionAtom)));
44+
}
45+
runSpecsConfigured(true, "documentation");
46+
}
47+
</script>
48+
</head>
49+
<body>
50+
<h3 style="margin: 1em">Speclj CLJS Specs</h3>
51+
52+
<p style="margin: 1em; width: 400px;">
53+
Typically these specs are run using phantomjs on the command line.
54+
But you can run them here if you like.
55+
That is, assuming all the cljs has been compiled in development.
56+
<br/>
57+
Open up the browser console:
58+
</p>
59+
<pre style="margin: 1em; padding: 1em; width: 400px; border: 1px dotted slategray; background-color: lightgray;">
60+
runSpecs()
61+
</pre>
62+
</body>
63+
</html>

dev/xapi_schema/dev/cljs.clj

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(ns xapi-schema.dev.cljs
2+
(:require [cljs.build.api :as api]
3+
[clojure.java.io :as io]))
4+
5+
6+
(def build-options
7+
{:optimizations :none
8+
:output-to "target/specs.js"
9+
:output-dir "target/cljs"
10+
:cache-analysis true
11+
:source-map true
12+
:pretty-print true
13+
:verbose true
14+
:watch-fn (fn [] (println "Success!"))
15+
})
16+
17+
(defn run-specs []
18+
(let [process (.exec (Runtime/getRuntime) "phantomjs bin/speclj.js")
19+
output (.getInputStream process)
20+
error (.getErrorStream process)]
21+
(io/copy output (System/out))
22+
(io/copy error (System/err))
23+
(System/exit (.waitFor process))))
24+
25+
(defn -main [& args]
26+
(api/build "spec" build-options)
27+
(run-specs))

dev/xapi_schema/dev/spec.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(ns xapi-schema.dev.spec
2+
"Run Speclj specs. Use this instead of the plugin to avoind conflicts with other installed versions."
3+
(:require [speclj.cli :as cli]))
4+
5+
(defn -main [& args]
6+
(apply cli/run "-p" "-c" "-f" "documentation" args))

project.clj

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,31 @@
1-
(defproject com.yetanalytics/xapi-schema "0.1.2"
1+
(defproject com.yetanalytics/xapi-schema "0.1.3-SNAPSHOT"
22
:description "Clojure(script) Schema for the Experience API v1.0.3"
33
:url "https://github.com/yetanalytics/xapi-schema"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
6-
:dependencies [[org.clojure/clojure "1.7.0-RC1"]
6+
:dependencies [[org.clojure/clojure "1.7.0-RC2"]
77
[org.clojure/clojurescript "0.0-3308"]
88
[prismatic/schema "0.4.3"]
99
[cheshire "5.5.0"]
1010
[org.clojure/core.match "0.3.0-alpha4"]
1111
[com.taoensso/tower "3.1.0-beta3"]]
1212
:exclusions [[org.clojure/clojure]
1313
[org.clojure/clojurescript]]
14-
:plugins [[lein-cljsbuild "1.0.6"]
15-
[speclj "3.2.0"]]
16-
:profiles {:dev {:dependencies [[speclj "3.2.0"]]
17-
:plugins [[com.keminglabs/cljx "0.6.0" :exclusions [org.clojure/clojure]]]}}
18-
19-
:cljx {:builds [{:source-paths ["src/cljx"]
20-
:output-path "target/classes/clj"
21-
:rules :clj}
22-
{:source-paths ["src/cljx"]
23-
:output-path "target/classes/cljs"
24-
:rules :cljs}
25-
{:source-paths ["spec/cljx"]
26-
:output-path "target/spec/clj"
27-
:rules :clj}
28-
{:source-paths ["spec/cljx"]
29-
:output-path "target/spec/cljs"
30-
:rules :cljs}]}
14+
:plugins [[lein-cljsbuild "1.0.6"]]
15+
:profiles {:dev {:dependencies [[speclj "3.3.0"]]}}
3116

3217
:cljsbuild {:builds [{:id "dev"
33-
:source-paths ["target/classes/cljs"]
18+
:source-paths ["src"]
3419
:compiler {:output-to "target/js/xapi_schema_dev.js"
3520
:optimizations :whitespace
3621
:pretty-print true}}
37-
{:id "test"
38-
:source-paths ["target/classes/cljs" "target/spec/cljs" "spec/clj"]
39-
:compiler {:output-to "target/js/xapi_schema_test.js"
40-
:optimizations :whitespace
41-
:pretty-print true}
42-
:notify-command ["phantomjs" "bin/speclj" "target/js/xapi_schema_test.js"]}
43-
{:id "test-browser"
44-
:source-paths ["target/classes/cljs"]
45-
:compiler {:output-to "resources/public/xapi_schema.js"
46-
:optimizations :advanced}}
4722
{:id "release"
48-
:source-paths ["target/classes/cljs"]
23+
:source-paths ["src"]
4924
:compiler {:output-to "target/js/xapi_schema.js"
50-
:optimizations :advanced}}]
51-
:test-commands {"test" ["phantomjs" "bin/speclj" "target/js/xapi_schema_test.js"]}}
52-
:source-paths ["target/classes/clj"]
53-
:resource-paths ["resources" "target/classes/cljs"]
54-
:test-paths ["target/classes/clj" "target/spec/clj" "spec/clj"]
55-
:prep-tasks [["cljx" "once"] "javac" "compile"]
56-
:aliases {"build-once" ["do" "clean," "cljx" "once"]
57-
"deploy-lib" ["do" "build-once," "deploy" "clojars"]
58-
"spec-clj" ["do" "clean," "spec"]
59-
"spec-cljs" ["do" "clean," "cljx," "cljsbuild" "once" "test"]})
25+
:optimizations :advanced}}]}
26+
:resource-paths ["resources"]
27+
:test-paths ["spec" "dev"]
28+
:aliases {"deploy-lib" ["do" "clean," "deploy" "clojars"]
29+
"spec-cljs" ["do" "clean," "run" "-m" "xapi-schema.dev.cljs"]
30+
"spec-clj" ["do" "run" "-m" "xapi-schema.dev.spec"]
31+
"ci" ["do" "spec-clj," "spec-cljs"]})

spec/clj/xapi_schema/support/macros.clj

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)