Skip to content

Commit

Permalink
Split review app tasks into app/tasks (without Gulp)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Mar 22, 2023
1 parent a39a8ec commit 09453b3
Show file tree
Hide file tree
Showing 28 changed files with 238 additions and 228 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: npm run heroku
web: npm start --workspace app
9 changes: 9 additions & 0 deletions app/gulpfile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import gulp from 'gulp'

import * as build from './tasks/build/index.mjs'

/**
* Build target tasks
*/
gulp.task('build', build.dist)
gulp.task('dev', build.dev)
8 changes: 7 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
},
"license": "MIT",
"scripts": {
"build": "gulp build",
"dev": "gulp dev",
"serve": "nodemon",
"prestart": "npm run build",
"start": "node src/start.mjs"
},
"dependencies": {
Expand All @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions app/tasks/assets.mjs
Original file line number Diff line number Diff line change
@@ -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, 'dist/assets')
})
}
14 changes: 14 additions & 0 deletions app/tasks/build/dev.mjs
Original file line number Diff line number Diff line change
@@ -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.dist()
await tasks.watch()
await npm.run('serve')
}
15 changes: 15 additions & 0 deletions app/tasks/build/dist.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as tasks from '../index.mjs'

/**
* Build review app task
* Prepare dist folder for review app
*/
export default async function build () {
await tasks.clean()

await Promise.all([
tasks.assets(),
tasks.scripts(),
tasks.styles()
])
}
5 changes: 5 additions & 0 deletions app/tasks/build/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Build target tasks
*/
export { default as dev } from './dev.mjs'
export { default as dist } from './dist.mjs'
13 changes: 13 additions & 0 deletions app/tasks/clean.mjs
Original file line number Diff line number Diff line change
@@ -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, 'dist')
})
}
8 changes: 8 additions & 0 deletions app/tasks/index.mjs
Original file line number Diff line number Diff line change
@@ -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'
25 changes: 25 additions & 0 deletions app/tasks/scripts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { join } 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, 'dist/javascripts'),

filePath (file) {
return join(file.dir, `${file.name}.min.js`)
}
})

// Build JSDoc for /docs/javascript
await npm.run('build:jsdoc')
}

compile.displayName = 'compile:scripts'
25 changes: 25 additions & 0 deletions app/tasks/styles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { join } 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/stylesheets'),
destPath: join(paths.app, 'dist/stylesheets'),

filePath (file) {
return join(file.dir, `${file.name}.min.css`)
}
})

// Build SassDoc for /docs/sass
await npm.run('build:sassdoc')
}

compile.displayName = 'compile:styles'
19 changes: 10 additions & 9 deletions tasks/gulp/watch.mjs → app/tasks/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
npm.run('lint:scss'),
'styles'
npm.task('lint:scss'),
styles.compile
)),

gulp.watch([
'jsdoc.config.js',
`${slash(paths.app)}/jsdoc.config.js`,
`${slash(paths.src)}/govuk/**/*.mjs`
], gulp.parallel(
npm.run('lint:js'),
'scripts'
npm.task('lint:js'),
scripts.compile
))
])
}

watch.displayName = 'watch'
4 changes: 2 additions & 2 deletions app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
7 changes: 1 addition & 6 deletions docs/contributing/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/dist` folder
- copy fonts and images
Expand All @@ -26,11 +26,6 @@ npm scripts are defined in `package.json`. These trigger a number of Gulp tasks.

- start up Express, restarting when `.mjs`, `.json` or `.yaml` files change

**`npm run heroku` runs on Heroku build/PR and it will:**

- run `npm run build:app`
- start up Express

**`npm run build:app` will do the following:**

- clean the `./app/dist` folder
Expand Down
54 changes: 3 additions & 51 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
@@ -1,61 +1,13 @@
import { join } 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, 'dist/javascripts'),

filePath (file) {
return join(file.dir, `${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/stylesheets'),
destPath: join(paths.app, 'dist/stylesheets'),

filePath (file) {
return join(file.dir, `${file.name}.min.css`)
}
}),

npm.run('build:sassdoc')
))
import { browser } from './tasks/index.mjs'

/**
* Build target tasks
*/
gulp.task('build:app', build.app())
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:app',
files.watch,
npm.run('serve', ['--workspace', 'app'])
))
gulp.task('build:package', build.package)
gulp.task('build:dist', build.dist)

/**
* Screenshots task
Expand Down
3 changes: 2 additions & 1 deletion jest-dev-server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const { ports } = require('./config/index.js')
* @type {import('jest-dev-server').Config}
*/
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
Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:app && 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:app": "gulp build:app",
"build:app": "npm run build --workspace app",
"build:package": "gulp build:package",
"build:dist": "gulp build:dist",
"build:types": "tsc --build",
Expand Down
27 changes: 0 additions & 27 deletions tasks/build/app.mjs

This file was deleted.

Loading

0 comments on commit 09453b3

Please sign in to comment.