blob: dd59ac3439c96e22bd38f77d437f21056c9e7396 [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
Akron7ca73872021-03-08 11:29:11 +010017const sass = require('sass');
18
Nils Diewaldea236742015-03-26 21:55:36 +000019module.exports = function(grunt) {
Akrone91da782017-12-15 17:17:50 +010020 var config;
Akron80055992017-12-20 16:30:52 +010021 var includeFile = 'default';
22 if (grunt.file.exists('kalamar.conf.js')) {
23 includeFile = 'root/kalamar.conf';
Akrone91da782017-12-15 17:17:50 +010024 };
25
26 // Generate requireJS files for l10n
27 var reqTasks = [];
Akrondf5ad372018-07-02 14:47:57 +020028 var uglyFiles = {
29 'public/js/korap-plugin-<%= pkg.pluginVersion %>.js': ['dev/js/src/plugin/client.js']
Akron94477f62018-07-19 12:18:40 +020030 };
Akrondf5ad372018-07-02 14:47:57 +020031
Akrone91da782017-12-15 17:17:50 +010032 for (var i in {'en' : 0, 'de' : 1}) {
33
Akrone91da782017-12-15 17:17:50 +010034 reqTasks.push({
35 options: {
Akron80055992017-12-20 16:30:52 +010036
Akron70821ba2018-07-16 17:24:36 +020037 optimize: "none",
Akrone91da782017-12-15 17:17:50 +010038 baseUrl: 'dev/js/src',
39 paths : {
Akron80055992017-12-20 16:30:52 +010040 'lib': '../lib',
41 'root' : '../../..'
Akrone91da782017-12-15 17:17:50 +010042 },
Akron80055992017-12-20 16:30:52 +010043 wrap: true,
Akrone91da782017-12-15 17:17:50 +010044 // dir : 'public/js',
45 name: 'lib/almond',
Akron80055992017-12-20 16:30:52 +010046 include : [includeFile, "app/" + i],
Akrone91da782017-12-15 17:17:50 +010047 out: 'public/js/kalamar-<%= pkg.version %>-' + i + '.js'
48 }
Akron70821ba2018-07-16 17:24:36 +020049 });
50
51 uglyFiles['public/js/kalamar-<%= pkg.version %>-' + i + '.js'] = ['public/js/kalamar-<%= pkg.version %>-' + i + '.js'];
Akrone91da782017-12-15 17:17:50 +010052 };
53
Nils Diewaldea236742015-03-26 21:55:36 +000054 grunt.initConfig({
55 pkg: grunt.file.readJSON('package.json'),
Nils Diewaldc2826192015-05-07 19:23:44 +000056 requirejs: reqTasks,
Akron020c3632020-01-16 09:25:32 +010057 terser: {
Akron70821ba2018-07-16 17:24:36 +020058 kalamar : {
Akron5e5cf1e2018-07-25 13:41:25 +020059 files: uglyFiles,
60 options : {
61 sourceMap: {
62 includeSources: true
63 }
64 }
Akron70821ba2018-07-16 17:24:36 +020065 }
66 },
Nils Diewaldea236742015-03-26 21:55:36 +000067 imagemin: {
68 dynamic: {
Akron49bfdbf2016-11-22 21:47:33 +010069 files: [{
70 expand: true,
71 cwd: 'dev/img/',
72 src: ['*.{png,gif,jpg}'],
73 dest: 'public/img/'
74 }]
Nils Diewaldea236742015-03-26 21:55:36 +000075 }
76 },
77 sass: {
78 dist: {
79 options: {
Akron7ca73872021-03-08 11:29:11 +010080 implementation: sass,
81 style: 'compressed',
82 sourceMap: true
Nils Diewaldea236742015-03-26 21:55:36 +000083 },
84 files: {
Nils Diewaldce328112015-04-08 22:48:18 +000085 'public/css/kalamar-<%= pkg.version %>.css' : 'dev/scss/kalamar.scss',
Akron7e5afce2020-08-25 15:50:19 +020086 'public/css/kalamar-plugin-<%= pkg.pluginVersion %>.css' : 'dev/scss/plugin.scss',
Akron49bfdbf2016-11-22 21:47:33 +010087 'dev/css/kalamar.css' : 'dev/scss/kalamar.scss',
hebasta75cfca52019-02-19 13:15:27 +010088 'dev/css/kwic.css' : 'dev/scss/main/kwic.scss',
Akron7e5afce2020-08-25 15:50:19 +020089 'dev/css/kalamar-plugin.css' : 'dev/scss/plugin.scss'
Nils Diewaldea236742015-03-26 21:55:36 +000090 }
91 }
92 },
Nils Diewaldaa17d142015-04-08 23:32:23 +000093 // see https://github.com/gruntjs/grunt-contrib-copy/issues/64
Akrondf5ad372018-07-02 14:47:57 +020094 jasmine: {
95 pivotal: {
96 src: [
97 'dev/js/src/menu.js',
98 'dev/js/src/match.js',
99 'dev/js/src/hint.js',
100 'dev/js/src/vc.js'
101 ],
102 options: {
103 specs: 'dev/js/spec/*Spec.js',
104 vendor: ['dev/js/lib/require.js']
105 }
106 }
107 },
108
109 // see https://github.com/gruntjs/grunt-contrib-copy/issues/64
Nils Diewald2488d052015-04-09 21:46:02 +0000110 // for copying binary files
Nils Diewaldce328112015-04-08 22:48:18 +0000111 copy : {
Nils Diewaldaa17d142015-04-08 23:32:23 +0000112 options: {
Akron49bfdbf2016-11-22 21:47:33 +0100113 process:false
Nils Diewaldaa17d142015-04-08 23:32:23 +0000114 },
115 main: {
Akron49bfdbf2016-11-22 21:47:33 +0100116 files:[
117 {
118 expand: true,
119 cwd: 'dev/font/',
120 src: '**',
121 dest: 'public/font/',
122 filter: 'isFile',
123 nonull: true,
124 timestamp: true
125 },
126 {
127 expand: true,
128 cwd: 'dev/img/',
Akron49bfdbf2016-11-22 21:47:33 +0100129 src: '*.svg',
130 dest: 'public/img/',
131 filter: 'isFile',
132 nonull:true,
133 timestamp:true
Akron88c26b12020-09-07 12:44:18 +0200134 },
135 {
136 src: 'dev/img/favicon.ico',
137 dest: 'public/favicon.ico',
138 timestamp:true
139 },
140 {
141 src: 'dev/robots.txt',
142 dest: 'public/robots.txt',
143 timestamp: true
Akron9adf2cc2020-09-24 07:19:08 +0200144 },
145 {
146 src: 'public/css/kalamar-plugin-<%= pkg.pluginVersion %>.css',
147 dest: 'public/css/kalamar-plugin-latest.css',
148 timestamp: true
149 },
150 {
151 src: 'public/js/korap-plugin-<%= pkg.pluginVersion %>.js',
Akron8bcb3542020-10-01 21:43:30 +0200152 dest: 'public/js/korap-plugin-latest.js',
Akron9adf2cc2020-09-24 07:19:08 +0200153 timestamp: true
Akron49bfdbf2016-11-22 21:47:33 +0100154 }
155 ]
Nils Diewaldaa17d142015-04-08 23:32:23 +0000156 }
Nils Diewaldce328112015-04-08 22:48:18 +0000157 },
Nils Diewaldea236742015-03-26 21:55:36 +0000158 watch: {
Nils Diewaldea236742015-03-26 21:55:36 +0000159 css: {
Akron7918e392020-04-16 18:52:27 +0200160 files: ['dev/scss/**/*.scss'],
Akron49bfdbf2016-11-22 21:47:33 +0100161 tasks: ['sass'],
162 options: {
163 spawn: false
164 }
Nils Diewaldea236742015-03-26 21:55:36 +0000165 }
Akron08648842019-03-28 11:55:22 +0100166 },
Nils Diewaldea236742015-03-26 21:55:36 +0000167 });
168
Nils Diewaldea236742015-03-26 21:55:36 +0000169 grunt.loadNpmTasks('grunt-contrib-imagemin');
170 grunt.loadNpmTasks('grunt-contrib-watch');
Akron7ca73872021-03-08 11:29:11 +0100171 grunt.loadNpmTasks('grunt-sass');
Nils Diewaldce328112015-04-08 22:48:18 +0000172 grunt.loadNpmTasks('grunt-contrib-copy');
Akron020c3632020-01-16 09:25:32 +0100173 grunt.loadNpmTasks('grunt-terser');
Nils Diewald0e6992a2015-04-14 20:13:52 +0000174 grunt.loadNpmTasks('grunt-contrib-requirejs');
Nils Diewalda31a5152015-04-17 21:05:23 +0000175 grunt.registerTask('img', ['imagemin','copy']);
Akron9f64fd02016-02-13 05:51:38 +0100176 grunt.registerTask('js', ['requirejs']);
Nils Diewaldea236742015-03-26 21:55:36 +0000177 grunt.registerTask('css', ['sass']);
Nils Diewaldce328112015-04-08 22:48:18 +0000178 grunt.registerTask(
179 'default',
Akron020c3632020-01-16 09:25:32 +0100180 ['requirejs', 'terser', 'imagemin', 'copy', 'sass']
Nils Diewaldce328112015-04-08 22:48:18 +0000181 );
Nils Diewaldea236742015-03-26 21:55:36 +0000182};