Nils Diewald | 2488d05 | 2015-04-09 21:46:02 +0000 | [diff] [blame] | 1 | /** |
| 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 Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 9 | /* |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 10 | * TODO: Use https://www.npmjs.com/package/grunt-contrib-compress |
Nils Diewald | 2488d05 | 2015-04-09 21:46:02 +0000 | [diff] [blame] | 11 | * for assets. |
| 12 | * http://yui.github.io/yuidoc/ |
| 13 | * TODO: Use https://www.npmjs.com/package/grunt-contrib-yuidoc |
Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 14 | * TODO: Implement a LaTeX generator for a pdf of the dokumentation |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 15 | */ |
Nils Diewald | c282619 | 2015-05-07 19:23:44 +0000 | [diff] [blame] | 16 | |
Akron | 7ca7387 | 2021-03-08 11:29:11 +0100 | [diff] [blame] | 17 | const sass = require('sass'); |
| 18 | |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 19 | module.exports = function(grunt) { |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 20 | var config; |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 21 | var includeFile = 'default'; |
| 22 | if (grunt.file.exists('kalamar.conf.js')) { |
| 23 | includeFile = 'root/kalamar.conf'; |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | // Generate requireJS files for l10n |
| 27 | var reqTasks = []; |
Akron | df5ad37 | 2018-07-02 14:47:57 +0200 | [diff] [blame] | 28 | var uglyFiles = { |
| 29 | 'public/js/korap-plugin-<%= pkg.pluginVersion %>.js': ['dev/js/src/plugin/client.js'] |
Akron | 94477f6 | 2018-07-19 12:18:40 +0200 | [diff] [blame] | 30 | }; |
Akron | df5ad37 | 2018-07-02 14:47:57 +0200 | [diff] [blame] | 31 | |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 32 | for (var i in {'en' : 0, 'de' : 1}) { |
| 33 | |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 34 | reqTasks.push({ |
| 35 | options: { |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 36 | |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 37 | optimize: "none", |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 38 | baseUrl: 'dev/js/src', |
| 39 | paths : { |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 40 | 'lib': '../lib', |
| 41 | 'root' : '../../..' |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 42 | }, |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 43 | wrap: true, |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 44 | // dir : 'public/js', |
| 45 | name: 'lib/almond', |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 46 | include : [includeFile, "app/" + i], |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 47 | out: 'public/js/kalamar-<%= pkg.version %>-' + i + '.js' |
| 48 | } |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 49 | }); |
| 50 | |
| 51 | uglyFiles['public/js/kalamar-<%= pkg.version %>-' + i + '.js'] = ['public/js/kalamar-<%= pkg.version %>-' + i + '.js']; |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 54 | grunt.initConfig({ |
| 55 | pkg: grunt.file.readJSON('package.json'), |
Nils Diewald | c282619 | 2015-05-07 19:23:44 +0000 | [diff] [blame] | 56 | requirejs: reqTasks, |
Akron | 020c363 | 2020-01-16 09:25:32 +0100 | [diff] [blame] | 57 | terser: { |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 58 | kalamar : { |
Akron | 5e5cf1e | 2018-07-25 13:41:25 +0200 | [diff] [blame] | 59 | files: uglyFiles, |
| 60 | options : { |
| 61 | sourceMap: { |
| 62 | includeSources: true |
| 63 | } |
| 64 | } |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 65 | } |
| 66 | }, |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 67 | imagemin: { |
| 68 | dynamic: { |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 69 | files: [{ |
| 70 | expand: true, |
| 71 | cwd: 'dev/img/', |
| 72 | src: ['*.{png,gif,jpg}'], |
| 73 | dest: 'public/img/' |
| 74 | }] |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 75 | } |
| 76 | }, |
| 77 | sass: { |
| 78 | dist: { |
| 79 | options: { |
Akron | 7ca7387 | 2021-03-08 11:29:11 +0100 | [diff] [blame] | 80 | implementation: sass, |
| 81 | style: 'compressed', |
Akron | ba21f6d | 2021-07-23 12:48:33 +0200 | [diff] [blame] | 82 | outputStyle: 'compressed', |
Akron | 7ca7387 | 2021-03-08 11:29:11 +0100 | [diff] [blame] | 83 | sourceMap: true |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 84 | }, |
| 85 | files: { |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 86 | 'public/css/kalamar-<%= pkg.version %>.css' : 'dev/scss/kalamar.scss', |
Akron | 7e5afce | 2020-08-25 15:50:19 +0200 | [diff] [blame] | 87 | 'public/css/kalamar-plugin-<%= pkg.pluginVersion %>.css' : 'dev/scss/plugin.scss', |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 88 | 'dev/css/kalamar.css' : 'dev/scss/kalamar.scss', |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 89 | 'dev/css/kwic.css' : 'dev/scss/main/kwic.scss', |
Akron | 7e5afce | 2020-08-25 15:50:19 +0200 | [diff] [blame] | 90 | 'dev/css/kalamar-plugin.css' : 'dev/scss/plugin.scss' |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | }, |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 94 | // see https://github.com/gruntjs/grunt-contrib-copy/issues/64 |
Akron | df5ad37 | 2018-07-02 14:47:57 +0200 | [diff] [blame] | 95 | jasmine: { |
| 96 | pivotal: { |
| 97 | src: [ |
| 98 | 'dev/js/src/menu.js', |
| 99 | 'dev/js/src/match.js', |
| 100 | 'dev/js/src/hint.js', |
| 101 | 'dev/js/src/vc.js' |
| 102 | ], |
| 103 | options: { |
| 104 | specs: 'dev/js/spec/*Spec.js', |
| 105 | vendor: ['dev/js/lib/require.js'] |
| 106 | } |
| 107 | } |
| 108 | }, |
| 109 | |
| 110 | // see https://github.com/gruntjs/grunt-contrib-copy/issues/64 |
Nils Diewald | 2488d05 | 2015-04-09 21:46:02 +0000 | [diff] [blame] | 111 | // for copying binary files |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 112 | copy : { |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 113 | options: { |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 114 | process:false |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 115 | }, |
| 116 | main: { |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 117 | files:[ |
| 118 | { |
| 119 | expand: true, |
| 120 | cwd: 'dev/font/', |
| 121 | src: '**', |
| 122 | dest: 'public/font/', |
| 123 | filter: 'isFile', |
| 124 | nonull: true, |
| 125 | timestamp: true |
| 126 | }, |
| 127 | { |
| 128 | expand: true, |
| 129 | cwd: 'dev/img/', |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 130 | src: '*.svg', |
| 131 | dest: 'public/img/', |
| 132 | filter: 'isFile', |
| 133 | nonull:true, |
| 134 | timestamp:true |
Akron | 88c26b1 | 2020-09-07 12:44:18 +0200 | [diff] [blame] | 135 | }, |
| 136 | { |
| 137 | src: 'dev/img/favicon.ico', |
| 138 | dest: 'public/favicon.ico', |
| 139 | timestamp:true |
| 140 | }, |
| 141 | { |
| 142 | src: 'dev/robots.txt', |
| 143 | dest: 'public/robots.txt', |
| 144 | timestamp: true |
Akron | 9adf2cc | 2020-09-24 07:19:08 +0200 | [diff] [blame] | 145 | }, |
| 146 | { |
| 147 | src: 'public/css/kalamar-plugin-<%= pkg.pluginVersion %>.css', |
| 148 | dest: 'public/css/kalamar-plugin-latest.css', |
| 149 | timestamp: true |
| 150 | }, |
| 151 | { |
| 152 | src: 'public/js/korap-plugin-<%= pkg.pluginVersion %>.js', |
Akron | 8bcb354 | 2020-10-01 21:43:30 +0200 | [diff] [blame] | 153 | dest: 'public/js/korap-plugin-latest.js', |
Akron | 9adf2cc | 2020-09-24 07:19:08 +0200 | [diff] [blame] | 154 | timestamp: true |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 155 | } |
| 156 | ] |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 157 | } |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 158 | }, |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 159 | watch: { |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 160 | css: { |
Akron | 7918e39 | 2020-04-16 18:52:27 +0200 | [diff] [blame] | 161 | files: ['dev/scss/**/*.scss'], |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 162 | tasks: ['sass'], |
| 163 | options: { |
| 164 | spawn: false |
| 165 | } |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 166 | } |
Akron | 0864884 | 2019-03-28 11:55:22 +0100 | [diff] [blame] | 167 | }, |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 168 | }); |
| 169 | |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 170 | grunt.loadNpmTasks('grunt-contrib-imagemin'); |
| 171 | grunt.loadNpmTasks('grunt-contrib-watch'); |
Akron | 7ca7387 | 2021-03-08 11:29:11 +0100 | [diff] [blame] | 172 | grunt.loadNpmTasks('grunt-sass'); |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 173 | grunt.loadNpmTasks('grunt-contrib-copy'); |
Akron | 020c363 | 2020-01-16 09:25:32 +0100 | [diff] [blame] | 174 | grunt.loadNpmTasks('grunt-terser'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 175 | grunt.loadNpmTasks('grunt-contrib-requirejs'); |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 176 | grunt.registerTask('img', ['imagemin','copy']); |
Akron | 9f64fd0 | 2016-02-13 05:51:38 +0100 | [diff] [blame] | 177 | grunt.registerTask('js', ['requirejs']); |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 178 | grunt.registerTask('css', ['sass']); |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 179 | grunt.registerTask( |
| 180 | 'default', |
Akron | f1c5152 | 2023-01-27 14:18:09 +0100 | [diff] [blame] | 181 | ['requirejs', 'terser', 'imagemin', 'sass', 'copy'] |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 182 | ); |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 183 | }; |