refactor: replace lodash templates #1810 (#2006)

We replace the lodash templates with arrow-functions and change the
single-argument object into multiple arguments.

Fixes #1810 
Closes #2006 

Change-Type: patch
Changelog-Entry: Replace Lodash templates with arrow-functions.
This commit is contained in:
Benedict Aas 2018-01-29 20:46:13 +00:00 committed by Jonas Hermsmeier
parent 4dc64ee15b
commit df2ebf93b6
5 changed files with 95 additions and 83 deletions

View File

@ -88,10 +88,7 @@ permissions.isElevated().then((elevated) => {
})
}).then((results) => {
return Bluebird.try(() => {
console.log(messages.info.flashComplete({
drive: results.flash.drive,
imageBasename: path.basename(results.imagePath)
}))
console.log(messages.info.flashComplete(path.basename(results.imagePath), results.flash.drive))
if (results.flash.checksum.crc32) {
console.log(`Checksum: ${results.flash.checksum.crc32}`)

View File

@ -82,10 +82,7 @@ module.exports = function (
return WarningModalService.display({
confirmationLabel: 'Yes, continue',
description: [
messages.warning.unrecommendedDriveSize({
image: selectionState.getImage(),
drive
}),
messages.warning.unrecommendedDriveSize(selectionState.getImage(), drive),
'Are you sure you want to continue?'
].join(' ')
})

View File

@ -75,10 +75,7 @@ module.exports = function (
imageWriter.flash(image.path, drive).then(() => {
if (!flashState.wasLastFlashCancelled()) {
notification.send('Success!', {
body: messages.info.flashComplete({
imageBasename: path.basename(image.path),
drive
}),
body: messages.info.flashComplete(path.basename(image.path), drive),
icon: iconPath
})
$state.go('success')
@ -86,10 +83,7 @@ module.exports = function (
})
.catch((error) => {
notification.send('Oops! Looks like the flash failed.', {
body: messages.error.flashFailure({
imageBasename: path.basename(image.path),
drive
}),
body: messages.error.flashFailure(path.basename(image.path), drive),
icon: iconPath
})

View File

@ -70,9 +70,7 @@ module.exports = function (
if (!supportedFormats.isSupportedImage(image.path)) {
const invalidImageError = errors.createUserError({
title: 'Invalid image',
description: messages.error.invalidImage({
image
})
description: messages.error.invalidImage(image)
})
osDialog.showError(invalidImageError)
@ -138,10 +136,7 @@ module.exports = function (
.catch((error) => {
const imageError = errors.createUserError({
title: 'Error opening image',
description: messages.error.openImage({
imageBasename: path.basename(imagePath),
errorMessage: error.message
})
description: messages.error.openImage(path.basename(imagePath), error.message)
})
osDialog.showError(imageError)

View File

@ -14,9 +14,9 @@
* limitations under the License.
*/
'use strict'
/* eslint-disable lodash/prefer-constant */
const _ = require('lodash')
'use strict'
/**
* @summary Application messages
@ -32,11 +32,12 @@ module.exports = {
*/
info: {
flashComplete: _.template([
'<%= imageBasename %> was successfully written to',
'<%= drive.description %> (<%= drive.raw %>)'
].join(' '))
flashComplete: (imageBasename, drive) => {
return [
`${imageBasename} was successfully written to`,
`${drive.description} (${drive.displayName})`
].join(' ')
}
},
/**
@ -46,28 +47,36 @@ module.exports = {
*/
warning: {
unrecommendedDriveSize: _.template([
'This image recommends a <%= image.recommendedDriveSize %>',
'bytes drive, however <%= drive.device %> is only <%= drive.size %> bytes.'
].join(' ')),
unrecommendedDriveSize: (image, drive) => {
return [
`This image recommends a ${image.recommendedDriveSize}`,
`bytes drive, however ${drive.device} is only ${drive.size} bytes.`
].join(' ')
},
exitWhileFlashing: _.template([
'You are currently flashing a drive.',
'Closing Etcher may leave your drive in an unusable state.'
].join(' ')),
exitWhileFlashing: () => {
return [
'You are currently flashing a drive.',
'Closing Etcher may leave your drive in an unusable state.'
].join(' ')
},
looksLikeWindowsImage: _.template([
'It looks like you are trying to burn a Windows image.\n\n',
'Unlike other images, Windows images require special processing to be made bootable.',
'We suggest you use a tool specially designed for this purpose, such as',
'<a href="https://rufus.akeo.ie">Rufus</a> (Windows) or Boot Camp Assistant (macOS).'
].join(' ')),
looksLikeWindowsImage: () => {
return [
'It looks like you are trying to burn a Windows image.\n\n',
'Unlike other images, Windows images require special processing to be made bootable.',
'We suggest you use a tool specially designed for this purpose, such as',
'<a href="https://rufus.akeo.ie">Rufus</a> (Windows) or Boot Camp Assistant (macOS).'
].join(' ')
},
missingPartitionTable: _.template([
'It looks like this is not a bootable image.\n\n',
'The image does not appear to contain a partition table,',
'and might not be recognized or bootable by your device.'
].join(' '))
missingPartitionTable: () => {
return [
'It looks like this is not a bootable image.\n\n',
'The image does not appear to contain a partition table,',
'and might not be recognized or bootable by your device.'
].join(' ')
}
},
@ -78,49 +87,69 @@ module.exports = {
*/
error: {
notEnoughSpaceInDrive: _.template([
'Not enough space on the drive.',
'Please insert larger one and try again.'
].join(' ')),
notEnoughSpaceInDrive: () => {
return [
'Not enough space on the drive.',
'Please insert larger one and try again.'
].join(' ')
},
genericFlashError: _.template('Oops, seems something went wrong.'),
genericFlashError: () => {
return 'Oops, seems something went wrong.'
},
validation: _.template([
'The write has been completed successfully but Etcher detected potential',
'corruption issues when reading the image back from the drive.',
'\n\nPlease consider writing the image to a different drive.'
].join(' ')),
validation: () => {
return [
'The write has been completed successfully but Etcher detected potential',
'corruption issues when reading the image back from the drive.',
'\n\nPlease consider writing the image to a different drive.'
].join(' ')
},
invalidImage: _.template('<%= image.path %> is not a supported image type.'),
invalidImage: (image) => {
return `${image.path} is not a supported image type.`
},
openImage: _.template([
'Something went wrong while opening <%= imageBasename %>\n\n',
'Error: <%= errorMessage %>'
].join('')),
openImage: (imageBasename, errorMessage) => {
return [
`Something went wrong while opening ${imageBasename}\n\n`,
`Error: ${errorMessage}`
].join('')
},
elevationRequired: _.template('This should should be run with root/administrator permissions.'),
elevationRequired: () => {
return 'This should should be run with root/administrator permissions.'
},
flashFailure: _.template([
'Something went wrong while writing <%= imageBasename %>',
'to <%= drive.description %> (<%= drive.raw %>)'
].join(' ')),
flashFailure: (imageBasename, drive) => {
return [
`Something went wrong while writing ${imageBasename}`,
`to ${drive.description} (${drive.displayName})`
].join(' ')
},
driveUnplugged: _.template([
'Looks like Etcher lost access to the drive.',
'Did it get unplugged accidentally?',
'\n\nSometimes this error is caused by faulty readers that don\'t provide stable access to the drive.'
].join(' ')),
driveUnplugged: () => {
return [
'Looks like Etcher lost access to the drive.',
'Did it get unplugged accidentally?',
'\n\nSometimes this error is caused by faulty readers that don\'t provide stable access to the drive.'
].join(' ')
},
inputOutput: _.template([
'Looks like Etcher is not able to write to this location of the drive.',
'This error is usually caused by a faulty drive, reader, or port.',
'\n\nPlease try again with another drive, reader, or port.'
].join(' ')),
inputOutput: () => {
return [
'Looks like Etcher is not able to write to this location of the drive.',
'This error is usually caused by a faulty drive, reader, or port.',
'\n\nPlease try again with another drive, reader, or port.'
].join(' ')
},
childWriterDied: _.template([
'The writer process ended unexpectedly.',
'Please try again, and contact the Etcher team if the problem persists.'
].join(' '))
childWriterDied: () => {
return [
'The writer process ended unexpectedly.',
'Please try again, and contact the Etcher team if the problem persists.'
].join(' ')
}
}