Skip to content

Commit

Permalink
Merge pull request #1907 from alphagov/creation-messaging
Browse files Browse the repository at this point in the history
Not showing progress reports for older installers.
  • Loading branch information
nataliecarey authored Jan 19, 2023
2 parents e4581ac + 8ab9c63 commit f544e5c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
21 changes: 15 additions & 6 deletions bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path')
const { spawn, exec } = require('../lib/exec')
const { parse } = require('./utils/argv-parser')
const { prepareMigration, preflightChecks } = require('../migrator')
const { npmInstall, packageJsonFormat } = require('./utils')
const { npmInstall, packageJsonFormat, getPackageVersionFromPackageJson, splitSemverVersion } = require('./utils')

// Avoid requiring any kit server code at the top-level as we might want to
// change environment variables below.
Expand All @@ -26,6 +26,13 @@ const verboseLogger = !argv.options.verbose
}

const progressLogger = function () {
if (argv.options['created-from-version']) {
const version = splitSemverVersion(argv.options['created-from-version'])
if (version.major === 13 && version.minor < 2) {
return
}
}

console.log(' - ', ...arguments)
}

Expand Down Expand Up @@ -182,11 +189,10 @@ function getArgumentsToPassThrough () {
return additionalArgs
}

function initialiserRequiresOldInitSyntax () {
const dependencies = require(path.join(getInstallLocation(), 'package.json')).dependencies || {}
const kitVersionParts = (dependencies['govuk-prototype-kit'] || '').split('.')
async function initialiserRequiresOldInitSyntax () {
const version = await getPackageVersionFromPackageJson(path.join(getInstallLocation(), 'node_modules', 'govuk-prototype-kit', 'package.json'))

const requiresOldInitSyntax = kitVersionParts[0].endsWith('13') && Number(kitVersionParts[1]) <= 2
const requiresOldInitSyntax = version.major === 13 && version.minor < 2
return requiresOldInitSyntax
}

Expand All @@ -204,7 +210,10 @@ async function runCreate () {
// as possible into stage two; stage one should ideally be able to install
// any future version of the kit.

verboseLogger('Cli running from', __filename)

console.log('')

const installDirectory = getInstallLocation()
const kitDependency = getChosenKitDependency()

Expand All @@ -225,7 +234,7 @@ async function runCreate () {

let runningWithinCreateScriptFlag = '--running-within-create-script'

if (initialiserRequiresOldInitSyntax()) {
if (await initialiserRequiresOldInitSyntax()) {
runningWithinCreateScriptFlag = '--'
}

Expand Down
2 changes: 1 addition & 1 deletion bin/utils/argv-parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('argv parser', () => {
paths: ['/tmp/hello-world']
})
})
it('should support semvar numbers as values', () => {
it('should support semver numbers as values', () => {
const result = parser.parse(addStandardArgs([
'--version',
'13.0.1',
Expand Down
20 changes: 19 additions & 1 deletion bin/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// local dependencies
const { spawn } = require('../../lib/exec')
const fse = require('fs-extra')

const packageJsonFormat = { encoding: 'utf8', spaces: 2 }

Expand All @@ -15,7 +16,24 @@ async function npmInstall (cwd, dependencies) {
})
}

function splitSemverVersion (version) {
const versionParts = version.split('.').map(Number)

return {
major: versionParts[0],
minor: versionParts[1],
patch: versionParts[2]
}
}

async function getPackageVersionFromPackageJson (packageJsonPath) {
const version = (await fse.readJson(packageJsonPath)).version
return splitSemverVersion(version)
}

module.exports = {
npmInstall,
packageJsonFormat
packageJsonFormat,
getPackageVersionFromPackageJson,
splitSemverVersion
}

0 comments on commit f544e5c

Please sign in to comment.