# Generated by "grunt ignorefiles"
+!/.grunt
*/**/yui/src/*/meta/
*/**/build/
node_modules/
theme/boost/amd/src/bootstrap/carousel.js
theme/boost/amd/src/bootstrap/collapse.js
theme/boost/amd/src/bootstrap/dropdown.js
-theme/boost/amd/src/bootstrap/index.js
theme/boost/amd/src/bootstrap/modal.js
theme/boost/amd/src/bootstrap/popover.js
theme/boost/amd/src/bootstrap/tools/sanitizer.js
theme/boost/amd/src/bootstrap/toast.js
theme/boost/amd/src/bootstrap/tooltip.js
theme/boost/amd/src/bootstrap/util.js
-theme/boost/scss/fontawesome/
\ No newline at end of file
+theme/boost/amd/src/index.js
+theme/boost/scss/fontawesome/
}
},
{
- files: ["**/amd/src/*.js", "**/amd/src/**/*.js", "Gruntfile*.js", "babel-plugin-add-module-to-define.js"],
+ files: ["**/amd/src/*.js", "**/amd/src/**/*.js", "Gruntfile.js", ".grunt/*.js", ".grunt/tasks/*.js"],
// We support es6 now. Woot!
env: {
es6: true
name: Core
-on: [push]
+on:
+ push:
+ branches-ignore:
+ - master
+ - MOODLE_[0-9]+_STABLE
+ tags-ignore:
+ - v[0-9]+.[0-9]+.[0-9]+*
env:
php: 7.4
atlassian-ide-plugin.xml
/node_modules/
/.vscode/
+moodle-plugin-ci.phar
const fs = require('fs');
const path = require('path');
const cwd = process.cwd();
- const ComponentList = require(path.resolve('GruntfileComponents.js'));
+ const ComponentList = require(path.join(process.cwd(), '.grunt', 'components.js'));
/**
* Search the list of components that match the given file name
return componentData;
};
+/**
+ * Get the list of component paths.
+ *
+ * @param {string} relativeTo
+ * @returns {array}
+ */
+const getComponentPaths = (relativeTo = '') => fetchComponentData().pathList.map(componentPath => {
+ return componentPath.replace(relativeTo, '');
+});
+
/**
* Get the list of paths to build AMD sources.
*
.sort();
};
+/**
+ * Get the list of thirdparty library paths.
+ *
+ * @returns {array}
+ */
+const getThirdPartyPaths = () => {
+ const DOMParser = require('xmldom').DOMParser;
+ const fs = require('fs');
+ const path = require('path');
+ const xpath = require('xpath');
+
+ const thirdpartyfiles = getThirdPartyLibsList(fs.realpathSync('./'));
+ const libs = ['node_modules/', 'vendor/'];
+
+ const addLibToList = lib => {
+ if (!lib.match('\\*') && fs.statSync(lib).isDirectory()) {
+ // Ensure trailing slash on dirs.
+ lib = lib.replace(/\/?$/, '/');
+ }
+
+ // Look for duplicate paths before adding to array.
+ if (libs.indexOf(lib) === -1) {
+ libs.push(lib);
+ }
+ };
+
+ thirdpartyfiles.forEach(function(file) {
+ const dirname = path.dirname(file);
+
+ const xmlContent = fs.readFileSync(file, 'utf8');
+ const doc = new DOMParser().parseFromString(xmlContent);
+ const nodes = xpath.select("/libraries/library/location/text()", doc);
+
+ nodes.forEach(function(node) {
+ let lib = path.posix.join(dirname, node.toString());
+ addLibToList(lib);
+ });
+ });
+
+ return libs;
+
+};
+
/**
* Find the name of the component matching the specified path.
*
module.exports = {
getAmdSrcGlobList,
getComponentFromPath,
+ getComponentPaths,
getOwningComponentDirectory,
getYuiSrcGlobList,
getThirdPartyLibsList,
+ getThirdPartyPaths,
};
--- /dev/null
+// 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();
+ });
+};
--- /dev/null
+// 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;
+};
--- /dev/null
+// 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') + '\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') + '\n');
+ };
+
+ grunt.registerTask('ignorefiles', 'Generate ignore files for linters', handler);
+
+ return handler;
+};
--- /dev/null
+// 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
+ */
+
+/**
+ * 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.
+ */
+const babelRename = function(destPath, srcPath) {
+ destPath = srcPath.replace('src', 'build');
+ destPath = destPath.replace('.js', '.min.js');
+ return destPath;
+};
+
+module.exports = grunt => {
+ // Load the Shifter tasks.
+ require('./shifter')(grunt);
+
+ // Load ESLint.
+ require('./eslint')(grunt);
+
+ const path = require('path');
+
+ // Register JS tasks.
+ grunt.registerTask('yui', ['eslint:yui', 'shifter']);
+ grunt.registerTask('amd', ['eslint:amd', 'babel']);
+ grunt.registerTask('js', ['amd', 'yui']);
+
+ // Register NPM tasks.
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadNpmTasks('grunt-contrib-watch');
+
+ // Load the Babel tasks and config.
+ grunt.loadNpmTasks('grunt-babel');
+ grunt.config.merge({
+ babel: {
+ options: {
+ sourceMaps: true,
+ comments: false,
+ plugins: [
+ 'transform-es2015-modules-amd-lazy',
+ 'system-import-transformer',
+ // This plugin modifies the Babel transpiling for "export default"
+ // so that if it's used then only the exported value is returned
+ // by the generated AMD module.
+ //
+ // It also adds the Moodle plugin name to the AMD module definition
+ // so that it can be imported as expected in other modules.
+ path.resolve('.grunt/babel-plugin-add-module-to-define.js'),
+ '@babel/plugin-syntax-dynamic-import',
+ '@babel/plugin-syntax-import-meta',
+ ['@babel/plugin-proposal-class-properties', {'loose': false}],
+ '@babel/plugin-proposal-json-strings'
+ ],
+ presets: [
+ ['minify', {
+ // This minification plugin needs to be disabled because it breaks the
+ // source map generation and causes invalid source maps to be output.
+ simplify: false,
+ builtIns: false
+ }],
+ ['@babel/preset-env', {
+ targets: {
+ browsers: [
+ ">0.25%",
+ "last 2 versions",
+ "not ie <= 10",
+ "not op_mini all",
+ "not Opera > 0",
+ "not dead"
+ ]
+ },
+ modules: false,
+ useBuiltIns: false
+ }]
+ ]
+ },
+ dist: {
+ files: [{
+ expand: true,
+ src: grunt.moodleEnv.files ? grunt.moodleEnv.files : grunt.moodleEnv.amdSrc,
+ rename: babelRename
+ }]
+ }
+ },
+ });
+
+ grunt.config.merge({
+ watch: {
+ amd: {
+ files: grunt.moodleEnv.inComponent
+ ? ['amd/src/*.js', 'amd/src/**/*.js']
+ : ['**/amd/src/**/*.js'],
+ tasks: ['amd']
+ },
+ },
+ });
+
+ // 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('babel.dist.files', [{expand: true, src: files, rename: babelRename}]);
+ changedFiles = Object.create(null);
+ }, 200);
+
+ grunt.event.on('watch', function(action, filepath) {
+ changedFiles[filepath] = action;
+ onChange();
+ });
+
+ return {
+ babelRename,
+ };
+};
--- /dev/null
+// 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 => {
+ grunt.loadNpmTasks('grunt-sass');
+
+ grunt.config.merge({
+ sass: {
+ dist: {
+ files: {
+ "theme/boost/style/moodle.css": "theme/boost/scss/preset/default.scss",
+ "theme/classic/style/moodle.css": "theme/classic/scss/classicgrunt.scss"
+ }
+ },
+ options: {
+ implementation: require('node-sass'),
+ includePaths: ["theme/boost/scss/", "theme/classic/scss/"]
+ }
+ },
+ });
+};
--- /dev/null
+// 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
+ */
+
+/* eslint-env node */
+
+module.exports = grunt => {
+ /**
+ * Shifter task. Is configured with a path to a specific file or a directory,
+ * in the case of a specific file it will work out the right module to be built.
+ *
+ * Note that this task runs the invidiaul shifter jobs async (becase it spawns
+ * so be careful to to call done().
+ */
+ const handler = function() {
+ const done = this.async();
+ const options = grunt.config('shifter.options');
+ const async = require('async');
+ const path = require('path');
+
+ // Run the shifter processes one at a time to avoid confusing output.
+ async.eachSeries(options.paths, function(src, filedone) {
+ var args = [];
+ args.push(path.normalize(process.cwd() + '/node_modules/shifter/bin/shifter'));
+
+ // Always ignore the node_modules directory.
+ args.push('--excludes', 'node_modules');
+
+ // Determine the most appropriate options to run with based upon the current location.
+ if (grunt.file.isMatch('**/yui/**/*.js', src)) {
+ // When passed a JS file, build our containing module (this happen with
+ // watch).
+ grunt.log.debug('Shifter passed a specific JS file');
+ src = path.dirname(path.dirname(src));
+ options.recursive = false;
+ } else if (grunt.file.isMatch('**/yui/src', src)) {
+ // When in a src directory --walk all modules.
+ grunt.log.debug('In a src directory');
+ args.push('--walk');
+ options.recursive = false;
+ } else if (grunt.file.isMatch('**/yui/src/*', src)) {
+ // When in module, only build our module.
+ grunt.log.debug('In a module directory');
+ options.recursive = false;
+ } else if (grunt.file.isMatch('**/yui/src/*/js', src)) {
+ // When in module src, only build our module.
+ grunt.log.debug('In a source directory');
+ src = path.dirname(src);
+ options.recursive = false;
+ }
+
+ if (grunt.option('watch')) {
+ grunt.fail.fatal('The --watch option has been removed, please use `grunt watch` instead');
+ }
+
+ // Add the stderr option if appropriate
+ if (grunt.option('verbose')) {
+ args.push('--lint-stderr');