Skip to content

Commit

Permalink
Initialise git repo when creating a kit.
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliecarey committed Dec 19, 2022
1 parent e4dac2e commit 6fc1a9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 14 additions & 1 deletion __tests__/spec/sanity-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const assert = require('assert')
const path = require('path')
const EOL = require('os').EOL

const fs = require('fs-extra')
const request = require('supertest')
Expand All @@ -14,7 +15,7 @@ let app
process.env.KIT_PROJECT_DIR = tmpDir

const { packageDir, projectDir } = require('../../lib/path-utils')

const { exec } = require('../../lib/exec')
const createKitTimeout = parseInt(process.env.CREATE_KIT_TIMEOUT || '90000', 10)

/**
Expand All @@ -38,6 +39,18 @@ describe('The Prototype Kit', () => {
)
})

it('should initialise git out of the box', async () => {
const outputLines = []
await exec('git log', { cwd: tmpDir }, (data) => outputLines.push(data.toString()))

function getLastMeaningfulLineTrimmed (outputLines) {
const meaningulLines = outputLines.join(EOL).split(EOL).filter(line => line !== '')
return meaningulLines.pop().trim()
}

expect(getLastMeaningfulLineTrimmed(outputLines)).toBe('Created prototype kit.')
})

describe('index page', () => {
it('should send a well formed response', async () => {
const response = await request(app).get('/')
Expand Down
8 changes: 6 additions & 2 deletions bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require('fs-extra')
const path = require('path')

const { spawn } = require('../lib/exec')
const { spawn, exec } = require('../lib/exec')
const { parse } = require('./utils/argvParser')
const { prepareMigration, preflightChecks } = require('../lib/migrator')
const { npmInstall, packageJsonFormat } = require('./utils')
Expand Down Expand Up @@ -49,6 +49,10 @@ async function updatePackageJson (packageJsonPath) {
await fs.writeJson(packageJsonPath, newPackageJson, packageJsonFormat)
}

async function initialiseGitRepo () {
return exec('git init && git add -A . && git commit -am "Created prototype kit."')
}

function usage () {
const prog = 'npx govuk-prototype-kit'
console.log(`
Expand Down Expand Up @@ -175,7 +179,7 @@ function warnIfNpmStart (argv, env) {
fs.writeFile(path.join(installDirectory, '.npmrc'), npmrc, 'utf8'),
copyFile('LICENCE.txt'),
updatePackageJson(path.join(installDirectory, 'package.json'))
])
]).then(initialiseGitRepo)
} else if (argv.command === 'dev') {
require('../start')
} else if (argv.command === 'start' || argv.command === 'serve') {
Expand Down

0 comments on commit 6fc1a9a

Please sign in to comment.