From 29c135df64eeeab5dae8333b7a703e60415e6e05 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Fri, 22 Jul 2022 16:27:17 +0100 Subject: [PATCH] Add logic for case where user has already upgraded to v13 --- lib/_update_javascripts.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/_update_javascripts.js b/lib/_update_javascripts.js index 07a4dd3f8b..7ff0f359d1 100644 --- a/lib/_update_javascripts.js +++ b/lib/_update_javascripts.js @@ -4,9 +4,12 @@ const path = require('path') const { projectDir, packageDir } = require('./path-utils') -async function fetchOriginal (filePath) { - const oldVersion = (await fs.readFile(path.join(projectDir, 'VERSION.txt'), 'utf8')).trim() - const remoteUrl = `https://raw.githubusercontent.com/alphagov/govuk-prototype-kit/v${oldVersion}/${filePath}` +async function getProjectVersion () { + return (await fs.readFile(path.join(projectDir, 'VERSION.txt'), 'utf8')).trim() +} + +async function fetchOriginal (version, filePath) { + const remoteUrl = `https://raw.githubusercontent.com/alphagov/govuk-prototype-kit/v${version}/${filePath}` let data = '' return new Promise((resolve, reject) => { @@ -34,8 +37,17 @@ async function fetchOriginal (filePath) { } async function removeKitJsFromApplicationJs () { + const userVersion = getProjectVersion() + + // If the user already has version 13 or greater of the kit installed then + // their application.js file is all their code and we don't don't want to + // change it + if (userVersion >= '13.0.0') { + return + } + const assetPath = 'assets/javascripts/application.js' - const original = await fetchOriginal(path.posix.join('app', assetPath)) + const original = await fetchOriginal(userVersion, path.posix.join('app', assetPath)) const theirs = await fs.readFile(path.resolve(projectDir, 'app', assetPath), 'utf8') // If the user hasn't changed their application.js file we can just replace it completely