-
Notifications
You must be signed in to change notification settings - Fork 112
/
Gruntfile.js
294 lines (280 loc) · 9.12 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/**
* Gruntfile for compiling theme_bootstrap .less files.
*
* This file configures tasks to be run by Grunt
* http://gruntjs.com/ for the current theme.
*
*
* Requirements:
* -------------
* nodejs, npm, grunt-cli.
*
* Installation:
* -------------
* node and npm: instructions at http://nodejs.org/
*
* grunt-cli: `[sudo] npm install -g grunt-cli`
*
* node dependencies: run `npm install` in the root directory.
*
*
* Usage:
* ------
* Call tasks from the theme root directory. Default behaviour
* (calling only `grunt`) is to run the watch task detailed below.
*
*
* Porcelain tasks:
* ----------------
* The nice user interface intended for everyday use. Provide a
* high level of automation and convenience for specific use-cases.
*
* grunt watch Watch the less directory (and all subdirectories)
* for changes to *.less files then on detection
* run 'grunt compile'
*
* Options:
*
* --dirroot=<path> Optional. Explicitly define the
* path to your Moodle root directory
* when your theme is not in the
* standard location.
* grunt compile Run the .less files through the compiler, create the
* RTL version of the output, then run decache so that
* the results can be seen on the next page load.
*
* Options:
*
* --dirroot=<path> Optional. Explicitly define the
* path to your Moodle root directory
* when your theme is not in the
* standard location.
*
*
* Plumbing tasks & targets:
* -------------------------
* Lower level tasks encapsulating a specific piece of functionality
* but usually only useful when called in combination with another.
*
* grunt less Compile all less files.
*
* grunt less:moodle Compile Moodle less files only.
*
* grunt less:editor Compile editor less files only.
*
* grunt decache Clears the Moodle theme cache.
*
* Options:
*
* --dirroot=<path> Optional. Explicitly define
* the path to your Moodle root
* directory when your theme is
* not in the standard location.
*
*
* grunt replace Run all text replace tasks.
*
* grunt replace:rtl_images Add _rtl to the filenames of certain images
* that require flipping for use with RTL
* languages.
*
* grunt replace:font_fix Correct the format for the Moodle font
* loader to pick up the Glyphicon font.
*
*
* grunt cssflip Create moodle-rtl.css by flipping the direction styles
* in moodle.css.
*
*
* @package theme
* @subpackage bootstrap
* @author Joby Harding www.iamjoby.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// jshint node: true, strict: false
module.exports = function(grunt) {
// Import modules.
var path = require('path');
// PHP strings for exec task.
var moodleroot = path.dirname(path.dirname(__dirname)),
configfile = '',
decachephp = '',
dirrootopt = grunt.option('dirroot') || process.env.MOODLE_DIR || '';
// Allow user to explicitly define Moodle root dir.
if ('' !== dirrootopt) {
moodleroot = path.resolve(dirrootopt);
}
var PWD = process.cwd(); // jshint ignore:line
configfile = path.join(moodleroot, 'config.php');
decachephp += 'define(\'CLI_SCRIPT\', true);';
decachephp += 'require(\'' + configfile + '\');';
decachephp += 'theme_reset_all_caches();';
grunt.initConfig({
less: {
// Compile moodle styles.
moodle: {
options: {
compress: false
},
src: 'less/moodle.less',
dest: 'style/moodle.css'
},
// Compile editor styles.
editor: {
options: {
compress: false,
strictMath: true
},
src: 'less/editor.less',
dest: 'style/editor.css'
}
},
autoprefixer: {
options: {
browsers: [
'Android 2.3',
'Android >= 4',
'Chrome >= 20',
'Firefox >= 24', // Firefox 24 is the latest ESR
'Explorer >= 8',
'iOS >= 6',
'Opera >= 12',
'Safari >= 6'
]
},
core: {
options: {
map: false
},
src: ['style/moodle.css', 'style/moodle-rtl.css', 'style/editor.css'],
},
},
cssmin: {
options: {
compatibility: 'ie8',
keepSpecialComments: '*',
noAdvanced: true
},
core: {
files: {
'style/moodle_min.css': 'style/moodle.css',
'style/editor_min.css': 'style/editor.css'
}
}
},
csscomb: {
options: {
config: 'less/bootstrap3/.csscomb.json'
},
dist: {
expand: true,
cwd: 'style/',
src: ['moodle.css', 'editor.css'],
dest: 'style/'
}
},
exec: {
decache: {
cmd: 'php -r "' + decachephp + '"',
callback: function(error) {
// exec will output error messages
// just add one to confirm success.
if (!error) {
grunt.log.writeln("Moodle theme cache reset.");
}
}
}
},
watch: {
// Watch for any changes to less files and compile.
files: ["less/**/*.less"],
tasks: ["compile"],
options: {
spawn: false,
livereload: true
}
},
cssflip: {
rtl: {
src: 'style/moodle.css',
dest: 'style/moodle-rtl.css'
}
},
replace: {
rtl_images: {
src: 'style/moodle-rtl.css',
overwrite: true,
replacements: [{
from: '[[pix:theme|fp/path_folder]]',
to: '[[pix:theme|fp/path_folder_rtl]]'
}, {
from: '[[pix:t/collapsed]]',
to: '[[pix:t/collapsed_rtl]]'
}, {
from: '[[pix:t/collapsed_empty]]',
to: '[[pix:t/collapsed_empty_rtl]]'
}, {
from: '[[pix:y/tn]]',
to: '[[pix:y/tn_rtl]]'
}, {
from: '[[pix:y/tp]]',
to: '[[pix:y/tp_rtl]]'
}, {
from: '[[pix:y/ln]]',
to: '[[pix:y/ln_rtl]]'
}, {
from: '[[pix:y/lp]]',
to: '[[pix:y/lp_rtl]]'
}]
}
},
jshint: {
options: {jshintrc: moodleroot + '/.jshintrc'},
files: ['**/amd/src/*.js']
},
uglify: {
dynamic_mappings: {
files: grunt.file.expandMapping(
['**/src/*.js', '!**/node_modules/**'],
'',
{
cwd: PWD,
rename: function(destBase, destPath) {
destPath = destPath.replace('src', 'build');
destPath = destPath.replace('.js', '.min.js');
destPath = path.resolve(PWD, destPath);
return destPath;
}
}
)
}
}
});
require('time-grunt')(grunt); // jshint ignore:line
// Load contrib tasks.
grunt.loadNpmTasks("grunt-autoprefixer");
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-exec");
grunt.loadNpmTasks("grunt-text-replace");
grunt.loadNpmTasks("grunt-css-flip");
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-csscomb');
// Load core tasks.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Register tasks.
grunt.registerTask("default", ["watch"]);
grunt.registerTask("decache", ["exec:decache"]);
grunt.registerTask("compile", [
"less",
"cssflip",
"replace:rtl_images",
"autoprefixer",
"csscomb",
"cssmin",
"decache"
]);
grunt.registerTask("amd", ["jshint", "uglify", "decache"]);
};