Skip to content

Commit

Permalink
Clarify emulator logs (#2022)
Browse files Browse the repository at this point in the history
Co-Authored-By: rachelsaunders <[email protected]>
  • Loading branch information
samtstern and rachelsaunders authored Mar 12, 2020
1 parent 9c687ad commit 2605a98
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/commands/emulators-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = new Command("emulators:start")
throw e;
}

utils.logSuccess("All emulators started, it is now safe to connect.");
utils.logLabeledSuccess("emulators", "All emulators started, it is now safe to connect.");

// Hang until explicitly killed
await new Promise((res, rej) => {
Expand Down
59 changes: 44 additions & 15 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ export async function startEmulator(instance: EmulatorInstance): Promise<void> {
if (!portOpen) {
await cleanShutdown();
const description = Constants.description(name);
utils.logWarning(`Port ${port} is not open on ${host}, could not start ${description}.`);
utils.logBullet(`To select a different host/port for the emulator, update your "firebase.json":
utils.logLabeledWarning(
name,
`Port ${port} is not open on ${host}, could not start ${description}.`
);
utils.logLabeledBullet(
name,
`To select a different host/port for the emulator, specify that host/port in a firebase.json config file:
{
// ...
"emulators": {
Expand All @@ -70,18 +75,19 @@ export async function startEmulator(instance: EmulatorInstance): Promise<void> {
"port": "${clc.yellow("PORT")}"
}
}
}`);
}`
);
return utils.reject(`Could not start ${name} emulator, port taken.`, {});
}

await EmulatorRegistry.start(instance);
}

export async function cleanShutdown(): Promise<boolean> {
utils.logBullet("Shutting down emulators.");
utils.logLabeledBullet("emulators", "Shutting down emulators.");

for (const name of EmulatorRegistry.listRunning()) {
utils.logBullet(`Stoppping ${Constants.description(name)}`);
utils.logLabeledBullet(name, `Stopping ${Constants.description(name)}`);
await EmulatorRegistry.stop(name);
}

Expand Down Expand Up @@ -141,7 +147,8 @@ export async function startAll(options: any, noGui: boolean = false): Promise<vo
const requested: string[] = options.only.split(",");
const ignored = _.difference(requested, targets);
for (const name of ignored) {
utils.logWarning(
utils.logLabeledWarning(
name,
`Not starting the ${clc.bold(name)} emulator, make sure you have run ${clc.bold(
"firebase init"
)}.`
Expand Down Expand Up @@ -239,19 +246,29 @@ export async function startAll(options: any, noGui: boolean = false): Promise<vo
}

const rulesLocalPath = options.config.get("firestore.rules");
const foundRulesFile = rulesLocalPath && fs.existsSync(rulesLocalPath);
if (rulesLocalPath) {
const rules: string = path.join(options.projectRoot, rulesLocalPath);
if (fs.existsSync(rules)) {
args.rules = rules;
} else {
utils.logWarning(
`Firestore rules file ${clc.bold(
rules
)} specified in firebase.json does not exist, starting Firestore emulator without rules.`
utils.logLabeledWarning(
"firestore",
`Cloud Firestore rules file ${clc.bold(rules)} specified in firebase.json does not exist.`
);
}
} else {
utils.logWarning(`No Firestore rules file specified in firebase.json, using default rules.`);
utils.logLabeledWarning(
"firestore",
"Did not find a Cloud Firestore rules file specified in a firebase.json config file."
);
}

if (!foundRulesFile) {
utils.logLabeledWarning(
"firestore",
"The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration."
);
}

const firestoreEmulator = new FirestoreEmulator(args);
Expand Down Expand Up @@ -282,19 +299,31 @@ export async function startAll(options: any, noGui: boolean = false): Promise<vo
}

const rulesLocalPath = options.config.get("database.rules");
const foundRulesFile = rulesLocalPath && fs.existsSync(rulesLocalPath);
if (rulesLocalPath) {
const rules: string = path.join(options.projectRoot, rulesLocalPath);
if (fs.existsSync(rules)) {
args.rules = rules;
} else {
utils.logWarning(
`Database rules file ${clc.bold(
utils.logLabeledWarning(
"database",
`Realtime Database rules file ${clc.bold(
rules
)} specified in firebase.json does not exist, starting Database emulator without rules.`
)} specified in firebase.json does not exist.`
);
}
} else {
utils.logWarning(`No Database rules file specified in firebase.json, using default rules.`);
utils.logLabeledWarning(
"database",
"Did not find a Realtime Database rules file specified in a firebase.json config file."
);
}

if (!foundRulesFile) {
utils.logLabeledWarning(
"database",
"The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration."
);
}

const databaseEmulator = new DatabaseEmulator(args);
Expand Down

0 comments on commit 2605a98

Please sign in to comment.