Skip to content

Commit

Permalink
Fixup comments from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanita Barrett committed Nov 12, 2021
1 parent 7501399 commit 8cc158c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tasks/gulp/compile-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -231,7 +238,7 @@ gulp.task('js:compile', (done) => {
})
))
.pipe(eol())
.pipe(gulp.dest(destinationPath() + newDirectory))
.pipe(gulp.dest(destinationPath() + newDirectoryPath))
})
done()
})

0 comments on commit 8cc158c

Please sign in to comment.