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