From 656f3e5cd98b45a4b7fb67fc9d832d9d3a4f6ea3 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 6 May 2015 11:58:06 -0300 Subject: [PATCH] Make use of resin-image to remove image writing logic from the CLI --- build/actions/os.js | 14 +++++--------- build/devices/raspberry-pi.js | 30 ------------------------------ lib/actions/os.coffee | 9 ++------- lib/devices/raspberry-pi.coffee | 22 ---------------------- package.json | 4 +--- 5 files changed, 8 insertions(+), 71 deletions(-) delete mode 100644 build/devices/raspberry-pi.js delete mode 100644 lib/devices/raspberry-pi.coffee diff --git a/build/actions/os.js b/build/actions/os.js index a788d035..fc5dea36 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -1,5 +1,5 @@ (function() { - var _, async, capitano, commandOptions, elevate, mkdirp, npm, os, packageJSON, path, resin, umount, visuals; + var _, async, capitano, commandOptions, elevate, image, mkdirp, npm, os, packageJSON, path, resin, visuals; capitano = require('capitano'); @@ -15,9 +15,9 @@ resin = require('resin-sdk'); - visuals = require('resin-cli-visuals'); + image = require('resin-image'); - umount = require('umount').umount; + visuals = require('resin-cli-visuals'); commandOptions = require('./command-options'); @@ -103,8 +103,6 @@ options: [commandOptions.yes], permission: 'user', action: function(params, options, done) { - var bundle; - bundle = require('../devices/raspberry-pi'); return async.waterfall([ function(callback) { return npm.isUpdated(packageJSON.name, packageJSON.version, callback); @@ -133,15 +131,13 @@ message = "This will completely erase " + params.device + ". Are you sure you want to continue?"; return visuals.patterns.confirm(options.yes, message, callback); }, function(confirmed, callback) { + var bar; if (!confirmed) { return done(); } - return umount(params.device, _.unary(callback)); - }, function(callback) { - var bar; bar = new visuals.widgets.Progress('Writing Device OS'); params.progress = _.bind(bar.update, bar); - return bundle.write(params, callback); + return image.write(params, callback); } ], function(error) { var resinWritePath; diff --git a/build/devices/raspberry-pi.js b/build/devices/raspberry-pi.js deleted file mode 100644 index 0a4eed7a..00000000 --- a/build/devices/raspberry-pi.js +++ /dev/null @@ -1,30 +0,0 @@ -(function() { - var diskio, fs, progressStream; - - fs = require('fs'); - - progressStream = require('progress-stream'); - - diskio = require('diskio'); - - exports.name = 'Raspberry Pi'; - - exports.write = function(options, callback) { - var error, imageFileSize, imageFileStream, progress; - imageFileSize = fs.statSync(options.image).size; - if (imageFileSize === 0) { - error = new Error("Invalid OS image: " + options.image + ". The image is 0 bytes."); - return callback(error); - } - progress = progressStream({ - length: imageFileSize, - time: 500 - }); - if (!options.quiet) { - progress.on('progress', options.progress); - } - imageFileStream = fs.createReadStream(options.image).pipe(progress); - return diskio.writeStream(options.device, imageFileStream, callback); - }; - -}).call(this); diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index af7dbe80..f7eac9f8 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -5,8 +5,8 @@ async = require('async') path = require('path') mkdirp = require('mkdirp') resin = require('resin-sdk') +image = require('resin-image') visuals = require('resin-cli-visuals') -umount = require('umount').umount commandOptions = require('./command-options') npm = require('../npm') packageJSON = require('../../package.json') @@ -117,8 +117,6 @@ exports.install = permission: 'user' action: (params, options, done) -> - bundle = require('../devices/raspberry-pi') - async.waterfall [ (callback) -> @@ -157,12 +155,9 @@ exports.install = (confirmed, callback) -> return done() if not confirmed - umount(params.device, _.unary(callback)) - - (callback) -> bar = new visuals.widgets.Progress('Writing Device OS') params.progress = _.bind(bar.update, bar) - bundle.write(params, callback) + image.write(params, callback) ], (error) -> return done() if not error? diff --git a/lib/devices/raspberry-pi.coffee b/lib/devices/raspberry-pi.coffee deleted file mode 100644 index 7778be7a..00000000 --- a/lib/devices/raspberry-pi.coffee +++ /dev/null @@ -1,22 +0,0 @@ -fs = require('fs') -progressStream = require('progress-stream') -diskio = require('diskio') - -exports.name = 'Raspberry Pi' - -exports.write = (options, callback) -> - imageFileSize = fs.statSync(options.image).size - - if imageFileSize is 0 - error = new Error("Invalid OS image: #{options.image}. The image is 0 bytes.") - return callback(error) - - progress = progressStream - length: imageFileSize - time: 500 - - if not options.quiet - progress.on('progress', options.progress) - - imageFileStream = fs.createReadStream(options.image).pipe(progress) - diskio.writeStream(options.device, imageFileStream, callback) diff --git a/package.json b/package.json index ce6d5e4f..8eb02397 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "capitano": "~1.5.0", "coffee-script": "~1.8.0", "conf.js": "^0.1.1", - "diskio": "^1.0.0", "drivelist": "^1.2.1", "lodash": "~2.4.1", "lodash-contrib": "~241.4.14", @@ -61,13 +60,12 @@ "npm": "^2.6.1", "open": "0.0.5", "president": "^1.0.0", - "progress-stream": "^0.5.0", "resin-cli-visuals": "^0.1.0", "resin-sdk": "^1.4.1", + "resin-image": "^1.1.1", "resin-settings-client": "^1.0.0", "resin-vcs": "^1.2.0", "tmp": "^0.0.25", - "umount": "^1.0.0", "underscore.string": "~2.4.0", "update-notifier": "^0.3.1" }