firebase-tools
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -58,3 +58,8 @@ var http = require('http'), | ||
res.on('end', function() { | ||
var response = JSON.parse(responseString); | ||
try { | ||
var response = JSON.parse(responseString); | ||
} catch (err) { | ||
console.log('SERVER ERROR'.red + ' - Please try again'); | ||
process.exit(1); | ||
} | ||
setTimeout(callback, 0, res.statusCode, response); | ||
@@ -61,0 +66,0 @@ }); |
187
lib/app.js
@@ -39,3 +39,3 @@ var http = require('http'), | ||
console.log('LOGIN ERROR'.red); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -45,3 +45,3 @@ auth.getFirebases(function(err, firebases) { | ||
console.log('INITIALIZATION ERROR'.red); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -52,3 +52,3 @@ var settingsFile = path.resolve('./firebase.json'); | ||
'initialized'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -58,3 +58,3 @@ if (firebases.length == 0) { | ||
'to initialize the app with at https://firebase.com'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -93,3 +93,3 @@ // Firebase names always a subset of ^[0-9a-z-]*$ so safe to regex | ||
console.log('USER INPUT ERROR'.red); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -99,3 +99,3 @@ if (path.relative('.', result['public']).match(/^\./)) { | ||
'must be within current working directory'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -105,3 +105,3 @@ if (!fs.existsSync(result['public'])) { | ||
'does not exist'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -119,3 +119,3 @@ var settings = { | ||
'not exist'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -128,3 +128,3 @@ } | ||
'permission to use this Firebase'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -138,2 +138,3 @@ console.log('Writing firebase.json settings file'); | ||
console.log('INITIALIZATION ERROR'.red); | ||
process.exit(1); | ||
} | ||
@@ -149,3 +150,3 @@ }); | ||
console.log('LOGIN ERROR'.red); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -155,3 +156,3 @@ auth.getFirebases(function(err, firebases) { | ||
console.log('INITIALIZATION ERROR'.red); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -161,3 +162,3 @@ if (firebases.length == 0) { | ||
'to bootstrap the app with at https://firebase.com'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -188,3 +189,3 @@ // Firebase names always a subset of ^[0-9a-z-]*$ so safe to regex | ||
console.log('USER INPUT ERROR'.red); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -203,3 +204,3 @@ var firebase = result.firebase; | ||
'permission to use this Firebase'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -219,3 +220,3 @@ var schema = { | ||
console.log('USER INPUT ERROR'.red); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -237,3 +238,3 @@ var dir = firebase; | ||
' directory'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -270,3 +271,3 @@ | ||
'template'); | ||
return | ||
process.exit(1); | ||
} | ||
@@ -294,3 +295,3 @@ response.on('end', function() { | ||
'update template with project settings'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -315,3 +316,3 @@ | ||
'settings file'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -331,3 +332,3 @@ console.log(supportedTemplates[result.template].completedMessage); | ||
console.log('LOGIN ERROR'.red); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -338,3 +339,3 @@ var settingsFile = path.resolve('./firebase.json'); | ||
'initialized'); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -344,73 +345,87 @@ try { | ||
settings = JSON.parse(settingsJSON); | ||
if (typeof(settings.firebase) === 'string') { | ||
auth.checkCanAccess(settings.firebase, function(err, bbToken, bbSite) { | ||
} catch (err) { | ||
console.log('INITIALIZATION ERROR'.red +' - Could not read ' + | ||
'firebase.json settings file'); | ||
process.exit(1); | ||
} | ||
if (typeof(settings.firebase) !== 'string') { | ||
console.log('INITIALIZATION ERROR'.red +' - Could not read ' + | ||
'firebase.json settings file'); | ||
process.exit(1); | ||
} | ||
auth.checkCanAccess(settings.firebase, function(err, bbToken, bbSite) { | ||
if (err) { | ||
console.log('PERMISSION ERROR'.red + ' - You do not have ' + | ||
'permission to use this Firebase'); | ||
process.exit(1); | ||
} | ||
if (bbToken) { | ||
settings.bbToken = bbToken; | ||
} | ||
if (bbSite) { | ||
settings.bbSite = bbSite; | ||
} | ||
for (var i in defaultSettings) { | ||
if (defaultSettings.hasOwnProperty(i) && | ||
!settings.hasOwnProperty(i)) { | ||
settings[i] = defaultSettings[i]; | ||
} | ||
} | ||
if (path.relative('.', settings['public']).match(/^\./)) { | ||
console.log('PUBLIC DIRECTORY ERROR'.red + ' - public directory' + | ||
' must be within current working directory'); | ||
process.exit(1); | ||
} | ||
if (!fs.existsSync(settings['public'])) { | ||
console.log('PUBLIC DIRECTORY ERROR'.red + ' - Public directory ' + | ||
'does not exist'); | ||
process.exit(1); | ||
} | ||
if (fs.readdirSync(settings['public']).length == 0) { | ||
console.log('PUBLIC DIRECTORY ERROR'.red + ' - Public directory ' + | ||
'must not be empty'); | ||
process.exit(1); | ||
} | ||
if (settings.rules) { | ||
if (!fs.existsSync(settings.rules)) { | ||
console.log('SECURITY RULES ERROR'.red + ' - specified security' + | ||
' rules file does not exist'); | ||
process.exit(1); | ||
} | ||
try { | ||
var rulesString = fs.readFileSync(settings.rules), | ||
rules = JSON.parse(rulesString); | ||
} catch (err) { | ||
console.log('SECURITY RULES ERROR'.red + ' - Couldn\'t parse ' + | ||
'security rules'); | ||
process.exit(1); | ||
} | ||
console.log('Deploying...'); | ||
auth.updateRules(settings.firebase, rules, function(err) { | ||
if (err) { | ||
console.log('PERMISSION ERROR'.red + ' - You do not have ' + | ||
'permission to use this Firebase'); | ||
return; | ||
console.log('DEPLOY ERROR'.red + ' - Couldn\'t update ' + | ||
'security rules'); | ||
process.exit(1); | ||
} | ||
if (bbToken) { | ||
settings.bbToken = bbToken; | ||
} | ||
if (bbSite) { | ||
settings.bbSite = bbSite; | ||
} | ||
for (var i in defaultSettings) { | ||
if (defaultSettings.hasOwnProperty(i) && | ||
!settings.hasOwnProperty(i)) { | ||
settings[i] = defaultSettings[i]; | ||
} | ||
} | ||
if (path.relative('.', settings['public']).match(/^\./)) { | ||
console.log('PUBLIC DIRECTORY ERROR'.red + ' - public directory' + | ||
' must be within current working directory'); | ||
return; | ||
} | ||
if (settings.rules && !fs.existsSync(settings.rules)) { | ||
console.log('SECURITY RULES ERROR'.red + ' - specified security' + | ||
' rules file does not exist'); | ||
return; | ||
} | ||
console.log('Deploying...'); | ||
bitballoon.deploy(settings, function(err, url) { | ||
if (err) { | ||
console.log('DEPLOY ERROR'.red + ' - Couldn\'t deploy app'); | ||
return; | ||
} | ||
if (settings.rules) { | ||
try { | ||
var rulesString = fs.readFileSync(settings.rules), | ||
rules = JSON.parse(rulesString); | ||
} catch (err) { | ||
var rules = null; | ||
} | ||
if (rules) { | ||
auth.updateRules(settings.firebase, rules, function(err) { | ||
if (err) { | ||
console.log('DEPLOY ERROR'.red + ' - Couldn\'t update ' + | ||
'security rules'); | ||
return; | ||
} | ||
console.log('DEPLOYED SUCCESSFULLY'.green + ' - View your' + | ||
' app at: ' + url.cyan); | ||
setTimeout(open, 1000, url); | ||
}); | ||
} else { | ||
console.log('DEPLOY ERROR'.red + ' - Couldn\'t parse ' + | ||
'security rules'); | ||
} | ||
} else { | ||
console.log('DEPLOYED SUCCESSFULLY'.green + ' - View your app' + | ||
' at: ' + url.cyan); | ||
setTimeout(open, 1000, url); | ||
} | ||
}); | ||
deploy(settings); | ||
}); | ||
} else { | ||
console.log('Deploying...'); | ||
deploy(settings); | ||
} | ||
} catch (err) { | ||
console.log('INITIALIZATION ERROR'.red +' - Could not read ' + | ||
'firebase.json settings file'); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
function deploy(settings) { | ||
bitballoon.deploy(settings, function(err, url) { | ||
if (err) { | ||
console.log('DEPLOY ERROR'.red + ' - Couldn\'t deploy app'); | ||
process.exit(1); | ||
} | ||
console.log('DEPLOYED SUCCESSFULLY'.green + ' - View your app' + | ||
' at: ' + url.cyan); | ||
setTimeout(open, 1000, url); | ||
}); | ||
} |
@@ -42,5 +42,5 @@ var prompt = require('prompt'), | ||
} else if (response.minCLI) { | ||
// Always fatal, don't call callback | ||
console.log('OUTDATED CLI VERSION'.red + ' - Please update to at ' + | ||
'least v' + response.minCLI); | ||
process.exit(1); | ||
} else { | ||
@@ -70,4 +70,4 @@ setTimeout(callback, 0, new Error('Invalid Access Token')); | ||
} else { | ||
// Always fatal, don't call callback | ||
console.log('LOGIN UNSUCCESSFUL'.red); | ||
process.exit(1); | ||
} | ||
@@ -130,5 +130,5 @@ }, | ||
} else if (response.minCLI) { | ||
// Always fatal, don't call callback | ||
console.log('OUTDATED CLI VERSION'.red + ' - Please update to at least ' + | ||
'v' + response.minCLI); | ||
process.exit(1); | ||
} else { | ||
@@ -135,0 +135,0 @@ if (typeof(callback) === 'function') { |
@@ -9,2 +9,3 @@ var auth = require('./auth'), | ||
console.log('LOGIN UNSUCCESSFUL'.red); | ||
process.exit(1); | ||
} else { | ||
@@ -19,2 +20,3 @@ console.log('LOGIN SUCCESSFUL'.green); | ||
console.log('LOG OUT UNSUCCESSFUL'.red); | ||
process.exit(1); | ||
} else { | ||
@@ -30,6 +32,8 @@ console.log('LOG OUT SUCCESSFUL'.green); | ||
console.log('LOGIN UNSUCCESSFUL'.red); | ||
} else { | ||
process.exit(1); | ||
} else { | ||
auth.getFirebases(function(err, firebases) { | ||
if (err) { | ||
console.log('COULD NOT LIST FIREBASES'.red); | ||
process.exit(1); | ||
} else { | ||
@@ -36,0 +40,0 @@ console.log('---------- YOUR FIREBASES ----------'.green); |
@@ -0,1 +1,3 @@ | ||
var firebase = require('./firebase'); | ||
module.exports = { | ||
@@ -149,5 +151,5 @@ showHelp: function(command) { | ||
'Firebase Command Line Tools\n' + | ||
'Version ' + this.version + '\n' + | ||
'Version ' + firebase.version + '\n' + | ||
'https://www.firebase.com\n'); | ||
} | ||
} |
{ | ||
"name": "firebase-tools", | ||
"preferGlobal": true, | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "The Firebase Command Line Tools", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
41058
1009
7