fix(CLI): pass required arguments to flashComplete message (#1630)

The `flashComplete` message takes the drive object and the image
basename as arguments. This was updated on the GUI, but causes the CLI
to throw an error upon completion.

Change-Type: patch
Changelog-Entry: Fix "imageBasename is not defined" error on the CLI.
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
This commit is contained in:
Juan Cruz Viotti 2017-08-01 12:32:50 -04:00 committed by GitHub
parent 70c79f6127
commit a63b6bf18c
8 changed files with 36 additions and 32 deletions

View File

@ -17,6 +17,7 @@
'use strict'; 'use strict';
const _ = require('lodash'); const _ = require('lodash');
const path = require('path');
const Bluebird = require('bluebird'); const Bluebird = require('bluebird');
const visuals = require('resin-cli-visuals'); const visuals = require('resin-cli-visuals');
const form = require('resin-cli-form'); const form = require('resin-cli-form');
@ -105,6 +106,12 @@ permissions.isElevated().then((elevated) => {
progressBars[state.type].update(state); progressBars[state.type].update(state);
} }
}).then((results) => {
return {
imagePath,
flash: results,
drive: selectedDrive
};
}); });
}); });
}).then((results) => { }).then((results) => {
@ -112,14 +119,17 @@ permissions.isElevated().then((elevated) => {
return Bluebird.try(() => { return Bluebird.try(() => {
if (robot.isEnabled(process.env)) { if (robot.isEnabled(process.env)) {
return robot.printMessage('done', { return robot.printMessage('done', {
sourceChecksum: results.sourceChecksum sourceChecksum: results.flash.sourceChecksum
}); });
} }
console.log(messages.info.flashComplete()); console.log(messages.info.flashComplete({
drive: results.drive,
imageBasename: path.basename(results.imagePath)
}));
if (results.sourceChecksum) { if (results.flash.sourceChecksum) {
console.log(`Checksum: ${results.sourceChecksum}`); console.log(`Checksum: ${results.flash.sourceChecksum}`);
} }
return Bluebird.resolve(); return Bluebird.resolve();

View File

@ -13,7 +13,7 @@
<h4 class="list-group-item-heading">{{ drive.description }} - <h4 class="list-group-item-heading">{{ drive.description }} -
<span class="word-keep">{{ drive.size | gigabyte | number:1 }} GB</span> <span class="word-keep">{{ drive.size | gigabyte | number:1 }} GB</span>
</h4> </h4>
<p class="list-group-item-text">{{ drive.name }}</p> <p class="list-group-item-text">{{ drive.displayName }}</p>
<footer class="list-group-item-footer"> <footer class="list-group-item-footer">

View File

@ -17,7 +17,6 @@
'use strict'; 'use strict';
const Rx = require('rx'); const Rx = require('rx');
const os = require('os');
const _ = require('lodash'); const _ = require('lodash');
const EventEmitter = require('events').EventEmitter; const EventEmitter = require('events').EventEmitter;
const drivelist = require('drivelist'); const drivelist = require('drivelist');
@ -40,19 +39,6 @@ const availableDrives = Rx.Observable.timer(
return Rx.Observable.fromNodeCallback(drivelist.list)(); return Rx.Observable.fromNodeCallback(drivelist.list)();
}) })
// Build human friendly "description"
.map((drives) => {
return _.map(drives, (drive) => {
drive.name = drive.device;
if (os.platform() === 'win32' && !_.isEmpty(drive.mountpoints)) {
drive.name = _.join(_.map(drive.mountpoints, 'path'), ', ');
}
return drive;
});
})
.map((drives) => { .map((drives) => {
if (settings.get('unsafeMode')) { if (settings.get('unsafeMode')) {
return drives; return drives;

View File

@ -62,7 +62,7 @@
ng-class="{ ng-class="{
'text-disabled': main.shouldDriveStepBeDisabled() 'text-disabled': main.shouldDriveStepBeDisabled()
}" }"
uib-tooltip="{{ main.selection.getDrive().description }} ({{ main.selection.getDrive().name }})"> uib-tooltip="{{ main.selection.getDrive().description }} ({{ main.selection.getDrive().displayName }})">
<span class="step-drive step-name"> <span class="step-drive step-name">
<!-- middleEllipses errors on undefined, therefore fallback to empty string --> <!-- middleEllipses errors on undefined, therefore fallback to empty string -->
{{ (main.selection.getDrive().description || "") | middleEllipses:11 }} {{ (main.selection.getDrive().description || "") | middleEllipses:11 }}

View File

@ -34,7 +34,7 @@ module.exports = {
flashComplete: _.template([ flashComplete: _.template([
'<%= imageBasename %> was successfully written to', '<%= imageBasename %> was successfully written to',
'<%= drive.description %> (<%= drive.name %>)' '<%= drive.description %> (<%= drive.displayName %>)'
].join(' ')) ].join(' '))
}, },
@ -102,7 +102,7 @@ module.exports = {
flashFailure: _.template([ flashFailure: _.template([
'Something went wrong while writing <%= imageBasename %>', 'Something went wrong while writing <%= imageBasename %>',
'to <%= drive.description %> (<%= drive.name %>)' 'to <%= drive.description %> (<%= drive.displayName %>)'
].join(' ')), ].join(' ')),
driveUnplugged: _.template([ driveUnplugged: _.template([

6
npm-shrinkwrap.json generated
View File

@ -1302,9 +1302,9 @@
"dev": true "dev": true
}, },
"drivelist": { "drivelist": {
"version": "5.0.27", "version": "5.1.0",
"from": "drivelist@5.0.27", "from": "drivelist@5.1.0",
"resolved": "https://registry.npmjs.org/drivelist/-/drivelist-5.0.27.tgz", "resolved": "https://registry.npmjs.org/drivelist/-/drivelist-5.1.0.tgz",
"dependencies": { "dependencies": {
"lodash": { "lodash": {
"version": "4.17.4", "version": "4.17.4",

View File

@ -51,7 +51,7 @@
"bootstrap-sass": "3.3.6", "bootstrap-sass": "3.3.6",
"chalk": "1.1.3", "chalk": "1.1.3",
"command-join": "2.0.0", "command-join": "2.0.0",
"drivelist": "5.0.27", "drivelist": "5.1.0",
"electron-is-running-in-asar": "1.0.0", "electron-is-running-in-asar": "1.0.0",
"etcher-image-write": "9.1.3", "etcher-image-write": "9.1.3",
"file-type": "4.1.0", "file-type": "4.1.0",

View File

@ -81,6 +81,7 @@ describe('Browser: driveScanner', function() {
this.drivelistStub.yields(null, [ this.drivelistStub.yields(null, [
{ {
device: '/dev/sda', device: '/dev/sda',
displayName: '/dev/sda',
description: 'WDC WD10JPVX-75J', description: 'WDC WD10JPVX-75J',
size: '931.5G', size: '931.5G',
mountpoints: [ mountpoints: [
@ -92,6 +93,7 @@ describe('Browser: driveScanner', function() {
}, },
{ {
device: '/dev/sdb', device: '/dev/sdb',
displayName: '/dev/sdb',
description: 'Foo', description: 'Foo',
size: '14G', size: '14G',
mountpoints: [ mountpoints: [
@ -103,6 +105,7 @@ describe('Browser: driveScanner', function() {
}, },
{ {
device: '/dev/sdc', device: '/dev/sdc',
displayName: '/dev/sdc',
description: 'Bar', description: 'Bar',
size: '14G', size: '14G',
mountpoints: [ mountpoints: [
@ -124,7 +127,7 @@ describe('Browser: driveScanner', function() {
m.chai.expect(drives).to.deep.equal([ m.chai.expect(drives).to.deep.equal([
{ {
device: '/dev/sdb', device: '/dev/sdb',
name: '/dev/sdb', displayName: '/dev/sdb',
description: 'Foo', description: 'Foo',
size: '14G', size: '14G',
mountpoints: [ mountpoints: [
@ -136,7 +139,7 @@ describe('Browser: driveScanner', function() {
}, },
{ {
device: '/dev/sdc', device: '/dev/sdc',
name: '/dev/sdc', displayName: '/dev/sdc',
description: 'Bar', description: 'Bar',
size: '14G', size: '14G',
mountpoints: [ mountpoints: [
@ -177,6 +180,7 @@ describe('Browser: driveScanner', function() {
this.drivelistStub.yields(null, [ this.drivelistStub.yields(null, [
{ {
device: '\\\\.\\PHYSICALDRIVE1', device: '\\\\.\\PHYSICALDRIVE1',
displayName: 'C:',
description: 'WDC WD10JPVX-75J', description: 'WDC WD10JPVX-75J',
size: '931.5G', size: '931.5G',
mountpoints: [ mountpoints: [
@ -188,6 +192,7 @@ describe('Browser: driveScanner', function() {
}, },
{ {
device: '\\\\.\\PHYSICALDRIVE2', device: '\\\\.\\PHYSICALDRIVE2',
displayName: '\\\\.\\PHYSICALDRIVE2',
description: 'Foo', description: 'Foo',
size: '14G', size: '14G',
mountpoints: [], mountpoints: [],
@ -195,6 +200,7 @@ describe('Browser: driveScanner', function() {
}, },
{ {
device: '\\\\.\\PHYSICALDRIVE3', device: '\\\\.\\PHYSICALDRIVE3',
displayName: 'F:',
description: 'Bar', description: 'Bar',
size: '14G', size: '14G',
mountpoints: [ mountpoints: [
@ -216,7 +222,7 @@ describe('Browser: driveScanner', function() {
m.chai.expect(drives).to.deep.equal([ m.chai.expect(drives).to.deep.equal([
{ {
device: '\\\\.\\PHYSICALDRIVE2', device: '\\\\.\\PHYSICALDRIVE2',
name: '\\\\.\\PHYSICALDRIVE2', displayName: '\\\\.\\PHYSICALDRIVE2',
description: 'Foo', description: 'Foo',
size: '14G', size: '14G',
mountpoints: [], mountpoints: [],
@ -224,7 +230,7 @@ describe('Browser: driveScanner', function() {
}, },
{ {
device: '\\\\.\\PHYSICALDRIVE3', device: '\\\\.\\PHYSICALDRIVE3',
name: 'F:', displayName: 'F:',
description: 'Bar', description: 'Bar',
size: '14G', size: '14G',
mountpoints: [ mountpoints: [
@ -252,6 +258,7 @@ describe('Browser: driveScanner', function() {
this.drivelistStub.yields(null, [ this.drivelistStub.yields(null, [
{ {
device: '\\\\.\\PHYSICALDRIVE3', device: '\\\\.\\PHYSICALDRIVE3',
displayName: 'F:',
description: 'Bar', description: 'Bar',
size: '14G', size: '14G',
mountpoints: [ mountpoints: [
@ -271,7 +278,7 @@ describe('Browser: driveScanner', function() {
it('should use the drive letter as the name', function(done) { it('should use the drive letter as the name', function(done) {
driveScanner.once('drives', function(drives) { driveScanner.once('drives', function(drives) {
m.chai.expect(drives).to.have.length(1); m.chai.expect(drives).to.have.length(1);
m.chai.expect(drives[0].name).to.equal('F:'); m.chai.expect(drives[0].displayName).to.equal('F:');
driveScanner.stop(); driveScanner.stop();
done(); done();
}); });
@ -288,6 +295,7 @@ describe('Browser: driveScanner', function() {
this.drivesListStub.yields(null, [ this.drivesListStub.yields(null, [
{ {
device: '\\\\.\\PHYSICALDRIVE3', device: '\\\\.\\PHYSICALDRIVE3',
displayName: 'F:, G:, H:',
description: 'Bar', description: 'Bar',
size: '14G', size: '14G',
mountpoints: [ mountpoints: [
@ -313,7 +321,7 @@ describe('Browser: driveScanner', function() {
it('should join all the mountpoints in `name`', function(done) { it('should join all the mountpoints in `name`', function(done) {
driveScanner.once('drives', function(drives) { driveScanner.once('drives', function(drives) {
m.chai.expect(drives).to.have.length(1); m.chai.expect(drives).to.have.length(1);
m.chai.expect(drives[0].name).to.equal('F:, G:, H:'); m.chai.expect(drives[0].displayName).to.equal('F:, G:, H:');
driveScanner.stop(); driveScanner.stop();
done(); done();
}); });