-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.js
182 lines (163 loc) · 5.09 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
var path = require('path');
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
files: {
js: [
'public/js/vendor/jquery.js',
'public/js/vendor/jquery.stickytableheaders.js',
'public/js/vendor/underscore.js',
'public/js/vendor/backbone.js',
'public/js/vendor/backbone.queryparams-1.1-shim.js',
'public/js/vendor/backbone.queryparams.js',
'public/js/namespace.js',
'public/js/preload.js',
'public/js/templates.js',
'public/js/modules/utils.js',
'public/js/modules/helpers.js',
'public/js/modules/*.js',
'public/js/main.js',
],
templates: [
'public/js/templates/*.tmpl'
],
},
jst: {
templates: {
options: {
namespace: 'app.templates',
templateSettings: {
variable: 'data'
},
processName: function(filename) {
return path.basename(filename).split('.')[0];
},
prettify: true
},
files: {
'public/js/templates.js': ['<%= files.templates %>']
}
}
},
sass: {
build: {
options: {
sourcemap: true,
style: 'compressed'
},
files: {
'public/build/app.css': 'public/sass/index.scss'
}
}
},
autoprefixer: {
options: {
map: 'public/build/',
},
build: {
src: 'public/build/app.css',
dest: 'public/build/app.css'
}
},
uglify: {
build: {
options: {
mangle: true,
compress: {},
sourceMap: true,
sourceMapRoot: 'public/',
preserveComments: 'some',
},
files: {
'public/build/app.js': ['<%= files.js %>']
}
}
},
watch: {
templates: {
files: '<%= files.templates %>',
tasks: ['jst']
},
sass: {
files: 'public/sass/*.scss',
tasks: ['css']
},
js: {
files: '<%= files.js %>',
tasks: ['js']
},
colors: {
files: 'tasks/colors/*',
tasks: ['colors']
},
histogram: {
files: 'tasks/histogram/*',
tasks: ['histogram']
},
preload: {
files: 'tasks/preload/*',
tasks: ['preload']
}
}
});
grunt.registerTask('colors', 'Generate colors', function() {
var colors = require('./tasks/colors/colors');
var template = grunt.file.read('tasks/colors/colors.tmpl');
var colorNames = colors.map(function(color) { return color.name; });
var css = grunt.template.process(template, {data: {colors: colors}});
grunt.file.write('public/sass/colors.scss', css);
grunt.file.write('tasks/preload/colornames.js', JSON.stringify(colorNames));
});
grunt.registerTask('schools', 'Generate schools', function() {
var done = this.async();
var schools = require('./tasks/schools');
schools.getNames(function(names) {
grunt.file.write('tasks/preload/schoolnames.js', JSON.stringify(names));
done();
});
});
grunt.registerTask('subjects', 'Generate subjects', function() {
var done = this.async();
var subjects = require('./tasks/subjects');
subjects.getNames(function(names) {
grunt.file.write('tasks/preload/subjectnames.js', JSON.stringify(names));
done();
});
});
grunt.registerTask('histogram', 'Generate APS entry histogram', function() {
var done = this.async();
var histogram = require('./tasks/histogram');
histogram(function(data) {
grunt.file.write('tasks/preload/aps.js', JSON.stringify(data.measures));
grunt.file.write('public/js/templates/histogram.tmpl', data.html);
grunt.file.write('public/sass/aps.scss', data.css);
done();
});
});
grunt.registerTask('preload', 'Generate preload.js', function() {
var preload = {
colornames: grunt.file.read('tasks/preload/colornames.js'),
subjectnames: grunt.file.read('tasks/preload/subjectnames.js'),
schoolnames: grunt.file.read('tasks/preload/schoolnames.js'),
aps: grunt.file.read('tasks/preload/aps.js')
};
var template = grunt.file.read('tasks/preload/preload.tmpl');
var content = grunt.template.process(template, {data: preload});
grunt.file.write('public/js/preload.js', content);
});
grunt.registerTask('cleanmap', 'Replace double backslash with forward slash (Windows bug).', function() {
var path = 'public/build/app.map';
var content = grunt.file.read(path);
content = content.replace(/\\{2}/g,'/');
grunt.file.write(path, content);
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-jst');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('css', ['sass', 'autoprefixer']);
grunt.registerTask('js', ['uglify', 'cleanmap']);
grunt.registerTask('generate', ['colors', 'schools', 'subjects', 'preload']);
grunt.registerTask('default', ['generate', 'css', 'jst', 'js']);
};