forked from probmods/webppl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
149 lines (135 loc) · 4.25 KB
/
Gruntfile.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
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
145
146
147
148
149
'use strict';
var _ = require('underscore');
var open = require('open');
var child_process = require('child_process');
var jslintSettings = {
options: {
flags: ['--flagfile .gjslintrc'],
reporter: {
name: 'console'
},
force: false
},
lib: {
src: [
'Gruntfile.js',
'src/header.wppl',
'src/**/!(dists|enumerate|elbo|eubo|ScoreAggregator).js'
]
},
test: {
src: ['tests/**/*.js']
},
wppl: {
src: [
'tests/test-data/**/*.wppl',
'examples/*.wppl'
]
}
};
module.exports = function(grunt) {
grunt.initConfig({
nodeunit: {
all: ['tests/test-*.js']
},
jshint: {
files: [
'Gruntfile.js',
'src/header.wppl',
'src/**/*.js',
'tests/**/*.js'
],
options: {
maxerr: 500,
camelcase: true,
nonew: true,
curly: true,
noarg: true,
trailing: true,
forin: true,
noempty: true,
node: true,
eqeqeq: true,
strict: false,
evil: true,
undef: true,
bitwise: true,
browser: true,
gcl: true,
newcap: false
}
},
gjslint: jslintSettings,
fixjsstyle: jslintSettings,
clean: ['bundle/*.js'],
watch: {
ad: {
files: ['**/*.ad.js'],
tasks: ['build']
}
}
});
function browserifyArgs(args) {
var pkgArg = '';
var requires = _.chain(_.toArray(args))
.map(function(name) { return ['--require', name]; })
.flatten().value();
pkgArg = ' -t [' + ['./src/bundle.js'].concat(requires).join(' ') + ']';
return pkgArg + ' -g brfs src/browser.js -o bundle/webppl.js';
}
grunt.loadNpmTasks('grunt-gjslint');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['gjslint', 'nodeunit']);
grunt.registerTask('test', ['nodeunit']);
grunt.registerTask('lint', ['gjslint']);
grunt.registerTask('hint', ['jshint']);
grunt.registerTask('fixstyle', ['fixjsstyle']);
grunt.registerTask('travis-phantomjs', ['bundle', 'test-phantomjs']);
grunt.registerTask('build', 'Build WebPPL.', function() {
var output = child_process.execSync('scripts/adify');
grunt.log.writeln(output);
});
grunt.registerTask('build-watch', 'Run the build task on fs changes.', ['watch']);
grunt.registerTask('bundle', 'Create browser bundle.', function() {
var taskArgs = (arguments.length > 0) ? ':' + _.toArray(arguments).join(':') : '';
grunt.task.run('browserify' + taskArgs, 'uglify');
});
grunt.registerTask('browserify', 'Generate "bundle/webppl.js".', function() {
child_process.execSync('mkdir -p bundle');
child_process.execSync('browserify' + browserifyArgs(arguments));
});
grunt.registerTask('browserify-watch', 'Run the browserify task on fs changes.', function() {
var done = this.async();
child_process.execSync('mkdir -p bundle');
var args = '-v' + browserifyArgs(arguments);
var p = child_process.spawn('watchify', args.split(' '));
p.stdout.on('data', grunt.log.writeln);
p.stderr.on('data', grunt.log.writeln);
p.on('close', done);
});
grunt.registerTask('uglify', 'Generate "bundle/webppl.min.js".', function() {
child_process.execSync('mkdir -p bundle');
child_process.execSync('uglifyjs bundle/webppl.js -b ascii_only=true,beautify=false > bundle/webppl.min.js');
});
grunt.registerTask('test-browser', 'Run browser tests in default browser.', function() {
open('tests/browser/index.html', process.env.BROWSER);
});
grunt.registerTask('test-phantomjs', 'Run browser tests in phantomjs.', function() {
var timeout = 10; // seconds
try {
var cmd = 'phantomjs node_modules/qunit-phantomjs-runner/runner-list.js tests/browser/index.html ' + timeout;
var output = child_process.execSync(cmd);
grunt.log.writeln(output);
} catch (e) {
grunt.log.writeln(e.output.join('\n'));
throw e;
}
});
grunt.registerTask('generate-docs', 'Generate documentation.', function() {
var output = child_process.execSync('scripts/distributionDocs > docs/distributions.rst');
grunt.log.writeln(output);
});
};