From 1822d0f346dace9c87a77a08b0063ed810c6107a Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Fri, 10 Mar 2023 10:20:16 +0000 Subject: [PATCH] Move build tasks into tasks/build --- gulpfile.mjs | 134 +----------------- jest.config.mjs | 4 +- package.json | 6 +- tasks/build/dist.mjs | 53 +++++++ .../dist.test.mjs} | 4 +- tasks/build/index.mjs | 6 + tasks/build/package.mjs | 78 ++++++++++ .../package.test.mjs} | 8 +- tasks/build/public.mjs | 28 ++++ 9 files changed, 182 insertions(+), 139 deletions(-) create mode 100644 tasks/build/dist.mjs rename tasks/{gulp/__tests__/after-build-dist.test.mjs => build/dist.test.mjs} (96%) create mode 100644 tasks/build/index.mjs create mode 100644 tasks/build/package.mjs rename tasks/{gulp/__tests__/after-build-package.test.mjs => build/package.test.mjs} (97%) create mode 100644 tasks/build/public.mjs diff --git a/gulpfile.mjs b/gulpfile.mjs index 7bd2fe25ff..9669506c32 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -2,13 +2,10 @@ import { join, normalize } from 'path' import gulp from 'gulp' -import { paths, pkg } from './config/index.js' -import { clean } from './tasks/clean.mjs' -import { compileConfig } from './tasks/compile-configs.mjs' +import { paths } from './config/index.js' +import * as build from './tasks/build/index.mjs' import { compileJavaScripts } from './tasks/compile-javascripts.mjs' import { compileStylesheets } from './tasks/compile-stylesheets.mjs' -import { version } from './tasks/file.mjs' -import { copyAssets, copyFiles } from './tasks/gulp/copy-to-destination.mjs' import { watch } from './tasks/gulp/watch.mjs' import { npmScriptTask } from './tasks/run.mjs' @@ -47,130 +44,11 @@ gulp.task('styles', gulp.series( )) /** - * Build public task - * Prepare public folder for review app + * Build target tasks */ -gulp.task('build:public', gulp.series( - clean('**/*', { - destPath: paths.public - }), - - // Copy GOV.UK Frontend static assets - copyAssets('**/*', { - srcPath: join(paths.src, 'govuk/assets'), - destPath: join(paths.public, 'assets') - }), - - 'scripts', - 'styles' -)) - -/** - * Build package task - * Prepare package folder for publishing - */ -gulp.task('build:package', gulp.series( - clean('**/*', { - destPath: paths.package, - ignore: [ - '**/package.json', - '**/README.md' - ] - }), - - // Copy GOV.UK Frontend files - copyFiles({ - srcPath: paths.src, - destPath: paths.package - }), - - // Copy GOV.UK Frontend JavaScript (ES modules) - copyAssets('**/!(*.test).mjs', { - srcPath: join(paths.src, 'govuk'), - destPath: join(paths.package, 'govuk-esm') - }), - - // Compile GOV.UK Frontend JavaScript (AMD modules) - compileJavaScripts('**/!(*.test).mjs', { - srcPath: join(paths.src, 'govuk'), - destPath: join(paths.package, 'govuk'), - - filePath (file) { - return join(file.dir, `${file.name}.js`) - } - }), - - // Apply CSS prefixes to GOV.UK Frontend Sass - compileStylesheets('**/*.scss', { - srcPath: join(paths.src, 'govuk'), - destPath: join(paths.package, 'govuk'), - - filePath (file) { - return join(file.dir, `${file.name}.scss`) - } - }), - - // Apply CSS prefixes to GOV.UK Prototype Kit Sass - compileStylesheets('init.scss', { - srcPath: join(paths.src, 'govuk-prototype-kit'), - destPath: join(paths.package, 'govuk-prototype-kit'), - - filePath (file) { - return join(file.dir, `${file.name}.scss`) - } - }), - - // Compile GOV.UK Prototype Kit config - compileConfig('govuk-prototype-kit.config.mjs', { - srcPath: join(paths.src, 'govuk-prototype-kit'), - destPath: paths.package, - - filePath (file) { - return join(file.dir, `${file.name}.json`) - } - }) -)) - -/** - * Build dist task - * Prepare dist folder for release - */ -gulp.task('build:dist', gulp.series( - clean('**/*', { - destPath: paths.dist - }), - - // Copy GOV.UK Frontend static assets - copyAssets('*/**', { - srcPath: join(paths.src, 'govuk/assets'), - destPath: join(paths.dist, 'assets') - }), - - // Compile GOV.UK Frontend JavaScript - compileJavaScripts('all.mjs', { - srcPath: join(paths.src, 'govuk'), - destPath: paths.dist, - - filePath (file) { - return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.js`) - } - }), - - // Compile GOV.UK Frontend Sass - compileStylesheets('[!_]*.scss', { - srcPath: join(paths.src, 'govuk'), - destPath: paths.dist, - - filePath (file) { - return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.css`) - } - }), - - // Update GOV.UK Frontend version - version('VERSION.txt', { - destPath: paths.dist - }) -)) +gulp.task('build:public', build.public()) +gulp.task('build:package', build.package()) +gulp.task('build:dist', build.dist()) /** * Dev task diff --git a/jest.config.mjs b/jest.config.mjs index 3828a60883..2f5951ef55 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -32,9 +32,9 @@ export default { projects: [ { ...config, - displayName: 'Gulp tasks', + displayName: 'Build tasks', testMatch: [ - '**/gulp/**/*.test.{js,mjs}' + '**/tasks/build/*.test.{js,mjs}' ] }, { diff --git a/package.json b/package.json index 67a02bc2ba..6933e4d991 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,10 @@ "build:package": "gulp build:package", "build:dist": "gulp build:dist", "build:types": "tsc --build", - "postbuild:package": "jest --color --selectProjects \"Gulp tasks\" --testMatch \"**/*build-package*\"", - "postbuild:dist": "jest --color --selectProjects \"Gulp tasks\" --testMatch \"**/*build-dist*\"", + "postbuild:package": "jest --color --selectProjects \"Build tasks\" --testMatch \"**/*package.test*\"", + "postbuild:dist": "jest --color --selectProjects \"Build tasks\" --testMatch \"**/*dist.test*\"", "pretest": "npm run build:public", - "test": "jest --color --ignoreProjects \"Gulp tasks\" --maxWorkers=50%", + "test": "jest --color --ignoreProjects \"Build tasks\" --maxWorkers=50%", "test:screenshots": "node ./tasks/screenshot-components.mjs", "lint": "npm run lint:editorconfig && npm run lint:prettier && npm run lint:js && npm run lint:scss", "lint:editorconfig": "npm run lint:editorconfig:cli", diff --git a/tasks/build/dist.mjs b/tasks/build/dist.mjs new file mode 100644 index 0000000000..2799e66891 --- /dev/null +++ b/tasks/build/dist.mjs @@ -0,0 +1,53 @@ +import { join } from 'path' + +import gulp from 'gulp' + +import { paths, pkg } from '../../config/index.js' +import { clean } from '../clean.mjs' +import { compileJavaScripts } from '../compile-javascripts.mjs' +import { compileStylesheets } from '../compile-stylesheets.mjs' +import { version } from '../file.mjs' +import { copyAssets } from '../gulp/copy-to-destination.mjs' + +/** + * Build dist task + * Prepare dist folder for release + * + * @returns {() => import('gulp').TaskFunction} Task function + */ +export default () => gulp.series( + clean('**/*', { + destPath: paths.dist + }), + + // Copy GOV.UK Frontend static assets + copyAssets('*/**', { + srcPath: join(paths.src, 'govuk/assets'), + destPath: join(paths.dist, 'assets') + }), + + // Compile GOV.UK Frontend JavaScript + compileJavaScripts('all.mjs', { + srcPath: join(paths.src, 'govuk'), + destPath: paths.dist, + + filePath (file) { + return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.js`) + } + }), + + // Compile GOV.UK Frontend Sass + compileStylesheets('[!_]*.scss', { + srcPath: join(paths.src, 'govuk'), + destPath: paths.dist, + + filePath (file) { + return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.css`) + } + }), + + // Update GOV.UK Frontend version + version('VERSION.txt', { + destPath: paths.dist + }) +) diff --git a/tasks/gulp/__tests__/after-build-dist.test.mjs b/tasks/build/dist.test.mjs similarity index 96% rename from tasks/gulp/__tests__/after-build-dist.test.mjs rename to tasks/build/dist.test.mjs index e045d34222..10b0f0afce 100644 --- a/tasks/gulp/__tests__/after-build-dist.test.mjs +++ b/tasks/build/dist.test.mjs @@ -2,8 +2,8 @@ import { readFile } from 'fs/promises' import { EOL } from 'os' import { join } from 'path' -import { paths, pkg } from '../../../config/index.js' -import { getListing } from '../../../lib/file-helper.js' +import { paths, pkg } from '../../config/index.js' +import { getListing } from '../../lib/file-helper.js' describe('dist/', () => { let listingSourceAssets diff --git a/tasks/build/index.mjs b/tasks/build/index.mjs new file mode 100644 index 0000000000..8e831bef0d --- /dev/null +++ b/tasks/build/index.mjs @@ -0,0 +1,6 @@ +/** + * Build target tasks + */ +export { default as public } from './public.mjs' +export { default as package } from './package.mjs' +export { default as dist } from './dist.mjs' diff --git a/tasks/build/package.mjs b/tasks/build/package.mjs new file mode 100644 index 0000000000..0f5ecc0e5c --- /dev/null +++ b/tasks/build/package.mjs @@ -0,0 +1,78 @@ +import { join } from 'path' + +import gulp from 'gulp' + +import { paths } from '../../config/index.js' +import { clean } from '../clean.mjs' +import { compileConfig } from '../compile-configs.mjs' +import { compileJavaScripts } from '../compile-javascripts.mjs' +import { compileStylesheets } from '../compile-stylesheets.mjs' +import { copyAssets, copyFiles } from '../gulp/copy-to-destination.mjs' + +/** + * Build package task + * Prepare package folder for publishing + * + * @returns {() => import('gulp').TaskFunction} Task function + */ +export default () => gulp.series( + clean('**/*', { + destPath: paths.package, + ignore: [ + '**/package.json', + '**/README.md' + ] + }), + + // Copy GOV.UK Frontend files + copyFiles({ + srcPath: paths.src, + destPath: paths.package + }), + + // Copy GOV.UK Frontend JavaScript (ES modules) + copyAssets('**/!(*.test).mjs', { + srcPath: join(paths.src, 'govuk'), + destPath: join(paths.package, 'govuk-esm') + }), + + // Compile GOV.UK Frontend JavaScript (AMD modules) + compileJavaScripts('**/!(*.test).mjs', { + srcPath: join(paths.src, 'govuk'), + destPath: join(paths.package, 'govuk'), + + filePath (file) { + return join(file.dir, `${file.name}.js`) + } + }), + + // Apply CSS prefixes to GOV.UK Frontend Sass + compileStylesheets('**/*.scss', { + srcPath: join(paths.src, 'govuk'), + destPath: join(paths.package, 'govuk'), + + filePath (file) { + return join(file.dir, `${file.name}.scss`) + } + }), + + // Apply CSS prefixes to GOV.UK Prototype Kit Sass + compileStylesheets('init.scss', { + srcPath: join(paths.src, 'govuk-prototype-kit'), + destPath: join(paths.package, 'govuk-prototype-kit'), + + filePath (file) { + return join(file.dir, `${file.name}.scss`) + } + }), + + // Compile GOV.UK Prototype Kit config + compileConfig('govuk-prototype-kit.config.mjs', { + srcPath: join(paths.src, 'govuk-prototype-kit'), + destPath: paths.package, + + filePath (file) { + return join(file.dir, `${file.name}.json`) + } + }) +) diff --git a/tasks/gulp/__tests__/after-build-package.test.mjs b/tasks/build/package.test.mjs similarity index 97% rename from tasks/gulp/__tests__/after-build-package.test.mjs rename to tasks/build/package.test.mjs index 88c534699a..04a8691494 100644 --- a/tasks/gulp/__tests__/after-build-package.test.mjs +++ b/tasks/build/package.test.mjs @@ -1,10 +1,10 @@ import { readFile } from 'fs/promises' import { join } from 'path' -import { paths } from '../../../config/index.js' -import { filterPath, getDirectories, getListing, mapPathTo } from '../../../lib/file-helper.js' -import { componentNameToClassName, componentPathToModuleName } from '../../../lib/helper-functions.js' -import { compileSassFile } from '../../../lib/jest-helpers.js' +import { paths } from '../../config/index.js' +import { filterPath, getDirectories, getListing, mapPathTo } from '../../lib/file-helper.js' +import { componentNameToClassName, componentPathToModuleName } from '../../lib/helper-functions.js' +import { compileSassFile } from '../../lib/jest-helpers.js' describe('package/', () => { let listingSource diff --git a/tasks/build/public.mjs b/tasks/build/public.mjs new file mode 100644 index 0000000000..3e25f38166 --- /dev/null +++ b/tasks/build/public.mjs @@ -0,0 +1,28 @@ +import { join } from 'path' + +import gulp from 'gulp' + +import { paths } from '../../config/index.js' +import { clean } from '../clean.mjs' +import { copyAssets } from '../gulp/copy-to-destination.mjs' + +/** + * Build public task + * Prepare public folder for review app + * + * @returns {() => import('gulp').TaskFunction} Task function + */ +export default () => gulp.series( + clean('**/*', { + destPath: paths.public + }), + + // Copy GOV.UK Frontend static assets + copyAssets('**/*', { + srcPath: join(paths.src, 'govuk/assets'), + destPath: join(paths.public, 'assets') + }), + + 'scripts', + 'styles' +)