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