Skip to content

Commit f458180

Browse files
authored
VSCode plugin: Add UX improvements (#6091)
1 parent c37634a commit f458180

File tree

9 files changed

+197
-80
lines changed

9 files changed

+197
-80
lines changed

firebase-vscode/common/messaging/protocol.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface WebviewToExtensionParamsMap {
6464
/**
6565
* Equivalent to the `firebase emulators:start` command.
6666
*/
67-
launchEmulators : {
67+
launchEmulators: {
6868
emulatorUiSelections: EmulatorUiSelections,
6969
};
7070

@@ -96,7 +96,11 @@ export interface ExtensionToWebviewParamsMap {
9696
* Notifies webview when user has successfully selected a hosting folder
9797
* and it has been written to firebase.json.
9898
*/
99-
notifyHostingInitDone: { projectId: string, folderPath?: string };
99+
notifyHostingInitDone: {
100+
projectId: string,
101+
folderPath?: string
102+
framework?: string
103+
};
100104

101105
/**
102106
* Notify webview of status of deployment attempt.
@@ -119,7 +123,7 @@ export interface ExtensionToWebviewParamsMap {
119123
notifyPreviewChannelResponse: { id: string };
120124

121125
notifyEmulatorsStopped: {};
122-
notifyRunningEmulatorInfo: RunningEmulatorInfo ;
126+
notifyRunningEmulatorInfo: RunningEmulatorInfo;
123127
notifyEmulatorImportFolder: { folder: string };
124128
}
125129

firebase-vscode/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firebase-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "firebase-vscode",
44
"publisher": "firebase",
55
"description": "VSCode Extension for Firebase",
6-
"version": "0.0.23-alpha.2",
6+
"version": "0.0.23-alpha.3",
77
"engines": {
88
"vscode": "^1.69.0"
99
},
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,89 @@
1+
import * as path from "path";
2+
import * as vscode from "vscode";
3+
import { transports, format } from "winston";
4+
import Transport from "winston-transport";
5+
import stripAnsi from "strip-ansi";
6+
import { SPLAT } from "triple-beam";
17
import { logger as cliLogger } from "../../src/logger";
8+
import { setupLoggers, tryStringify } from "../../src/utils";
29
import { setInquirerLogger } from "./stubs/inquirer-stub";
10+
import { getRootFolders } from "./config-files";
311

412
export const pluginLogger: Record<string, (...args) => void> = {};
513

614
const logLevels = ['debug', 'info', 'log', 'warn', 'error'];
715

16+
const outputChannel = vscode.window.createOutputChannel('Firebase');
17+
18+
export function showOutputChannel() {
19+
outputChannel.show();
20+
}
21+
822
for (const logLevel of logLevels) {
923
pluginLogger[logLevel] = (...args) => {
1024
const prefixedArgs = ['[Firebase Plugin]', ...args];
1125
cliLogger[logLevel](...prefixedArgs);
1226
};
1327
}
1428

29+
/**
30+
* Logging setup for logging to console and to file.
31+
*/
32+
export function logSetup({ shouldWriteDebug, debugLogPath }: {
33+
shouldWriteDebug: boolean,
34+
debugLogPath: string
35+
}) {
36+
// Log to console (use built in CLI functionality)
37+
process.env.DEBUG = 'true';
38+
setupLoggers();
39+
40+
// Log to file
41+
// Only log to file if firebase.debug extension setting is true.
42+
if (shouldWriteDebug) {
43+
// Re-implement file logger call from ../../src/bin/firebase.ts to not bring
44+
// in the entire firebase.ts file
45+
const rootFolders = getRootFolders();
46+
const filePath = debugLogPath || path.join(rootFolders[0], 'firebase-plugin-debug.log');
47+
pluginLogger.info('Logging to path', filePath);
48+
cliLogger.add(
49+
new transports.File({
50+
level: "debug",
51+
filename: filePath,
52+
format: format.printf((info) => {
53+
const segments = [info.message, ...(info[SPLAT] || [])]
54+
.map(tryStringify);
55+
return `[${info.level}] ${stripAnsi(segments.join(" "))}`;
56+
}),
57+
})
58+
);
59+
cliLogger.add(
60+
new VSCodeOutputTransport({ level: "info" })
61+
);
62+
}
63+
}
64+
65+
/**
66+
* Custom Winston transport that writes to VSCode output channel.
67+
* Write only "info" and greater to avoid too much spam from "debug".
68+
*/
69+
class VSCodeOutputTransport extends Transport {
70+
constructor(opts) {
71+
super(opts);
72+
}
73+
log(info, callback) {
74+
setImmediate(() => {
75+
this.emit('logged', info);
76+
});
77+
const segments = [info.message, ...(info[SPLAT] || [])]
78+
.map(tryStringify);
79+
const text = `[${info.level}] ${stripAnsi(segments.join(" "))}`;
80+
81+
if (info.level !== 'debug') {
82+
// info or greater: write to output window
83+
outputChannel.appendLine(text);
84+
}
85+
86+
callback();
87+
}
88+
}
1589
setInquirerLogger(pluginLogger);

firebase-vscode/src/workflow.ts

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import * as path from "path";
21
import * as vscode from "vscode";
3-
import { transports, format } from "winston";
4-
import stripAnsi from "strip-ansi";
5-
import { SPLAT } from "triple-beam";
62
import { ExtensionContext, workspace } from "vscode";
73

84
import { FirebaseProjectMetadata } from "../../src/types/project";
@@ -19,16 +15,13 @@ import {
1915
import { User } from "../../src/types/auth";
2016
import { currentOptions } from "./options";
2117
import { selectProjectInMonospace } from "../../src/monospace";
22-
import { setupLoggers, tryStringify } from "../../src/utils";
23-
import { pluginLogger } from "./logger-wrapper";
24-
import { logger } from '../../src/logger';
18+
import { logSetup, pluginLogger, showOutputChannel } from "./logger-wrapper";
2519
import { discover } from "../../src/frameworks";
2620
import { setEnabled } from "../../src/experiments";
2721
import {
2822
readAndSendFirebaseConfigs,
2923
setupFirebaseJsonAndRcFileSystemWatcher,
30-
updateFirebaseRCProject,
31-
getRootFolders
24+
updateFirebaseRCProject
3225
} from "./config-files";
3326
import { ServiceAccountUser } from "../common/types";
3427

@@ -37,6 +30,7 @@ export let currentUser: User | ServiceAccountUser;
3730
// Stores a mapping from user email to list of projects for that user
3831
let projectsUserMapping = new Map<string, FirebaseProjectMetadata[]>();
3932
let channels = null;
33+
let currentFramework: string | undefined;
4034

4135
async function fetchUsers() {
4236
const accounts = await getAccounts();
@@ -116,32 +110,8 @@ export async function setupWorkflow(
116110
if (useFrameworks) {
117111
setEnabled('webframeworks', true);
118112
}
119-
/**
120-
* Logging setup for logging to console and to file.
121-
*/
122-
// Sets up CLI logger to log to console
123-
process.env.DEBUG = 'true';
124-
setupLoggers();
125113

126-
// Only log to file if firebase.debug extension setting is true.
127-
if (shouldWriteDebug) {
128-
// Re-implement file logger call from ../../src/bin/firebase.ts to not bring
129-
// in the entire firebase.ts file
130-
const rootFolders = getRootFolders();
131-
const filePath = debugLogPath || path.join(rootFolders[0], 'firebase-plugin-debug.log');
132-
pluginLogger.info('Logging to path', filePath);
133-
logger.add(
134-
new transports.File({
135-
level: "debug",
136-
filename: filePath,
137-
format: format.printf((info) => {
138-
const segments = [info.message, ...(info[SPLAT] || [])]
139-
.map(tryStringify);
140-
return `[${info.level}] ${stripAnsi(segments.join(" "))}`;
141-
}),
142-
})
143-
);
144-
}
114+
logSetup({ shouldWriteDebug, debugLogPath });
145115

146116
/**
147117
* Call pluginLogger with log arguments received from webview.
@@ -227,6 +197,9 @@ export async function setupWorkflow(
227197
broker.on("selectAndInitHostingFolder", selectAndInitHosting);
228198

229199
broker.on("hostingDeploy", async ({ target: deployTarget }) => {
200+
showOutputChannel();
201+
pluginLogger.info(`Starting deployment of project `
202+
+ `${currentOptions.projectId} to channel: ${deployTarget}`);
230203
const { success, consoleUrl, hostingUrl } = await deployToHosting(
231204
currentOptions.config,
232205
deployTarget
@@ -323,14 +296,14 @@ export async function setupWorkflow(
323296
}
324297

325298
async function selectAndInitHosting({ projectId, singleAppSupport }) {
326-
let discoveredFramework;
299+
currentFramework = undefined;
327300
// Note: discover() takes a few seconds. No need to block users that don't
328301
// have frameworks support enabled.
329302
if (useFrameworks) {
330-
discoveredFramework = useFrameworks && await discover(currentOptions.cwd, false);
303+
currentFramework = useFrameworks && await discover(currentOptions.cwd, false);
331304
pluginLogger.debug('Searching for a web framework in this project.');
332305
}
333-
if (discoveredFramework) {
306+
if (currentFramework) {
334307
pluginLogger.debug('Detected web framework, launching frameworks init.');
335308
await initHosting({
336309
spa: singleAppSupport,
@@ -358,7 +331,7 @@ export async function setupWorkflow(
358331
}
359332
readAndSendFirebaseConfigs(broker, context);
360333
broker.send("notifyHostingInitDone",
361-
{ projectId, folderPath: currentOptions.cwd });
334+
{ projectId, folderPath: currentOptions.cwd, framework: currentFramework });
362335
await fetchChannels(true);
363336
}
364337
}

firebase-vscode/webviews/SidebarApp.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function SidebarApp() {
1919
const [env, setEnv] = useState<{ isMonospace: boolean }>();
2020
const [channels, setChannels] = useState<ChannelWithId[]>(null);
2121
const [user, setUser] = useState<User | ServiceAccountUser | null>(null);
22+
const [framework, setFramework] = useState<string | null>(null);
2223
/**
2324
* null - has not finished checking yet
2425
* empty array - finished checking, no users logged in
@@ -86,9 +87,12 @@ export function SidebarApp() {
8687
setUser(user);
8788
});
8889

89-
broker.on("notifyHostingInitDone", ({ projectId, folderPath }) => {
90+
broker.on("notifyHostingInitDone", ({ projectId, folderPath, framework }) => {
9091
webLogger.debug(`notifyHostingInitDone: ${projectId}, ${folderPath}`);
9192
setHostingOnboarded(true);
93+
if (framework) {
94+
setFramework(framework);
95+
}
9296
});
9397

9498
broker.on("notifyHostingDeploy", ({ success }) => {
@@ -134,6 +138,7 @@ export function SidebarApp() {
134138
setHostingState={setHostingState}
135139
projectId={projectId}
136140
channels={channels}
141+
framework={framework}
137142
/>
138143
)}
139144
<Spacer size="large" />

0 commit comments

Comments
 (0)