forked from hhzl/LearnWords2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
325 lines (250 loc) · 8.93 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/* LearnWords2 -- Gruntfile.js
Aim:
Define the tasks for the grunt task runner.
http://gruntjs.com/
Date:
6th February 2017
Contents of the file:
- The "wrapper" function
- Project and task configuration
- Loading Grunt plugins and tasks
- Custom tasks
Structure of the file:
This file contains a single function which takes the
grunt task runner as an argument:
function(grunt) {
grunt.initConfig(aHugeConfigurationObjectForTheTasks);
// When a task is run, Grunt looks for its configuration
// under a property of the same name.
// load tasks from published grunt modules,
// for example the task 'grunt-contrib-clean'
// which cleans up directories
grunt.loadNpmTasks('grunt-contrib-clean');
... load more modules
// define custom tasks.
grunt.registerMultiTask('js','Builds bundle for JavaScript component LW.js', function(){
...
};
... more custom tasks
// define tasks as a sequence of other tasks
grunt.registerTask('build', ['clean:build','js']);
...
}
Available tasks
clean Clean files and folders. *
jshint Validate files with JSHint. *
connect Start a connect web server. *
copy Copy files. *
watch Run predefined tasks whenever watched files change.
js Builds bundle for JavaScript component *
jasmine Creates bundle for Jasmine tests *
csv2json Converts CSV to JSON *
csv2anki Converts CSV to Anki *
json2yaml Converts JSON to YAML *
json2htmlList Converts JSON to HTML *
json2htmlSpelling Converts JSON to a HTML presentation with spelling demo *
htmlreport Alias for "json2htmlList", "copy:pictures" tasks.
spellingpresentation Alias for "json2htmlSpelling", "copy:pictures" tasks.
data Alias for "clean:data", "csv2json", "csv2anki",
"htmlreport" tasks.
build Alias for "clean:build", "jshint:es5", "js" tasks.
demo Alias for "build", "data", "copy:data", "copy:js" tasks.
test Alias for "clean:test", "jasmine" tasks.
default Alias for "demo", "test", "connect", "watch" tasks.
Tasks run in the order specified. Arguments may be passed to tasks that accept
them by using colons, like "lint:files". Tasks marked with * are "multi tasks"
and will iterate over all sub-targets if no argument is specified.
The list of available tasks may change based on tasks directories or grunt
plugins specified in the Gruntfile or via command-line options.
For more information, see http://gruntjs.com/
*/
var path = require('path');
module.exports = function(grunt) {
var p = grunt.file.readYAML('./Grunt_parameters_ini.yml');
console.log('OUTPUT_DIR=',p.OUTPUT_DIR);
console.log('WEB_ROOT=',p.WEB_ROOT);
// =========================================================
// Project configuration.
// =========================================================
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
options: {
force: true
},
data: [path.join(p.WEB_ROOT,'data'),p.OUTPUT_DIR],
odg: [path.join(p.OUTPUT_DIR,'odg')],
build: [path.join(p.DIST_DIR,'**')],
js: [path.join(p.BUILD_DIR,'**')],
test: [path.join(p.BUILD_DIR,'jasmine-bundle.js')]
},
jshint: {
es5: ['src/*.js'],
es6: {options: {
esversion: 6
},
files: {
src: ['Gruntfile.js', 'src/data-conversion/*.js']
}
}
},
csv2anki: {
data: {
src: path.join(p.INPUT_DIR,'csv','**/*.csv'),
dest: path.join(p.OUTPUT_DIR,'anki')
}
},
csv2json: {
data: {
src: path.join(p.INPUT_DIR,'csv','**/*.csv'),
dest: path.join(p.INPUT_DIR,'json')
}
},
json2yaml: {
data: {
src: path.join(p.INPUT_DIR,'json','**/*.json'),
dest: path.join(p.OUTPUT_DIR,'yaml')
}
},
json2htmlList: {
data: {
src: path.join(p.INPUT_DIR,'json','**/*.json'),
dest: path.join(p.OUTPUT_DIR,'html')
}
},
json2htmlSpelling: {
data: {
src: path.join(p.INPUT_DIR,'json','**/*.json'),
dest: path.join(p.OUTPUT_DIR,'html')
}
},
json2odg: {
data: {
src: path.join(p.INPUT_DIR,'json','wordlist_animals*.json'),
dest: path.join(p.OUTPUT_DIR,'odg')
}
},
jasmine:{
browser: {
src: path.join('spec','support','Jasmine.json'),
dest: path.join(p.BUILD_DIR,'jasmine-bundle.js')
}
},
js:{
dist: {
options:{
debug: false
},
src: [path.join('src','index.js')],
dest: path.join(p.DIST_DIR,'LW.js')
},
debug: {
options: {
debug: true
},
src: [path.join('src','index.js')],
dest: path.join(p.DIST_DIR,'LW-debug.js')
}
},
watch:{
options: {
livereload: true
},
test: {
files: [path.join('src','**','*.js'),path.join('spec','**','*.js')],
tasks: ['build','test']
},
html: {
files: [path.join(p.WEB_ROOT,'**','*.html')]
}
},
connect:{
test: {
options: {
base: {
path: p.WEB_ROOT,
options: {
index: 'SpecRunner.html'
}
},
hostname: '*',
livereload: true,
open: true,
useAvailablePort: true,
}
},
demo: {
options: {
base: {
path: p.WEB_ROOT,
options: {
index: 'demo.html'
}
},
hostname: '*',
livereload: true,
open: true,
useAvailablePort: true,
}
}
},
copy: {
data: {
expand: true,
flatten: true,
filter: 'isFile',
src: path.join(p.INPUT_DIR,'json','**'),
dest: path.join(p.WEB_ROOT,'data','json')
},
pictures: {
expand: true,
flatten: true,
filter: 'isFile',
src: path.join(p.INPUT_DIR,'pictures','c10','**'),
dest: path.join(p.OUTPUT_DIR,'html','c10')
},
pictures_odg: {
expand: true,
flatten: true,
filter: 'isFile',
src: path.join(p.INPUT_DIR,'pictures','c10','**'),
dest: path.join(p.OUTPUT_DIR,'odg','pictures','c10')
},
js: {
expand: true,
flatten: true,
src: path.join(p.DIST_DIR,'*'),
dest: path.join(p.WEB_ROOT,'js')
}
}
});
// ====================================================================
// Load grunt tasks
// ====================================================================
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
// ================================================================================
// Custom tasks
// ================================================================================
// load custom tasks
require('./Grunt-customtasks.js')(grunt,p);
require('./Grunt-customtasks-reports.js')(grunt);
require('./Grunt-customtasks-data-conversion.js')(grunt);
// =========================================================================================
// Definition of tasks as sequences of other tasks.
// =========================================================================================
// The following means that the htmlreport task is defined as the call to the
// convertJson2html task followed by the copy:pictures task.
grunt.registerTask('htmlreport',['json2htmlList','copy:pictures']);
grunt.registerTask('spellingpresentation',['json2htmlSpelling','copy:pictures']);
grunt.registerTask('odgreport',['clean:odg','json2odg','copy:pictures_odg']);
grunt.registerTask('data',['clean:data','csv2json','csv2anki','htmlreport']);
grunt.registerTask('build', ['clean:build','jshint:es5','js']);
grunt.registerTask('demo',['build','data','copy:data','copy:js']);
grunt.registerTask('test', ['clean:test','jasmine']);
// The default task is executed if grunt is called without giving a task name
grunt.registerTask('default', ['demo','test','connect','watch']);
};