void AddReferencedModules(Module module) { foreach (var reference in module.References) { var referencedModule = moduleContainer.FindModule(reference); if (!modules.Contains(referencedModule)) { modules.Add(referencedModule); AddReferencedModules(referencedModule); } } }
public void Write(Module module) { var minifier = new Minifier(); textWriter.Write( minifier.MinifyStyleSheet( string.Join( "\r\n", module.Resources.Select(ReadCss) ) ) ); }
public void Write(Module module) { var minifier = new Minifier(); textWriter.Write( minifier.MinifyJavaScript( string.Join( "\r\n", module.Resources.Select(s => GetJavaScript(rootDirectory + s.Path)) ) ) ); }
public void Write_compiles_coffee_script() { using (var textWriter = new StringWriter()) { var module = new Module("a", new[] { new Resource("a/test.coffee", new byte[0], new string[0]) }, new string[0], null); var sources = new Dictionary<string, string> { { "a/test.coffee", "x = 1" } }; var moduleWriter = new ScriptModuleWriter(textWriter, "", path => sources[path], new FakeCompiler()); moduleWriter.Write(module); var output = textWriter.GetStringBuilder().ToString(); output.ShouldEqual("compiled"); } }
public void Write_minifies_all_script_content_in_given_order() { using (var textWriter = new StringWriter()) { var module = new Module("a", new[] { CreateScript("1"), CreateScript("2") }, new string[0], null); var sources = new Dictionary<string, string> { { "a/1.js", "function test1 () { }" }, { "a/2.js", "function test2 () { }" } }; var moduleWriter = new ScriptModuleWriter(textWriter, "", path => sources[path], null); moduleWriter.Write(module); var output = textWriter.GetStringBuilder().ToString(); output.ShouldEqual("function test1(){}function test2(){}"); } }
public void Compare_ModuleManifest_with_added_module_to_old_returns_difference() { var oldModuleManifest = new ModuleManifest(new Module[0]); Module module; var newModuleManifest = new ModuleManifest(new[] { module = new Module( @"scripts/module-a", new Resource[0], new string[0], null ) }); var differences = newModuleManifest.CompareTo(oldModuleManifest); differences.Length.ShouldEqual(1); differences[0].Type.ShouldEqual(ModuleDifferenceType.Added); differences[0].Module.ShouldEqual(module); }
public Resolve_an_UnresolvedModule_with_scripts_in_subdirectory() { var script1 = new UnresolvedResource( @"scripts/module-a/sub/test-1.js", new byte[0], new[] { @"test-2.js" } ); var script2 = new UnresolvedResource( @"scripts/module-a/sub/test-2.js", new byte[0], new string[] { } ); unresolvedModule = new UnresolvedModule( @"scripts/module-a", new[] { script1, script2 }, null, false ); module = unresolvedModule.Resolve(s => @"scripts/module-a"); }
public void Compare_ModuleManifest_with_changed_module_to_old_returns_Add_and_Delete_differences() { Module oldModule; var oldModuleManifest = new ModuleManifest(new[] { oldModule = new Module( @"scripts/module-a", new Resource[] { new Resource(@"scripts/module-a/test.js", new byte[] { 1 }, new string[0]) }, new string[0], null ) }); Module changedModule; var newModuleManifest = new ModuleManifest(new[] { changedModule = new Module( @"scripts/module-a", new Resource[] { new Resource(@"scripts/module-a/test.js", new byte[] { 2 }, new string[0]) }, new string[0], null ) }); var differences = newModuleManifest.CompareTo(oldModuleManifest); differences.Length.ShouldEqual(2); differences[0].Type.ShouldEqual(ModuleDifferenceType.Deleted); differences[0].Module.ShouldEqual(oldModule); differences[1].Type.ShouldEqual(ModuleDifferenceType.Added); differences[1].Module.ShouldEqual(changedModule); }
public bool Equals(Module other) { return other != null && other.path == path && HashEqual(other.hash); }
public ModuleDifference(Module module, ModuleDifferenceType type) { this.module = module; this.type = type; }
public Resolve_a_UnresolvedModule_with_script_having_an_external_reference() { var script = new UnresolvedResource( @"scripts/module-a/test.js", new byte[0], new[] { @"scripts/module-b/lib.js" } ); unresolvedModule = new UnresolvedModule( @"scripts/module-a", new[] { script }, null, false ); module = unresolvedModule.Resolve(s => @"scripts/module-b"); }
public UnresolvedModule_with_scripts_having_only_internal_references() { var scriptA = CreateScript("a", "c"); var scriptB = CreateScript("b"); var scriptC = CreateScript("c", "b"); // Dependency chain: b <- c <- a unresolvedModule = new UnresolvedModule( @"scripts/module-a", new[] { scriptA, scriptB, scriptC }, null, false ); module = unresolvedModule.Resolve(s => null); }
public UnresolvedModule_with_fixed_resource_order() { // Create scripts with some dependencies declared. var scriptA = CreateScript("a", "c"); var scriptB = CreateScript("b"); var scriptC = CreateScript("c", "b"); // Declared dependency chain: b <- c <- a unresolvedModule = new UnresolvedModule( @"scripts/module-a", new[] { scriptA, scriptB, scriptC }, null, isResourceOrderFixed: true ); module = unresolvedModule.Resolve(s => null); }