public void InitInteractiveMode(string versionDir) { _hasBuildWork.Set(); _dc.ChangeObservable.Throttle(TimeSpan.FromMilliseconds(200)).Subscribe((_) => _hasBuildWork.Set()); Task.Run(() => { while (_hasBuildWork.WaitOne()) { if (!_dc.CheckForTrueChange()) { continue; } _dc.ResetChange(); _hasBuildWork.Set(); DateTime start = DateTime.UtcNow; ProjectOptions[] toBuild; lock (_projectsLock) { toBuild = _projects.ToArray(); } if (toBuild.Length == 0) { _logger.Error("Change detected, but no project to build"); continue; } _mainServer.NotifyCompilationStarted(); int errors = 0; int warnings = 0; var messages = new List <CompilationResultMessage>(); var messagesFromFiles = new HashSet <string>(); var totalFiles = 0; foreach (var proj in toBuild) { _logger.WriteLine("Build started " + proj.Owner.Owner.FullPath, ConsoleColor.Blue); try { proj.Owner.LoadProjectJson(_forbiddenDependencyUpdate); proj.Owner.InitializeOnce(); proj.OutputSubDir = versionDir; proj.GenerateCode(); proj.RefreshMainFile(); proj.RefreshTestSources(); proj.SpriterInitialization(); proj.DetectBobrilJsxDts(); proj.RefreshExampleSources(); proj.UpdateTSConfigJson(); var ctx = new BuildCtx(_compilerPool, _verbose, ShowTsVersion); ctx.TSCompilerOptions = proj.GetDefaultTSCompilerOptions(); ctx.Sources = new HashSet <string>(); ctx.Sources.Add(proj.MainFile); proj.ExampleSources.ForEach(s => ctx.Sources.Add(s)); if (proj.BobrilJsxDts != null) { ctx.Sources.Add(proj.BobrilJsxDts); } proj.Owner.Build(ctx); var buildResult = ctx.BuildResult; var filesContent = new Dictionary <string, object>(); proj.FillOutputByAdditionalResourcesDirectory(filesContent); var fastBundle = new FastBundleBundler(_tools); fastBundle.FilesContent = filesContent; fastBundle.Project = proj; fastBundle.BuildResult = buildResult; fastBundle.Build("bb/base", "bundle.js.map"); proj.MainProjFastBundle = fastBundle; IncludeMessages(proj.MainProjFastBundle, ref errors, ref warnings, messages, messagesFromFiles, proj.Owner.Owner.FullPath); if (errors == 0 && proj.LiveReloadEnabled) { proj.LiveReloadIdx++; proj.LiveReloadAwaiter.TrySetResult(Unit.Default); } if (proj.TestSources != null && proj.TestSources.Count > 0) { ctx = new BuildCtx(_compilerPool, _verbose, ShowTsVersion); ctx.TSCompilerOptions = proj.GetDefaultTSCompilerOptions(); ctx.Sources = new HashSet <string>(); ctx.Sources.Add(proj.JasmineDts); proj.TestSources.ForEach(s => ctx.Sources.Add(s)); if (proj.BobrilJsxDts != null) { ctx.Sources.Add(proj.BobrilJsxDts); } proj.Owner.Build(ctx); var testBuildResult = ctx.BuildResult; fastBundle = new FastBundleBundler(_tools); fastBundle.FilesContent = filesContent; fastBundle.Project = proj; fastBundle.BuildResult = testBuildResult; fastBundle.Build("bb/base", "testbundle.js.map", true); proj.TestProjFastBundle = fastBundle; IncludeMessages(proj.TestProjFastBundle, ref errors, ref warnings, messages, messagesFromFiles, proj.Owner.Owner.FullPath); if (errors == 0) { _testServer.StartTest("/test.html", new Dictionary <string, SourceMap> { { "testbundle.js", testBuildResult.SourceMap } }); StartChromeTest(); } } else { proj.TestProjFastBundle = null; } proj.FilesContent = filesContent; totalFiles += filesContent.Count; } catch (Exception ex) { _logger.Error("Fatal Error: " + ex); errors++; } } var duration = DateTime.UtcNow - start; _mainServer.NotifyCompilationFinished(errors, warnings, duration.TotalSeconds, messages); _notificationManager.SendNotification( NotificationParameters.CreateBuildParameters(errors, warnings, duration.TotalSeconds)); var color = errors != 0 ? ConsoleColor.Red : warnings != 0 ? ConsoleColor.Yellow : ConsoleColor.Green; _logger.WriteLine( "Build done in " + (DateTime.UtcNow - start).TotalSeconds.ToString("F1", CultureInfo.InvariantCulture) + "s with " + Plural(errors, "error") + " and " + Plural(warnings, "warning") + " and has " + Plural(totalFiles, "file"), color); _dc.ResetChange(); } }); }
void RunTest(TestCommand testCommand) { InitDiskCache(); InitTestServer(); InitMainServer(); AddProject(PathUtils.Normalize(Environment.CurrentDirectory), testCommand.Sprite.Value); int port = 0; if (int.TryParse(testCommand.Port.Value, out var portInInt)) { port = portInInt; } StartWebServer(port, false); DateTime start = DateTime.UtcNow; int errors = 0; int testFailures = 0; int warnings = 0; var messages = new List <CompilationResultMessage>(); var messagesFromFiles = new HashSet <string>(); var totalFiles = 0; foreach (var proj in _projects) { try { _logger.WriteLine("Test build started " + proj.Owner.Owner.FullPath, ConsoleColor.Blue); TestResultsHolder testResults = new TestResultsHolder(); proj.Owner.LoadProjectJson(true); proj.Owner.InitializeOnce(); proj.StyleDefNaming = StyleDefNamingStyle.AddNames; proj.GenerateCode(); proj.SpriterInitialization(); proj.RefreshMainFile(); proj.DetectBobrilJsxDts(); proj.RefreshTestSources(); if (proj.TestSources != null && proj.TestSources.Count > 0) { var ctx = new BuildCtx(_compilerPool, _verbose, ShowTsVersion); ctx.TSCompilerOptions = proj.GetDefaultTSCompilerOptions(); ctx.Sources = new HashSet <string>(); ctx.Sources.Add(proj.JasmineDts); proj.TestSources.ForEach(s => ctx.Sources.Add(s)); if (proj.BobrilJsxDts != null) { ctx.Sources.Add(proj.BobrilJsxDts); } proj.Owner.Build(ctx); var testBuildResult = ctx.BuildResult; var fastBundle = new FastBundleBundler(_tools); var filesContent = new Dictionary <string, object>(); proj.FillOutputByAdditionalResourcesDirectory(filesContent); fastBundle.FilesContent = filesContent; fastBundle.Project = proj; fastBundle.BuildResult = testBuildResult; fastBundle.Build("bb/base", "testbundle.js.map", true); proj.TestProjFastBundle = fastBundle; proj.FilesContent = filesContent; IncludeMessages(proj.TestProjFastBundle, ref errors, ref warnings, messages, messagesFromFiles, proj.Owner.Owner.FullPath); if (errors == 0) { var wait = new Semaphore(0, 1); _testServer.OnTestResults.Subscribe((results) => { testFailures = results.TestsFailed; testResults = results; wait.Release(); }); var durationb = DateTime.UtcNow - start; _logger.Success("Build successful. Starting Chrome to run tests in " + durationb.TotalSeconds.ToString("F1", CultureInfo.InvariantCulture) + "s"); _testServer.StartTest("/test.html", new Dictionary <string, SourceMap> { { "testbundle.js", testBuildResult.SourceMap } }); StartChromeTest(); wait.WaitOne(); StopChromeTest(); } } if (testCommand.Out.Value != null) { File.WriteAllText(testCommand.Out.Value, testResults.ToJUnitXml(testCommand.FlatTestSuites.Value), new UTF8Encoding(false)); } } catch (Exception ex) { _logger.Error("Fatal Error: " + ex); errors++; } } var duration = DateTime.UtcNow - start; var color = (errors + testFailures) != 0 ? ConsoleColor.Red : warnings != 0 ? ConsoleColor.Yellow : ConsoleColor.Green; _logger.WriteLine( "Test done in " + duration.TotalSeconds.ToString("F1", CultureInfo.InvariantCulture) + " with " + Plural(errors, "error") + " and " + Plural(warnings, "warning") + " and has " + Plural(totalFiles, "file") + " and " + Plural(testFailures, "failure"), color); Environment.ExitCode = (errors + testFailures) != 0 ? 1 : 0; }
public void Build(ProjectOptions project) { var ctx = new BuildCtx(_compilerPool, false, ShowTsVersion); project.Owner.Build(ctx); }
void RunBuild(BuildCommand bCommand) { InitDiskCache(); AddProject(PathUtils.Normalize(Environment.CurrentDirectory), bCommand.Sprite.Value); _forbiddenDependencyUpdate = bCommand.NoUpdate.Value; DateTime start = DateTime.UtcNow; int errors = 0; int warnings = 0; var messages = new List <CompilationResultMessage>(); var messagesFromFiles = new HashSet <string>(); var totalFiles = 0; foreach (var proj in _projects) { try { _logger.WriteLine("Build started " + proj.Owner.Owner.FullPath, ConsoleColor.Blue); proj.Owner.LoadProjectJson(_forbiddenDependencyUpdate); if (bCommand.Localize.Value != null) { proj.Localize = bCommand.Localize.Value ?? false; } proj.Owner.InitializeOnce(); proj.OutputSubDir = bCommand.VersionDir.Value; proj.CompressFileNames = !bCommand.Fast.Value; proj.StyleDefNaming = ParseStyleDefNaming(bCommand.Style.Value ?? (bCommand.Fast.Value ? "2" : "0")); proj.BundleCss = !bCommand.Fast.Value; proj.Defines["DEBUG"] = bCommand.Fast.Value; proj.GenerateCode(); proj.SpriterInitialization(); proj.RefreshMainFile(); proj.DetectBobrilJsxDts(); proj.RefreshExampleSources(); var ctx = new BuildCtx(_compilerPool, _verbose, ShowTsVersion); ctx.TSCompilerOptions = proj.GetDefaultTSCompilerOptions(); ctx.Sources = new HashSet <string>(); ctx.Sources.Add(proj.MainFile); proj.ExampleSources.ForEach(s => ctx.Sources.Add(s)); if (proj.BobrilJsxDts != null) { ctx.Sources.Add(proj.BobrilJsxDts); } proj.Owner.Build(ctx); var buildResult = ctx.BuildResult; var filesContent = new Dictionary <string, object>(); proj.FillOutputByAdditionalResourcesDirectory(filesContent); IncludeMessages(buildResult, ref errors, ref warnings, messages, messagesFromFiles, proj.Owner.Owner.FullPath); if (errors == 0) { if (proj.Localize && bCommand.UpdateTranslations.Value) { proj.TranslationDb.SaveLangDbs(PathToTranslations(proj)); } else { if (bCommand.Fast.Value) { var fastBundle = new FastBundleBundler(_tools); fastBundle.FilesContent = filesContent; fastBundle.Project = proj; fastBundle.BuildResult = buildResult; fastBundle.Build("bb/base", "bundle.js.map"); } else { var bundle = new BundleBundler(_tools); bundle.FilesContent = filesContent; bundle.Project = proj; bundle.BuildResult = buildResult; bundle.Build(bCommand.Compress.Value, bCommand.Mangle.Value, bCommand.Beautify.Value); } SaveFilesContentToDisk(filesContent, bCommand.Dir.Value); totalFiles += filesContent.Count; } } } catch (Exception ex) { _logger.Error("Fatal Error: " + ex); errors++; } } var duration = DateTime.UtcNow - start; var color = errors != 0 ? ConsoleColor.Red : warnings != 0 ? ConsoleColor.Yellow : ConsoleColor.Green; _logger.WriteLine( "Build done in " + duration.TotalSeconds.ToString("F1", CultureInfo.InvariantCulture) + "s with " + Plural(errors, "error") + " and " + Plural(warnings, "warning") + " and has " + Plural(totalFiles, "file"), color); Environment.ExitCode = errors != 0 ? 1 : 0; }