2017-10-13 07:32:41 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const fs = require('fs');
|
2017-09-12 22:34:25 +00:00
|
|
|
|
|
|
|
gulp.task('default', function () {
|
|
|
|
|
2017-10-13 22:30:57 +00:00
|
|
|
const isLineAComment = function (aLine) {
|
|
|
|
const lineStartsWithComment = (
|
|
|
|
aLine.indexOf("// ") === 0 ||
|
|
|
|
aLine.indexOf("/*") === 0 ||
|
|
|
|
aLine.indexOf(" */") === 0 ||
|
|
|
|
aLine.indexOf(" * ") === 0
|
|
|
|
);
|
|
|
|
return lineStartsWithComment;
|
2017-10-14 04:23:49 +00:00
|
|
|
};
|
2017-10-13 22:30:57 +00:00
|
|
|
|
|
|
|
const builtScriptComment = "/** This file is automatically generated. **/\n";
|
2017-10-13 07:32:41 +00:00
|
|
|
const standardsDefDir = "data/standards";
|
2017-09-12 22:34:25 +00:00
|
|
|
|
|
|
|
// Build all the standards listings into a single features.js file.
|
2017-10-13 07:32:41 +00:00
|
|
|
const combinedStandards = fs.readdirSync(standardsDefDir)
|
2017-09-12 22:34:25 +00:00
|
|
|
.reduce(function (prev, next) {
|
|
|
|
|
|
|
|
if (next.indexOf(".json") === -1) {
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
2017-10-13 07:32:41 +00:00
|
|
|
const fileContents = fs.readFileSync(standardsDefDir + "/" + next, {encoding: "utf8"});
|
|
|
|
const standardContents = JSON.parse(fileContents);
|
2017-10-14 04:23:49 +00:00
|
|
|
const nameParts = [standardContents.info.name, standardContents.info.subsection_name].filter(part => !!part);
|
|
|
|
const standardIdenitifer = nameParts.join(": ").trim();
|
|
|
|
standardContents.info.idenitifer = standardIdenitifer;
|
|
|
|
prev[standardIdenitifer] = standardContents;
|
2017-09-12 22:34:25 +00:00
|
|
|
return prev;
|
|
|
|
}, {});
|
|
|
|
|
2017-10-13 22:30:57 +00:00
|
|
|
const renderedStandardsModule = builtScriptComment + `window.WEB_API_MANAGER.standards = ${JSON.stringify(combinedStandards)};`;
|
2017-09-12 22:34:25 +00:00
|
|
|
|
2017-10-13 07:32:41 +00:00
|
|
|
fs.writeFileSync("content_scripts/dist/standards.js", renderedStandardsModule);
|
|
|
|
|
|
|
|
const proxyBlockSrc = fs.readFileSync("content_scripts/src/proxyblock.js", "utf8");
|
|
|
|
const instrumentSrc = fs.readFileSync("content_scripts/src/instrument.js", "utf8");
|
2017-10-14 04:23:49 +00:00
|
|
|
|
2017-10-13 07:32:41 +00:00
|
|
|
const stripCommentsFromSource = function (source) {
|
|
|
|
const fileLines = source.split("\n");
|
2017-10-13 22:30:57 +00:00
|
|
|
const linesWithoutComments = fileLines.filter(aLine => !isLineAComment(aLine));
|
2017-10-13 07:32:41 +00:00
|
|
|
return linesWithoutComments.join("\n");
|
|
|
|
};
|
2017-10-14 04:23:49 +00:00
|
|
|
|
2017-10-13 07:32:41 +00:00
|
|
|
const proxyBlockSrcWOComments = stripCommentsFromSource(proxyBlockSrc);
|
|
|
|
const instrumentSrcWOComments = stripCommentsFromSource(instrumentSrc);
|
|
|
|
const instrumentSrcWithProxyInjected = instrumentSrcWOComments.replace(
|
|
|
|
"###-INJECTED-PROXY-BLOCKING-CODE-###",
|
|
|
|
proxyBlockSrcWOComments
|
|
|
|
);
|
|
|
|
|
2017-10-13 22:30:57 +00:00
|
|
|
fs.writeFileSync("content_scripts/dist/instrument.js", builtScriptComment + instrumentSrcWithProxyInjected);
|
2017-10-13 07:32:41 +00:00
|
|
|
|
|
|
|
// Last, several content script files are just copied over, unmodified,
|
|
|
|
// as script files to be injected.
|
2017-10-13 22:30:57 +00:00
|
|
|
const srcFilesToCopy = ["defaults.js"];
|
2017-10-13 07:32:41 +00:00
|
|
|
srcFilesToCopy.forEach(function (aSrcPath) {
|
2017-10-13 22:30:57 +00:00
|
|
|
const scriptSrc = fs.readFileSync("content_scripts/src/" + aSrcPath, "utf8");
|
|
|
|
const scriptSrcWOComments = stripCommentsFromSource(scriptSrc);
|
|
|
|
fs.writeFileSync("content_scripts/dist/" + aSrcPath, builtScriptComment + scriptSrcWOComments);
|
2017-10-13 07:32:41 +00:00
|
|
|
});
|
2017-09-12 22:34:25 +00:00
|
|
|
});
|