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