Code coverage report for ./src/ocLazyLoad.loaders.core.js

Statements: 81.9% (95 / 116)      Branches: 72.92% (70 / 96)      Functions: 100% (19 / 19)      Lines: 81.9% (95 / 116)      Ignored: none     

All files » ./src/ » ocLazyLoad.loaders.core.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237    1     1 29             28 21   21             21   21   21 21   21 1 1   21 21     20   1 1     20 18   18                   20 3 17 4 13 13       1 1       21 2   19 19       21 3 3 3 1 1   2     3     21 4 4 4 1 1   3     4     21 13 13 13 1 1   12     13     21           21 1 1     20 20 20                     28 25   25             25 25     25   5 10       5 4   1     5       20 16 16 16       4   4 1       3       20               20                       20     20       20 17 16   1     3     20       28        
'use strict';
 
(function (angular) {
    'use strict';
 
    angular.module('oc.lazyLoad').config(function ($provide) {
        $provide.decorator('$ocLazyLoad', function ($delegate, $q) {
            /**
             * The function that loads new files
             * @param config
             * @param params
             * @returns {*}
             */
            $delegate.filesLoader = function filesLoader(config) {
                var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
 
                var cssFiles = [],
                    templatesFiles = [],
                    jsFiles = [],
                    promises = [],
                    cachePromise = null,
                    filesCache = $delegate._getFilesCache();
 
                $delegate.toggleWatch(true); // start watching angular.module calls
 
                angular.extend(params, config);
 
                var pushFile = function pushFile(path) {
                    var file_type = null,
                        m;
                    if (angular.isObject(path)) {
                        file_type = path.type;
                        path = path.path;
                    }
                    cachePromise = filesCache.get(path);
                    if (angular.isUndefined(cachePromise) || params.cache === false) {
 
                        // always check for requirejs syntax just in case
                        if ((m = /^(css|less|html|htm|js)?(?=!)/.exec(path)) !== null) {
                            // Detect file type using preceding type declaration (ala requireJS)
                            file_type = m[1];
                            path = path.substr(m[1].length + 1, path.length); // Strip the type from the path
                        }
 
                        if (!file_type) {
                            Eif ((m = /[.](css|less|html|htm|js)?((\?|#).*)?$/.exec(path)) !== null) {
                                // Detect file type via file extension
                                file_type = m[1];
                            } else if (!$delegate.jsLoader.hasOwnProperty('ocLazyLoadLoader') && $delegate.jsLoader.hasOwnProperty('requirejs')) {
                                // requirejs
                                file_type = 'js';
                            } else {
                                $delegate._$log.error('File type could not be determined. ' + path);
                                return;
                            }
                        }
 
                        if ((file_type === 'css' || file_type === 'less') && cssFiles.indexOf(path) === -1) {
                            cssFiles.push(path);
                        } else if ((file_type === 'html' || file_type === 'htm') && templatesFiles.indexOf(path) === -1) {
                            templatesFiles.push(path);
                        } else Eif (file_type === 'js' || jsFiles.indexOf(path) === -1) {
                            jsFiles.push(path);
                        } else {
                            $delegate._$log.error('File type is not valid. ' + path);
                        }
                    } else Eif (cachePromise) {
                        promises.push(cachePromise);
                    }
                };
 
                if (params.serie) {
                    pushFile(params.files.shift());
                } else {
                    angular.forEach(params.files, function (path) {
                        pushFile(path);
                    });
                }
 
                if (cssFiles.length > 0) {
                    var cssDeferred = $q.defer();
                    $delegate.cssLoader(cssFiles, function (err) {
                        if (angular.isDefined(err) && $delegate.cssLoader.hasOwnProperty('ocLazyLoadLoader')) {
                            $delegate._$log.error(err);
                            cssDeferred.reject(err);
                        } else {
                            cssDeferred.resolve();
                        }
                    }, params);
                    promises.push(cssDeferred.promise);
                }
 
                if (templatesFiles.length > 0) {
                    var templatesDeferred = $q.defer();
                    $delegate.templatesLoader(templatesFiles, function (err) {
                        if (angular.isDefined(err) && $delegate.templatesLoader.hasOwnProperty('ocLazyLoadLoader')) {
                            $delegate._$log.error(err);
                            templatesDeferred.reject(err);
                        } else {
                            templatesDeferred.resolve();
                        }
                    }, params);
                    promises.push(templatesDeferred.promise);
                }
 
                if (jsFiles.length > 0) {
                    var jsDeferred = $q.defer();
                    $delegate.jsLoader(jsFiles, function (err) {
                        if (angular.isDefined(err) && ($delegate.jsLoader.hasOwnProperty("ocLazyLoadLoader") || $delegate.jsLoader.hasOwnProperty("requirejs"))) {
                            $delegate._$log.error(err);
                            jsDeferred.reject(err);
                        } else {
                            jsDeferred.resolve();
                        }
                    }, params);
                    promises.push(jsDeferred.promise);
                }
 
                Iif (promises.length === 0) {
                    var deferred = $q.defer(),
                        err = "Error: no file to load has been found, if you're trying to load an existing module you should use the 'inject' method instead of 'load'.";
                    $delegate._$log.error(err);
                    deferred.reject(err);
                    return deferred.promise;
                } else if (params.serie && params.files.length > 0) {
                    return $q.all(promises).then(function () {
                        return $delegate.filesLoader(config, params);
                    });
                } else {
                    return $q.all(promises)['finally'](function (res) {
                        $delegate.toggleWatch(false); // stop watching angular.module calls
                        return res;
                    });
                }
            };
 
            /**
             * Load a module or a list of modules into Angular
             * @param module Mixed the name of a predefined module config object, or a module config object, or an array of either
             * @param params Object optional parameters
             * @returns promise
             */
            $delegate.load = function (originalModule) {
                var originalParams = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
 
                var self = this,
                    config = null,
                    deferredList = [],
                    deferred = $q.defer(),
                    errText;
 
                // clean copy
                var module = angular.copy(originalModule);
                var params = angular.copy(originalParams);
 
                // If module is an array, break it down
                if (angular.isArray(module)) {
                    // Resubmit each entry as a single module
                    angular.forEach(module, function (m) {
                        deferredList.push(self.load(m, params));
                    });
 
                    // Resolve the promise once everything has loaded
                    $q.all(deferredList).then(function (res) {
                        deferred.resolve(res);
                    }, function (err) {
                        deferred.reject(err);
                    });
 
                    return deferred.promise;
                }
 
                // Get or Set a configuration depending on what was passed in
                if (angular.isString(module)) {
                    config = self.getModuleConfig(module);
                    Eif (!config) {
                        config = {
                            files: [module]
                        };
                    }
                } else Eif (angular.isObject(module)) {
                    // case {type: 'js', path: lazyLoadUrl + 'testModule.fakejs'}
                    if (angular.isDefined(module.path) && angular.isDefined(module.type)) {
                        config = {
                            files: [module]
                        };
                    } else {
                        config = self.setModuleConfig(module);
                    }
                }
 
                Iif (config === null) {
                    var moduleName = self._getModuleName(module);
                    errText = 'Module "' + (moduleName || 'unknown') + '" is not configured, cannot load.';
                    $delegate._$log.error(errText);
                    deferred.reject(new Error(errText));
                    return deferred.promise;
                } else {
                    // deprecated
                    Iif (angular.isDefined(config.template)) {
                        if (angular.isUndefined(config.files)) {
                            config.files = [];
                        }
                        if (angular.isString(config.template)) {
                            config.files.push(config.template);
                        } else if (angular.isArray(config.template)) {
                            config.files.concat(config.template);
                        }
                    }
                }
 
                var localParams = angular.extend({}, params, config);
 
                // if someone used an external loader and called the load function with just the module name
                Iif (angular.isUndefined(config.files) && angular.isDefined(config.name) && $delegate.moduleExists(config.name)) {
                    return $delegate.inject(config.name, localParams, true);
                }
 
                $delegate.filesLoader(config, localParams).then(function () {
                    $delegate.inject(null, localParams).then(function (res) {
                        deferred.resolve(res);
                    }, function (err) {
                        deferred.reject(err);
                    });
                }, function (err) {
                    deferred.reject(err);
                });
 
                return deferred.promise;
            };
 
            // return the patched service
            return $delegate;
        });
    });
})(angular);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkM6L3d3dy9vY0xhenlMb2FkL3NyYy9vY0xhenlMb2FkLmxvYWRlcnMuY29yZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLENBQUMsVUFBQSxPQUFPLEVBQUk7QUFDUixnQkFBWSxDQUFDOztBQUVi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HN0YXJ0IHdhdGNoaW5nIGFuZ3VsYXIubW9kdWxlIGNhbGxzXHJcblxyXG4gICAgICAgICAgICAgICAgYW5ndWxhci5leHRlbmQocGFyYW1zLCBjb25maWcpO1xyXG5cclxuICAgICAgICAgICAgICAgIHZhciBwdXNoRmlsZSA9IGZ1bmN0aW9uKHBhdGgpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgZmlsZV90eXBlID0gbnVsbCwgbTtcclxuICAgICAgICAgICAgICAgICAgICBpZihhbmd1bGFyLmlzT2JqZWN0KHBhdGgpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZpbGVfdHlwZSA9IHBhdGgudHlwZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcGF0aCA9IHBhdGgucGF0aDtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgY2FjaGVQcm9taXNlID0gZmlsZXNDYWNoZS5nZXQocGF0aCk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYoYW5ndWxhci5pc1VuZGVmaW5lZChjYWNoZVByb21pc2UpIHx8IHBhcmFtcy5jYWNoZSA9PT0gZmFsc2UpIHtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIGFsd2F5cyBjaGVjayBmb3IgcmVxdWlyZWpzIHN5bnRheCBqdXN0IGluIGNhc2VcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYoKG0gPSAvXihjc3N8bGVzc3xodG1sfGh0bXxqcyk/KD89ISkvLmV4ZWMocGF0aCkpICE9PSBudWxsKSB7IC8vIERldGVjdCBmaWxlIHR5cGUgdXNpbmcgcHJlY2VkaW5nIHR5cGUgZGVjbGFyYXRpb24gKGFsYSByZXF1aXJlSlMpXHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaWxlX3R5cGUgPSBtWzFdO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcGF0aCA9IHBhdGguc3Vic3RyKG1bMV0ubGVuZ3RoICsgMSwgcGF0aC5sZW5ndGgpOyAgLy8gU3RyaXAgdGhlIHR5cGUgZnJvbSB0aGUgcGF0aFxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZighZmlsZV90eXBlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZigobSA9IC9bLl0oY3NzfGxlc3N8aHRtbHxodG18anMpPygoXFw/fCMpLiopPyQvLmV4ZWMocGF0aCkpICE9PSBudWxsKSB7ICAvLyBEZXRlY3QgZmlsZSB0eXBlIHZpYSBmaWxlIGV4dGVuc2lvblxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpbGVfdHlwZSA9IG1bMV07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYoISRkZWxlZ2F0ZS5qc0xvYWRlci5oYXNPd25Qcm9wZXJ0eSgnb2NMYXp5TG9hZExvYWRlcicpICYmICRkZWxlZ2F0ZS5qc0xvYWRlci5oYXNPd25Qcm9wZXJ0eSgncmVxdWlyZWpzJykpIHsgLy8gcmVxdWlyZWpzXHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmlsZV90eXBlID0gJ2pzJztcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJGRlbGVnYXRlLl8kbG9nLmVycm9yKGBGaWxlIHR5cGUgY291bGQgbm90IGJlIGRldGVybWluZWQuICR7IHBhdGggfWApO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYoKGZpbGVfdHlwZSA9PT0gJ2NzcycgfHwgZmlsZV90eXBlID09PSAnbGVzcycpICYmIGNzc0ZpbGVzLmluZGV4T2YocGF0aCkgPT09IC0xKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjc3NGaWxlcy5wdXNoKHBhdGgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYoKGZpbGVfdHlwZSA9PT0gJ2h0bWwnIHx8IGZpbGVfdHlwZSA9PT0gJ2h0bScpICYmIHRlbXBsYXRlc0ZpbGVzLmluZGV4T2YocGF0aCkgPT09IC0xKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0ZW1wbGF0ZXNGaWxlcy5wdXNoKHBhdGgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYoZmlsZV90eXBlID09PSAnanMnIHx8IGpzRmlsZXMuaW5kZXhPZihwYXRoKSA9PT0gLTEpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGpzRmlsZXMucHVzaChwYXRoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICRkZWxlZ2F0ZS5fJGxvZy5lcnJvcihgRmlsZSB0eXBlIGlzIG5vdCB2YWxpZC4gJHsgcGF0aCB9YCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmKGNhY2hlUHJvbWlzZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBwcm9taXNlcy5wdXNoKGNhY2hlUHJvbWlzZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZihwYXJhbXMuc2VyaWUpIHtcclxuICAgICAgICAgICAgICAgICAgICBwdXNoRmlsZShwYXJhbXMuZmlsZXMuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGFuZ3VsYXIuZm9yRWFjaChwYXJhbXMuZmlsZXMsIHBhdGggPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBwdXNoRmlsZShwYXRoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBpZihjc3NGaWxlcy5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGNzc0RlZmVycmVkID0gJHEuZGVmZXIoKTtcclxuICAgICAgICAgICAgICAgICAgICAkZGVsZWdhdGUuY3NzTG9hZGVyKGNzc0ZpbGVzLCBlcnIgPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZihhbmd1bGFyLmlzRGVmaW5lZChlcnIpICYmICRkZWxlZ2F0ZS5jc3NMb2FkZXIuaGFzT3duUHJvcGVydHkoJ29jTGF6eUxvYWRMb2FkZXInKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgJGRlbGVnYXRlLl8kbG9nLmVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjc3NEZWZlcnJlZC5yZWplY3QoZXJyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNzc0RlZmVycmVkLnJlc29sdmUoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0sIHBhcmFtcyk7XHJcbiAgICAgICAgICAgICAgICAgICAgcHJvbWlzZXMucHVzaChjc3NEZWZlcnJlZC5wcm9taXNlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBpZih0ZW1wbGF0ZXNGaWxlcy5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIHRlbXBsYXRlc0RlZmVycmVkID0gJHEuZGVmZXIoKTtcclxuICAgICAgICAgICAgICAgICAgICAkZGVsZWdhdGUudGVtcGxhdGVzTG9hZGVyKHRlbXBsYXRlc0ZpbGVzLCBlcnIgPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZihhbmd1bGFyLmlzRGVmaW5lZChlcnIpICYmICRkZWxlZ2F0ZS50ZW1wbGF0ZXNMb2FkZXIuaGFzT3duUHJvcGVydHkoJ29jTGF6eUxvYWRMb2FkZXInKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgJGRlbGVnYXRlLl8kbG9nLmVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0ZW1wbGF0ZXNEZWZlcnJlZC5yZWplY3QoZXJyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRlbXBsYXRlc0RlZmVycmVkLnJlc29sdmUoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0sIHBhcmFtcyk7XHJcbiAgICAgICAgICAgICAgICAgICAgcHJvbWlzZXMucHVzaCh0ZW1wbGF0ZXNEZWZlcnJlZC5wcm9taXNlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBpZihqc0ZpbGVzLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIganNEZWZlcnJlZCA9ICRxLmRlZmVyKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgJGRlbGVnYXRlLmpzTG9hZGVyKGpzRmlsZXMsIGVyciA9PiB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGFuZ3VsYXIuaXNEZWZpbmVkKGVycikgJiYgKCRkZWxlZ2F0ZS5qc0xvYWRlci5oYXNPd25Qcm9wZXJ0eShcIm9jTGF6eUxvYWRMb2FkZXJcIikgfHwgJGRlbGVnYXRlLmpzTG9hZGVyLmhhc093blByb3BlcnR5KFwicmVxdWlyZWpzXCIpKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgJGRlbGVnYXRlLl8kbG9nLmVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBqc0RlZmVycmVkLnJlamVjdChlcnIpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAganNEZWZlcnJlZC5yZXNvbHZlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9LCBwYXJhbXMpO1xyXG4gICAgICAgICAgICAgICAgICAgIHByb21pc2VzLnB1c2goanNEZWZlcnJlZC5wcm9taXNlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBpZihwcm9taXNlcy5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBsZXQgZGVmZXJyZWQgPSAkcS5kZWZlcigpLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBlcnIgPSBcIkVycm9yOiBubyBmaWxlIHRvIGxvYWQgaGFzIGJlZW4gZm91bmQsIGlmIHlvdSdyZSB0cnlpbmcgdG8gbG9hZCBhbiBleGlzdGluZyBtb2R1bGUgeW91IHNob3VsZCB1c2UgdGhlICdpbmplY3QnIG1ldGhvZCBpbnN0ZWFkIG9mICdsb2FkJy5cIjtcclxuICAgICAgICAgICAgICAgICAgICAkZGVsZWdhdGUuXyRsb2cuZXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZWplY3QoZXJyKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGVmZXJyZWQucHJvbWlzZTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZihwYXJhbXMuc2VyaWUgJiYgcGFyYW1zLmZpbGVzLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gJHEuYWxsKHByb21pc2VzKS50aGVuKCgpID0+ICRkZWxlZ2F0ZS5maWxlc0xvYWRlcihjb25maWcsIHBhcmFtcykpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gJHEuYWxsKHByb21pc2VzKS5maW5hbGx5KHJlcyA9PiB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICRkZWxlZ2F0ZS50b2dnbGVXYXRjaChmYWxzZSk7IC8vIHN0b3Agd2F0Y2hpbmcgYW5ndWxhci5tb2R1bGUgY2FsbHNcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlcztcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBMb2FkIGEgbW9kdWxlIG9yIGEgbGlzdCBvZiBtb2R1bGVzIGludG8gQW5ndWxhclxyXG4gICAgICAgICAgICAgKiBAcGFyYW0gbW9kdWxlIE1peGVkIHRoZSBuYW1lIG9mIGEgcHJlZGVmaW5lZCBtb2R1bGUgY29uZmlnIG9iamVjdCwgb3IgYSBtb2R1bGUgY29uZmlnIG9iamVjdCwgb3IgYW4gYXJyYXkgb2YgZWl0aGVyXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSBwYXJhbXMgT2JqZWN0IG9wdGlvbmFsIHBhcmFtZXRlcnNcclxuICAgICAgICAgICAgICogQHJldHVybnMgcHJvbWlzZVxyXG4gICAgICAgICAgICAgKi9cclxuICAgICAgICAgICAgJGRlbGVnYXRlLmxvYWQgPSBmdW5jdGlvbihvcmlnaW5hbE1vZHVsZSwgb3JpZ2luYWxQYXJhbXMgPSB7fSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHNlbGYgPSB0aGlzLFxyXG4gICAgICAgICAgICAgICAgICAgIGNvbmZpZyA9IG51bGwsXHJcbiAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWRMaXN0ID0gW10sXHJcbiAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQgPSAkcS5kZWZlcigpLFxyXG4gICAgICAgICAgICAgICAgICAgIGVyclRleHQ7XHJcblxyXG4gICAgICAgICAgICAgICAgLy8gY2xlYW4gY29weVxyXG4gICAgICAgICAgICAgICAgdmFyIG1vZHVsZSA9IGFuZ3VsYXIuY29weShvcmlnaW5hbE1vZHVsZSk7XHJcbiAgICAgICAgICAgICAgICB2YXIgcGFyYW1zID0gYW5ndWxhci5jb3B5KG9yaWdpbmFsUGFyYW1zKTtcclxuXHJcbiAgICAgICAgICAgICAgICAvLyBJZiBtb2R1bGUgaXMgYW4gYXJyYXksIGJyZWFrIGl0IGRvd25cclxuICAgICAgICAgICAgICAgIGlmKGFuZ3VsYXIuaXNBcnJheShtb2R1bGUpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgLy8gUmVzdWJtaXQgZWFjaCBlbnRyeSBhcyBhIHNpbmdsZSBtb2R1bGVcclxuICAgICAgICAgICAgICAgICAgICBhbmd1bGFyLmZvckVhY2gobW9kdWxlLCBtID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWRMaXN0LnB1c2goc2VsZi5sb2FkKG0sIHBhcmFtcykpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICAvLyBSZXNvbHZlIHRoZSBwcm9taXNlIG9uY2UgZXZlcnl0aGluZyBoYXMgbG9hZGVkXHJcbiAgICAgICAgICAgICAgICAgICAgJHEuYWxsKGRlZmVycmVkTGlzdCkudGhlbihyZXMgPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZXNvbHZlKHJlcyk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgZXJyID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQucmVqZWN0KGVycik7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBkZWZlcnJlZC5wcm9taXNlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIC8vIEdldCBvciBTZXQgYSBjb25maWd1cmF0aW9uIGRlcGVuZGluZyBvbiB3aGF0IHdhcyBwYXNzZWQgaW5cclxuICAgICAgICAgICAgICAgIGlmKGFuZ3VsYXIuaXNTdHJpbmcobW9kdWxlKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGNvbmZpZyA9IHNlbGYuZ2V0TW9kdWxlQ29uZmlnKG1vZHVsZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYoIWNvbmZpZykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjb25maWcgPSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaWxlczogW21vZHVsZV1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYoYW5ndWxhci5pc09iamVjdChtb2R1bGUpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgLy8gY2FzZSB7dHlwZTogJ2pzJywgcGF0aDogbGF6eUxvYWRVcmwgKyAndGVzdE1vZHVsZS5mYWtlanMnfVxyXG4gICAgICAgICAgICAgICAgICAgIGlmKGFuZ3VsYXIuaXNEZWZpbmVkKG1vZHVsZS5wYXRoKSAmJiBhbmd1bGFyLmlzRGVmaW5lZChtb2R1bGUudHlwZSkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29uZmlnID0ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZmlsZXM6IFttb2R1bGVdXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29uZmlnID0gc2VsZi5zZXRNb2R1bGVDb25maWcobW9kdWxlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgaWYoY29uZmlnID09PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG1vZHVsZU5hbWUgPSBzZWxmLl9nZXRNb2R1bGVOYW1lKG1vZHVsZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgZXJyVGV4dCA9IGBNb2R1bGUgXCIkeyBtb2R1bGVOYW1lIHx8ICd1bmtub3duJyB9XCIgaXMgbm90IGNvbmZpZ3VyZWQsIGNhbm5vdCBsb2FkLmA7XHJcbiAgICAgICAgICAgICAgICAgICAgJGRlbGVnYXRlLl8kbG9nLmVycm9yKGVyclRleHQpO1xyXG4gICAgICAgICAgICAgICAgICAgIGRlZmVycmVkLnJlamVjdChuZXcgRXJyb3IoZXJyVGV4dCkpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBkZWZlcnJlZC5wcm9taXNlO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAvLyBkZXByZWNhdGVkXHJcbiAgICAgICAgICAgICAgICAgICAgaWYoYW5ndWxhci5pc0RlZmluZWQoY29uZmlnLnRlbXBsYXRlKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZihhbmd1bGFyLmlzVW5kZWZpbmVkKGNvbmZpZy5maWxlcykpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbmZpZy5maWxlcyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGFuZ3VsYXIuaXNTdHJpbmcoY29uZmlnLnRlbXBsYXRlKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uZmlnLmZpbGVzLnB1c2goY29uZmlnLnRlbXBsYXRlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmKGFuZ3VsYXIuaXNBcnJheShjb25maWcudGVtcGxhdGUpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25maWcuZmlsZXMuY29uY2F0KGNvbmZpZy50ZW1wbGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgdmFyIGxvY2FsUGFyYW1zID0gYW5ndWxhci5leHRlbmQoe30sIHBhcmFtcywgY29uZmlnKTtcclxuXHJcbiAgICAgICAgICAgICAgICAvLyBpZiBzb21lb25lIHVzZWQgYW4gZXh0ZXJuYWwgbG9hZGVyIGFuZCBjYWxsZWQgdGhlIGxvYWQgZnVuY3Rpb24gd2l0aCBqdXN0IHRoZSBtb2R1bGUgbmFtZVxyXG4gICAgICAgICAgICAgICAgaWYoYW5ndWxhci5pc1VuZGVmaW5lZChjb25maWcuZmlsZXMpICYmIGFuZ3VsYXIuaXNEZWZpbmVkKGNvbmZpZy5uYW1lKSAmJiAkZGVsZWdhdGUubW9kdWxlRXhpc3RzKGNvbmZpZy5uYW1lKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiAkZGVsZWdhdGUuaW5qZWN0KGNvbmZpZy5uYW1lLCBsb2NhbFBhcmFtcywgdHJ1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgJGRlbGVnYXRlLmZpbGVzTG9hZGVyKGNvbmZpZywgbG9jYWxQYXJhbXMpLnRoZW4oKCkgPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICRkZWxlZ2F0ZS5pbmplY3QobnVsbCwgbG9jYWxQYXJhbXMpLnRoZW4ocmVzID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQucmVzb2x2ZShyZXMpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0sIGVyciA9PiB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlZmVycmVkLnJlamVjdChlcnIpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgfSwgZXJyID0+IHtcclxuICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZWplY3QoZXJyKTtcclxuICAgICAgICAgICAgICAgIH0pO1xyXG5cclxuICAgICAgICAgICAgICAgIHJldHVybiBkZWZlcnJlZC5wcm9taXNlO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgLy8gcmV0dXJuIHRoZSBwYXRjaGVkIHNlcnZpY2VcclxuICAgICAgICAgICAgcmV0dXJuICRkZWxlZ2F0ZTtcclxuICAgICAgICB9KTtcclxuICAgIH0pO1xyXG5cclxufSkoYW5ndWxhcik7XHJcbiJdfQ==