|
|
|
@ -18,8 +18,33 @@ var utils = require('../../public/src/utils');
|
|
|
|
|
module.exports = function (Meta) {
|
|
|
|
|
|
|
|
|
|
Meta.css = {};
|
|
|
|
|
Meta.css.cache = undefined;
|
|
|
|
|
Meta.css.acpCache = undefined;
|
|
|
|
|
|
|
|
|
|
var buildImports = {
|
|
|
|
|
client: function (source) {
|
|
|
|
|
return '@import "./theme";\n' + source + '\n' + [
|
|
|
|
|
'@import "font-awesome";',
|
|
|
|
|
'@import (inline) "../public/vendor/jquery/css/smoothness/jquery-ui.css";',
|
|
|
|
|
'@import (inline) "../public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css";',
|
|
|
|
|
'@import (inline) "../public/vendor/colorpicker/colorpicker.css";',
|
|
|
|
|
'@import (inline) "../node_modules/cropperjs/dist/cropper.css";',
|
|
|
|
|
'@import "../../public/less/flags.less";',
|
|
|
|
|
'@import "../../public/less/blacklist.less";',
|
|
|
|
|
'@import "../../public/less/generics.less";',
|
|
|
|
|
'@import "../../public/less/mixins.less";',
|
|
|
|
|
'@import "../../public/less/global.less";',
|
|
|
|
|
].map(function (str) { return str.replace(/\//g, path.sep); }).join('\n');
|
|
|
|
|
},
|
|
|
|
|
admin: function (source) {
|
|
|
|
|
return source + '\n' + [
|
|
|
|
|
'@import "font-awesome";',
|
|
|
|
|
'@import "../public/less/admin/admin";',
|
|
|
|
|
'@import "../public/less/generics.less";',
|
|
|
|
|
'@import (inline) "../public/vendor/colorpicker/colorpicker.css";',
|
|
|
|
|
'@import (inline) "../public/vendor/jquery/css/smoothness/jquery-ui.css";',
|
|
|
|
|
'@import (inline) "../public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css";',
|
|
|
|
|
].map(function (str) { return str.replace(/\//g, path.sep); }).join('\n');
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.css.minify = function (target, callback) {
|
|
|
|
|
callback = callback || function () {};
|
|
|
|
@ -30,25 +55,25 @@ module.exports = function (Meta) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var themeId = (themeData['theme:id'] || 'nodebb-theme-persona'),
|
|
|
|
|
baseThemePath = path.join(nconf.get('themes_path'), (themeData['theme:type'] && themeData['theme:type'] === 'local' ? themeId : 'nodebb-theme-vanilla')),
|
|
|
|
|
paths = [
|
|
|
|
|
baseThemePath,
|
|
|
|
|
path.join(__dirname, '../../node_modules'),
|
|
|
|
|
path.join(__dirname, '../../public/vendor/fontawesome/less')
|
|
|
|
|
],
|
|
|
|
|
source = '@import "font-awesome";';
|
|
|
|
|
var themeId = (themeData['theme:id'] || 'nodebb-theme-persona');
|
|
|
|
|
var baseThemePath = path.join(nconf.get('themes_path'), (themeData['theme:type'] && themeData['theme:type'] === 'local' ? themeId : 'nodebb-theme-vanilla'));
|
|
|
|
|
var paths = [
|
|
|
|
|
baseThemePath,
|
|
|
|
|
path.join(__dirname, '../../node_modules'),
|
|
|
|
|
path.join(__dirname, '../../public/vendor/fontawesome/less')
|
|
|
|
|
];
|
|
|
|
|
var source = '';
|
|
|
|
|
|
|
|
|
|
plugins.lessFiles = filterMissingFiles(plugins.lessFiles);
|
|
|
|
|
plugins.cssFiles = filterMissingFiles(plugins.cssFiles);
|
|
|
|
|
var lessFiles = filterMissingFiles(plugins.lessFiles);
|
|
|
|
|
var cssFiles = filterMissingFiles(plugins.cssFiles);
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
getStyleSource(plugins.cssFiles, '\n@import (inline) ".', '.css', next);
|
|
|
|
|
getStyleSource(cssFiles, '\n@import (inline) ".', '.css', next);
|
|
|
|
|
},
|
|
|
|
|
function (src, next) {
|
|
|
|
|
source += src;
|
|
|
|
|
getStyleSource(plugins.lessFiles, '\n@import ".', '.less', next);
|
|
|
|
|
getStyleSource(lessFiles, '\n@import ".', '.less', next);
|
|
|
|
|
},
|
|
|
|
|
function (src, next) {
|
|
|
|
|
source += src;
|
|
|
|
@ -59,43 +84,11 @@ module.exports = function (Meta) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var acpSource = source;
|
|
|
|
|
|
|
|
|
|
if (target !== 'admin.css') {
|
|
|
|
|
source += '\n@import (inline) "..' + path.sep + '..' + path.sep + 'public/vendor/jquery/css/smoothness/jquery-ui.css";';
|
|
|
|
|
source += '\n@import (inline) "..' + path.sep + '..' + path.sep + 'public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css";';
|
|
|
|
|
source += '\n@import (inline) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.css";';
|
|
|
|
|
source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/flags.less";';
|
|
|
|
|
source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/blacklist.less";';
|
|
|
|
|
source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/generics.less";';
|
|
|
|
|
source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/mixins.less";';
|
|
|
|
|
source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/global.less";';
|
|
|
|
|
source += '\n@import (inline) "..' + path.sep + 'node_modules/cropperjs/dist/cropper.css";';
|
|
|
|
|
source = '@import "./theme";\n' + source;
|
|
|
|
|
|
|
|
|
|
minify(source, paths, 'cache', callback);
|
|
|
|
|
} else {
|
|
|
|
|
acpSource += '\n@import "..' + path.sep + 'public/less/admin/admin";\n';
|
|
|
|
|
acpSource += '\n@import "..' + path.sep + 'public/less/generics.less";\n';
|
|
|
|
|
acpSource += '\n@import (inline) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.css";\n';
|
|
|
|
|
acpSource += '\n@import (inline) "..' + path.sep + 'public/vendor/jquery/css/smoothness/jquery-ui.css";';
|
|
|
|
|
acpSource += '\n@import (inline) "..' + path.sep + 'public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css";';
|
|
|
|
|
|
|
|
|
|
minify(acpSource, paths, 'acpCache', callback);
|
|
|
|
|
}
|
|
|
|
|
minify(buildImports[target](source), paths, target, callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.css.getFromFile = function (callback) {
|
|
|
|
|
async.series([
|
|
|
|
|
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/stylesheet.css'), 'cache'),
|
|
|
|
|
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/admin.css'), 'acpCache')
|
|
|
|
|
], function (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getStyleSource(files, prefix, extension, callback) {
|
|
|
|
|
var pluginDirectories = [],
|
|
|
|
|
source = '';
|
|
|
|
@ -125,35 +118,22 @@ module.exports = function (Meta) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Meta.css.commitToFile = function (filename, callback) {
|
|
|
|
|
var file = (filename === 'acpCache' ? 'admin' : 'stylesheet') + '.css';
|
|
|
|
|
Meta.css.commitToFile = function (target, source, callback) {
|
|
|
|
|
var filename = (target === 'client' ? 'stylesheet' : 'admin') + '.css';
|
|
|
|
|
|
|
|
|
|
fs.writeFile(path.join(__dirname, '../../public/' + file), Meta.css[filename], function (err) {
|
|
|
|
|
fs.writeFile(path.join(__dirname, '../../build/public/' + filename), source, function (err) {
|
|
|
|
|
if (!err) {
|
|
|
|
|
winston.verbose('[meta/css] ' + file + ' committed to disk.');
|
|
|
|
|
winston.verbose('[meta/css] ' + target + ' CSS committed to disk.');
|
|
|
|
|
} else {
|
|
|
|
|
winston.error('[meta/css] ' + err.message);
|
|
|
|
|
process.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.css.loadFile = function (filePath, filename, callback) {
|
|
|
|
|
winston.verbose('[meta/css] Reading stylesheet ' + filePath.split('/').pop() + ' from file');
|
|
|
|
|
|
|
|
|
|
fs.readFile(filePath, function (err, file) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Meta.css[filename] = file;
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function minify(source, paths, destination, callback) {
|
|
|
|
|
function minify(source, paths, target, callback) {
|
|
|
|
|
callback = callback || function () {};
|
|
|
|
|
less.render(source, {
|
|
|
|
|
paths: paths
|
|
|
|
@ -163,20 +143,14 @@ module.exports = function (Meta) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
postcss([ autoprefixer, clean() ]).process(lessOutput.css).then(function (result) {
|
|
|
|
|
postcss(global.env === 'development' ? [ autoprefixer ] : [ autoprefixer, clean() ]).process(lessOutput.css).then(function (result) {
|
|
|
|
|
result.warnings().forEach(function (warn) {
|
|
|
|
|
winston.verbose(warn.toString());
|
|
|
|
|
});
|
|
|
|
|
Meta.css[destination] = result.css;
|
|
|
|
|
|
|
|
|
|
// Save the compiled CSS in public/ so things like nginx can serve it
|
|
|
|
|
if (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false) {
|
|
|
|
|
return Meta.css.commitToFile(destination, function () {
|
|
|
|
|
callback(null, result.css);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, result.css);
|
|
|
|
|
return Meta.css.commitToFile(target, result.css, function () {
|
|
|
|
|
callback(null, result.css);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|