@ministryofjustice/hmpps-connect-dps-components 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,7 +39,20 @@ npm install @ministryofjustice/hmpps-connect-dps-components
39
39
 
40
40
  Currently, the package provides the header and the footer component.
41
41
 
42
- To incorporate use the middleware for appropriate routes within your Express application:
42
+ #### Automatic installation
43
+
44
+ You can use this script to attempt to automatically install DPS components. It is designed to work with the latest
45
+ [hmpps-template-typescript](https://github.com/ministryofjustice/hmpps-template-typescript) file layout.
46
+
47
+ ```shell
48
+ npx @ministryofjustice/hmpps-connect-dps-components
49
+ ```
50
+
51
+ Do take care to check the diff carefully, in case your repository has diverged from the template.
52
+
53
+ #### Manual installation
54
+
55
+ To incorporate, use the middleware for appropriate routes within your Express application:
43
56
 
44
57
  ```javascript
45
58
  import { getFrontendComponents } from '@ministryofjustice/hmpps-connect-dps-components'
@@ -51,8 +64,7 @@ To incorporate use the middleware for appropriate routes within your Express app
51
64
  componentApiConfig: config.apis.componentApi,
52
65
  dpsUrl: config.serviceUrls.digitalPrison,
53
66
  requestOptions: { includeSharedData: true },
54
- })
55
- )
67
+ }))
56
68
  ```
57
69
 
58
70
  **However, please 🙏 consider carefully whether you need the components for EVERY request.**
@@ -94,7 +106,7 @@ There are a [number of options](./src/index.ts) available depending on your requ
94
106
  Add the `hmpps-connect-dps-components` path to the nunjucksSetup.ts file to enable css to be loaded:
95
107
 
96
108
  ```javascript
97
- const njkEnv = nunjucks.configure(
109
+ const njkEnv = nunjucks.configure(
98
110
  [
99
111
  path.join(__dirname, '../../server/views'),
100
112
  'node_modules/govuk-frontend/dist/',
@@ -112,13 +124,13 @@ Add the `hmpps-connect-dps-components` path to the nunjucksSetup.ts file to enab
112
124
 
113
125
  Include the package scss within the all.scss file
114
126
  ```scss
115
- @import 'node_modules/@ministryofjustice/hmpps-connect-dps-components/dist/assets/footer';
116
- @import 'node_modules/@ministryofjustice/hmpps-connect-dps-components/dist/assets/header-bar';
127
+ @import '@ministryofjustice/hmpps-connect-dps-components/dist/assets/footer';
128
+ @import '@ministryofjustice/hmpps-connect-dps-components/dist/assets/header-bar';
117
129
  ```
118
130
 
119
131
  Include reference to the components in your layout.njk file:
120
132
 
121
- ```typescript
133
+ ```nunjucks
122
134
  {% for js in feComponents.jsIncludes %}
123
135
  <script src="{{ js }}" nonce="{{ cspNonce }}"></script>
124
136
  {% endfor %}
@@ -127,12 +139,12 @@ Include reference to the components in your layout.njk file:
127
139
  <link href="{{ css }}" nonce="{{ cspNonce }}" rel="stylesheet" />
128
140
  {% endfor %}
129
141
  ```
130
- ```typescript
142
+ ```nunjucks
131
143
  {% block header %}
132
144
  {{ feComponents.header | safe }}
133
145
  {% endblock %}
134
146
  ```
135
- ```typescript
147
+ ```nunjucks
136
148
  {% block footer %}
137
149
  {{ feComponents.footer | safe }}
138
150
  {% endblock %}
@@ -156,7 +168,7 @@ of routes. e.g. in `setUpAuthentication.ts` on the `/autherror` path:
156
168
  res.status(401)
157
169
  return res.render('autherror')
158
170
  },
159
- )
171
+ )
160
172
  ```
161
173
 
162
174
  This will provide a stripped down header for if there is no user object on `res.locals`.
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-connect-dps-components",
3
- "version": "5.0.1",
4
- "description": "A package to allow the inclusion of connect dps micro frontend components within dps applications",
3
+ "version": "5.1.0",
4
+ "description": "A package to allow the inclusion of connect DPS micro frontend components within DPS applications",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.esm.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "files": [
9
9
  "dist/**/*"
10
10
  ],
11
+ "bin": "./scripts/install.ts",
11
12
  "scripts": {
12
13
  "prepare": "hmpps-precommit-hooks-prepare",
13
14
  "build": "rollup -c rollup.config.ts --bundleConfigAsCjs && npm run copy:assets",
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ /* eslint-disable no-console */
3
+ import { execSync } from 'node:child_process'
4
+ import { resolve } from 'node:path'
5
+
6
+ console.info('→ Installing @ministryofjustice/hmpps-connect-dps-components')
7
+ execSync('npm install --save-prod @ministryofjustice/hmpps-connect-dps-components')
8
+
9
+ console.info('→ Applying patch')
10
+ const patchFile = resolve(__dirname, 'patch.diff')
11
+ execSync(`git apply ${patchFile}`)
12
+
13
+ console.info('→ Connect DPS components have been installed')
14
+ console.info(
15
+ 'However, please consider whether you need the components for EVERY request; see README in hmpps-connect-dps-components.',
16
+ )
17
+ console.info(
18
+ 'Make sure to resolve merge conflicts and check the diff carefully (eg. for duplicate environment variables)',
19
+ )