Skip to content

Commit

Permalink
Merge caedba2 into 826451f
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenshi committed Dec 18, 2019
2 parents 826451f + caedba2 commit b8efc6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,3 +1,4 @@
* Clean up extraneous error messages in extensions commands.
* Adds breakpoint debugging for the Cloud Functions emulator using the `--inspect-functions` flag (#1360).
* Adds the ability for the Hosting emulator start offline through `emulators:start` (#1854).
* Adds the ability for the Hosting emulator start offline through `emulators:start` (#1854).
* Sets the GCLOUD_PROJECT environment variable for scripts ran through 'emulators:exec'.
12 changes: 9 additions & 3 deletions src/commands/emulators-exec.ts
Expand Up @@ -12,11 +12,12 @@ import { DatabaseEmulator } from "../emulator/databaseEmulator";
import { EmulatorRegistry } from "../emulator/registry";
import { FirestoreEmulator } from "../emulator/firestoreEmulator";
import * as commandUtils from "../emulator/commandUtils";
import * as getProjectId from "../getProjectId";

async function runScript(script: string): Promise<number> {
async function runScript(script: string, extraEnv: Record<string, string>): Promise<number> {
utils.logBullet(`Running script: ${clc.bold(script)}`);

const env: NodeJS.ProcessEnv = { ...process.env };
const env: NodeJS.ProcessEnv = { ...process.env, ...extraEnv };

const databaseInstance = EmulatorRegistry.get(Emulators.DATABASE);
if (databaseInstance) {
Expand Down Expand Up @@ -84,10 +85,15 @@ module.exports = new Command("emulators:exec <script>")
.option(commandUtils.FLAG_ONLY, commandUtils.DESC_ONLY)
.option(commandUtils.FLAG_INSPECT_FUNCTIONS, commandUtils.DESC_INSPECT_FUNCTIONS)
.action(async (script: string, options: any) => {
const projectId = getProjectId(options, true);
const extraEnv: Record<string, string> = {};
if (projectId) {
extraEnv.GCLOUD_PROJECT = projectId;
}
let exitCode = 0;
try {
await controller.startAll(options);
exitCode = await runScript(script);
exitCode = await runScript(script, extraEnv);
} catch (e) {
logger.debug("Error in emulators:exec", e);
throw e;
Expand Down

0 comments on commit b8efc6f

Please sign in to comment.