Exemple #1
0
        public void ExpandLocalPathWhenAvailable()
        {
            var expected = "/jquery";
            var actual   = ScriptProcessor.ExpandPaths("jquery_with_fallback", configuration);

            Assert.Equal(expected, actual);
        }
Exemple #2
0
        public void NotExpandMatchesInsidePaths()
        {
            var expected = "my/jquery/alternative";
            var actual   = ScriptProcessor.ExpandPaths("my/jquery/alternative", configuration);

            Assert.Equal(expected, actual);
        }
Exemple #3
0
        public void NotExpandPartialMatches()
        {
            var expected = "jqueryui";
            var actual   = ScriptProcessor.ExpandPaths("jqueryui", configuration);

            Assert.Equal(expected, actual);
        }
Exemple #4
0
        public void ExpandsStartOfPath()
        {
            var expected = "/somewhere/jquery-1.10.2/jquery/subfile";
            var actual   = ScriptProcessor.ExpandPaths("jquery/subfile", configuration);

            Assert.Equal(expected, actual);
        }
Exemple #5
0
        public void DoCaseInsensitiveMatches()
        {
            var expected = "/somewhere/jquery-1.10.2/jquery";
            var actual   = ScriptProcessor.ExpandPaths("JQuERy", configuration);

            Assert.Equal(expected, actual);
        }
Exemple #6
0
        public void ExpandsExactMatches()
        {
            var expected = "/somewhere/jquery-1.10.2/jquery";
            var actual   = ScriptProcessor.ExpandPaths("jquery", configuration);

            Assert.Equal(expected, actual);
        }
Exemple #7
0
        public void LeaveRelativePaths()
        {
            var expected = "relative/url";
            var actual   = ScriptProcessor.ExpandPaths("relative/url", configuration);

            Assert.Equal(expected, actual);
        }
        private IEnumerable <string> physicalPathsOf(IEnumerable <AutoBundleItem> autoBundleItems)
        {
            var baseUrl = Path.Combine(ProjectPath, "Scripts");

            foreach (var item in autoBundleItems)
            {
                // check if the file path is actually an URL
                if (!string.IsNullOrEmpty(item.File) && !item.File.Contains("?"))
                {
                    var path = ScriptProcessor.ExpandPaths(item.File, Configuration);
                    yield return(this.ResolvePhysicalPath(path, baseUrl));
                }
                else if (!string.IsNullOrEmpty(item.Directory))
                {
                    var absDirectory = this.GetAbsoluteDirectory(item.Directory);

                    // not using filter for this since we're going to use the one the user provided in the future
                    var dirFiles = Directory.GetFiles(absDirectory, "*", SearchOption.AllDirectories).Where(r => Path.GetExtension(r) == ".js").ToList();
                    foreach (var file in dirFiles)
                    {
                        yield return(file);
                    }
                }
            }
        }
        private IEnumerable <string> physicalPathsOf(IEnumerable <AutoBundleItem> autoBundleItems, HashSet <string> excludedFiles)
        {
            var baseUrl = Path.Combine(ProjectPath, "Scripts");

            foreach (var item in autoBundleItems)
            {
                // check if the file path is actually an URL
                if (!string.IsNullOrEmpty(item.File) && !item.File.Contains("?"))
                {
                    item.File = ScriptProcessor.ExpandPaths(item.File, Configuration);

                    if (!excludedFiles.Contains(item.File))
                    {
                        var physicalPath = this.ResolvePhysicalPath(item.File, baseUrl);
                        if (physicalPath == null)
                        {
                            Log?.LogError($"Could not to resolve path for {item.File}. File does not exist in {baseUrl}! Did you forget to include it in the project?");
                        }
                        yield return(physicalPath);
                    }
                    else
                    {
                        Log?.LogMessage(LogLevel, $"    - EXCLUDING {item.File}");
                    }
                }
                else if (!string.IsNullOrEmpty(item.Directory))
                {
                    item.Directory = ScriptProcessor.ExpandPaths(item.Directory, Configuration);

                    var absDirectory = this.GetAbsoluteDirectory(item.Directory);
                    Log?.LogMessage(LogLevel, $"    - Directory '{item.Directory}' -> {absDirectory}");

                    // not using filter for this since we're going to use the one the user provided in the future
                    var dirFiles = Directory.GetFiles(absDirectory, "*", SearchOption.AllDirectories).Where(r => Path.GetExtension(r) == ".js").ToList();
                    foreach (var file in dirFiles)
                    {
#warning We try to match absolute paths here while we match relative paths above?!
                        if (!excludedFiles.Contains(file))
                        {
                            yield return(file);
                        }
                        else
                        {
                            Log?.LogMessage(LogLevel, $"    - EXCLUDING {file} from {item.Directory}");
                        }
                    }
                }
            }
        }
Exemple #10
0
        public void ExpandUrlsToNull()
        {
            var actual = ScriptProcessor.ExpandPaths("external_jquery", configuration);

            Assert.Null(actual);
        }