public string GetDeclaration(BundleContext bundleContext, V3DeferredSourceMap sourceMap) { //Close everything so everything is written to the output sourceMap.EndPackage(); sourceMap.Dispose(); switch (sourceMap.SourceMapType) { case SourceMapType.Default: var mapContent = sourceMap.SourceMapOutput; //now we need to save the map file so it can be retreived via the controller //we need to go one level above the composite path into the non-compression named folder since the map request will always be 'none' compression var mapPath = Path.Combine(bundleContext.BundleCompositeFile.Directory.Parent.FullName, bundleContext.BundleCompositeFile.Name + ".map"); using (var writer = new StreamWriter(File.Create(mapPath))) { writer.Write(mapContent); } var url = GetSourceMapUrl( bundleContext.BundleRequest.FileKey, bundleContext.BundleRequest.Extension, bundleContext.BundleRequest.Debug, bundleContext.BundleRequest.CacheBuster); return(sourceMap.GetExternalFileSourceMapMarkup(url)); case SourceMapType.Inline: return(sourceMap.GetInlineSourceMapMarkup()); case SourceMapType.None: default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Gets or Adds a V3InlineSourceMap into the current bundle context /// </summary> /// <param name="bundleContext"></param> /// <param name="sourceMapType"></param> /// <returns></returns> public static V3DeferredSourceMap GetSourceMapFromContext(this BundleContext bundleContext, SourceMapType sourceMapType) { var key = typeof(V3DeferredSourceMap).Name; object ctx; if (bundleContext.Items.TryGetValue(key, out ctx)) { return((V3DeferredSourceMap)ctx); } //not in the context so add it var sb = new StringBuilder(); var sourceMapWriter = new Utf8StringWriter(sb); var inlineSourceMap = new V3DeferredSourceMap((V3SourceMap)SourceMapFactory.Create(sourceMapWriter, V3SourceMap.ImplementationName), sb, sourceMapType); bundleContext.Items[key] = inlineSourceMap; return(inlineSourceMap); }