firebase-tools
Version:
Command-Line Interface for Firebase
42 lines (41 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.update = update;
exports.inferUpdateSource = inferUpdateSource;
const semver = require("semver");
const error_1 = require("../error");
const extensionsApi = require("./extensionsApi");
const extensionsHelper_1 = require("./extensionsHelper");
async function update(updateOptions) {
const { projectId, instanceId, extRef, params, systemParams, canEmitEvents, allowedEventTypes, eventarcChannel, } = updateOptions;
if (extRef) {
return await extensionsApi.updateInstanceFromRegistry({
projectId,
instanceId,
extRef,
params,
systemParams,
canEmitEvents,
allowedEventTypes,
eventarcChannel,
});
}
throw new error_1.FirebaseError(`A version of the extension was not supplied for ${instanceId}. Please make sure this is a valid extension and try again.`);
}
function inferUpdateSource(updateSource, existingRef) {
if (!updateSource) {
return `${existingRef}@latest`;
}
if (semver.valid(updateSource)) {
return `${existingRef}@${updateSource}`;
}
if (!(0, extensionsHelper_1.isLocalOrURLPath)(updateSource) && updateSource.split("/").length < 2) {
return updateSource.includes("@")
? `firebase/${updateSource}`
: `firebase/${updateSource}@latest`;
}
if (!(0, extensionsHelper_1.isLocalOrURLPath)(updateSource) && !updateSource.includes("@")) {
return `${updateSource}@latest`;
}
return updateSource;
}