From 8cc158c3ca83ed2110ba930e0b5029d7b1378f86 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Thu, 11 Nov 2021 15:50:42 +0000 Subject: [PATCH] Fixup comments from code review --- tasks/gulp/compile-assets.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tasks/gulp/compile-assets.js b/tasks/gulp/compile-assets.js index 9875caf51c..2054635358 100644 --- a/tasks/gulp/compile-assets.js +++ b/tasks/gulp/compile-assets.js @@ -200,22 +200,29 @@ function convertFileNameToModuleName (filename) { // Compile js task for preview ---------- // -------------------------------------- gulp.task('js:compile', (done) => { - // for dist/ folder we only want compiled 'all.js' + // For dist/ folder we only want compiled 'all.js' const fileLookup = isDist ? configPaths.src + 'all.js' : configPaths.src + '**/!(*.test).js' + + // Perform a synchronous search and return an array of matching file names const srcFiles = glob.sync(fileLookup) srcFiles.forEach(function (file) { - const currentDirectory = path.dirname(file) - const newDirectory = currentDirectory.replace('src/govuk', '') - const fileName = path.parse(file).name + // This is combined with desinationPath in gulp.dest() + // so the files are output to the correct folders + const newDirectoryPath = path.dirname(file).replace('src/govuk', '') // Convert the file name from dashed (e.g: character-count) to PascalCase (e.g: CharacterCount) + const fileName = path.parse(file).name const moduleName = convertFileNameToModuleName(fileName) + // We only want to give component JavaScript a unique module name + const componentJavaScript = path.dirname(file).includes("/components/") + return gulp.src(file) .pipe(rollup({ - // Used to set the `window` global and UMD/AMD export name. - name: fileName === 'all' ? 'GOVUKFrontend' : 'GOVUKFrontend.' + moduleName, + // Used to set the `window` global and UMD/AMD export name + // Component JavaScript is given a unique name to aid individual imports, e.g GOVUKFrontend.Accordion + name: componentJavaScript ? 'GOVUKFrontend.' + moduleName : 'GOVUKFrontend', // Legacy mode is required for IE8 support legacy: true, // UMD allows the published bundle to work in CommonJS and in the browser. @@ -231,7 +238,7 @@ gulp.task('js:compile', (done) => { }) )) .pipe(eol()) - .pipe(gulp.dest(destinationPath() + newDirectory)) + .pipe(gulp.dest(destinationPath() + newDirectoryPath)) }) done() })