private List<string> CheckNonCdnBundle(string bundleName, IEnumerable<string> allBundleDebugLines) { var errors = new List<string>(); var allFilesWithDate = _searcher.UnpackBundle(allBundleDebugLines, s => errors.Add(s)) .Select(x => new FileWithDateUpdated(_mvcAppPath, x)).ToList(); if (!allFilesWithDate.Any()) { errors.Add($"The bundle called {bundleName} did not contain any files to work on."); return errors; } var fileExtension = Path.GetExtension(allFilesWithDate.First().FileRelPath); var fileTypeInfo = _config.GetFileTypeData(fileExtension); AddErrorIfAnyFilesInBadFiles(bundleName, allFilesWithDate.Where(x => !x.Exists).Select(x => x.FileRelPath).ToList(), "were missing", errors); FileWithDateUpdated concatFileInfo = null; if (_checkForConcatFile) { concatFileInfo = new FileWithDateUpdated(_mvcAppPath, Path.Combine(_mvcAppPath, fileTypeInfo.Directory, bundleName + fileExtension)); if (!concatFileInfo.Exists) { errors.Add($"Warning: the concat file for '{bundleName}' is missing. Continuing test."); concatFileInfo = null; } } var minfiedFileInfo = new FileWithDateUpdated(_mvcAppPath, Path.Combine(_mvcAppPath, fileTypeInfo.Directory, bundleName + ".min" + fileExtension)); if (!minfiedFileInfo.Exists) { errors.Add($"The minified file for '{bundleName}' is missing."); return errors; } var newerFiles = allFilesWithDate.Where(x => x.LastWrittenUtc > (concatFileInfo ?? minfiedFileInfo).LastWrittenUtc) .Select(x => x.FileRelPath).ToList(); if (newerFiles.Any()) { var concatOrMinfied = concatFileInfo == null ? "minified" : "concat"; errors.Add( $"The {concatOrMinfied} file for '{bundleName}' is out of date. Newer files are:\n - {string.Join("\n - ", newerFiles)}"); } if (_checkForConcatFile && concatFileInfo != null && minfiedFileInfo.LastWrittenUtc < concatFileInfo.LastWrittenUtc) errors.Add($"The concat file for '{bundleName}' is newer than the minified file."); return errors; }
/// <summary> /// This checks that the minified files for each bundle is older than the /// BowerBundles.json file that defines what is in a bundle. /// </summary> /// <returns></returns> public string CheckBundleFileIsNotNewerThanMinifiedFiles() { var errors = new List<string>(); var bundleInfo = new FileWithDateUpdated(_mvcAppPath, _bundleFilePath); //Note: we exclude the cdn bundles as the minified file is not normally created by the build process var badFiles = (from bundleName in _reader.BundleNames.Where(x => !_reader.GetBundleCdnInfo(x).Any()) let fileExtension = Path.GetExtension(_reader.GetBundleDebugFiles(bundleName, "", s => errors.Add(s)).First()) let fileTypeInfo = _config.GetFileTypeData(fileExtension) let minfiedFile = new FileWithDateUpdated(_mvcAppPath, Path.Combine(fileTypeInfo.Directory, bundleName + ".min" + fileExtension)) where !minfiedFile.Exists || minfiedFile.LastWrittenUtc < bundleInfo.LastWrittenUtc select minfiedFile.FileRelPath).ToList(); if (errors.Any()) return $"Errors in the BowerBundles file: {string.Join("\n", errors)}."; return badFiles.Any() ? $"The following minified files have not been updated since the change in the bundle file:\n - {string.Join("\n - ", badFiles)}" : null; }