build: Simplify banana config with require() and for-of

* `require()` is more direct and likely faster than a synchronous
  file read into user land and then sync JSON.parse (as grunt.file
  does) than Node natively reading and parsing a file in one go.

  Also benefits being less Grunt-specific and theoretically some minor
  benefit to IDE and static analysis.

* Inline loop as for-of without the forEach function calls.

Change-Id: I06c8f8729b2f4ba2c574c7aaeaa2ae56513b4595
This commit is contained in:
Timo Tijhof 2023-09-19 14:47:32 -07:00 committed by James D. Forrester
parent 2f9beac0fa
commit 2a47e936aa

View file

@ -1,23 +1,17 @@
/* eslint-env node */
module.exports = function ( grunt ) {
const messagesDirs = grunt.file.readJSON( 'extension.json' ).MessagesDirs;
const subExtensions = [
const messagesDirs = require( './extension.json' ).MessagesDirs;
for ( const subExtension of [
'QuestyCaptcha',
'ReCaptchaNoCaptcha',
'FancyCaptcha',
'MathCaptcha',
'hCaptcha'
];
subExtensions.forEach(
function ( subExtension ) {
messagesDirs[ subExtension ] = grunt.file.readJSON( subExtension + '/extension.json' ).MessagesDirs[ subExtension ].map(
function ( path ) {
return subExtension + '/' + path;
}
);
} );
] ) {
messagesDirs[ subExtension ] = require( './' + subExtension + '/extension.json' )
.MessagesDirs[ subExtension ]
.map( function ( path ) { return subExtension + '/' + path; } );
}
grunt.loadNpmTasks( 'grunt-banana-checker' );
grunt.loadNpmTasks( 'grunt-eslint' );