Updates from punch list.

This commit is contained in:
Michael Bleigh
2015-10-09 18:09:49 -07:00
parent 2a5e92ac83
commit 97d949b2eb
5 changed files with 28 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ var api = require('../lib/api');
var requireAuth = require('../lib/requireAuth');
var RSVP = require('rsvp');
var FirebaseError = require('../lib/error');
var utils = require('../lib/utils');
var NEW_FIREBASE = '[create a new firebase]';
@@ -28,18 +29,19 @@ module.exports = new Command('init')
var cwd = options.cwd || process.cwd();
if (_isOutside(homeDir, cwd)) {
logger.warn(chalk.yellow(' Initializing outside your home directory'));
utils.logWarning(chalk.bold.yellow('Caution!') + ' Initializing outside your home directory');
}
if (cwd === homeDir) {
logger.warn(chalk.yellow(' Initializing directly at your home directory'));
utils.logWarning(chalk.bold.yellow('Caution!') + ' Initializing directly at your home directory');
}
if (fs.existsSync(path.join(cwd, 'firebase.json'))) {
return RSVP.reject(new FirebaseError('Cannot run init, firebase.json already present'));
}
var emptyDir = _.difference(fs.readdirSync(cwd), ['firebase-debug.log']).length === 0;
if (!emptyDir) {
logger.warn(chalk.yellow('Initializing in a non-empty directory'));
var fileCount = _.difference(fs.readdirSync(cwd), ['firebase-debug.log']).length;
if (fileCount !== 0) {
utils.logWarning('Initializing in a directory with ' + chalk.bold(fileCount) + ' files');
logger.warn();
}
return api.getFirebases().then(function(firebases) {

View File

@@ -7,6 +7,7 @@ var chalk = require('chalk');
var Table = require('cli-table');
var _ = require('lodash');
var logger = require('../lib/logger');
var Config = require('../lib/config');
var coloredPlan = function(plan) {
var color;
@@ -21,7 +22,9 @@ var coloredPlan = function(plan) {
module.exports = new Command('list')
.description('list the Firebases to which you have access')
.before(requireAuth)
.action(function() {
.action(function(options) {
var config = Config.load(options, true);
return api.getFirebases().then(function(firebases) {
var table = new Table({
head: ['Name', 'Plan', 'Collaborators'],
@@ -44,9 +47,13 @@ module.exports = new Command('list')
});
});
var displayName = name;
if (_.get(config, 'defaults.project') === name) {
displayName = chalk.cyan.bold(displayName + ' (current)');
}
out.push(project);
table.push([
name,
displayName,
coloredPlan(data.plan),
_.keys(data.users).join('\n')
]);

View File

@@ -18,7 +18,7 @@ var Config = function(src, options) {
this.defaults = {};
if (this._src.firebase) {
this.defaults.app = this._src.firebase;
this.defaults.project = this._src.firebase;
}
Config.TARGETS.forEach(function(target) {

View File

@@ -15,8 +15,8 @@ module.exports = function(options) {
return options.firebase;
}
var config = Config.load(options, true);
if (config && config.defaults.app) {
return config.defaults.app;
if (config && config.defaults.project) {
return config.defaults.project;
}
throw new FirebaseError('No app specified. Run with -f or inside app directory', {

View File

@@ -75,6 +75,15 @@ module.exports = {
type = type || 'info';
logger[type](chalk.cyan.bold('i '), message);
},
/**
* Log an info statement with a gray bullet at the start of the line.
* @param {String} The message to log
* @param {String} The log type, defaults to 'info'
*/
logWarning: function(message, type) {
type = type || 'warn';
logger[type](chalk.yellow.bold('⚠ '), message);
},
/**
* Return a promise that rejects with a FirebaseError.
* @param {String} message the error message