mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-09 04:12:51 +00:00
Mock local Raspberry Pi bundle
This commit is contained in:
parent
af6e9ef85d
commit
4a7d3d5945
@ -1,10 +1,8 @@
|
|||||||
(function() {
|
(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');
|
_ = require('lodash-contrib');
|
||||||
|
|
||||||
fs = require('fs');
|
|
||||||
|
|
||||||
os = require('os');
|
os = require('os');
|
||||||
|
|
||||||
async = require('async');
|
async = require('async');
|
||||||
@ -17,10 +15,6 @@
|
|||||||
|
|
||||||
visuals = require('resin-cli-visuals');
|
visuals = require('resin-cli-visuals');
|
||||||
|
|
||||||
progressStream = require('progress-stream');
|
|
||||||
|
|
||||||
diskio = require('diskio');
|
|
||||||
|
|
||||||
commandOptions = require('./command-options');
|
commandOptions = require('./command-options');
|
||||||
|
|
||||||
npm = require('../npm');
|
npm = require('../npm');
|
||||||
@ -102,6 +96,8 @@
|
|||||||
options: [commandOptions.yes],
|
options: [commandOptions.yes],
|
||||||
permission: 'user',
|
permission: 'user',
|
||||||
action: function(params, options, done) {
|
action: function(params, options, done) {
|
||||||
|
var bundle;
|
||||||
|
bundle = require('../devices/raspberry-pi');
|
||||||
return async.waterfall([
|
return async.waterfall([
|
||||||
function(callback) {
|
function(callback) {
|
||||||
return npm.isUpdated(packageJSON.name, packageJSON.version, 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?";
|
message = "This will completely erase " + params.device + ". Are you sure you want to continue?";
|
||||||
return visuals.patterns.confirm(options.yes, message, callback);
|
return visuals.patterns.confirm(options.yes, message, callback);
|
||||||
}, function(confirmed, callback) {
|
}, function(confirmed, callback) {
|
||||||
var bar, error, imageFileSize, imageFileStream, progress;
|
var bar;
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
imageFileSize = fs.statSync(params.image).size;
|
bar = new visuals.widgets.Progress('Writing Device OS');
|
||||||
if (imageFileSize === 0) {
|
params.progress = bar.update;
|
||||||
error = new Error("Invalid OS image: " + params.image + ". The image is 0 bytes.");
|
return bundle.write(params, callback);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
], function(error) {
|
], function(error) {
|
||||||
var resinWritePath;
|
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')
|
_ = require('lodash-contrib')
|
||||||
fs = require('fs')
|
|
||||||
os = require('os')
|
os = require('os')
|
||||||
async = require('async')
|
async = require('async')
|
||||||
path = require('path')
|
path = require('path')
|
||||||
mkdirp = require('mkdirp')
|
mkdirp = require('mkdirp')
|
||||||
resin = require('resin-sdk')
|
resin = require('resin-sdk')
|
||||||
visuals = require('resin-cli-visuals')
|
visuals = require('resin-cli-visuals')
|
||||||
progressStream = require('progress-stream')
|
|
||||||
diskio = require('diskio')
|
|
||||||
commandOptions = require('./command-options')
|
commandOptions = require('./command-options')
|
||||||
npm = require('../npm')
|
npm = require('../npm')
|
||||||
packageJSON = require('../../package.json')
|
packageJSON = require('../../package.json')
|
||||||
@ -127,6 +124,9 @@ exports.install =
|
|||||||
options: [ commandOptions.yes ]
|
options: [ commandOptions.yes ]
|
||||||
permission: 'user'
|
permission: 'user'
|
||||||
action: (params, options, done) ->
|
action: (params, options, done) ->
|
||||||
|
|
||||||
|
bundle = require('../devices/raspberry-pi')
|
||||||
|
|
||||||
async.waterfall [
|
async.waterfall [
|
||||||
|
|
||||||
(callback) ->
|
(callback) ->
|
||||||
@ -166,25 +166,9 @@ exports.install =
|
|||||||
(confirmed, callback) ->
|
(confirmed, callback) ->
|
||||||
return done() if not confirmed
|
return done() if not confirmed
|
||||||
|
|
||||||
imageFileSize = fs.statSync(params.image).size
|
bar = new visuals.widgets.Progress('Writing Device OS')
|
||||||
|
params.progress = bar.update
|
||||||
if imageFileSize is 0
|
bundle.write(params, callback)
|
||||||
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)
|
|
||||||
|
|
||||||
], (error) ->
|
], (error) ->
|
||||||
return done() if not 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