Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unix line-endings everywhere #1738

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
CYPRESS_CACHE_FOLDER: ~/.cache/Cypress

steps:
- run: |
git config --global core.autocrlf false
git config --global core.eol lf

- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand All @@ -45,4 +49,4 @@ jobs:
- run: npm run test:unit && npm run test:integration
env:
CI: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 8 additions & 9 deletions __tests__/spec/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require('path')
const fs = require('fs')
const fse = require('fs-extra')
const { spawn } = require('../../lib/exec')
const os = require('os')
const { mkdtempSync } = require('../util')
const { sleep } = require('../../lib/utils')

Expand Down Expand Up @@ -57,27 +56,27 @@ describe('migrate test prototype', () => {

expect(routesFileContents).toEqual(
'const router = require(\'govuk-prototype-kit\').requests.setupRouter()' +
os.EOL + os.EOL +
'\n\n' +
'// Add your routes here' +
os.EOL + os.EOL + os.EOL
'\n\n\n'
)
})

it('filters.js', () => {
const filtersFileContents = fs.readFileSync(path.join(appDirectory, 'filters.js'), 'utf8')

expect(filtersFileContents).toEqual(
'const addFilter = require(\'govuk-prototype-kit\').views.addFilter' + os.EOL
'const addFilter = require(\'govuk-prototype-kit\').views.addFilter' + '\n'
)
})

it('application.js', () => {
const jsFileContents = fs.readFileSync(path.join(assetsDirectory, 'javascripts', 'application.js'), 'utf8')

expect(jsFileContents).toEqual(
'window.GOVUKPrototypeKit.documentReady(() => {' + os.EOL +
' // Add JavaScript here' + os.EOL +
'})' + os.EOL
'window.GOVUKPrototypeKit.documentReady(() => {' + '\n' +
' // Add JavaScript here' + '\n' +
'})' + '\n'
)
})

Expand All @@ -86,15 +85,15 @@ describe('migrate test prototype', () => {

expect(sassFileContents).toEqual(
'// Add extra styles here' +
os.EOL + os.EOL + os.EOL
'\n\n\n'
)
})

it('layout.html', () => {
const layoutFileContents = fs.readFileSync(path.join(appDirectory, 'views', 'layout.html'), 'utf8')

expect(layoutFileContents).toEqual(
'{% extends "govuk-prototype-kit/layouts/govuk-branded.html" %}' + os.EOL
'{% extends "govuk-prototype-kit/layouts/govuk-branded.html" %}' + '\n'
)
})
})
3 changes: 1 addition & 2 deletions bin/cli
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

const fs = require('fs-extra')
const os = require('os')
const path = require('path')

const { spawn } = require('../lib/exec')
Expand Down Expand Up @@ -40,7 +39,7 @@ const packageJson = {
}
}

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

async function updatePackageJson (packageJsonPath) {
let newPackageJson = Object.assign({}, packageJson)
Expand Down
7 changes: 3 additions & 4 deletions lib/build/tasks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path')
const { EOL } = require('os')

const chokidar = require('chokidar')
const colour = require('ansi-colors')
Expand Down Expand Up @@ -90,7 +89,7 @@ function proxyUserSassIfItExists (filename) {
}
ensureTempDirExists(path.dirname(proxyFilePath))

fse.writeFileSync(path.join(proxyFilePath), proxyFileLines.join(EOL))
fse.writeFileSync(path.join(proxyFilePath), proxyFileLines.join('\n'))
}

function generateCss (sassPath, cssPath, options = {}) {
Expand Down Expand Up @@ -181,15 +180,15 @@ function autoImportComponentsSync () {
macroName,
importFrom
}
}) => `{% from "${importFrom}" import ${macroName} %}`).join(EOL)
}) => `{% from "${importFrom}" import ${macroName} %}`).join('\n')

extensions.getByType('importNunjucksMacrosInto').map(({ packageName, item: templatePath }) => {
return {
shadowPath: path.join(shadowNunjucks, packageName, templatePath),
newContents: [
includeString,
fse.readFileSync(path.join(projectDir, 'node_modules', packageName, templatePath), 'utf8')
].join(EOL + EOL)
].join('\n\n')
}
}).forEach(file => {
fse.ensureDirSync(path.dirname(file.shadowPath))
Expand Down
5 changes: 2 additions & 3 deletions lib/migrator/fileHelpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const os = require('os')
const path = require('path')
const { packageDir, projectDir } = require('../path-utils')
const fs = require('fs').promises
Expand All @@ -24,8 +23,8 @@ const verboseLogError = async (e) => {
await verboseLog()
}

const joinLines = arr => arr.join(os.EOL)
const splitIntoLines = fileContents => fileContents.split(os.EOL)
const joinLines = arr => arr.join('\n')
const splitIntoLines = fileContents => fileContents.split('\n')
const successOutput = () => true

const getFileAsLines = async (filePath) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/migrator/fileHelpers.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env jest */

const util = require('util')
const os = require('os')
const path = require('path')

jest.mock('./logger')
Expand All @@ -11,7 +10,7 @@ const { projectDir } = require('../path-utils')
const { removeLineFromFile, replaceStartOfFile, deleteFile, deleteDirectory } = require('./fileHelpers')

describe('file helpers', () => {
const joinLines = arr => arr.join(os.EOL)
const joinLines = arr => arr.join('\n')
const writeFileToMockFile = (filePathParts, contentStringOrArray) => testScope.fileSystem
.writeFile(filePathParts, typeof contentStringOrArray === 'string' ? contentStringOrArray : joinLines(contentStringOrArray))

Expand Down
3 changes: 1 addition & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Core dependencies
const path = require('path')
const url = require('url')
const os = require('os')
const { existsSync } = require('fs')
const fs = require('fs').promises

Expand Down Expand Up @@ -167,7 +166,7 @@ app.get('/docs/tutorials-and-examples', function (req, res) {
app.get('/', async (req, res) => {
const starterHomepageCode = await fs.readFile(path.join(packageDir, 'prototype-starter', 'app', 'views', 'index.html'), 'utf8')
res.render('govuk-prototype-kit/backup-homepage', {
starterHomepageCodeLines: starterHomepageCode.split(os.EOL)
starterHomepageCodeLines: starterHomepageCode.split('\n')
})
})

Expand Down