Skip to content

Commit cff15e0

Browse files
author
Jacob Wenger
committed
Merge pull request #72 from firebase/mb-headless-progress
Don't use ProgressBar when non-interactive.
2 parents 0e71110 + 0433bcb commit cff15e0

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

commands/login.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var ticketsRef = new Firebase(utils.addSubdomain(api.realtimeOrigin, 'firebase')
1818
module.exports = new Command('login')
1919
.description('sign into Firebase')
2020
.action(function(options) {
21-
if (utils.getInheritedOption(options, 'nonInteractive')) {
21+
if (options.nonInteractive) {
2222
return utils.reject('Cannot run login in non-interactive mode. Pass ' + chalk.bold('--token') + ' instead.', {exit: 1});
2323
}
2424

lib/command.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Command.prototype.register = function(client) {
9494
};
9595

9696
Command.prototype._prepare = function(options) {
97-
if (!process.stdin.isTTY) {
97+
if (!process.stdin.isTTY || utils.getInheritedOption(options, 'nonInteractive')) {
9898
options.nonInteractive = true;
9999
}
100100
if (utils.getInheritedOption(options, 'debug')) {

lib/deploy/hosting/deploy.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,41 @@ module.exports = function(context, options, payload) {
3232

3333
return new RSVP.Promise(function(resolve, reject) {
3434
var lastCount = 0;
35-
36-
var bar = new ProgressBar(chalk.bold('Uploading:') + ' [:bar] :percent', {
37-
total: upload.manifest.length,
38-
width: 40,
39-
complete: chalk.green('='),
40-
incomplete: ' ',
41-
clear: true
42-
});
35+
var lastPercent = 0;
36+
var bar;
37+
if (!options.nonInteractive && process.stderr) {
38+
bar = new ProgressBar(chalk.bold('Uploading:') + ' [:bar] :percent', {
39+
total: upload.manifest.length,
40+
width: 40,
41+
complete: chalk.green('='),
42+
incomplete: ' ',
43+
clear: true
44+
});
45+
} else {
46+
process.stdout.write(chalk.cyan.bold('\ni') + chalk.bold(' Progress: ['));
47+
}
4348

4449
local.versionRef.on('value', function(snap) {
4550
var status = snap.child('status').val();
4651
switch (status) {
4752
case 'deploying':
4853
var uc = snap.child('uploadedCount').val() || 0;
49-
bar.tick(uc - lastCount);
54+
var percent = Math.round(100.0 * uc / upload.manifest.length);
55+
if (bar) {
56+
bar.tick(uc - lastCount);
57+
} else {
58+
process.stdout.write(_.repeat(chalk.green('.'), percent - lastPercent));
59+
lastPercent = percent;
60+
}
5061
lastCount = uc;
5162
break;
5263
case 'deployed':
64+
if (bar) {
65+
bar.terminate();
66+
} else {
67+
process.stdout.write(chalk.bold(']') + '\n\n');
68+
}
5369
utils.logSuccess(upload.manifest.length + ' files uploaded successfully');
54-
bar.terminate();
5570
local.versionRef.off('value');
5671
resolve();
5772
break;

lib/prompt.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var inquirer = require('inquirer');
44
var _ = require('lodash');
55
var FirebaseError = require('./error');
66
var RSVP = require('rsvp');
7-
var utils = require('./utils');
87

98
module.exports = function(options, questions) {
109
return new RSVP.Promise(function(resolve, reject) {
@@ -15,7 +14,7 @@ module.exports = function(options, questions) {
1514
}
1615
}
1716

18-
if (prompts.length && utils.getInheritedOption(options, 'nonInteractive')) {
17+
if (prompts.length && options.nonInteractive) {
1918
return reject(new FirebaseError('Missing required options (' + _.uniq(_.pluck(prompts, 'name')).join(', ') + ') while running in non-interactive mode', {
2019
children: prompts,
2120
exit: 1

0 commit comments

Comments
 (0)