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 0.0.2 to 0.0.4

275

lib/app.js

@@ -1,3 +0,2 @@

var optimist = require('optimist'),
http = require('http'),
var http = require('http'),
https = require('https'),

@@ -34,3 +33,3 @@ fs = require('fs'),

module.exports = {
init: function() {
init: function(argv) {
auth.requireLogin(function(err) {

@@ -59,2 +58,9 @@ if (err) {

var pattern = new RegExp('^(' + firebases.join('|') + ')$');
if (!argv.firebase ||
(typeof(argv.firebase) !== 'string') ||
!argv.firebase.match(pattern)) {
console.log('---------- YOUR FIREBASES ----------\n'.green +
firebases.join('\n') +
'\n------------------------------------'.green);
}
var schema = {

@@ -65,6 +71,4 @@ properties: {

pattern: pattern,
description: '----- YOUR FIREBASES -----\n'.green +
firebases.join('\n') +
'\n--------------------------\n'.green +
'Enter a Firebase:'
description: 'Firebase:',
type: 'string'
},

@@ -74,6 +78,8 @@ 'public': {

description: 'Public Directory:',
default: defaultSettings['public']
default: defaultSettings['public'],
type: 'string'
},
rules: {
description: 'Security Rules File: (none)'
description: 'Security Rules File: (none)',
type: 'string'
}

@@ -97,2 +103,17 @@ }

}
var settings = {
firebase: result.firebase,
'public': result['public']
};
if (result.rules) {
if (fs.existsSync(result.rules) &&
fs.statSync(result.rules).isFile()) {
prompt.logger.info('Found rules file');
settings.rules = result.rules;
} else {
prompt.logger.error('INITIALIZATION ERROR - rules file does ' +
'not exist');
return;
}
}
prompt.logger.info('Initializing app into current directory');

@@ -106,12 +127,2 @@ auth.checkCanAccess(result.firebase, function(err) {

prompt.logger.info('Writing firebase.json settings file');
var settings = {
firebase: result.firebase,
'public': result['public']
};
if (result.rules &&
fs.existsSync(result.rules) &&
fs.statSync(result.rules).isFile()) {
prompt.logger.info('Found rules file');
settings.rules = result.rules;
}
var settingsJSON = JSON.stringify(settings, null, 2) + "\n";

@@ -129,3 +140,3 @@ try {

},
bootstrap: function() {
bootstrap: function(argv) {
auth.requireLogin(function(err) {

@@ -150,2 +161,9 @@ if (err) {

Object.keys(supportedTemplates).join('|') + ')$');
if (!argv.firebase ||
(typeof(argv.firebase) !== 'string') ||
!argv.firebase.match(firebasePattern)) {
console.log('---------- YOUR FIREBASES ----------\n'.green +
firebases.join('\n') +
'\n------------------------------------'.green);
}
var schema = {

@@ -156,14 +174,4 @@ properties: {

pattern: firebasePattern,
description: '----- YOUR FIREBASES -----\n'.green +
firebases.join('\n') +
'\n--------------------------\n'.green +
'Enter a Firebase:'
},
template: {
required: true,
pattern: templatePattern,
description: '------- TEMPLATES --------\n'.green +
Object.keys(supportedTemplates).join('\n') +
'\n--------------------------\n'.green +
'Enter a Template:'
description: 'Firebase:',
type: 'string'
}

@@ -177,3 +185,11 @@ }

}
auth.checkCanAccess(result.firebase, function(err) {
var firebase = result.firebase;
if (!argv.template ||
(typeof(argv.template) !== 'string') ||
!argv.template.match(templatePattern)) {
console.log('------- AVAILABLE TEMPLATES --------\n'.green +
Object.keys(supportedTemplates).join('\n') +
'\n------------------------------------'.green);
}
auth.checkCanAccess(firebase, function(err) {
if (err) {

@@ -184,96 +200,112 @@ prompt.logger.error('PERMISSION ERROR - You do not have ' +

}
var dir = result.firebase;
var projectDir = path.resolve(dir);
if (fs.existsSync(projectDir)) {
var i = 1;
do {
dir = result.firebase + '_' + i++;
projectDir = path.resolve(dir);
} while (fs.existsSync(projectDir));
}
prompt.logger.info('Bootstrapping into directory \'' + dir + '\'');
try {
fs.mkdirSync(projectDir, '0755');
} catch (err) {
prompt.logger.error('FILESYSTEM ERROR - ' +
'Could not create new directory');
return;
}
prompt.logger.info('Downloading and unpacking template');
var gunzip = zlib.createGunzip();
var untar = tar.Extract({
path: projectDir,
strip: 1
});
var urlParts = url.parse(supportedTemplates[result.template].url);
var protocol, port;
if (urlParts.protocol === 'https:') {
protocol = https;
port = 443;
} else {
protocol = http;
port = 80;
}
if (urlParts.port) {
port = urlParts.port;
}
var request = protocol.get({
host: urlParts.hostname,
path: urlParts.pathname,
port: port
});
request.on('response', function(response) {
var schema = {
properties: {
template: {
required: true,
pattern: templatePattern,
description: 'Template:',
type: 'string'
}
}
};
prompt.get(schema, function(err, result) {
if (err) {
prompt.logger.error('USER INPUT ERROR');
return;
}
var dir = firebase;
var projectDir = path.resolve(dir);
if (fs.existsSync(projectDir)) {
var i = 1;
do {
dir = firebase + '_' + i++;
projectDir = path.resolve(dir);
} while (fs.existsSync(projectDir));
}
prompt.logger.info('Bootstrapping into directory \'' + dir + '\'');
try {
response.pipe(gunzip).pipe(untar);
fs.mkdirSync(projectDir, '0755');
} catch (err) {
prompt.logger.error('DOWNLOAD ERROR - ' +
'Could not download template');
return
prompt.logger.error('FILESYSTEM ERROR - ' +
'Could not create new directory');
return;
}
response.on('end', function() {
var config = path.join(
projectDir,
supportedTemplates[result.template].config
);
prompt.logger.info('Downloading and unpacking template');
var gunzip = zlib.createGunzip();
var untar = tar.Extract({
path: projectDir,
strip: 1
});
var urlParts = url.parse(supportedTemplates[result.template].url);
var protocol, port;
if (urlParts.protocol === 'https:') {
protocol = https;
port = 443;
} else {
protocol = http;
port = 80;
}
if (urlParts.port) {
port = urlParts.port;
}
var request = protocol.get({
host: urlParts.hostname,
path: urlParts.pathname,
port: port
});
request.on('response', function(response) {
try {
var data = fs.readFileSync(config, 'utf8'),
realtimeHost = api.realtime.protocol + '//' +
result.firebase + '.' +
api.realtime.host;
if (api.realtime.port) {
realtimeHost += ':' + api.realtime.port;
}
var replaced = data.replace(
supportedTemplates[result.template].configRegex,
realtimeHost
);
fs.writeFileSync(config, replaced);
response.pipe(gunzip).pipe(untar);
} catch (err) {
prompt.logger.error('INITIALIZATION ERROR - ' +
'Couldn\'t update template with project settings');
return;
prompt.logger.error('DOWNLOAD ERROR - ' +
'Could not download template');
return
}
response.on('end', function() {
var config = path.join(
projectDir,
supportedTemplates[result.template].config
);
try {
var data = fs.readFileSync(config, 'utf8'),
realtimeHost = api.realtime.protocol + '//' +
firebase + '.' +
api.realtime.host;
if (api.realtime.port) {
realtimeHost += ':' + api.realtime.port;
}
var replaced = data.replace(
supportedTemplates[result.template].configRegex,
realtimeHost
);
fs.writeFileSync(config, replaced);
} catch (err) {
prompt.logger.error('INITIALIZATION ERROR - ' +
'Couldn\'t update template with project settings');
return;
}
prompt.logger.info('Writing firebase.json settings file');
var publicPath = supportedTemplates[result.template]
prompt.logger.info('Writing firebase.json settings file');
var publicPath = supportedTemplates[result.template]
.settings['public'].replace(/\//g, path.sep),
rulesPath = supportedTemplates[result.template]
rulesPath = supportedTemplates[result.template]
.settings['rules'].replace(/\//g, path.sep);
var settings = {
'firebase': result.firebase,
'public': publicPath,
'rules': rulesPath
};
var settingsJSON = JSON.stringify(settings, null, 2) + "\n";
var settingsFile = path.join(projectDir, 'firebase.json');
try {
fs.writeFileSync(settingsFile, settingsJSON);
} catch (err) {
prompt.logger.error('FILESYSTEM ERROR - ' +
'Could not save settings file');
return;
}
prompt.logger.info(
supportedTemplates[result.template].completedMessage);
var settings = {
'firebase': firebase,
'public': publicPath,
'rules': rulesPath
};
var settingsJSON = JSON.stringify(settings, null, 2) + "\n";
var settingsFile = path.join(projectDir, 'firebase.json');
try {
fs.writeFileSync(settingsFile, settingsJSON);
} catch (err) {
prompt.logger.error('FILESYSTEM ERROR - ' +
'Could not save settings file');
return;
}
prompt.logger.info(
supportedTemplates[result.template].completedMessage);
});
});

@@ -324,2 +356,7 @@ });

}
if (settings.rules && !fs.existsSync(settings.rules)) {
prompt.logger.error('SECURITY RULES ERROR - specified security ' +
'rules file does not exist');
return;
}
prompt.logger.info('Deploying...');

@@ -331,3 +368,3 @@ bitballoon.deploy(settings, function(err, url) {

}
if (settings.rules && fs.existsSync(settings.rules)) {
if (settings.rules) {
try {

@@ -334,0 +371,0 @@ var rulesString = fs.readFileSync(settings.rules),

@@ -81,3 +81,4 @@ var prompt = require('prompt'),

message: 'Must be a valid email address',
required: true
required: true,
type: 'string'
},

@@ -87,3 +88,4 @@ password: {

hidden: true,
required: true
required: true,
type: 'string'
}

@@ -90,0 +92,0 @@ }

var bitballoon = require('bitballoon'),
auth = require('./auth'),
path = require('path');
auth = require('./auth');

@@ -5,0 +4,0 @@ module.exports = {

@@ -1,7 +0,3 @@

var argv = require('optimist').argv,
auth = require('./auth'),
fs = require('fs'),
path = require('path'),
var auth = require('./auth'),
prompt = require('prompt'),
api = require('./api'),
packageInfo = require('../package.json');

@@ -19,4 +15,3 @@

},
logout: function() {
var deleteAll = ((typeof(argv.d) !== 'undefined') && (argv.d));
logout: function(deleteAll) {
auth.logout(deleteAll, function(err) {

@@ -40,5 +35,5 @@ if (err) {

} else {
console.log('----- YOUR FIREBASES -----'.green);
console.log('---------- YOUR FIREBASES ----------'.green);
console.log(firebases.join('\n'));
console.log('--------------------------'.green);
console.log('------------------------------------'.green);
}

@@ -45,0 +40,0 @@ });

{
"name": "firebase-tools",
"preferGlobal": true,
"version": "0.0.2",
"version": "0.0.4",
"description": "The Firebase Command Line Tools",

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

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