From 7dc25d55d8fec7520ac37849ce957da1e75ba610 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Fri, 15 Jun 2018 13:00:36 -0400 Subject: [PATCH] testing line checking --- dev/app.scss | 10 +++---- dev/modules.php | 8 ++--- setup/moduleLib.js | 75 +++++++++++++++++++++++++++++++++++++++++----- setup/renderer.js | 18 ----------- 4 files changed, 77 insertions(+), 34 deletions(-) diff --git a/dev/app.scss b/dev/app.scss index 06ac902..8a17547 100644 --- a/dev/app.scss +++ b/dev/app.scss @@ -5,9 +5,9 @@ @import "foundation"; @import "core/header/header"; @import "core/topbar/topbar"; -@import "core/interior-page/interior-page"; +// @import "core/interior-page/interior-page"; @import "core/front-page/front-page"; -@import "core/blog/blog"; +// @import "core/blog/blog"; @import "core/off-canvas/off-canvas"; @import "core/off-canvas-overlay/off-canvas-overlay"; @import "core/footer/footer"; @@ -15,12 +15,12 @@ /*Custom Modules */ @import "custom/sidebar/sidebar"; @import "custom/slideshow/slideshow"; -@import "custom/gravity-forms/gravity-forms"; +// @import "custom/gravity-forms/gravity-forms"; @import "custom/weather/weather"; @import "custom/nextgen/nextgen"; @import "custom/glma/glm-member-db"; -@import "custom/glma/glm-member-db-events"; +// @import "custom/glma/glm-member-db-events"; @import "custom/blocks/glm-blocks"; @import "custom/action-items/action-items"; @import "custom/svg-map/svg-map"; -@import "custom/woocommerce/woocommerce"; \ No newline at end of file +// // // @import "custom/woocommerce/woocommerce"; \ No newline at end of file diff --git a/dev/modules.php b/dev/modules.php index 30796e0..60547aa 100644 --- a/dev/modules.php +++ b/dev/modules.php @@ -4,14 +4,14 @@ require_once('core/header/functions/header.php'); require_once('core/topbar/functions/topbar.php'); require_once('core/footer/functions/footer.php'); require_once('core/front-page/functions/front-page.php'); -require_once('core/interior-page/functions/interior-page.php'); +// require_once('core/interior-page/functions/interior-page.php'); require_once('core/off-canvas/functions/off-canvas.php'); require_once('core/off-canvas-overlay/functions/off-canvas-overlay.php'); -require_once('core/blog/functions/blog.php'); +// require_once('core/blog/functions/blog.php'); /* Custom Modules */ -require_once('custom/gravity-forms/functions/gravity-forms.php'); -require_once('custom/woocommerce/functions/woocommerce.php'); +// require_once('custom/gravity-forms/functions/gravity-forms.php'); +// // // require_once('custom/woocommerce/functions/woocommerce.php'); require_once('custom/svg-map-forms/functions/svg-map.php'); require_once('custom/sidebar/functions/sidebar.php'); require_once('custom/nextgen/functions/nextgen.php'); diff --git a/setup/moduleLib.js b/setup/moduleLib.js index de66f48..35324cf 100644 --- a/setup/moduleLib.js +++ b/setup/moduleLib.js @@ -1,3 +1,22 @@ +String.prototype.stringFromToken = function(position, token, lastToken = false, string = false){ + let length = 1; + if(string) length = token.length; + + if(lastToken && position === 'before'){ + return this.substr(0, this.lastIndexOf(token)) + }else if(lastToken && !postition === 'before'){ + return this.substr(this.lastIndexOf(token) + length); + }else { + if(position === 'before'){ + return this.substr(0, this.indexOf(token)) + }else{ + return this.substr(this.indexOf(token)+length) + } + } +} +String.prototype.stripSlashes = function(){ + return this.replace(/\\(.)/mg, "$1"); +} const modLib = (function() { let appState = {}; let fs = require('fs'); @@ -13,16 +32,24 @@ const modLib = (function() { input: fs.createReadStream(filePath) }); }, + checkLine: function(line, mod){ - if ( modLib.moduleFound(line, mod)){ - console.log(line) + if ( modLib.moduleFound(line, mod) && modLib.isValidLine(line, mod)){ + return true + } else { + return false; } }, + editFile: function(reader,mod){ reader.on("line",function(line){ - modLib.checkLine(line, mod) + let file = (this.input.path.indexOf("scss") > -1) ? 'sass' : 'php'; + if(modLib.checkLine(line, mod)){ + modLib.deactivateModule(line, mod, file) + } }) }, + moduleFound(line,mod){ if(modLib.isValidLine(line, mod) ){ if(line.indexOf(`${mod.name}"`) > -1 || line.indexOf(`${mod.name}.php`) > -1){ @@ -32,9 +59,38 @@ const modLib = (function() { } } }, - deactivateModule(mod, line){ - + + deactivateModule(line, mod, file){ + let pathString = (file === "sass") ? mod.sass.sassFile : mod.functions.functionsFile; + if(!mod.active){ + + // conver to function + fs.readFile(pathString, 'utf8', function (err,data) { + if (err) { + return console.log(err); + } + result = data.replace(line, `// ${line}`); + + fs.writeFile(pathString, result, 'utf8', function (err) { + if (err) return console.log(err); + }); + }); + } else{ + console.log("active") + fs.readFile(pathString, 'utf8', function (err,data) { + if (err) { + return console.log(err); + } + console.log(data); + result = data.replace(line, line.stripSlashes()); + + fs.writeFile(pathString, result, 'utf8', function (err) { + if (err) return console.log(err); + }); + }); + } }, + isValidLine(line){ let valid = false; for (var i = 0; i < acceptedToken.length; i++) { @@ -47,13 +103,16 @@ const modLib = (function() { } return valid; }, + setModules: function(modType,modName){ appState[modType] = modName; return appState; }, + moduleActive(mod){ return mod.active; }, + storeModules: function(appState){ localStorage.setItem("app", JSON.stringify(appState)); }, @@ -134,10 +193,12 @@ const modLib = (function() { scanDevDir: function(){ var slash = modLib.getDirSlash(); + let devPath = require('path').join(__dirname, `../dev`); if(modLib.getModules() === null){ [`dev${slash}core`, `dev${slash}custom`].forEach(function(dirPath) { let modType = dirPath.stringFromToken('after', `${slash}`); let fullPath = require('path').join(__dirname, `../${dirPath}`); + let mods = []; fs.readdir(fullPath, function(err, item) { item.forEach(function(modName){ @@ -147,8 +208,8 @@ const modLib = (function() { modType: modType, active: true, path: `${fullPath}${slash}${modName}`, - sass: {lineRef:` ${reference}${slash}${modName}`, sassFile: `dev${slash}app${slash}scss`}, - functions: {lineRef: `${reference}${slash}functions${slash}${modName}.php`, functionsfile: `dev${slash}modules.php`}, + sass: {lineRef:` ${reference}${slash}${modName}`, sassFile: `${devPath}${slash}app.scss`}, + functions: {lineRef: `${reference}${slash}functions${slash}${modName}.php`, functionsFile: `${devPath}${slash}modules.php`}, reference:reference }); }); diff --git a/setup/renderer.js b/setup/renderer.js index 5fd7743..3bff5b1 100644 --- a/setup/renderer.js +++ b/setup/renderer.js @@ -2,25 +2,7 @@ const merge = require('merge-stream'); const dir = require('node-dir'); const lib = require('./moduleLib'); -String.prototype.stringFromToken = function(position, token, lastToken = false, string = false){ - let length = 1; - if(string) length = token.length; - if(lastToken && position === 'before'){ - return this.substr(0, this.lastIndexOf(token)) - }else if(lastToken && !postition === 'before'){ - return this.substr(this.lastIndexOf(token) + length); - }else { - if(position === 'before'){ - return this.substr(0, this.indexOf(token)) - }else{ - return this.substr(this.indexOf(token)+length) - } - } -} -String.prototype.stripSlashes = function(){ - return this.replace(/\\(.)/mg, "$1"); -} $(document).on("click", '.module-item', function(){ _ = $(this); -- 2.17.1