private static int Run(BundleFileProcessor processor, string configPath, string file, bool isClean) { var configs = GetConfigs(configPath, file); if (configs == null || !configs.Any()) { Console.WriteLine("No configurations matched".Orange().Bright()); return(-1); } try { if (isClean) { processor.Clean(configPath, configs); } else { processor.Process(configPath, configs); } return(0); } catch (Exception ex) { Console.WriteLine($"{ex.Message}".Red().Bright()); return(-1); } }
/// <summary> /// Execute the Task /// </summary> public override bool Execute() { FileInfo configFile = new FileInfo(FileName); if (!configFile.Exists) { Log.LogWarning(configFile.FullName + " does not exist"); return true; } Log.LogMessage(MessageImportance.High, Environment.NewLine + "Bundler: Begin processing " + configFile.Name); Telemetry.SetDeviceName("MSBuild"); BundleFileProcessor processor = new BundleFileProcessor(); processor.Processing += (s, e) => { RemoveReadonlyFlagFromFile(e.Bundle.GetAbsoluteOutputFile()); }; processor.AfterBundling += Processor_AfterProcess; BundleMinifier.BeforeWritingMinFile += (s, e) => { RemoveReadonlyFlagFromFile(e.ResultFile); }; processor.BeforeWritingSourceMap += (s, e) => { RemoveReadonlyFlagFromFile(e.ResultFile); }; processor.AfterWritingSourceMap += Processor_AfterWritingSourceMap; BundleMinifier.ErrorMinifyingFile += BundleMinifier_ErrorMinifyingFile; BundleMinifier.AfterWritingMinFile += FileMinifier_AfterWritingMinFile; processor.Process(configFile.FullName); Log.LogMessage(MessageImportance.High, "Bundler: Done processing " + configFile.Name); return _isSuccessful; }
static int Main(params string[] args) { string configPath = args[0]; string file = args.Length > 1 ? args[1] : null; var configs = GetConfigs(configPath, file); if (configs == null) { Console.WriteLine("\x1B[33mNo configurations matched"); return 0; } BundleFileProcessor processor = new BundleFileProcessor(); EventHookups(processor, configPath); try { processor.Process(configPath, configs); return 0; } catch (Exception ex) { Console.WriteLine($"\x1B[33m{ex.Message}"); return 1; } }
/// <summary> /// Execute the Task /// </summary> public override bool Execute() { FileInfo configFile = new FileInfo(FileName); Log.LogMessage(MessageImportance.High, Environment.NewLine + "Bundler: Begin processing " + configFile.Name); if (!configFile.Exists) { Log.LogWarning(configFile.FullName + " does not exist"); return(true); } BundleFileProcessor processor = new BundleFileProcessor(); processor.BeforeProcess += (s, e) => { RemoveReadonlyFlagFromFile(e.Bundle.GetAbsoluteOutputFile()); }; processor.AfterProcess += Processor_AfterProcess; processor.BeforeWritingSourceMap += (s, e) => { RemoveReadonlyFlagFromFile(e.ResultFile); }; processor.AfterWritingSourceMap += Processor_AfterWritingSourceMap; BundleMinifier.ErrorMinifyingFile += BundleMinifier_ErrorMinifyingFile; BundleMinifier.AfterWritingMinFile += FileMinifier_AfterWritingMinFile; processor.Process(configFile.FullName); Log.LogMessage(MessageImportance.High, "Bundler: Done processing " + configFile.Name); return(_isSuccessful); }
static int Main(params string[] args) { if (args.Length == 0) { Console.WriteLine("\x1B[33mUsage: BundlerMinifier <configPath> [configFile]"); return(0); } string configPath = args[0]; string file = args.Length > 1 ? args[1] : null; var configs = GetConfigs(configPath, file); if (configs == null) { Console.WriteLine("\x1B[33mNo configurations matched"); return(0); } BundleFileProcessor processor = new BundleFileProcessor(); EventHookups(processor, configPath); try { processor.Process(configPath, configs); return(0); } catch (Exception ex) { Console.WriteLine($"\x1B[33m{ex.Message}"); return(1); } }
/// <summary> /// Execute the Task /// </summary> public override bool Execute() { try { Log.LogMessage(MessageImportance.High, $"{Environment.NewLine}BundleConfig: {FileName}"); FileInfo configFile = new FileInfo(FileName); if (!configFile.Exists) { Log.LogWarning(configFile.FullName + " does not exist"); return(true); } Log.LogMessage(MessageImportance.High, Environment.NewLine + $"Bundler: Begin processing {configFile.Name}"); BundleFileProcessor processor = new BundleFileProcessor(); processor.Processing += (s, e) => { RemoveReadonlyFlagFromFile(e.Bundle.GetAbsoluteOutputFile()); }; processor.AfterBundling += Processor_AfterProcess; BundleMinifier.BeforeWritingMinFile += (s, e) => { RemoveReadonlyFlagFromFile(e.ResultFile); }; processor.BeforeWritingSourceMap += (s, e) => { RemoveReadonlyFlagFromFile(e.ResultFile); }; processor.AfterWritingSourceMap += Processor_AfterWritingSourceMap; BundleMinifier.ErrorMinifyingFile += BundleMinifier_ErrorMinifyingFile; BundleMinifier.AfterWritingMinFile += FileMinifier_AfterWritingMinFile; processor.Process(configFile.FullName); Log.LogMessage(MessageImportance.High, $"Bundler: Done processing {configFile.Name}"); } catch (Exception e) { _isSuccessful = false; Log.LogErrorFromException(e); Log.LogErrorFromException(e.InnerException); } return(_isSuccessful); }
public bool FilesChanged(FileSystemEventArgs e) { if (!IsFileValid(e.FullPath)) { return(false); } if (!BundleFileProcessor.IsFileConfigured(_configFile, e.FullPath).Any()) { return(false); } var inputs = _bundle.GetAbsoluteInputFiles(); var inputLastModified = inputs.Count > 0 ? inputs.Max(inputFile => File.GetLastWriteTimeUtc(inputFile)) : DateTime.MaxValue; if ((_bundle.GetAbsoluteInputFiles().Count > 1 || _bundle.InputFiles.FirstOrDefault() != _bundle.OutputFileName) && inputLastModified > File.GetLastWriteTimeUtc(_bundle.GetAbsoluteOutputFile())) { return(_processor.Process(_configFile, new Bundle[] { _bundle })); } return(false); }
private static bool ReloadConfig() { bool anyChanges = false; IEnumerable <Bundle> bundles; if (!BundleHandler.TryGetBundles(_configPath, out bundles)) { throw new Exception("Unable to load bundles."); } var oldHandlers = ChangeHandlers.ToList(); if (!_watchingAll) { foreach (ChangeHandler handler in oldHandlers) { Bundle bundle = bundles.FirstOrDefault(x => string.Equals(x.OutputFileName, handler.Bundle.OutputFileName, StringComparison.OrdinalIgnoreCase)); if (bundle != null) { ChangeHandler newHandler = new ChangeHandler(_processor, bundle.FileName, bundle); if (!newHandler.Equals(handler)) { ChangeHandlers.Remove(handler); ChangeHandlers.Add(newHandler); _processor.Process(_configPath, new[] { bundle }); anyChanges = true; } } else { ChangeHandlers.Remove(handler); Console.WriteLine($"Cannot find configuration {handler.Bundle.OutputFileName}".Orange().Bright()); } } } else { HashSet <Bundle> bundlesToProcess = new HashSet <Bundle>(bundles); foreach (ChangeHandler handler in oldHandlers) { Bundle bundle = bundles.FirstOrDefault(x => string.Equals(x.OutputFileName, handler.Bundle.OutputFileName, StringComparison.OrdinalIgnoreCase)); if (bundle != null) { bundlesToProcess.Remove(bundle); ChangeHandler newHandler = new ChangeHandler(_processor, bundle.FileName, bundle); if (!newHandler.Equals(handler)) { ChangeHandlers.Remove(handler); ChangeHandlers.Add(newHandler); _processor.Process(_configPath, new[] { bundle }); anyChanges = true; } } } foreach (Bundle bundle in bundlesToProcess) { ChangeHandlers.Add(new ChangeHandler(_processor, _configPath, bundle)); _processor.Process(_configPath, new[] { bundle }); anyChanges = true; } } return(anyChanges); }