-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactoring] convert serve/index.js to typescript code (#1873)
* 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
1 parent
859e966
commit 9ca80cf
Showing
3 changed files
with
46 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
} |