@@ -8,7 +8,6 @@ const bodyParser = require('body-parser')
88const cookieParser = require ( 'cookie-parser' )
99const dotenv = require ( 'dotenv' )
1010const express = require ( 'express' )
11- const fse = require ( 'fs-extra' )
1211const { expressNunjucks, getNunjucksAppEnv, stopWatchingNunjucks } = require ( './lib/nunjucks/nunjucksConfiguration' )
1312
1413// We want users to be able to keep api keys, config variables and other
@@ -20,11 +19,11 @@ dotenv.config()
2019const { projectDir, packageDir, finalBackupNunjucksDir } = require ( './lib/utils/paths' )
2120const config = require ( './lib/config.js' ) . getConfig ( )
2221const packageJson = require ( './package.json' )
22+ const { govukFrontendPaths } = require ( './lib/govukFrontendPaths' )
2323const utils = require ( './lib/utils' )
2424const sessionUtils = require ( './lib/session.js' )
2525const plugins = require ( './lib/plugins/plugins.js' )
2626const routesApi = require ( './lib/routes/api.js' )
27- const { getInternalGovukFrontendDir } = require ( './lib/utils' )
2827
2928const app = express ( )
3029routesApi . setApp ( app )
@@ -40,6 +39,12 @@ if (isSecure) {
4039 app . set ( 'trust proxy' , 1 ) // needed for secure cookies on heroku
4140}
4241
42+ // Find GOV.UK Frontend (via project, internal package fallback)
43+ const govukFrontend = govukFrontendPaths ( [ projectDir , packageDir ] )
44+
45+ // Find GOV.UK Frontend (via internal package, project fallback)
46+ const govukFrontendInternal = govukFrontendPaths ( [ packageDir , projectDir ] )
47+
4348// Add variables that are available in all views
4449app . locals . asset_path = '/public/'
4550app . locals . useAutoStoreData = config . useAutoStoreData
@@ -56,6 +61,11 @@ if (plugins.legacyGovukFrontendFixesNeeded()) {
5661app . locals . pluginConfig = plugins . getAppConfig ( {
5762 scripts : utils . prototypeAppScripts
5863} )
64+
65+ // Add GOV.UK Frontend paths to Nunjucks locals
66+ app . locals . govukFrontend = govukFrontend
67+ app . locals . govukFrontendInternal = govukFrontendInternal
68+
5969// keep extensionConfig around for backwards compatibility
6070// TODO: remove in v14
6171app . locals . extensionConfig = app . locals . pluginConfig
@@ -70,16 +80,15 @@ app.use(cookieParser())
7080// static assets to prevent unauthorised access
7181app . use ( require ( './lib/authentication.js' ) ( ) )
7282
73- // Get internal govuk-frontend views
74- const internalGovUkFrontendDir = getInternalGovukFrontendDir ( )
75- const internalGovUkFrontendConfig = fse . readJsonSync ( path . join ( internalGovUkFrontendDir , 'govuk-prototype-kit.config.json' ) )
76- const internalGovUkFrontendViews = internalGovUkFrontendConfig . nunjucksPaths . map ( viewPath => path . join ( internalGovUkFrontendDir , viewPath ) )
83+ // Get GOV.UK Frontend (internal) views
84+ const govukFrontendNunjucksPaths = ( govukFrontendInternal . config ?. nunjucksPaths || [ ] )
85+ . map ( nunjucksPath => path . join ( govukFrontendInternal . baseDir , nunjucksPath ) )
7786
7887// Set up App
7988const appViews = [
8089 path . join ( projectDir , '/app/views/' )
8190] . concat ( plugins . getAppViews ( [
82- ...internalGovUkFrontendViews ,
91+ ...govukFrontendNunjucksPaths ,
8392 finalBackupNunjucksDir
8493] ) )
8594
0 commit comments