public void Build(BuildCtx buildCtx, BuildResult buildResult, int iterationId) { var tryDetectChanges = !buildCtx.ProjectStructureChanged; buildResult.HasError = false; if (!buildResult.Incremental || !tryDetectChanges) { buildResult.RecompiledIncrementaly.Clear(); } var buildModuleCtx = new BuildModuleCtx() { BuildCtx = buildCtx, Owner = this, Result = buildResult, ToCheck = new OrderedHashSet <string>(), IterationId = iterationId }; try { ProjectOptions.BuildCache.StartTransaction(); ITSCompiler compiler = null; try { if (!tryDetectChanges) { if (!ProjectOptions.TypeScriptVersionOverride && DevDependencies != null && DevDependencies.Contains("typescript")) { ProjectOptions.Tools.SetTypeScriptPath(Owner.FullPath); } else { ProjectOptions.Tools.SetTypeScriptVersion(ProjectOptions.TypeScriptVersion); } } compiler = buildCtx.CompilerPool.GetTs(DiskCache, buildCtx.CompilerOptions); var trueTSVersion = compiler.GetTSVersion(); buildCtx.ShowTsVersion(trueTSVersion); ProjectOptions.ConfigurationBuildCacheId = ProjectOptions.BuildCache.MapConfiguration(trueTSVersion, JsonConvert.SerializeObject(buildCtx.CompilerOptions, Formatting.None, TSCompilerOptions.GetSerializerSettings())); } finally { if (compiler != null) { buildCtx.CompilerPool.ReleaseTs(compiler); } } if (buildModuleCtx.Result.CommonSourceDirectory == null) { buildModuleCtx.Result.CommonSourceDirectory = Owner.FullPath; } buildResult.TaskForSemanticCheck = buildCtx.StartTypeCheck().ContinueWith((task) => { if (task.IsCompletedSuccessfully) { buildResult.SemanticResult = task.Result; buildResult.NotifySemanticResult(task.Result); } }); if (tryDetectChanges) { if (!buildModuleCtx.CrawlChanges()) { buildResult.Incremental = true; goto noDependencyChangeDetected; } buildCtx.ProjectStructureChanged = true; buildResult.Incremental = false; buildModuleCtx.Result.JavaScriptAssets.Clear(); foreach (var info in buildModuleCtx.Result.Path2FileInfo) { info.Value.IterationId = iterationId - 1; } } buildModuleCtx.CrawledCount = 0; buildModuleCtx.ToCheck.Clear(); ProjectOptions.HtmlHeadExpanded = buildModuleCtx.ExpandHtmlHead(ProjectOptions.HtmlHead); if (buildCtx.MainFile != null) { buildModuleCtx.CheckAdd(PathUtils.Join(Owner.FullPath, buildCtx.MainFile), FileCompilationType.Unknown); } if (buildCtx.ExampleSources != null) { foreach (var src in buildCtx.ExampleSources) { buildModuleCtx.CheckAdd(PathUtils.Join(Owner.FullPath, src), FileCompilationType.Unknown); } } if (buildCtx.TestSources != null) { foreach (var src in buildCtx.TestSources) { buildModuleCtx.CheckAdd(PathUtils.Join(Owner.FullPath, src), FileCompilationType.Unknown); } } if (ProjectOptions.IncludeSources != null) { foreach (var src in ProjectOptions.IncludeSources) { buildModuleCtx.CheckAdd(PathUtils.Join(Owner.FullPath, src), FileCompilationType.Unknown); } } buildModuleCtx.Crawl(); noDependencyChangeDetected :; ProjectOptions.CommonSourceDirectory = buildModuleCtx.Result.CommonSourceDirectory; if (ProjectOptions.SpriteGeneration) { ProjectOptions.SpriteGenerator.ProcessNew(); } var hasError = false; foreach (var item in buildModuleCtx.Result.Path2FileInfo) { if (item.Value.HasError) { hasError = true; break; } } buildModuleCtx.Result.HasError = hasError; if (ProjectOptions.BuildCache.IsEnabled) { buildModuleCtx.StoreResultToBuildCache(buildModuleCtx.Result); } } finally { ProjectOptions.BuildCache.EndTransaction(); } }
public void ApplySourceInfo(ISourceReplacer sourceReplacer, SourceInfo sourceInfo, BuildResult buildResult) { if (sourceInfo == null) { return; } if (sourceInfo.Assets != null) { foreach (var a in sourceInfo.Assets) { if (a.Name == null) { continue; } var assetName = a.Name; if (assetName.StartsWith("resource:")) { assetName = assetName.Substring(9); } sourceReplacer.Replace(a.StartLine, a.StartCol, a.EndLine, a.EndCol, "\"" + buildResult.ToOutputUrl(assetName) + "\""); } } if (sourceInfo.Sprites != null) { if (SpriteGeneration) { var spriteHolder = SpriteGenerator; var outputSprites = spriteHolder.Retrieve(sourceInfo.Sprites); foreach (var os in outputSprites) { var s = os.Me; if (s.Name == null) { continue; } if (s.HasColor == true && s.Color == null) { // Modify method name to b.spritebc and remove first parameter with sprite name sourceReplacer.Replace(s.StartLine, s.StartCol, s.ColorStartLine, s.ColorStartCol, sourceInfo.BobrilImport + ".spritebc("); // Replace parameters after color with sprite size and position sourceReplacer.Replace(s.ColorEndLine, s.ColorEndCol, s.EndLine, s.EndCol, "," + os.owidth + "," + os.oheight + "," + os.ox + "," + os.oy + ")"); } else { // Modify method name to b.spriteb and replace parameters with sprite size and position sourceReplacer.Replace(s.StartLine, s.StartCol, s.EndLine, s.EndCol, sourceInfo.BobrilImport + ".spriteb(" + os.owidth + "," + os.oheight + "," + os.ox + "," + os.oy + ")"); } } } else { foreach (var s in sourceInfo.Sprites) { if (s.Name == null) { continue; } sourceReplacer.Replace(s.NameStartLine, s.NameStartCol, s.NameEndLine, s.NameEndCol, "\"" + buildResult.ToOutputUrl(s.Name) + "\""); } } } var trdb = TranslationDb; if (trdb != null && sourceInfo.Translations != null) { foreach (var t in sourceInfo.Translations) { if (t.Message == null) { continue; } if (t.JustFormat) { continue; } var id = trdb.AddToDB(t.Message, t.Hint, t.WithParams); var finalId = trdb.MapId(id); sourceReplacer.Replace(t.StartLine, t.StartCol, t.EndLine, t.EndCol, "" + finalId); sourceReplacer.Replace(t.StartHintLine, t.StartHintCol, t.EndHintLine, t.EndHintCol, null); } } var styleDefs = sourceInfo.StyleDefs; if (styleDefs != null) { var styleDefNaming = StyleDefNaming; var styleDefPrefix = PrefixStyleNames; foreach (var s in styleDefs) { var skipEx = s.IsEx ? 1 : 0; if (s.UserNamed) { if (styleDefNaming == StyleDefNamingStyle.AddNames || styleDefNaming == StyleDefNamingStyle.PreserveNames) { if (styleDefPrefix.Length > 0) { if (s.Name != null) { sourceReplacer.Replace(s.StartLine, s.StartCol, s.EndLine, s.EndCol, "\"" + styleDefPrefix + s.Name + "\""); } else { sourceReplacer.Replace(s.StartLine, s.StartCol, s.StartLine, s.StartCol, "\"" + styleDefPrefix + "\"+("); sourceReplacer.Replace(s.EndLine, s.EndCol, s.EndLine, s.EndCol, ")"); } } } else { sourceReplacer.Replace(s.BeforeNameLine, s.BeforeNameCol, s.EndLine, s.EndCol, ""); } } else { if (styleDefNaming == StyleDefNamingStyle.AddNames && s.Name != null) { var padArgs = (s.ArgCount == 1 + (s.IsEx ? 1 : 0)) ? ",undefined" : ""; sourceReplacer.Replace(s.BeforeNameLine, s.BeforeNameCol, s.BeforeNameLine, s.BeforeNameCol, padArgs + ",\"" + styleDefPrefix + s.Name + "\""); } } } } }
void RecursiveFillOutputByAdditionalResourcesDirectory(IDirectoryCache directoryCache, string resourcesPath, RefDictionary <string, object> filesContent, BuildResult buildResult) { Owner.DiskCache.UpdateIfNeeded(directoryCache); foreach (var child in directoryCache) { if (child is IDirectoryCache) { RecursiveFillOutputByAdditionalResourcesDirectory(child as IDirectoryCache, resourcesPath, filesContent, buildResult); continue; } if (child.IsInvalid) { continue; } var outPathFileName = PathUtils.Subtract(child.FullPath, resourcesPath); buildResult.TakenNames.Add(outPathFileName); if (child is IFileCache) { filesContent.GetOrAddValueRef(outPathFileName) = new Lazy <object>(() => { var res = ((IFileCache)child).ByteContent; ((IFileCache)child).FreeCache(); return(res); }); } } }
public void FillOutputByAssetsFromModules(RefDictionary <string, object> filesContent, Dictionary <string, TSProject> modules, string nodeModulesDir, BuildResult buildResult) { foreach (var keyValuePair in modules) { keyValuePair.Value.FillOutputByAssets(filesContent, buildResult, nodeModulesDir, this); } }
public void FillOutputByAdditionalResourcesDirectory(RefDictionary <string, object> filesContent, Dictionary <string, TSProject> buildResultModules, BuildResult buildResult) { var nodeModulesDir = Owner.Owner.FullPath; Owner.FillOutputByAssets(filesContent, buildResult, nodeModulesDir, this); FillOutputByAssetsFromModules(filesContent, buildResultModules, nodeModulesDir, buildResult); if (AdditionalResourcesDirectory == null) { return; } var resourcesPath = PathUtils.Join(Owner.Owner.FullPath, AdditionalResourcesDirectory); var item = Owner.DiskCache.TryGetItem(resourcesPath); if (item is IDirectoryCache) { RecursiveFillOutputByAdditionalResourcesDirectory(item as IDirectoryCache, resourcesPath, filesContent, buildResult); } }