Skip to content

Commit

Permalink
Merge pull request alphagov#135 from alphagov/add-node-version-checking
Browse files Browse the repository at this point in the history
Add node version checking
  • Loading branch information
NickColley authored Jan 24, 2018
2 parents f4ad2ce + 838ba5f commit 8a32d66
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.9.4
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
language: node_js

node_js:
- 8

script:
- npm run lint
- npm run build
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,29 @@ designing government services.**

## Run locally

Make sure you have [Node.js](https://nodejs.org/en/) installed.
You'll need [Git](https://help.github.com/articles/set-up-git/) and [Node.js](https://nodejs.org/en/) installed to get this project running.

Note: You will need the [active LTS (Long-term support)](https://github.com/nodejs/Release#release-schedule) Node.js version for this project (as specified in [.nvmrc](./.nvmrc))

### Fork repository (optional)
If you're an external contributor make sure to [fork this project first](https://help.github.com/articles/fork-a-repo/)

### Clone repository
```
git clone git@github.com:alphagov/govuk-design-system.git # or clone your own fork
cd govuk-design-system
```

### Install dependencies
### Using nvm (optional)
If you work across multiple Node.js projects there's a good chance they require different Node.js and npm versions.

To enable this we use [nvm (Node Version Manager)](https://github.com/creationix/nvm) to switch between versions easily.

1. [install nvm](https://github.com/creationix/nvm#installation)
2. Run `nvm install` in the project directory (this will use [.nvmrc](./.nvmrc))

### Install npm dependencies
```
npm install
```
Expand Down
33 changes: 33 additions & 0 deletions bin/check-nvmrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env node

'use strict'

var fs = require('fs')
var path = require('path')

fs.readFile(path.join(__dirname, '../.nvmrc'), 'utf8', function (error, data) {
if (error) throw error
var expectedVersion = data.trim()
var currentVersion = process.version.replace('v', '')

var versionMatchesExactly = expectedVersion === currentVersion
var versionMatchesMajor = expectedVersion.split('.')[0] === currentVersion.split('.')[0]

if (versionMatchesExactly) {
process.exit()
}

if (versionMatchesMajor) {
console.log('' +
'Warning: You are using Node.js version ' + currentVersion + ' which we do not use. ' +
'You may encounter issues, consider installing Node.js version ' + expectedVersion + '.' +
'')
process.exit()
}

console.log('' +
'You are using Node.js version ' + currentVersion + ' which we do not support. ' +
'Please install Node.js version ' + expectedVersion + ' and try again.' +
'')
process.exit(1) // exit with a failure mode
})
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
},
"homepage": "https://github.com/alphagov/govuk-design-system#readme",
"scripts": {
"preinstall": "node bin/check-nvmrc.js",
"prestart": "node bin/check-nvmrc.js",
"build": "node tasks/build.js",
"start": "node tasks/serve.js",
"lint": "gulp scss:lint"
Expand Down Expand Up @@ -40,5 +42,8 @@
"metalsmith-sass": "^1.5.0",
"metalsmith-tagcleaner": "0.0.2",
"nunjucks": "^3.0.1"
},
"engines": {
"node": "8.9.4"
}
}

0 comments on commit 8a32d66

Please sign in to comment.