예제 #1
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;
        }
예제 #2
0
        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);
        }
예제 #3
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.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;
        }
        private Bundle createBundleOf(AutoBundle autoBundle)
        {
            var excludedFiles = new HashSet<string>(physicalPathsOf(autoBundle.Excludes), StringComparer.InvariantCultureIgnoreCase);

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

            var requiredFiles = enumerateDependenciesOf(files, excludedFiles);

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

            return new Bundle
            {
                Files = fileSpecList,
                Output = this.GetOutputPath(autoBundle.OutputPath, autoBundle.Id),
                ContainingConfig = autoBundle.ContainingConfig,
                BundleId = autoBundle.Id
            };
        }
예제 #5
0
        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);
        }
예제 #6
0
        public void CreateSingleAutoBundleItemForSameBundleId()
        {
            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 = "bootstrap" } }
                                  };

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

            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\bundleA.js",
                                                                    Includes = new List<AutoBundleItem>
                                                                                    {
                                                                                        new AutoBundleItem { File = "jquery" },
                                                                                        new AutoBundleItem { File = "amplify" }
                                                                                    },
                                                                    Excludes = new List<AutoBundleItem>
                                                                                    {
                                                                                        new AutoBundleItem { File = "bootstrap" },
                                                                                        new AutoBundleItem { File = "bforms" }
                                                                                    }
                                                                } 
                                                        };

            CustomAssert.JsonEquals(expectedCollection, merged);
        }