diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6f711f0ea0..028e0c1116 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,9 +31,6 @@ jobs: name: Build runs-on: ${{ github.event.inputs.runner || 'ubuntu-latest' }} - env: - ENVIRONMENT: production - steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/lib/metalsmith.js b/lib/metalsmith.js index f28b456657..2a15fafe45 100644 --- a/lib/metalsmith.js +++ b/lib/metalsmith.js @@ -78,7 +78,13 @@ module.exports = metalsmith(resolve(__dirname, '../')) // global variables used in layout files .metadata({ title: '[TITLE NOT SET]', - colours + colours, + + // include safe environment variables as metalsmith metadata + // used to e.g. detect when we're building in a preview environment + env: { + NODE_ENV: process.env.NODE_ENV ?? 'production' + } }) // rename .md files to .md.njk, so they're passed through the Nunjucks parser @@ -97,11 +103,6 @@ module.exports = metalsmith(resolve(__dirname, '../')) // Ignore internal config .ignore('.eslintrc.js') - // include environment variables as metalsmith metadata - // used to e.g. detect when we're building in a preview environment - .env(process.env) - .use((files, ms) => { ms.metadata(ms.env()) }) - // convert *.scss files to *.css .use(sass({ quietDeps: true, diff --git a/package-lock.json b/package-lock.json index a6b59e1e90..69c40d2d56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "@rollup/plugin-terser": "^0.4.3", "accessible-autocomplete": "^2.0.4", "browser-sync": "2.29.3", + "cross-env": "^7.0.3", "eslint": "^8.43.0", "eslint-config-standard": "^17.0.0", "eslint-plugin-import": "^2.27.5", @@ -5300,6 +5301,24 @@ "node": ">= 0.2.0" } }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-fetch": { "version": "3.1.6", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.6.tgz", @@ -20066,6 +20085,15 @@ "integrity": "sha512-w9UZUtkaGd8MfS7eMG7Sa0lV5vCJghqQfiOnwNVrPhbZScUp5h0jwYoAF933MKlotlG1JAJOCCT3xU6r+SDKNw==", "dev": true }, + "cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.1" + } + }, "cross-fetch": { "version": "3.1.6", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.6.tgz", diff --git a/package.json b/package.json index c8831b66c2..5fa96e2665 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ "homepage": "https://github.com/alphagov/govuk-design-system#readme", "scripts": { "postinstall": "npm ls --depth=0", - "build": "node tasks/build.js", - "start": "node tasks/start.js", - "serve": "node tasks/serve.js", + "build": "cross-env NODE_ENV=production node tasks/build.js", + "start": "cross-env NODE_ENV=development node tasks/start.js", + "serve": "cross-env NODE_ENV=development node tasks/serve.js", "pretest": "npm run build", "test": "npm run lint && jest", "lint": "npm run lint:js && npm run lint:scss && npm run lint:html --ignore-scripts", @@ -53,6 +53,7 @@ "@rollup/plugin-terser": "^0.4.3", "accessible-autocomplete": "^2.0.4", "browser-sync": "2.29.3", + "cross-env": "^7.0.3", "eslint": "^8.43.0", "eslint-config-standard": "^17.0.0", "eslint-plugin-import": "^2.27.5", diff --git a/views/layouts/_generic.njk b/views/layouts/_generic.njk index 9541e9cba1..0441ccbbf0 100644 --- a/views/layouts/_generic.njk +++ b/views/layouts/_generic.njk @@ -5,7 +5,7 @@ {% block pageTitle %}{{ title }} – GOV.UK Design System{% endblock %} {% block head %} - {% if not ENVIRONMENT or ENVIRONMENT != 'production' %} + {% if env.NODE_ENV != 'production' %} {% endif %}