blob: 106e2414731765d767268d17823ed8743f54f6e3 [file] [log] [blame]
Nils Diewald2488d052015-04-09 21:46:02 +00001/**
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 Diewaldea236742015-03-26 21:55:36 +00009/*
Nils Diewaldea236742015-03-26 21:55:36 +000010 * TODO: Use https://www.npmjs.com/package/grunt-contrib-compress
Nils Diewald2488d052015-04-09 21:46:02 +000011 * for assets.
12 * http://yui.github.io/yuidoc/
13 * TODO: Use https://www.npmjs.com/package/grunt-contrib-yuidoc
Nils Diewald4c221252015-04-21 20:19:25 +000014 * TODO: Implement a LaTeX generator for a pdf of the dokumentation
Nils Diewaldea236742015-03-26 21:55:36 +000015 */
Nils Diewaldc2826192015-05-07 19:23:44 +000016
Akron7ca73872021-03-08 11:29:11 +010017const sass = require('sass');
18
Nils Diewaldea236742015-03-26 21:55:36 +000019module.exports = function(grunt) {
Akrone91da782017-12-15 17:17:50 +010020 var config;
Akron80055992017-12-20 16:30:52 +010021 var includeFile = 'default';
22 if (grunt.file.exists('kalamar.conf.js')) {
23 includeFile = 'root/kalamar.conf';
Akrone91da782017-12-15 17:17:50 +010024 };
25
26 // Generate requireJS files for l10n
27 var reqTasks = [];
Akrondf5ad372018-07-02 14:47:57 +020028 var uglyFiles = {
29 'public/js/korap-plugin-<%= pkg.pluginVersion %>.js': ['dev/js/src/plugin/client.js']
Akron94477f62018-07-19 12:18:40 +020030 };
Akrondf5ad372018-07-02 14:47:57 +020031
Akrone91da782017-12-15 17:17:50 +010032 for (var i in {'en' : 0, 'de' : 1}) {
33
Akrone91da782017-12-15 17:17:50 +010034 reqTasks.push({
35 options: {
Akron80055992017-12-20 16:30:52 +010036
Akron70821ba2018-07-16 17:24:36 +020037 optimize: "none",
Akrone91da782017-12-15 17:17:50 +010038 baseUrl: 'dev/js/src',
39 paths : {
Akron80055992017-12-20 16:30:52 +010040 'lib': '../lib',
41 'root' : '../../..'
Akrone91da782017-12-15 17:17:50 +010042 },
Akron80055992017-12-20 16:30:52 +010043 wrap: true,
Akrone91da782017-12-15 17:17:50 +010044 // dir : 'public/js',
45 name: 'lib/almond',
Akron80055992017-12-20 16:30:52 +010046 include : [includeFile, "app/" + i],
Akrone91da782017-12-15 17:17:50 +010047 out: 'public/js/kalamar-<%= pkg.version %>-' + i + '.js'
48 }
Akron70821ba2018-07-16 17:24:36 +020049 });
50
51 uglyFiles['public/js/kalamar-<%= pkg.version %>-' + i + '.js'] = ['public/js/kalamar-<%= pkg.version %>-' + i + '.js'];
Akrone91da782017-12-15 17:17:50 +010052 };
53
Nils Diewaldea236742015-03-26 21:55:36 +000054 grunt.initConfig({
55 pkg: grunt.file.readJSON('package.json'),
Nils Diewaldc2826192015-05-07 19:23:44 +000056 requirejs: reqTasks,
Akron020c3632020-01-16 09:25:32 +010057 terser: {
Akron70821ba2018-07-16 17:24:36 +020058 kalamar : {
Akron5e5cf1e2018-07-25 13:41:25 +020059 files: uglyFiles,
60 options : {
61 sourceMap: {
62 includeSources: true
63 }
64 }
Akron70821ba2018-07-16 17:24:36 +020065 }
66 },
Nils Diewaldea236742015-03-26 21:55:36 +000067 imagemin: {
68 dynamic: {
Akron49bfdbf2016-11-22 21:47:33 +010069 files: [{
70 expand: true,
71 cwd: 'dev/img/',
72 src: ['*.{png,gif,jpg}'],
73 dest: 'public/img/'
74 }]
Nils Diewaldea236742015-03-26 21:55:36 +000075 }
76 },
77 sass: {
78 dist: {
79 options: {
Akron7ca73872021-03-08 11:29:11 +010080 implementation: sass,
81 style: 'compressed',
Akronba21f6d2021-07-23 12:48:33 +020082 outputStyle: 'compressed',
Akron7ca73872021-03-08 11:29:11 +010083 sourceMap: true
Nils Diewaldea236742015-03-26 21:55:36 +000084 },
85 files: {
Nils Diewaldce328112015-04-08 22:48:18 +000086 'public/css/kalamar-<%= pkg.version %>.css' : 'dev/scss/kalamar.scss',
Akron7e5afce2020-08-25 15:50:19 +020087 'public/css/kalamar-plugin-<%= pkg.pluginVersion %>.css' : 'dev/scss/plugin.scss',
Akron49bfdbf2016-11-22 21:47:33 +010088 'dev/css/kalamar.css' : 'dev/scss/kalamar.scss',
hebasta75cfca52019-02-19 13:15:27 +010089 'dev/css/kwic.css' : 'dev/scss/main/kwic.scss',
Akron7e5afce2020-08-25 15:50:19 +020090 'dev/css/kalamar-plugin.css' : 'dev/scss/plugin.scss'
Nils Diewaldea236742015-03-26 21:55:36 +000091 }
92 }
93 },
Nils Diewaldaa17d142015-04-08 23:32:23 +000094 // see https://github.com/gruntjs/grunt-contrib-copy/issues/64
Akrondf5ad372018-07-02 14:47:57 +020095 jasmine: {
96 pivotal: {
97 src: [
98 'dev/js/src/menu.js',
99 'dev/js/src/match.js',
100 'dev/js/src/hint.js',
101 'dev/js/src/vc.js'
102 ],
103 options: {
104 specs: 'dev/js/spec/*Spec.js',
105 vendor: ['dev/js/lib/require.js']
106 }
107 }
108 },
109
110 // see https://github.com/gruntjs/grunt-contrib-copy/issues/64
Nils Diewald2488d052015-04-09 21:46:02 +0000111 // for copying binary files
Nils Diewaldce328112015-04-08 22:48:18 +0000112 copy : {
Nils Diewaldaa17d142015-04-08 23:32:23 +0000113 options: {
Akron49bfdbf2016-11-22 21:47:33 +0100114 process:false
Nils Diewaldaa17d142015-04-08 23:32:23 +0000115 },
116 main: {
Akron49bfdbf2016-11-22 21:47:33 +0100117 files:[
118 {
119 expand: true,
120 cwd: 'dev/font/',
121 src: '**',
122 dest: 'public/font/',
123 filter: 'isFile',
124 nonull: true,
125 timestamp: true
126 },
127 {
128 expand: true,
129 cwd: 'dev/img/',
Akron49bfdbf2016-11-22 21:47:33 +0100130 src: '*.svg',
131 dest: 'public/img/',
132 filter: 'isFile',
133 nonull:true,
134 timestamp:true
Akron88c26b12020-09-07 12:44:18 +0200135 },
136 {
137 src: 'dev/img/favicon.ico',
138 dest: 'public/favicon.ico',
139 timestamp:true
140 },
141 {
142 src: 'dev/robots.txt',
143 dest: 'public/robots.txt',
144 timestamp: true
Akron9adf2cc2020-09-24 07:19:08 +0200145 },
146 {
147 src: 'public/css/kalamar-plugin-<%= pkg.pluginVersion %>.css',
148 dest: 'public/css/kalamar-plugin-latest.css',
149 timestamp: true
150 },
151 {
152 src: 'public/js/korap-plugin-<%= pkg.pluginVersion %>.js',
Akron8bcb3542020-10-01 21:43:30 +0200153 dest: 'public/js/korap-plugin-latest.js',
Akron9adf2cc2020-09-24 07:19:08 +0200154 timestamp: true
Akron49bfdbf2016-11-22 21:47:33 +0100155 }
156 ]
Nils Diewaldaa17d142015-04-08 23:32:23 +0000157 }
Nils Diewaldce328112015-04-08 22:48:18 +0000158 },
Nils Diewaldea236742015-03-26 21:55:36 +0000159 watch: {
Nils Diewaldea236742015-03-26 21:55:36 +0000160 css: {
Akron7918e392020-04-16 18:52:27 +0200161 files: ['dev/scss/**/*.scss'],
Akron49bfdbf2016-11-22 21:47:33 +0100162 tasks: ['sass'],
163 options: {
164 spawn: false
165 }
Nils Diewaldea236742015-03-26 21:55:36 +0000166 }
Akron08648842019-03-28 11:55:22 +0100167 },
Nils Diewaldea236742015-03-26 21:55:36 +0000168 });
169
Nils Diewaldea236742015-03-26 21:55:36 +0000170 grunt.loadNpmTasks('grunt-contrib-imagemin');
171 grunt.loadNpmTasks('grunt-contrib-watch');
Akron7ca73872021-03-08 11:29:11 +0100172 grunt.loadNpmTasks('grunt-sass');
Nils Diewaldce328112015-04-08 22:48:18 +0000173 grunt.loadNpmTasks('grunt-contrib-copy');
Akron020c3632020-01-16 09:25:32 +0100174 grunt.loadNpmTasks('grunt-terser');
Nils Diewald0e6992a2015-04-14 20:13:52 +0000175 grunt.loadNpmTasks('grunt-contrib-requirejs');
Nils Diewalda31a5152015-04-17 21:05:23 +0000176 grunt.registerTask('img', ['imagemin','copy']);
Akron9f64fd02016-02-13 05:51:38 +0100177 grunt.registerTask('js', ['requirejs']);
Nils Diewaldea236742015-03-26 21:55:36 +0000178 grunt.registerTask('css', ['sass']);
Nils Diewaldce328112015-04-08 22:48:18 +0000179 grunt.registerTask(
180 'default',
Akronf1c51522023-01-27 14:18:09 +0100181 ['requirejs', 'terser', 'imagemin', 'sass', 'copy']
Nils Diewaldce328112015-04-08 22:48:18 +0000182 );
Nils Diewaldea236742015-03-26 21:55:36 +0000183};