diff --git a/.travis.yml b/.travis.yml index f1da9798..df59a8c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: cpp sudo: false env: - - NODE_VERSION="4" + - NODE_VERSION="5" os: - linux - osx diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 269f625e..88db8553 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,9 @@ Thanks for your interest in contributing to this project! This document aims to ## Running locally -You can manually run the application with the following steps: +- Install [NodeJS v5.10.0](https://nodejs.org/en/). + +Sadly we need to enforce the same NodeJS version that the Electron version we use is running to avoid module version mismatches when building native dependencies (`electron-rebuild` doesn't seem to be enough). - Clone the repository. diff --git a/appveyor.yml b/appveyor.yml index 88edd18c..26ab29cd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,13 +11,13 @@ cache: # what combinations to test environment: matrix: - - nodejs_version: 4 + - nodejs_version: 5 install: - ps: Install-Product node $env:nodejs_version x64 - npm -g install npm@2 - set PATH=%APPDATA%\npm;%PATH% - - npm install + - npm install --build-from-source build: off diff --git a/lib/gui/partials/main.html b/lib/gui/partials/main.html index d174b82b..ed35e614 100644 --- a/lib/gui/partials/main.html +++ b/lib/gui/partials/main.html @@ -8,7 +8,7 @@
- +
diff --git a/lib/src/writer.js b/lib/src/writer.js index e8533c59..bbfd5293 100644 --- a/lib/src/writer.js +++ b/lib/src/writer.js @@ -17,10 +17,9 @@ 'use strict'; const imageWrite = require('etcher-image-write'); -const zipImage = require('resin-zip-image'); +const imageStream = require('etcher-image-stream'); const Bluebird = require('bluebird'); const umount = Bluebird.promisifyAll(require('umount')); -const fs = require('fs'); const os = require('os'); const isWindows = os.platform() === 'win32'; @@ -28,35 +27,6 @@ if (isWindows) { var removedrive = Bluebird.promisifyAll(require('removedrive')); } -/** - * @summary Get image readable stream - * @function - * @private - * - * @description - * This function adds a custom `.length` property - * to the stream which equals the image size in bytes. - * - * @param {String} image - path to image - * @returns {ReadableStream} image stream - * - * @example - * const stream = writer.getImageStream('foo/bar/baz.img'); - */ -exports.getImageStream = function(image) { - if (zipImage.isZip(image)) { - if (!zipImage.isValidZipImage(image)) { - return Bluebird.reject(new Error('Invalid zip image')); - } - - return zipImage.extractImage(image); - } - - let stream = fs.createReadStream(image); - stream.length = fs.statSync(image).size; - return Bluebird.resolve(stream); -}; - /** * @summary Write an image to a disk drive * @function @@ -66,7 +36,7 @@ exports.getImageStream = function(image) { * See https://github.com/resin-io-modules/etcher-image-write for information * about the `state` object passed to `onProgress` callback. * - * @param {String} image - path to image + * @param {String} imagePath - path to image * @param {Object} drive - drive * @param {Object} options - options * @param {Boolean} [options.unmountOnSuccess=false] - unmount on success @@ -88,13 +58,14 @@ exports.getImageStream = function(image) { * console.log('Done!'); * }); */ -exports.writeImage = function(image, drive, options, onProgress) { +exports.writeImage = function(imagePath, drive, options, onProgress) { return umount.umountAsync(drive.device).then(function() { - return exports.getImageStream(image); - }).then(function(stream) { - return imageWrite.write(drive.device, stream, { + return imageStream.getFromFilePath(imagePath); + }).then(function(image) { + return imageWrite.write(drive.device, image.stream, { check: options.validateWriteOnSuccess, - size: stream.length + size: image.size, + transform: image.transform }); }).then(function(writer) { return new Bluebird(function(resolve, reject) { diff --git a/package.json b/package.json index b5421faf..df5b8f05 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,7 @@ "url": "git@github.com:resin-io/etcher.git" }, "scripts": { - "test:main": "electron-mocha --recursive tests/src -R progress", - "test:gui": "electron-mocha --recursive --renderer tests/gui -R progress", - "test": "npm run-script test:main && npm run-script test:gui", + "test": "electron-mocha --recursive --renderer tests/gui -R progress", "start": "electron lib/start.js" }, "author": "Juan Cruz Viotti ", @@ -65,7 +63,6 @@ "resin-cli-errors": "^1.2.0", "resin-cli-form": "^1.4.1", "resin-cli-visuals": "^1.2.8", - "resin-zip-image": "^1.1.2", "sudo-prompt": "^3.1.0", "trackjs": "^2.1.16", "umount": "^1.1.3", @@ -85,8 +82,6 @@ "gulp-sass": "^2.0.4", "jshint": "^2.9.1", "jshint-stylish": "^2.0.1", - "mochainon": "^1.0.0", - "rindle": "^1.3.0", - "tmp": "0.0.28" + "mochainon": "^1.0.0" } } diff --git a/tests/src/writer.spec.js b/tests/src/writer.spec.js deleted file mode 100644 index 482bc382..00000000 --- a/tests/src/writer.spec.js +++ /dev/null @@ -1,89 +0,0 @@ -'use strict'; - -const m = require('mochainon'); -const ReadableStream = require('stream').Readable; -const Bluebird = require('bluebird'); -const fs = Bluebird.promisifyAll(require('fs')); -const path = require('path'); -const tmp = require('tmp'); -const rindle = require('rindle'); -const writer = require('../../lib/src/writer'); - -describe('Writer:', function() { - - describe('.getImageStream()', function() { - - describe('given a valid image file', function() { - - beforeEach(function() { - this.image = path.join(__dirname, '..', 'utils', 'data.random'); - }); - - it('should return a readable stream', function(done) { - writer.getImageStream(this.image).then(function(stream) { - m.chai.expect(stream).to.be.an.instanceof(ReadableStream); - }).nodeify(done); - }); - - it('should append a .length property with the correct size', function(done) { - writer.getImageStream(this.image).then(function(stream) { - m.chai.expect(stream.length).to.equal(2097152); - }).nodeify(done); - }); - - }); - - describe('given a valid image zip', function() { - - beforeEach(function() { - this.image = path.join(__dirname, '..', 'utils', 'data.zip'); - }); - - it('should return a readable stream', function(done) { - writer.getImageStream(this.image).then(function(stream) { - m.chai.expect(stream).to.be.an.instanceof(ReadableStream); - }).nodeify(done); - }); - - it('should append a .length property with the correct size', function(done) { - writer.getImageStream(this.image).then(function(stream) { - m.chai.expect(stream.length).to.equal(2097152); - }).nodeify(done); - }); - - it('should pipe the image from the zip', function(done) { - const tmpFile = tmp.tmpNameSync(); - const image = path.join(__dirname, '..', 'utils', 'data.random'); - const output = fs.createWriteStream(tmpFile); - - writer.getImageStream(this.image).then(function(stream) { - return stream.pipe(output); - }).then(rindle.wait).then(function() { - return Bluebird.props({ - output: fs.readFileAsync(tmpFile), - data: fs.readFileAsync(image) - }); - }).then(function(results) { - m.chai.expect(results.output).to.deep.equal(results.data); - return fs.unlinkAsync(tmpFile); - }).nodeify(done); - }); - - }); - - describe('given an invalid image zip', function() { - - beforeEach(function() { - this.image = path.join(__dirname, '..', 'utils', 'invalid.zip'); - }); - - it('should be rejected with an error', function() { - const promise = writer.getImageStream(this.image); - m.chai.expect(promise).to.be.rejectedWith('Invalid zip image'); - }); - - }); - - }); - -}); diff --git a/tests/utils/data.random b/tests/utils/data.random deleted file mode 100644 index ebd106c6..00000000 Binary files a/tests/utils/data.random and /dev/null differ diff --git a/tests/utils/data.zip b/tests/utils/data.zip deleted file mode 100644 index 617a734d..00000000 Binary files a/tests/utils/data.zip and /dev/null differ diff --git a/tests/utils/invalid.zip b/tests/utils/invalid.zip deleted file mode 100644 index 3e4181c9..00000000 Binary files a/tests/utils/invalid.zip and /dev/null differ