diff --git a/commands/init.js b/commands/init.js index 0dc1cae7..db50803d 100644 --- a/commands/init.js +++ b/commands/init.js @@ -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) { diff --git a/commands/list.js b/commands/list.js index a40e465c..4ec0a084 100644 --- a/commands/list.js +++ b/commands/list.js @@ -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') ]); diff --git a/lib/config.js b/lib/config.js index 7ffa104c..8e4a9c77 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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) { diff --git a/lib/getFirebaseName.js b/lib/getFirebaseName.js index b5248f03..9ec6717e 100644 --- a/lib/getFirebaseName.js +++ b/lib/getFirebaseName.js @@ -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', { diff --git a/lib/utils.js b/lib/utils.js index 835fa7ba..74639758 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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