Skip to content

Commit

Permalink
Merge pull request #5470 from alphagov/disable-dev-linting
Browse files Browse the repository at this point in the history
  • Loading branch information
romaricpascal authored Nov 5, 2024
2 parents 57f5b73 + cb94610 commit 96572b1
Showing 1 changed file with 41 additions and 44 deletions.
85 changes: 41 additions & 44 deletions tasks/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ import { assets, fixtures, scripts, styles, templates } from './index.mjs'
*
* @type {import('@govuk-frontend/tasks').TaskFunction}
*/
export const watch = (options) =>
gulp.parallel(
/**
* Stylesheets lint watcher
*/
task.name('lint:scss watch', () =>
export const watch = (options) => gulp.parallel(...getTasks(options))

/**
* Compute the lists of tasks to be run in parallel
*
* Allows some of the tasks to be disabled by environment variables
*
* @param {import('@govuk-frontend/tasks').TaskOptions} options
* @returns {any[]} The list of tasks to run in parallel
*/
function getTasks(options) {
const tasks = {
'lint:scss watch': disabledBy('GOVUK_DS_FRONTEND_NO_LINTING', 'scss', () =>
gulp.watch(
'**/*.scss',
{ cwd: options.srcPath },
Expand All @@ -38,24 +45,15 @@ export const watch = (options) =>
])
)
),

/**
* Stylesheets build watcher
*/
task.name('compile:scss watch', () =>
'compile:scss watch': () =>
gulp.watch(
'**/*.scss',
{ cwd: options.srcPath },

// Run Sass compile
styles(options)
)
),

/**
* JavaScripts lint watcher
*/
task.name('lint:js watch', () =>
),
'lint:js watch': disabledBy('GOVUK_DS_FRONTEND_NO_LINTING', 'js', () =>
gulp.watch(
'**/*.{cjs,js,mjs}',
{ cwd: options.srcPath, ignored: ['**/*.test.*'] },
Expand All @@ -70,54 +68,53 @@ export const watch = (options) =>
)
)
),

/**
* JavaScripts build watcher
*/
task.name('compile:js watch', () =>
'compile:js watch': () =>
gulp.watch(
'**/*.{cjs,js,mjs}',
{ cwd: options.srcPath, ignored: ['**/*.test.*'] },

// Run JavaScripts compile
scripts(options)
)
),

/**
* Component fixtures watcher
*/
task.name('compile:fixtures watch', () =>
),
'compile:fixtures watch': () =>
gulp.watch(
'govuk/components/*/*.yaml',
{ cwd: options.srcPath },

// Run fixtures compile
fixtures(options)
)
),

/**
* Component template watcher
*/
task.name('copy:templates watch', () =>
),
'copy:templates watch': () =>
gulp.watch(
'govuk/**/*.{md,njk}',
{ cwd: options.srcPath },

// Run templates copy
templates(options)
)
),

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

// Run assets copy
assets(options)
)
)
)
}

return Object.entries(tasks)
.filter(([taskName, fn]) => !!fn)
.map(([taskName, fn]) => task.name(taskName, fn))
}

function disabledBy(envVariableName, value, fn) {
// Split by comma to ensure we'll match full options
// avoiding `css` to match `scss` if we were looking in the whole string
const disabledValues = process.env[envVariableName]?.split?.(',')

if (disabledValues?.includes?.(value)) {
return null
}

return fn
}

0 comments on commit 96572b1

Please sign in to comment.