public void DeleteOutputFiles(string bundleFileName)
        {
            var bundles = BundleHandler.GetBundles(bundleFileName);

            foreach (Bundle bundle in bundles)
            {
                var outputFile = bundle.GetAbsoluteOutputFile();
                var minFile    = BundleFileProcessor.GetMinFileName(outputFile);
                var mapFile    = minFile + ".map";

                if (File.Exists(outputFile))
                {
                    File.Delete(outputFile);
                }
                if (File.Exists(minFile))
                {
                    File.Delete(minFile);
                }
                if (File.Exists(mapFile))
                {
                    File.Delete(mapFile);
                }
            }

            Telemetry.TrackEvent("Delete output files");
        }
Example #2
0
        internal List <string> GetAbsoluteInputFiles()
        {
            List <string> files   = new List <string>();
            string        folder  = new DirectoryInfo(Path.GetDirectoryName(FileName)).FullName;
            string        ext     = Path.GetExtension(InputFiles.First());
            Options       options = new Options {
                AllowWindowsPaths = true
            };

            foreach (string inputFile in InputFiles.Where(f => !f.StartsWith("!", StringComparison.Ordinal)))
            {
                int globIndex = inputFile.IndexOf('*');

                if (globIndex > -1)
                {
                    string relative = string.Empty;
                    int    last     = inputFile.LastIndexOf('/', globIndex);

                    if (last > -1)
                    {
                        relative = inputFile.Substring(0, last + 1);
                    }

                    var output    = GetAbsoluteOutputFile();
                    var outputMin = BundleFileProcessor.GetMinFileName(output);

                    string searchDir = new FileInfo(Path.Combine(folder, relative).Replace("/", "\\")).FullName;
                    var    allFiles  = Directory.EnumerateFiles(searchDir, "*" + ext, SearchOption.AllDirectories).Select(f => f.Replace(folder + "\\", ""));

                    var matches = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f));
                    matches = matches.Where(match => match != output && match != outputMin);
                    files.AddRange(matches.Where(f => !files.Contains(f)));
                }
                else
                {
                    string fullPath = Path.Combine(folder, inputFile).Replace("/", "\\");

                    if (Directory.Exists(fullPath))
                    {
                        DirectoryInfo dir      = new DirectoryInfo(fullPath);
                        SearchOption  search   = SearchOption.TopDirectoryOnly;
                        var           dirFiles = dir.GetFiles("*" + Path.GetExtension(OutputFileName), search);
                        files.AddRange(dirFiles.Select(f => f.FullName).Where(f => !files.Contains(f)));
                    }
                    else
                    {
                        files.Add(fullPath);
                    }
                }
            }

            // Remove files starting with a !
            foreach (string inputFile in InputFiles)
            {
                int globIndex = inputFile.IndexOf('!');

                if (globIndex == 0)
                {
                    var allFiles = files.Select(f => f.Replace(folder + "\\", ""));
                    var matches  = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f));
                    files = matches.ToList();
                }
            }

            return(files);
        }