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', |
| 82 | sourceMap: true |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 83 | }, |
| 84 | files: { |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 85 | 'public/css/kalamar-<%= pkg.version %>.css' : 'dev/scss/kalamar.scss', |
Akron | 7e5afce | 2020-08-25 15:50:19 +0200 | [diff] [blame] | 86 | 'public/css/kalamar-plugin-<%= pkg.pluginVersion %>.css' : 'dev/scss/plugin.scss', |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 87 | 'dev/css/kalamar.css' : 'dev/scss/kalamar.scss', |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 88 | 'dev/css/kwic.css' : 'dev/scss/main/kwic.scss', |
Akron | 7e5afce | 2020-08-25 15:50:19 +0200 | [diff] [blame] | 89 | 'dev/css/kalamar-plugin.css' : 'dev/scss/plugin.scss' |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | }, |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 93 | // see https://github.com/gruntjs/grunt-contrib-copy/issues/64 |
Akron | df5ad37 | 2018-07-02 14:47:57 +0200 | [diff] [blame] | 94 | 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 Diewald | 2488d05 | 2015-04-09 21:46:02 +0000 | [diff] [blame] | 110 | // for copying binary files |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 111 | copy : { |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 112 | options: { |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 113 | process:false |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 114 | }, |
| 115 | main: { |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 116 | 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/', |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 129 | src: '*.svg', |
| 130 | dest: 'public/img/', |
| 131 | filter: 'isFile', |
| 132 | nonull:true, |
| 133 | timestamp:true |
Akron | 88c26b1 | 2020-09-07 12:44:18 +0200 | [diff] [blame] | 134 | }, |
| 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 |
Akron | 9adf2cc | 2020-09-24 07:19:08 +0200 | [diff] [blame] | 144 | }, |
| 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', |
Akron | 8bcb354 | 2020-10-01 21:43:30 +0200 | [diff] [blame] | 152 | dest: 'public/js/korap-plugin-latest.js', |
Akron | 9adf2cc | 2020-09-24 07:19:08 +0200 | [diff] [blame] | 153 | timestamp: true |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 154 | } |
| 155 | ] |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 156 | } |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 157 | }, |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 158 | watch: { |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 159 | css: { |
Akron | 7918e39 | 2020-04-16 18:52:27 +0200 | [diff] [blame] | 160 | files: ['dev/scss/**/*.scss'], |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 161 | tasks: ['sass'], |
| 162 | options: { |
| 163 | spawn: false |
| 164 | } |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 165 | } |
Akron | 0864884 | 2019-03-28 11:55:22 +0100 | [diff] [blame] | 166 | }, |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 167 | }); |
| 168 | |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 169 | grunt.loadNpmTasks('grunt-contrib-imagemin'); |
| 170 | grunt.loadNpmTasks('grunt-contrib-watch'); |
Akron | 7ca7387 | 2021-03-08 11:29:11 +0100 | [diff] [blame] | 171 | grunt.loadNpmTasks('grunt-sass'); |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 172 | grunt.loadNpmTasks('grunt-contrib-copy'); |
Akron | 020c363 | 2020-01-16 09:25:32 +0100 | [diff] [blame] | 173 | grunt.loadNpmTasks('grunt-terser'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 174 | grunt.loadNpmTasks('grunt-contrib-requirejs'); |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 175 | grunt.registerTask('img', ['imagemin','copy']); |
Akron | 9f64fd0 | 2016-02-13 05:51:38 +0100 | [diff] [blame] | 176 | grunt.registerTask('js', ['requirejs']); |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 177 | grunt.registerTask('css', ['sass']); |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 178 | grunt.registerTask( |
| 179 | 'default', |
Akron | 020c363 | 2020-01-16 09:25:32 +0100 | [diff] [blame] | 180 | ['requirejs', 'terser', 'imagemin', 'copy', 'sass'] |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 181 | ); |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 182 | }; |