Skip to content

Commit

Permalink
Merge pull request #72 from hmrc/PLATUI-342_relative_path_for_scss_sq…
Browse files Browse the repository at this point in the history
…uashed

Squashed commit of relative path work
  • Loading branch information
matthewmascord authored Apr 22, 2020
2 parents 065083d + 1b4506e commit 3416823
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ sassdoc/
# hmrc-frontend specific
package/
__tests__/package.json
__tests__/govuk-frontend
__tests__/hmrc-frontend
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.11.0] - 2020-04-22

### Fixed

- The way Sass assets from govuk-frontend are imported to allow use in Scala front-ends
- Removed compatibility check for now due to issues with versions of the form X.Y0.Z

## [1.10.1] - 2020-04-22

### Fixed
Expand Down
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,38 @@ npm install

### Frontend microservices

Currently unsupported.

We offer a few ways of incorporating the GOV UK and HMRC CSS and JS libraries into your service. Pick the one which best suits your service. In the following instructions, `1.X.X` and `3.X.X` refers to the version of the library you require.

### 1. CDN
If you are just using the GOVUK Frontend and HMRC Frontend and are not going to be adding any service-specific CSS or JS we suggest you use the HMRC CDN version of the assets.
You will need to link to these in your service’s page template.

1. add CDN js links to your `@bodyEnd` block in the layout template
- `<script type="text/javascript" src="https://www.tax.service.gov.uk/assets/hmrc-frontend/1.X.X/hmrc-frontend-1.X.X.min.js"></script>`
2. add CDN css links to your `@headTag` block in the layout template
- `<link rel="stylesheet" type="text/css" href="https://www.tax.service.gov.uk/assets/hmrc-frontend/1.X.X/hmrc-frontend-1.X.X.min.css">`
- `<link rel="stylesheet" type="text/css" href="https://www.tax.service.gov.uk/assets/hmrc-frontend/1.X.X/hmrc-frontend-ie8-1.X.X.min.css">`
`

### 2. Webjar
If you are adding some custom CSS to your service we suggest you use a webjar to pull in the GOV UK and HMRC Frontend libraries.
This will enable you to use the appropriate SASS mixins to ensure your custom code is consistent with other components.
It will allow you to package your code along with the libraries into a single download for the user.
It will also mean you can optionally just consume the parts of the libraries you actually need for your service.

1. add `"org.webjars.npm" % "govuk-frontend" % "3.X.X"` to your app dependencies (`hmrc-frontend` has a dependency on `govuk-frontend`)
2. add `"org.webjars.npm" % "hmrc-frontend" % "1.X.X"` to your app dependencies
3. in `application.scss`:
- add `$hmrc-assets-path: "/url-of-your-service/assets/lib/hmrc-frontend/hmrc/assets";`
- to import all components, add `@import "lib/hmrc-frontend/hmrc/all";`
- to import individual components, add
- `@import "lib/hmrc-frontend/hmrc/components/header/header";`
- `@import "lib/hmrc-frontend/hmrc/components/account-menu/account-menu";`
- `and so on`
- to add to or override SASS, update `application.scss` or create additional `.scss` files and import them as described above
4. in `application.js`:
- to add to or override javascript, update `application.js` or create additional `.js` files and add them to `build.sbt`

## How to contribute

### Design patterns
Expand Down
2 changes: 1 addition & 1 deletion check-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (!knownPrototypeKitNames.includes(consumerPackageJson.name)) {
}

const compatibility = {
'1.10': {
'1.11': {
'prototype-kit': ['9.6', '9.5', '9.4', '9.3', '9.2', '9.1', '9.0']
},
'0.6': {
Expand Down
1 change: 1 addition & 0 deletions config/paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"src": "src/",
"components": "src/components/",
"govukFrontend": "node_modules/govuk-frontend",
"packageTest": "__tests__/packageTest",
"ports": {
"app": 3000,
"test": 8888
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hmrc-frontend",
"version": "1.10.1",
"version": "1.11.0",
"description": "Design patterns for HMRC frontends",
"scripts": {
"start": "gulp dev",
Expand Down
8 changes: 4 additions & 4 deletions src/components/account-menu/_account-menu.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "node_modules/govuk-frontend/govuk/settings/all";
@import "node_modules/govuk-frontend/govuk/tools/all";
@import "node_modules/govuk-frontend/govuk/helpers/all";
@import "node_modules/govuk-frontend/govuk/vendor/sass-mq";
@import "../../../../govuk-frontend/govuk/settings/all";
@import "../../../../govuk-frontend/govuk/tools/all";
@import "../../../../govuk-frontend/govuk/helpers/all";
@import "../../../../govuk-frontend/govuk/vendor/sass-mq";

// previously provided by govuk-template, no equivalent in govuk-frontend
.hidden {
Expand Down
8 changes: 4 additions & 4 deletions src/components/add-to-a-list/_add-to-a-list.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "node_modules/govuk-frontend/govuk/settings/all";
@import "node_modules/govuk-frontend/govuk/tools/all";
@import "node_modules/govuk-frontend/govuk/helpers/all";
@import "node_modules/govuk-frontend/govuk/vendor/sass-mq";
@import "../../../../govuk-frontend/govuk/settings/all";
@import "../../../../govuk-frontend/govuk/tools/all";
@import "../../../../govuk-frontend/govuk/helpers/all";
@import "../../../../govuk-frontend/govuk/vendor/sass-mq";

.hmrc-add-to-a-list {
padding-left: 0;
Expand Down
8 changes: 4 additions & 4 deletions src/components/currency-input/_currency-input.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "node_modules/govuk-frontend/govuk/settings/all";
@import "node_modules/govuk-frontend/govuk/tools/all";
@import "node_modules/govuk-frontend/govuk/helpers/all";
@import "node_modules/govuk-frontend/govuk/vendor/sass-mq";
@import "../../../../govuk-frontend/govuk/settings/all";
@import "../../../../govuk-frontend/govuk/tools/all";
@import "../../../../govuk-frontend/govuk/helpers/all";
@import "../../../../govuk-frontend/govuk/vendor/sass-mq";

.hmrc-currency-input__wrapper {
position: relative;
Expand Down
8 changes: 4 additions & 4 deletions src/components/timeout-dialog/_timeout-dialog.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "node_modules/govuk-frontend/govuk/settings/all";
@import "node_modules/govuk-frontend/govuk/tools/all";
@import "node_modules/govuk-frontend/govuk/helpers/all";
@import "node_modules/govuk-frontend/govuk/vendor/sass-mq";
@import "../../../../govuk-frontend/govuk/settings/all";
@import "../../../../govuk-frontend/govuk/tools/all";
@import "../../../../govuk-frontend/govuk/helpers/all";
@import "../../../../govuk-frontend/govuk/vendor/sass-mq";

.hmrc-timeout-overlay {
position: fixed;
Expand Down
32 changes: 29 additions & 3 deletions tasks/gulp/__tests__/after-build-package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,35 @@ describe('package/', () => {
})

describe('all.scss', () => {
it('should compile without throwing an exeption', async () => {
const allScssFile = path.join(configPaths.package, 'hmrc/all.scss')
await sassRender({ file: allScssFile })
const govukLink = path.join(configPaths.packageTest, 'govuk-frontend')
const hmrcLink = path.join(configPaths.packageTest, 'hmrc-frontend')
const removeSymLinksIfPresent = async () => {
try {
await fs.promises.unlink(govukLink)
} catch (e) {}
try {
await fs.promises.unlink(hmrcLink)
} catch (e) {}
}
const createSymlinks = async () => {
await fs.promises.mkdir(path.join(configPaths.packageTest), { recursive: true })
await removeSymLinksIfPresent()
const projectRoot = path.join(__dirname, '../../..')
await fs.promises.symlink(path.join(projectRoot, configPaths.govukFrontend), govukLink)
await fs.promises.symlink(path.join(projectRoot, configPaths.package), hmrcLink)
}

it('should compile without throwing an exception', async () => {
await createSymlinks()
try {
const allScssFile = path.join(configPaths.packageTest, 'hmrc-frontend/hmrc/all.scss')
await sassRender({ file: allScssFile })
} catch (e) {
await removeSymLinksIfPresent()
console.error(e.messageFormatted || e)
throw e
}
await removeSymLinksIfPresent()
})
})
})
3 changes: 0 additions & 3 deletions tasks/gulp/compile-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ gulp.task('scss:compile', () => {
let compile = gulp.src(compileStylesheet)
.pipe(plumber(errorHandler))
.pipe(gulpif(!isPackage, sourcemaps.init()))
.pipe(sass({
includePaths: ['node_modules']
}))
// minify css add vendor prefixes and normalize to compiled css
.pipe(gulpif(isDist, postcss([
autoprefixer,
Expand Down

0 comments on commit 3416823

Please sign in to comment.