@dwp/govuk-casa 7.0.9 → 7.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/CHANGELOG.md +8 -0
- package/casa.js +1 -0
- package/lib/ConfigIngestor.js +27 -3
- package/lib/view-filters/formatDateObject.js +3 -3
- package/middleware/static/index.js +11 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [7.1.0](https://github.com/dwp/govuk-casa/compare/7.0.9...7.1.0) (2022-09-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add date format option to formatDateObject filter ([f20fbab](https://github.com/dwp/govuk-casa/commit/f20fbaba430e56f489106ad9b8a58cf85fb38910))
|
|
11
|
+
* Applied ability to disable generation of static assets ([6686d24](https://github.com/dwp/govuk-casa/commit/6686d240116e8c292c5da0b9c8a737a72f365ded))
|
|
12
|
+
|
|
5
13
|
### [7.0.9](https://github.com/dwp/govuk-casa/compare/7.0.8...7.0.9) (2022-01-13)
|
|
6
14
|
|
|
7
15
|
|
package/casa.js
CHANGED
|
@@ -75,6 +75,7 @@ function mountCasaMiddleware(app, config, i18nUtility) {
|
|
|
75
75
|
proxyMountUrl: config.proxyMountUrl,
|
|
76
76
|
compiledAssetsDir: config.compiledAssetsDir,
|
|
77
77
|
npmPackages: staticModulePaths,
|
|
78
|
+
skipAssetsGeneration: config.skipAssetsGeneration,
|
|
78
79
|
});
|
|
79
80
|
mwNunjucks(app, config.views.dirs, staticModulePaths.govukFrontend);
|
|
80
81
|
mwSession(
|
package/lib/ConfigIngestor.js
CHANGED
|
@@ -37,11 +37,12 @@ function validateUseStickyEdit(useStickyEdit = false) {
|
|
|
37
37
|
* Validates directory and checks that it is writeable.
|
|
38
38
|
*
|
|
39
39
|
* @param {string} compiledAssetsDir Directory.
|
|
40
|
+
* @param {boolean} skipAssetsGeneration skip static assets generation
|
|
40
41
|
* @throws {ReferenceError} For missing directory value.
|
|
41
42
|
* @throws {Error} For missing directory.
|
|
42
43
|
* @returns {string} Directory.
|
|
43
44
|
*/
|
|
44
|
-
function validateCompiledAssetsDir(compiledAssetsDir) {
|
|
45
|
+
function validateCompiledAssetsDir(compiledAssetsDir, skipAssetsGeneration = false) {
|
|
45
46
|
if (typeof compiledAssetsDir === 'undefined') {
|
|
46
47
|
throw new ReferenceError('Compiled assets directory required (compiledAssetsDir)');
|
|
47
48
|
}
|
|
@@ -50,7 +51,10 @@ function validateCompiledAssetsDir(compiledAssetsDir) {
|
|
|
50
51
|
try {
|
|
51
52
|
/* eslint-disable no-bitwise */
|
|
52
53
|
const constants = fs.constants || fs;
|
|
53
|
-
|
|
54
|
+
const permissions = skipAssetsGeneration
|
|
55
|
+
? (constants.F_OK | constants.R_OK)
|
|
56
|
+
: (constants.F_OK | constants.R_OK | constants.W_OK);
|
|
57
|
+
fs.accessSync(cad, permissions);
|
|
54
58
|
} catch (err) {
|
|
55
59
|
if (err.code === 'ENOENT') {
|
|
56
60
|
err.message = 'Compiled assets directory missing (compiledAssetsDir)';
|
|
@@ -483,6 +487,20 @@ function validateSessionsCookieSameSite(cookieSameSite, defaultFlag) {
|
|
|
483
487
|
return value;
|
|
484
488
|
}
|
|
485
489
|
|
|
490
|
+
/**
|
|
491
|
+
* Validate skip assets generation flag.
|
|
492
|
+
*
|
|
493
|
+
* @param {boolean} skipAssetsGeneration Flag.
|
|
494
|
+
* @throws {TypeError} For invalid argument type.
|
|
495
|
+
* @returns {boolean} Flag.
|
|
496
|
+
*/
|
|
497
|
+
function validateSkipAssetsGeneration(skipAssetsGeneration = false) {
|
|
498
|
+
if (typeof skipAssetsGeneration !== 'boolean') {
|
|
499
|
+
throw new TypeError('Skip assets generation flag must be a boolean (skipAssetsGeneration)');
|
|
500
|
+
}
|
|
501
|
+
return skipAssetsGeneration;
|
|
502
|
+
}
|
|
503
|
+
|
|
486
504
|
/**
|
|
487
505
|
* Ingest, validate, sanitise and manipulate configuration parameters.
|
|
488
506
|
*
|
|
@@ -500,8 +518,13 @@ function ingest(config = {}) {
|
|
|
500
518
|
// Use "sticky" edit mode
|
|
501
519
|
useStickyEdit: validateUseStickyEdit(config.useStickyEdit),
|
|
502
520
|
|
|
521
|
+
// Skip assets Generation
|
|
522
|
+
skipAssetsGeneration: validateSkipAssetsGeneration(config.skipAssetsGeneration),
|
|
523
|
+
|
|
503
524
|
// Directory to store compiled assets
|
|
504
|
-
compiledAssetsDir: validateCompiledAssetsDir(
|
|
525
|
+
compiledAssetsDir: validateCompiledAssetsDir(
|
|
526
|
+
config.compiledAssetsDir, config.skipAssetsGeneration,
|
|
527
|
+
),
|
|
505
528
|
|
|
506
529
|
// Content security policies
|
|
507
530
|
csp: validateContentSecurityPolicies(config.csp),
|
|
@@ -585,4 +608,5 @@ module.exports = {
|
|
|
585
608
|
validateSessionsTtl,
|
|
586
609
|
validateViewsObject,
|
|
587
610
|
validateViewsDirs,
|
|
611
|
+
validateSkipAssetsGeneration,
|
|
588
612
|
};
|
|
@@ -13,11 +13,11 @@ const { DateTime } = require('luxon');
|
|
|
13
13
|
* object - {dd:'', mm:'', yyyy:''}
|
|
14
14
|
*
|
|
15
15
|
* @param {object} date Date (see supported formats above)
|
|
16
|
-
* @param {object} config Holds locale
|
|
16
|
+
* @param {object} config Holds locale and luxon date format
|
|
17
17
|
* @returns {string} Formatted date
|
|
18
18
|
*/
|
|
19
19
|
module.exports = function formatDateObject(date, config = {}) {
|
|
20
|
-
const { locale = 'en' } = config;
|
|
20
|
+
const { locale = 'en', format = 'd MMMM yyyy' } = config;
|
|
21
21
|
|
|
22
22
|
if (
|
|
23
23
|
Object.prototype.toString.call(date) === '[object Object]'
|
|
@@ -29,7 +29,7 @@ module.exports = function formatDateObject(date, config = {}) {
|
|
|
29
29
|
year: Math.max(0, parseInt(date.yyyy, 10)),
|
|
30
30
|
month: Math.max(0, parseInt(date.mm, 10)),
|
|
31
31
|
day: Math.max(1, parseInt(date.dd, 10)),
|
|
32
|
-
}).setLocale(locale).toFormat(
|
|
32
|
+
}).setLocale(locale).toFormat(format);
|
|
33
33
|
}
|
|
34
34
|
return 'INVALID DATE OBJECT';
|
|
35
35
|
};
|
|
@@ -39,6 +39,7 @@ const onehour = 3600000;
|
|
|
39
39
|
* govukFrontend: govuk-frontend npm package path <string>,
|
|
40
40
|
* govukTemplateJinja: govuk_template_jinja npm package path <string>
|
|
41
41
|
* govukCasa: @dwp/govuk-casa npm package path <string>
|
|
42
|
+
* skipAssetsGeneration: boolean value to determine whether to skip the preparation of assets
|
|
42
43
|
*
|
|
43
44
|
* @param {object} args See above
|
|
44
45
|
* @returns {void}
|
|
@@ -55,6 +56,7 @@ module.exports = (args) => {
|
|
|
55
56
|
govukTemplateJinja = '',
|
|
56
57
|
govukCasa = '',
|
|
57
58
|
} = Object.create(null),
|
|
59
|
+
skipAssetsGeneration,
|
|
58
60
|
} = args;
|
|
59
61
|
|
|
60
62
|
const compiledAssetsDir = path.resolve(cAssetsDir);
|
|
@@ -74,13 +76,15 @@ module.exports = (args) => {
|
|
|
74
76
|
|
|
75
77
|
const prefixCasa = `${proxyMountUrl}/govuk/casa`.replace(/\/+/g, '/');
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
if (!skipAssetsGeneration) {
|
|
80
|
+
logger.trace('Calling prepare-assets');
|
|
81
|
+
mwPrepareAssets({
|
|
82
|
+
logger,
|
|
83
|
+
npmGovukCasa: govukCasa,
|
|
84
|
+
compiledAssetsDir,
|
|
85
|
+
mountUrl,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
84
88
|
|
|
85
89
|
logger.trace('Calling serve-assets');
|
|
86
90
|
mwServeAssets({
|