Skip to content

Commit

Permalink
MAP-1729 - Update the service from the template project (#207)
Browse files Browse the repository at this point in the history
* Stringify audit details (#343)

Co-authored-by: Paul Solecki <[email protected]>

* Update all non major NPM dependencies (#362)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update Helm release generic-service to 3.3 (#363)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Paul Solecki <[email protected]>

* CDPS-721: Removing prometheus metrics scraping (#365)

* CDPS-721: Adding changelog for PR 365 (#366)

* Update all non major NPM dependencies (#367)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update Node.js to v20.14.0 (#368)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency audit-ci to v7 (#369)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update all non major NPM dependencies (#370)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update Helm release generic-prometheus-alerts to 1.8 (#372)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency uuid to v10 (#371)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Paul Solecki <[email protected]>

* SDIT-1802: ✨ Add request session to tests (#374)

* Added ESBuild for building app and bundling/minfiying assets (#375)

* Added ESBuild for bundling and building app

* Update all non major NPM dependencies (#376)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Add dotenv to ESBuild server watch (#378)

* Update all non major NPM dependencies (#379)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency @types/uuid to v10 (#380)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* jQueryify card.js

---------

Co-authored-by: Lee Jacobson <[email protected]>
Co-authored-by: Paul Solecki <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jon Brighton <[email protected]>
Co-authored-by: petergphillips <[email protected]>
Co-authored-by: Thomas-Geraghty <[email protected]>
  • Loading branch information
7 people authored Nov 8, 2024
1 parent 1b08f1c commit 5ec5c07
Show file tree
Hide file tree
Showing 30 changed files with 4,133 additions and 2,579 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
"rules": {
"@typescript-eslint/ban-ts-comment": "off"
}
},
{
"files": ["esbuild/**/*"],
"rules": {
"no-console": "off"
}
}
],

Expand Down Expand Up @@ -94,7 +100,7 @@
"comma-dangle": ["error", "always-multiline"],
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": ["**/*.test.js", "**/*.test.ts", "**/testutils/**", "cypress.config.ts"] }
{ "devDependencies": ["**/*.test.js", "**/*.test.ts", "**/testutils/**", "cypress.config.ts", "esbuild/**/*"] }
],
"no-only-tests/no-only-tests": "error",
"prettier/prettier": [
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

**May 22nd 2024** – Remove prometheus metrics middleware and metrics app. We had discussed that very few teams actually go on to set up a dashboard to surface the information and tend to use application insights instead for the information. In addition it had also caused a memory leak and production issues (manifesting in increased 502 error rates) in at least two applications that had inherited from the template so it seems wise to remove this tooling by default.

PR: [#365](https://github.com/ministryofjustice/hmpps-template-typescript/pull/365)

---

**May 10th 2024** – Derive user details from the `authorization_code` "user" token instead of making an API call to `hmpps-manage-users-api`, thereby removing an unnecessary dependency.

PR: [#352](https://github.com/ministryofjustice/hmpps-template-typescript/pull/352)
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ARG GIT_BRANCH

COPY package*.json ./
RUN CYPRESS_INSTALL_BINARY=0 npm ci --no-audit
ENV NODE_ENV='production'

COPY . .
RUN npm run build
Expand All @@ -53,16 +54,13 @@ COPY --from=build --chown=appuser:appgroup \
/app/package-lock.json \
./

COPY --from=build --chown=appuser:appgroup \
/app/assets ./assets

COPY --from=build --chown=appuser:appgroup \
/app/dist ./dist

COPY --from=build --chown=appuser:appgroup \
/app/node_modules ./node_modules

EXPOSE 3000 3001
EXPOSE 3000
ENV NODE_ENV='production'
USER 2000

Expand Down
26 changes: 15 additions & 11 deletions assets/js/card.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
$(() => {
// Loops through dom and finds all elements with card--clickable class
document.querySelectorAll('.card--clickable').forEach(card => {
// Check if card has a link within it
if (card.querySelector('a') !== null) {
// Clicks the link within the heading to navigate to desired page
card.addEventListener('click', () => {
card.querySelector('a').click()
})
}
module.exports = () => {
$(() => {
// Loops through dom and finds all elements with card--clickable class
$('.card--clickable').each(function () {
const link = this.querySelector('a')
// Check if card has a link within it
if (link !== null) {
// Clicks the link within the heading to navigate to desired page
$(this).on('click', () => {
// Use HTMLAnchorElement.click() rather than jQuery's trigger('click') to prevent recursion
link.click()
})
}
})
})
})
}
3 changes: 0 additions & 3 deletions assets/js/govukFrontendInit.js

This file was deleted.

13 changes: 13 additions & 0 deletions assets/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as govukFrontend from 'govuk-frontend'
import * as mojFrontend from '@ministryofjustice/frontend'

import card from './card'
import multiSelect from './multiSelect'
import localNameInputSubmit from './localNameInputSubmit'

govukFrontend.initAll()
mojFrontend.initAll()

card()
multiSelect(mojFrontend)
localNameInputSubmit()
10 changes: 10 additions & 0 deletions assets/js/localNameInputSubmit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = () => {
$(() => {
$('.local-name-text-input').on('keydown', function (e) {
if (e.key === 'Enter') {
e.preventDefault()
$(this).closest('form').submit()
}
})
})
}
13 changes: 0 additions & 13 deletions assets/js/mojFrontendInit.js

This file was deleted.

39 changes: 27 additions & 12 deletions assets/js/multiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,32 @@ function updateCheckedCount() {
}
}

$(() => {
const multiSelect = new MOJFrontend.MultiSelect({
container: '.moj-multi-select',
checkboxes: '.govuk-checkboxes__input:not(#checkboxes-all)',
})
module.exports = mojFrontend => {
// Disable autocomplete for the select all checkbox
mojFrontend.MultiSelect.prototype.getToggleHtml = function () {
return (
'' +
'<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">' +
' <input type="checkbox" class="govuk-checkboxes__input" id="checkboxes-all" autocomplete="off">' +
' <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="checkboxes-all">' +
' <span class="govuk-visually-hidden">Select all</span>' +
' </label>' +
'</div>'
)
}

$('.sticky-select-action-bar__clear-link').on('click', () => {
multiSelect.uncheckAll()
multiSelect.toggleButton[0].checked = false
updateCheckedCount()
})
$(() => {
const multiSelect = new mojFrontend.MultiSelect({
container: '.moj-multi-select',
checkboxes: '.govuk-checkboxes__input:not(#checkboxes-all)',
})

$('.govuk-checkboxes__input').on('click', updateCheckedCount)
})
$('.sticky-select-action-bar__clear-link').on('click', () => {
multiSelect.uncheckAll()
multiSelect.toggleButton[0].checked = false
updateCheckedCount()
})

$('.govuk-checkboxes__input').on('click', updateCheckedCount)
})
}
12 changes: 0 additions & 12 deletions assets/js/textInputWithCharacterCount.js

This file was deleted.

6 changes: 3 additions & 3 deletions assets/scss/application.scss
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ $path: "/assets/images/";
$moj-page-width: 1170px;
$govuk-page-width: $moj-page-width;

@import 'govuk/all';
@import 'moj/all';
@import "govuk-frontend/dist/govuk/all";
@import "@ministryofjustice/frontend/moj/all";

@import './components/card';
@import './components/header-bar';
Expand All @@ -14,4 +14,4 @@ $govuk-page-width: $moj-page-width;
@import './components/summary-card';
@import './components/feedback-banner';
@import './components/inactive-location-banner';
@import 'assets/scss/local';
@import './local';
26 changes: 26 additions & 0 deletions esbuild/app.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { copy } = require('esbuild-plugin-copy')
const { typecheckPlugin } = require('@jgoz/esbuild-plugin-typecheck')
const esbuild = require('esbuild')
const glob = require('glob')

module.exports = buildConfig => {
console.log('\u{1b}[1m\u{2728} Building app....\u{1b}[0m')

esbuild
.build({
entryPoints: glob.sync(buildConfig.app.entryPoints),
outdir: buildConfig.app.outDir,
bundle: false,
sourcemap: true,
platform: 'node',
format: 'cjs',
plugins: [
typecheckPlugin(),
copy({
resolveFrom: 'cwd',
assets: buildConfig.app.copy,
}),
],
})
.catch(() => process.exit(1))
}
54 changes: 54 additions & 0 deletions esbuild/assets.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { copy } = require('esbuild-plugin-copy')
const { sassPlugin } = require('esbuild-sass-plugin')
const { clean } = require('esbuild-plugin-clean')
const manifestPlugin = require('esbuild-plugin-manifest')
const esbuild = require('esbuild')
const path = require('path')
const { glob } = require('glob')

const buildAdditionalAssets = buildConfig =>
esbuild.build({
outdir: buildConfig.assets.outDir,
plugins: [
copy({
resolveFrom: 'cwd',
assets: buildConfig.assets.copy,
}),
],
})

const buildAssets = buildConfig => {
return esbuild.build({
entryPoints: buildConfig.assets.entryPoints,
outdir: buildConfig.assets.outDir,
entryNames: '[ext]/app',
minify: buildConfig.isProduction,
sourcemap: !buildConfig.isProduction,
platform: 'browser',
target: 'es2018',
external: ['/assets/*'],
bundle: true,
plugins: [
clean({
patterns: glob.sync(buildConfig.assets.clear),
}),
manifestPlugin({
generate: entries =>
Object.fromEntries(Object.entries(entries).map(paths => paths.map(p => p.replace(/^dist\//, '/')))),
}),
sassPlugin({
quietDeps: true,
loadPaths: [process.cwd(), path.join(process.cwd(), 'node_modules')],
}),
],
})
}

module.exports = buildConfig => {
console.log('\u{1b}[1m\u{2728} Building assets....\u{1b}[0m')

Promise.all([buildAssets(buildConfig), buildAdditionalAssets(buildConfig)]).catch(e => {
console.log(e)
process.exit(1)
})
}
68 changes: 68 additions & 0 deletions esbuild/esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const path = require('path')
const { glob } = require('glob')
const chokidar = require('chokidar')
const { spawn } = require('child_process')
const buildAssets = require('./assets.config')
const buildApp = require('./app.config')

const cwd = process.cwd()
const buildConfig = {
isProduction: process.env.NODE_ENV === 'production',
app: {
outDir: path.join(cwd, 'dist'),
entryPoints: glob
.sync([path.join(cwd, '*.ts'), path.join(cwd, 'server/**/*.ts')])
.filter(file => !file.endsWith('.test.ts')),
copy: [
{
from: path.join(cwd, 'server/views/**/*'),
to: path.join(cwd, 'dist/server/views'),
},
],
},

assets: {
outDir: path.join(cwd, 'dist/assets'),
entryPoints: glob.sync([path.join(cwd, 'assets/js/index.js'), path.join(cwd, 'assets/scss/application.scss')]),
copy: [
{
from: path.join(cwd, 'assets/images/**/*'),
to: path.join(cwd, 'dist/assets/images'),
},
],
clear: glob.sync([path.join(cwd, 'dist/assets/{css,js}')]),
},
}

function main() {
const chokidarOptions = {
persistent: true,
ignoreInitial: true,
}

const args = process.argv
if (args.includes('--build')) {
buildApp(buildConfig)
buildAssets(buildConfig)
}

if (args.includes('--dev-server')) {
let serverProcess = null
chokidar.watch(['dist']).on('all', () => {
if (serverProcess) serverProcess.kill()
serverProcess = spawn('node', ['-r', 'dotenv/config', 'dist/server.js'], { stdio: 'inherit' })
})
}

if (args.includes('--watch')) {
console.log('\u{1b}[1m\u{1F52D} Watching for changes...\u{1b}[0m')
// Assets
chokidar.watch(['assets/**/*'], chokidarOptions).on('all', () => buildAssets(buildConfig))

// App
chokidar
.watch(['server/**/*'], { ...chokidarOptions, ignored: ['**/*.test.ts'] })
.on('all', () => buildApp(buildConfig))
}
}
main()
6 changes: 0 additions & 6 deletions helm_deploy/hmpps-locations-inside-prison/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ generic-service:
httpGet:
path: /ping

custommetrics:
enabled: true
scrapeInterval: 15s
metricsPath: /metrics
metricsPort: 3001

# Environment variables to load into the deployment
env:
NODE_ENV: "production"
Expand Down
Loading

0 comments on commit 5ec5c07

Please sign in to comment.