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) => { }).then((results) => {
return Bluebird.try(() => { return Bluebird.try(() => {
console.log(messages.info.flashComplete({ console.log(messages.info.flashComplete(path.basename(results.imagePath), results.flash.drive))
drive: results.flash.drive,
imageBasename: path.basename(results.imagePath)
}))
if (results.flash.checksum.crc32) { if (results.flash.checksum.crc32) {
console.log(`Checksum: ${results.flash.checksum.crc32}`) console.log(`Checksum: ${results.flash.checksum.crc32}`)

View File

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

View File

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

View File

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

View File

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