Skip to content

Commit

Permalink
Merge pull request #17 from firebase/v1.0.1
Browse files Browse the repository at this point in the history
V1.0.1
  • Loading branch information
Chris Raynor committed May 17, 2014
2 parents d042137 + 2d9ae3e commit 76779f5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 45 deletions.
14 changes: 10 additions & 4 deletions bin/firebase
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ if (argv._.length === 0) {
}

} else {
if (argv.help) {
if (
argv.h ||
argv.hel ||
argv.hep ||
argv.hepl ||
argv.help
) {

help.showHelp(argv._[0]);

Expand All @@ -40,14 +46,14 @@ if (argv._.length === 0) {
// Top-level functionality

case 'login':
firebase.login();
firebase.login(argv);
break;
case 'logout':
firebase.logout(argv.d);
firebase.logout(argv);
break;
case 'ls':
case 'list':
firebase.list();
firebase.list(argv);
break;

// Submodules
Expand Down
39 changes: 19 additions & 20 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var request = require('request'),
_when = require('when');

var defaultSettings = {
'public': '.'
'public': '.',
'ignore': ['firebase.json', '.*', '**/node_modules/**']
};

temp.track();
Expand Down Expand Up @@ -51,7 +52,7 @@ function getPrompt(schema, onComplete, idx, results) {

module.exports = {
init: function(argv) {
auth.listFirebases().then(function(res) {
auth.listFirebases(argv).then(function(res) {

var settingsFile = path.resolve('./firebase.json');
if (fs.existsSync(settingsFile)) {
Expand Down Expand Up @@ -120,7 +121,8 @@ module.exports = {
}
var settings = {
firebase: results.firebase,
'public': results['public']
'public': results['public'],
'ignore': defaultSettings['ignore']
};
console.log('Initializing app into current directory...');
auth.checkCanAccess(results.firebase, function(err) {
Expand Down Expand Up @@ -150,7 +152,7 @@ module.exports = {
});
},
bootstrap: function(argv) {
_when.join(this.getTemplates(), auth.listFirebases()).done(function(resultSet) {
_when.join(this.getTemplates(), auth.listFirebases(argv)).done(function(resultSet) {
var supportedTemplates = resultSet[0],
res = resultSet[1];

Expand Down Expand Up @@ -213,18 +215,11 @@ module.exports = {

results.directory = dir;
console.log('Bootstrapping into directory \'' + dir + '\'...');
try {
fs.mkdirSync(projectDir, '0755');
} catch (err) {
console.log(chalk.red('Filesystem Error') + ' - Could not create new' +
' directory');
process.exit(1);
}

// Load the project root if defined, and gracefully handle missing '/'
var templateRoot = supportedTemplates[results.template].templateRoot || '/';
if (templateRoot && templateRoot[0] !== '/') {
templateRoot = '/' + templateRoot;
var templateRoot = (supportedTemplates[results.template].templateRoot || '/').replace(/\//g, path.sep);
if (templateRoot && templateRoot[0] !== path.sep) {
templateRoot = path.sep + templateRoot;
}

console.log('Downloading and unpacking template...');
Expand Down Expand Up @@ -284,15 +279,19 @@ module.exports = {
console.log('Writing firebase.json settings file...');
var settings = {
'firebase': firebase,
'public': '.'
'public': defaultSettings['public'],
'ignore': defaultSettings['ignore']
};

if (supportedTemplates[results.template].settings) {
if (supportedTemplates[results.template].settings['public']) {
settings.public = supportedTemplates[results.template].settings['public'].replace(/\//g, path.sep)
settings.public = supportedTemplates[results.template].settings['public'];
}
if (supportedTemplates[results.template].settings['rules']) {
settings.rules = supportedTemplates[results.template].settings['rules'].replace(/\//g, path.sep);
settings.rules = supportedTemplates[results.template].settings['rules'];
}
if (supportedTemplates[results.template].settings['ignore']) {
settings.ignore = supportedTemplates[results.template].settings['ignore'];
}
}

Expand All @@ -306,7 +305,7 @@ module.exports = {
}

console.log(chalk.green('Successfully added template'));
console.log('To deploy: %s then %s', chalk.bold(util.format('cd %s/', results.directory)), chalk.bold('firebase deploy'));
console.log('To deploy: %s then %s', chalk.bold(util.format('cd %s', results.directory + path.sep)), chalk.bold('firebase deploy'));
});
});
}, function(error) {
Expand All @@ -330,7 +329,7 @@ module.exports = {
});
},
deploy: function(argv) {
auth.requireLogin(function(err) {
auth.requireLogin(argv, function(err) {
if (err) {
console.log(chalk.red('Login Error'));
process.exit(1);
Expand Down Expand Up @@ -440,7 +439,7 @@ module.exports = {
message = argv.message;
}

upload.send(settings.firebase, settings['public'], directoryRef.name(), message, function(err, directory) {
upload.send(settings.firebase, settings['public'], settings.ignore || defaultSettings.ignore, directoryRef.name(), message, function(err, directory) {
if (err) {
console.log(chalk.red('Deploy Error') + ' - Couldn\'t upload app');
console.log(err);
Expand Down
12 changes: 8 additions & 4 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ var auth = {
'.firebaserc'
),
maxRetries: 3,
requireLogin: function(callback) {
requireLogin: function(argv, callback) {
var that = this;

if ((this.email.length === 0) || (this.token.length === 0)) {
if (argv.email && argv.password) {
this._attemptLogin(this.maxRetries, callback);
} else if ((this.email.length === 0) || (this.token.length === 0)) {
console.log('Please sign into your Firebase account to continue...');
this._attemptLogin(this.maxRetries, callback);
} else {
Expand Down Expand Up @@ -61,6 +63,8 @@ var auth = {
if (tries > 0) {
if (tries !== this.maxRetries) {
console.log('Email or password incorrect, please try again');
delete prompt.override.email;
delete prompt.override.password;
}
this._loginRequest(function(err, email, token) {
if (err) {
Expand Down Expand Up @@ -253,9 +257,9 @@ var auth = {
} catch (e) {}
return config;
},
listFirebases: function() {
listFirebases: function(argv) {
return _when.promise(function(resolve, reject, notify) {
auth.requireLogin(function(err) {
auth.requireLogin(argv, function(err) {
if (err) {
var error = new Error('Login Unsuccessful');
error.type = 'LOGIN';
Expand Down
10 changes: 5 additions & 5 deletions lib/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var auth = require('./auth'),
chalk = require('chalk');

module.exports = {
login: function() {
login: function(argv) {
auth.login(function(err) {
if (err) {
console.log(chalk.red('Login Unsuccessful'));
Expand All @@ -13,8 +13,8 @@ module.exports = {
}
});
},
logout: function(deleteAll) {
auth.logout(deleteAll, function(err) {
logout: function(argv) {
auth.logout(argv.d, function(err) {
if (err) {
console.log(chalk.red('Log Out Unsuccessful'));
process.exit(1);
Expand All @@ -23,8 +23,8 @@ module.exports = {
}
});
},
list: function() {
auth.listFirebases().then(function(res) {
list: function(argv) {
auth.listFirebases(argv).then(function(res) {
res.showFirebases();
}, function(error) {
switch (error.type) {
Expand Down
18 changes: 8 additions & 10 deletions lib/upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var request = require('request'),
auth = require('./auth'),
api = require('./api'),
fstream = require('fstream'),
fstreamIgnore = require('fstream-ignore'),
tar = require('tar'),
zlib = require('zlib'),
temp = require('temp'),
Expand All @@ -12,7 +12,7 @@ var request = require('request'),
temp.track();

module.exports = {
send: function(firebase, publicDir, pushId, message, callback) {
send: function(firebase, publicDir, ignoreRules, pushId, message, callback) {
var writeStream = temp.createWriteStream({ suffix: '.tar.gz' }),
filename = writeStream.path,
fileCount = 0,
Expand All @@ -21,16 +21,11 @@ module.exports = {

console.log('Preparing to deploy Public Directory...');

fstream.Reader({
var reader = fstreamIgnore({
path: publicDir,
type: 'Directory',
follow: true,
filter: function() {
if (this.type !== 'Directory' && (
this.basename.match(/^firebase\.json$/) ||
this.basename.match(/^\./))) {
return false;
}
if (this.type !== 'Directory') {
fileCount += 1;
}
Expand All @@ -39,8 +34,11 @@ module.exports = {
}
return true;
}
})
.pipe(tar.Pack())
});

reader.addIgnoreRules(ignoreRules);

reader.pipe(tar.Pack())
.pipe(zlib.createGzip())
.pipe(writeStream);

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "firebase-tools",
"preferGlobal": true,
"version": "1.0.0",
"version": "1.0.1",
"description": "The Firebase Command Line Tools",
"keywords": [
"firebase"
Expand Down Expand Up @@ -29,7 +29,7 @@
"tar": "0.1.x",
"open": "0.0.x",
"request": "2.34.x",
"fstream": "0.1.x",
"fstream-ignore": "0.0.x",
"temp": "0.6.x",
"firebase": "~1.0.11",
"progress": "~1.1.5",
Expand Down

0 comments on commit 76779f5

Please sign in to comment.