mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-06 16:56:57 +02:00
safety
This commit is contained in:
33
tools/aggregate-js-handlers.js
Normal file
33
tools/aggregate-js-handlers.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* 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 = `module.exports = {\n${ handlers.join(',\n') }\n};\n`;
|
||||
fs.writeFileSync(path.join(BASEDIR, "lib/site/handlers.js"), masterFile);
|
Reference in New Issue
Block a user