Skip to content

Commit

Permalink
Add logic for case where user has already upgraded to v13
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdebrux committed Jul 22, 2022
1 parent 3cd2582 commit 7dc024e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/_update_javascripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ const path = require('path')
const { projectDir, packageDir } = require('./path-utils')
const updateDir = path.join(projectDir, 'update')

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) => {
Expand Down Expand Up @@ -37,10 +40,20 @@ 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
if (original === theirs) {
return fs.copyFile(path.join(packageDir, 'lib', assetPath), path.join(projectDir, 'app', assetPath))
Expand Down

0 comments on commit 7dc024e

Please sign in to comment.