Skip to content

Commit

Permalink
Move build tasks into tasks/build
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Mar 13, 2023
1 parent 7191c8f commit 1822d0f
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 139 deletions.
134 changes: 6 additions & 128 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export default {
projects: [
{
...config,
displayName: 'Gulp tasks',
displayName: 'Build tasks',
testMatch: [
'**/gulp/**/*.test.{js,mjs}'
'**/tasks/build/*.test.{js,mjs}'
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
53 changes: 53 additions & 0 deletions tasks/build/dist.mjs
Original file line number Diff line number Diff line change
@@ -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
})
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tasks/build/index.mjs
Original file line number Diff line number Diff line change
@@ -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'
78 changes: 78 additions & 0 deletions tasks/build/package.mjs
Original file line number Diff line number Diff line change
@@ -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`)
}
})
)
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 28 additions & 0 deletions tasks/build/public.mjs
Original file line number Diff line number Diff line change
@@ -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'
)

0 comments on commit 1822d0f

Please sign in to comment.