balena-cli/build/utils/helpers.js
Juan Cruz Viotti f6d8f12ba2 Implement os download command
This command download an unconfigured image to both the cache and to the
specified location by the `--output` option.
2015-09-29 13:03:14 -04:00

47 lines
1.2 KiB
JavaScript

(function() {
var Promise, _, chalk, os;
Promise = require('bluebird');
_ = require('lodash');
_.str = require('underscore.string');
os = require('os');
chalk = require('chalk');
exports.getOperatingSystem = function() {
var platform;
platform = os.platform();
if (platform === 'darwin') {
platform = 'osx';
}
return platform;
};
exports.stateToString = function(state) {
var percentage, result;
percentage = _.str.lpad(state.percentage, 3, '0') + '%';
result = (chalk.blue(percentage)) + " " + (chalk.cyan(state.operation.command));
switch (state.operation.command) {
case 'copy':
return result + " " + state.operation.from.path + " -> " + state.operation.to.path;
case 'replace':
return result + " " + state.operation.file.path + ", " + state.operation.copy + " -> " + state.operation.replace;
case 'run-script':
return result + " " + state.operation.script;
default:
throw new Error("Unsupported operation: " + state.operation.type);
}
};
exports.waitStream = function(stream) {
return new Promise(function(resolve, reject) {
stream.on('close', resolve);
return stream.on('error', reject);
});
};
}).call(this);