2017-10-15 13:02:08 +00:00
|
|
|
const gulp = require("gulp");
|
|
|
|
const fs = require("fs");
|
2017-09-12 22:34:25 +00:00
|
|
|
|
2017-10-23 08:29:59 +00:00
|
|
|
gulp.task("default", function () {
|
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"});
|
2017-11-02 20:13:26 +00:00
|
|
|
let standardContents;
|
|
|
|
try {
|
|
|
|
standardContents = JSON.parse(fileContents);
|
|
|
|
} catch (e) {
|
|
|
|
console.log("Invalid JSON in " + next);
|
|
|
|
throw e;
|
|
|
|
}
|
2017-10-23 08:29:59 +00:00
|
|
|
|
|
|
|
const stdName = standardContents.info.name;
|
|
|
|
const stdSubName = standardContents.info.subsection_name;
|
|
|
|
const nameParts = [stdName, stdSubName].filter(part => !!part);
|
|
|
|
|
2017-10-21 15:39:08 +00:00
|
|
|
const standardIdentifier = nameParts.join(": ").trim();
|
|
|
|
standardContents.info.identifier = standardIdentifier;
|
|
|
|
prev[standardIdentifier] = standardContents;
|
2017-09-12 22:34:25 +00:00
|
|
|
return prev;
|
|
|
|
}, {});
|
|
|
|
|
2017-10-23 08:29:59 +00:00
|
|
|
let renderedStandardsModule = builtScriptComment + "\n";
|
|
|
|
renderedStandardsModule += "window.WEB_API_MANAGER.standards = ";
|
|
|
|
renderedStandardsModule += JSON.stringify(combinedStandards) + ";";
|
2017-09-12 22:34:25 +00:00
|
|
|
|
2017-10-21 15:49:56 +00:00
|
|
|
fs.writeFileSync("add-on/lib/standards.js", renderedStandardsModule);
|
2017-09-12 22:34:25 +00:00
|
|
|
});
|