-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcheck-compatibility-with-govuk-frontend-version.js
More file actions
executable file
·68 lines (60 loc) · 2.54 KB
/
check-compatibility-with-govuk-frontend-version.js
File metadata and controls
executable file
·68 lines (60 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// prototypes load and compile a subset of hmrc-frontend styles using their
// own version of govuk-frontend, if their version of govuk-frontend is
// lower than 5.4.0 then the compilation of styles will fail with an error
// that can be hard for interaction designers to debug, we would like to
// give them a warning on installation so that they don't get stuck later
// when trying to use the hmrc-frontend styles.
const fs = require('fs');
const path = require('path');
function hmrcFrontendDisableCompatibilityCheck() {
return (process.env.npm_config_hmrc_frontend_disable_compatibility_check || process.env.HMRC_FRONTEND_DISABLE_COMPATIBILITY_CHECK) === 'true';
}
function semverGreaterThanOrEqualTo(a, b) {
const [aMaj, aMin, aPat] = a.split('.').map(Number);
const [bMaj, bMin, bPat] = b.split('.').map(Number);
return ((aMaj - bMaj) || (aMin - bMin) || (aPat - bPat)) >= 0;
}
function withinPrototypeKitAndUsingIncompatibleGovukFrontendVersion() {
const projectDir = process.env.INIT_CWD || process.cwd();
const projectPackagePath = path.join(projectDir, 'package.json');
const projectPackageJson = JSON.parse(fs.readFileSync(projectPackagePath, 'utf8'));
if (
!projectPackageJson.dependencies
|| !projectPackageJson.dependencies['govuk-frontend']
|| !projectPackageJson.dependencies['govuk-prototype-kit']
) {
process.exit(0);
}
const currentVersionInProject = projectPackageJson.dependencies['govuk-frontend'].replace(/[^0-9.]/g, '');
const minimumGovukFrontendVersion = '6.0.0';
return (!semverGreaterThanOrEqualTo(currentVersionInProject, minimumGovukFrontendVersion));
}
try {
if (hmrcFrontendDisableCompatibilityCheck()) {
process.exit(0);
}
if (withinPrototypeKitAndUsingIncompatibleGovukFrontendVersion()) {
// eslint-disable-next-line no-console
process.stderr.write(`
Hello friend, looks like your prototype is using a version of
govuk-frontend lower than v6.0.0, which is the minimum version
compatible to automatically compile and load the styles for the
version of hmrc-frontend you're installing with the govuk-prototype-kit.
You can silence this warning by setting the environment variable
HMRC_FRONTEND_DISABLE_COMPATIBILITY_CHECK=true.
- PlatUI
-------------------------------------------
\\ ^__^
\\ (oo)_______
(__) )\\/\\
||----w |
|| ||
- PlatMooI the PlatUI Helper Cow
`);
process.exit(1);
} else {
process.exit(0);
}
} catch (err) {
process.exit(0);
}