This repository has been archived by the owner on Nov 23, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
/
grunt.js
114 lines (103 loc) · 3.4 KB
/
grunt.js
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
module.exports = function(grunt) {
grunt.initConfig({
lint: {
src: [
'./src/*.js'
]
},
jison: {
'./lib/typeparser.js': './src/typegrammar.js',
'./lib/parser.js': './src/grammar.js'
},
cjsify: {
'roy.js': {
entry: 'src/compile.js',
dir: __dirname,
options: {
'export': 'roy',
'ignoreMissing': true,
'node': false
}
}
},
jasmine: {
src: './test'
},
min: {
'roy-min.js': 'roy.js'
},
watch: {
parsers: {
files: './src/*grammar.js',
tasks: 'jison'
},
jasmine: {
files: ['./src/*.js', './test/*Spec.js'],
tasks: 'jasmine'
}
},
jshint: {
options: {
es3: true,
indent: 4,
noarg: true,
node: true,
trailing: true,
undef: true,
unused: true
}
}
});
grunt.registerMultiTask('jison', 'Parser generator by jison.', function() {
var Parser = require('jison').Parser,
grammar = require(this.data).grammar;
parser = new Parser(grammar, {debug: grunt.option('debug')}),
fs = require('fs');
fs.writeFileSync(this.target, parser.generate());
});
grunt.registerMultiTask('cjsify', 'Bundling by commonjs-everywhere.', function() {
var cjsify = require('commonjs-everywhere').cjsify,
escodegen = require('escodegen'),
target = this.target,
ast = cjsify(this.data.entry, this.data.dir, this.data.options),
output = escodegen.generate(ast);
grunt.file.write(target, output);
});
// Watching the task doesn't work. Sadly jasmine-node
// executeSpecsInFolder is not idempotent
grunt.registerMultiTask('jasmine', 'Testing by jasmine.', function() {
var path = require('path'),
specDir = this.file.src,
badCache = grunt.file.expand(specDir).concat([
path.dirname(require.resolve("jasmine-node")),
]),
jasmine,
done = this.async(),
key;
// Would be nice to use grunt.file.clearRequireCache
grunt.utils._.each(require.cache, function(v, k) {
var isBad = grunt.utils._.any(badCache, function(dir) {
return k.indexOf(path.resolve(dir)) === 0;
});
if(!isBad) return;
delete require.cache[k];
});
jasmine = require("jasmine-node");
// Not nice (necessary for jasmine-node's asyncSpecWait, etc)
for(key in jasmine) if(jasmine[key] instanceof Function) global[key] = jasmine[key];
function onComplete(runner) {
if (runner.results().failedCount > 0) {
process.exit(1);
return;
}
done(true);
};
jasmine.executeSpecsInFolder({
'specFolders': [specDir],
'onComplete': onComplete,
'isVerbose': false,
'showColors': true
});
});
grunt.registerTask('default', 'jison lint jasmine cjsify min');
};