public IEnumerable<string> Scan(Build build) { if (!Directory.Exists(BuildFolder)) { // Need to build everything. return QuiFiles; } Build previousBuild = new Build(BuildFolder); previousBuild.AddExistingFiles(); List<string> quiFilesToCompile = new List<string>(); foreach (string quiFile in QuiFiles) { BuildUnit previousBuildUnit; bool found = previousBuild.GetCorrespondingBuildUnit(quiFile, out previousBuildUnit); if (found && !RequiresCompilation(quiFile, previousBuildUnit)) { // Up to date -- add to current build as is. build.Add(previousBuildUnit); } else { // Need to compile. quiFilesToCompile.Add(quiFile); } } return quiFilesToCompile; }
public void Typical() { string[] files = { "Class.SuperClass.js", "Foo.UnknownSuperClass.js", "NoSuperClass.js", "Subclass.Class.js", "SuperClass.js" }; Build build = new Build(); foreach (BuildUnit unit in files.Select(file => new BuildUnit(file))) { build.Add(unit); } string[] expected = { "Foo.UnknownSuperClass.js", "NoSuperClass.js", "SuperClass.js", "Class.SuperClass.js", "Subclass.Class.js" }; BuildUnit[] sortedBuildFiles = build.SortBuildUnits().ToArray(); for (int i = 0; i < sortedBuildFiles.Count(); i++) { Assert.AreEqual(expected[i], sortedBuildFiles[i].JsFileName); } }
/// <summary> /// Perform an incremental build of the project. /// </summary> public void Build() { Build build = new Build(BuildFolder); // Phase 1: Scan the project's Quick markup source files and previous // build output to determine which files need to be recompiled. IEnumerable<string> quiFilesToCompile = scanner.Scan(build); // Phase 2: Compile files that need it and add the output to the build. bool compileSuccess; if (quiFilesToCompile.Count() == 0) { // All build files up to date. compileSuccess = true; } else { compileSuccess = compiler.Compile(quiFilesToCompile, build); } // Phase 3: Create the project's combined output files. if (compileSuccess) { combiner.Combine(build); } else { // Fail; remove any (now out of date) project output. combiner.Clean(); } // Phase 4: Clean up and remove any obsolete build files. build.RemoveObsoleteFiles(); }
/// <summary> /// Combine the output of the supplied build to create the project's /// output files. /// </summary> /// <remarks> /// If there are no build files of a given type, no combined output file /// for that type will be created. /// </remarks> public void Combine(Build build) { // See if we need to recombine either of the combined files. bool combineJsFile = RequiresCombining(build.JsFiles, CombinedJsFile); bool combineCssFile = RequiresCombining(build.CssFiles, CombinedCssFile); // Only do the work if the combined files are out of date. if (combineJsFile || combineCssFile) { IEnumerable<BuildUnit> buildUnits = build.SortBuildUnits(); if (combineJsFile) { CombineFile(buildUnits, CombinedJsFile); } if (combineCssFile) { CombineFile(buildUnits, CombinedCssFile); } } }
/// <summary> /// Compile the given Quick markup files. /// Return true if successful, false if there were errors. /// </summary> /// <remarks> /// The compiled JS and CSS files are returned in the properties /// of the corresponding name. /// </remarks> public bool Compile(IEnumerable<string> quiFiles, Build currentBuild) { if (!Directory.Exists(BuildFolder)) { Directory.CreateDirectory(BuildFolder); } bool batchSuccess = true; foreach (string quiFile in quiFiles) { BuildUnit buildUnit; bool fileSuccess = Compile(quiFile, out buildUnit); if (fileSuccess) { currentBuild.Add(buildUnit); } else { batchSuccess = false; } } return batchSuccess; }