public static TSFileAdditionalInfo AutodetectAndAddDependencyCore(ProjectOptions projectOptions, string depName, IFileCache usedFrom) { var dc = projectOptions.Owner.DiskCache; var extension = PathUtils.GetExtension(depName); var depFile = dc.TryGetItem(depName) as IFileCache; if (depFile == null) { if (usedFrom != null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("In " + usedFrom.FullPath + " missing dependency " + depName); Console.ForegroundColor = ConsoleColor.Gray; TSFileAdditionalInfo.Get(usedFrom, dc) .ReportDiag(true, -3, "Missing dependency " + depName, 0, 0, 0, 0); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Somethere missing dependency " + depName); Console.ForegroundColor = ConsoleColor.Gray; } return(null); } var assetFileInfo = TSFileAdditionalInfo.Get(depFile, dc); if (projectOptions.BundleCss && extension == "css") { assetFileInfo.Type = FileCompilationType.Css; return(assetFileInfo); } if (assetFileInfo.OutputUrl == null) { assetFileInfo.OutputUrl = projectOptions.AllocateName(PathUtils.Subtract(depFile.FullPath, projectOptions.Owner.Owner.FullPath)); } switch (extension) { case "css": assetFileInfo.Type = FileCompilationType.Css; break; case "js": assetFileInfo.Type = FileCompilationType.JavaScriptAsset; break; default: assetFileInfo.Type = FileCompilationType.Resource; break; } return(assetFileInfo); }
public void Build(bool compress, bool mangle, bool beautify) { var diskCache = Project.Owner.DiskCache; var root = Project.Owner.Owner.FullPath; _jsFilesContent = new Dictionary <string, string>(); var cssLink = ""; var cssToBundle = new List <SourceFromPair>(); foreach (var source in BuildResult.Path2FileInfo) { if (source.Value.Type == FileCompilationType.TypeScript || source.Value.Type == FileCompilationType.JavaScript || source.Value.Type == FileCompilationType.JavaScriptAsset) { if (source.Value.Output == null) { continue; // Skip d.ts } _jsFilesContent[PathUtils.ChangeExtension(source.Key, "js").ToLowerInvariant()] = source.Value.Output; } else if (source.Value.Type == FileCompilationType.Css) { cssToBundle.Add(new SourceFromPair(source.Value.Owner.Utf8Content, source.Value.Owner.FullPath)); } else if (source.Value.Type == FileCompilationType.Resource) { FilesContent[source.Value.OutputUrl] = source.Value.Owner.ByteContent; } } if (cssToBundle.Count > 0) { string cssPath = Project.AllocateName("bundle.css"); var cssProcessor = new CssProcessor(Project.Tools); FilesContent[cssPath] = cssProcessor.ConcatenateAndMinifyCss(cssToBundle, (string url, string from) => { var full = PathUtils.Join(from, url); var fullJustName = full.Split('?', '#')[0]; var fileAdditionalInfo = BuildModuleCtx.AutodetectAndAddDependencyCore(Project, fullJustName, diskCache.TryGetItem(from) as IFileCache); FilesContent[fileAdditionalInfo.OutputUrl] = fileAdditionalInfo.Owner.ByteContent; return(PathUtils.SplitDirAndFile(fileAdditionalInfo.OutputUrl).Item2 + full.Substring(fullJustName.Length)); }).Result; cssLink += "<link rel=\"stylesheet\" href=\"" + cssPath + "\">"; } if (Project.SpriteGeneration) { _bundlePng = Project.BundlePngUrl; var bundlePngContent = Project.SpriteGenerator.BuildImage(true); if (bundlePngContent != null) { _bundlePngInfo = new List <float>(); foreach (var slice in bundlePngContent) { FilesContent[PathUtils.InjectQuality(_bundlePng, slice.Quality)] = slice.Content; _bundlePngInfo.Add(slice.Quality); } } else { _bundlePng = null; } } var bundler = new BundlerImpl(_tools); bundler.Callbacks = this; if (Project.ExampleSources.Count > 0) { bundler.MainFiles = new[] { PathUtils.ChangeExtension(Project.ExampleSources[0], "js") }; } else { bundler.MainFiles = new[] { PathUtils.ChangeExtension(Project.MainFile, "js") }; } _mainJsBundleUrl = Project.BundleJsUrl; bundler.Compress = compress; bundler.Mangle = mangle; bundler.Beautify = beautify; var defines = new Dictionary <string, object>(); foreach (var p in Project.Defines) { defines.Add(p.Key, p.Value); } bundler.Defines = defines; bundler.Bundle(); if (!Project.NoHtml) { BuildFastBundlerIndexHtml(cssLink); FilesContent["index.html"] = _indexHtml; } }