mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
Build pipeline improvements
- Refactor meta/css - `fs.link` usage consolidated to `file.link` - rimraf built modules directory to fix error - Remove `local-assets` flag
This commit is contained in:
102
src/meta/css.js
102
src/meta/css.js
@@ -18,8 +18,32 @@ 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) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.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 +54,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,29 +83,7 @@ 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 = '@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);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -115,22 +117,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, '../../build/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);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
function minify(source, paths, destination, callback) {
|
||||
function minify(source, paths, target, callback) {
|
||||
callback = callback || function () {};
|
||||
less.render(source, {
|
||||
paths: paths
|
||||
@@ -140,20 +142,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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user