Skip to content

Commit

Permalink
MDL-67449 grunt: Build ignorefiles from component list
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 6, 2020
1 parent 093be5c commit d7678ab
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
64 changes: 35 additions & 29 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,28 +225,29 @@ module.exports = function(grunt) {
* @return {array} The list of thirdparty paths.
*/
var getThirdPartyPathsFromXML = function() {
var thirdpartyfiles = grunt.file.expand('*/**/thirdpartylibs.xml');
var libs = ['node_modules/', 'vendor/'];
const thirdpartyfiles = ComponentList.getThirdPartyLibsList(gruntFilePath + '/');
const libs = ['node_modules/', 'vendor/'];

thirdpartyfiles.forEach(function(file) {
var dirname = path.dirname(file);
const dirname = path.dirname(file);

var doc = new DOMParser().parseFromString(grunt.file.read(file));
var nodes = xpath.select("/libraries/library/location/text()", doc);
const doc = new DOMParser().parseFromString(grunt.file.read(file));
const nodes = xpath.select("/libraries/library/location/text()", doc);

nodes.forEach(function(node) {
var lib = path.join(dirname, node.toString());
if (grunt.file.isDir(lib)) {
// Ensure trailing slash on dirs.
lib = lib.replace(/\/?$/, '/');
}
nodes.forEach(function(node) {
let lib = path.join(dirname, node.toString());
if (grunt.file.isDir(lib)) {
// Ensure trailing slash on dirs.
lib = lib.replace(/\/?$/, '/');
}

// Look for duplicate paths before adding to array.
if (libs.indexOf(lib) === -1) {
libs.push(lib);
}
});
// Look for duplicate paths before adding to array.
if (libs.indexOf(lib) === -1) {
libs.push(lib);
}
});
});

return libs;
};

Expand Down Expand Up @@ -374,19 +375,24 @@ module.exports = function(grunt) {
* Generate ignore files (utilising thirdpartylibs.xml data)
*/
tasks.ignorefiles = function() {
// An array of paths to third party directories.
var thirdPartyPaths = getThirdPartyPathsFromXML();
// Generate .eslintignore.
var eslintIgnores = ['# Generated by "grunt ignorefiles"', '*/**/yui/src/*/meta/', '*/**/build/'].concat(thirdPartyPaths);
grunt.file.write('.eslintignore', eslintIgnores.join('\n'));
// Generate .stylelintignore.
var 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'));
// An array of paths to third party directories.
const thirdPartyPaths = getThirdPartyPathsFromXML();
// Generate .eslintignore.
const eslintIgnores = [
'# Generated by "grunt ignorefiles"',
'*/**/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'));
};

/**
Expand Down
16 changes: 16 additions & 0 deletions GruntfileComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ const getYuiSrcGlobList = relativeTo => {
return globList;
};

/**
* Get the list of paths to thirdpartylibs.xml.
*
* @param {String} relativeTo
* @returns {Array}
*/
const getThirdPartyLibsList = relativeTo => {
const fs = require('fs');

return fetchComponentData().pathList
.map(componentPath => componentPath.replace(relativeTo, '') + '/thirdpartylibs.xml')
.filter(path => fs.existsSync(path))
.sort();
};

/**
* Find the name of the component matching the specified path.
*
Expand Down Expand Up @@ -166,4 +181,5 @@ module.exports = {
getComponentFromPath,
getOwningComponentDirectory,
getYuiSrcGlobList,
getThirdPartyLibsList,
};

0 comments on commit d7678ab

Please sign in to comment.