Newer
Older
//------------------------------------------------------------------------------
// This file is part of Mentat system (https://mentat.cesnet.cz/).
//
// Copyright (C) since 2011 CESNET, z.s.p.o (http://www.ces.net/)
// Author: Jan Mach <jan.mach@cesnet.cz>
// Use of this source is governed by the MIT license, see LICENSE file.
//------------------------------------------------------------------------------
function minify_json_file(src, tgt) {
src_content = grunt.file.readJSON(src);
tgt = tgt.replace(/\.json$/, '.min.json')
grunt.file.write(
tgt,
JSON.stringify(src_content)
);
console.log("Minified JSON file '" + src + "' to '" + tgt + "'");
}
pkg: grunt.file.readJSON('package.json'),
// Project paths to important directories.
'web_dir': 'lib/hawat/',
Jan Mach
committed
'web_static_dir': 'lib/hawat/blueprints/design/static/'
},
// ---------------------------------------------------------------------
Jan Mach
committed
// Cleanup web UI directory
webui: {
Jan Mach
committed
"<%= project_paths.web_static_dir %>vendor"
}
},
// ---------------------------------------------------------------------
Jan Mach
committed
// Compile language dictionaries.
Jan Mach
committed
pybabel_hawat: {
Jan Mach
committed
command: 'make hpybabel-compile'
}
},
// ---------------------------------------------------------------------
// Copy certain files to appropriate locations.
Jan Mach
committed
// Copy components for web user interface.
webui: {
files: [
// ----- Popper.js
{
expand: true,
flatten: true,
cwd: 'node_modules/popper.js/dist/umd/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/popper.js/js/'
},
Jan Mach
committed
{
expand: true,
flatten: true,
cwd: 'node_modules/bootstrap/dist/css/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/bootstrap/css/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/bootstrap/dist/fonts/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/bootstrap/fonts/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/bootstrap/dist/js/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/bootstrap/js/'
},
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
// ----- CLDRJS.
{
expand: true,
cwd: 'node_modules/cldrjs/dist/',
src: './cldr.js',
dest: '<%= project_paths.web_static_dir %>vendor/cldrjs'
},
{
expand: true,
cwd: 'node_modules/cldrjs/dist/cldr/',
src: './*.js',
dest: '<%= project_paths.web_static_dir %>vendor/cldrjs/cldr'
},
// ----- CLDR.
{
expand: true,
cwd: 'node_modules/cldr-data/main/cs/',
src: './*.json',
dest: '<%= project_paths.web_static_dir %>vendor/cldr/main/cs'
},
{
expand: true,
cwd: 'node_modules/cldr-data/main/en/',
src: './*.json',
dest: '<%= project_paths.web_static_dir %>vendor/cldr/main/en'
},
{
expand: true,
cwd: 'node_modules/cldr-data/supplemental/',
src: './*.json',
dest: '<%= project_paths.web_static_dir %>vendor/cldr/supplemental'
},
{
expand: true,
cwd: 'node_modules/iana-tz-data/',
src: './iana-tz-data.json',
dest: '<%= project_paths.web_static_dir %>vendor/iana-tz-data'
},
// ----- Globalize.
{
expand: true,
cwd: 'node_modules/globalize/dist/',
src: './globalize.js',
dest: '<%= project_paths.web_static_dir %>vendor/globalize'
},
{
expand: true,
cwd: 'node_modules/globalize/dist/globalize/',
src: './*.js',
dest: '<%= project_paths.web_static_dir %>vendor/globalize/globalize'
},
// ----- D3
{
expand: true,
flatten: true,
cwd: 'node_modules/d3/',
src: './d3*.js',
dest: '<%= project_paths.web_static_dir %>vendor/d3/js/'
},
// ----- NVD3
{
expand: true,
flatten: true,
cwd: 'node_modules/nvd3/build/',
src: './*.js*',
dest: '<%= project_paths.web_static_dir %>vendor/nvd3/js/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/nvd3/build/',
src: './*.css*',
dest: '<%= project_paths.web_static_dir %>vendor/nvd3/css/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/moment/min/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/moment/js/'
},
Jan Mach
committed
{
expand: true,
flatten: true,
cwd: 'node_modules/bootstrap-select/dist/css/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/bootstrap-select/css/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/bootstrap-select/dist/js/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/bootstrap-select/js/'
},
// ----- eonasdan-bootstrap-datetimepicker
{
expand: true,
flatten: true,
cwd: 'node_modules/eonasdan-bootstrap-datetimepicker/build/css/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/bootstrap-datetimepicker/css/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/eonasdan-bootstrap-datetimepicker/build/js/',
src: './*',
dest: '<%= project_paths.web_static_dir %>vendor/bootstrap-datetimepicker/js/'
},
Jan Mach
committed
{
expand: true,
flatten: true,
cwd: 'node_modules/@fortawesome/fontawesome-free/css/',
Jan Mach
committed
src: './**',
dest: '<%= project_paths.web_static_dir %>vendor/font-awesome/css/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/@fortawesome/fontawesome-free/webfonts/',
Jan Mach
committed
src: './**',
dest: '<%= project_paths.web_static_dir %>vendor/font-awesome/webfonts/'
Jan Mach
committed
},
Jan Mach
committed
{
expand: true,
flatten: true,
cwd: 'node_modules/jquery/dist/',
src: './jquery.min.js',
dest: '<%= project_paths.web_static_dir %>vendor/jquery/js/'
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
},
// ----- DataTables.net
{
expand: true,
flatten: true,
cwd: 'node_modules/datatables.net/js/',
src: './*.js',
dest: '<%= project_paths.web_static_dir %>vendor/datatables/js/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/datatables.net-plugins/',
src: [
'./integration/bootstrap/3/dataTables.bootstrap*.js'
],
dest: '<%= project_paths.web_static_dir %>vendor/datatables/js/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/datatables.net-plugins/',
src: [
'./integration/bootstrap/3/dataTables.bootstrap.css',
'./integration/font-awesome/dataTables.fontAwesome.css'
],
dest: '<%= project_paths.web_static_dir %>vendor/datatables/css/'
},
{
expand: true,
flatten: true,
cwd: 'node_modules/datatables.net-plugins/i18n/',
src: [
'./*.lang'
],
dest: '<%= project_paths.web_static_dir %>vendor/datatables/i18n/'
},
Jan Mach
committed
]
// ---------------------------------------------------------------------
// Strip comments from source files
comments: {
// Strip comments from datatables localization files, otherwise they
// are not valid JSON files and table localization does not work.
dti18n: {
options: {
singleline: true,
multiline: true
},
src: [ '<%= project_paths.web_static_dir %>vendor/datatables/i18n/*.lang']
},
}
});
// ---------------------------------------------------------------------
require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
require('time-grunt')(grunt);
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
326
327
328
329
330
// Subtask for minification of CLDR JSON files.
grunt.registerTask('minify-cldrs', function() {
// Minify IANA timezone metadata.
[
[
'node_modules/iana-tz-data/iana-tz-data.json',
'<%= project_paths.web_dir %>templates/iana-tz-data/iana-tz-data.json'
],
[
'node_modules/iana-tz-data/iana-tz-data.json',
'<%= project_paths.web_static_dir %>vendor/iana-tz-data/iana-tz-data.json'
]
].forEach(function(item) {
src = grunt.template.process(item[0]);
tgt = grunt.template.process(item[1]);
minify_json_file(src, tgt);
});
// Minify CLDR metadata.
[
{
expand: true,
cwd: 'node_modules/cldr-data/main/cs/',
src: './*.json',
dest: '<%= project_paths.web_static_dir %>vendor/cldr/main/cs'
},
{
expand: true,
cwd: 'node_modules/cldr-data/main/en/',
src: './*.json',
dest: '<%= project_paths.web_static_dir %>vendor/cldr/main/en'
},
{
expand: true,
cwd: 'node_modules/cldr-data/supplemental/',
src: './*.json',
dest: '<%= project_paths.web_static_dir %>vendor/cldr/supplemental'
}
].forEach(function(item) {
file_mapping = grunt.file.expandMapping(item.src, item.dest, item);
file_mapping.forEach(function(subitem) {
src = grunt.template.process(subitem.src[0]);
tgt = grunt.template.process(subitem.dest);
minify_json_file(src, tgt);
});
});
});
// ---------------------------------------------------------------------
// Setup custom task(s).
// ---------------------------------------------------------------------
grunt.registerTask(
'webui',
'(RUN) Build and install web user interface dependencies.',
['clean:webui', 'shell:pybabel_hawat', 'copy:webui', 'comments', 'minify-cldrs']
);
grunt.registerTask(
'default',
'(RUN) Alias for webui.',
['webui']
);