Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version info from package.json to config #3113

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/app.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const cheerio = require('cheerio')

const configPaths = require('../config/paths')
const config = require('../config')
const { getDirectories } = require('../lib/file-helper')

const PORT = configPaths.ports.test
const PORT = config.ports.test

const expectedPages = [
'/',
Expand Down Expand Up @@ -45,7 +45,7 @@ describe(`http://localhost:${PORT}`, () => {
const response = await fetchPath('/')
const $ = cheerio.load(await response.text())

const componentNames = await getDirectories(configPaths.components)
const componentNames = await getDirectories(config.paths.components)
const componentsList = $('li a[href^="/components/"]').get()

// Since we have an 'all' component link that renders the default example of all
Expand Down
4 changes: 2 additions & 2 deletions app/banner.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const cheerio = require('cheerio')

const configPaths = require('../config/paths')
const PORT = configPaths.ports.test
const config = require('../config')
const PORT = config.ports.test

// Returns Fetch API wrapper which applies these options by default
const fetchPath = (path, options) => {
Expand Down
4 changes: 2 additions & 2 deletions app/full-page-examples.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const cheerio = require('cheerio')

const configPaths = require('../config/paths')
const PORT = configPaths.ports.test
const config = require('../config')
const PORT = config.ports.test

const expectedPages = [
'bank-holidays',
Expand Down
4 changes: 2 additions & 2 deletions app/start.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const configPaths = require('../config/paths')
const config = require('../config')

const app = require('./app')

const PORT = process.env.PORT || configPaths.ports.app
const PORT = process.env.PORT || config.ports.app

app()
.then(server => server.listen(PORT, () =>
Expand Down
13 changes: 13 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const pkg = require('../package/package.json')

/**
* Config
*/
const paths = require('./paths')
const ports = require('./ports')

module.exports = {
paths,
pkg,
ports
}
4 changes: 2 additions & 2 deletions config/jest/server/start.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getServers, setup } from 'jest-dev-server'
import waitOn from 'wait-on'

import configPaths from '../../paths.js'
import config from '../../index.js'

import serverStop from './stop.mjs'

const { PORT = configPaths.ports.test } = process.env
const PORT = process.env.PORT || config.ports.test

/**
* Start web server
Expand Down
8 changes: 1 addition & 7 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,5 @@ module.exports = {
views: join(configPaths.app, 'views'),
examples: join(configPaths.app, 'views/examples'),
fullPageExamples: join(configPaths.app, 'views/full-page-examples'),
layouts: join(configPaths.app, 'views/layouts'),

// Review application ports
ports: {
app: 3000,
test: 8888
}
layouts: join(configPaths.app, 'views/layouts')
}
7 changes: 7 additions & 0 deletions config/ports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Review application ports
*/
module.exports = {
app: 3000,
test: 8888
}
4 changes: 2 additions & 2 deletions lib/puppeteer-helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const configPaths = require('../config/paths')
const config = require('../config')

const { componentNameToJavaScriptClassName } = require('./helper-functions')
const { renderHtml } = require('./jest-helpers')

const PORT = process.env.PORT || configPaths.ports.test
const PORT = process.env.PORT || config.ports.test

/**
* Render and initialise a component within test boilerplate HTML
Expand Down
6 changes: 2 additions & 4 deletions tasks/asset-version.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { readFile, writeFile } from 'fs/promises'
import { writeFile } from 'fs/promises'
import { EOL } from 'os'
import { join } from 'path'

import configPaths from '../config/paths.js'
import { pkg } from '../config/index.js'

import { destination, isDist } from './task-arguments.mjs'

Expand All @@ -13,8 +13,6 @@ import { destination, isDist } from './task-arguments.mjs'
* @returns {Promise<void>}
*/
export async function updateDistAssetsVersion () {
const pkg = JSON.parse(await readFile(join(configPaths.package, 'package.json'), 'utf8'))

if (!isDist) {
throw new Error('Asset version can only be applied to ./dist')
}
Expand Down
14 changes: 6 additions & 8 deletions tasks/gulp/__tests__/after-build-dist.test.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { readFile } from 'fs/promises'
import { join } from 'path'

import configPaths from '../../../config/paths.js'
import { paths, pkg } from '../../../config/index.js'
import { getListing } from '../../../lib/file-helper.js'

describe('dist/', () => {
let pkg
let listingSourceAssets
let listingDistAssets

beforeAll(async () => {
pkg = JSON.parse(await readFile(join(configPaths.package, 'package.json'), 'utf8'))
listingSourceAssets = await getListing(configPaths.assets)
listingDistAssets = await getListing(join(configPaths.dist, 'assets'))
listingSourceAssets = await getListing(paths.assets)
listingDistAssets = await getListing(join(paths.dist, 'assets'))
})

describe('assets/', () => {
Expand All @@ -27,7 +25,7 @@ describe('dist/', () => {

beforeAll(async () => {
filename = `govuk-frontend-${pkg.version}.min.css`
stylesheet = await readFile(join(configPaths.dist, filename), 'utf8')
stylesheet = await readFile(join(paths.dist, filename), 'utf8')
})

it('should not contain current media query displayed on body element', () => {
Expand All @@ -49,7 +47,7 @@ describe('dist/', () => {

beforeAll(async () => {
filename = `govuk-frontend-ie8-${pkg.version}.min.css`
stylesheet = await readFile(join(configPaths.dist, filename), 'utf8')
stylesheet = await readFile(join(paths.dist, filename), 'utf8')
})

it('should not contain current media query displayed on body element', () => {
Expand All @@ -67,7 +65,7 @@ describe('dist/', () => {

beforeAll(async () => {
filename = `govuk-frontend-${pkg.version}.min.js`
javascript = await readFile(join(configPaths.dist, filename), 'utf8')
javascript = await readFile(join(paths.dist, filename), 'utf8')
})

it('should have the correct version name', () => {
Expand Down
18 changes: 8 additions & 10 deletions tasks/gulp/compile-assets.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import { readFile } from 'fs/promises'
import { join, parse } from 'path'

import gulp from 'gulp'
Expand All @@ -16,13 +15,12 @@ import nodeSass from 'node-sass'
import PluginError from 'plugin-error'
import slash from 'slash'

import configPaths from '../../config/paths.js'
import { paths, pkg } from '../../config/index.js'
import { getListing } from '../../lib/file-helper.js'
import { componentNameToJavaScriptModuleName } from '../../lib/helper-functions.js'
import { destination, isDev, isDist, isPackage } from '../task-arguments.mjs'

const sass = gulpSass(nodeSass)
const pkg = JSON.parse(await readFile(join(configPaths.package, 'package.json'), 'utf8'))

/**
* Compile Sass to CSS task
Expand All @@ -38,7 +36,7 @@ export function compileStylesheets () {
if (isDist) {
return merge(
compileStylesheet(
gulp.src(`${slash(configPaths.src)}/govuk/all.scss`, {
gulp.src(`${slash(paths.src)}/govuk/all.scss`, {
sourcemaps: true
})
.pipe(rename({
Expand All @@ -48,7 +46,7 @@ export function compileStylesheets () {
}))),

compileStylesheet(
gulp.src(`${slash(configPaths.src)}/govuk/all-ie8.scss`, {
gulp.src(`${slash(paths.src)}/govuk/all-ie8.scss`, {
sourcemaps: true
})
.pipe(rename({
Expand All @@ -65,12 +63,12 @@ export function compileStylesheets () {
// Review application
return merge(
compileStylesheet(
gulp.src(`${slash(configPaths.app)}/assets/scss/app?(-ie8).scss`, {
gulp.src(`${slash(paths.app)}/assets/scss/app?(-ie8).scss`, {
sourcemaps: true
})),

compileStylesheet(
gulp.src(`${slash(configPaths.app)}/assets/scss/app-legacy?(-ie8).scss`, {
gulp.src(`${slash(paths.app)}/assets/scss/app-legacy?(-ie8).scss`, {
sourcemaps: true
}), {
includePaths: [
Expand All @@ -80,7 +78,7 @@ export function compileStylesheets () {
}),

compileStylesheet(
gulp.src(`${slash(configPaths.fullPageExamples)}/**/styles.scss`, {
gulp.src(`${slash(paths.fullPageExamples)}/**/styles.scss`, {
sourcemaps: true
})
.pipe(rename((path) => {
Expand Down Expand Up @@ -124,7 +122,7 @@ export async function compileJavaScripts () {
const fileLookup = isDist ? 'govuk/all.mjs' : 'govuk/**/!(*.test).mjs'

// Perform a search and return an array of matching file names
const srcFiles = await getListing(configPaths.src, fileLookup)
const srcFiles = await getListing(paths.src, fileLookup)

return merge(srcFiles.map((file) => {
const { dir: srcPath, name } = parse(file)
Expand All @@ -138,7 +136,7 @@ export async function compileJavaScripts () {
? componentNameToJavaScriptModuleName(name)
: 'GOVUKFrontend'

return compileJavaScript(gulp.src(slash(join(configPaths.src, file)), {
return compileJavaScript(gulp.src(slash(join(paths.src, file)), {
sourcemaps: true
}), moduleName)
.pipe(gulp.dest(slash(join(destPath, modulePath)), {
Expand Down