Skip to content

Commit

Permalink
Merge branch 'dequelabs:develop' into issue3315
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-tripp authored Feb 21, 2022
2 parents da97217 + fa6cbf4 commit 4ea16d3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 361 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ test/integration/*/index.html
axe.js
axe.*.js

# generated src file
lib/core/base/metadata-function-map.js

# generated jsdoc api docs
doc/api/*
Expand Down
15 changes: 15 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ module.exports = function(grunt) {
]
}
},
'metadata-function-map': {
core: {
files: [
{
expand: true,
src: [
'lib/checks/**/*-{evaluate,after}.js',
'lib/rules/**/*-matches.js'
],
dest: 'lib/core/base/metadata-function-map.js'
}
]
}
},
'aria-supported': {
data: {
entry: 'lib/commons/aria/index.js',
Expand Down Expand Up @@ -239,6 +253,7 @@ module.exports = function(grunt) {
grunt.registerTask('build', [
'clean:core',
'validate',
'metadata-function-map',
'esbuild',
'configure',
'babel',
Expand Down
49 changes: 49 additions & 0 deletions build/tasks/metadata-function-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const path = require('path').posix;
const glob = require('glob');
const fs = require('fs');

function toTitleCase(str) {
return str.replace(/-\w/g, txt => {
return txt.charAt(1).toUpperCase() + txt.substr(2).toLowerCase();
});
}

module.exports = function(grunt) {
grunt.registerMultiTask(
'metadata-function-map',
'Task to generate the metadata-function-map file',
function() {
const files = grunt.task.current.data.files;

files.forEach(file => {
const src = Array.isArray(file.src) ? file.src : [file.src];
const map = {};
let outFile =
'// This file is automatically generated using build/tasks/metadata-function-map.js\n';

src.forEach(globPath => {
glob.sync(globPath).forEach(filePath => {
const relativePath = path.relative(
path.dirname(file.dest),
filePath
);
const filename = path.basename(filePath, '.js');
const functionName = toTitleCase(filename);

outFile += `import ${functionName} from '${relativePath}';\n`;
map[filename] = functionName;
});
});

outFile += `\nconst metadataFunctionMap = {\n`;
outFile += Object.keys(map)
.sort()
.map(key => ` '${key}': ${map[key]}`)
.join(',\n');
outFile += `\n};\n\nexport default metadataFunctionMap;`;

fs.writeFileSync(file.dest, outFile, 'utf-8');
});
}
);
};
Loading

0 comments on commit 4ea16d3

Please sign in to comment.