private static int Run(BundleFileProcessor processor, string configPath, string file, bool isClean) { var configs = GetConfigs(configPath, file); if (configs == null || !configs.Any()) { System.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) { System.Console.WriteLine($"{ex.Message}".Red().Bright()); return(-1); } }
public PageHeadBuilder( CommonSettings commonSettings, IActionContextAccessor actionContextAccessor, IHostingEnvironment hostingEnvironment, IAppFileProvider fileProvider, IStaticCacheManager cacheManager, IUrlHelperFactory urlHelperFactory ) { _processor = new BundleFileProcessor(); _commonSettings = commonSettings; _actionContextAccessor = actionContextAccessor; _hostingEnvironment = hostingEnvironment; _fileProvider = fileProvider; _cacheManager = cacheManager; _urlHelperFactory = urlHelperFactory; _titleParts = new List <string>(); _metaDescriptionParts = new List <string>(); _metaKeywordParts = new List <string>(); _scriptParts = new Dictionary <ResourceLocation, List <ScriptReferenceMeta> >(); _inlineScriptParts = new Dictionary <ResourceLocation, List <string> >(); _cssParts = new Dictionary <ResourceLocation, List <CssReferenceMeta> >(); _canonicalUrlParts = new List <string>(); _headCustomParts = new List <string>(); _pageCssClassParts = new List <string>(); }
public PageHeadBuilder(CachingSettings cachingSettings, CommonSettings commonSettings, IActionContextAccessor actionContextAccessor, ICacheKeyService cacheKeyService, IWebHostEnvironment webHostEnvironment, INopFileProvider fileProvider, IStaticCacheManager staticCacheManager, IUrlHelperFactory urlHelperFactory, IUrlRecordService urlRecordService, SeoSettings seoSettings ) { _processor = new BundleFileProcessor(); _cachingSettings = cachingSettings; _commonSettings = commonSettings; _actionContextAccessor = actionContextAccessor; _cacheKeyService = cacheKeyService; _webHostEnvironment = webHostEnvironment; _fileProvider = fileProvider; _staticCacheManager = staticCacheManager; _urlHelperFactory = urlHelperFactory; _urlRecordService = urlRecordService; _seoSettings = seoSettings; _titleParts = new List <string>(); _metaDescriptionParts = new List <string>(); _metaKeywordParts = new List <string>(); _scriptParts = new Dictionary <ResourceLocation, List <ScriptReferenceMeta> >(); _inlineScriptParts = new Dictionary <ResourceLocation, List <string> >(); _cssParts = new Dictionary <ResourceLocation, List <CssReferenceMeta> >(); _canonicalUrlParts = new List <string>(); _headCustomParts = new List <string>(); _pageCssClassParts = new List <string>(); }
private bool IsFileValid(string file) { try { string fileName = Path.GetFileName(file); // VS adds ~ to temp file names so let's ignore those if (fileName.Contains('~') || fileName.Contains(".min.")) { return(false); } if (_ignorePatterns.Any(p => file.IndexOf(p) > -1)) { //var fsw = (FileSystemWatcher)sender; //fsw.EnableRaisingEvents = false; return(false); } if (!BundleFileProcessor.IsSupported(file)) { return(false); } return(true); } catch (Exception) { return(false); } }
private void BeforeQueryStatus(object sender, EventArgs e) { var button = (OleMenuCommand)sender; var items = ProjectHelpers.GetSelectedItems(); button.Visible = false; if (items.Count() != 1) { return; } var item = items.First(); if (item == null || item.ContainingProject == null || item.Properties == null) { return; } var sourceFile = item.Properties.Item("FullPath").Value.ToString(); if (!BundleFileProcessor.IsSupported(sourceFile)) { return; } string configFile = item.ContainingProject.GetConfigFile(); _bundles = BundleService.IsOutputConfigered(configFile, sourceFile); button.Visible = _bundles.Any(); }
private void BeforeQueryStatus(object sender, EventArgs e) { var button = (OleMenuCommand)sender; var files = ProjectHelpers.GetSelectedItemPaths(); button.Visible = BundleFileProcessor.IsSupported(files); }
public PageBuilder(IWebHostEnvironment hostingEnvironment, IHoodCache cache) { _hostingEnvironment = hostingEnvironment; _cache = cache; _scripts = new Dictionary <ResourceLocation, List <FileReferenceMetadata> >(); _inlineScripts = new Dictionary <ResourceLocation, List <string> >(); _css = new Dictionary <ResourceLocation, List <FileReferenceMetadata> >(); _bundleFileProcessor = new BundleFileProcessor(); }
private void BeforeQueryStatus(object sender, EventArgs e) { var button = (OleMenuCommand)sender; button.Enabled = button.Visible = false; var files = ProjectHelpers.GetSelectedItemPaths(); var supported = BundleFileProcessor.IsSupported(files.ToArray()); if (supported) { if (files.Count() == 1) { var sourceFile = files.First(); var project = BundlerMinifierPackage._dte.Solution.FindProjectItem(sourceFile)?.ContainingProject; var configFile = project.GetConfigFile(); var bundles = BundleService.IsOutputConfigered(configFile, sourceFile); bool isMinFile = Path.GetFileName(sourceFile).Contains(".min."); if (!bundles.Any() && !isMinFile) { var minFileName = FileHelpers.GetMinFileName(sourceFile, bundles.FirstOrDefault <Bundle>().MinFileName); bundles = BundleService.IsOutputConfigered(configFile, minFileName); } if (bundles.Any()) { if (isMinFile) { button.Text = Resources.Text.ButtonReMinify; } else { button.Text = Resources.Text.ButtonReBundle; } } else if (BundleFileProcessor.IsFileConfigured(configFile, sourceFile).Any()) { supported = false; } else if (!isMinFile) { button.Text = Resources.Text.ButtonMinify; } } else { button.Text = Resources.Text.ButtonBundle; } button.Visible = button.Enabled = supported; } }
private void AddBundle(object sender, EventArgs e) { var item = ProjectHelpers.GetSelectedItems().FirstOrDefault(); if (item == null || item.ContainingProject == null) { return; } string folder = item.ContainingProject.GetRootFolder(); string configFile = Path.Combine(folder, Constants.CONFIG_FILENAME); IEnumerable <string> files = ProjectHelpers.GetSelectedItemPaths().Select(f => BundlerMinifier.FileHelpers.MakeRelative(configFile, f)); string inputFile = item.Properties.Item("FullPath").Value.ToString(); string outputFile = inputFile; if (files.Count() > 1) { outputFile = GetOutputFileName(inputFile, Path.GetExtension(files.First())); } else { // Reminify file var bundles = BundleFileProcessor.IsFileConfigured(configFile, inputFile); if (bundles.Any()) { BundleService.SourceFileChanged(configFile, inputFile); Telemetry.TrackEvent("VS recompile config"); return; } } if (string.IsNullOrEmpty(outputFile)) { return; } BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 0, 2); string relativeOutputFile = BundlerMinifier.FileHelpers.MakeRelative(configFile, outputFile); Bundle bundle = CreateBundleFile(files, relativeOutputFile); BundleHandler.AddBundle(configFile, bundle); BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 1, 2); item.ContainingProject.AddFileToProject(configFile, "None"); BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 2, 2); BundleService.Process(configFile); BundlerMinifierPackage._dte.StatusBar.Progress(false, "Creating bundle"); BundlerMinifierPackage._dte.StatusBar.Text = "Bundle created"; Telemetry.TrackEvent("VS create bundle"); }
private static void EventHookups(BundleFileProcessor processor, string configPath) { // For console colors, see http://stackoverflow.com/questions/23975735/what-is-this-u001b9-syntax-of-choosing-what-color-text-appears-on-console processor.Processing += (s, e) => { System.Console.WriteLine($"Processing {e.Bundle.OutputFileName.Cyan().Bright()}"); FileHelpers.RemoveReadonlyFlagFromFile(e.Bundle.GetAbsoluteOutputFile()); }; processor.AfterBundling += (s, e) => { System.Console.WriteLine($" Bundled".Green().Bright()); }; processor.BeforeWritingSourceMap += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); }; processor.AfterWritingSourceMap += (s, e) => { System.Console.WriteLine($" Sourcemapped".Green().Bright()); }; BundleMinifier.BeforeWritingMinFile += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); }; BundleMinifier.AfterWritingMinFile += (s, e) => { System.Console.WriteLine($" Minified".Green().Bright()); }; BundleMinifier.BeforeWritingGzipFile += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); }; BundleMinifier.AfterWritingGzipFile += (s, e) => { System.Console.WriteLine($" GZipped".Green().Bright()); }; BundleMinifier.ErrorMinifyingFile += (s, e) => { System.Console.WriteLine($"{string.Join(Environment.NewLine, e.Result.Errors)}"); }; }
/// <summary> /// Constuctor /// </summary> /// <param name="seoSettings">SEO settings</param> /// <param name="hostingEnvironment">Hosting environment</param> public PageHeadBuilder(/*SeoSettings seoSettings,*/ IHostingEnvironment hostingEnvironment) { //this._seoSettings = seoSettings; this._hostingEnvironment = hostingEnvironment; this._processor = new BundleFileProcessor(); this._titleParts = new List <string>(); this._metaDescriptionParts = new List <string>(); this._metaKeywordParts = new List <string>(); this._scriptParts = new Dictionary <ResourceLocation, List <ScriptReferenceMeta> >(); this._cssParts = new Dictionary <ResourceLocation, List <CssReferenceMeta> >(); this._canonicalUrlParts = new List <string>(); this._headCustomParts = new List <string>(); this._pageCssClassParts = new List <string>(); }
private void BeforeQueryStatus(object sender, EventArgs e) { var button = (OleMenuCommand)sender; var files = ProjectHelpers.GetSelectedItemPaths(); if (files.Count() == 1) { button.Text = "Minify File"; } else { button.Text = "Bundle and Minify Files"; } button.Visible = BundleFileProcessor.IsSupported(files); }
public PageHeadBuilder( IHostingEnvironment hostingEnvironment, IFileProviderHelper fileProvider, IStaticCacheManager staticCacheManager) { this._hostingEnvironment = hostingEnvironment; this._fileProvider = fileProvider; this._staticCacheManager = staticCacheManager; this._processor = new BundleFileProcessor(); this._titleParts = new List <string>(); this._scriptParts = new Dictionary <ResourceLocation, List <ScriptReferenceMeta> >(); this._inlineScriptParts = new Dictionary <ResourceLocation, List <string> >(); this._cssParts = new Dictionary <ResourceLocation, List <CssReferenceMeta> >(); this._pageCssClassParts = new List <string>(); }
public HeadBuilder(SeoSettings seoSettings, IHostingEnvironment hostingEnvironment, IStaticCacheManager cacheManager, ICustomFileProvider fileProvider) { _seoSettings = seoSettings; _hostingEnvironment = hostingEnvironment; _cacheManager = cacheManager; _fileProvider = fileProvider; _processor = new BundleFileProcessor(); _titleParts = new List <string>(); _metaDescriptionParts = new List <string>(); _scriptParts = new Dictionary <ResourceLocation, List <BundleMeta> >(); _styleParts = new List <BundleMeta>(); }
public void IsSupported() { var files1 = new[] { "file.js", "file2.js" }; var result1 = BundleFileProcessor.IsSupported(files1); Assert.IsTrue(result1); var files2 = new[] { "file.js", "file2.css" }; var result2 = BundleFileProcessor.IsSupported(files2); Assert.IsFalse(result2); var files3 = new[] { null, "file2.css" }; var result3 = BundleFileProcessor.IsSupported(files3); Assert.IsTrue(result3); }
public SayfaHeadOluşturucu(SeoAyarları seoAyarları, IHostingEnvironment hostingEnvironment, IStatikÖnbellekYönetici cacheManager) { this._seoAyarları = seoAyarları; this._baslikParçaları = new List <string>(); this._metaDescriptionParçaları = new List <string>(); this._metaKeywordParçaları = new List <string>(); this._scriptParçaları = new Dictionary <KaynakKonumu, List <ScriptReferenceMeta> >(); this._cssParçaları = new Dictionary <KaynakKonumu, List <CssReferenceMeta> >(); this._canonicalUrlParçaları = new List <string>(); this._özelHeadParçaları = new List <string>(); this._sayfaCssSınıfıParçaları = new List <string>(); this._hostingEnvironment = hostingEnvironment; this._cacheManager = cacheManager; this._processor = new BundleFileProcessor(); }
/// <summary> /// Ctor /// </summary> /// <param name="seoSettings">SEO settings</param> /// <param name="hostingEnvironment">Hosting environment</param> /// <param name="cacheManager">Cache manager</param> /// <param name="fileProvider">File provider</param> public PageHeadBuilder(IHostingEnvironment hostingEnvironment, IStaticCacheManager cacheManager, IResearchFileProvider fileProvider) { this._hostingEnvironment = hostingEnvironment; this._cacheManager = cacheManager; this._fileProvider = fileProvider; this._processor = new BundleFileProcessor(); this._titleParts = new List <string>(); this._metaDescriptionParts = new List <string>(); this._metaKeywordParts = new List <string>(); this._scriptParts = new Dictionary <ResourceLocation, List <ScriptReferenceMeta> >(); this._inlineScriptParts = new Dictionary <ResourceLocation, List <string> >(); this._cssParts = new Dictionary <ResourceLocation, List <CssReferenceMeta> >(); this._canonicalUrlParts = new List <string>(); this._headCustomParts = new List <string>(); this._pageCssClassParts = new List <string>(); }
private void UpdateSelectedBundle(object sender, EventArgs e) { var configFile = ProjectHelpers.GetSelectedItemPaths().FirstOrDefault(); if (string.IsNullOrEmpty(configFile)) { var project = ProjectHelpers.GetActiveProject(); configFile = project?.GetConfigFile(); } if (string.IsNullOrEmpty(configFile) || !File.Exists(configFile)) { return; } var bundles = BundleHandler.GetBundles(configFile); BundleFileProcessor processor = new BundleFileProcessor(); processor.Clean(configFile, bundles); }
/// <summary> /// Constuctor /// </summary> /// <param name="seoSettings">SEO settings</param> /// <param name="hostingEnvironment">Hosting environment</param> public PageHeadBuilder(SeoSettings seoSettings, IWebHostEnvironment hostingEnvironment, IActionContextAccessor actionContextAccessor) { _seoSettings = seoSettings; _hostingEnvironment = hostingEnvironment; _actionContextAccessor = actionContextAccessor; _processor = new BundleFileProcessor(); _titleParts = new List <string>(); _metaDescriptionParts = new List <string>(); _metaKeywordParts = new List <string>(); _scriptParts = new Dictionary <ResourceLocation, List <ScriptReferenceMeta> >(); _cssParts = new Dictionary <ResourceLocation, List <CssReferenceMeta> >(); _canonicalUrlParts = new List <string>(); _headCustomParts = new List <string>(); _pageCssClassParts = new List <string>(); if (!string.IsNullOrEmpty(seoSettings.CustomHeadTags)) { AppendHeadCustomParts(seoSettings.CustomHeadTags); } }
public void Setup() { _processor = new BundleFileProcessor(); _guid = Guid.NewGuid(); }
static int Main(params string[] args) { int readConfigsUntilIndex = args.Length; string configPath; if (GetConfigFileFromArgs(args, out configPath)) { --readConfigsUntilIndex; } if (configPath == null) { ShowHelp(); return(0); } System.Console.WriteLine($"Bundling with configuration from {configPath}".Green().Bright()); BundleFileProcessor processor = new BundleFileProcessor(); EventHookups(processor, configPath); List <string> configurations = new List <string>(); bool isClean = false; bool isWatch = false; bool isNoColor = false; bool isHelp = false; for (int i = 0; i < readConfigsUntilIndex; ++i) { bool currentArgIsClean = string.Equals(args[i], "clean", StringComparison.OrdinalIgnoreCase); bool currentArgIsWatch = string.Equals(args[i], "watch", StringComparison.OrdinalIgnoreCase); bool currentArgIsNoColor = string.Equals(args[i], "--no-color", StringComparison.OrdinalIgnoreCase); bool currentArgIsHelp = string.Equals(args[i], "help", StringComparison.OrdinalIgnoreCase); currentArgIsHelp |= string.Equals(args[i], "-h", StringComparison.OrdinalIgnoreCase); currentArgIsHelp |= string.Equals(args[i], "--help", StringComparison.OrdinalIgnoreCase); currentArgIsHelp |= string.Equals(args[i], "help", StringComparison.OrdinalIgnoreCase); currentArgIsHelp |= string.Equals(args[i], "-?", StringComparison.OrdinalIgnoreCase); if (currentArgIsHelp) { isHelp = true; break; } else if (currentArgIsClean) { isClean = true; } else if (currentArgIsWatch) { isWatch = true; } else if (currentArgIsNoColor) { isNoColor = true; } else { configurations.Add(args[i]); } } if (isNoColor) { StringExtensions.NoColor = true; } if (isHelp) { ShowHelp(); return(0); } if (isClean && isWatch) { System.Console.WriteLine("The clean and watch options may not be used together.".Red().Bright()); return(-1); } if (isWatch) { bool isWatching = Watcher.Configure(processor, configurations, configPath); if (!isWatching) { System.Console.WriteLine("No output file names were matched".Red().Bright()); return(-1); } System.Console.WriteLine("Watching... Press [Enter] to stop".LightGray().Bright()); System.Console.ReadLine(); Watcher.Stop(); return(0); } if (configurations.Count == 0) { return(Run(processor, configPath, null, isClean)); } foreach (string config in configurations) { int runResult = Run(processor, configPath, config, isClean); if (runResult < 0) { return(runResult); } } return(0); }
private string GetBundle(string[] inputFiles, string type) { var bundleFileProcessor = new BundleFileProcessor(); var bundle = new BundlerMinifier.Bundle(); //we wil store the file names with date of modification to keep track whether a new bundle should be generated or not //any minor modification will cause regeneration of the bundle //we do this because it is a performance intensive operation and the we should only do it when needed var distinctFiles = inputFiles.Distinct().ToList(); var fileNamesWithDates = new List <string>(); foreach (var inputFile in distinctFiles) { //the input file can either be 1. theme-css 2. plugin-css 3. admin-css 4. common-css //check them one by one var file = ServerHelper.MapPath("~/Content/Themes" + inputFile); if (!_localFileProvider.FileExists(file)) { //plugins file = ServerHelper.MapPath("~/" + inputFile); if (!_localFileProvider.FileExists(file)) { //administration & common file = ServerHelper.MapPath("~/" + inputFile, true); if (!_localFileProvider.FileExists(file)) { continue; //can't do anything...the file doesn't exist } } } bundle.InputFiles.Add(file); var modDate = _localFileProvider.GetLastModifiedDateTime(file); fileNamesWithDates.Add($"{file}:{modDate}"); } var outputFilePart1 = GetOutputFileName(fileNamesWithDates); var outputFilePart2 = GetOutputFileName(distinctFiles); var outputFile = outputFilePart1 + "_" + outputFilePart2; var bundlesDirectory = ServerHelper.MapPath(ApplicationConfig.BundlesDirectory, true); var bundleFileName = bundlesDirectory + "/" + outputFile + $".min.{type}"; bundle.OutputFileName = bundleFileName; //do we need to generate the bundle? if (!_localFileProvider.FileExists(bundleFileName)) { //delete the existing bundles of these files try { _localFileProvider.DeleteFiles(bundlesDirectory, $"*_{outputFilePart2}.min.{type}*"); } catch { //do nothing...the file must be locked...will try next time } bundle.FileName = bundleFileName + ".json"; BundleMinifier.ErrorMinifyingFile += BundleMinifier_ErrorMinifyingFile; bundleFileProcessor.Process(bundle.FileName, new List <BundlerMinifier.Bundle>() { bundle }); } //if operation succeeded, return the url, else null if (bundle.OutputFileName == null) { return(null); } //also create a gzipped version as well using (var bundleFileStream = File.OpenRead(bundleFileName)) using (var compressedFileStream = File.Create(bundleFileName + ".gz")) { using (var compressionStream = new GZipStream(compressedFileStream, CompressionMode.Compress)) { bundleFileStream.CopyTo(compressionStream); } } return(bundle.OutputFileName == null ? null : ApplicationEngine.MapUrl(bundleFileName)); }
private static void Execute(CommandLineOptions options) { var processor = new BundleFileProcessor(); processor.Process(options.ConfigFileName); }