forked from skeeto/webgl-game-of-life
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
172 lines (146 loc) · 5.08 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
module.exports = function(grunt) {
grunt.initConfig({
/*--- Data for templates ---*/
// Files to lint for terminating newlines and trailing whitespace
lintspaces_src: [
'.gitignore',
'.jshintrc',
'config.rb',
'glsl/*',
'Gruntfile.js',
'index.html',
'js/**/*.js',
'package.json',
'README.md',
'scss/*.scss',
'tests/**/*.js'
],
/*--- Core tasks ---*/
// Lint for terminating newlines and trailing whitespace
lintspaces: {
webgol: {
options: {
newline: true, // Check for one newline at end of every file
trailingspaces: true // Check for any trailing whitespace
},
src: ['<%= lintspaces_src %>']
}
},
// Minify GLSL shaders
'string-replace': {
webgol: {
options: {
replacements: [
{
// Remove single-line comments
pattern: / *\/\/.*$/gm,
replacement: ''
},
{
// Remove multi-line comments
pattern: /\/\*[\s\S]+?\*\//g,
replacement: ''
},
{
// Collapse multiple newlines
pattern: /\n+/g,
replacement: '\n'
},
{
// Collapse whitespace
pattern: / +/g,
replacement: ' '
}
]
},
files: [
{
expand: true, // Enable dynamic expansion
cwd: 'glsl/', // src matches are relative to this path
src: '*', // Pattern to match
dest: 'glslmin/' // Destination path prefix
}
]
}
},
// Lint JavaScript files
jshint: {
webgol: {
options: {
jshintrc: '.jshintrc'
},
src: [
'js/**/*.js',
'tests/**/*.js'
]
}
},
// Insert minified GLSL shaders into shader-sources.js
includereplace: {
webgol: {
options: {
includesDir: 'glslmin/',
processIncludeContents: function(includeContents) {
// Replace newlines with \n to create valid JavaScript string literals
return includeContents.replace(/\n/g, '\\n');
}
},
src: 'js/shader-sources.js',
dest: 'jsmin/shader-sources.js'
}
},
// Compile SCSS to CSS
compass: {
webgol: {
options: {
config: 'config.rb'
}
}
},
/*--- Dev tasks ---*/
// Concatenate JavaScript files without minifying
concat: {
webgol: {
files: {
'jsmin/gol.js': ['js/gol/**/*.js'],
'jsmin/main.js': ['js/main.js']
}
}
},
/*--- Prod tasks ---*/
// Concatenate and minify JavaScript files
uglify: {
webgol: {
files: {
'jsmin/shader-sources.js': ['jsmin/shader-sources.js'],
'jsmin/gol.js': ['js/gol/**/*.js'],
'jsmin/main.js': ['js/main.js']
}
}
},
/*--- Test tasks ---*/
// Run Jasmine tests
jasmine: {
webgol: {
options: {
specs: 'tests/specs/**/*.js',
helpers: 'tests/helpers/**/*.js'
},
src: 'js/gol/**/*.js'
}
}
});
grunt.loadNpmTasks('grunt-lintspaces');
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-include-replace');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.registerTask('webgol_core', ['lintspaces', 'string-replace', 'jshint', 'includereplace', 'compass']);
grunt.registerTask('webgol_dev', ['webgol_core', 'concat']);
grunt.registerTask('webgol_prod', ['webgol_core', 'uglify']);
grunt.registerTask('webgol_test', ['lintspaces', 'jshint', 'jasmine']);
grunt.registerTask('default', ['webgol_dev']);
};