forked from ckknight/gorillascript
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.gs
144 lines (133 loc) · 4.7 KB
/
Gruntfile.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require! path
require! fs
module.exports := #(grunt)
grunt.init-config
gorilla:
build:
options: {
+verbose
}
files: [{
expand: true
cwd: "src/"
src: for filter file in fs.readdir-sync('./src')
path.extname(file) == ".gs" and not file.match(r"prelude\.gs\$") and file != "shared.gs"
dest: "lib/"
ext: ".js"
}]
"build-cov":
options: {
+verbose
+coverage
}
files: [{
expand: true
cwd: "src/"
src: for filter file in fs.readdir-sync('./src')
path.extname(file) == ".gs" and not file.match(r"prelude\.gs\$") and file != "shared.gs"
dest: "lib-cov/"
ext: ".js"
}]
test:
options: {
+verbose
}
files: [{
expand: true
cwd: "test/"
src: ["**/*.gs"]
dest: "test-js/"
ext: ".js"
}]
uglify:
browser:
files: {
"extras/gorillascript.min.js": ["extras/gorillascript.js"]
}
clean:
test: ["test-js"]
mochaTest:
test:
options:
timeout: 10_000_ms
src: ["test-js/**/*.js"]
"test-cov":
options:
reporter: "html-cov"
timeout: 10_000_ms
quiet: true
src: ["test-js/**/*.js"]
dest: "coverage.html"
grunt.load-npm-tasks "@kkirbatski/grunt-gorilla"
grunt.load-npm-tasks "grunt-contrib-clean"
grunt.load-npm-tasks "grunt-contrib-uglify"
grunt.load-npm-tasks "grunt-mocha-test"
grunt.register-task "build", ["gorilla:build"]
grunt.register-task "build-cov", ["gorilla:build-cov"]
grunt.register-task "browser", "Build gorillascript.js for use in the browser", #
let done = @async()
let promise = promise!
let filename-path = yield to-promise! fs.realpath __filename
let lib-path = path.join(path.dirname(filename-path), "lib")
let parts = []
for file in ["utils", "jsutils", "types", "jsast", "parser", "parser-utils", "parser-scope", "parser-nodes", "parser-macroholder", "parser-macrocontext", "jstranslator", "gorilla", "browser"]
let text = yield to-promise! fs.read-file path.join(lib-path, file & ".js"), "utf8"
parts.push """
require['./$file'] = function () {
var module = { exports: this };
var exports = this;
$(text.split("\n").join("\n "))
return module.exports;
};
"""
let gorilla = require('./lib/gorilla')
let serialized-prelude = yield gorilla.get-serialized-prelude()
let mutable code = """
;(function (root) {
"use strict";
var GorillaScript = (function (realRequire) {
function require(path) {
var has = Object.prototype.hasOwnProperty;
if (has.call(require._cache, path)) {
return require._cache[path];
} else if (has.call(require, path)) {
var func = require[path];
delete require[path];
return require._cache[path] = func.call({});
} else if (realRequire) {
return realRequire(path);
}
}
require._cache = {};
$(parts.join("\n").split("\n").join("\n "))
require("./browser");
return require("./gorilla").withPrelude($(serialized-prelude.split("\n").join("\n ")));
}(typeof module !== "undefined" && typeof require === "function" ? require : void 0));
if (typeof define === "function" && define.amd) {
define(function () { return GorillaScript; });
} else {
root.GorillaScript = GorillaScript;
}
}(this));
"""
grunt.file.write "extras/gorillascript.js", code
grunt.log.writeln 'File "extras/gorillascript.js" created.'
promise.then(
#-> done()
#(e)
grunt.log.error e?.stack or e
done(false))
grunt.register-task "test", #
if @args.length > 0
grunt.config(
'gorilla.test.files.0.src',
@args.map #(arg) -> "**/$(arg).gs"
)
grunt.task.run(["clean:test", "gorilla:test", "mochaTest:test"])
grunt.register-task "check-env-cov", "Verify that GORILLA_COV is set", #
unless process.env.GORILLASCRIPT_COV
grunt.log.error "You must set the GORILLASCRIPT_COV environment variable"
false
grunt.register-task "test-cov", ["check-env-cov", "clean:test", "gorilla:test", "mochaTest:test-cov"]
grunt.register-task "default", ["build", "test", "browser"]
grunt.register-task "full", ["default", "uglify"]