forked from pcottle/learnGitBranching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
259 lines (238 loc) · 7.82 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
var _ = require('underscore');
var fs = require('fs');
// Haha, this is so tricky. so we have a template for index.html to stick
// in the hashed JS and style files -- that template also contains
// templates used in the app. in order to avoid evaluating those
// templates, we change the regexes so we can effectively nest templates
_.templateSettings.interpolate = /\{\{(.+?)\}\}/g;
_.templateSettings.escape = /\{\{\{(.*?)\}\}\}/g;
_.templateSettings.evaluate = /\{\{-(.*?)\}\}/g;
// precompile for speed
var indexFile = fs.readFileSync('src/template.index.html').toString();
var indexTemplate = _.template(indexFile);
/**
* This is SUPER jank but I cant get the underscore templating to evaluate
* correctly with custom regexes, so I'm just going to use interpolate
* and define the strings here.
*/
var prodDependencies = [
'<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/4.1.1/es5-shim.min.js"></script>',
'<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>',
'<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>',
'<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>'
];
var devDependencies = [
'<script src="lib/jquery-1.8.0.min.js"></script>',
'<script src="lib/underscore-min.js"></script>',
'<script src="lib/raphael-min.js"></script>',
'<script src="lib/es5-shim.min.js"></script>'
];
/*global module:false*/
module.exports = function(grunt) {
// eventually have sound...?
grunt.registerTask('compliment', 'Stay motivated!', function() {
var compliments = grunt.config('compliment.compliments');
var index = Math.floor(Math.random() * compliments.length);
grunt.log.writeln(compliments[index]);
});
grunt.registerTask('lintStrings', 'Find if an INTL string doesnt exist', function() {
var child_process = require('child_process');
child_process.exec('node src/js/intl/checkStrings', function(err, output) {
grunt.log.writeln(output);
});
});
var buildIndex = function(config) {
grunt.log.writeln('Building index...');
// first find the one in here that we want
var buildFiles = fs.readdirSync('build');
var hashedMinFile;
if (buildFiles.length == 2) {
grunt.log.writeln('Assuming debug mode wanted');
hashedMinFile = 'bundle.js';
}
var jsRegex = /bundle\.min\.\w+\.js/;
_.each(buildFiles, function(jsFile) {
if (jsRegex.test(jsFile)) {
if (hashedMinFile) {
throw new Error('more than one hashed file: ' + jsFile + hashedMinFile);
}
hashedMinFile = jsFile;
}
});
if (!hashedMinFile) { throw new Error('no hashed min file found!'); }
grunt.log.writeln('Found hashed js file: ' + hashedMinFile);
var styleRegex = /main\.\w+\.css/;
var hashedStyleFile;
_.each(buildFiles, function(styleFile) {
if (styleRegex.test(styleFile)) {
if (hashedStyleFile) {
throw new Error('more than one hashed style: ' + styleFile + hashedStyleFile);
}
hashedStyleFile = styleFile;
}
});
if (!hashedStyleFile) { throw new Error('no style found'); }
grunt.log.writeln('Found hashed style file: ' + hashedStyleFile);
// output these filenames to our index template
var outputIndex = indexTemplate({
jsFile: hashedMinFile,
styleFile: hashedStyleFile,
jsDependencies: config.isProd ?
prodDependencies.join("\n") :
devDependencies.join("\n")
});
fs.writeFileSync('index.html', outputIndex);
};
grunt.registerTask('buildIndex', 'stick in hashed resources', buildIndex.bind(null, {isProd: true}));
grunt.registerTask('buildIndexDev', 'stick in hashed resources', buildIndex.bind(null, {isProd: false}));
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
all: [
'Gruntfile.js',
'src/__tests__/spec/*.js',
'src/js/**/*.js',
'src/js/**/**/*.js',
'src/levels/**/*.js'
],
options: {
ignores: [
'src/js/**/*.ios.js',
'src/js/native_react_views/*.js'
],
curly: true,
// sometimes triple equality is just redundant and unnecessary
eqeqeq: false,
// i know my regular expressions
regexp: false,
// i think it's super weird to not use new on a constructor
nonew: false,
// these latedefs are just annoying -- no pollution of global scope
latedef: false,
// use this in mocks
forin: false,
// This gets annoying
globalstrict: false,
// for use strict warnings
node: true,
///////////////////////////////
// All others are true
//////////////////////////////
immed: true,
newcap: true,
noarg: true,
bitwise: true,
sub: true,
undef: true,
unused: false,
trailing: true,
devel: true,
jquery: true,
nonstandard: true,
boss: true,
eqnull: true,
browser: true,
debug: true,
globals: {
casper: true,
Raphael: true,
require: true,
console: true,
describe: true,
expect: true,
it: true,
runs: true,
waitsFor: true,
exports: true,
module: true,
prompt: true,
process: true
}
},
},
compliment: {
compliments: [
"Wow peter great work!",
"Such a professional dev environment",
"Can't stop the TRAIN",
"git raging"
]
},
hash: {
js: {
src: 'build/bundle.min.js',
dest: 'build/'
},
css: {
src: 'src/style/main.css',
dest: 'build/'
}
},
watch: {
files: '<config:lint.files>',
tasks: 'watching'
},
uglify: {
build: {
src: ['build/bundle.js'],
dest: 'build/bundle.min.js'
}
},
clean: ['build/*'],
shell: {
gitAdd: {
command: 'git add build/'
},
casperTest: {
command: 'echo "Running $(ls -1 ./src/__tests__/casperjs/*_test.js | wc -l) tests" && ' +
'ls -1 ./src/__tests__/casperjs/*_test.js | while IFS= read -r line; do casperjs test $line; done'
}
},
jasmine_node: {
projectRoot: './src/js/__tests__/',
forceExit: true,
verbose: true,
requirejs: false
},
browserify: {
options: {
transform: [require('grunt-react').browserify],
ignore: [
'src/__tests__/casperjs/*.js',
'src/js/__tests__/create.js',
'src/js/__tests__/*.js',
'src/js/native_react_views/*.js',
'src/js/**/*.ios.js'
]
},
dist: {
files: {
'build/bundle.js': [
'src/**/*.js',
'src/**/*.jsx',
'src/js/**/*.js',
'src/js/**/*.jsx'
]
},
}
},
});
// all my npm helpers
grunt.loadNpmTasks('grunt-jsxhint');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-hash');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-shell-spawn');
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-react');
grunt.registerTask('build',
['clean', 'browserify', 'uglify', 'hash', 'buildIndex', 'shell:gitAdd', 'jasmine_node', 'jshint', 'lintStrings', 'compliment']
);
grunt.registerTask('lint', ['jshint', 'compliment']);
grunt.registerTask('fastBuild', ['clean', 'browserify', 'hash', 'buildIndexDev', 'jshint']);
grunt.registerTask('watching', ['fastBuild', 'jasmine_node', 'jshint', 'lintStrings']);
grunt.registerTask('default', ['build']);
grunt.registerTask('test', ['jasmine_node']);
grunt.registerTask('casperTest', ['shell:casperTest']);
};