-
Notifications
You must be signed in to change notification settings - Fork 106
/
Gruntfile.js
275 lines (257 loc) · 9.15 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
var createIndex = function (grunt, taskname) {
'use strict';
var conf = grunt.config('index')[taskname],
tmpl = grunt.file.read(conf.template);
// register the task name in global scope so we can access it in the .tmpl file
grunt.config.set('currentTask', {name: taskname});
grunt.file.write(conf.dest, grunt.template.process(tmpl));
grunt.log.writeln('Generated \'' + conf.dest + '\' from \'' + conf.template + '\'');
};
/*global module:false*/
module.exports = function(grunt) {
'use strict';
// Project configuration.
// Put files to be included in build here
var ownJsFiles = [
'js/marked.js',
'js/init.js',
'js/logging.js',
'js/stage.js',
'js/main.js',
'js/util.js',
'js/modules.js',
'js/basic_skeleton.js',
'js/bootstrap.js',
'js/gimmicker.js',
// gimmicks
'js/gimmicks/alerts.js',
'js/gimmicks/colorbox.js',
'js/gimmicks/carousel.js',
'js/gimmicks/disqus.js',
'js/gimmicks/facebooklike.js',
'js/gimmicks/forkmeongithub.js',
//'js/gimmicks/github_gist.js',
'js/gimmicks/gist.js',
'js/gimmicks/googlemaps.js',
'js/gimmicks/highlight.js',
'js/gimmicks/iframe.js',
'js/gimmicks/math.js',
// 'js/gimmicks/leaflet.js',
'js/gimmicks/themechooser.js',
'js/gimmicks/twitter.js',
'js/gimmicks/youtube_embed.js',
'js/gimmicks/chart.js',
'js/gimmicks/yuml.js'
],
internalCssFiles = [
'extlib/css/colorbox.css'
],
// ONLY PUT ALREADY MINIFIED FILES IN HERE!
internalJsFiles = [
'extlib/js/jquery.colorbox.min.js'
],
// files that we inline in the fat release (basically everything)
// ONLY PUT ALREADY MINIFIED FILES IN HERE!
externalJsFiles = [
'extlib/js/jquery-3.2.0.min.js',
'extlib/js/bootstrap-3.0.0.min.js',
// Highlight.js crashes when included inline. Included script tag in index.tmpl for usage.
//'extlib/js/highlight-7.3.min.js'
],
externalCssFiles = [
'extlib/css/highlight.github.css',
'extlib/css/bootstrap-3.0.0.min.css',
];
// Map across above directories to add mdwiki/ at start
var addMdwikiFolder = function(fileRef) {
if(fileRef.startsWith('mdwiki/')) {
return fileRef;
}
return 'mdwiki/' + fileRef;
}
grunt.initConfig({
// Metadata.
pkg: {
name: 'MDwiki-OLE',
version: '0.6.3'
},
ownJsFiles: ownJsFiles.map(addMdwikiFolder),
internalCssFiles: internalCssFiles.map(addMdwikiFolder),
internalJsFiles: internalJsFiles.map(addMdwikiFolder),
externalJsFiles: externalJsFiles.map(addMdwikiFolder),
externalCssFiles: externalCssFiles.map(addMdwikiFolder),
// references we add in the slim release (stuff available on CDN locations)
// Not used for open-learning-exchange, but left in as option
externalJsRefs: [
'ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js',
'netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js',
'yandex.st/highlightjs/7.3/highlight.min.js'
],
externalCssRefs: [
'netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css',
'yandex.st/highlightjs/7.3/styles/github.min.css'
// 'www.3solarmasses.com/retriever-bootstrap/css/retriever.css'
// '3solarmasses.com/corgi-bootstrap/css/corgi.css'
],
concat: {
options: {
//banner: '<%= banner %>',
stripBanners: true
},
dev: {
src: '<%= ownJsFiles %>',
dest: 'mdwiki/dist/<%= pkg.name %>.js'
}
},
uglify: {
options: {
// banner: '<%= banner %>'
},
dist: {
src: '<%= concat.dev.dest %>',
dest: 'mdwiki/dist/<%= pkg.name %>.min.js'
}
},
index: {
fat: {
template: 'mdwiki/index.tmpl',
dest: 'mdwiki/dist/mdwiki.html'
},
slim: {
template: 'mdwiki/index.tmpl',
dest: 'mdwiki/dist/mdwiki-slim.html'
},
debug: {
template: 'mdwiki/index.tmpl',
dest: 'mdwiki/dist/mdwiki-debug.html'
}
},
/* make it use .jshintrc */
jshint: {
options: {
curly: false,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
unused: false,
boss: true,
eqnull: true,
browser: true,
globals: {
jQuery: true,
marked: true,
google: true,
hljs: true,
/* leaflet.js*/
L: true,
console: true,
Chart: true
}
},
/*gruntfile: {
src: 'Gruntfile.js'
},*/
js: {
src: ['mdwiki/js/*.js', 'mdwiki/js/**/*.js', '!mdwiki/js/marked.js']
}
},
lib_test: {
src: ['mdwiki/lib/**/*.js', 'mdwiki/test/**/*.js']
},
copy: {
release_fat: {
expand: false,
flatten: true,
src: [ 'mdwiki/dist/mdwiki.html' ],
dest: 'mdwiki/release/mdwiki-<%= grunt.config("pkg").version %>/mdwiki.html'
},
release_slim: {
expand: false,
flatten: true,
src: [ 'mdwiki/dist/mdwiki-slim.html' ],
dest: 'mdwiki/release/mdwiki-<%= grunt.config("pkg").version %>/mdwiki-slim.html'
},
release_debug: {
expand: false,
flatten: true,
src: [ 'mdwiki/dist/mdwiki-debug.html' ],
dest: 'mdwiki/release/mdwiki-<%= grunt.config("pkg").version %>/mdwiki-debug.html'
},
release_templates: {
expand: true,
flatten: true,
src: [ 'mdwiki/release_templates/*' ],
dest: 'mdwiki/release/mdwiki-<%= grunt.config("pkg").version %>/'
},
// Added for OLE. Release copies the fat version to index.html, devel does same with debug
OLE_release: {
expand: false,
flatten: true,
src: [ 'mdwiki/dist/mdwiki.html' ],
dest: 'index.html'
},
OLE_devel: {
expand: false,
flatten: true,
src: [ 'mdwiki/dist/mdwiki-debug.html' ],
dest: 'index.html'
}
},
shell: {
zip_release: {
options: {
stdout: true
},
command: 'cd release && zip -r mdwiki-<%= grunt.config("pkg").version %>.zip mdwiki-<%= grunt.config("pkg").version %>'
}
},
watch: {
files: [
'Gruntfile.js',
'mdwiki/js/*.js',
'mdwiki/js/**/*.js',
'mdwiki/index.tmpl'
],
tasks: ['devel']
},
reload: {
port: 35729,
liveReload: {}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-reload');
grunt.registerTask('index_slim', 'Generate slim mdwiki.html, most scripts on CDN', function() {
createIndex(grunt, 'slim');
});
grunt.registerTask('index_fat', 'Generate mdwiki-fat.html, inline all scripts', function() {
createIndex(grunt, 'fat');
});
grunt.registerTask('index_debug', 'Generate mdwiki-fat.html, inline all scripts', function() {
createIndex(grunt, 'debug');
});
grunt.registerTask('release-slim',[ 'jshint', 'concat:dev', 'uglify:dist', 'index_slim' ]);
grunt.registerTask('release-fat', [ 'jshint', 'concat:dev', 'uglify:dist', 'index_fat' ]);
/* Debug is basically the fat version but without any minifing */
grunt.registerTask('release-debug', [ 'jshint', 'concat:dev', 'index_debug' ]);
grunt.registerTask('devel', [ 'release-debug','copy:OLE_devel', 'reload', 'watch' ]);
grunt.registerTask('release',[
'release-slim', 'release-fat', 'release-debug',
'copy:release_slim', 'copy:release_fat', 'copy:release_debug', 'copy:release_templates','copy:OLE_release',
'shell:zip_release'
]);
// Default task.
grunt.registerTask('default',
[ 'release-slim', 'release-fat', 'release-debug' ]
);
};