| 1 |
using System.Web.Optimization; |
= |
1 |
using System.Web.Optimization; |
| 2 |
using System; |
|
2 |
using System; |
| 3 |
using System.Collections.Generic; |
|
3 |
using System.Collections.Generic; |
| 4 |
using System.IO; |
|
4 |
using System.IO; |
| 5 |
using System.Text.RegularExpressions; |
|
5 |
using System.Text.RegularExpressions; |
| 6 |
using Glob; |
<> |
6 |
using GlobExpressions; |
| 7 |
using BundleTransformer.Core.Bundles; |
= |
7 |
using BundleTransformer.Core.Bundles; |
| 8 |
using BundleTransformer.Core.Orderers; |
|
8 |
using BundleTransformer.Core.Orderers; |
| 9 |
using BundleTransformer.Core.Resolvers; |
|
9 |
using BundleTransformer.Core.Resolvers; |
| |
|
-+ |
10 |
using System.Web; |
| 10 |
|
= |
11 |
|
| 11 |
namespace AspnetMvcStarter |
|
12 |
namespace AspnetMvcStarter |
| 12 |
{ |
|
13 |
{ |
| |
|
-+ |
14 |
public class CssRewriteUrlTransformWrapper : IItemTransform |
| |
|
|
15 |
{ |
| |
|
|
16 |
public string Process(string includedVirtualPath, string input) |
| |
|
|
17 |
{ |
| |
|
|
18 |
return new CssRewriteUrlTransform().Process("~" + VirtualPathUtility.ToAbsolute(includedVirtualPath), input); |
| |
|
|
19 |
} |
| |
|
|
20 |
} |
| 13 |
|
= |
21 |
|
| 14 |
public class BundleConfig |
|
22 |
public class BundleConfig |
| 15 |
{ |
|
23 |
{ |
| 16 |
|
|
24 |
|
| 17 |
public static void RegisterBundles(BundleCollection bundles) |
|
25 |
public static void RegisterBundles(BundleCollection bundles) |
| 18 |
{ |
|
26 |
{ |
| 19 |
|
|
27 |
|
| 20 |
|
|
28 |
|
| 21 |
|
|
29 |
|
| 22 |
|
|
30 |
|
| 23 |
|
|
31 |
|
| 24 |
BundleResolver.Current = new CustomBundleResolver(); |
|
32 |
BundleResolver.Current = new CustomBundleResolver(); |
| 25 |
|
|
33 |
|
| 26 |
|
|
34 |
|
| 27 |
|
|
35 |
|
| 28 |
|
|
36 |
|
| 29 |
|
|
37 |
|
| 30 |
bundles.Add(SassBundle("~/bundle/css/main").Include("~/Content/main.scss")); |
|
38 |
bundles.Add(SassBundle("~/bundle/css/main").Include("~/Content/main.scss")); |
| 31 |
bundles.Add(new ScriptBundle("~/bundle/js/main").Include("~/Scripts/main.js")); |
|
39 |
bundles.Add(new ScriptBundle("~/bundle/js/main").Include("~/Scripts/main.js")); |
| 32 |
|
|
40 |
|
| 33 |
|
|
41 |
|
| 34 |
bundles.Add(new ScriptBundle("~/bundle/vendor/js/jquery-validation-unobtrusive/jquery-validation-unobtrusive").Include( |
|
42 |
bundles.Add(new ScriptBundle("~/bundle/vendor/js/jquery-validation-unobtrusive/jquery-validation-unobtrusive").Include( |
| 35 |
"~/node_modules/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.js")); |
|
43 |
"~/node_modules/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.js")); |
| 36 |
|
|
44 |
|
| 37 |
|
|
45 |
|
| 38 |
|
|
46 |
|
| 39 |
|
|
47 |
|
| 40 |
|
|
48 |
|
| 41 |
bundles.Add(SassBundle("~/bundle/vendor/css/bootstrap").Include("~/Vendor/css/bootstrap.scss")); |
|
49 |
bundles.Add(SassBundle("~/bundle/vendor/css/bootstrap").Include("~/Vendor/css/bootstrap.scss")); |
| 42 |
bundles.Add(SassBundle("~/bundle/vendor/css/appwork").Include("~/Vendor/css/appwork.scss")); |
|
50 |
bundles.Add(SassBundle("~/bundle/vendor/css/appwork").Include("~/Vendor/css/appwork.scss")); |
| 43 |
bundles.Add(SassBundle("~/bundle/vendor/css/theme-corporate").Include("~/Vendor/css/theme-corporate.scss")); |
|
51 |
bundles.Add(SassBundle("~/bundle/vendor/css/theme-corporate").Include("~/Vendor/css/theme-corporate.scss")); |
| 44 |
bundles.Add(SassBundle("~/bundle/vendor/css/colors").Include("~/Vendor/css/colors.scss")); |
|
52 |
bundles.Add(SassBundle("~/bundle/vendor/css/colors").Include("~/Vendor/css/colors.scss")); |
| 45 |
bundles.Add(SassBundle("~/bundle/vendor/css/uikit").Include("~/Vendor/css/uikit.scss")); |
|
53 |
bundles.Add(SassBundle("~/bundle/vendor/css/uikit").Include("~/Vendor/css/uikit.scss")); |
| 46 |
|
|
54 |
|
| 47 |
|
|
55 |
|
| 48 |
|
|
56 |
|
| 49 |
|
|
57 |
|
| 50 |
|
|
58 |
|
| 51 |
|
|
59 |
|
| 52 |
foreach (string[] bundleFile in GetVendorBundles("js", "js", "**/*", "js")) |
|
60 |
foreach (string[] bundleFile in GetVendorBundles("js", "js", "**/*", "js")) |
| 53 |
{ |
|
61 |
{ |
| 54 |
bundles.Add(new ScriptBundle(bundleFile[0]).Include(bundleFile[1])); |
<> |
62 |
bundles.Add(new Bundle(bundleFile[0]).Include(bundleFile[1])); |
| 55 |
} |
= |
63 |
} |
| 56 |
|
|
64 |
|
| 57 |
|
|
65 |
|
| 58 |
|
|
66 |
|
| 59 |
|
|
67 |
|
| 60 |
|
|
68 |
|
| 61 |
|
|
69 |
|
| 62 |
foreach (string[] bundleFile in GetVendorBundles("css\\pages", "css/pages", "**/*", "scss")) |
|
70 |
foreach (string[] bundleFile in GetVendorBundles("css\\pages", "css/pages", "**/*", "scss")) |
| 63 |
{ |
|
71 |
{ |
| 64 |
bundles.Add(SassBundle(bundleFile[0]).Include(bundleFile[1])); |
|
72 |
bundles.Add(SassBundle(bundleFile[0]).Include(bundleFile[1])); |
| 65 |
} |
|
73 |
} |
| 66 |
|
|
74 |
|
| 67 |
|
|
75 |
|
| 68 |
|
|
76 |
|
| 69 |
|
|
77 |
|
| 70 |
|
|
78 |
|
| 71 |
|
|
79 |
|
| 72 |
foreach (string[] bundleFile in GetVendorBundles("fonts", "fonts", "*", "css")) |
|
80 |
foreach (string[] bundleFile in GetVendorBundles("fonts", "fonts", "*", "css")) |
| 73 |
{ |
|
81 |
{ |
| 74 |
bundles.Add(new StyleBundle(bundleFile[0]).Include(bundleFile[1], new CssRewriteUrlTransform())); |
<> |
82 |
bundles.Add(new Bundle(bundleFile[0]).Include(bundleFile[1], new CssRewriteUrlTransformWrapper())); |
| 75 |
} |
= |
83 |
} |
| 76 |
|
|
84 |
|
| 77 |
|
|
85 |
|
| 78 |
|
|
86 |
|
| 79 |
|
|
87 |
|
| 80 |
|
|
88 |
|
| 81 |
|
|
89 |
|
| 82 |
foreach (string[] bundleFile in GetVendorBundles("libs", "css", "**/*", "scss")) |
|
90 |
foreach (string[] bundleFile in GetVendorBundles("libs", "css", "**/*", "scss")) |
| 83 |
{ |
|
91 |
{ |
| 84 |
if (bundleFile[2] == "true") |
|
92 |
if (bundleFile[2] == "true") |
| 85 |
{ |
|
93 |
{ |
| 86 |
bundles.Add(SassBundle(bundleFile[0]).Include(bundleFile[1], new CssRewriteUrlTransform())); |
<> |
94 |
bundles.Add(SassBundle(bundleFile[0]).Include(bundleFile[1], new CssRewriteUrlTransformWrapper())); |
| 87 |
} |
= |
95 |
} |
| 88 |
else |
|
96 |
else |
| 89 |
{ |
|
97 |
{ |
| 90 |
bundles.Add(SassBundle(bundleFile[0]).Include(bundleFile[1])); |
|
98 |
bundles.Add(SassBundle(bundleFile[0]).Include(bundleFile[1])); |
| 91 |
} |
|
99 |
} |
| 92 |
} |
|
100 |
} |
| 93 |
|
|
101 |
|
| 94 |
|
|
102 |
|
| 95 |
foreach (string[] bundleFile in GetVendorBundles("libs", "js", "**/*", "js")) |
|
103 |
foreach (string[] bundleFile in GetVendorBundles("libs", "js", "**/*", "js")) |
| 96 |
{ |
|
104 |
{ |
| 97 |
bundles.Add(new ScriptBundle(bundleFile[0]).Include(bundleFile[1])); |
<> |
105 |
bundles.Add(new Bundle(bundleFile[0]).Include(bundleFile[1])); |
| 98 |
} |
= |
106 |
} |
| 99 |
|
|
107 |
|
| 100 |
} |
|
108 |
} |
| 101 |
|
|
109 |
|
| 102 |
private static Bundle SassBundle(string path) |
|
110 |
private static Bundle SassBundle(string path) |
| 103 |
{ |
|
111 |
{ |
| 104 |
return new CustomStyleBundle(path) |
|
112 |
return new CustomStyleBundle(path) |
| 105 |
{ |
|
113 |
{ |
| 106 |
Orderer = new NullOrderer() |
|
114 |
Orderer = new NullOrderer() |
| 107 |
}; |
|
115 |
}; |
| 108 |
} |
|
116 |
} |
| 109 |
|
|
117 |
|
| 110 |
private static string[][] GetVendorBundles(string sourcePath, string bundlePath, string globPattern, string ext) |
|
118 |
private static string[][] GetVendorBundles(string sourcePath, string bundlePath, string globPattern, string ext) |
| 111 |
{ |
|
119 |
{ |
| 112 |
|
|
120 |
|
| 113 |
string APP_PATH = AppDomain.CurrentDomain.BaseDirectory; |
|
121 |
string APP_PATH = AppDomain.CurrentDomain.BaseDirectory; |
| 114 |
|
|
122 |
|
| 115 |
|
|
123 |
|
| 116 |
DirectoryInfo dirInfo = new DirectoryInfo(APP_PATH + "\\Vendor\\" + sourcePath); |
|
124 |
DirectoryInfo dirInfo = new DirectoryInfo(APP_PATH + "\\Vendor\\" + sourcePath); |
| 117 |
IEnumerable<FileInfo> contents = dirInfo.GlobFiles(globPattern + "." + ext); |
|
125 |
IEnumerable<FileInfo> contents = dirInfo.GlobFiles(globPattern + "." + ext); |
| 118 |
|
|
126 |
|
| 119 |
List<string[]> bundles = new List<string[]>(); |
|
127 |
List<string[]> bundles = new List<string[]>(); |
| 120 |
|
|
128 |
|
| 121 |
Regex normalizeRegex = new Regex("\\\\"); |
|
129 |
Regex normalizeRegex = new Regex("\\\\"); |
| 122 |
|
|
130 |
|
| 123 |
sourcePath = normalizeRegex.Replace(sourcePath, "/") + "/"; |
|
131 |
sourcePath = normalizeRegex.Replace(sourcePath, "/") + "/"; |
| 124 |
|
|
132 |
|
| 125 |
Regex pathRegex = new Regex(".*?" + Regex.Escape("/Vendor/" + sourcePath)); |
|
133 |
Regex pathRegex = new Regex(".*?" + Regex.Escape("/Vendor/" + sourcePath)); |
| 126 |
Regex nameRegex = new Regex("\\." + Regex.Escape(ext) + "$"); |
|
134 |
Regex nameRegex = new Regex("\\." + Regex.Escape(ext) + "$"); |
| 127 |
|
|
135 |
|
| 128 |
Regex urlRewriteTestRegex = new Regex("/(" + |
|
136 |
Regex urlRewriteTestRegex = new Regex("/(" + |
| 129 |
"minicolors/minicolors" + "|" + |
|
137 |
"minicolors/minicolors" + "|" + |
| 130 |
"blueimp-gallery/gallery-video" + "|" + |
|
138 |
"blueimp-gallery/gallery-video" + "|" + |
| 131 |
"blueimp-gallery/gallery" + "|" + |
|
139 |
"blueimp-gallery/gallery" + "|" + |
| 132 |
"jstree/themes/default/style" + "|" + |
|
140 |
"jstree/themes/default/style" + "|" + |
| 133 |
"jstree/themes/default-dark/style" + "|" + |
|
141 |
"jstree/themes/default-dark/style" + "|" + |
| 134 |
"photoswipe/photoswipe" + |
|
142 |
"photoswipe/photoswipe" + |
| 135 |
")\\.scss$"); |
|
143 |
")\\.scss$"); |
| 136 |
|
|
144 |
|
| 137 |
foreach (FileInfo file in contents) |
|
145 |
foreach (FileInfo file in contents) |
| 138 |
{ |
|
146 |
{ |
| 139 |
string filePath = pathRegex.Replace(normalizeRegex.Replace(file.FullName, "/"), ""); |
|
147 |
string filePath = pathRegex.Replace(normalizeRegex.Replace(file.FullName, "/"), ""); |
| 140 |
string relativeBundlePath = "~/bundle/vendor/" + bundlePath + "/" + nameRegex.Replace(filePath, ""); |
|
148 |
string relativeBundlePath = "~/bundle/vendor/" + bundlePath + "/" + nameRegex.Replace(filePath, ""); |
| 141 |
string relativeSourcePath = "~/Vendor/" + sourcePath + filePath; |
|
149 |
string relativeSourcePath = "~/Vendor/" + sourcePath + filePath; |
| 142 |
bool urlRewrite = urlRewriteTestRegex.IsMatch(relativeSourcePath); |
|
150 |
bool urlRewrite = urlRewriteTestRegex.IsMatch(relativeSourcePath); |
| 143 |
|
|
151 |
|
| 144 |
bundles.Add(new string[] { relativeBundlePath, relativeSourcePath, urlRewrite ? "true" : "false" }); |
|
152 |
bundles.Add(new string[] { relativeBundlePath, relativeSourcePath, urlRewrite ? "true" : "false" }); |
| 145 |
} |
|
153 |
} |
| 146 |
|
|
154 |
|
| 147 |
return bundles.ToArray(); |
|
155 |
return bundles.ToArray(); |
| 148 |
} |
|
156 |
} |
| 149 |
|
|
157 |
|
| 150 |
} |
|
158 |
} |
| 151 |
} |
|
159 |
} |