Skip to content

Commit

Permalink
Update review app to use pre-built govuk-frontend modules
Browse files Browse the repository at this point in the history
Rollup build is not necessary when `govuk-frontend.min.js` is already built
  • Loading branch information
colinrotherham committed Jul 5, 2023
1 parent f9079c6 commit 754315c
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 89 deletions.
2 changes: 0 additions & 2 deletions docs/contributing/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ This task will:

This task will:

- check JavaScript code quality via ESLint (`npm run lint:js`) (using JavaScript Standard Style)
- compile JavaScript to Immediately Invoked Function Expression (IIFE) into `./packages/govuk-frontend-review/dist/javascripts`
- compile JavaScript documentation into `./packages/govuk-frontend-review/dist/docs/jsdoc`

## Review app only
Expand Down
12 changes: 10 additions & 2 deletions packages/govuk-frontend-review/browsersync.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ module.exports = {

// Files to watch for auto reload
files: [
join(paths.app, 'dist/javascripts/**/*.mjs'),
join(paths.app, 'dist/stylesheets/**/*.css'),
join(paths.app, 'src/views/**/*.njk'),

packageTypeToPath('govuk-frontend', {
modulePath: 'govuk-frontend.min.js',
moduleRoot: paths.app
}),

packageTypeToPath('govuk-frontend', {
modulePath: '**/*.njk',
moduleRoot: paths.app
Expand All @@ -36,7 +41,10 @@ module.exports = {
serveStatic: [
{
route: '/javascripts',
dir: join(paths.app, 'dist/javascripts')
dir: packageTypeToPath('govuk-frontend', {
modulePath: '/',
moduleRoot: paths.app
})
},
{
route: '/stylesheets',
Expand Down
2 changes: 1 addition & 1 deletion packages/govuk-frontend-review/nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"../../shared/lib",
"../../shared/stats"
],
"ignore": ["./src/javascripts/**", "**/*.test.*"],
"ignore": ["**/*.test.*"],
"events": {
"restart": "browser-sync reload --config browsersync.config.js"
},
Expand Down
45 changes: 0 additions & 45 deletions packages/govuk-frontend-review/rollup.config.mjs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const router = express.Router()
*/

router.use('/assets', express.static(packageTypeToPath('govuk-frontend', { modulePath: 'assets', moduleRoot: paths.app })))
router.use('/javascripts', express.static(join(paths.app, 'dist/javascripts')))
router.use('/javascripts', express.static(packageTypeToPath('govuk-frontend', { modulePath: '/', moduleRoot: paths.app })))
router.use('/stylesheets', express.static(join(paths.app, 'dist/stylesheets')))

export default router
1 change: 0 additions & 1 deletion packages/govuk-frontend-review/src/javascripts/all.mjs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
{% endblock %}

{% block bodyEnd %}
<script type="module" src="/javascripts/all.bundle.min.mjs"></script>
<script type="module" src="/javascripts/govuk-frontend.min.js"></script>
<script type="module">
import { initAll } from '/javascripts/all.bundle.min.mjs'
import { initAll } from '/javascripts/govuk-frontend.min.js'
const $scope = document.getElementById('scoped')
initAll({ scope: $scope })
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@

{% block bodyEnd %}
<!-- block:bodyEnd -->
<script type="module" src="/javascripts/all.bundle.min.mjs"></script>
<script type="module" src="/javascripts/govuk-frontend.min.js"></script>
<script type="module">
import { initAll } from '/javascripts/all.bundle.min.mjs'
import { initAll } from '/javascripts/govuk-frontend.min.js'
initAll()
</script>
<!-- endblock:bodyEnd -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

{% block bodyEnd %}
<!-- block:bodyEnd -->
<script type="module" src="/javascripts/all.bundle.min.mjs"></script>
<script type="module" src="/javascripts/govuk-frontend.min.js"></script>
<script type="module">
import { initAll } from '/javascripts/all.bundle.min.mjs'
import { initAll } from '/javascripts/govuk-frontend.min.js'
initAll()
</script>
<!-- endblock:bodyEnd -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,9 @@
{% endblock %}

{% block bodyEnd %}
<script type="module" src="/javascripts/all.bundle.min.mjs"></script>
<script type="module" src="/javascripts/govuk-frontend.min.js"></script>
<script type="module">
import { initAll } from '/javascripts/all.bundle.min.mjs'
import { initAll } from '/javascripts/govuk-frontend.min.js'
initAll({
accordion: {
i18n: {
Expand Down
4 changes: 2 additions & 2 deletions packages/govuk-frontend-review/src/views/layouts/_generic.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
{% set mainClasses = 'govuk-main-wrapper--auto-spacing' %}

{% block bodyEnd %}
<script type="module" src="/javascripts/all.bundle.min.mjs"></script>
<script type="module" src="/javascripts/govuk-frontend.min.js"></script>
<script type="module">
import { initAll } from '/javascripts/all.bundle.min.mjs'
import { initAll } from '/javascripts/govuk-frontend.min.js'
initAll()
</script>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block head %}
{{ super() }}
<script type="importmap">
{ "imports": { "govuk-frontend": "/javascripts/all.bundle.min.mjs" } }
{ "imports": { "govuk-frontend": "/javascripts/govuk-frontend.min.js" } }
</script>
{% endblock %}

Expand All @@ -21,5 +21,5 @@
{% endblock %}

{% block bodyEnd %}
<script type="module" src="/javascripts/all.bundle.min.mjs"></script>
<script type="module" src="/javascripts/govuk-frontend.min.js"></script>
{% endblock %}
17 changes: 2 additions & 15 deletions packages/govuk-frontend-review/tasks/scripts.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import { join } from 'path'

import { npm, scripts, task } from 'govuk-frontend-tasks'
import { npm } from 'govuk-frontend-tasks'
import gulp from 'gulp'

/**
* JavaScripts task (for watch)
* Compilation, documentation
* Documentation
*
* @type {import('govuk-frontend-tasks').TaskFunction}
*/
export const compile = (options) => gulp.series(
task.name('compile:js', () =>
scripts.compile('all.mjs', {
...options,

srcPath: join(options.srcPath, 'javascripts'),
destPath: join(options.destPath, 'javascripts'),
configPath: join(options.basePath, 'rollup.config.mjs')
})
),

// Build JSDoc for /docs/javascript
npm.script('build:jsdoc', [], options)
)
10 changes: 0 additions & 10 deletions packages/govuk-frontend-review/tasks/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,12 @@ export const watch = (options) => gulp.parallel(
], styles(options))
),

/**
* JavaScripts lint watcher
*/
task.name('lint:js watch', () =>
gulp.watch([
`${slash(paths.app)}/src/javascripts/**/*.mjs`
], npm.script('lint:js:cli', [slash(join(options.workspace, '**/*.{cjs,js,md,mjs}'))]))
),

/**
* JavaScripts build watcher
*/
task.name('compile:js watch', () =>
gulp.watch([
`${slash(paths.root)}/typedoc.config.js`,
`${slash(paths.app)}/src/javascripts/**/*.mjs`,
`${slash(paths.package)}/dist/govuk/**/*.mjs`
], scripts(options))
)
Expand Down

0 comments on commit 754315c

Please sign in to comment.