Skip to content

Commit

Permalink
Watch for changes to assets
Browse files Browse the repository at this point in the history
Watch the `govuk/assets` folder and re-run the assets task when there are changes.

This means that changes to the assets folder are applied to the dist folder (and therefore are reflected in the review app) without having to manually run the `build:package` task.
  • Loading branch information
36degrees committed Jul 6, 2023
1 parent 6a8fb79 commit ed92f34
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
18 changes: 18 additions & 0 deletions packages/govuk-frontend/tasks/assets.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { join } from 'path'

import { files, task } from 'govuk-frontend-tasks'
import gulp from 'gulp'

/**
* Copy GOV.UK Frontend assets (for watch)
*
* @type {import('govuk-frontend-tasks').TaskFunction}
*/
export const assets = (options) => gulp.series(
task.name('copy:assets', () =>
files.copy('**/*', {
srcPath: join(options.srcPath, 'govuk/assets'),
destPath: join(options.destPath, 'govuk/assets')
})
)
)
11 changes: 2 additions & 9 deletions packages/govuk-frontend/tasks/build/package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'path'
import { files, task } from 'govuk-frontend-tasks'
import gulp from 'gulp'

import { fixtures, scripts, styles, templates } from '../index.mjs'
import { assets, fixtures, scripts, styles, templates } from '../index.mjs'

/**
* Build package task
Expand All @@ -16,19 +16,12 @@ export default (options) => gulp.series(
files.clean('*', options)
),

assets(options),
fixtures(options),
scripts(options),
styles(options),
templates(options),

// Copy GOV.UK Frontend static assets
task.name('copy:assets', () =>
files.copy('**/*', {
srcPath: join(options.srcPath, 'govuk/assets'),
destPath: join(options.destPath, 'govuk/assets')
})
),

// Copy GOV.UK Prototype Kit JavaScript
task.name("copy:files 'govuk-prototype-kit'", () =>
files.copy('**/*.js', {
Expand Down
1 change: 1 addition & 0 deletions packages/govuk-frontend/tasks/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Build tasks
*/
export { assets } from './assets.mjs'
export { compile as fixtures } from './fixtures.mjs'
export { compile as scripts } from './scripts.mjs'
export { compile as styles } from './styles.mjs'
Expand Down
9 changes: 8 additions & 1 deletion packages/govuk-frontend/tasks/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { npm, task } from 'govuk-frontend-tasks'
import gulp from 'gulp'
import slash from 'slash'

import { fixtures, scripts, styles, templates } from './index.mjs'
import { assets, fixtures, scripts, styles, templates } from './index.mjs'

/**
* Watch task
Expand Down Expand Up @@ -57,5 +57,12 @@ export const watch = (options) => gulp.parallel(
gulp.watch([
`${slash(options.srcPath)}/govuk/**/*.{md,njk}`
], templates(options))
),

// Copy GOV.UK Frontend static assets
task.name('copy:assets watch', () =>
gulp.watch([
`${slash(options.srcPath)}/govuk/assets/`
], assets(options))
)
)

0 comments on commit ed92f34

Please sign in to comment.