Skip to content

Commit

Permalink
Merge pull request #2876 from alphagov/source-javascript-copy
Browse files Browse the repository at this point in the history
Don’t copy *.js files into `govuk-esm`
  • Loading branch information
colinrotherham authored Sep 26, 2022
2 parents 69e5c32 + 79ae895 commit 5369f8e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 57 deletions.
3 changes: 1 addition & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ gulp.task('dev', gulp.series(
gulp.task('build:package', gulp.series(
cleanPackage,
'copy-files',
'js:compile',
'js:copy-esm'
'js:compile'
))

gulp.task('build:dist', gulp.series(
Expand Down
117 changes: 62 additions & 55 deletions tasks/gulp/copy-to-destination.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,70 @@ const taskArguments = require('../task-arguments')

gulp.task('copy-files', () => {
return merge(
/**
* Copy files to destination with './govuk-esm' suffix
* Includes only source JavaScript ECMAScript (ES) modules
*/
gulp.src([
`${configPaths.src}**/*`,

// Exclude files from copy
'!**/.DS_Store',
'!**/*.mjs',
'!**/*.test.*',
'!**/__snapshots__/',
'!**/__snapshots__/**',

// Preserve destination README when copying to ./package
// https://github.com/alphagov/govuk-frontend/tree/main/package#readme
`!${configPaths.src}README.md`,

// Exclude files from other streams
`!${configPaths.src}**/*.scss`,
`!${configPaths.components}**/*.yaml`
]),

// Add CSS prefixes to Sass
gulp.src(`${configPaths.src}**/*.scss`)
.pipe(postcss([autoprefixer], { syntax: postcssScss })),

// Generate fixtures.json from ${component}.yaml
gulp.src(`${configPaths.components}**/*.yaml`, { base: configPaths.src })
.pipe(map((file, done) =>
generateFixtures(file)
.then((fixture) => done(null, fixture))
.catch(done)
))
.pipe(rename({
basename: 'fixtures',
extname: '.json'
})),

// Generate macro-options.json from ${component}.yaml
gulp.src(`${configPaths.components}**/*.yaml`, { base: configPaths.src })
.pipe(map((file, done) =>
generateMacroOptions(file)
.then((macro) => done(null, macro))
.catch(done)
))
.pipe(rename({
basename: 'macro-options',
extname: '.json'
}))
`${configPaths.src}**/*.mjs`,
`!${configPaths.src}**/*.test.*`
]).pipe(gulp.dest(`${taskArguments.destination}/govuk-esm/`)),

/**
* Copy files to destination with './govuk' suffix
* Includes fonts, images, polyfills, component files
*/
merge(
gulp.src([
`${configPaths.src}**/*`,

// Exclude files we don't want to publish
'!**/.DS_Store',
'!**/*.mjs',
'!**/*.test.*',
'!**/__snapshots__/',
'!**/__snapshots__/**',

// Preserve destination README when copying to ./package
// https://github.com/alphagov/govuk-frontend/tree/main/package#readme
`!${configPaths.src}README.md`,

// Exclude Sass files handled by PostCSS stream below
`!${configPaths.src}**/*.scss`,

// Exclude source YAML handled by JSON streams below
`!${configPaths.components}**/*.yaml`
]),

// Add CSS prefixes to Sass
gulp.src(`${configPaths.src}**/*.scss`)
.pipe(postcss([autoprefixer], { syntax: postcssScss })),

// Generate fixtures.json from ${component}.yaml
gulp.src(`${configPaths.components}**/*.yaml`, { base: configPaths.src })
.pipe(map((file, done) =>
generateFixtures(file)
.then((fixture) => done(null, fixture))
.catch(done)
))
.pipe(rename({
basename: 'fixtures',
extname: '.json'
})),

// Generate macro-options.json from ${component}.yaml
gulp.src(`${configPaths.components}**/*.yaml`, { base: configPaths.src })
.pipe(map((file, done) =>
generateMacroOptions(file)
.then((macro) => done(null, macro))
.catch(done)
))
.pipe(rename({
basename: 'macro-options',
extname: '.json'
}))
).pipe(gulp.dest(`${taskArguments.destination}/govuk/`))
)
.pipe(gulp.dest(`${taskArguments.destination}/govuk/`))
})

/**
Expand Down Expand Up @@ -109,15 +125,6 @@ async function generateFixtures (file) {
return file
}

gulp.task('js:copy-esm', () => {
return gulp.src([
`${configPaths.src}**/*.mjs`,
`${configPaths.src}**/*.js`,
`!${configPaths.src}**/*.test.*`
])
.pipe(gulp.dest(taskArguments.destination + '/govuk-esm/'))
})

/**
* Replace file content with macro-options.json
*
Expand Down

0 comments on commit 5369f8e

Please sign in to comment.