mirror of
https://github.com/zhigang1992/firebase-tools.git
synced 2026-01-13 09:09:56 +08:00
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
var _ = require('lodash');
|
|
var RSVP = require('rsvp');
|
|
var FirebaseError = require('./error');
|
|
|
|
module.exports = function(options) {
|
|
function numFilters(targetTypes) {
|
|
return _.filter(options.only, function(opt) {
|
|
var optChunks = opt.split(':');
|
|
return _.includes(targetTypes, optChunks[0]) && optChunks.length > 1;
|
|
}).length;
|
|
}
|
|
function targetContainsFilter(targetTypes) {
|
|
return numFilters(targetTypes) > 1;
|
|
}
|
|
function targetDoesNotContainFilter(targetTypes) {
|
|
return numFilters(targetTypes) === 0;
|
|
}
|
|
|
|
return new RSVP.Promise(function(resolve, reject) {
|
|
if (!options.only) {
|
|
return resolve();
|
|
}
|
|
if (options.except) {
|
|
return reject(new FirebaseError('Cannot specify both --only and --except', {exit: 1}));
|
|
}
|
|
if (targetContainsFilter(['database', 'storage', 'hosting'])) {
|
|
return reject(new FirebaseError('Filters specified with colons (e.g. --only functions:func1,functions:func2) are only supported for functions', {exit: 1}));
|
|
}
|
|
if (targetContainsFilter(['functions']) && targetDoesNotContainFilter(['functions'])) {
|
|
return reject(new FirebaseError('Cannot specify "--only functions" and "--only functions:<filter>" at the same time', {exit: 1}));
|
|
}
|
|
return resolve();
|
|
});
|
|
};
|