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 | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 26 | var uglyFiles = {}; |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 27 | for (var i in {'en' : 0, 'de' : 1}) { |
| 28 | |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 29 | reqTasks.push({ |
| 30 | options: { |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 31 | |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 32 | optimize: "none", |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 33 | baseUrl: 'dev/js/src', |
| 34 | paths : { |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 35 | 'lib': '../lib', |
| 36 | 'root' : '../../..' |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 37 | }, |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 38 | wrap: true, |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 39 | // dir : 'public/js', |
| 40 | name: 'lib/almond', |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 41 | include : [includeFile, "app/" + i], |
Akron | e91da78 | 2017-12-15 17:17:50 +0100 | [diff] [blame] | 42 | out: 'public/js/kalamar-<%= pkg.version %>-' + i + '.js' |
| 43 | } |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 44 | }); |
| 45 | |
| 46 | 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] | 47 | }; |
| 48 | |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 49 | grunt.initConfig({ |
| 50 | pkg: grunt.file.readJSON('package.json'), |
Nils Diewald | c282619 | 2015-05-07 19:23:44 +0000 | [diff] [blame] | 51 | requirejs: reqTasks, |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 52 | uglify: { |
| 53 | kalamar : { |
| 54 | files: uglyFiles |
| 55 | } |
| 56 | }, |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 57 | imagemin: { |
| 58 | dynamic: { |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 59 | files: [{ |
| 60 | expand: true, |
| 61 | cwd: 'dev/img/', |
| 62 | src: ['*.{png,gif,jpg}'], |
| 63 | dest: 'public/img/' |
| 64 | }] |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 65 | } |
| 66 | }, |
| 67 | sass: { |
| 68 | dist: { |
| 69 | options: { |
| 70 | style: 'compressed' |
| 71 | }, |
| 72 | files: { |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 73 | 'public/css/kalamar-<%= pkg.version %>.css' : 'dev/scss/kalamar.scss', |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 74 | 'dev/css/kalamar.css' : 'dev/scss/kalamar.scss', |
Akron | b56986f | 2017-06-29 20:52:29 +0200 | [diff] [blame] | 75 | 'dev/css/kwic.css' : 'dev/scss/main/kwic.scss' |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | }, |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 79 | // see https://github.com/gruntjs/grunt-contrib-copy/issues/64 |
Nils Diewald | 2488d05 | 2015-04-09 21:46:02 +0000 | [diff] [blame] | 80 | // for copying binary files |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 81 | copy : { |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 82 | options: { |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 83 | process:false |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 84 | }, |
| 85 | main: { |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 86 | files:[ |
| 87 | { |
| 88 | expand: true, |
| 89 | cwd: 'dev/font/', |
| 90 | src: '**', |
| 91 | dest: 'public/font/', |
| 92 | filter: 'isFile', |
| 93 | nonull: true, |
| 94 | timestamp: true |
| 95 | }, |
| 96 | { |
| 97 | expand: true, |
| 98 | cwd: 'dev/img/', |
| 99 | src: 'favicon.ico', |
| 100 | dest: 'public/', |
| 101 | filter: 'isFile', |
| 102 | nonull:true, |
| 103 | timestamp:true |
| 104 | }, |
| 105 | { |
| 106 | expand: true, |
| 107 | cwd: 'dev/img/', |
| 108 | src: '*.svg', |
| 109 | dest: 'public/img/', |
| 110 | filter: 'isFile', |
| 111 | nonull:true, |
| 112 | timestamp:true |
| 113 | } |
| 114 | ] |
Nils Diewald | aa17d14 | 2015-04-08 23:32:23 +0000 | [diff] [blame] | 115 | } |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 116 | }, |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 117 | watch: { |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 118 | css: { |
Akron | ae8f31c | 2017-11-28 18:05:52 +0100 | [diff] [blame] | 119 | files: ['dev/scss/{util,base,fonts,kalamar,media,no-js}.scss', |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 120 | 'dev/scss/footer/footer.scss', |
Akron | 189b359 | 2016-01-04 20:56:46 +0100 | [diff] [blame] | 121 | 'dev/scss/sidebar/sidebar.scss', |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 122 | 'dev/scss/header/{header,hint,menu,searchbar,vc,datepicker}.scss', |
Akron | bd39a43 | 2017-09-20 13:57:13 +0200 | [diff] [blame] | 123 | 'dev/scss/main/{alertify,intro,koralquery,highlight,kwic,logos,tagger,' + |
Akron | 537bc52 | 2018-07-13 19:06:27 +0200 | [diff] [blame] | 124 | 'main,matchinfo,panel,tree,pagination,query,'+ |
Akron | bec4a6a | 2018-07-10 14:45:15 +0200 | [diff] [blame] | 125 | 'resultinfo,sidebar,tutorial,buttongroup}.scss' |
Akron | 49bfdbf | 2016-11-22 21:47:33 +0100 | [diff] [blame] | 126 | ], |
| 127 | tasks: ['sass'], |
| 128 | options: { |
| 129 | spawn: false |
| 130 | } |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 131 | } |
Nils Diewald | 2488d05 | 2015-04-09 21:46:02 +0000 | [diff] [blame] | 132 | } |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 133 | }); |
| 134 | |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 135 | grunt.loadNpmTasks('grunt-contrib-imagemin'); |
| 136 | grunt.loadNpmTasks('grunt-contrib-watch'); |
| 137 | grunt.loadNpmTasks('grunt-contrib-sass'); |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 138 | grunt.loadNpmTasks('grunt-contrib-copy'); |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 139 | grunt.loadNpmTasks('grunt-contrib-uglify-es'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 140 | grunt.loadNpmTasks('grunt-contrib-requirejs'); |
| 141 | |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 142 | grunt.registerTask('img', ['imagemin','copy']); |
Akron | 9f64fd0 | 2016-02-13 05:51:38 +0100 | [diff] [blame] | 143 | grunt.registerTask('js', ['requirejs']); |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 144 | grunt.registerTask('css', ['sass']); |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 145 | grunt.registerTask( |
| 146 | 'default', |
Akron | 70821ba | 2018-07-16 17:24:36 +0200 | [diff] [blame] | 147 | ['requirejs', 'uglify', 'imagemin', 'copy', 'sass'] |
Nils Diewald | ce32811 | 2015-04-08 22:48:18 +0000 | [diff] [blame] | 148 | ); |
Nils Diewald | ea23674 | 2015-03-26 21:55:36 +0000 | [diff] [blame] | 149 | }; |