UNPKG

basecamp-guide

Version:
103 lines (82 loc) 3.28 kB
// Dependecies var Colors = require('colors'); var FileSys = require('./FileSystem.js'); var FileContent = require('./FileContent.js'); var Feedback = require('./Feedback.js'); var p = require('path'); /** * * Configs the config app file of Laravel * */ var LaravelAppConfig = (function() { // private variables var config = { provider : { file : 'config/app.php', comment : 'Basecamp Providers...', namespace : 'Basecamp\\Providers\\' }, middleware : { file : 'app/Http/Kernel.php' } }; // private methods var parseProviderClass = function(provider) { return '\n ' + config.provider.namespace + provider + '::class,'; }; var getParsedComment = function() { return ' /*\n * ' + config.provider.comment + '\n */'; }; var parseStyleImport = function(lib) { return "\n@import '" + lib + "'"; }; var parseVueViewImport = function(view) { return "\nvar "+p.basename(view, '.js') +" = new Vue(require('"+ view +"'));"; }; var parseRouteMiddleware = function(middleware, alias) { return " '" + alias + "' => \\Basecamp\\Middleware\\"+ middleware +"::class,\n "; }; return { // public functions addProvider : function(provider) { FileSys.modifyFile(config.provider.file, function(content) { if (content.get().search(config.provider.comment) < 0) content.addBetween('providers\' => [', ']', getParsedComment() + '\n\n'); var action = content.addAfter(getParsedComment(), parseProviderClass(provider)); Feedback.tell(action, provider); return content; }); }, addRouteMiddleware : function(middleware, alias) { FileSys.modifyFile(config.middleware.file, function(content) { var action = content.addBetween('protected $routeMiddleware = [', '];', parseRouteMiddleware(middleware, alias)); Feedback.tell(action, middleware); return content; }); }, addStyleDependecy : function(library, file) { FileSys.modifyFile(file, function(content) { var action = content.addAfter("'basecamp-design/design'", parseStyleImport(library)); Feedback.tell(action, library); return content; }); }, addVueViewDependecy : function(view, file) { FileSys.modifyFile(file, function(content) { var action = content.addAfter('// Views', parseVueViewImport(view)); Feedback.tell(action, view); return content; }); }, addENV : function(name, value) { FileSys.modifyFile('.env', function(content) { var contentToAdd = name + '=' + value; var parsedContentToAdd = '\n' + contentToAdd; var action = content.add(parsedContentToAdd); Feedback.tell(action, contentToAdd); return content; }); }, }; })(); module.exports = LaravelAppConfig;