web-api-manager/gulpfile.js

36 lines
1.3 KiB
JavaScript
Raw Normal View History

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 builtScriptComment = "/** This file is automatically generated. **/\n";
const standardsDefDir = "data/standards";
2017-09-12 22:34:25 +00:00
// Build all the standards listings into a single features.js file.
const combinedStandards = fs.readdirSync(standardsDefDir)
2017-09-12 22:34:25 +00:00
.reduce(function (prev, next) {
if (next.indexOf(".json") === -1) {
return prev;
}
const fileContents = fs.readFileSync(standardsDefDir + "/" + next, {encoding: "utf8"});
const standardContents = JSON.parse(fileContents);
const stdName = standardContents.info.name;
const stdSubName = standardContents.info.subsection_name;
const nameParts = [stdName, stdSubName].filter(part => !!part);
const standardIdentifier = nameParts.join(": ").trim();
standardContents.info.identifier = standardIdentifier;
prev[standardIdentifier] = standardContents;
2017-09-12 22:34:25 +00:00
return prev;
}, {});
let renderedStandardsModule = builtScriptComment + "\n";
renderedStandardsModule += "window.WEB_API_MANAGER.standards = ";
renderedStandardsModule += JSON.stringify(combinedStandards) + ";";
2017-09-12 22:34:25 +00:00
fs.writeFileSync("add-on/lib/standards.js", renderedStandardsModule);
2017-09-12 22:34:25 +00:00
});