Skip to content

Commit

Permalink
[Refactoring] convert serve/index.js to typescript code (#1873)
Browse files Browse the repository at this point in the history
* serve/index.js to typescript

* convert serve/index js to typescript code

* change require to import

* change export serve and fix relative source

* convert arrow function

* function serve return type

* add jsdoc

* refactoring  remove `const target `
  • Loading branch information
iida-hayato authored and bkendall committed Jan 7, 2020
1 parent 859e966 commit 9ca80cf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var utils = require("../utils");
var { requirePermissions } = require("../requirePermissions");
var requireConfig = require("../requireConfig");
var checkDupHostingKeys = require("../checkDupHostingKeys");
var serve = require("../serve/index");
var { serve } = require("../serve/index");
var filterTargets = require("../filterTargets");
var getProjectNumber = require("../getProjectNumber");

Expand Down
48 changes: 0 additions & 48 deletions src/serve/index.js

This file was deleted.

45 changes: 45 additions & 0 deletions src/serve/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { EmulatorServer } from "../emulator/emulatorServer";
import * as _ from "lodash";
import * as logger from "../logger";

const TARGETS: {
[key: string]:
| EmulatorServer
| { start: (o: any) => void; stop: (o: any) => void; connect: () => void };
} = {
hosting: require("./hosting"),
functions: require("./functions"),
database: require("./database"),
firestore: require("./firestore"),
};

/**
* Serve runs the emulators for a set of targets provided in options.
* @param options Firebase CLI options.
*/
export async function serve(options: any): Promise<void> {
const targetNames = options.targets;
options.port = parseInt(options.port, 10);
await Promise.all(
_.map(targetNames, (targetName: string) => {
return TARGETS[targetName].start(options);
})
);
await Promise.all(
_.map(targetNames, (targetName: string) => {
return TARGETS[targetName].connect();
})
);
await new Promise((resolve) => {
process.on("SIGINT", () => {
logger.info("Shutting down...");
return Promise.all(
_.map(targetNames, (targetName: string) => {
return TARGETS[targetName].stop(options);
})
)
.then(resolve)
.catch(resolve);
});
});
}

0 comments on commit 9ca80cf

Please sign in to comment.