Skip to content

Commit

Permalink
Make logging of migration script more consistent
Browse files Browse the repository at this point in the history
Make sure paths are always logged as relative to the project directory,
to keep them short and easier to read.
  • Loading branch information
lfdebrux committed Dec 8, 2022
1 parent b729117 commit 4129eb9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/migrator/fileHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ const handleNotFound = resultIfFileNotFound => e => {
}

const replaceStartOfFile = async ({ filePath, lineToFind, replacement }) => {
const prettyFilePath = path.relative(projectDir, filePath)
const fileLines = await getFileAsLines(filePath)
const replacementLineNumber = fileLines.indexOf(lineToFind)
if (replacementLineNumber > -1) {
await verboseLog(`Found [${lineToFind}] in [${filePath}, replacing`)
await verboseLog(`Found [${lineToFind}] in [${prettyFilePath}], replacing`)
const linesFromOldFile = fileLines.splice(replacementLineNumber + 1)
await verboseLog('Keeping these lines from old file', linesFromOldFile)
const updatedFileLines = [replacement, ...linesFromOldFile]
return writeFileLinesToFile(filePath, updatedFileLines)
}
await verboseLog(`Could not found [${lineToFind}] in [${filePath}, aborting`)
await verboseLog(`Could not found [${lineToFind}] in [${prettyFilePath}], aborting`)
return false
}

Expand Down Expand Up @@ -101,7 +102,7 @@ const deleteDirectoryIfEmpty = async (partialPath) => {
const copyFileFromStarter = async (starterPath, newPath) => {
const src = path.join(packageDir, 'prototype-starter', starterPath)
const dest = path.join(projectDir, newPath || starterPath)
await verboseLog(`copying from [${src}] to [${dest}]`)
await verboseLog(`Copying from [${path.relative(projectDir, src)}] to [${path.relative(projectDir, dest)}]`)
return fse.copy(src, dest)
.then(successOutput)
.catch(async e => {
Expand Down
6 changes: 3 additions & 3 deletions lib/migrator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ const directoriesToDelete = [
]

const directoriesToDeleteIfEmpty = [
'/app/assets/sass/patterns',
'/app/assets/images',
'/app/views/includes'
'app/assets/sass/patterns',
'app/assets/images',
'app/views/includes'
]

const filesToUpdateIfUnchanged = [
Expand Down
2 changes: 1 addition & 1 deletion lib/migrator/migrationSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module.exports.deleteUnusedFiles = async (filesToDelete) => {
// Do not report files that don't exist
return true
}
const reporter = await addReporter(`Delete ${filePath}`)
const reporter = await addReporter(`Delete ${file}`)
const result = await deleteFile(path.join(projectDir, file))
await reporter(result)
return result
Expand Down

0 comments on commit 4129eb9

Please sign in to comment.