Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch for changes to assets #3910

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we share this new task with release.mjs too?

It's mostly identical between package.mjs and release.mjs

Would just need destPath overriding without the govuk/ prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will leave this as a future improvement if that's alright.

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but we might want to remove unlink (delete) events from our watchers

Suggested change
], assets(options))
], { events: ['add', 'change'] }, assets(options))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had noticed that when deleting a file from src it wasn't deleted from package, presumably because we're only running copy:files and not clean.

Removing the unlink wouldn't fix that but would prevent running the task when a file's deleted when it's not going to do anything anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point, it would only stop early triggering of tasks really—but might free up some "polling" CPU time for all our Windows users too?

Would be a separate issue to synchronise directories fully

)
)