Automatically generated installer lang files
[moodle.git] / .grunt / tasks / ignorefiles.js
blob153e03fee7fa75aa856167ec588a982b84b45c99
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.
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 */
18 /**
19  * @copyright  2021 Andrew Nicols
20  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21  */
23 module.exports = grunt => {
25     /**
26      * Generate the PHPCS configuration.
27      *
28      * @param {Object} thirdPartyPaths
29      */
30     const phpcsIgnore = (thirdPartyPaths) => {
31         const {toXML} = require('jstoxml');
33         const config = {
34             _name: 'ruleset',
35             _attrs: {
36                 name: "MoodleCore",
37             },
38             _content: [
39                 {
40                     rule: {
41                         _attrs: {
42                             ref: './.phpcs.xml.dist',
43                         },
44                     },
45                 },
46             ],
47         };
49         thirdPartyPaths.forEach(library => {
50             config._content.push({
51                 'exclude-pattern': library,
52             });
53         });
55         grunt.file.write('.phpcs.xml', toXML(config, {
56             header: true,
57             indent: '  ',
58         }) + "\n");
59     };
61     /**
62      * Generate ignore files (utilising thirdpartylibs.xml data)
63      */
64     const handler = function() {
65         const path = require('path');
66         const ComponentList = require(path.join(process.cwd(), '.grunt', 'components.js'));
68         // An array of paths to third party directories.
69         const thirdPartyPaths = ComponentList.getThirdPartyPaths();
71         // Generate .eslintignore.
72         const eslintIgnores = [
73             '# Generated by "grunt ignorefiles"',
74             // Do not ignore the .grunt directory.
75             '!/.grunt',
77             // Ignore all yui/src meta directories and build directories.
78             '*/**/yui/src/*/meta/',
79             '*/**/build/',
80         ].concat(thirdPartyPaths);
81         grunt.file.write('.eslintignore', eslintIgnores.join('\n') + '\n');
83         // Generate .stylelintignore.
84         const stylelintIgnores = [
85             '# Generated by "grunt ignorefiles"',
86             '**/yui/build/*',
87             'theme/boost/style/moodle.css',
88             'theme/classic/style/moodle.css',
89             'jsdoc/styles/*.css',
90             'admin/tool/componentlibrary/hugo/dist/css/docs.css',
91         ].concat(thirdPartyPaths);
92         grunt.file.write('.stylelintignore', stylelintIgnores.join('\n') + '\n');
94         phpcsIgnore(thirdPartyPaths);
95     };
97     grunt.registerTask('ignorefiles', 'Generate ignore files for linters', handler);
99     return handler;