From 2a47e936aaf7553f5f49360baaa64da4e58fbab4 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 19 Sep 2023 14:47:32 -0700 Subject: [PATCH] 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 --- Gruntfile.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index cdb5b91f3..1ed341f9c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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' );