2
0
Преглед на файлове

devkit: writeConfig tries to find actual path in array

Herbert Vojčík преди 10 години
родител
ревизия
ba9031b836
променени са 1 файла, в които са добавени 18 реда и са изтрити 0 реда
  1. 18 0
      external/amber-dev/lib/config.js

+ 18 - 0
external/amber-dev/lib/config.js

@@ -12,8 +12,26 @@ exports.writeConfig = function (searchDir, fileForConfig, callback) {
     fileForConfig = fileForConfig || 'config.js';
     callback = callback || function (err) { if (err) throw err; };
 
+    function tryToFlattenPathsMapping(mapping) {
+        if (Array.isArray(mapping)) {
+            for (var i = 0; i < mapping.length; ++i) {
+                var element = mapping[i];
+                if (element.match(/(^|:)\/\//)) break;
+                try {
+                    var stat = fs.statSync(path.join(searchDir, element + ".js"));
+                    if (stat.isDirectory()) break;
+                    if (stat.isFile()) return element;
+                } catch (e) {}
+            }
+        }
+        return mapping;
+    }
+
     configBuilder.produceConfigObject(searchDir, function (err, result) {
         if (err) return callback(err);
+        for (var p in result.paths) {
+            result.paths[p] = tryToFlattenPathsMapping(result.paths[p]);
+        }
         var text = "/* DO NOT EDIT! This file is generated. */\n" +
             "\n" +
             "var require;\n" +