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