mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-23 15:32:22 +00:00
Merge pull request #42 from resin-io/feature/use-resin-image
Make use of resin-image to remove image writing logic from the CLI
This commit is contained in:
commit
2019f9fdeb
@ -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;
|
||||
|
@ -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);
|
@ -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?
|
||||
|
@ -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)
|
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user