1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-01-18 06:08:20 +01:00
BezierInfo-2/tools/aggregate-js-handlers.js
2017-03-26 11:41:20 -07:00

34 lines
1.3 KiB
JavaScript

/**********************************************************************
*
* This script is a JS handling aggregator that grabs all handler.js
* files defined for any section, and turns it into a giant master
* handler file for later use, keyed on section dir names.
*
**********************************************************************/
var fs = require("fs-extra");
var glob = require('glob');
var path = require("path");
var jsxshim = require("./lib/jsx-shim");
const BASEDIR = path.join(__dirname, "..");
var index = require(path.join(BASEDIR, "components/sections"));
var handlers = [];
Object.keys(index).forEach( section => {
var handlerFile = path.join(BASEDIR, `components/sections/${section}/handler.js`);
if (fs.existsSync(handlerFile)) {
let content = fs.readFileSync(handlerFile).toString();
content = content.replace("module.exports = ","return ");
content = `(function() { ${content} }())`;
let def = ` "${section}": {
handler: ${content}`;
if (content.indexOf('keyHandlingOptions') > -1) { def += `,\n withKeys: true`; }
def += `\n }`;
handlers.push(def);
}
});
var masterFile = `window["Bezier Section Handlers"] = {\n${ handlers.join(',\n') }\n};\n`;
fs.writeFileSync(path.join(BASEDIR, "lib/site/handlers.js"), masterFile);