Explorar o código

Fix DTS generation

sebavan %!s(int64=6) %!d(string=hai) anos
pai
achega
ca1e8b3148

+ 2 - 1
Tools/Config/config.json

@@ -506,7 +506,8 @@
                         "@babylonjs/core": "BABYLON",
                         "@babylonjs/loaders": "BABYLON",
                         "@babylonjs/serializers": "BABYLON",
-                        "@babylonjs/gui": "BABYLON.GUI"
+                        "@babylonjs/gui": "BABYLON.GUI",
+                        "@fortawesome": false
                     }
                 }
             },

+ 48 - 0
Tools/Gulp/helpers/gulp-processAmdDeclarationToModule.js

@@ -73,6 +73,54 @@ var processData = function(data, options) {
     // Recreate the file.
     str = lines.join('\n');
 
+    // !!! Be carefull
+    // Could cause issues if this appears in several import scope
+    // with different aliases.
+
+    // !!! Be carefull multiline not managed.
+
+    // Remove unmanaged externals Appears as classMap false in the config.
+    if (options.externals) {
+        for (let ext in options.externals) {
+            // Need to remove the module and dependencies if false.
+            if (options.externals[ext] === false) {
+                // Replace import { foo, bar } from ...
+                const package = ext;
+                var babylonRegex = new RegExp(`import {(.*)} from ['"](${package})[\/'"](.*);`, "g");
+                var match = babylonRegex.exec(str);
+                let classes = new Set();
+                while (match != null) {
+                    if (match[1]) {
+                        match[1].split(",").forEach(element => {
+                            classes.add(element.trim());
+                        });
+                    }
+                    match = babylonRegex.exec(str);
+                }
+                str = str.replace(babylonRegex, '');
+
+                classes.forEach(cls => {
+                    let className = cls;
+                    let alias = cls;
+
+                    // Deal with import { foo as A, bar as B } from ...
+                    if (cls.indexOf(" as ") > -1) {
+                        const tokens = cls.split(" as ");
+                        className = tokens[0];
+                        alias = tokens[1];
+                    }
+
+                    // !!! Be carefull multiline not managed.
+                    const rg = new RegExp(`.*[ <]${alias}[^\\w].*`, "g")
+                    str = str.replace(rg, "");
+                });
+            }
+        }
+
+        // Remove Empty Lines
+        str = str.replace(/^\s*$/gm, "");
+    }
+
     // Add Entry point.
     str += `
 declare module "${moduleName}" {

+ 17 - 3
Tools/Gulp/helpers/gulp-processModuleDeclarationToNamespace.js

@@ -160,8 +160,22 @@ var processData = function(data, packageName, options) {
                     alias = tokens[1];
                 }
 
-                const rg = new RegExp(`([ <])(${alias})([^\\w])`, "g")
-                str = str.replace(rg, `$1${options.classMap[package]}.${className}$3`);
+                // !!! Be carefull
+                // Could cause issues if this appears in several import scope
+                // with different aliases.
+
+                // !!! Be carefull multiline not managed.
+
+                // False is a special case to remove all the lines.
+                if (options.classMap[package] === false) {
+                    const rg = new RegExp(`.*[ <]${alias}[^\\w].*`, "g")
+                    str = str.replace(rg, "");
+                }
+                // Else replace with the namespace prefix.
+                else {
+                    const rg = new RegExp(`([ <])(${alias})([^\\w])`, "g")
+                    str = str.replace(rg, `$1${options.classMap[package]}.${className}$3`);
+                }
             });
         });
 
@@ -205,7 +219,7 @@ var processData = function(data, packageName, options) {
     }
 
     // Remove Empty Lines
-    str = str.replace(/^\s*$/g, "");
+    str = str.replace(/^\s*$/gm, "");
 
     // Remove Inlined Import
     str = str.replace(/import\("[A-Za-z0-9\/]*"\)\./g, "");