Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/commands/ext-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as utils from "../utils";

import { marked } from "marked";
import { markedTerminal } from "marked-terminal";
import { ExtensionSpec } from "../extensions/types";
import { ExtensionSpec, ExtensionVersion } from "../extensions/types";

const FUNCTION_TYPE_REGEX = /\..+\.function/;

Expand All @@ -23,6 +23,7 @@ export const command = new Command("ext:info <extensionName>")
.before(checkMinRequiredVersion, "extMinVersion")
.action(async (extensionName: string, options: any) => {
let spec: ExtensionSpec;
let version: ExtensionVersion | undefined;
if (isLocalExtension(extensionName)) {
if (!options.markdown) {
utils.logLabeledBullet(logPrefix, `reading extension from directory: ${extensionName}`);
Expand All @@ -41,7 +42,7 @@ export const command = new Command("ext:info <extensionName>")
const [name, version] = extensionName.split("@");
extensionName = `firebase/${name}@${version || "latest"}`;
}
const version = await extensionsApi.getExtensionVersion(extensionName);
version = await extensionsApi.getExtensionVersion(extensionName);
spec = version.spec;
}

Expand All @@ -60,6 +61,9 @@ export const command = new Command("ext:info <extensionName>")
const url = spec.author?.url;
const urlMarkdown = url ? `(**[${url}](${url})**)` : "";
lines.push(`**Author**: ${authorName} ${urlMarkdown}`);
if (version?.sourceDownloadUri) {
lines.push(`**Download URL**: ${version.sourceDownloadUri}`);
}

if (spec.description) {
lines.push(`**Description**: ${spec.description}`);
Expand Down
32 changes: 32 additions & 0 deletions src/extensions/listExtensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const MOCK_INSTANCES = [
extensionRef: "firebase/image-resizer",
name: "projects/my-test-proj/instances/image-resizer/configurations/95355951-397f-4821-a5c2-9c9788b2cc63",
createTime: "2019-05-19T00:20:10.416947Z",
params: {
IMG_BUCKET: "my-test-proj.firebasestorage.app",
IMG_SIZES: "200x200,400x400",
DELETE_ORIGINAL_FILE: "false",
},
systemParams: {
"firebaseextensions.v1beta.function/location": "us-central1",
},
source: {
state: "ACTIVE",
spec: {
Expand All @@ -35,6 +43,14 @@ const MOCK_INSTANCES = [
extensionRef: "firebase/image-resizer",
name: "projects/my-test-proj/instances/image-resizer-1/configurations/5b1fb749-764d-4bd1-af60-bb7f22d27860",
createTime: "2019-06-19T00:21:06.722782Z",
params: {
IMG_BUCKET: "my-test-proj.firebasestorage.app",
IMG_SIZES: "300x300",
DELETE_ORIGINAL_FILE: "true",
},
systemParams: {
"firebaseextensions.v1beta.function/location": "us-central1",
},
source: {
spec: {
version: "0.1.0",
Expand Down Expand Up @@ -78,6 +94,14 @@ describe("listExtensions", () => {
state: "ACTIVE",
updateTime: "2019-06-19 00:21:06",
version: "0.1.0",
params: {
IMG_BUCKET: "my-test-proj.firebasestorage.app",
IMG_SIZES: "300x300",
DELETE_ORIGINAL_FILE: "true",
},
systemParams: {
"firebaseextensions.v1beta.function/location": "us-central1",
},
},
{
extension: "firebase/image-resizer",
Expand All @@ -86,6 +110,14 @@ describe("listExtensions", () => {
state: "ACTIVE",
updateTime: "2019-05-19 00:20:10",
version: "0.1.0",
params: {
IMG_BUCKET: "my-test-proj.firebasestorage.app",
IMG_SIZES: "200x200,400x400",
DELETE_ORIGINAL_FILE: "false",
},
systemParams: {
"firebaseextensions.v1beta.function/location": "us-central1",
},
},
];
expect(result).to.eql(expected);
Expand Down
19 changes: 16 additions & 3 deletions src/extensions/listExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ import * as extensionsUtils from "./utils";
/**
* Lists the extensions installed under a project
* @param projectId ID of the project we're querying
* @return mapping that contains a list of instances under the "instances" key
* @return list of listed extensions
*/
export async function listExtensions(projectId: string): Promise<Record<string, string>[]> {
export interface ListedExtension {
extension: string;
publisher: string;
instanceId: string;
state: string;
version?: string;
updateTime: string;
params: Record<string, string>;
systemParams: Record<string, string>;
}
Comment on lines +15 to +24
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While defining the ListedExtension interface here is functional, it would be better for maintainability to move it to src/extensions/types.ts alongside other extension-related types. This keeps the codebase organized and makes the interface easily reusable by other commands or utilities that might need to process the output of listExtensions.


export async function listExtensions(projectId: string): Promise<ListedExtension[]> {
const instances = await listInstances(projectId);
if (instances.length < 1) {
logLabeledBullet(
Expand All @@ -30,7 +41,7 @@ export async function listExtensions(projectId: string): Promise<Record<string,
const sorted = instances.sort(
(a, b) => new Date(b.createTime).valueOf() - new Date(a.createTime).valueOf(),
);
const formatted: Record<string, string>[] = [];
const formatted: ListedExtension[] = [];
sorted.forEach((instance) => {
let extension = instance.config.extensionRef || "";
let publisher;
Expand All @@ -54,6 +65,8 @@ export async function listExtensions(projectId: string): Promise<Record<string,
state,
version,
updateTime,
params: instance.config.params,
systemParams: instance.config.systemParams,
});
});

Expand Down
Loading