Skip to content

Commit d93bceb

Browse files
implemented q-style wrapper and adjusted the build scripts
1 parent 821f295 commit d93bceb

File tree

9 files changed

+39
-18
lines changed

9 files changed

+39
-18
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ bin
2020
scripts
2121
spec
2222
src
23+
support
2324
.npmignore
2425
.travis.yml
2526
project.clj

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"url": "https://raw.github.com/swannodette/mori/master/epl-v10.html"
2727
}
2828
],
29-
"main": "./mori.node.js",
29+
"main": "./mori.js",
3030
"repository": {
3131
"type": "git",
3232
"url": "git://github.com/swannodette/mori.git"

scripts/build.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
lein deps
12
lein cljsbuild clean
23
lein cljsbuild once release
34
$moribarejs = Get-Content mori.bare.js
5+
$wrapperbeg = Get-Content support/wrapper.beg.txt
6+
$wrapperend = Get-Content support/wrapper.end.txt
47
ni "mori.js" -type file -force
5-
ac "mori.js" "(function() {"
8+
ac "mori.js" $wrapperbeg
69
ac "mori.js" $moribarejs
7-
ac "mori.js" "}).call(this);"
8-
ni "mori.node.js" -type file -force
9-
ac "mori.node.js" $moribarejs
10-
ac "mori.node.js" ";module.exports = this.mori;"
10+
ac "mori.js" $wrapperend
1111
rm mori.bare.js

scripts/build.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55

66
echo "Finalizing mori.js"
77

8-
(echo "(function() {"; cat mori.bare.js; echo "}).call(this);") > mori.js
9-
10-
echo "Finalizing mori.node.js"
11-
12-
(cat mori.bare.js; echo ";module.exports = this.mori;") > mori.node.js
8+
(cat support/wrapper.beg.txt; cat mori.bare.js; cat support/wrapper.end.txt) > mori.js
139

1410
echo "Deleting mori.bare.js"
1511

scripts/clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22

3-
rm -f mori.node.js mori.js
3+
rm -f mori.js
44

55
./bin/lein_prefer cljsbuild clean

support/wrapper.beg.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(function(definition){if(typeof exports==="object"){module.exports=definition();}else if(typeof define==="function"&&define.amd){define(definition);}else{mori=definition();}})(function(){return function(){

support/wrapper.end.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
;return this.mori;}.call({});});

support/wrapper.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1-
function test() {
1+
(function (definition) {
2+
// This file will function properly as a <script> tag, or a module
3+
// using CommonJS and NodeJS or RequireJS module formats. In
4+
// Common/Node/RequireJS, the module exports the mori API and when
5+
// executed as a simple <script>, it creates a mori global
6+
// instead.
27

3-
var testME;
8+
// Wrapper gratefully adapted from:
9+
// https://github.com/kriskowal/q/blob/master/q.js
410

5-
var REPLACEME;
11+
// CommonJS
12+
if (typeof exports === "object") {
13+
module.exports = definition();
614

7-
function allIwantIsMinify() {
15+
// RequireJS
16+
} else if (typeof define === "function" && define.amd) {
17+
define(definition);
818

19+
// <script>
20+
} else {
21+
mori = definition();
922
}
10-
}
23+
})(function () {
24+
return function () {
25+
26+
var REPLACE_WITH_MORI_BARE_JS;
27+
28+
;return this.mori;
29+
30+
}.call({});
31+
32+
});

support/wrapper.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)