forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-68496 grunt: Restructure grunt tasks into subdirectories
Prior to this change all Grunt features were in a single Gruntfile.js but this has become difficult to manage and maintain. This commit moves the existing dependencies for component calculation and babel moduel definition into a new .grunt directory, and restructures the existing tasks in Gruntfile.js into separate task configuration files. This improves the maintainability of the Grunt build system and allows for easier future expansion.
- Loading branch information
1 parent
fc335f5
commit 61fca0e
Showing
15 changed files
with
1,220 additions
and
764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Generated by "grunt ignorefiles" | ||
!/.grunt | ||
*/**/yui/src/*/meta/ | ||
*/**/build/ | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
/* jshint node: true, browser: false */ | ||
/* eslint-env node */ | ||
|
||
/** | ||
* @copyright 2021 Andrew Nicols | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
module.exports = grunt => { | ||
const files = grunt.moodleEnv.files; | ||
|
||
// Project configuration. | ||
grunt.config.merge({ | ||
eslint: { | ||
// Even though warnings dont stop the build we don't display warnings by default because | ||
// at this moment we've got too many core warnings. | ||
// To display warnings call: grunt eslint --show-lint-warnings | ||
// To fail on warnings call: grunt eslint --max-lint-warnings=0 | ||
// Also --max-lint-warnings=-1 can be used to display warnings but not fail. | ||
options: { | ||
quiet: (!grunt.option('show-lint-warnings')) && (typeof grunt.option('max-lint-warnings') === 'undefined'), | ||
maxWarnings: ((typeof grunt.option('max-lint-warnings') !== 'undefined') ? grunt.option('max-lint-warnings') : -1) | ||
}, | ||
|
||
// Check AMD src files. | ||
amd: {src: files ? files : grunt.moodleEnv.amdSrc}, | ||
|
||
// Check YUI module source files. | ||
yui: {src: files ? files : grunt.moodleEnv.yuiSrc}, | ||
}, | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-eslint'); | ||
|
||
// On watch, we dynamically modify config to build only affected files. This | ||
// method is slightly complicated to deal with multiple changed files at once (copied | ||
// from the grunt-contrib-watch readme). | ||
let changedFiles = Object.create(null); | ||
const onChange = grunt.util._.debounce(function() { | ||
const files = Object.keys(changedFiles); | ||
grunt.config('eslint.amd.src', files); | ||
grunt.config('eslint.yui.src', files); | ||
changedFiles = Object.create(null); | ||
}, 200); | ||
|
||
grunt.event.on('watch', (action, filepath) => { | ||
changedFiles[filepath] = action; | ||
onChange(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
/* jshint node: true, browser: false */ | ||
/* eslint-env node */ | ||
|
||
/** | ||
* @copyright 2021 Andrew Nicols | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
module.exports = grunt => { | ||
/** | ||
* Get the list of feature files to pass to the gherkin linter. | ||
* | ||
* @returns {Array} | ||
*/ | ||
const getGherkinLintTargets = () => { | ||
if (grunt.moodleEnv.files) { | ||
// Specific files were requested. Only check these. | ||
return grunt.moodleEnv.files; | ||
} | ||
|
||
if (grunt.moodleEnv.inComponent) { | ||
return [`${grunt.moodleEnv.runDir}/tests/behat/*.feature`]; | ||
} | ||
|
||
return ['**/tests/behat/*.feature']; | ||
}; | ||
|
||
const handler = function() { | ||
const done = this.async(); | ||
const options = grunt.config('gherkinlint.options'); | ||
|
||
// Grab the gherkin-lint linter and required scaffolding. | ||
const linter = require('gherkin-lint/dist/linter.js'); | ||
const featureFinder = require('gherkin-lint/dist/feature-finder.js'); | ||
const configParser = require('gherkin-lint/dist/config-parser.js'); | ||
const formatter = require('gherkin-lint/dist/formatters/stylish.js'); | ||
|
||
// Run the linter. | ||
return linter.lint( | ||
featureFinder.getFeatureFiles(grunt.file.expand(options.files)), | ||
configParser.getConfiguration(configParser.defaultConfigFileName) | ||
) | ||
.then(results => { | ||
// Print the results out uncondtionally. | ||
formatter.printResults(results); | ||
|
||
return results; | ||
}) | ||
.then(results => { | ||
// Report on the results. | ||
// The done function takes a bool whereby a falsey statement causes the task to fail. | ||
return results.every(result => result.errors.length === 0); | ||
}) | ||
.then(done); // eslint-disable-line promise/no-callback-in-promise | ||
}; | ||
|
||
grunt.registerTask('gherkinlint', 'Run gherkinlint against the current directory', handler); | ||
|
||
grunt.config.set('gherkinlint', { | ||
options: { | ||
files: getGherkinLintTargets(), | ||
} | ||
}); | ||
|
||
grunt.config.merge({ | ||
watch: { | ||
gherkinlint: { | ||
files: [grunt.moodleEnv.inComponent ? 'tests/behat/*.feature' : '**/tests/behat/*.feature'], | ||
tasks: ['gherkinlint'], | ||
}, | ||
}, | ||
}); | ||
|
||
return handler; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
/* jshint node: true, browser: false */ | ||
/* eslint-env node */ | ||
|
||
/** | ||
* @copyright 2021 Andrew Nicols | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
module.exports = grunt => { | ||
/** | ||
* Generate ignore files (utilising thirdpartylibs.xml data) | ||
*/ | ||
const handler = function() { | ||
const path = require('path'); | ||
const ComponentList = require(path.join(process.cwd(), '.grunt', 'components.js')); | ||
|
||
// An array of paths to third party directories. | ||
const thirdPartyPaths = ComponentList.getThirdPartyPaths(); | ||
|
||
// Generate .eslintignore. | ||
const eslintIgnores = [ | ||
'# Generated by "grunt ignorefiles"', | ||
// Do not ignore the .grunt directory. | ||
'!/.grunt', | ||
|
||
// Ignore all yui/src meta directories and build directories. | ||
'*/**/yui/src/*/meta/', | ||
'*/**/build/', | ||
].concat(thirdPartyPaths); | ||
grunt.file.write('.eslintignore', eslintIgnores.join('\n')); | ||
|
||
// Generate .stylelintignore. | ||
const stylelintIgnores = [ | ||
'# Generated by "grunt ignorefiles"', | ||
'**/yui/build/*', | ||
'theme/boost/style/moodle.css', | ||
'theme/classic/style/moodle.css', | ||
].concat(thirdPartyPaths); | ||
grunt.file.write('.stylelintignore', stylelintIgnores.join('\n')); | ||
}; | ||
|
||
grunt.registerTask('ignorefiles', 'Generate ignore files for linters', handler); | ||
|
||
return handler; | ||
}; |
Oops, something went wrong.