Automatically scan all modules in require.build.js
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 20 May 2015 22:22:50 +0000 (00:22 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 20 May 2015 22:22:50 +0000 (00:22 +0200)
wcfsetup/install/files/js/require.build.js

index 3f36e59be74895a3006fc0f6c821da4521065c4e..43c40b2624fa284a9d2c4b7c669fbd2f19df8aa0 100644 (file)
@@ -1,14 +1,54 @@
 ({
        mainConfigFile: 'require.config.js',
-       name: "WoltLab/WCF/Bootstrap",
-       out: "WCF.Combined.min.js",
+       name: "WoltLab/_Meta",
+       out: "WCF.Core.min.js",
        useStrict: true,
+       preserveLicenseComments: false,
+       optimize: 'uglify2',
+       uglify2: {},
        paths: {
                "requireLib": "require",
                
-               "jquery": "empty:"
+               "jquery": "empty:",
        },
        include: [
-               "requireLib"
-       ]
+               "requireLib",
+       ],
+       excludeShallow: [
+               'WoltLab/_Meta',
+       ],
+       rawText: {
+               'WoltLab/_Meta': 'define([], function () {});',
+       },
+       onBuildRead: function (moduleName, path, contents) {
+               if (!process.versions.node) {
+                       throw new Error('You need to run node.js');
+               }
+               
+               if (moduleName === 'WoltLab/_Meta') {
+                       if (global.allModules == undefined) {
+                               var fs = module.require('fs')
+                                 , path = module.require('path');
+                               global.allModules = [];
+                               var queue = [ 'WoltLab' ];
+                               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 (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, "\\'") + "'"; }).join(', ') + '], function () { });';
+               }
+               
+               return contents;
+       },
 })