Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

firebase-tools

Package Overview
Dependencies
Maintainers
1
Versions
424
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firebase-tools - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

CHANGELOG.md

154

lib/app.js

@@ -27,3 +27,3 @@ var request = require('request'),

function getPrompt(schema, onComplete, idx, results) {
function getPrompt(argv, schema, onComplete, index, results) {
if (!Array.isArray(schema)) {

@@ -34,9 +34,16 @@ console.log(chalk.red('An error occurred'));

onComplete = typeof onComplete !== 'function' ? function() {} : onComplete;
idx = typeof idx !== 'number' ? 0 : idx;
index = typeof index !== 'number' ? 0 : index;
results = typeof results !== 'object' ? {} : results;
var item = schema[idx];
var item = schema[index];
if (argv.silent) {
if (!prompt.override[item.name] || (item.pattern && !item.pattern.test(prompt.override[item.name]))) {
console.log(chalk.red('Input Error') + ' - Not enough or invalid parameters specified while in silent mode');
console.log('Required ' + chalk.bold(item.name) + ' parameter missing or invalid');
process.exit(1);
}
}
if (typeof item.beforeValue === 'function') {
item.beforeValue(results);
}
prompt.get(schema[idx], function (error, result) {
prompt.get(schema[index], function (error, result) {
if (error) {

@@ -47,4 +54,4 @@ console.log(chalk.red('Input Error'));

results[item.name] = result[item.name];
if (++idx < schema.length) {
getPrompt(schema, onComplete, idx, results);
if (++index < schema.length) {
getPrompt(argv, schema, onComplete, index, results);
} else {

@@ -56,2 +63,23 @@ onComplete(results);

function getSettings(argv) {
var settingsFile = path.resolve('./firebase.json');
var settingsJSON, settings;
if (!fs.existsSync(settingsFile)) {
console.log(chalk.red('Initialization Error') + ' - Directory not ' +
'initialized');
process.exit(1);
}
try {
settingsJSON = fs.readFileSync(settingsFile);
settings = JSON.parse(settingsJSON);
} catch (err) {
console.log(chalk.red('Initialization Error') +' - Could not read ' +
'firebase.json settings file');
process.exit(1);
}
util._extend(settings, argv);
return settings;
}
module.exports = {

@@ -117,3 +145,3 @@ init: function(argv) {

getPrompt(schema, function(results) {
getPrompt(argv, schema, function(results) {
if (path.relative('.', results['public']).match(/^\./)) {

@@ -208,3 +236,3 @@ console.log(chalk.red('init cancelled - the public directory must be within the current working directory'));

getPrompt(schema, function(results) {
getPrompt(argv, schema, function(results) {
var firebase = results.firebase;

@@ -343,18 +371,3 @@ var dir = firebase;

}
var settingsFile = path.resolve('./firebase.json');
var settingsJSON, settings;
if (!fs.existsSync(settingsFile)) {
console.log(chalk.red('Initialization Error') + ' - Directory not ' +
'initialized');
process.exit(1);
}
try {
settingsJSON = fs.readFileSync(settingsFile);
settings = JSON.parse(settingsJSON);
} catch (err) {
console.log(chalk.red('Initialization Error') +' - Could not read ' +
'firebase.json settings file');
process.exit(1);
}
util._extend(settings, argv);
var settings = getSettings(argv);
if (typeof(settings.firebase) !== 'string') {

@@ -450,3 +463,3 @@ console.log(chalk.red('Initialization Error') +' - Could not read ' +

upload.send(settings.firebase, settings['public'], settings.ignore || defaultSettings.ignore, directoryRef.name(), message, function(err, directory) {
upload.send(settings.firebase, settings['public'], settings.ignore, directoryRef.name(), message, function(err, directory) {
if (err) {

@@ -462,18 +475,79 @@ console.log(chalk.red('Deploy Error') + ' - Couldn\'t upload app');

},
deleteSite: function(argv) {
auth.requireLogin(argv, function(err) {
if (err) {
console.log(chalk.red('Login Error'));
process.exit(1);
}
var settings = getSettings(argv);
if (typeof(settings.firebase) !== 'string') {
console.log(chalk.red('Initialization Error') +' - Could not read ' +
'firebase.json settings file');
process.exit(1);
}
auth.checkCanAccess(settings.firebase, function(err, tokens) {
if (err) {
console.log(chalk.red('Permission Error') + ' - You do not have ' +
'permission to use this Firebase');
process.exit(1);
}
var firebaseRef = new Firebase(api.realtimeUrl.replace(/\/\//, '//firebase.'));
firebaseRef.auth(tokens.firebaseToken, function(error, result) {
if (error) {
console.log('Firebase authentication failed!');
process.exit(1);
}
});
var directoryRef = firebaseRef
.child('hosting/versions')
.child(settings.firebase)
.push();
var bar = null;
var total = 0;
directoryRef.on('value', function(snapshot) {
var status = snapshot.child('status').val();
if (status === 'deploying') {
if (!bar && snapshot.hasChild('fileCount')) {
total = snapshot.child('fileCount').val();
bar = new ProgressBar(chalk.yellow('progress: :percent'), {
total: total
});
}
if (bar) {
var uploadedCount = snapshot.hasChild('uploadedCount') ? snapshot.child('uploadedCount').val() : 0;
bar.update(uploadedCount / total);
}
} else if (status === 'removed') {
console.log(chalk.green('Sucessfully removed'));
process.exit(0);
} else if (status === 'failed') {
if (bar) {
bar.terminate();
}
var message = chalk.red('Deploy Failed');
if (snapshot.hasChild('statusMessage')) {
message += ' - ' + snapshot.child('statusMessage').val();
}
console.log(message);
process.exit(1);
}
});
var message = null;
if (argv.message && (typeof(argv.message) === 'string')) {
message = argv.message;
}
upload.deleteSite(settings.firebase, directoryRef.name(), message, function(err, directory) {
if (err) {
console.log(chalk.red('Deploy Error') + ' - Couldn\'t upload app');
console.log(err);
process.exit(1);
}
});
});
});
},
open: function(argv) {
var settingsFile = path.resolve('./firebase.json');
var settingsJSON, settings;
if (!fs.existsSync(settingsFile)) {
console.log(chalk.red('Initialization Error') + ' - Directory not ' +
'initialized');
process.exit(1);
}
try {
settingsJSON = fs.readFileSync(settingsFile);
settings = JSON.parse(settingsJSON);
} catch (err) {
console.log(chalk.red('Initialization Error') +' - Could not read ' +
'firebase.json settings file');
process.exit(1);
}
var settings = getSettings(argv);
if (typeof(settings.firebase) !== 'string') {

@@ -480,0 +554,0 @@ console.log(chalk.red('Initialization Error') +' - Could not read ' +

@@ -19,6 +19,6 @@ var prompt = require('prompt'),

if (argv.email && argv.password) {
this._attemptLogin(this.maxRetries, callback);
this._attemptLogin(argv, 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);
this._attemptLogin(argv, this.maxRetries, callback);
} else {

@@ -28,3 +28,3 @@ this._validate(function(err) {

console.log('Please sign into your Firebase account to continue...');
that._attemptLogin(that.maxRetries, callback);
that._attemptLogin(argv, that.maxRetries, callback);
} else {

@@ -60,9 +60,13 @@ setTimeout(callback, 0, null, that.email, that.token);

},
login: function(callback) {
this._attemptLogin(this.maxRetries, callback);
login: function(argv, callback) {
this._attemptLogin(argv, this.maxRetries, callback);
},
_attemptLogin: function(tries, callback) {
_attemptLogin: function(argv, tries, callback) {
var that = this;
if (tries > 0) {
if (tries !== this.maxRetries) {
if (argv.silent) {
console.log(chalk.red('Input Error') + ' - Email or password incorrect');
process.exit(1);
}
console.log('Email or password incorrect, please try again');

@@ -72,5 +76,5 @@ delete prompt.override.email;

}
this._loginRequest(function(err, email, token) {
this._loginRequest(argv, function(err, email, token) {
if (err) {
that._attemptLogin(tries - 1, callback);
that._attemptLogin(argv, tries - 1, callback);
} else {

@@ -85,7 +89,7 @@ setTimeout(callback, 0, null, email, token);

},
_loginRequest: function(callback) {
_loginRequest: function(argv, callback) {
var that = this,
schema = {
properties: {
email: {
schema = [
{
name: 'email',
description: 'Email:',

@@ -96,4 +100,4 @@ pattern: /@/,

type: 'string'
},
password: {
},{
name: 'password',
description: 'Password:',

@@ -104,9 +108,19 @@ hidden: true,

}
}
};
];
if (this.email.length > 0) {
schema.properties.email.default = this.email;
schema[0].default = this.email;
}
if (argv.silent) {
for (var i in schema) {
var item = schema[i];
if (!prompt.override[item.name] || (item.pattern && !item.pattern.test(prompt.override[item.name]))) {
console.log(chalk.red('Input Error') + ' - Not enough or invalid parameters specified while in silent mode');
console.log('Required ' + chalk.bold(item.name) + ' parameter missing or invalid');
process.exit(1);
}
}
}
prompt.get(schema, function(err, result) {

@@ -113,0 +127,0 @@ if (err) {

@@ -7,3 +7,3 @@ var auth = require('./auth'),

login: function(argv) {
auth.login(function(err) {
auth.login(argv, function(err) {
if (err) {

@@ -10,0 +10,0 @@ console.log(chalk.red('Login Unsuccessful'));

@@ -136,2 +136,19 @@ var app = require('./app'),

break;
case 'delete-site':
console.log('\n' +
' firebase delete-site\n' +
' Deletes the current app from Firebase Hosting and displays a \n' +
' \'Site not Found\' page as if the site had never been deployed to.\n' +
'\n' +
' Optional command line parameters:\n' +
'\n' +
' -m, --message An optional version message\n' +
'\n' +
' -f, --firebase Overrides the Firebase setting in the firebase.json\n' +
'\n' +
' Deletes the site associated with the Firebase detailed in the firebase.json\n' +
' settings file. The current user must have access to the Firebase, and if\n' +
' the user is not currently logged in, they are prompted to do so - see\n' +
' `firebase login --help` for more details.\n');
break;
case 'open':

@@ -171,2 +188,6 @@ console.log('\n' +

'\n' +
' delete-site\n' +
' Deletes the current app from Firebase Hosting and displays a \n' +
' \'Site not Found\' page as if the site had never been deployed to.\n' +
'\n' +
' login\n' +

@@ -186,2 +207,6 @@ ' Logs you into Firebase. All commands that require login will prompt\n' +

'\n' +
' -s, --silent\n' +
' Silent mode for scripting - commands will error with non-zero status code\n' +
' instead of waiting for prompt if not enough information supplied.\n' +
'\n' +
'For a quick start guide, see https://www.firebase.com/docs/hosting.html\n');

@@ -188,0 +213,0 @@ }

@@ -77,3 +77,37 @@ var request = require('request'),

});
},
deleteSite: function(firebase, pushId, message, callback) {
var writeStream = temp.createWriteStream({ suffix: '.tar.gz' }),
filename = writeStream.path,
publicDir = temp.mkdirSync();
console.log('Preparing to delete site...');
fstreamIgnore({
path: publicDir,
type: 'Directory'
}).pipe(tar.Pack())
.pipe(zlib.createGzip())
.pipe(writeStream);
writeStream.once('finish', function() {
var params = ['id=' + encodeURIComponent(pushId), 'fileCount=0', 'token=' + auth.token];
if (message) {
params.push('message=' + encodeURIComponent(message));
}
var url = api.uploadUrl + '/upload/' + firebase + '?' + params.join('&')
var readStream = fs.createReadStream(filename);
var r = request.put({
url: url,
json: true
}, function(err, response, body) {
fs.unlink(filename);
var failed = (err || !body || !body.success);
setTimeout(callback, 0, failed, body ? body.directory : undefined);
});
var form = r.form();
form.append('site', readStream);
});
}
}
{
"name": "firebase-tools",
"preferGlobal": true,
"version": "1.0.5",
"version": "1.0.6",
"description": "The Firebase Command Line Tools",

@@ -6,0 +6,0 @@ "keywords": [

@@ -46,2 +46,6 @@ firebase-tools

Lists the Firebases available to the currently logged in user.
delete-site
Deletes the current app from Firebase Hosting and displays a
'Site not Found' page as if the site had never been deployed to.

@@ -56,7 +60,11 @@ login

-h, --help
Shows this help screen. Use `firebase <command> --help` for more detailed
help instructions.
Shows this help screen. Use `firebase <command> --help` for more
detailed help instructions.
-v, --version
Displays the current version.
-s, --silent
Silent mode for scripting - commands will error with non-zero status code
instead of waiting for prompt if not enough information supplied.
```

@@ -63,0 +71,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc