blob: 25773946fecf6f48d490bb4e17c7cc8ac6b65932 [file] [log] [blame]
Nils Diewald2488d052015-04-09 21:46:02 +00001/**
2 * Grunt build file for Kalamar.
3 * Create assets (based on files in /dev) running
4 * $ grunt
5 * in the current folder.
6 *
7 * @author Nils Diewald
8 */
Nils Diewaldea236742015-03-26 21:55:36 +00009/*
Nils Diewaldea236742015-03-26 21:55:36 +000010 * TODO: Use https://www.npmjs.com/package/grunt-contrib-compress
Nils Diewald2488d052015-04-09 21:46:02 +000011 * for assets.
12 * http://yui.github.io/yuidoc/
13 * TODO: Use https://www.npmjs.com/package/grunt-contrib-yuidoc
Nils Diewald4c221252015-04-21 20:19:25 +000014 * TODO: Implement a LaTeX generator for a pdf of the dokumentation
Nils Diewaldea236742015-03-26 21:55:36 +000015 */
Nils Diewaldc2826192015-05-07 19:23:44 +000016
Nils Diewaldea236742015-03-26 21:55:36 +000017module.exports = function(grunt) {
Akrone91da782017-12-15 17:17:50 +010018 var config;
Akron80055992017-12-20 16:30:52 +010019 var includeFile = 'default';
20 if (grunt.file.exists('kalamar.conf.js')) {
21 includeFile = 'root/kalamar.conf';
Akrone91da782017-12-15 17:17:50 +010022 };
23
24 // Generate requireJS files for l10n
25 var reqTasks = [];
Akrondf5ad372018-07-02 14:47:57 +020026 var uglyFiles = {
27 'public/js/korap-plugin-<%= pkg.pluginVersion %>.js': ['dev/js/src/plugin/client.js']
Akron94477f62018-07-19 12:18:40 +020028 };
Akrondf5ad372018-07-02 14:47:57 +020029
Akrone91da782017-12-15 17:17:50 +010030 for (var i in {'en' : 0, 'de' : 1}) {
31
Akrone91da782017-12-15 17:17:50 +010032 reqTasks.push({
33 options: {
Akron80055992017-12-20 16:30:52 +010034
Akron70821ba2018-07-16 17:24:36 +020035 optimize: "none",
Akrone91da782017-12-15 17:17:50 +010036 baseUrl: 'dev/js/src',
37 paths : {
Akron80055992017-12-20 16:30:52 +010038 'lib': '../lib',
39 'root' : '../../..'
Akrone91da782017-12-15 17:17:50 +010040 },
Akron80055992017-12-20 16:30:52 +010041 wrap: true,
Akrone91da782017-12-15 17:17:50 +010042 // dir : 'public/js',
43 name: 'lib/almond',
Akron80055992017-12-20 16:30:52 +010044 include : [includeFile, "app/" + i],
Akrone91da782017-12-15 17:17:50 +010045 out: 'public/js/kalamar-<%= pkg.version %>-' + i + '.js'
46 }
Akron70821ba2018-07-16 17:24:36 +020047 });
48
49 uglyFiles['public/js/kalamar-<%= pkg.version %>-' + i + '.js'] = ['public/js/kalamar-<%= pkg.version %>-' + i + '.js'];
Akrone91da782017-12-15 17:17:50 +010050 };
51
Nils Diewaldea236742015-03-26 21:55:36 +000052 grunt.initConfig({
53 pkg: grunt.file.readJSON('package.json'),
Nils Diewaldc2826192015-05-07 19:23:44 +000054 requirejs: reqTasks,
Akron70821ba2018-07-16 17:24:36 +020055 uglify: {
56 kalamar : {
Akron5e5cf1e2018-07-25 13:41:25 +020057 files: uglyFiles,
58 options : {
59 sourceMap: {
60 includeSources: true
61 }
62 }
Akron70821ba2018-07-16 17:24:36 +020063 }
64 },
Nils Diewaldea236742015-03-26 21:55:36 +000065 imagemin: {
66 dynamic: {
Akron49bfdbf2016-11-22 21:47:33 +010067 files: [{
68 expand: true,
69 cwd: 'dev/img/',
70 src: ['*.{png,gif,jpg}'],
71 dest: 'public/img/'
72 }]
Nils Diewaldea236742015-03-26 21:55:36 +000073 }
74 },
75 sass: {
76 dist: {
77 options: {
78 style: 'compressed'
79 },
80 files: {
Nils Diewaldce328112015-04-08 22:48:18 +000081 'public/css/kalamar-<%= pkg.version %>.css' : 'dev/scss/kalamar.scss',
Akron49bfdbf2016-11-22 21:47:33 +010082 'dev/css/kalamar.css' : 'dev/scss/kalamar.scss',
Akronb56986f2017-06-29 20:52:29 +020083 'dev/css/kwic.css' : 'dev/scss/main/kwic.scss'
Nils Diewaldea236742015-03-26 21:55:36 +000084 }
85 }
86 },
Nils Diewaldaa17d142015-04-08 23:32:23 +000087 // see https://github.com/gruntjs/grunt-contrib-copy/issues/64
Akrondf5ad372018-07-02 14:47:57 +020088 jasmine: {
89 pivotal: {
90 src: [
91 'dev/js/src/menu.js',
92 'dev/js/src/match.js',
93 'dev/js/src/hint.js',
94 'dev/js/src/vc.js'
95 ],
96 options: {
97 specs: 'dev/js/spec/*Spec.js',
98 vendor: ['dev/js/lib/require.js']
99 }
100 }
101 },
102
103 // see https://github.com/gruntjs/grunt-contrib-copy/issues/64
Nils Diewald2488d052015-04-09 21:46:02 +0000104 // for copying binary files
Nils Diewaldce328112015-04-08 22:48:18 +0000105 copy : {
Nils Diewaldaa17d142015-04-08 23:32:23 +0000106 options: {
Akron49bfdbf2016-11-22 21:47:33 +0100107 process:false
Nils Diewaldaa17d142015-04-08 23:32:23 +0000108 },
109 main: {
Akron49bfdbf2016-11-22 21:47:33 +0100110 files:[
111 {
112 expand: true,
113 cwd: 'dev/font/',
114 src: '**',
115 dest: 'public/font/',
116 filter: 'isFile',
117 nonull: true,
118 timestamp: true
119 },
120 {
121 expand: true,
122 cwd: 'dev/img/',
123 src: 'favicon.ico',
124 dest: 'public/',
125 filter: 'isFile',
126 nonull:true,
127 timestamp:true
128 },
129 {
130 expand: true,
131 cwd: 'dev/img/',
132 src: '*.svg',
133 dest: 'public/img/',
134 filter: 'isFile',
135 nonull:true,
136 timestamp:true
137 }
138 ]
Nils Diewaldaa17d142015-04-08 23:32:23 +0000139 }
Nils Diewaldce328112015-04-08 22:48:18 +0000140 },
Nils Diewaldea236742015-03-26 21:55:36 +0000141 watch: {
Nils Diewaldea236742015-03-26 21:55:36 +0000142 css: {
Akronae8f31c2017-11-28 18:05:52 +0100143 files: ['dev/scss/{util,base,fonts,kalamar,media,no-js}.scss',
Akron2f979122018-07-25 17:00:23 +0200144 'dev/scss/base/flextable.scss',
Akron49f88cc2018-09-11 11:06:19 +0200145 'dev/scss/base/fragment.scss',
Akron49bfdbf2016-11-22 21:47:33 +0100146 'dev/scss/footer/footer.scss',
Akron189b3592016-01-04 20:56:46 +0100147 'dev/scss/sidebar/sidebar.scss',
Akron2f979122018-07-25 17:00:23 +0200148 'dev/scss/header/{header,hint,menu,searchbar,vc,statistics,datepicker}.scss',
Akronbd39a432017-09-20 13:57:13 +0200149 'dev/scss/main/{alertify,intro,koralquery,highlight,kwic,logos,tagger,' +
Akron537bc522018-07-13 19:06:27 +0200150 'main,matchinfo,panel,tree,pagination,query,'+
Akrone8e2c952018-07-04 13:43:12 +0200151 'resultinfo,sidebar,tutorial,plugin,buttongroup}.scss'
Akron49bfdbf2016-11-22 21:47:33 +0100152 ],
153 tasks: ['sass'],
154 options: {
155 spawn: false
156 }
Nils Diewaldea236742015-03-26 21:55:36 +0000157 }
Akron08648842019-03-28 11:55:22 +0100158 },
159 shell: {
160 options: {
161 stderr: false
162 },
163 makeDir: {
164 command : 'mkdir -p ./dev/js/spec/src'
165 },
166 createPage: {
167 command : 'perl script/kalamar get / > ./dev/js/spec/src/page.html'
168 }
Nils Diewald2488d052015-04-09 21:46:02 +0000169 }
Nils Diewaldea236742015-03-26 21:55:36 +0000170 });
171
Nils Diewaldea236742015-03-26 21:55:36 +0000172 grunt.loadNpmTasks('grunt-contrib-imagemin');
173 grunt.loadNpmTasks('grunt-contrib-watch');
174 grunt.loadNpmTasks('grunt-contrib-sass');
Nils Diewaldce328112015-04-08 22:48:18 +0000175 grunt.loadNpmTasks('grunt-contrib-copy');
Akron08648842019-03-28 11:55:22 +0100176 grunt.loadNpmTasks('grunt-shell');
Akron70821ba2018-07-16 17:24:36 +0200177 grunt.loadNpmTasks('grunt-contrib-uglify-es');
Nils Diewald0e6992a2015-04-14 20:13:52 +0000178 grunt.loadNpmTasks('grunt-contrib-requirejs');
Nils Diewalda31a5152015-04-17 21:05:23 +0000179 grunt.registerTask('img', ['imagemin','copy']);
Akron9f64fd02016-02-13 05:51:38 +0100180 grunt.registerTask('js', ['requirejs']);
Nils Diewaldea236742015-03-26 21:55:36 +0000181 grunt.registerTask('css', ['sass']);
Nils Diewaldce328112015-04-08 22:48:18 +0000182 grunt.registerTask(
183 'default',
Akron08648842019-03-28 11:55:22 +0100184 ['requirejs', 'uglify', 'imagemin', 'copy', 'sass','shell:makeDir', 'shell:createPage']
Nils Diewaldce328112015-04-08 22:48:18 +0000185 );
Nils Diewaldea236742015-03-26 21:55:36 +0000186};