mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-02 17:20:52 +00:00
Mock local Raspberry Pi bundle
This commit is contained in:
parent
af6e9ef85d
commit
4a7d3d5945
@ -1,10 +1,8 @@
|
||||
(function() {
|
||||
var _, async, commandOptions, diskio, elevate, fs, mkdirp, npm, os, packageJSON, path, progressStream, resin, updateActions, visuals;
|
||||
var _, async, commandOptions, elevate, mkdirp, npm, os, packageJSON, path, resin, updateActions, visuals;
|
||||
|
||||
_ = require('lodash-contrib');
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
os = require('os');
|
||||
|
||||
async = require('async');
|
||||
@ -17,10 +15,6 @@
|
||||
|
||||
visuals = require('resin-cli-visuals');
|
||||
|
||||
progressStream = require('progress-stream');
|
||||
|
||||
diskio = require('diskio');
|
||||
|
||||
commandOptions = require('./command-options');
|
||||
|
||||
npm = require('../npm');
|
||||
@ -102,6 +96,8 @@
|
||||
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);
|
||||
@ -130,27 +126,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, error, imageFileSize, imageFileStream, progress;
|
||||
var bar;
|
||||
if (!confirmed) {
|
||||
return done();
|
||||
}
|
||||
imageFileSize = fs.statSync(params.image).size;
|
||||
if (imageFileSize === 0) {
|
||||
error = new Error("Invalid OS image: " + params.image + ". The image is 0 bytes.");
|
||||
return callback(error);
|
||||
}
|
||||
progress = progressStream({
|
||||
length: imageFileSize,
|
||||
time: 500
|
||||
});
|
||||
if (!options.quiet) {
|
||||
bar = new visuals.widgets.Progress('Writing Device OS');
|
||||
progress.on('progress', function(status) {
|
||||
return bar.update(status);
|
||||
});
|
||||
}
|
||||
imageFileStream = fs.createReadStream(params.image).pipe(progress);
|
||||
return diskio.writeStream(params.device, imageFileStream, callback);
|
||||
bar = new visuals.widgets.Progress('Writing Device OS');
|
||||
params.progress = bar.update;
|
||||
return bundle.write(params, callback);
|
||||
}
|
||||
], function(error) {
|
||||
var resinWritePath;
|
||||
|
30
build/devices/raspberry-pi.js
Normal file
30
build/devices/raspberry-pi.js
Normal file
@ -0,0 +1,30 @@
|
||||
(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);
|
@ -1,13 +1,10 @@
|
||||
_ = require('lodash-contrib')
|
||||
fs = require('fs')
|
||||
os = require('os')
|
||||
async = require('async')
|
||||
path = require('path')
|
||||
mkdirp = require('mkdirp')
|
||||
resin = require('resin-sdk')
|
||||
visuals = require('resin-cli-visuals')
|
||||
progressStream = require('progress-stream')
|
||||
diskio = require('diskio')
|
||||
commandOptions = require('./command-options')
|
||||
npm = require('../npm')
|
||||
packageJSON = require('../../package.json')
|
||||
@ -127,6 +124,9 @@ exports.install =
|
||||
options: [ commandOptions.yes ]
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
|
||||
bundle = require('../devices/raspberry-pi')
|
||||
|
||||
async.waterfall [
|
||||
|
||||
(callback) ->
|
||||
@ -166,25 +166,9 @@ exports.install =
|
||||
(confirmed, callback) ->
|
||||
return done() if not confirmed
|
||||
|
||||
imageFileSize = fs.statSync(params.image).size
|
||||
|
||||
if imageFileSize is 0
|
||||
error = new Error("Invalid OS image: #{params.image}. The image is 0 bytes.")
|
||||
return callback(error)
|
||||
|
||||
progress = progressStream
|
||||
length: imageFileSize
|
||||
time: 500
|
||||
|
||||
if not options.quiet
|
||||
bar = new visuals.widgets.Progress('Writing Device OS')
|
||||
|
||||
progress.on 'progress', (status) ->
|
||||
bar.update(status)
|
||||
|
||||
imageFileStream = fs.createReadStream(params.image).pipe(progress)
|
||||
|
||||
diskio.writeStream(params.device, imageFileStream, callback)
|
||||
bar = new visuals.widgets.Progress('Writing Device OS')
|
||||
params.progress = bar.update
|
||||
bundle.write(params, callback)
|
||||
|
||||
], (error) ->
|
||||
return done() if not error?
|
||||
|
22
lib/devices/raspberry-pi.coffee
Normal file
22
lib/devices/raspberry-pi.coffee
Normal file
@ -0,0 +1,22 @@
|
||||
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)
|
Loading…
x
Reference in New Issue
Block a user