A few final fixes (#298)

This commit is contained in:
Michael Bleigh
2018-08-09 10:40:00 -07:00
committed by GitHub
parent 9457c74081
commit b77ef9759f
3 changed files with 24 additions and 12 deletions

View File

@@ -2,10 +2,16 @@ const fs = require("fs-extra");
const path = require("path");
const logger = require("../../logger");
exports.load = function(cwd) {
function cachePath(cwd, name) {
return path.resolve(cwd, ".firebase/hosting." + name + ".cache");
}
exports.load = function(cwd, name) {
try {
const out = {};
lines = fs.readFileSync(path.resolve(cwd, ".firebase/hostingcache"), { encoding: "utf8" });
lines = fs.readFileSync(cachePath(cwd, name), {
encoding: "utf8",
});
lines.split("\n").forEach(function(line) {
const d = line.split(",");
if (d.length === 3) {
@@ -15,21 +21,21 @@ exports.load = function(cwd) {
return out;
} catch (e) {
if (e.code === "ENOENT") {
logger.debug("[hosting] hash cache not populated");
logger.debug("[hosting] hash cache [" + name + "] not populated");
} else {
logger.debug("[hosting] hash cache load error:", e.message);
logger.debug("[hosting] hash cache [" + name + "] load error:", e.message);
}
return {};
}
};
exports.dump = function(cwd, data) {
exports.dump = function(cwd, name, data) {
let st = "";
let count = 0;
for (let path in data) {
count++;
st += path + "," + data[path].mtime + "," + data[path].hash + "\n";
}
fs.outputFileSync(path.resolve(cwd, ".firebase/hostingcache"), st, { encoding: "utf8" });
logger.debug("[hosting] hash cache stored for", count, "files");
fs.outputFileSync(cachePath(cwd, name), st, { encoding: "utf8" });
logger.debug("[hosting] hash cache [" + name + "] stored for", count, "files");
};

View File

@@ -32,7 +32,7 @@ class Uploader {
this.version = options.version;
this.cwd = options.cwd || process.cwd();
this.cache = hashcache.load(this.cwd);
this.cache = hashcache.load(this.cwd, "0");
this.cacheNew = {};
this.gzipLevel = options.gzipLevel || 9;
@@ -78,7 +78,7 @@ class Uploader {
.wait()
.then(self.queuePopulate.bind(self))
.then(function() {
hashcache.dump(self.cwd, self.cacheNew);
hashcache.dump(self.cwd, "0", self.cacheNew);
logger.debug("[hosting][hash queue][FINAL]", self.hashQueue.stats());
self.populateQueue.close();
return self.populateQueue.wait();

View File

@@ -37,7 +37,13 @@
"bugs": {
"url": "https://github.com/firebase/firebase-tools/issues"
},
"files": ["bin/**", "lib/**", "commands/**", "templates/**", "index.js"],
"files": [
"bin/**",
"lib/**",
"commands/**",
"templates/**",
"index.js"
],
"homepage": "https://github.com/firebase/firebase-tools",
"dependencies": {
"JSONStream": "^1.2.1",
@@ -68,9 +74,9 @@
"ora": "0.2.3",
"portfinder": "^1.0.13",
"progress": "^2.0.0",
"request": "^2.58.0",
"request": "^2.87.0",
"semver": "^5.0.3",
"superstatic": "^5.0.2",
"superstatic": "^6.0.1",
"tar": "^4.3.0",
"tmp": "0.0.33",
"universal-analytics": "^0.4.16",