mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 16:00:26 +01:00
removed symlink logic and using route bridging instead.
Also allowed plugins to define modules from their plugin.json
This commit is contained in:
@@ -70,7 +70,6 @@ module.exports = function(grunt) {
|
||||
clientUpdated: {
|
||||
files: [
|
||||
'public/src/**/*.js',
|
||||
'!public/src/modules/*.js',
|
||||
'node_modules/nodebb-*/*.js', 'node_modules/nodebb-*/**/*.js',
|
||||
'!node_modules/nodebb-*/node_modules/**',
|
||||
'node_modules/templates.js/lib/templates.js',
|
||||
|
||||
35
public/src/modules/.gitignore
vendored
35
public/src/modules/.gitignore
vendored
@@ -1,35 +0,0 @@
|
||||
# Warning: This directory contains auto-generated files (symlinked), and should
|
||||
# not be tracked by git. If you want to specifically have a file tracked by git,
|
||||
# please include it in this file.
|
||||
|
||||
|
||||
|
||||
# Ignore all files in this directory...
|
||||
/*
|
||||
|
||||
# except these folders...
|
||||
!/settings
|
||||
|
||||
# and these files...
|
||||
!/.gitignore
|
||||
!/alerts.js
|
||||
!/autocomplete.js
|
||||
!/chat.js
|
||||
!/components.js
|
||||
!/coverPhoto.js
|
||||
!/csrf.js
|
||||
!/helpers.js
|
||||
!/iconSelect.js
|
||||
!/navigator.js
|
||||
!/notifications.js
|
||||
!/postSelect.js
|
||||
!/search.js
|
||||
!/settings.js
|
||||
!/share.js
|
||||
!/sort.js
|
||||
!/sounds.js
|
||||
!/string.js
|
||||
!/taskbar.js
|
||||
!/topicSelect.js
|
||||
!/translator.js
|
||||
!/uploader.js
|
||||
@@ -61,7 +61,6 @@ var async = require('async'),
|
||||
async.apply(plugins.clearRequireCache),
|
||||
async.apply(plugins.reload),
|
||||
async.apply(plugins.reloadRoutes),
|
||||
async.apply(Meta.js.symlinkModules),
|
||||
async.apply(Meta.css.minify),
|
||||
async.apply(Meta.js.minify, 'nodebb.min.js'),
|
||||
async.apply(Meta.js.minify, 'acp.min.js'),
|
||||
|
||||
@@ -6,7 +6,6 @@ var winston = require('winston'),
|
||||
async = require('async'),
|
||||
nconf = require('nconf'),
|
||||
fs = require('fs'),
|
||||
rimraf = require('rimraf'),
|
||||
file = require('../file'),
|
||||
plugins = require('../plugins'),
|
||||
emitter = require('../emitter'),
|
||||
@@ -79,7 +78,7 @@ module.exports = function(Meta) {
|
||||
'public/src/modules/string.js'
|
||||
],
|
||||
|
||||
// modules listed below are symlinked to public/src/modules so they can be defined anonymously
|
||||
// modules listed below are routed through express (/src/modules) so they can be defined anonymously
|
||||
modules: [
|
||||
'./node_modules/chart.js/Chart.js',
|
||||
'./node_modules/mousetrap/mousetrap.js',
|
||||
@@ -89,38 +88,30 @@ module.exports = function(Meta) {
|
||||
}
|
||||
};
|
||||
|
||||
Meta.js.symlinkModules = function(callback) {
|
||||
// Symlink all defined modules to /public/src/modules
|
||||
var modulesLoaded = 0,
|
||||
targetPath;
|
||||
Meta.js.bridgeModules = function(app, callback) {
|
||||
// Add routes for AMD-type modules to serve those files
|
||||
console.log('bridging modules:', Meta.js.scripts.modules);
|
||||
var numBridged = 0;
|
||||
|
||||
async.series([
|
||||
function(next) {
|
||||
async.each(Meta.js.scripts.modules, function(localPath, next) {
|
||||
targetPath = path.join(__dirname, '../../public/src/modules', path.basename(localPath));
|
||||
|
||||
async.waterfall([
|
||||
async.apply(fs.access, localPath, fs.R_OK),
|
||||
async.apply(rimraf, targetPath),
|
||||
async.apply(fs.link, localPath, targetPath)
|
||||
], function(err) {
|
||||
if (err) {
|
||||
winston.error('[meta/js] Could not symlink `' + localPath + '` to modules folder');
|
||||
} else {
|
||||
winston.verbose('[meta/js] Symlinked `' + localPath + '` to modules folder');
|
||||
++modulesLoaded;
|
||||
}
|
||||
|
||||
next(err);
|
||||
app.get(path.join('/src/modules/', path.basename(localPath)), function(req, res) {
|
||||
return res.sendFile(path.join(__dirname, '../../', localPath), {
|
||||
maxAge: app.enabled('cache') ? 5184000000 : 0
|
||||
});
|
||||
});
|
||||
|
||||
++numBridged;
|
||||
next();
|
||||
}, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
winston.error('[meta/js] Encountered error while symlinking modules:' + err.message);
|
||||
winston.error('[meta/js] Encountered error while bridging modules:' + err.message);
|
||||
}
|
||||
|
||||
winston.verbose('[meta/js] ' + modulesLoaded + ' of ' + Meta.js.scripts.modules.length + ' modules symlinked');
|
||||
winston.verbose('[meta/js] ' + numBridged + ' of ' + Meta.js.scripts.modules.length + ' modules bridged');
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -7,8 +7,10 @@ var fs = require('fs'),
|
||||
winston = require('winston'),
|
||||
nconf = require('nconf'),
|
||||
_ = require('underscore'),
|
||||
file = require('../file'),
|
||||
utils = require('../../public/src/utils');
|
||||
file = require('../file');
|
||||
|
||||
var utils = require('../../public/src/utils'),
|
||||
meta = require('../meta');
|
||||
|
||||
|
||||
module.exports = function(Plugins) {
|
||||
@@ -40,6 +42,9 @@ module.exports = function(Plugins) {
|
||||
function(next) {
|
||||
mapClientSideScripts(pluginData, next);
|
||||
},
|
||||
function(next) {
|
||||
mapClientModules(pluginData, next);
|
||||
},
|
||||
function(next) {
|
||||
loadLanguages(pluginData, next);
|
||||
}
|
||||
@@ -163,7 +168,21 @@ module.exports = function(Plugins) {
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
function mapClientModules(pluginData, callback) {
|
||||
if (Array.isArray(pluginData.modules)) {
|
||||
if (global.env === 'development') {
|
||||
winston.verbose('[plugins] Found ' + pluginData.modules.length + ' AMD-style module(s) for plugin ' + pluginData.id);
|
||||
}
|
||||
|
||||
meta.js.scripts.modules = meta.js.scripts.modules.concat(pluginData.modules.map(function(file) {
|
||||
return path.join('./node_modules/', pluginData.id, file);
|
||||
}));
|
||||
}
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
function loadLanguages(pluginData, callback) {
|
||||
if (typeof pluginData.languages !== 'string') {
|
||||
|
||||
@@ -84,10 +84,10 @@ function initializeNodeBB(callback) {
|
||||
function(next) {
|
||||
plugins.init(app, middleware, next);
|
||||
},
|
||||
async.apply(meta.js.bridgeModules, app),
|
||||
function(next) {
|
||||
async.series([
|
||||
async.apply(meta.templates.compile),
|
||||
async.apply(meta.js.symlinkModules),
|
||||
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(meta.css.minify),
|
||||
|
||||
Reference in New Issue
Block a user