/// <summary> /// Parses a compiler config file and deletes all outputs including .min and .min.map files /// </summary> public void DeleteOutputFiles(string configFile) { var configs = ConfigHandler.GetConfigs(configFile); foreach (var item in configs) { var outputFile = item.GetAbsoluteOutputFile().FullName; var minFile = Path.ChangeExtension(outputFile, ".min" + Path.GetExtension(outputFile)); var mapFile = minFile + ".map"; var gzipFile = minFile + ".gz"; DeleteFile(outputFile); DeleteFile(minFile); DeleteFile(mapFile); DeleteFile(gzipFile); } }
private static object _syncRoot = new object(); // Used for source file changes so they don't try to write to the same file at the same time. /// <summary> /// Parses a compiler config file and runs the configured compilers. /// </summary> /// <param name="configFile">The absolute or relative file path to compilerconfig.json</param> /// <param name="configs">Optional configuration items in the config file</param> /// <param name="force">Forces compilation of all config items.</param> /// <returns>A list of compiler results.</returns> public IEnumerable <CompilerResult> Process(string configFile, IEnumerable <Config> configs = null, bool force = false) { if (_processing.Contains(configFile)) { return(Enumerable.Empty <CompilerResult>()); } _processing.Add(configFile); List <CompilerResult> list = new List <CompilerResult>(); try { FileInfo info = new FileInfo(configFile); configs = configs ?? ConfigHandler.GetConfigs(configFile); if (configs.Any()) { OnConfigProcessed(configs.First(), 0, configs.Count()); } foreach (Config config in configs) { if (force || config.CompilationRequired()) { if (!GlobHelper.IsGlobPattern(config.InputFile)) { var result = ProcessConfig(info.Directory.FullName, config); list.Add(result); OnConfigProcessed(config, list.Count, configs.Count()); } } } } finally { if (_processing.Contains(configFile)) { _processing.Remove(configFile); } } return(list); }
/// <summary> /// Compiles all configs with the same input file extension as the specified sourceFile /// </summary> public IEnumerable <CompilerResult> SourceFileChanged(string configFile, string sourceFile) { lock (_syncRoot) { string folder = Path.GetDirectoryName(configFile); List <CompilerResult> list = new List <CompilerResult>(); var configs = ConfigHandler.GetConfigs(configFile); // Compile if the file if it's referenced directly in compilerconfig.json foreach (Config config in configs) { string input = Path.Combine(folder, config.InputFile.Replace("/", "\\")); if (input.Equals(sourceFile, StringComparison.OrdinalIgnoreCase)) { list.Add(ProcessConfig(folder, config)); } } // If not referenced directly, compile all configs with same file extension if (list.Count == 0) { string sourceExtension = Path.GetExtension(sourceFile); foreach (Config config in configs) { string inputExtension = Path.GetExtension(config.InputFile); if (inputExtension.Equals(sourceExtension, StringComparison.OrdinalIgnoreCase)) { list.Add(ProcessConfig(folder, config)); } } } return(list); } }
private static IEnumerable <Config> GetConfigs(string configPath, string file) { var configs = ConfigHandler.GetConfigs(configPath); if (configs == null || !configs.Any()) { return(null); } if (file != null) { if (file.StartsWith("*")) { configs = configs.Where(c => Path.GetExtension(c.InputFile).Equals(file.Substring(1), StringComparison.OrdinalIgnoreCase)); } else { configs = configs.Where(c => c.InputFile.Equals(file, StringComparison.OrdinalIgnoreCase)); } } return(configs); }
/// <summary> /// Compiles all configs with the same input file extension as the specified sourceFile /// </summary> private IEnumerable <CompilerResult> SourceFileChanged(string configFile, string sourceFile, string projectPath, HashSet <string> compiledFiles) { lock (_syncRoot) { string folder = Path.GetDirectoryName(configFile); List <CompilerResult> list = new List <CompilerResult>(); var configs = ConfigHandler.GetConfigs(configFile); // Compile if the file if it's referenced directly in compilerconfig.json foreach (Config config in configs) { string input = Path.Combine(folder, config.InputFile.Replace("/", "\\")); if (input.Equals(sourceFile, StringComparison.OrdinalIgnoreCase)) { list.Add(ProcessConfig(folder, config)); compiledFiles.Add(input.ToLowerInvariant()); } } //compile files that are dependent on the current file var dependencies = DependencyService.GetDependencies(projectPath, sourceFile); if (dependencies != null) { string key = sourceFile.ToLowerInvariant(); if (dependencies.ContainsKey(key)) { //compile all files that have references to the compiled file foreach (var file in dependencies[key].DependentFiles.ToArray()) { if (!compiledFiles.Contains(file.ToLowerInvariant())) { list.AddRange(SourceFileChanged(configFile, file, projectPath, compiledFiles)); } } } } else { // If not referenced directly, compile all configs with same file extension if (list.Count == 0) { string sourceExtension = Path.GetExtension(sourceFile); foreach (Config config in configs) { string inputExtension = Path.GetExtension(config.InputFile); if (inputExtension.Equals(sourceExtension, StringComparison.OrdinalIgnoreCase)) { list.Add(ProcessConfig(folder, config)); } } } } return(list); } }