private async Task GenerateAsync(BundleDocument bundle, string extension, bool hasUpdated = false) { _dte.StatusBar.Text = "Generating bundle..."; if (ProjectHelpers.GetProjectItem(bundle.FileName) == null) { ProjectHelpers.AddFileToActiveProject(bundle.FileName); } string bundleFile = Path.Combine(Path.GetDirectoryName(bundle.FileName), Path.GetFileNameWithoutExtension(bundle.FileName)); if (!string.IsNullOrEmpty(bundle.OutputDirectory)) { bundleFile = ProjectHelpers.GetAbsolutePathFromSettings(bundle.OutputDirectory, Path.Combine(Path.GetDirectoryName(bundle.FileName), Path.GetFileNameWithoutExtension(bundle.FileName))); } ProjectHelpers.CreateDirectoryInProject(bundleFile); bool hasChanged = await BundleGenerator.MakeBundle(bundle, bundleFile, UpdateBundleAsync); ProjectHelpers.AddFileToProject(bundle.FileName, bundleFile); if (!hasUpdated) { WebEssentialsPackage.DTE.ItemOperations.OpenFile(bundle.FileName); } if (bundle.Minified) { await BundleGenerator.MakeMinFile(bundleFile, extension, hasChanged); } _dte.StatusBar.Text = "Bundle generated"; }
public async static Task <Dictionary <string, string> > WatchFiles(BundleDocument document, Func <string, bool, Task> updateBundle, string bundleFile = null) { if (document == null) { return(null); } if (bundleFile == null && document.OutputDirectory != null) { bundleFile = ProjectHelpers.GetAbsolutePathFromSettings(document.OutputDirectory, Path.Combine(Path.GetDirectoryName(document.FileName), Path.GetFileNameWithoutExtension(document.FileName))); } Dictionary <string, string> files = new Dictionary <string, string>(); await new BundleFileObserver().AttachFileObserver(document, document.FileName, updateBundle); foreach (string asset in document.OriginalBundleAssets) { string absolute = asset.Contains(":\\") ? asset : ProjectHelpers.ToAbsoluteFilePath(asset, document.FileName); string absoluteActual = GetActualAsset(absolute); if (!File.Exists(absoluteActual)) { WebEssentialsPackage.DTE.ItemOperations.OpenFile(document.FileName); Logger.ShowMessage(String.Format(CultureInfo.CurrentCulture, "Bundle error: The file '{0}' doesn't exist", asset)); return(null); } if (!File.Exists(absolute)) { WebEssentialsPackage.DTE.ItemOperations.OpenFile(document.FileName); Logger.ShowMessage(String.Format(CultureInfo.CurrentCulture, "Bundle error: The file '{0}' doesn't exist", absolute)); return(null); } if (!files.ContainsKey(absoluteActual)) { if (Path.IsPathRooted(asset)) { files.Add(absolute, asset); } else { files.Add(absolute, FileHelpers.RelativePath(bundleFile, Path.GetFullPath(Path.Combine(Path.GetDirectoryName(document.FileName), asset)))); } await new BundleFileObserver().AttachFileObserver(document, absoluteActual, updateBundle); } } return(files); }