Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
/* jshint node: true, browser: false */
16
/* eslint-env node */
17
 
18
/**
19
 * @copyright  2021 Andrew Nicols
20
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 */
22
 
23
module.exports = grunt => {
24
    const files = grunt.moodleEnv.files;
25
 
26
    // Project configuration.
27
    grunt.config.merge({
28
        eslint: {
29
            // Even though warnings dont stop the build we don't display warnings by default because
30
            // at this moment we've got too many core warnings.
31
            // To display warnings call: grunt eslint --show-lint-warnings
32
            // To fail on warnings call: grunt eslint --max-lint-warnings=0
33
            // Also --max-lint-warnings=-1 can be used to display warnings but not fail.
34
            options: {
35
                quiet: (!grunt.option('show-lint-warnings')) && (typeof grunt.option('max-lint-warnings') === 'undefined'),
36
                maxWarnings: ((typeof grunt.option('max-lint-warnings') !== 'undefined') ? grunt.option('max-lint-warnings') : -1)
37
            },
38
 
39
            // Check AMD src files.
40
            amd: {src: files ? files : grunt.moodleEnv.amdSrc},
41
 
42
            // Check YUI module source files.
43
            yui: {src: files ? files : grunt.moodleEnv.yuiSrc},
44
        },
45
    });
46
 
47
    grunt.loadNpmTasks('grunt-eslint');
48
 
49
    // On watch, we dynamically modify config to build only affected files. This
50
    // method is slightly complicated to deal with multiple changed files at once (copied
51
    // from the grunt-contrib-watch readme).
52
    let changedFiles = Object.create(null);
53
    const onChange = grunt.util._.debounce(function() {
54
        const files = Object.keys(changedFiles);
55
        grunt.config('eslint.amd.src', files);
56
        grunt.config('eslint.yui.src', files);
57
        changedFiles = Object.create(null);
58
    }, 200);
59
 
60
    grunt.event.on('watch', (action, filepath) => {
61
        changedFiles[filepath] = action;
62
        onChange();
63
    });
64
};