Skip to content

Commit

Permalink
Merge 9500cdf into 1386ad7
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpbrewster committed Jan 10, 2019
2 parents 1386ad7 + 9500cdf commit 4132685
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/emulator/download.js
Expand Up @@ -2,17 +2,22 @@

const FirebaseError = require("../error");
const fs = require("fs-extra");
const tmp = require("tmp");
const request = require("request");
const emulatorConstants = require("./constants");
const utils = require("../utils");

tmp.setGracefulCleanup();

module.exports = (name) => {
return new Promise((resolve, reject) => {
utils.logLabeledBullet(name, "downloading emulator...");
let emulator = emulatorConstants.emulators[name];
fs.ensureDirSync(emulator.cacheDir);

let tmpFile = tmp.fileSync();
let req = request.get(emulator.remoteUrl);
let writeStream = fs.createWriteStream(emulator.localPath);
let writeStream = fs.createWriteStream(tmpFile.name);
req.on("error", (err) => reject(err));
req.on("response", (response) => {
if (response.statusCode != 200) {
Expand All @@ -21,6 +26,7 @@ module.exports = (name) => {
});
req.on("end", () => {
writeStream.close();
fs.copySync(tmpFile.name, emulator.localPath);
fs.chmodSync(emulator.localPath, 0o755);
resolve();
});
Expand Down

0 comments on commit 4132685

Please sign in to comment.