mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-24 03:36:36 +00:00
Refactor Etcher using ES6 features
This commit is contained in:
parent
f7ddce3000
commit
122f136ff8
@ -59,7 +59,7 @@
|
||||
"evil" : false, // Tolerate use of `eval`.
|
||||
"expr" : true, // Tolerate `ExpressionStatement` as Programs.
|
||||
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
|
||||
"globalstrict" : false, // Allow global "use strict" (also enables 'strict').
|
||||
"globalstrict" : true, // Allow global "use strict" (also enables 'strict').
|
||||
"iterator" : false, // Allow usage of __iterator__ property.
|
||||
"lastsemic" : false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
|
||||
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
|
||||
|
20
gulpfile.js
20
gulpfile.js
@ -14,13 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var gulp = require('gulp');
|
||||
var jscs = require('gulp-jscs');
|
||||
var jshint = require('gulp-jshint');
|
||||
var jshintStylish = require('jshint-stylish');
|
||||
var sass = require('gulp-sass');
|
||||
'use strict';
|
||||
|
||||
var paths = {
|
||||
const gulp = require('gulp');
|
||||
const jscs = require('gulp-jscs');
|
||||
const jshint = require('gulp-jshint');
|
||||
const jshintStylish = require('jshint-stylish');
|
||||
const sass = require('gulp-sass');
|
||||
|
||||
const paths = {
|
||||
scripts: [
|
||||
'./tests/**/*.spec.js',
|
||||
'./lib/**/*.js',
|
||||
@ -32,16 +34,12 @@ var paths = {
|
||||
};
|
||||
|
||||
gulp.task('sass', function() {
|
||||
'use strict';
|
||||
|
||||
return gulp.src(paths.sass)
|
||||
.pipe(sass().on('error', sass.logError))
|
||||
.pipe(gulp.dest('./build/css'));
|
||||
});
|
||||
|
||||
gulp.task('lint', function() {
|
||||
'use strict';
|
||||
|
||||
return gulp.src(paths.scripts)
|
||||
.pipe(jshint())
|
||||
.pipe(jshint.reporter(jshintStylish))
|
||||
@ -50,8 +48,6 @@ gulp.task('lint', function() {
|
||||
});
|
||||
|
||||
gulp.task('watch', [ 'lint', 'sass' ], function() {
|
||||
'use strict';
|
||||
|
||||
gulp.watch(paths.scripts, [ 'lint' ]);
|
||||
gulp.watch(paths.sass, [ 'sass' ]);
|
||||
});
|
||||
|
@ -18,11 +18,13 @@
|
||||
* @module ResinEtcher
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var angular = require('angular');
|
||||
var _ = require('lodash');
|
||||
var electron = require('electron');
|
||||
var shell = electron.remote.require('shell');
|
||||
var dialog = electron.remote.require('./src/dialog');
|
||||
const _ = require('lodash');
|
||||
const electron = require('electron');
|
||||
const shell = electron.remote.require('shell');
|
||||
const dialog = electron.remote.require('./src/dialog');
|
||||
|
||||
require('angular-ui-bootstrap');
|
||||
require('./browser/modules/selection-state');
|
||||
@ -30,7 +32,7 @@ require('./browser/modules/drive-scanner');
|
||||
require('./browser/modules/image-writer');
|
||||
require('./browser/modules/path');
|
||||
|
||||
var app = angular.module('ResinEtcher', [
|
||||
const app = angular.module('ResinEtcher', [
|
||||
'ui.bootstrap',
|
||||
|
||||
// Resin Etcher modules
|
||||
@ -43,8 +45,6 @@ var app = angular.module('ResinEtcher', [
|
||||
// TrackJS integration
|
||||
// http://docs.trackjs.com/tracker/framework-integrations
|
||||
app.config(function($provide) {
|
||||
'use strict';
|
||||
|
||||
$provide.decorator('$exceptionHandler', function($delegate, $window) {
|
||||
return function(exception, cause) {
|
||||
$window.trackJs.track(exception);
|
||||
@ -55,7 +55,7 @@ app.config(function($provide) {
|
||||
$provide.decorator('$log', function($delegate, $window) {
|
||||
|
||||
// Save the original $log.debug()
|
||||
var debugFn = $delegate.debug;
|
||||
let debugFn = $delegate.debug;
|
||||
|
||||
$delegate.debug = function(message) {
|
||||
message = new Date() + ' ' + message;
|
||||
@ -68,9 +68,7 @@ app.config(function($provide) {
|
||||
});
|
||||
|
||||
app.controller('AppController', function($q, $log, DriveScannerService, SelectionStateService, ImageWriterService) {
|
||||
'use strict';
|
||||
|
||||
var self = this;
|
||||
let self = this;
|
||||
this.selection = SelectionStateService;
|
||||
this.writer = ImageWriterService;
|
||||
this.scanner = DriveScannerService;
|
||||
@ -86,14 +84,14 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
// otherwise the drive is selected while the drive step is disabled
|
||||
// which looks very weird.
|
||||
if (drives.length === 1 && self.selection.hasImage()) {
|
||||
var drive = _.first(drives);
|
||||
const drive = _.first(drives);
|
||||
|
||||
// Do not autoselect the same drive over and over again
|
||||
// and fill the logs unnecessary.
|
||||
// `angular.equals` is used instead of `_.isEqual` to
|
||||
// cope with `$$hashKey`.
|
||||
if (!angular.equals(self.selection.getDrive(), drive)) {
|
||||
$log.debug('Autoselecting drive: ' + drive.device);
|
||||
$log.debug(`Autoselecting drive: ${drive.device}`);
|
||||
self.selectDrive(drive);
|
||||
}
|
||||
|
||||
@ -117,13 +115,13 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
this.selectImage = function() {
|
||||
return $q.when(dialog.selectImage()).then(function(image) {
|
||||
self.selection.setImage(image);
|
||||
$log.debug('Image selected: ' + image);
|
||||
$log.debug(`Image selected: ${image}`);
|
||||
});
|
||||
};
|
||||
|
||||
this.selectDrive = function(drive) {
|
||||
self.selection.setDrive(drive);
|
||||
$log.debug('Drive selected: ' + drive.device);
|
||||
$log.debug(`Drive selected: ${drive.device}`);
|
||||
};
|
||||
|
||||
this.reselectImage = function() {
|
||||
@ -155,7 +153,7 @@ app.controller('AppController', function($q, $log, DriveScannerService, Selectio
|
||||
// otherwise Windows throws EPERM
|
||||
self.scanner.stop();
|
||||
|
||||
$log.debug('Burning ' + image + ' to ' + drive.device);
|
||||
$log.debug(`Burning ${image} to ${drive.device}`);
|
||||
return self.writer.burn(image, drive).then(function() {
|
||||
$log.debug('Done!');
|
||||
}).catch(dialog.showError);
|
||||
|
@ -14,14 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module ResinEtcher.drive-scanner
|
||||
*/
|
||||
|
||||
var angular = require('angular');
|
||||
var _ = require('lodash');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var electron = require('electron');
|
||||
const angular = require('angular');
|
||||
const _ = require('lodash');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const electron = require('electron');
|
||||
|
||||
if (window.mocha) {
|
||||
var path = require('path');
|
||||
@ -33,12 +35,10 @@ if (window.mocha) {
|
||||
var dialog = electron.remote.require('./src/dialog');
|
||||
}
|
||||
|
||||
var driveScanner = angular.module('ResinEtcher.drive-scanner', []);
|
||||
const driveScanner = angular.module('ResinEtcher.drive-scanner', []);
|
||||
|
||||
driveScanner.service('DriveScannerRefreshService', function($interval, $timeout) {
|
||||
'use strict';
|
||||
|
||||
var interval = null;
|
||||
let interval = null;
|
||||
|
||||
/**
|
||||
* @summary Run a function every certain milliseconds
|
||||
@ -80,9 +80,7 @@ driveScanner.service('DriveScannerRefreshService', function($interval, $timeout)
|
||||
});
|
||||
|
||||
driveScanner.service('DriveScannerService', function($q, DriveScannerRefreshService) {
|
||||
'use strict';
|
||||
|
||||
var self = this;
|
||||
let self = this;
|
||||
|
||||
/**
|
||||
* @summary List of available drives
|
||||
@ -160,14 +158,14 @@ driveScanner.service('DriveScannerService', function($q, DriveScannerRefreshServ
|
||||
* @returns {EventEmitter} event emitter instance
|
||||
*
|
||||
* @example
|
||||
* var emitter = DriveScannerService.start(2000);
|
||||
* const emitter = DriveScannerService.start(2000);
|
||||
*
|
||||
* emitter.on('scan', function(drives) {
|
||||
* console.log(drives);
|
||||
* });
|
||||
*/
|
||||
this.start = function(ms) {
|
||||
var emitter = new EventEmitter();
|
||||
let emitter = new EventEmitter();
|
||||
|
||||
DriveScannerRefreshService.every(function() {
|
||||
return self.scan().then(function(drives) {
|
||||
|
@ -14,12 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module ResinEtcher.image-writer
|
||||
*/
|
||||
|
||||
var angular = require('angular');
|
||||
var electron = require('electron');
|
||||
const angular = require('angular');
|
||||
const electron = require('electron');
|
||||
|
||||
if (window.mocha) {
|
||||
var writer = electron.remote.require(require('path').join(__dirname, '..', '..', 'src', 'writer'));
|
||||
@ -27,13 +29,11 @@ if (window.mocha) {
|
||||
var writer = electron.remote.require('./src/writer');
|
||||
}
|
||||
|
||||
var imageWriter = angular.module('ResinEtcher.image-writer', []);
|
||||
const imageWriter = angular.module('ResinEtcher.image-writer', []);
|
||||
|
||||
imageWriter.service('ImageWriterService', function($q, $timeout, $log) {
|
||||
'use strict';
|
||||
|
||||
var self = this;
|
||||
var burning = false;
|
||||
let self = this;
|
||||
let burning = false;
|
||||
|
||||
/*
|
||||
* @summary Progress state
|
||||
@ -80,7 +80,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout, $log) {
|
||||
// Transform bytes to megabytes preserving only two decimal places
|
||||
self.state.speed = Math.floor(state.speed / 1e+6 * 100) / 100 || 0;
|
||||
|
||||
$log.debug('Progress: ' + self.state.progress + '% at ' + self.state.speed + ' MB/s');
|
||||
$log.debug(`Progress: ${self.state.progress}% at ${self.state.speed} MB/s`);
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -14,17 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module ResinEtcher.path
|
||||
*/
|
||||
|
||||
var angular = require('angular');
|
||||
var path = require('path');
|
||||
const angular = require('angular');
|
||||
const path = require('path');
|
||||
|
||||
var pathModule = angular.module('ResinEtcher.path', []);
|
||||
const pathModule = angular.module('ResinEtcher.path', []);
|
||||
|
||||
pathModule.filter('basename', function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @summary Get the basename of a path
|
||||
|
@ -14,25 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module ResinEtcher.selection-state
|
||||
*/
|
||||
|
||||
var _ = require('lodash');
|
||||
var angular = require('angular');
|
||||
var selectionState = angular.module('ResinEtcher.selection-state', []);
|
||||
const _ = require('lodash');
|
||||
const angular = require('angular');
|
||||
const selectionState = angular.module('ResinEtcher.selection-state', []);
|
||||
|
||||
selectionState.service('SelectionStateService', function() {
|
||||
'use strict';
|
||||
|
||||
var self = this;
|
||||
let self = this;
|
||||
|
||||
/**
|
||||
* @summary Selection state
|
||||
* @type Object
|
||||
* @private
|
||||
*/
|
||||
var selection = {};
|
||||
let selection = {};
|
||||
|
||||
/**
|
||||
* @summary Set a drive
|
||||
@ -72,7 +72,7 @@ selectionState.service('SelectionStateService', function() {
|
||||
* @returns {Object} drive
|
||||
*
|
||||
* @example
|
||||
* var drive = SelectionStateService.getDrive();
|
||||
* const drive = SelectionStateService.getDrive();
|
||||
*/
|
||||
this.getDrive = function() {
|
||||
return selection.drive;
|
||||
@ -86,7 +86,7 @@ selectionState.service('SelectionStateService', function() {
|
||||
* @returns {String} image
|
||||
*
|
||||
* @example
|
||||
* var image = SelectionStateService.getImage();
|
||||
* const image = SelectionStateService.getImage();
|
||||
*/
|
||||
this.getImage = function() {
|
||||
return selection.image;
|
||||
@ -132,9 +132,7 @@ selectionState.service('SelectionStateService', function() {
|
||||
* @example
|
||||
* SelectionStateService.removeDrive();
|
||||
*/
|
||||
this.removeDrive = function() {
|
||||
self.setDrive(undefined);
|
||||
};
|
||||
this.removeDrive = _.partial(self.setDrive, undefined);
|
||||
|
||||
/**
|
||||
* @summary Remove image
|
||||
@ -144,9 +142,7 @@ selectionState.service('SelectionStateService', function() {
|
||||
* @example
|
||||
* SelectionStateService.removeImage();
|
||||
*/
|
||||
this.removeImage = function() {
|
||||
self.setImage(undefined);
|
||||
};
|
||||
this.removeImage = _.partial(self.setImage, undefined);
|
||||
|
||||
/**
|
||||
* @summary Clear selections
|
||||
|
@ -19,6 +19,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
Polymer({ is: "hero-badge" });
|
||||
Polymer({ is: 'hero-badge' });
|
||||
</script>
|
||||
</dom-module>
|
||||
|
@ -40,7 +40,7 @@
|
||||
|
||||
<script>
|
||||
Polymer({
|
||||
is: "hero-button",
|
||||
is: 'hero-button',
|
||||
properties: {
|
||||
disabled: {
|
||||
type: String
|
||||
@ -51,7 +51,9 @@
|
||||
}
|
||||
},
|
||||
ready: function() {
|
||||
this.querySelector('.btn').className += ' btn-' + this.type;
|
||||
'use strict';
|
||||
|
||||
this.querySelector('.btn').className += ` btn-${this.type}`;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -15,6 +15,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
Polymer({ is: "hero-caption" });
|
||||
Polymer({ is: 'hero-caption' });
|
||||
</script>
|
||||
</dom-module>
|
||||
|
@ -20,11 +20,11 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
Polymer({
|
||||
is: "hero-icon",
|
||||
is: 'hero-icon',
|
||||
properties: {
|
||||
path: {
|
||||
type: String
|
||||
@ -40,9 +40,11 @@
|
||||
}
|
||||
},
|
||||
ready: function() {
|
||||
var iconElement = this.querySelector('.icon');
|
||||
var imagePath = path.join(__dirname, this.path);
|
||||
var contents = fs.readFileSync(imagePath, {
|
||||
'use strict';
|
||||
|
||||
const iconElement = this.querySelector('.icon');
|
||||
const imagePath = path.join(__dirname, this.path);
|
||||
const contents = fs.readFileSync(imagePath, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
<script>
|
||||
Polymer({
|
||||
is: "hero-progress-button",
|
||||
is: 'hero-progress-button',
|
||||
properties: {
|
||||
disabled: {
|
||||
type: String
|
||||
@ -49,10 +49,14 @@
|
||||
}
|
||||
},
|
||||
setProgress: function(percentage) {
|
||||
var bar = this.querySelector('.bar');
|
||||
'use strict';
|
||||
|
||||
let bar = this.querySelector('.bar');
|
||||
bar.style.width = percentage + '%';
|
||||
},
|
||||
ready: function() {
|
||||
'use strict';
|
||||
|
||||
this.setProgress(this.percentage);
|
||||
this.addEventListener('percentage-changed', function(event) {
|
||||
this.setProgress(event.detail.value);
|
||||
|
@ -24,21 +24,23 @@
|
||||
|
||||
<script>
|
||||
Polymer({
|
||||
is: "hero-tick",
|
||||
is: 'hero-tick',
|
||||
properties: {
|
||||
type: {
|
||||
type: String
|
||||
}
|
||||
},
|
||||
ready: function() {
|
||||
var glyphicon = this.querySelector('.glyphicon');
|
||||
'use strict';
|
||||
|
||||
let glyphicon = this.querySelector('.glyphicon');
|
||||
|
||||
if (this.type === 'success') {
|
||||
glyphicon.className += ' glyphicon-ok';
|
||||
} else if (this.type === 'error') {
|
||||
glyphicon.className += ' glyphicon-remove';
|
||||
} else {
|
||||
throw new Error('Unknown hero-tick type: ' + this.state);
|
||||
throw new Error(`Unknown hero-tick type: ${this.state}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -14,16 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var _ = require('lodash');
|
||||
var electron = require('electron');
|
||||
var isElevated = require('is-elevated');
|
||||
var sudoPrompt = require('sudo-prompt');
|
||||
var os = require('os');
|
||||
var platform = os.platform();
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const electron = require('electron');
|
||||
const isElevated = require('is-elevated');
|
||||
const sudoPrompt = require('sudo-prompt');
|
||||
const os = require('os');
|
||||
const platform = os.platform();
|
||||
|
||||
exports.require = function(app, callback) {
|
||||
'use strict';
|
||||
|
||||
isElevated(function(error, elevated) {
|
||||
if (error) {
|
||||
return callback(error);
|
||||
@ -52,7 +52,7 @@ exports.require = function(app, callback) {
|
||||
process.exit(0);
|
||||
});
|
||||
} else if (platform === 'win32') {
|
||||
var elevator = require('elevator');
|
||||
const elevator = require('elevator');
|
||||
|
||||
elevator.execute(process.argv, {}, function(error) {
|
||||
if (error) {
|
||||
|
@ -14,15 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var electron = require('electron');
|
||||
var path = require('path');
|
||||
var elevate = require('./elevate');
|
||||
var mainWindow = null;
|
||||
'use strict';
|
||||
|
||||
const electron = require('electron');
|
||||
const path = require('path');
|
||||
const elevate = require('./elevate');
|
||||
let mainWindow = null;
|
||||
|
||||
electron.app.on('window-all-closed', electron.app.quit);
|
||||
|
||||
electron.app.on('ready', function() {
|
||||
'use strict';
|
||||
|
||||
// No menu bar
|
||||
electron.Menu.setApplicationMenu(null);
|
||||
@ -49,7 +50,7 @@ electron.app.on('ready', function() {
|
||||
mainWindow.webContents.openDevTools();
|
||||
});
|
||||
|
||||
mainWindow.loadURL('file://' + path.join(__dirname, 'index.html'));
|
||||
mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var electron = require('electron');
|
||||
var Bluebird = require('bluebird');
|
||||
var _ = require('lodash');
|
||||
'use strict';
|
||||
|
||||
const electron = require('electron');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
/**
|
||||
* @summary Open an image selection dialog
|
||||
@ -35,8 +36,6 @@ var _ = require('lodash');
|
||||
* });
|
||||
*/
|
||||
exports.selectImage = function() {
|
||||
'use strict';
|
||||
|
||||
return new Bluebird(function(resolve) {
|
||||
electron.dialog.showOpenDialog({
|
||||
properties: [ 'openFile' ],
|
||||
@ -49,10 +48,8 @@ exports.selectImage = function() {
|
||||
]
|
||||
}
|
||||
]
|
||||
}, function(file) {
|
||||
return resolve(_.first(file));
|
||||
});
|
||||
});
|
||||
}, resolve);
|
||||
}).get(0);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -66,7 +63,5 @@ exports.selectImage = function() {
|
||||
* dialog.showError(new Error('Foo Bar'));
|
||||
*/
|
||||
exports.showError = function(error) {
|
||||
'use strict';
|
||||
|
||||
electron.dialog.showErrorBox(error.message, error.stack || '');
|
||||
};
|
||||
|
@ -14,8 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var Bluebird = require('bluebird');
|
||||
var drivelist = Bluebird.promisifyAll(require('drivelist'));
|
||||
'use strict';
|
||||
|
||||
const Bluebird = require('bluebird');
|
||||
const drivelist = Bluebird.promisifyAll(require('drivelist'));
|
||||
|
||||
/**
|
||||
* @summary List all available removable drives
|
||||
@ -33,8 +35,6 @@ var drivelist = Bluebird.promisifyAll(require('drivelist'));
|
||||
* });
|
||||
*/
|
||||
exports.listRemovable = function() {
|
||||
'use strict';
|
||||
|
||||
return drivelist.listAsync().then(function(drives) {
|
||||
return drives.filter(function(drive) {
|
||||
return !drive.system;
|
||||
|
@ -14,12 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var imageWrite = require('resin-image-write');
|
||||
var Bluebird = require('bluebird');
|
||||
var umount = Bluebird.promisifyAll(require('umount'));
|
||||
var fs = require('fs');
|
||||
var os = require('os');
|
||||
var isWindows = os.platform() === 'win32';
|
||||
'use strict';
|
||||
|
||||
const imageWrite = require('resin-image-write');
|
||||
const Bluebird = require('bluebird');
|
||||
const umount = Bluebird.promisifyAll(require('umount'));
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const isWindows = os.platform() === 'win32';
|
||||
|
||||
if (isWindows) {
|
||||
var removedrive = Bluebird.promisifyAll(require('removedrive'));
|
||||
@ -38,12 +40,10 @@ if (isWindows) {
|
||||
* @returns {ReadableStream} image stream
|
||||
*
|
||||
* @example
|
||||
* var stream = writer.getImageStream('foo/bar/baz.img');
|
||||
* const stream = writer.getImageStream('foo/bar/baz.img');
|
||||
*/
|
||||
exports.getImageStream = function(image) {
|
||||
'use strict';
|
||||
|
||||
var stream = fs.createReadStream(image);
|
||||
let stream = fs.createReadStream(image);
|
||||
stream.length = fs.statSync(image).size;
|
||||
return stream;
|
||||
};
|
||||
@ -73,10 +73,8 @@ exports.getImageStream = function(image) {
|
||||
* });
|
||||
*/
|
||||
exports.writeImage = function(image, drive, onProgress) {
|
||||
'use strict';
|
||||
|
||||
return umount.umountAsync(drive.device).then(function() {
|
||||
var stream = exports.getImageStream(image);
|
||||
let stream = exports.getImageStream(image);
|
||||
return imageWrite.write(drive.device, stream);
|
||||
}).then(function(writer) {
|
||||
return new Bluebird(function(resolve, reject) {
|
||||
|
@ -1,18 +1,19 @@
|
||||
var m = require('mochainon');
|
||||
var angular = require('angular');
|
||||
'use strict';
|
||||
|
||||
const m = require('mochainon');
|
||||
const angular = require('angular');
|
||||
require('angular-mocks');
|
||||
require('../../../lib/browser/modules/drive-scanner');
|
||||
|
||||
describe('Browser: DriveScanner', function() {
|
||||
'use strict';
|
||||
|
||||
beforeEach(angular.mock.module('ResinEtcher.drive-scanner'));
|
||||
|
||||
describe('DriveScannerRefreshService', function() {
|
||||
|
||||
var DriveScannerRefreshService;
|
||||
var $interval;
|
||||
var $timeout;
|
||||
let DriveScannerRefreshService;
|
||||
let $interval;
|
||||
let $timeout;
|
||||
|
||||
beforeEach(angular.mock.inject(function(_$interval_, _$timeout_, _DriveScannerRefreshService_) {
|
||||
$interval = _$interval_;
|
||||
@ -23,7 +24,7 @@ describe('Browser: DriveScanner', function() {
|
||||
describe('.every()', function() {
|
||||
|
||||
it('should call the function right away', function() {
|
||||
var spy = m.sinon.spy();
|
||||
const spy = m.sinon.spy();
|
||||
DriveScannerRefreshService.every(spy, 1000);
|
||||
$timeout.flush();
|
||||
DriveScannerRefreshService.stop();
|
||||
@ -31,7 +32,7 @@ describe('Browser: DriveScanner', function() {
|
||||
});
|
||||
|
||||
it('should call the function in an interval', function() {
|
||||
var spy = m.sinon.spy();
|
||||
const spy = m.sinon.spy();
|
||||
DriveScannerRefreshService.every(spy, 100);
|
||||
$timeout.flush();
|
||||
|
||||
@ -48,10 +49,10 @@ describe('Browser: DriveScanner', function() {
|
||||
|
||||
describe('DriveScannerService', function() {
|
||||
|
||||
var $interval;
|
||||
var $timeout;
|
||||
var $q;
|
||||
var DriveScannerService;
|
||||
let $interval;
|
||||
let $timeout;
|
||||
let $q;
|
||||
let DriveScannerService;
|
||||
|
||||
beforeEach(angular.mock.inject(function(_$interval_, _$timeout_, _$q_, _DriveScannerService_) {
|
||||
$interval = _$interval_;
|
||||
@ -69,7 +70,7 @@ describe('Browser: DriveScanner', function() {
|
||||
describe('.hasAvailableDrives()', function() {
|
||||
|
||||
it('should return false', function() {
|
||||
var hasDrives = DriveScannerService.hasAvailableDrives();
|
||||
const hasDrives = DriveScannerService.hasAvailableDrives();
|
||||
m.chai.expect(hasDrives).to.be.false;
|
||||
});
|
||||
|
||||
@ -78,7 +79,7 @@ describe('Browser: DriveScanner', function() {
|
||||
describe('.setDrives()', function() {
|
||||
|
||||
it('should be able to set drives', function() {
|
||||
var drives = [
|
||||
const drives = [
|
||||
{
|
||||
device: '/dev/sdb',
|
||||
description: 'Foo',
|
||||
@ -122,7 +123,7 @@ describe('Browser: DriveScanner', function() {
|
||||
describe('.hasAvailableDrives()', function() {
|
||||
|
||||
it('should return true', function() {
|
||||
var hasDrives = DriveScannerService.hasAvailableDrives();
|
||||
const hasDrives = DriveScannerService.hasAvailableDrives();
|
||||
m.chai.expect(hasDrives).to.be.true;
|
||||
});
|
||||
|
||||
@ -184,8 +185,8 @@ describe('Browser: DriveScanner', function() {
|
||||
describe('.start()', function() {
|
||||
|
||||
it('should emit a `scan` event with the drives', function() {
|
||||
var emitter = DriveScannerService.start(2000);
|
||||
var scanSpy = m.sinon.spy();
|
||||
const emitter = DriveScannerService.start(2000);
|
||||
const scanSpy = m.sinon.spy();
|
||||
emitter.on('scan', scanSpy);
|
||||
$timeout.flush();
|
||||
$interval.flush(1000);
|
||||
|
@ -1,19 +1,20 @@
|
||||
var m = require('mochainon');
|
||||
var angular = require('angular');
|
||||
'use strict';
|
||||
|
||||
const m = require('mochainon');
|
||||
const angular = require('angular');
|
||||
require('angular-mocks');
|
||||
require('../../../lib/browser/modules/image-writer');
|
||||
|
||||
describe('Browser: ImageWriter', function() {
|
||||
'use strict';
|
||||
|
||||
beforeEach(angular.mock.module('ResinEtcher.image-writer'));
|
||||
|
||||
describe('ImageWriterService', function() {
|
||||
|
||||
var $q;
|
||||
var $timeout;
|
||||
var $rootScope;
|
||||
var ImageWriterService;
|
||||
let $q;
|
||||
let $timeout;
|
||||
let $rootScope;
|
||||
let ImageWriterService;
|
||||
|
||||
beforeEach(angular.mock.inject(function(_$q_, _$timeout_, _$rootScope_, _ImageWriterService_) {
|
||||
$q = _$q_;
|
||||
@ -174,7 +175,7 @@ describe('Browser: ImageWriter', function() {
|
||||
});
|
||||
|
||||
it('should be rejected with the error', function() {
|
||||
var rejection;
|
||||
let rejection;
|
||||
ImageWriterService.burn('foo.img', '/dev/disk2').catch(function(error) {
|
||||
rejection = error;
|
||||
});
|
||||
|
@ -1,25 +1,26 @@
|
||||
var m = require('mochainon');
|
||||
var angular = require('angular');
|
||||
var os = require('os');
|
||||
'use strict';
|
||||
|
||||
const m = require('mochainon');
|
||||
const angular = require('angular');
|
||||
const os = require('os');
|
||||
require('angular-mocks');
|
||||
require('../../../lib/browser/modules/path');
|
||||
|
||||
describe('Browser: Path', function() {
|
||||
'use strict';
|
||||
|
||||
beforeEach(angular.mock.module('ResinEtcher.path'));
|
||||
|
||||
describe('BasenameFilter', function() {
|
||||
|
||||
var basenameFilter;
|
||||
let basenameFilter;
|
||||
|
||||
beforeEach(angular.mock.inject(function(_basenameFilter_) {
|
||||
basenameFilter = _basenameFilter_;
|
||||
}));
|
||||
|
||||
it('should return the basename', function() {
|
||||
var isWindows = os.platform() === 'win32';
|
||||
var basename;
|
||||
const isWindows = os.platform() === 'win32';
|
||||
let basename;
|
||||
|
||||
if (isWindows) {
|
||||
basename = basenameFilter('C:\\Users\\jviotti\\foo.img');
|
||||
|
@ -1,16 +1,17 @@
|
||||
var m = require('mochainon');
|
||||
var angular = require('angular');
|
||||
'use strict';
|
||||
|
||||
const m = require('mochainon');
|
||||
const angular = require('angular');
|
||||
require('angular-mocks');
|
||||
require('../../../lib/browser/modules/selection-state');
|
||||
|
||||
describe('Browser: SelectionState', function() {
|
||||
'use strict';
|
||||
|
||||
beforeEach(angular.mock.module('ResinEtcher.selection-state'));
|
||||
|
||||
describe('SelectionStateService', function() {
|
||||
|
||||
var SelectionStateService;
|
||||
let SelectionStateService;
|
||||
|
||||
beforeEach(angular.mock.inject(function(_SelectionStateService_) {
|
||||
SelectionStateService = _SelectionStateService_;
|
||||
@ -23,22 +24,22 @@ describe('Browser: SelectionState', function() {
|
||||
});
|
||||
|
||||
it('getDrive() should return undefined', function() {
|
||||
var drive = SelectionStateService.getDrive();
|
||||
const drive = SelectionStateService.getDrive();
|
||||
m.chai.expect(drive).to.be.undefined;
|
||||
});
|
||||
|
||||
it('getImage() should return undefined', function() {
|
||||
var image = SelectionStateService.getImage();
|
||||
const image = SelectionStateService.getImage();
|
||||
m.chai.expect(image).to.be.undefined;
|
||||
});
|
||||
|
||||
it('hasDrive() should return false', function() {
|
||||
var hasDrive = SelectionStateService.hasDrive();
|
||||
const hasDrive = SelectionStateService.hasDrive();
|
||||
m.chai.expect(hasDrive).to.be.false;
|
||||
});
|
||||
|
||||
it('hasImage() should return false', function() {
|
||||
var hasImage = SelectionStateService.hasImage();
|
||||
const hasImage = SelectionStateService.hasImage();
|
||||
m.chai.expect(hasImage).to.be.false;
|
||||
});
|
||||
|
||||
@ -53,7 +54,7 @@ describe('Browser: SelectionState', function() {
|
||||
describe('.getDrive()', function() {
|
||||
|
||||
it('should return the drive', function() {
|
||||
var drive = SelectionStateService.getDrive();
|
||||
const drive = SelectionStateService.getDrive();
|
||||
m.chai.expect(drive).to.equal('/dev/disk2');
|
||||
});
|
||||
|
||||
@ -62,7 +63,7 @@ describe('Browser: SelectionState', function() {
|
||||
describe('.hasDrive()', function() {
|
||||
|
||||
it('should return true', function() {
|
||||
var hasDrive = SelectionStateService.hasDrive();
|
||||
const hasDrive = SelectionStateService.hasDrive();
|
||||
m.chai.expect(hasDrive).to.be.true;
|
||||
});
|
||||
|
||||
@ -72,7 +73,7 @@ describe('Browser: SelectionState', function() {
|
||||
|
||||
it('should override the drive', function() {
|
||||
SelectionStateService.setDrive('/dev/disk5');
|
||||
var drive = SelectionStateService.getDrive();
|
||||
const drive = SelectionStateService.getDrive();
|
||||
m.chai.expect(drive).to.equal('/dev/disk5');
|
||||
});
|
||||
|
||||
@ -82,7 +83,7 @@ describe('Browser: SelectionState', function() {
|
||||
|
||||
it('should clear the drive', function() {
|
||||
SelectionStateService.removeDrive();
|
||||
var drive = SelectionStateService.getDrive();
|
||||
const drive = SelectionStateService.getDrive();
|
||||
m.chai.expect(drive).to.be.undefined;
|
||||
});
|
||||
|
||||
@ -96,7 +97,7 @@ describe('Browser: SelectionState', function() {
|
||||
|
||||
it('should be able to set a drive', function() {
|
||||
SelectionStateService.setDrive('/dev/disk5');
|
||||
var drive = SelectionStateService.getDrive();
|
||||
const drive = SelectionStateService.getDrive();
|
||||
m.chai.expect(drive).to.equal('/dev/disk5');
|
||||
});
|
||||
|
||||
@ -113,7 +114,7 @@ describe('Browser: SelectionState', function() {
|
||||
describe('.getImage()', function() {
|
||||
|
||||
it('should return the image', function() {
|
||||
var image = SelectionStateService.getImage();
|
||||
const image = SelectionStateService.getImage();
|
||||
m.chai.expect(image).to.equal('foo.img');
|
||||
});
|
||||
|
||||
@ -122,7 +123,7 @@ describe('Browser: SelectionState', function() {
|
||||
describe('.hasImage()', function() {
|
||||
|
||||
it('should return true', function() {
|
||||
var hasImage = SelectionStateService.hasImage();
|
||||
const hasImage = SelectionStateService.hasImage();
|
||||
m.chai.expect(hasImage).to.be.true;
|
||||
});
|
||||
|
||||
@ -132,7 +133,7 @@ describe('Browser: SelectionState', function() {
|
||||
|
||||
it('should override the image', function() {
|
||||
SelectionStateService.setImage('bar.img');
|
||||
var image = SelectionStateService.getImage();
|
||||
const image = SelectionStateService.getImage();
|
||||
m.chai.expect(image).to.equal('bar.img');
|
||||
});
|
||||
|
||||
@ -142,7 +143,7 @@ describe('Browser: SelectionState', function() {
|
||||
|
||||
it('should clear the image', function() {
|
||||
SelectionStateService.removeImage();
|
||||
var image = SelectionStateService.getImage();
|
||||
const image = SelectionStateService.getImage();
|
||||
m.chai.expect(image).to.be.undefined;
|
||||
});
|
||||
|
||||
@ -156,7 +157,7 @@ describe('Browser: SelectionState', function() {
|
||||
|
||||
it('should be able to set an image', function() {
|
||||
SelectionStateService.setImage('foo.img');
|
||||
var image = SelectionStateService.getImage();
|
||||
const image = SelectionStateService.getImage();
|
||||
m.chai.expect(image).to.equal('foo.img');
|
||||
});
|
||||
|
||||
@ -194,22 +195,22 @@ describe('Browser: SelectionState', function() {
|
||||
});
|
||||
|
||||
it('getDrive() should return undefined', function() {
|
||||
var drive = SelectionStateService.getDrive();
|
||||
const drive = SelectionStateService.getDrive();
|
||||
m.chai.expect(drive).to.be.undefined;
|
||||
});
|
||||
|
||||
it('getImage() should return the image', function() {
|
||||
var image = SelectionStateService.getImage();
|
||||
const image = SelectionStateService.getImage();
|
||||
m.chai.expect(image).to.equal('foo.img');
|
||||
});
|
||||
|
||||
it('hasDrive() should return false', function() {
|
||||
var hasDrive = SelectionStateService.hasDrive();
|
||||
const hasDrive = SelectionStateService.hasDrive();
|
||||
m.chai.expect(hasDrive).to.be.false;
|
||||
});
|
||||
|
||||
it('hasImage() should return true', function() {
|
||||
var hasImage = SelectionStateService.hasImage();
|
||||
const hasImage = SelectionStateService.hasImage();
|
||||
m.chai.expect(hasImage).to.be.true;
|
||||
});
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
var m = require('mochainon');
|
||||
var electron = require('electron');
|
||||
var dialog = require('../../lib/src/dialog');
|
||||
'use strict';
|
||||
|
||||
const m = require('mochainon');
|
||||
const electron = require('electron');
|
||||
const dialog = require('../../lib/src/dialog');
|
||||
|
||||
describe('Dialog:', function() {
|
||||
'use strict';
|
||||
|
||||
describe('.selectImage()', function() {
|
||||
|
||||
@ -19,7 +20,7 @@ describe('Dialog:', function() {
|
||||
});
|
||||
|
||||
it('should eventually equal the file', function() {
|
||||
var promise = dialog.selectImage();
|
||||
const promise = dialog.selectImage();
|
||||
m.chai.expect(promise).to.eventually.equal('foo/bar');
|
||||
});
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
var m = require('mochainon');
|
||||
var Bluebird = require('bluebird');
|
||||
var drivelist = require('drivelist');
|
||||
var drives = require('../../lib/src/drives');
|
||||
'use strict';
|
||||
|
||||
const m = require('mochainon');
|
||||
const Bluebird = require('bluebird');
|
||||
const drivelist = require('drivelist');
|
||||
const drives = require('../../lib/src/drives');
|
||||
|
||||
describe('Drives:', function() {
|
||||
'use strict';
|
||||
|
||||
describe('.listRemovable()', function() {
|
||||
|
||||
@ -20,7 +21,7 @@ describe('Drives:', function() {
|
||||
});
|
||||
|
||||
it('should eventually equal an empty array', function() {
|
||||
var promise = drives.listRemovable();
|
||||
const promise = drives.listRemovable();
|
||||
m.chai.expect(promise).to.eventually.become([]);
|
||||
});
|
||||
|
||||
@ -48,7 +49,7 @@ describe('Drives:', function() {
|
||||
});
|
||||
|
||||
it('should eventually equal an empty array', function() {
|
||||
var promise = drives.listRemovable();
|
||||
const promise = drives.listRemovable();
|
||||
m.chai.expect(promise).to.eventually.become([]);
|
||||
});
|
||||
|
||||
@ -90,7 +91,7 @@ describe('Drives:', function() {
|
||||
});
|
||||
|
||||
it('should eventually become the removable drives', function() {
|
||||
var promise = drives.listRemovable();
|
||||
const promise = drives.listRemovable();
|
||||
m.chai.expect(promise).to.eventually.become([
|
||||
{
|
||||
device: '/dev/sdb',
|
||||
@ -123,7 +124,7 @@ describe('Drives:', function() {
|
||||
});
|
||||
|
||||
it('should be rejected with the error', function() {
|
||||
var promise = drives.listRemovable();
|
||||
const promise = drives.listRemovable();
|
||||
m.chai.expect(promise).to.be.rejectedWith('scan error');
|
||||
});
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
var m = require('mochainon');
|
||||
var ReadableStream = require('stream').Readable;
|
||||
var path = require('path');
|
||||
var umount = require('umount');
|
||||
var writer = require('../../lib/src/writer');
|
||||
'use strict';
|
||||
|
||||
const m = require('mochainon');
|
||||
const ReadableStream = require('stream').Readable;
|
||||
const path = require('path');
|
||||
const umount = require('umount');
|
||||
const writer = require('../../lib/src/writer');
|
||||
|
||||
describe('Writer:', function() {
|
||||
'use strict';
|
||||
|
||||
describe('.getImageStream()', function() {
|
||||
|
||||
@ -16,12 +17,12 @@ describe('Writer:', function() {
|
||||
});
|
||||
|
||||
it('should return a readable stream', function() {
|
||||
var stream = writer.getImageStream(this.image);
|
||||
const stream = writer.getImageStream(this.image);
|
||||
m.chai.expect(stream).to.be.an.instanceof(ReadableStream);
|
||||
});
|
||||
|
||||
it('should append a .length property with the correct size', function() {
|
||||
var stream = writer.getImageStream(this.image);
|
||||
const stream = writer.getImageStream(this.image);
|
||||
m.chai.expect(stream.length).to.equal(2097152);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user