Skip to content

Commit

Permalink
Compile GOV.UK Prototype Kit config to package top level
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed May 18, 2023
1 parent 1f37064 commit ab45c0b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
1 change: 1 addition & 0 deletions bin/pre-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ npm run build:package
if [[ -n $(git status --porcelain) ]]; then
echo "✍️ Commiting changed package"
git add packages/govuk-frontend/dist/
git add --force packages/govuk-frontend/govuk-prototype-kit.config.json

git commit -m "Release GOV.UK Frontend to '$BRANCH_NAME' for testing"

Expand Down
2 changes: 2 additions & 0 deletions packages/govuk-frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
govuk-prototype-kit.config.json

# Build output (committed)
!/dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { join } from 'path'

import { filterPath, getDirectories, getListing } from 'govuk-frontend-lib/files'
import { componentNameToMacroName, packageNameToPath } from 'govuk-frontend-lib/names'
import slash from 'slash'
Expand All @@ -10,35 +8,35 @@ import slash from 'slash'
* @returns {Promise<PrototypeKitConfig>} GOV.UK Prototype Kit config
*/
export default async () => {
const componentsFiles = await getListing(packageNameToPath('govuk-frontend', 'src/govuk/components'))
const componentMacros = await getListing(packageNameToPath('govuk-frontend', 'src'), '**/components/**/macro.njk')
const componentNames = await getDirectories(packageNameToPath('govuk-frontend', 'src/govuk/components'))

// Build array of macros
const nunjucksMacros = componentNames
.map((componentName) => {
const [macroPath] = componentsFiles
const [macroPath = ''] = componentMacros
.filter(filterPath([`**/${componentName}/macro.njk`]))

return {
importFrom: slash(join('govuk/components', macroPath)),
importFrom: slash(macroPath),
macroName: componentNameToMacroName(componentName)
}
})

return {
assets: [
'/govuk/assets',
'/govuk/all.js.map'
'/dist/govuk/assets',
'/dist/govuk/all.js.map'
],
sass: [
'/govuk-prototype-kit/init.scss'
'/dist/govuk-prototype-kit/init.scss'
],
scripts: [
'/govuk/all.js',
'/govuk-prototype-kit/init.js'
'/dist/govuk/all.js',
'/dist/govuk-prototype-kit/init.js'
],
nunjucksMacros,
nunjucksPaths: ['/']
nunjucksPaths: ['/dist']
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ describe('GOV.UK Prototype Kit config', () => {

it('includes paths for assets, scripts, sass', () => {
expect(config.assets).toEqual([
'/govuk/assets',
'/govuk/all.js.map'
'/dist/govuk/assets',
'/dist/govuk/all.js.map'
])

expect(config.sass).toEqual([
'/govuk-prototype-kit/init.scss'
'/dist/govuk-prototype-kit/init.scss'
])

expect(config.scripts).toEqual([
'/govuk/all.js',
'/govuk-prototype-kit/init.js'
'/dist/govuk/all.js',
'/dist/govuk-prototype-kit/init.js'
])
})

Expand Down Expand Up @@ -159,7 +159,7 @@ describe('GOV.UK Prototype Kit config', () => {
})

it('includes paths', () => {
expect(config.nunjucksPaths).toEqual(['/'])
expect(config.nunjucksPaths).toEqual(['/dist'])
})
})
})
7 changes: 3 additions & 4 deletions packages/govuk-frontend/tasks/build/package.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ describe('packages/govuk-frontend/dist/', () => {
const listingExpected = listingSource
.filter(filterPath(filterPatterns))

// Replaces GOV.UK Prototype kit config with JSON
.flatMap(mapPathTo(['**/govuk-prototype-kit.config.mjs'], ({ dir: requirePath, name }) => [
join(requirePath, '../', `${name}.json`)
]))
// Removes GOV.UK Prototype kit config (moved to package top level)
.flatMap(mapPathTo(['**/govuk-prototype-kit.config.mjs'], () => []))

// Replaces all source '*.mjs' files
.flatMap(mapPathTo(['**/*.mjs'], ({ dir: requirePath, name }) => {
Expand Down Expand Up @@ -95,6 +93,7 @@ describe('packages/govuk-frontend/dist/', () => {
// Check top level package contents
expect(listingPackage).toEqual([
'README.md',
'govuk-prototype-kit.config.json',
'gulpfile.mjs',
'package.json',
'postcss.config.mjs',
Expand Down
4 changes: 2 additions & 2 deletions packages/govuk-frontend/tasks/scripts.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'path'
import { join, resolve } from 'path'

import { configs, scripts, task } from 'govuk-frontend-tasks'
import gulp from 'gulp'
Expand Down Expand Up @@ -39,7 +39,7 @@ export const compile = (options) => gulp.series(
task.name("compile:js 'govuk-prototype-kit'", () =>
configs.compile('govuk-prototype-kit.config.mjs', {
srcPath: join(options.srcPath, 'govuk-prototype-kit'),
destPath: options.destPath,
destPath: resolve(options.destPath, '../'), // Top level (not dist) for compatibility

filePath (file) {
return join(file.dir, `${file.name}.json`)
Expand Down

0 comments on commit ab45c0b

Please sign in to comment.