diff --git a/Gruntfile.js b/Gruntfile.js index 36c054445f..fa4ceed1e9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -17,17 +17,20 @@ module.exports = function(grunt) { args.push('--log-level=info'); } - if (target === 'lessUpdated') { - fromFile = ['js','tpl']; - compiling = 'less'; + if (target === 'lessUpdated_Client') { + fromFile = ['js', 'tpl', 'acpLess']; + compiling = 'clientLess'; + } else if (target === 'lessUpdated_Admin') { + fromFile = ['js', 'tpl', 'clientLess']; + compiling = 'acpLess'; } else if (target === 'clientUpdated') { - fromFile = ['less','tpl']; + fromFile = ['clientLess', 'acpLess', 'tpl']; compiling = 'js'; } else if (target === 'templatesUpdated') { - fromFile = ['js','less']; + fromFile = ['js', 'clientLess', 'acpLess']; compiling = 'tpl'; } else if (target === 'serverUpdated') { - fromFile = ['less','js','tpl']; + fromFile = ['clientLess', 'acpLess', 'js', 'tpl']; } fromFile = fromFile.filter(function(ext) { @@ -53,8 +56,11 @@ module.exports = function(grunt) { grunt.initConfig({ watch: { - lessUpdated: { - files: ['public/**/*.less', 'node_modules/nodebb-*/*.less', 'node_modules/nodebb-*/*/*.less', 'node_modules/nodebb-*/*/*/*.less', 'node_modules/nodebb-*/*/*/*/*.less'] + lessUpdated_Client: { + files: ['public/*.less', 'node_modules/nodebb-*/*.less', 'node_modules/nodebb-*/*/*.less', 'node_modules/nodebb-*/*/*/*.less', 'node_modules/nodebb-*/*/*/*/*.less'] + }, + lessUpdated_Admin: { + files: ['public/**/*.less'] }, clientUpdated: { files: ['public/src/**/*.js', 'node_modules/nodebb-*/*.js', 'node_modules/nodebb-*/*/*.js', 'node_modules/nodebb-*/*/*/*.js', 'node_modules/nodebb-*/*/*/*/*.js', 'node_modules/templates.js/lib/templates.js'] diff --git a/src/meta/css.js b/src/meta/css.js index 172c2bf0e6..09ed87af55 100644 --- a/src/meta/css.js +++ b/src/meta/css.js @@ -80,11 +80,22 @@ module.exports = function(Meta) { source = '@import "./theme";\n' + source; + var fromFile = nconf.get('from-file') || ''; async.parallel([ function(next) { + if (fromFile.match('clientLess')) { + winston.info('[minifier] Compiling front-end LESS files skipped'); + return Meta.css.getFromFile(path.join(__dirname, '../../public/stylesheet.css'), Meta.css.cache, next); + } + minify(source, paths, 'cache', next); }, function(next) { + if (fromFile.match('acpLess')) { + winston.info('[minifier] Compiling ACP LESS files skipped'); + return Meta.css.getFromFile(path.join(__dirname, '../../public/admin.css'), Meta.css.acpCache, next); + } + minify(acpSource, paths, 'acpCache', next); } ], function(err, minified) { @@ -151,28 +162,12 @@ module.exports = function(Meta) { }); }; - Meta.css.getFromFile = function(callback) { - var cachePath = path.join(__dirname, '../../public/stylesheet.css'), - acpCachePath = path.join(__dirname, '../../public/admin.css'); - file.exists(cachePath, function(exists) { - if (!exists) { - winston.warn('[meta/css] No stylesheets found on disk, re-minifying'); - Meta.css.minify(callback); - return; - } - - if (nconf.get('isPrimary') !== 'true') { - return callback(); - } - - winston.verbose('[meta/css] Reading stylesheets from file'); - async.map([cachePath, acpCachePath], fs.readFile, function(err, files) { - Meta.css.cache = files[0]; - Meta.css.acpCache = files[1]; + Meta.css.getFromFile = function(filePath, cache, callback) { + winston.verbose('[meta/css] Reading stylesheet ' + filePath.split('/').pop() + ' from file'); - emitter.emit('meta:css.compiled'); - callback(); - }); + fs.readFile(filePath, function(err, file) { + cache = file; + callback(); }); }; diff --git a/src/webserver.js b/src/webserver.js index 32ab6c2a59..1db202e520 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -78,11 +78,6 @@ function initializeNodeBB(callback) { skipJS = true; } - if (fromFile.match('less')) { - winston.info('[minifier] Compiling LESS files skipped'); - skipLess = true; - } - async.waterfall([ async.apply(cacheStaticFiles), async.apply(meta.themes.setupPaths), @@ -94,7 +89,7 @@ function initializeNodeBB(callback) { async.apply(meta.templates.compile), async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'nodebb.min.js'), async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'acp.min.js'), - async.apply(!skipLess ? meta.css.minify : meta.css.getFromFile), + async.apply(meta.css.minify), async.apply(meta.sounds.init), async.apply(meta.blacklist.load) ], next);