mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
grunt: only compile ACP less if that was changed, and vice versa with theme/plugin less
This commit is contained in:
22
Gruntfile.js
22
Gruntfile.js
@@ -17,17 +17,20 @@ module.exports = function(grunt) {
|
|||||||
args.push('--log-level=info');
|
args.push('--log-level=info');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target === 'lessUpdated') {
|
if (target === 'lessUpdated_Client') {
|
||||||
fromFile = ['js','tpl'];
|
fromFile = ['js', 'tpl', 'acpLess'];
|
||||||
compiling = 'less';
|
compiling = 'clientLess';
|
||||||
|
} else if (target === 'lessUpdated_Admin') {
|
||||||
|
fromFile = ['js', 'tpl', 'clientLess'];
|
||||||
|
compiling = 'acpLess';
|
||||||
} else if (target === 'clientUpdated') {
|
} else if (target === 'clientUpdated') {
|
||||||
fromFile = ['less','tpl'];
|
fromFile = ['clientLess', 'acpLess', 'tpl'];
|
||||||
compiling = 'js';
|
compiling = 'js';
|
||||||
} else if (target === 'templatesUpdated') {
|
} else if (target === 'templatesUpdated') {
|
||||||
fromFile = ['js','less'];
|
fromFile = ['js', 'clientLess', 'acpLess'];
|
||||||
compiling = 'tpl';
|
compiling = 'tpl';
|
||||||
} else if (target === 'serverUpdated') {
|
} else if (target === 'serverUpdated') {
|
||||||
fromFile = ['less','js','tpl'];
|
fromFile = ['clientLess', 'acpLess', 'js', 'tpl'];
|
||||||
}
|
}
|
||||||
|
|
||||||
fromFile = fromFile.filter(function(ext) {
|
fromFile = fromFile.filter(function(ext) {
|
||||||
@@ -53,8 +56,11 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
watch: {
|
watch: {
|
||||||
lessUpdated: {
|
lessUpdated_Client: {
|
||||||
files: ['public/**/*.less', 'node_modules/nodebb-*/*.less', 'node_modules/nodebb-*/*/*.less', 'node_modules/nodebb-*/*/*/*.less', 'node_modules/nodebb-*/*/*/*/*.less']
|
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: {
|
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']
|
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']
|
||||||
|
|||||||
@@ -80,11 +80,22 @@ module.exports = function(Meta) {
|
|||||||
|
|
||||||
source = '@import "./theme";\n' + source;
|
source = '@import "./theme";\n' + source;
|
||||||
|
|
||||||
|
var fromFile = nconf.get('from-file') || '';
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function(next) {
|
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);
|
minify(source, paths, 'cache', next);
|
||||||
},
|
},
|
||||||
function(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);
|
minify(acpSource, paths, 'acpCache', next);
|
||||||
}
|
}
|
||||||
], function(err, minified) {
|
], function(err, minified) {
|
||||||
@@ -151,28 +162,12 @@ module.exports = function(Meta) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Meta.css.getFromFile = function(callback) {
|
Meta.css.getFromFile = function(filePath, cache, callback) {
|
||||||
var cachePath = path.join(__dirname, '../../public/stylesheet.css'),
|
winston.verbose('[meta/css] Reading stylesheet ' + filePath.split('/').pop() + ' from file');
|
||||||
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') {
|
fs.readFile(filePath, function(err, file) {
|
||||||
return callback();
|
cache = file;
|
||||||
}
|
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];
|
|
||||||
|
|
||||||
emitter.emit('meta:css.compiled');
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -78,11 +78,6 @@ function initializeNodeBB(callback) {
|
|||||||
skipJS = true;
|
skipJS = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromFile.match('less')) {
|
|
||||||
winston.info('[minifier] Compiling LESS files skipped');
|
|
||||||
skipLess = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(cacheStaticFiles),
|
async.apply(cacheStaticFiles),
|
||||||
async.apply(meta.themes.setupPaths),
|
async.apply(meta.themes.setupPaths),
|
||||||
@@ -94,7 +89,7 @@ function initializeNodeBB(callback) {
|
|||||||
async.apply(meta.templates.compile),
|
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, 'nodebb.min.js'),
|
||||||
async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'acp.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.sounds.init),
|
||||||
async.apply(meta.blacklist.load)
|
async.apply(meta.blacklist.load)
|
||||||
], next);
|
], next);
|
||||||
|
|||||||
Reference in New Issue
Block a user