firebase-tools
Version:
Command-Line Interface for Firebase
84 lines (83 loc) • 3.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.markdownDocsOfTools = exports.availableTools = void 0;
const index_1 = require("./apphosting/index");
const index_2 = require("./apptesting/index");
const index_3 = require("./auth/index");
const index_4 = require("./core/index");
const index_5 = require("./crashlytics/index");
const index_6 = require("./dataconnect/index");
const index_7 = require("./firestore/index");
const index_8 = require("./functions/index");
const index_9 = require("./messaging/index");
const index_10 = require("./realtime_database/index");
const index_11 = require("./remoteconfig/index");
const index_12 = require("./storage/index");
function addFeaturePrefix(feature, tools) {
return tools.map((tool) => (Object.assign(Object.assign({}, tool), { mcp: Object.assign(Object.assign({}, tool.mcp), { name: `${feature}_${tool.mcp.name}`, _meta: Object.assign(Object.assign({}, tool.mcp._meta), { feature }) }) })));
}
const tools = {
apphosting: addFeaturePrefix("apphosting", index_1.appHostingTools),
apptesting: addFeaturePrefix("apptesting", index_2.apptestingTools),
auth: addFeaturePrefix("auth", index_3.authTools),
core: addFeaturePrefix("firebase", index_4.coreTools),
crashlytics: addFeaturePrefix("crashlytics", index_5.crashlyticsTools),
database: addFeaturePrefix("realtimedatabase", index_10.realtimeDatabaseTools),
dataconnect: addFeaturePrefix("dataconnect", index_6.dataconnectTools),
firestore: addFeaturePrefix("firestore", index_7.firestoreTools),
functions: addFeaturePrefix("functions", index_8.functionsTools),
messaging: addFeaturePrefix("messaging", index_9.messagingTools),
remoteconfig: addFeaturePrefix("remoteconfig", index_11.remoteConfigTools),
storage: addFeaturePrefix("storage", index_12.storageTools),
};
const allToolsMap = new Map(Object.values(tools)
.flat()
.sort((a, b) => a.mcp.name.localeCompare(b.mcp.name))
.map((t) => [t.mcp.name, t]));
function getToolsByName(names) {
const selectedTools = new Set();
for (const toolName of names) {
const tool = allToolsMap.get(toolName);
if (tool) {
selectedTools.add(tool);
}
}
return Array.from(selectedTools);
}
function getToolsByFeature(serverFeatures) {
const features = new Set((serverFeatures === null || serverFeatures === void 0 ? void 0 : serverFeatures.length) ? serverFeatures : Object.keys(tools));
features.add("core");
return Array.from(features).flatMap((feature) => tools[feature] || []);
}
async function availableTools(ctx, activeFeatures, enabledTools) {
if (enabledTools === null || enabledTools === void 0 ? void 0 : enabledTools.length) {
return getToolsByName(enabledTools);
}
const allTools = getToolsByFeature(activeFeatures);
const availabilities = await Promise.all(allTools.map((t) => {
if (t.isAvailable) {
return t.isAvailable(ctx);
}
return true;
}));
return allTools.filter((_, i) => availabilities[i]);
}
exports.availableTools = availableTools;
function markdownDocsOfTools() {
var _a, _b, _c;
const allTools = getToolsByFeature([]);
let doc = `
| Tool Name | Feature Group | Description |
| --------- | ------------- | ----------- |`;
for (const tool of allTools) {
let feature = ((_b = (_a = tool.mcp) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.feature) || "";
if (feature === "firebase") {
feature = "core";
}
const description = (((_c = tool.mcp) === null || _c === void 0 ? void 0 : _c.description) || "").replaceAll("\n", "<br>");
doc += `
| ${tool.mcp.name} | ${feature} | ${description} |`;
}
return doc;
}
exports.markdownDocsOfTools = markdownDocsOfTools;