report-processor refactored to use stream-buffers

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent 945426d2e8
commit 8f1f4269ef
  1. 45
      BuildServer/lib/report-processor.js
  2. 65
      BuildServer/package.json

@ -3,27 +3,42 @@
const path = require("path"); const path = require("path");
const fs = require("fs"); const fs = require("fs");
const glob = require("glob"); const glob = require("glob");
const streamBuffers = require("stream-buffers");
const _ = require("underscore"); const _ = require("underscore");
const writeReport = (releaseDir, err, result, callback) => fs.writeFile(path.join(releaseDir, "report.json"), JSON.stringify({ const writeReport = (releaseDir, err, result, callback) => {
"date": Date.now(), const readable = new streamBuffers.ReadableStreamBuffer();
err,
result
}), callback);
const readReport = (releaseDir, callback) => fs.readFile(path.join(releaseDir, "report.json"), (err, dataBuffer) => { readable
if (err) { .pipe(fs.createWriteStream(path.join(releaseDir, "report.json")))
return callback(err); .on("error", callback)
} .on("finish", callback);
const data = dataBuffer.toString(); readable.put(JSON.stringify({
"date": Date.now(),
err,
result
}));
readable.stop();
};
const readReport = (releaseDir, callback) => {
const writable = new streamBuffers.WritableStreamBuffer();
const readStream = fs.createReadStream(path.join(releaseDir, "report.json"));
readStream
.pipe(writable)
.on("error", callback)
.on("finish", () => {
const data = writable.getContentsAsString();
if (!data) { if (!data) {
return callback("ReportFileNotFound"); return callback("ReportFileNotFound");
} }
return callback(null, JSON.parse(data)); return callback(null, JSON.parse(data));
}); });
};
exports.writeReport = writeReport; exports.writeReport = writeReport;

@ -26,6 +26,7 @@
"recursive-tree-copy": "0.0.1", "recursive-tree-copy": "0.0.1",
"serve-favicon": "^2.3.2", "serve-favicon": "^2.3.2",
"serve-static": "^1.11.1", "serve-static": "^1.11.1",
"stream-buffers": "^3.0.1",
"uglify-js": "^2.7.5", "uglify-js": "^2.7.5",
"underscore": "^1.8.3" "underscore": "^1.8.3"
}, },
@ -38,19 +39,61 @@
}, },
"extends": "eslint:all", "extends": "eslint:all",
"rules": { "rules": {
"quotes": ["warn", "double"], "quotes": [
"warn",
"double"
],
"require-jsdoc": "off", "require-jsdoc": "off",
"func-names": ["warn", "never"], "func-names": [
"max-len": ["warn", { "code": 140 }], "warn",
"operator-linebreak": ["warn", "before"], "never"
"padded-blocks": ["warn", "never"], ],
"dot-notation": ["warn", { "allowPattern": "^[a-z]+(_[a-z]+)+$" }], "max-len": [
"linebreak-style": ["warn", "windows"], "warn",
{
"code": 140
}
],
"operator-linebreak": [
"warn",
"before"
],
"padded-blocks": [
"warn",
"never"
],
"dot-notation": [
"warn",
{
"allowPattern": "^[a-z]+(_[a-z]+)+$"
}
],
"linebreak-style": [
"warn",
"windows"
],
"no-console": "off", "no-console": "off",
"dot-location": ["warn", "property"], "dot-location": [
"object-curly-spacing": ["warn", "always"], "warn",
"one-var": ["warn", { "initialized": "never" }], "property"
"no-extra-parens": ["warn", "all", { "nestedBinaryExpressions": false }] ],
"object-curly-spacing": [
"warn",
"always"
],
"one-var": [
"warn",
{
"initialized": "never"
}
],
"no-extra-parens": [
"warn",
"all",
{
"nestedBinaryExpressions": false
}
]
} }
} }
} }

Loading…
Cancel
Save