-
Notifications
You must be signed in to change notification settings - Fork 156
/
Gruntfile.js
115 lines (102 loc) · 3.33 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
/* eslint no-undef: "error" */
/* eslint camelcase: 2 */
/* eslint-env node */
"use strict";
module.exports = function(grunt) {
var path = require('path'),
PWD = process.env.PWD || process.cwd();
var decachephp = "../../admin/cli/purge_caches.php";
var inAMD = path.basename(PWD) == 'amd';
// Globbing pattern for matching all AMD JS source files.
var amdSrc = [inAMD ? PWD + "/src/*.js" : "**/amd/src/*.js"];
/**
* Function to generate the destination for the uglify task
* (e.g. build/file.min.js). This function will be passed to
* the rename property of files array when building dynamically:
* http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
*
* @param {String} destPath the current destination
* @param {String} srcPath the matched src path
* @return {String} The rewritten destination path.
*/
var uglifyRename = function(destPath, srcPath) {
destPath = srcPath.replace("src", "build");
destPath = destPath.replace(".js", ".min.js");
destPath = path.resolve(PWD, destPath);
return destPath;
};
grunt.initConfig({
eslint: {
options: {quiet: !grunt.option("show-lint-warnings")},
amd: {src: amdSrc},
yui: {src: ["**/yui/src/**/*.js", "!*/**/yui/src/*/meta/*.js"]}
},
uglify: {
amd: {
files: [{
expand: true,
src: amdSrc,
rename: uglifyRename
}],
options: {
report: "min",
sourceMap: true
}
}
},
watch: {
options: {
nospawn: true,
livereload: true
},
amd: {
files: ["**/amd/src/**/*.js"],
tasks: ["amd", "decache"]
},
css: {
files: ["scss/**/*.scss"],
tasks: ["decache"]
}
},
stylelint: {
scss: {
options: {syntax: "scss"},
src: ["*/**/*.scss"]
},
css: {
src: ["*/**/*.css"],
options: {
configOverrides: {
rules: {
"at-rule-no-unknown": true,
}
}
}
}
},
exec: {
decache: {
cmd: "php " + decachephp,
callback: function(error) {
if (!error) {
grunt.log.writeln("Moodle theme cache reseted.");
}
}
}
}
});
// Load contrib tasks.
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-exec");
// Load core tasks.
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-eslint");
grunt.loadNpmTasks("grunt-stylelint");
// Register CSS taks.
grunt.registerTask("css", ["stylelint:scss", "stylelint:css"]);
// Register tasks.
grunt.registerTask("amd", ["uglify"]);
grunt.registerTask("default", ["watch"]);
grunt.registerTask("decache", ["exec:decache"]);
grunt.registerTask("compile", ["uglify", "decache"]);
};