From f7ec3185fb31b97177b367eadb4205b8bf2fc8d7 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 14 Mar 2023 16:45:14 +0000 Subject: [PATCH] Split review app tasks into app/tasks (without Gulp) --- Procfile | 2 +- app/gulpfile.mjs | 10 ++++++ app/package.json | 8 ++++- app/tasks/assets.mjs | 14 ++++++++ app/tasks/build/dev.mjs | 14 ++++++++ app/tasks/build/index.mjs | 5 +++ app/tasks/build/public.mjs | 15 ++++++++ app/tasks/clean.mjs | 13 +++++++ app/tasks/index.mjs | 8 +++++ app/tasks/scripts.mjs | 23 ++++++++++++ app/tasks/styles.mjs | 23 ++++++++++++ {tasks/gulp => app/tasks}/watch.mjs | 23 ++++++------ app/tsconfig.json | 4 +-- docs/contributing/tasks.md | 7 +--- gulpfile.mjs | 54 ++--------------------------- jest-dev-server.config.js | 3 +- package-lock.json | 8 ++++- package.json | 5 ++- tasks/build/dist.mjs | 26 ++++++-------- tasks/build/index.mjs | 1 - tasks/build/package.mjs | 50 ++++++++++++-------------- tasks/build/public.mjs | 27 --------------- tasks/configs.mjs | 18 ++++------ tasks/files.mjs | 28 ++++----------- tasks/gulp/copy-to-destination.mjs | 16 +++------ tasks/npm.mjs | 20 +---------- tasks/scripts.mjs | 26 ++++++-------- tasks/styles.mjs | 23 +++++------- 28 files changed, 232 insertions(+), 242 deletions(-) create mode 100644 app/gulpfile.mjs create mode 100644 app/tasks/assets.mjs create mode 100644 app/tasks/build/dev.mjs create mode 100644 app/tasks/build/index.mjs create mode 100644 app/tasks/build/public.mjs create mode 100644 app/tasks/clean.mjs create mode 100644 app/tasks/index.mjs create mode 100644 app/tasks/scripts.mjs create mode 100644 app/tasks/styles.mjs rename {tasks/gulp => app/tasks}/watch.mjs (67%) delete mode 100644 tasks/build/public.mjs diff --git a/Procfile b/Procfile index 32413752186..235e18a3bcb 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: npm run heroku +web: npm start --workspace app diff --git a/app/gulpfile.mjs b/app/gulpfile.mjs new file mode 100644 index 00000000000..09b57ee42bc --- /dev/null +++ b/app/gulpfile.mjs @@ -0,0 +1,10 @@ + +import gulp from 'gulp' + +import * as build from './tasks/build/index.mjs' + +/** + * Build target tasks + */ +gulp.task('build:public', build.public) +gulp.task('dev', build.dev) diff --git a/app/package.json b/app/package.json index 0e00caee377..9d1730c6625 100644 --- a/app/package.json +++ b/app/package.json @@ -9,7 +9,10 @@ }, "license": "MIT", "scripts": { + "build:public": "gulp build:public", + "dev": "gulp dev", "serve": "nodemon", + "prestart": "npm run build:public", "start": "node src/start.mjs" }, "dependencies": { @@ -21,6 +24,8 @@ "govuk_frontend_toolkit": "^9.0.1", "govuk_template_jinja": "^0.26.0", "govuk-elements-sass": "3.1.3", + "gulp": "^4.0.2", + "gulp-cli": "^2.3.0", "highlight.js": "^11.7.0", "html5shiv": "^3.7.3", "iframe-resizer": "3.5.15", @@ -32,7 +37,8 @@ "nodemon": "^2.0.21", "nunjucks": "^3.2.3", "outdent": "^0.8.0", - "shuffle-seed": "^1.1.6" + "shuffle-seed": "^1.1.6", + "slash": "^5.0.0" }, "devDependencies": { "cheerio": "^1.0.0-rc.12", diff --git a/app/tasks/assets.mjs b/app/tasks/assets.mjs new file mode 100644 index 00000000000..5df5486d0d3 --- /dev/null +++ b/app/tasks/assets.mjs @@ -0,0 +1,14 @@ +import { join } from 'path' + +import { paths } from '../../config/index.js' +import * as files from '../../tasks/files.mjs' + +/** + * Copy GOV.UK Frontend static assets + */ +export async function assets () { + await files.copy('**/*', { + srcPath: join(paths.src, 'govuk/assets'), + destPath: join(paths.app, 'public/assets') + }) +} diff --git a/app/tasks/build/dev.mjs b/app/tasks/build/dev.mjs new file mode 100644 index 00000000000..7010b7735a9 --- /dev/null +++ b/app/tasks/build/dev.mjs @@ -0,0 +1,14 @@ +import * as npm from '../../../tasks/npm.mjs' +import * as tasks from '../index.mjs' + +import * as build from './index.mjs' + +/** + * Dev task + * Runs a sequence of tasks on start + */ +export default async function dev () { + await build.public() + await tasks.watch() + await npm.run('serve') +} diff --git a/app/tasks/build/index.mjs b/app/tasks/build/index.mjs new file mode 100644 index 00000000000..ac9b97ba8c9 --- /dev/null +++ b/app/tasks/build/index.mjs @@ -0,0 +1,5 @@ +/** + * Build target tasks + */ +export { default as dev } from './dev.mjs' +export { default as public } from './public.mjs' diff --git a/app/tasks/build/public.mjs b/app/tasks/build/public.mjs new file mode 100644 index 00000000000..646c8a99722 --- /dev/null +++ b/app/tasks/build/public.mjs @@ -0,0 +1,15 @@ +import * as tasks from '../index.mjs' + +/** + * Build public task + * Prepare public folder for review app + */ +export default async function build () { + await tasks.clean() + + await Promise.all([ + tasks.assets(), + tasks.scripts(), + tasks.styles() + ]) +} diff --git a/app/tasks/clean.mjs b/app/tasks/clean.mjs new file mode 100644 index 00000000000..fc8bfaff936 --- /dev/null +++ b/app/tasks/clean.mjs @@ -0,0 +1,13 @@ +import { join } from 'path' + +import { paths } from '../../config/index.js' +import * as files from '../../tasks/files.mjs' + +/** + * Clean task + */ +export async function clean () { + await files.clean('**/*', { + destPath: join(paths.app, 'public') + }) +} diff --git a/app/tasks/index.mjs b/app/tasks/index.mjs new file mode 100644 index 00000000000..786501008ea --- /dev/null +++ b/app/tasks/index.mjs @@ -0,0 +1,8 @@ +/** + * Build tasks + */ +export { assets } from './assets.mjs' +export { clean } from './clean.mjs' +export { compile as scripts } from './scripts.mjs' +export { compile as styles } from './styles.mjs' +export { watch } from './watch.mjs' diff --git a/app/tasks/scripts.mjs b/app/tasks/scripts.mjs new file mode 100644 index 00000000000..26498f38a3d --- /dev/null +++ b/app/tasks/scripts.mjs @@ -0,0 +1,23 @@ +import { join, normalize } from 'path' + +import { paths } from '../../config/index.js' +import * as npm from '../../tasks/npm.mjs' +import * as scripts from '../../tasks/scripts.mjs' + +/** + * JavaScripts task (for watch) + * Compilation, documentation + */ +export async function compile () { + await scripts.compile('all.mjs', { + srcPath: join(paths.src, 'govuk'), + destPath: join(paths.app, 'public/javascripts'), + + filePath (file) { + return normalize(`${file.name}.min.js`) + } + }) + + // Build JSDoc for /docs/javascript + await npm.run('build:jsdoc') +} diff --git a/app/tasks/styles.mjs b/app/tasks/styles.mjs new file mode 100644 index 00000000000..d1f02255756 --- /dev/null +++ b/app/tasks/styles.mjs @@ -0,0 +1,23 @@ +import { join, normalize } from 'path' + +import { paths } from '../../config/index.js' +import * as npm from '../../tasks/npm.mjs' +import * as styles from '../../tasks/styles.mjs' + +/** + * Stylesheets task (for watch) + * Compilation, documentation + */ +export async function compile () { + await styles.compile('[!_]*.scss', { + srcPath: join(paths.app, 'src'), + destPath: join(paths.app, 'public/stylesheets'), + + filePath (file) { + return normalize(`${file.name}.min.css`) + } + }) + + // Build SassDoc for /docs/sass + await npm.run('build:sassdoc') +} diff --git a/tasks/gulp/watch.mjs b/app/tasks/watch.mjs similarity index 67% rename from tasks/gulp/watch.mjs rename to app/tasks/watch.mjs index 280d11bb00f..2466ff45263 100644 --- a/tasks/gulp/watch.mjs +++ b/app/tasks/watch.mjs @@ -2,7 +2,10 @@ import gulp from 'gulp' import slash from 'slash' import { paths } from '../../config/index.js' -import * as npm from '../npm.mjs' +import * as npm from '../../tasks/npm.mjs' + +import * as scripts from './scripts.mjs' +import * as styles from './styles.mjs' /** * Watch task @@ -15,23 +18,21 @@ import * as npm from '../npm.mjs' export function watch () { return Promise.all([ gulp.watch([ - 'sassdoc.config.yaml', + `${slash(paths.app)}/sassdoc.config.yaml`, `${slash(paths.app)}/src/**/*.scss`, `${slash(paths.src)}/govuk/**/*.scss`, `!${slash(paths.src)}/govuk/vendor/*` - ], gulp.parallel( + ], () => Promise.all([ npm.run('lint:scss'), - 'styles' - )), + styles.compile() + ])), gulp.watch([ - 'jsdoc.config.js', + `${slash(paths.app)}/jsdoc.config.js`, `${slash(paths.src)}/govuk/**/*.mjs` - ], gulp.parallel( + ], () => Promise.all([ npm.run('lint:js'), - 'scripts' - )) + scripts.compile() + ])) ]) } - -watch.displayName = 'watch' diff --git a/app/tsconfig.json b/app/tsconfig.json index 515b6c6e3a1..e1a35712108 100644 --- a/app/tsconfig.json +++ b/app/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../tsconfig.base.json", - "include": ["./src/**/*.mjs", "./src/**/*.json"], - "exclude": ["./src/**/*.test.*"], + "include": ["**/*.mjs", "**/*.json"], + "exclude": ["**/*.test.*", "./public/**"], "compilerOptions": { "resolveJsonModule": true } diff --git a/docs/contributing/tasks.md b/docs/contributing/tasks.md index 925966e3b80..e73fb25b072 100644 --- a/docs/contributing/tasks.md +++ b/docs/contributing/tasks.md @@ -8,7 +8,7 @@ To run the application without any tasks being triggered, see [Express app only] npm scripts are defined in `package.json`. These trigger a number of Gulp tasks. -**`npm start` will trigger `gulp dev` that will:** +**`npm start` will trigger `npm run dev --workspace app` that will:** - clean the `./app/public` folder - copy fonts and images @@ -26,11 +26,6 @@ npm scripts are defined in `package.json`. These trigger a number of Gulp tasks. - start up Express, restarting when `.js` files change -**`npm run heroku` runs on Heroku build/PR and it will:** - -- run `npm run build:public` -- start up Express - **`npm run build:public` will do the following:** - clean the `./app/public` folder diff --git a/gulpfile.mjs b/gulpfile.mjs index 80bdd2467dc..18787e8798e 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -1,61 +1,13 @@ -import { join, normalize } from 'path' - import gulp from 'gulp' -import { paths } from './config/index.js' import * as build from './tasks/build/index.mjs' -import { browser, files, scripts, styles, npm } from './tasks/index.mjs' - -/** - * Umbrella scripts tasks (for watch) - * Runs JavaScript code quality checks, documentation, compilation - */ -gulp.task('scripts', gulp.series( - scripts.compile('all.mjs', { - srcPath: join(paths.src, 'govuk'), - destPath: join(paths.app, 'public/javascripts'), - - filePath (file) { - return normalize(`${file.name}.min.js`) - } - }), - - npm.run('build:jsdoc') -)) - -/** - * Umbrella styles tasks (for watch) - * Runs Sass code quality checks, documentation, compilation - */ -gulp.task('styles', gulp.series( - styles.compile('[!_]*.scss', { - srcPath: join(paths.app, 'src'), - destPath: join(paths.app, 'public/stylesheets'), - - filePath (file) { - return normalize(`${file.name}.min.css`) - } - }), - - npm.run('build:sassdoc') -)) +import { browser } from './tasks/index.mjs' /** * Build target tasks */ -gulp.task('build:public', build.public()) -gulp.task('build:package', build.package()) -gulp.task('build:dist', build.dist()) - -/** - * Dev task - * Runs a sequence of tasks on start - */ -gulp.task('dev', gulp.series( - 'build:public', - files.watch, - npm.run('serve', ['--workspace', 'app']) -)) +gulp.task('build:package', build.package) +gulp.task('build:dist', build.dist) /** * Screenshots task diff --git a/jest-dev-server.config.js b/jest-dev-server.config.js index e44b8888c7f..0d51da02f75 100644 --- a/jest-dev-server.config.js +++ b/jest-dev-server.config.js @@ -4,7 +4,8 @@ const { ports } = require('./config/index.js') * @type {import('jest-dev-server').JestDevServerOptions} */ module.exports = { - command: 'npm start --workspace app', + // Start Express.js without "prestart" build script + command: 'npm start --ignore-scripts --workspace app', port: ports.app, // Skip when already running diff --git a/package-lock.json b/package-lock.json index 03e31e19352..6f82b3909f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -99,6 +99,8 @@ "govuk_frontend_toolkit": "^9.0.1", "govuk_template_jinja": "^0.26.0", "govuk-elements-sass": "3.1.3", + "gulp": "^4.0.2", + "gulp-cli": "^2.3.0", "highlight.js": "^11.7.0", "html5shiv": "^3.7.3", "iframe-resizer": "3.5.15", @@ -110,7 +112,8 @@ "nodemon": "^2.0.21", "nunjucks": "^3.2.3", "outdent": "^0.8.0", - "shuffle-seed": "^1.1.6" + "shuffle-seed": "^1.1.6", + "slash": "^5.0.0" }, "devDependencies": { "cheerio": "^1.0.0-rc.12", @@ -33252,6 +33255,8 @@ "govuk_frontend_toolkit": "^9.0.1", "govuk_template_jinja": "^0.26.0", "govuk-elements-sass": "3.1.3", + "gulp": "^4.0.2", + "gulp-cli": "^2.3.0", "highlight.js": "^11.7.0", "html5shiv": "^3.7.3", "iframe-resizer": "3.5.15", @@ -33264,6 +33269,7 @@ "nunjucks": "^3.2.3", "outdent": "^0.8.0", "shuffle-seed": "^1.1.6", + "slash": "^5.0.0", "supertest": "^6.3.3" }, "dependencies": { diff --git a/package.json b/package.json index 1ecdeba90f3..070dc4b9304 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,14 @@ ], "scripts": { "postinstall": "npm ls --depth=0", - "start": "gulp dev", + "start": "npm run dev --workspace app", "serve": "npm run serve --workspace app", - "heroku": "npm run build:public && npm start --workspace app", "build-release": "./bin/build-release.sh", "publish-release": "./bin/publish-release.sh", "pre-release": "./bin/pre-release.sh", "build:sassdoc": "sassdoc --config sassdoc.config.yaml ./src/govuk", "build:jsdoc": "jsdoc --configure jsdoc.config.js ./src/govuk", - "build:public": "gulp build:public", + "build:public": "npm run build:public --workspace app", "build:package": "gulp build:package", "build:dist": "gulp build:dist", "build:types": "tsc --build", diff --git a/tasks/build/dist.mjs b/tasks/build/dist.mjs index af1e8151ef5..c723b1c67c7 100644 --- a/tasks/build/dist.mjs +++ b/tasks/build/dist.mjs @@ -1,7 +1,5 @@ import { join } from 'path' -import gulp from 'gulp' - import { paths, pkg } from '../../config/index.js' import * as files from '../files.mjs' import * as scripts from '../scripts.mjs' @@ -10,42 +8,40 @@ import * as styles from '../styles.mjs' /** * Build dist task * Prepare dist folder for release - * - * @returns {() => import('gulp').TaskFunction} Task function */ -export default () => gulp.series( - files.clean('**/*', { +export default async function build () { + await files.clean('**/*', { destPath: paths.dist - }), + }) // Copy GOV.UK Frontend static assets - files.copy('*/**', { + await files.copy('*/**', { srcPath: join(paths.src, 'govuk/assets'), destPath: join(paths.dist, 'assets') - }), + }) // Compile GOV.UK Frontend JavaScript - scripts.compile('all.mjs', { + await scripts.compile('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 - styles.compile('[!_]*.scss', { + await styles.compile('[!_]*.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 - files.version('VERSION.txt', { + await files.version('VERSION.txt', { destPath: paths.dist }) -) +} diff --git a/tasks/build/index.mjs b/tasks/build/index.mjs index 8e831bef0de..dd0dcb62742 100644 --- a/tasks/build/index.mjs +++ b/tasks/build/index.mjs @@ -1,6 +1,5 @@ /** * 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 index 92b370acd49..9cfde5f299f 100644 --- a/tasks/build/package.mjs +++ b/tasks/build/package.mjs @@ -1,7 +1,5 @@ import { join } from 'path' -import gulp from 'gulp' - import { paths } from '../../config/index.js' import * as configs from '../configs.mjs' import * as files from '../files.mjs' @@ -11,95 +9,93 @@ import * as styles from '../styles.mjs' /** * Build package task * Prepare package folder for publishing - * - * @returns {() => import('gulp').TaskFunction} Task function */ -export default () => gulp.series( - files.clean('**/*', { +export default async function build () { + await files.clean('**/*', { destPath: paths.package, ignore: [ '**/package.json', '**/README.md' ] - }), + }) // Copy GOV.UK Frontend template files - files.copy('**/*.{md,njk}', { + await files.copy('**/*.{md,njk}', { srcPath: join(paths.src, 'govuk'), destPath: join(paths.package, 'govuk'), // Preserve paths.package README when copying to ./package // https://github.com/alphagov/govuk-frontend/tree/main/package#readme ignore: ['**/govuk/README.md'] - }), + }) // Copy GOV.UK Frontend static assets - files.copy('**/*', { + await files.copy('**/*', { srcPath: join(paths.src, 'govuk/assets'), destPath: join(paths.package, 'govuk/assets') - }), + }) // Generate GOV.UK Frontend fixtures.json from ${componentName}.yaml - files.generateFixtures({ + await files.generateFixtures({ srcPath: paths.src, destPath: paths.package - }), + }) // Generate GOV.UK Frontend macro-options.json from ${componentName}.yaml - files.generateMacroOptions({ + await files.generateMacroOptions({ srcPath: paths.src, destPath: paths.package - }), + }) // Copy GOV.UK Frontend JavaScript (ES modules) - files.copy('**/!(*.test).mjs', { + await files.copy('**/!(*.test).mjs', { srcPath: join(paths.src, 'govuk'), destPath: join(paths.package, 'govuk-esm') - }), + }) // Compile GOV.UK Frontend JavaScript (AMD modules) - scripts.compile('**/!(*.test).mjs', { + await scripts.compile('**/!(*.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 - styles.compile('**/*.scss', { + await styles.compile('**/*.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 - styles.compile('init.scss', { + await styles.compile('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 - configs.compile('govuk-prototype-kit.config.mjs', { + await configs.compile('govuk-prototype-kit.config.mjs', { srcPath: join(paths.src, 'govuk-prototype-kit'), destPath: paths.package, filePath (file) { return join(file.dir, `${file.name}.json`) } - }), + }) // Copy GOV.UK Prototype Kit JavaScript - files.copy('**/*.js', { + await files.copy('**/*.js', { srcPath: join(paths.src, 'govuk-prototype-kit'), destPath: join(paths.package, 'govuk-prototype-kit') }) -) +} diff --git a/tasks/build/public.mjs b/tasks/build/public.mjs deleted file mode 100644 index 07721754497..00000000000 --- a/tasks/build/public.mjs +++ /dev/null @@ -1,27 +0,0 @@ -import { join } from 'path' - -import gulp from 'gulp' - -import { paths } from '../../config/index.js' -import * as files from '../files.mjs' - -/** - * Build public task - * Prepare public folder for review app - * - * @returns {() => import('gulp').TaskFunction} Task function - */ -export default () => gulp.series( - files.clean('**/*', { - destPath: join(paths.app, 'public') - }), - - // Copy GOV.UK Frontend static assets - files.copy('**/*', { - srcPath: join(paths.src, 'govuk/assets'), - destPath: join(paths.app, 'public/assets') - }), - - 'scripts', - 'styles' -) diff --git a/tasks/configs.mjs b/tasks/configs.mjs index ee9ed74a5ac..41cc466b87b 100644 --- a/tasks/configs.mjs +++ b/tasks/configs.mjs @@ -1,28 +1,22 @@ import { writeFile } from 'fs/promises' import { EOL } from 'os' -import { basename, parse, join } from 'path' +import { parse, join } from 'path' /** * Write config to JSON * * @param {AssetEntry[0]} modulePath - File path to config * @param {AssetEntry[1]} options - Asset options - * @returns {() => Promise} Prepared compile task + * @returns {Promise} */ -export function compile (modulePath, { srcPath, destPath, filePath }) { +export async function compile (modulePath, { srcPath, destPath, filePath }) { const configPath = join(destPath, filePath ? filePath(parse(modulePath)) : modulePath) - const task = async () => { - const { default: configFn } = await import(join(srcPath, modulePath)) + const { default: configFn } = await import(join(srcPath, modulePath)) - // Write JSON config file - return writeFile(configPath, JSON.stringify(await configFn(), null, 2) + EOL) - } - - task.displayName = `compile:config ${basename(configPath)}` - - return task + // Write JSON config file + return writeFile(configPath, JSON.stringify(await configFn(), null, 2) + EOL) } /** diff --git a/tasks/files.mjs b/tasks/files.mjs index 7fd5e8f49fa..b8d6e9d233b 100644 --- a/tasks/files.mjs +++ b/tasks/files.mjs @@ -1,6 +1,6 @@ import { writeFile } from 'fs/promises' import { EOL } from 'os' -import { basename, join } from 'path' +import { join } from 'path' import cpy from 'cpy' import { deleteAsync } from 'del' @@ -13,14 +13,9 @@ import { pkg } from '../config/index.js' * * @param {string} pattern - Pattern to remove * @param {AssetEntry[1]} options - Asset options - * @returns {() => Promise} Prepared compile task */ -export function clean (pattern, { destPath, ignore }) { - const task = () => deleteAsync(slash(join(destPath, pattern)), { ignore }) - - task.displayName = `clean:${basename(destPath)}` - - return task +export async function clean (pattern, { destPath, ignore }) { + await deleteAsync(slash(join(destPath, pattern)), { ignore }) } /** @@ -28,14 +23,9 @@ export function clean (pattern, { destPath, ignore }) { * * @param {AssetEntry[0]} assetPath - File path to asset * @param {AssetEntry[1]} options - Asset options - * @returns {() => Promise} Prepared compile task */ -export function version (assetPath, { destPath }) { - const task = () => writeFile(join(destPath, assetPath), pkg.version + EOL) - - task.displayName = `file:version ${basename(assetPath)}` - - return task +export async function version (assetPath, { destPath }) { + await writeFile(join(destPath, assetPath), pkg.version + EOL) } /** @@ -44,20 +34,16 @@ export function version (assetPath, { destPath }) { * * @param {string} pattern - Minimatch pattern * @param {AssetEntry[1]} options - Asset options - * @returns {() => Promise} Prepared copy task */ -export function copy (pattern, { srcPath, destPath, ignore = [] }) { +export async function copy (pattern, { srcPath, destPath, ignore = [] }) { const srcPatterns = [slash(join(srcPath, pattern))] .concat(ignore.map((pattern) => `!${pattern}`)) - const task = async () => cpy(srcPatterns, destPath, { cwd: srcPath }) - task.displayName = `copy:${basename(destPath)}` - return task + await cpy(srcPatterns, destPath, { cwd: srcPath }) } // Include Gulp legacy file tasks export { generateFixtures, generateMacroOptions } from './gulp/copy-to-destination.mjs' -export { watch } from './gulp/watch.mjs' /** * @typedef {import('./assets.mjs').AssetEntry} AssetEntry diff --git a/tasks/gulp/copy-to-destination.mjs b/tasks/gulp/copy-to-destination.mjs index 2d33491b124..3833fff491b 100644 --- a/tasks/gulp/copy-to-destination.mjs +++ b/tasks/gulp/copy-to-destination.mjs @@ -13,10 +13,10 @@ import { paths } from '../../config/index.js' * Generate fixtures.json from ${componentName}.yaml * * @param {AssetEntry[1]} options - Asset options - * @returns {() => import('stream').Stream} Output file stream + * @returns {import('stream').Stream} Output file stream */ export function generateFixtures ({ srcPath, destPath }) { - const task = () => gulp.src(`${slash(srcPath)}/govuk/components/**/*.yaml`, { + return gulp.src(`${slash(srcPath)}/govuk/components/**/*.yaml`, { base: slash(srcPath) }) .pipe(map(async (file, done) => { @@ -31,20 +31,16 @@ export function generateFixtures ({ srcPath, destPath }) { extname: '.json' })) .pipe(gulp.dest(slash(destPath))) - - task.displayName = 'copy:fixtures' - - return task } /** * Generate macro-options.json from ${componentName}.yaml * * @param {AssetEntry[1]} options - Asset options - * @returns {() => import('stream').Stream} Output file stream + * @returns {import('stream').Stream} Output file stream */ export function generateMacroOptions ({ srcPath, destPath }) { - const task = () => gulp.src(`${slash(srcPath)}/govuk/components/**/*.yaml`, { + return gulp.src(`${slash(srcPath)}/govuk/components/**/*.yaml`, { base: slash(srcPath) }) .pipe(map(async (file, done) => { @@ -59,10 +55,6 @@ export function generateMacroOptions ({ srcPath, destPath }) { extname: '.json' })) .pipe(gulp.dest(slash(destPath))) - - task.displayName = 'copy:macro-options' - - return task } /** diff --git a/tasks/npm.mjs b/tasks/npm.mjs index bcfeb64d040..11404e07641 100644 --- a/tasks/npm.mjs +++ b/tasks/npm.mjs @@ -4,13 +4,12 @@ import { isDev } from './helpers/task-arguments.mjs' /** * Spawns Node.js child process for npm script - * rather than using Gulp * * @param {string} name - npm script name * @param {string[]} [args] - npm script arguments * @returns {Promise} Exit code */ -export async function script (name, args = []) { +export async function run (name, args = []) { const command = process.platform === 'win32' ? 'npm.cmd' : 'npm' return new Promise((resolve, reject) => { @@ -63,20 +62,3 @@ export async function script (name, args = []) { }) }) } - -/** - * Creates a Gulp task for script() - * - * @param {string} name - npm script name - * @param {string[]} [args] - npm script arguments - * @returns {() => Promise} Exit code - */ -export function run (name, args = []) { - const task = () => script(name, args) - - // Add task alias - // https://gulpjs.com/docs/en/api/task#task-metadata - task.displayName = `npm run ${name} ${args.join(' ')}`.trim() - - return task -} diff --git a/tasks/scripts.mjs b/tasks/scripts.mjs index 76056bd4e4b..a0617b7ac1c 100644 --- a/tasks/scripts.mjs +++ b/tasks/scripts.mjs @@ -17,25 +17,19 @@ import * as assets from './assets.mjs' * * @param {string} pattern - Minimatch pattern * @param {AssetEntry[1]} [options] - Asset options - * @returns {() => Promise} Prepared compile task + * @returns {Promise} */ -export function compile (pattern, options) { - const task = async () => { - const modulePaths = await getListing(options.srcPath, pattern) - - try { - const compileTasks = modulePaths - .map((modulePath) => compileJavaScript([modulePath, options])) - - await Promise.all(compileTasks) - } catch (cause) { - throw new PluginError('compile:js', cause) - } - } +export async function compile (pattern, options) { + const modulePaths = await getListing(options.srcPath, pattern) - task.displayName = 'compile:js' + try { + const compileTasks = modulePaths + .map((modulePath) => compileJavaScript([modulePath, options])) - return task + await Promise.all(compileTasks) + } catch (cause) { + throw new PluginError('compile:js', cause) + } } /** diff --git a/tasks/styles.mjs b/tasks/styles.mjs index 1c608cae610..60d524ecbac 100644 --- a/tasks/styles.mjs +++ b/tasks/styles.mjs @@ -18,25 +18,18 @@ import * as assets from './assets.mjs' * * @param {string} pattern - Minimatch pattern * @param {AssetEntry[1]} [options] - Asset options - * @returns {() => Promise} Prepared compile task */ -export function compile (pattern, options) { - const task = async () => { - const modulePaths = await getListing(options.srcPath, pattern) +export async function compile (pattern, options) { + const modulePaths = await getListing(options.srcPath, pattern) - try { - const compileTasks = modulePaths - .map((modulePath) => compileStylesheet([modulePath, options])) + try { + const compileTasks = modulePaths + .map((modulePath) => compileStylesheet([modulePath, options])) - await Promise.all(compileTasks) - } catch (cause) { - throw new PluginError('compile:scss', cause) - } + await Promise.all(compileTasks) + } catch (cause) { + throw new PluginError('compile:scss', cause) } - - task.displayName = 'compile:scss' - - return task } /**