From 38340e3b7314a967637f2acabaf4be28ca4c2554 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 16 Aug 2016 16:43:04 +0200 Subject: [PATCH] Updated JS for production --- files/js/WCF.Conversation.js | 2 +- files/js/require.build.js | 71 ++++++++++++++++++++++++++++++++++++ templates/conversation.tpl | 1 + 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 files/js/require.build.js diff --git a/files/js/WCF.Conversation.js b/files/js/WCF.Conversation.js index 69b6691..856f6d8 100644 --- a/files/js/WCF.Conversation.js +++ b/files/js/WCF.Conversation.js @@ -460,7 +460,7 @@ WCF.Conversation.InlineEditor = WCF.InlineEditor.extend({ switch (optionName) { case 'addParticipants': - require(['WoltLab/Conversation/Ui/Participant/Add'], function(UiParticipantAdd) { + require(['WoltLabSuite/Core/Conversation/Ui/Participant/Add'], function(UiParticipantAdd) { new UiParticipantAdd(document.getElementById(elementID).getAttribute('data-conversation-id')); }); break; diff --git a/files/js/require.build.js b/files/js/require.build.js new file mode 100644 index 0000000..a399391 --- /dev/null +++ b/files/js/require.build.js @@ -0,0 +1,71 @@ +(function () { + var config; + config = { + name: "WoltLabSuite/_Meta", + out: "WoltLabSuite.Core.Conversation.min.js", + useStrict: true, + preserveLicenseComments: false, + optimize: 'uglify2', + uglify2: {}, + excludeShallow: [ + 'WoltLabSuite/_Meta' + ], + rawText: { + 'WoltLabSuite/_Meta': 'define([], function() {});' + }, + onBuildRead: function(moduleName, path, contents) { + if (!process.versions.node) { + throw new Error('You need to run node.js'); + } + + if (moduleName === 'WoltLabSuite/_Meta') { + if (global.allModules == undefined) { + var fs = module.require('fs'), + path = module.require('path'); + global.allModules = []; + + var queue = ['WoltLabSuite']; + var folder; + while (folder = queue.shift()) { + var files = fs.readdirSync(folder); + for (var i = 0; i < files.length; i++) { + var filename = path.join(folder, files[i]); + if (filename === 'WoltLabSuite/Core/Acp') continue; + + if (path.extname(filename) == '.js') { + global.allModules.push(filename); + } + else if (fs.statSync(filename).isDirectory()) { + queue.push(filename); + } + } + } + } + + return 'define([' + global.allModules.map(function (item) { return "'" + item.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\.js$/, '') + "'"; }).join(', ') + '], function() { });'; + } + + return contents; + } + }; + + var _isSupportedBuildUrl = require._isSupportedBuildUrl; + require._isSupportedBuildUrl = function (url) { + var result = _isSupportedBuildUrl(url); + if (!result) return result; + if (Object.keys(config.rawText).map(function (item) { return process.cwd() + '/' + item + '.js'; }).indexOf(url) !== -1) return result; + + var fs = module.require('fs'); + try { + fs.statSync(url); + } + catch (e) { + console.log('Unable to find module:', url, 'ignoring.'); + + return false; + } + return true; + }; + + return config; +})(); diff --git a/templates/conversation.tpl b/templates/conversation.tpl index f41bdc0..ccf4993 100644 --- a/templates/conversation.tpl +++ b/templates/conversation.tpl @@ -118,6 +118,7 @@ {/hascontent} +{if !ENABLE_DEBUG_MODE}{/if}