public void ReadAutoBundles()
        {
            var config     = ReadJson(new TestFileReader());
            var autoBundle = new AutoBundle
            {
                Id         = "full",
                OutputPath = @"bundles\auto\",
                Includes   =
                    new List <AutoBundleItem>
                {
                    new AutoBundleItem
                    {
                        Directory = @"\controllers\Root\",
                    },
                    new AutoBundleItem
                    {
                        File = "jquery-1.10.2"
                    }
                },
                Excludes         = new List <AutoBundleItem>(),
                ContainingConfig = "JsonReaderShould.ReadAutoBundles.json"
            };
            var expected = ConfigurationCreators.CreateCollectionWithAutoBundles(autoBundle);

            CustomAssert.JsonEquals(expected, config);
        }
        private Bundle createBundleOf(AutoBundle autoBundle)
        {
            Log?.LogMessage(LogLevel, $"Creating bundle {autoBundle.Id} for {autoBundle.Includes.Count} includes at {autoBundle.OutputPath}");

            var excludedFiles = new HashSet <string>(physicalPathsOf(autoBundle.Excludes), StringComparer.InvariantCultureIgnoreCase);

            Log?.LogMessage(LogLevel, $" - Identified {excludedFiles.Count} excluded files.");

            var files = physicalPathsOf(autoBundle.Includes, excludedFiles).Distinct().ToList();

            Log?.LogMessage(LogLevel, $" - Looked up physical paths of {files.Count} files.");

            var requiredFiles = enumerateDependenciesOf(files, excludedFiles);

            Log?.LogMessage(LogLevel, $" - Enumerated {requiredFiles.Count} dependencies.");

            var fileSpecList = requiredFilesByDependency(requiredFiles, excludedFiles, autoBundle.CompressionType);

            Log?.LogMessage(LogLevel, $" - Created {fileSpecList.Count} fileSpecLists.");
            foreach (var file in fileSpecList)
            {
                Log?.LogMessage(LogLevel, $"    - {file.FileName}: {file.FileContent.Length} chars");
            }

            return(new Bundle
            {
                Files = fileSpecList,
                Output = this.GetOutputPath(autoBundle.OutputPath, autoBundle.Id),
                ContainingConfig = autoBundle.ContainingConfig,
                BundleId = autoBundle.Id
            });
        }
        public void CreateSingleAutoBundleListForDifferentBundleIds()
        {
            var firstBundle = new AutoBundle
            {
                Id         = "bundleA",
                OutputPath = @"\Scripts\bundleA.js",
                Includes   = new List <AutoBundleItem> {
                    new AutoBundleItem {
                        File = "jquery"
                    }
                },
                Excludes = new List <AutoBundleItem> {
                    new AutoBundleItem {
                        File = "jquery"
                    }
                }
            };
            var secondBundle = new AutoBundle
            {
                Id         = "bundleB",
                OutputPath = @"\Scripts\bundleB.js",
                Includes   = new List <AutoBundleItem> {
                    new AutoBundleItem {
                        File = "jquery"
                    }
                },
                Excludes = new List <AutoBundleItem> {
                    new AutoBundleItem {
                        File = "jquery"
                    }
                }
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithAutoBundles(firstBundle);
            var secondCollection = ConfigurationCreators.CreateCollectionWithAutoBundles(secondBundle);

            var merger = ConfigurationCreators.CreateDefaultConfigMerger(firstCollection, secondCollection);
            var merged = merger.GetMerged();

            var expectedCollection = ConfigurationCreators.CreateEmptyCollection();

            expectedCollection.AutoBundles.Bundles = new List <AutoBundle>
            {
                firstBundle,
                secondBundle
            };

            CustomAssert.JsonEquals(expectedCollection, merged);
        }
        private AutoBundles GetAutoBundles(JObject document)
        {
            var autoBundles = new AutoBundles();

            autoBundles.Bundles = new List <AutoBundle>();
            string parseSection = "autoBundles";

            if (document != null && document[parseSection] != null)
            {
                JToken autoBundlesParent = JsonParseOrThrow <JObject>(document[parseSection], parseSection, Path, null);
                autoBundles.Bundles = autoBundlesParent.Select(
                    r =>
                {
                    var currentBundle       = new AutoBundle();
                    var prop                = (JProperty)r;
                    currentBundle.Id        = prop.Name;
                    string parseSectionHint = parseSection + "." + prop.Name;
                    var valueObj            = prop.Value as JObject;
                    if (valueObj != null)
                    {
                        currentBundle.OutputPath       = JsonParseStringOrThrow(valueObj, "outputPath", parseSectionHint, Path);
                        currentBundle.CompressionType  = JsonParseStringOrThrow(valueObj, "compressionType", parseSectionHint, Path);
                        currentBundle.ContainingConfig = Path;
                        currentBundle.Includes         = new List <AutoBundleItem>();
                        if (valueObj["include"] != null)
                        {
                            JToken includeParent   = JsonParseOrThrow <JArray>(valueObj["include"], parseSection, Path, null);
                            currentBundle.Includes = includeParent.Select(x => autoBundleItemFrom(x, parseSectionHint)).ToList();
                        }
                        currentBundle.Excludes = new List <AutoBundleItem>();
                        if (valueObj["exclude"] != null)
                        {
                            JToken excludeParent   = JsonParseOrThrow <JArray>(valueObj["exclude"], parseSection, Path, null);
                            currentBundle.Excludes = excludeParent.Select(x => autoBundleItemFrom(x, parseSectionHint)).ToList();
                        }
                    }

                    return(currentBundle);
                }).ToList();
            }

            return(autoBundles);
        }
        private Bundle createBundleOf(AutoBundle autoBundle)
        {
            Log?.LogMessage(LogLevel, $"Creating bundle {autoBundle.Id} for {autoBundle.Includes.Count} includes at {autoBundle.OutputPath}");

            var excludedFiles = new HashSet <string>(physicalPathsOf(autoBundle.Excludes), StringComparer.InvariantCultureIgnoreCase);

            Log?.LogMessage(LogLevel, $" - Identified {excludedFiles.Count} excluded files.");

            var files = physicalPathsOf(autoBundle.Includes, excludedFiles).Distinct().ToList();

            Log?.LogMessage(LogLevel, $" - Looked up physical paths of {files.Count} files.");

            // check if provided paths make sense
            if (files.Count == 0 || files[0] == null)
            {
                throw new ArgumentException($"Error for autoBundle {autoBundle.Id}: "
                                            + "Provided list of includes: \"" + string.Join(";", autoBundle.Includes) + "\""
                                            + (excludedFiles.Count > 0 ? (" without excludes: \"" + string.Join(";", excludedFiles)) + "\"" : "")
                                            + " results in empty autoBundle.");
            }

            var requiredFiles = enumerateDependenciesOf(files, excludedFiles);

            Log?.LogMessage(LogLevel, $" - Enumerated {requiredFiles.Count} dependencies.");

            var fileSpecList = requiredFilesByDependency(requiredFiles, excludedFiles, autoBundle.CompressionType);

            Log?.LogMessage(LogLevel, $" - Created {fileSpecList.Count} fileSpecLists.");
            foreach (var file in fileSpecList)
            {
                Log?.LogMessage(LogLevel, $"    - {file.FileName}: {file.FileContent.Length} chars");
            }

            return(new Bundle
            {
                Files = fileSpecList,
                Output = this.GetOutputPath(autoBundle.OutputPath, autoBundle.Id),
                ContainingConfig = autoBundle.ContainingConfig,
                BundleId = autoBundle.Id
            });
        }
        public void OverrideOutputPathForAutoBundleWithSameId()
        {
            var firstBundle = new AutoBundle
            {
                Id         = "bundleA",
                OutputPath = @"\Scripts\bundleA.js",
                Includes   = new List <AutoBundleItem>(),
                Excludes   = new List <AutoBundleItem>()
            };

            var secondBundle = new AutoBundle
            {
                Id         = "bundleA",
                OutputPath = @"\Scripts\bundleB.js",
                Includes   = new List <AutoBundleItem>(),
                Excludes   = new List <AutoBundleItem>()
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithAutoBundles(firstBundle);
            var secondCollection = ConfigurationCreators.CreateCollectionWithAutoBundles(secondBundle);

            var merger = ConfigurationCreators.CreateDefaultConfigMerger(firstCollection, secondCollection);
            var merged = merger.GetMerged();

            var expectedCollection = ConfigurationCreators.CreateEmptyCollection();

            expectedCollection.AutoBundles.Bundles = new List <AutoBundle>
            {
                new AutoBundle
                {
                    Id         = "bundleA",
                    OutputPath = @"\Scripts\bundleB.js",
                    Includes   = new List <AutoBundleItem>(),
                    Excludes   = new List <AutoBundleItem>()
                }
            };

            CustomAssert.JsonEquals(expectedCollection, merged);
        }
        private AutoBundles GetAutoBundles(JObject document)
        {
            var autoBundles = new AutoBundles();

            autoBundles.Bundles = new List <AutoBundle>();
            if (document != null && document["autoBundles"] != null)
            {
                autoBundles.Bundles = document["autoBundles"].Select(
                    r =>
                {
                    var currentBundle = new AutoBundle();
                    var prop          = (JProperty)r;
                    currentBundle.Id  = prop.Name;
                    var valueObj      = prop.Value as JObject;
                    if (valueObj != null)
                    {
                        currentBundle.OutputPath       = valueObj["outputPath"] != null ? valueObj["outputPath"].ToString() : null;
                        currentBundle.CompressionType  = valueObj["compressionType"] != null ? valueObj["compressionType"].ToString() : null;
                        currentBundle.ContainingConfig = Path;
                        currentBundle.Includes         = new List <AutoBundleItem>();
                        if (valueObj["include"] != null)
                        {
                            currentBundle.Includes = valueObj["include"].Select(x => autoBundleItemFrom(x)).ToList();
                        }
                        currentBundle.Excludes = new List <AutoBundleItem>();
                        if (valueObj["exclude"] != null)
                        {
                            currentBundle.Excludes = valueObj["exclude"].Select(x => autoBundleItemFrom(x)).ToList();
                        }
                    }

                    return(currentBundle);
                }).ToList();
            }

            return(autoBundles);
        }
Exemple #8
0
        private AutoBundles GetAutoBundles(JObject document)
        {
            var autoBundles = new AutoBundles();

            autoBundles.Bundles = new List <AutoBundle>();
            if (document != null && document["autoBundles"] != null)
            {
                autoBundles.Bundles = document["autoBundles"].Select(
                    r =>
                {
                    var currentBundle = new AutoBundle();
                    var prop          = (JProperty)r;
                    currentBundle.Id  = prop.Name;
                    var valueObj      = prop.Value as JObject;
                    if (valueObj != null)
                    {
                        currentBundle.OutputPath       = valueObj["outputPath"] != null ? valueObj["outputPath"].ToString() : null;
                        currentBundle.ContainingConfig = Path;
                        currentBundle.Includes         = new List <AutoBundleItem>();
                        if (valueObj["include"] != null)
                        {
                            currentBundle.Includes = valueObj["include"].Select(
                                x =>
                            {
                                var includesObj = x as JObject;
                                var inclItem    = new AutoBundleItem();
                                if (includesObj == null)
                                {
                                    return(inclItem);
                                }

                                inclItem.BundleId  = includesObj["bundleId"] != null ? includesObj["bundleId"].ToString() : null;
                                inclItem.File      = includesObj["file"] != null ? includesObj["file"].ToString() : null;
                                inclItem.Directory = includesObj["directory"] != null ? includesObj["directory"].ToString() : null;
                                return(inclItem);
                            })
                                                     .ToList();
                        }
                        currentBundle.Excludes = new List <AutoBundleItem>();
                        if (valueObj["exclude"] != null)
                        {
                            currentBundle.Excludes = valueObj["exclude"].Select(
                                x =>
                            {
                                var includesObj = x as JObject;
                                var inclItem    = new AutoBundleItem();
                                if (includesObj == null)
                                {
                                    return(inclItem);
                                }

                                inclItem.BundleId  = includesObj["bundleId"] != null ? includesObj["bundleId"].ToString() : null;
                                inclItem.File      = includesObj["file"] != null ? includesObj["file"].ToString() : null;
                                inclItem.Directory = includesObj["directory"] != null ? includesObj["directory"].ToString() : null;
                                return(inclItem);
                            })
                                                     .ToList();
                        }
                    }

                    return(currentBundle);
                }).ToList();
            }

            return(autoBundles);
        }