Files
firebase-tools/lib/identifierToProjectId.js
2016-05-31 12:25:08 -07:00

26 lines
554 B
JavaScript

'use strict';
var _ = require('lodash');
var api = require('./api');
module.exports = function(id) {
return api.getProjects().then(function(projects) {
// if exact match for a project id, return it
if (_.includes(_.keys(projects), id)) {
return id;
}
for (var projectId in projects) {
if (projects.hasOwnProperty(projectId)) {
var instance = _.get(projects, [projectId, 'instances', 'database', '0']);
if (id === instance) {
return projectId;
}
}
}
return null;
});
};