[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves "emulators:start" logs #2219

Merged
merged 17 commits into from
May 14, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- Adds new API commands that handle list/create/delete operations on the Android SHA certificate hashes `apps:android:sha:list`, `apps:android:sha:create`, and `apps:android:sha:delete`.
- Fixes an issue where the CLI did not assume admin privileges when performing Firestore / RTDB emulator operations.
- Fixes an issue where the functions and hosting emulators would crash when not properly initialized (#2112).
- Improves logs when running `emulators:start`.
64 changes: 63 additions & 1 deletion src/commands/emulators-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import { Command } from "../command";
import * as controller from "../emulator/controller";
import * as commandUtils from "../emulator/commandUtils";
import * as utils from "../utils";
import * as logger from "../logger";
import { EmulatorRegistry } from "../emulator/registry";
import { DOWNLOADABLE_EMULATORS, Emulators, EMULATORS_SUPPORTED_BY_GUI } from "../emulator/types";
import * as clc from "cli-color";
import { getLogFileName } from "../emulator/downloadableEmulators";

const Table = require("cli-table");

function stylizeLink(url: String) {
return clc.underline(clc.bold(url));
}

module.exports = new Command("emulators:start")
.before(commandUtils.beforeEmulatorCommand)
Expand All @@ -17,7 +28,58 @@ module.exports = new Command("emulators:start")
throw e;
}

utils.logLabeledSuccess("emulators", "All emulators started, it is now safe to connect.");
const guiInfo = EmulatorRegistry.getInfo(Emulators.GUI);
const guiUrl = `http://${guiInfo?.host}:${guiInfo?.port}`;
const head = ["Emulator", "Host:Port", "Log File"];

if (guiInfo) {
head.push("View in UI");
}

const uiTable = new Table();
uiTable.push([`${clc.green('✔')} All emulators ready! View status and logs at ${stylizeLink(guiUrl)}`]);
abeisgoat marked this conversation as resolved.
Show resolved Hide resolved

const emulatorsTable = new Table({
head: head,
style: {
head: ["yellow"],
},
});

emulatorsTable.push(
...controller
.filterEmulatorTargets(options)
.map((emulator) => {
const instance = EmulatorRegistry.get(emulator);
const info = EmulatorRegistry.getInfo(emulator);
const emulatorName = emulator.slice(0, 1).toUpperCase() + emulator.slice(1);
const isSupportedByGUI = EMULATORS_SUPPORTED_BY_GUI.includes(emulator);

if (!info) {
return [emulatorName, "Failed to initialize (see above)", "", ""];
}

return [
emulatorName,
`${info?.host}:${info?.port}`,
DOWNLOADABLE_EMULATORS.indexOf(emulator) >= 0 ? getLogFileName(emulator) : clc.blackBright("n/a"),
isSupportedByGUI && guiInfo ? stylizeLink(`${guiUrl}/${emulator}`) : clc.blackBright("n/a"),
];
})
.map((col) => col.slice(0, head.length))
.filter((v) => v)
);

logger.info(`${"\n" + uiTable.toString() + "\n"}
${emulatorsTable.toString()}

Issues? Report them at ${stylizeLink(
"https://github.com/firebase/firebase-tools/issues"
)} and attach the log files.
`);

// Add this line above once connect page is implemented
// It is now safe to connect your app. Instructions: http://${guiInfo?.host}:${guiInfo?.port}/connect

// Hang until explicitly killed
await new Promise((res, rej) => {
Expand Down
14 changes: 0 additions & 14 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,6 @@ export async function startAll(options: any, noGui: boolean = false): Promise<vo

const firestoreEmulator = new FirestoreEmulator(args);
await startEmulator(firestoreEmulator);

utils.logLabeledBullet(
Emulators.FIRESTORE,
`For testing set ${clc.bold(
`${Constants.FIRESTORE_EMULATOR_HOST}=${firestoreAddr.host}:${firestoreAddr.port}`
)}`
);
}

if (shouldStart(options, Emulators.DATABASE)) {
Expand Down Expand Up @@ -351,13 +344,6 @@ export async function startAll(options: any, noGui: boolean = false): Promise<vo

const databaseEmulator = new DatabaseEmulator(args);
await startEmulator(databaseEmulator);

utils.logLabeledBullet(
Emulators.DATABASE,
`For testing set ${clc.bold(
`${Constants.FIREBASE_DATABASE_EMULATOR_HOST}=${databaseAddr.host}:${databaseAddr.port}`
)}`
);
}

if (shouldStart(options, Emulators.HOSTING)) {
Expand Down
9 changes: 2 additions & 7 deletions src/emulator/downloadableEmulators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function getExecPath(name: DownloadableEmulators): string {
return details.binaryPath || details.downloadPath;
}

function _getLogFileName(name: string): string {
export function getLogFileName(name: string): string {
return `${name}-debug.log`;
}

Expand Down Expand Up @@ -213,7 +213,7 @@ async function _runBinary(
extraEnv: NodeJS.ProcessEnv
): Promise<void> {
return new Promise((resolve) => {
emulator.stdout = fs.createWriteStream(_getLogFileName(emulator.name));
emulator.stdout = fs.createWriteStream(getLogFileName(emulator.name));
try {
emulator.instance = childProcess.spawn(command.binary, command.args, {
env: { ...process.env, ...extraEnv },
Expand All @@ -239,11 +239,6 @@ async function _runBinary(
return;
}

utils.logLabeledBullet(
emulator.name,
`${description} logging to ${clc.bold(_getLogFileName(emulator.name))}`
);

emulator.instance.stdout.on("data", (data) => {
logger.debug(data.toString());
emulator.stdout.write(data);
Expand Down
6 changes: 0 additions & 6 deletions src/emulator/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as clc from "cli-color";

import { ALL_EMULATORS, EmulatorInstance, Emulators, EmulatorInfo } from "./types";
import { FirebaseError } from "../error";
import * as utils from "../utils";
import * as controller from "./controller";
import { Constants } from "./constants";

Expand All @@ -25,11 +24,6 @@ export class EmulatorRegistry {
const info = instance.getInfo();
await controller.waitForPortClosed(info.port, info.host);
this.set(instance.getName(), instance);

utils.logLabeledSuccess(
instance.getName(),
`${description} started at ${clc.bold.underline(`http://${info.host}:${info.port}`)}`
);
}

static async stop(name: Emulators): Promise<void> {
Expand Down