mirror of
https://github.com/zhigang1992/firebase-tools.git
synced 2026-04-28 20:05:23 +08:00
Merge branch 'next' into bl-html-templates
This commit is contained in:
@@ -48,7 +48,7 @@ module.exports = new Command('data:push <path> [infile]')
|
||||
path += '/';
|
||||
}
|
||||
|
||||
var refurl = utils.addSubdomain(api.realtimeOrigin, options.instance) + path + body.name;
|
||||
var refurl = utils.consoleUrl(options.project, '/database/data' + path + body.name);
|
||||
|
||||
utils.logSuccess('Data pushed successfully');
|
||||
logger.info();
|
||||
|
||||
@@ -57,7 +57,7 @@ module.exports = new Command('data:set <path> [infile]')
|
||||
|
||||
utils.logSuccess('Data persisted successfully');
|
||||
logger.info();
|
||||
logger.info(chalk.bold('View data at:'), utils.addSubdomain(api.realtimeOrigin, options.instance) + path);
|
||||
logger.info(chalk.bold('View data at:'), utils.consoleUrl(options.project, '/database/data' + path));
|
||||
return resolve();
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ module.exports = new Command('data:update <path> [infile]')
|
||||
|
||||
utils.logSuccess('Data updated successfully');
|
||||
logger.info();
|
||||
logger.info(chalk.bold('View data at:'), utils.addSubdomain(api.realtimeOrigin, options.instance) + path);
|
||||
logger.info(chalk.bold('View data at:'), utils.consolUrl(options.project, '/database/data' + path));
|
||||
return resolve();
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -1,42 +1,76 @@
|
||||
'use strict';
|
||||
|
||||
var Command = require('../lib/command');
|
||||
var requireAccess = require('../lib/requireAccess');
|
||||
var logger = require('../lib/logger');
|
||||
var open = require('open');
|
||||
var _ = require('lodash');
|
||||
var chalk = require('chalk');
|
||||
var open = require('open');
|
||||
var RSVP = require('rsvp');
|
||||
|
||||
var api = require('../lib/api');
|
||||
var Command = require('../lib/command');
|
||||
var logger = require('../lib/logger');
|
||||
var prompt = require('../lib/prompt');
|
||||
var requireAccess = require('../lib/requireAccess');
|
||||
var utils = require('../lib/utils');
|
||||
|
||||
var PANELS = {
|
||||
dashboard: '/',
|
||||
data: '/',
|
||||
rules: '/?page=Security',
|
||||
simulator: '/?page=Simulator',
|
||||
analytics: '/?page=Analytics',
|
||||
auth: '/?page=Auth',
|
||||
hosting: '/?page=Hosting'
|
||||
};
|
||||
var LINKS = [
|
||||
{name: 'Project Dashboard', arg: 'dashboard', consoleUrl: '/overview'},
|
||||
{name: 'Analytics', arg: 'analytics', consoleUrl: '/analytics'},
|
||||
{name: 'Database: Data', arg: 'database', consoleUrl: '/database/data'},
|
||||
{name: 'Database: Rules', arg: 'database:rules', consoleUrl: '/database/rules'},
|
||||
{name: 'Authentication: Providers', arg: 'auth', consoleUrl: '/authentication/providers'},
|
||||
{name: 'Authentication: Users', arg: 'auth:users', consoleUrl: '/authentication/users'},
|
||||
{name: 'Storage: Files', arg: 'storage', consoleUrl: '/storage/files'},
|
||||
{name: 'Storage: Rules', arg: 'storage:rules', consoleUrl: '/storage/rules'},
|
||||
{name: 'Hosting', arg: 'hosting', consoleUrl: '/hosting/main'},
|
||||
{name: 'Hosting: Deployed Site', arg: 'hosting:site'},
|
||||
{name: 'Remote Config', arg: 'config', consoleUrl: '/config'},
|
||||
{name: 'Remote Config: Conditions', arg: 'config:conditions', consoleUrl: '/config/conditions'},
|
||||
{name: 'Test Lab', arg: 'testlab', consoleUrl: '/testlab/histories/'},
|
||||
{name: 'Crash Reporting', arg: 'crash', consoleUrl: '/monitoring'},
|
||||
{name: 'Notifications', arg: 'notifications', consoleUrl: '/notification'},
|
||||
{name: 'Dynamic Links', arg: 'links', consoleUrl: '/durablelinks'},
|
||||
{name: 'Project Settings', arg: 'settings', consoleUrl: '/settings/general'},
|
||||
{name: 'Docs', arg: 'docs', url: 'https://firebase.google.com/docs'}
|
||||
];
|
||||
|
||||
module.exports = new Command('open [panel]')
|
||||
.description('open Firebase Hosting URL in browser or jump to a dashboard panel')
|
||||
var CHOICES = _.map(LINKS, 'name');
|
||||
|
||||
module.exports = new Command('open [link]')
|
||||
.description('quickly open a browser to relevant project resources')
|
||||
.before(requireAccess)
|
||||
.action(function(panel, options) {
|
||||
var url;
|
||||
|
||||
if (panel && PANELS[panel]) {
|
||||
// TODO: Change this to point to new console.
|
||||
var dashOrigin = utils.addSubdomain(api.realtimeOrigin, options.instance);
|
||||
url = dashOrigin + PANELS[panel];
|
||||
} else if (!panel || panel === 'site') {
|
||||
url = utils.addSubdomain(api.hostingOrigin, options.instance);
|
||||
} else {
|
||||
return utils.reject('Unrecognized panel, must be one of: ' + Object.keys(PANELS).join(', '), {exit: 1});
|
||||
.action(function(linkName, options) {
|
||||
var link = _.find(LINKS, {arg: linkName});
|
||||
if (linkName && !link) {
|
||||
return utils.reject('Unrecognized link name. Valid links are:\n\n' + _.map(LINKS, 'arg').join('\n'));
|
||||
}
|
||||
|
||||
logger.info('Opening URL in your default browser:');
|
||||
logger.info(chalk.bold.underline(url));
|
||||
open(url);
|
||||
return RSVP.resolve(url);
|
||||
var next = RSVP.resolve(link);
|
||||
if (!link) {
|
||||
next = prompt.once({
|
||||
type: 'list',
|
||||
message: 'What link would you like to open?',
|
||||
choices: CHOICES
|
||||
}).then(function(result) {
|
||||
return _.find(LINKS, {name: result});
|
||||
});
|
||||
}
|
||||
|
||||
return next.then(function(finalLink) {
|
||||
var url;
|
||||
if (finalLink.consoleUrl) {
|
||||
url = utils.consoleUrl(options.project, finalLink.consoleUrl);
|
||||
} else if (finalLink.url) {
|
||||
url = finalLink.url;
|
||||
} else if (finalLink.arg === 'hosting:site') {
|
||||
url = utils.addSubdomain(api.hostingOrigin, options.instance);
|
||||
}
|
||||
|
||||
logger.info(chalk.bold.cyan('Tip: ') + 'You can also run ' + chalk.bold.underline('firebase open ' + finalLink.arg));
|
||||
logger.info();
|
||||
logger.info('Opening ' + chalk.bold(finalLink.name) + ' link in your default browser:');
|
||||
logger.info(chalk.bold.underline(url));
|
||||
|
||||
open(url);
|
||||
return RSVP.resolve(url);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
var superstatic = require('superstatic').server;
|
||||
var chalk = require('chalk');
|
||||
var RSVP = require('rsvp');
|
||||
var requireConfig = require('../lib/requireConfig');
|
||||
var superstatic = require('superstatic').server;
|
||||
|
||||
var Command = require('../lib/command');
|
||||
var FirebaseError = require('../lib/error');
|
||||
var logger = require('../lib/logger');
|
||||
var requireConfig = require('../lib/requireConfig');
|
||||
var utils = require('../lib/utils');
|
||||
|
||||
var MAX_PORT_ATTEMPTS = 10;
|
||||
|
||||
var _attempts = 0;
|
||||
var startServer = function(options) {
|
||||
var server = superstatic({
|
||||
debug: true,
|
||||
port: options.port,
|
||||
host: options.host,
|
||||
config: options.config.get('hosting'),
|
||||
stack: 'strict'
|
||||
}).listen(function() {
|
||||
logger.info();
|
||||
logger.info('Server listening at: ' + chalk.underline(chalk.bold('http://' + options.host + ':' + options.port)));
|
||||
});
|
||||
|
||||
server.on('error', function(err) {
|
||||
if (err.code === 'EADDRINUSE') {
|
||||
var message = 'Port ' + options.port + ' is not available.';
|
||||
if (_attempts < MAX_PORT_ATTEMPTS) {
|
||||
utils.logWarning(message + ' Trying another port...');
|
||||
options.port++;
|
||||
_attempts++;
|
||||
startServer(options);
|
||||
} else {
|
||||
utils.logWarning(message);
|
||||
throw new FirebaseError('Could not find an open port for development server.', {exit: 1});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = new Command('serve')
|
||||
.description('start a local server for your static assets')
|
||||
@@ -13,17 +47,8 @@ module.exports = new Command('serve')
|
||||
.option('-o, --host <host>', 'the host on which to listen (default: localhost)', 'localhost')
|
||||
.before(requireConfig)
|
||||
.action(function(options) {
|
||||
var config = options.config;
|
||||
|
||||
superstatic({
|
||||
debug: true,
|
||||
port: options.port,
|
||||
host: options.host,
|
||||
config: config.get('hosting'),
|
||||
stack: 'strict'
|
||||
}).listen();
|
||||
|
||||
logger.info('Listening at', chalk.underline(chalk.bold('http://' + options.host + ':' + options.port)));
|
||||
logger.info('Starting Firebase development server...');
|
||||
startServer(options);
|
||||
|
||||
return new RSVP.Promise(function(resolve) {
|
||||
process.on('SIGINT', function() {
|
||||
|
||||
@@ -69,13 +69,14 @@ var api = {
|
||||
// https://developers.google.com/identity/protocols/OAuth2InstalledApp
|
||||
clientId: utils.envOverride('FIREBASE_CLIENT_ID', '563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com'),
|
||||
clientSecret: utils.envOverride('FIREBASE_CLIENT_SECRET', 'j9iVZfS8kkCEFUPaAeJV0sAi'),
|
||||
authOrigin: utils.envOverride('FIREBASE_AUTH_URL', 'https://accounts.google.com'),
|
||||
tokenOrigin: utils.envOverride('FIREBASE_TOKEN_URL', 'https://www.googleapis.com'),
|
||||
realtimeOrigin: utils.envOverride('FIREBASE_REALTIME_URL', 'https://firebaseio.com'),
|
||||
adminOrigin: utils.envOverride('FIREBASE_ADMIN_URL', 'https://admin.firebase.com'),
|
||||
authOrigin: utils.envOverride('FIREBASE_AUTH_URL', 'https://accounts.google.com'),
|
||||
consoleOrigin: utils.envOverride('FIREBASE_CONSOLE_URL', 'https://console.firebase.google.com'),
|
||||
deployOrigin: utils.envOverride('FIREBASE_DEPLOY_URL', utils.envOverride('FIREBASE_UPLOAD_URL', 'https://deploy.firebase.com')),
|
||||
hostingOrigin: utils.envOverride('FIREBASE_HOSTING_URL', 'https://firebaseapp.com'),
|
||||
realtimeOrigin: utils.envOverride('FIREBASE_REALTIME_URL', 'https://firebaseio.com'),
|
||||
rulesOrigin: utils.envOverride('FIREBASE_RULES_URL', 'https://firebaserules.googleapis.com'),
|
||||
tokenOrigin: utils.envOverride('FIREBASE_TOKEN_URL', 'https://www.googleapis.com'),
|
||||
|
||||
setToken: function(token) {
|
||||
refreshToken = token;
|
||||
|
||||
11
lib/auth.js
11
lib/auth.js
@@ -16,6 +16,8 @@ var portfinder = require('portfinder');
|
||||
var configstore = require('./configstore');
|
||||
var FirebaseError = require('./error');
|
||||
|
||||
portfinder.basePort = 9005;
|
||||
|
||||
var FIFTEEN_MINUTES_IN_MS = 15 * 60 * 1000;
|
||||
var SCOPES = [
|
||||
'email',
|
||||
@@ -149,10 +151,7 @@ var _loginWithLocalhost = function(port) {
|
||||
_respondWithFile(req, res, 400, '../templates/loginFailure.html');
|
||||
});
|
||||
|
||||
server.listen(port, function(err) {
|
||||
if (err) {
|
||||
return _loginWithoutLocalhost().then(resolve, reject);
|
||||
}
|
||||
server.listen(port, function() {
|
||||
logger.info();
|
||||
logger.info('Visit this URL on any device to log in:');
|
||||
logger.info(chalk.bold.underline(authUrl));
|
||||
@@ -161,6 +160,10 @@ var _loginWithLocalhost = function(port) {
|
||||
|
||||
open(authUrl);
|
||||
});
|
||||
|
||||
server.on('error', function() {
|
||||
_loginWithoutLocalhost().then(resolve, reject);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -106,9 +106,9 @@ var deploy = function(targetNames, options) {
|
||||
logger.info();
|
||||
var deployedHosting = _.includes(targetNames, 'hosting');
|
||||
if (deployedHosting) {
|
||||
logger.info(chalk.bold('URL:'), utils.addSubdomain(api.hostingOrigin, options.instance));
|
||||
logger.info(chalk.bold('Hosting Site:'), utils.addSubdomain(api.hostingOrigin, options.instance));
|
||||
}
|
||||
logger.info(chalk.bold('Dashboard:'), utils.addSubdomain(api.realtimeOrigin, options.instance));
|
||||
logger.info(chalk.bold('Dashboard:'), utils.consoleUrl(options.project, '/overview'));
|
||||
if (deployedHosting) {
|
||||
logger.info();
|
||||
logger.info('Visit the URL above or run', chalk.bold('firebase open'));
|
||||
|
||||
@@ -46,7 +46,7 @@ var _prepareSource = function(options) {
|
||||
_.assign(env, {
|
||||
firebase: {
|
||||
database: {
|
||||
url: utils.addSubdomain(api.realtimeOrigin, options.project),
|
||||
url: utils.addSubdomain(api.realtimeOrigin, options.instance),
|
||||
secret: secret
|
||||
}
|
||||
}
|
||||
|
||||
17
lib/utils.js
17
lib/utils.js
@@ -1,15 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var logger = require('./logger');
|
||||
var chalk = require('chalk');
|
||||
var Readable = require('stream').Readable;
|
||||
var RSVP = require('rsvp');
|
||||
|
||||
var configstore = require('./configstore');
|
||||
var FirebaseError = require('./error');
|
||||
var RSVP = require('rsvp');
|
||||
var Readable = require('stream').Readable;
|
||||
var logger = require('./logger');
|
||||
|
||||
var isWindows = process.platform === 'win32';
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Create a Firebase Console URL for the specified path and project.
|
||||
* @param {String} project The Project ID for the URL.
|
||||
* @param {String} path The console path for the URL.
|
||||
*/
|
||||
consoleUrl: function(project, path) {
|
||||
var api = require('./api');
|
||||
return api.consoleOrigin + '/project/' + project + path;
|
||||
},
|
||||
/**
|
||||
* Trace up the ancestry of objects that have a `parent` key, finding the
|
||||
* first instance of the provided key.
|
||||
|
||||
Reference in New Issue
Block a user