diff --git a/src/AbpDevTools/Commands/BuildCommand.cs b/src/AbpDevTools/Commands/BuildCommand.cs index 76b1475..3d0f098 100644 --- a/src/AbpDevTools/Commands/BuildCommand.cs +++ b/src/AbpDevTools/Commands/BuildCommand.cs @@ -2,7 +2,6 @@ using AbpDevTools.Notifications; using CliFx.Infrastructure; using Spectre.Console; -using System; using System.Diagnostics; namespace AbpDevTools.Commands; @@ -49,9 +48,11 @@ public async ValueTask ExecuteAsync(IConsole console) buildFiles = await FindBuildFilesAsync("*.csproj", "csproj"); } + buildFiles = (buildFiles ?? Array.Empty()).Union(await FindBuildFilesAsync("angular.json", "angular")).ToArray(); + if (buildFiles.Length == 0) { - await console.Output.WriteLineAsync("No .csproj files found. No files to build."); + await console.Output.WriteLineAsync("No .csproj or angular.json files found. No files to build."); return; } @@ -67,19 +68,37 @@ public async ValueTask ExecuteAsync(IConsole console) var commandSuffix = string.Empty; - if (!string.IsNullOrEmpty(Configuration)) + var tools = toolsConfiguration.GetOptions(); + if (buildFile.Name == "angular.json") { - commandSuffix += $" --configuration {Configuration}"; - } + if (!string.IsNullOrEmpty(Configuration)) + { + commandSuffix += $" --env={Configuration.Replace("debug", "development").Replace("release", "production")}"; + } - var tools = toolsConfiguration.GetOptions(); - runningProcess = Process.Start(new ProcessStartInfo(tools["dotnet"], "build /graphBuild" + commandSuffix) + runningProcess = Process.Start(new ProcessStartInfo(tools["powershell"], "-Command yarn" + commandSuffix) + { + WorkingDirectory = Path.GetDirectoryName(buildFile.FullName), + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + })!; + } + else { - WorkingDirectory = Path.GetDirectoryName(buildFile.FullName), - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - })!; + if (!string.IsNullOrEmpty(Configuration)) + { + commandSuffix += $" --configuration {Configuration}"; + } + + runningProcess = Process.Start(new ProcessStartInfo(tools["dotnet"], "build /graphBuild" + commandSuffix) + { + WorkingDirectory = Path.GetDirectoryName(buildFile.FullName), + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + })!; + } // equivalent of WaitForExit var _output = await runningProcess.StandardOutput.ReadToEndAsync(); @@ -109,7 +128,7 @@ public async ValueTask ExecuteAsync(IConsole console) if (buildFiles.Length == 1) { - await notificationManager.SendAsync("Build "+ (successfulCount > 0 ? "Completed!" : "Failed!"), $"{buildFiles[0].Name} has been built."); + await notificationManager.SendAsync("Build " + (successfulCount > 0 ? "Completed!" : "Failed!"), $"{buildFiles[0].Name} has been built."); } else { diff --git a/src/AbpDevTools/Commands/RunCommand.cs b/src/AbpDevTools/Commands/RunCommand.cs index c5e7717..15b92d6 100644 --- a/src/AbpDevTools/Commands/RunCommand.cs +++ b/src/AbpDevTools/Commands/RunCommand.cs @@ -106,13 +106,13 @@ public async ValueTask ExecuteAsync(IConsole console) await Task.Yield(); - return Directory.EnumerateFiles(WorkingDirectory, "*.csproj", SearchOption.AllDirectories) - .Where(x => _runnableProjects.Any(y => x.EndsWith(y + ".csproj"))) + return MultiEnumerateFiles(WorkingDirectory, "*.csproj|*.json") + .Where(x => _runnableProjects.Any(y => x.EndsWith(y + ".csproj") || x.EndsWith(y + ".json"))) .Select(x => new FileInfo(x)) .ToArray(); }); - await console.Output.WriteLineAsync($"{csprojs.Length} csproj file(s) found."); + await console.Output.WriteLineAsync($"{csprojs.Length} file(s) found."); if (!SkipMigration && localRootConfig?.Run?.SkipMigrate != true) { @@ -159,20 +159,40 @@ public async ValueTask ExecuteAsync(IConsole console) { localConfigurationManager.TryLoad(csproj.FullName, out var localConfiguration); - var commandPrefix = BuildCommandPrefix(localConfiguration?.Run?.Watch); - var commandSuffix = BuildCommandSuffix( - localConfiguration?.Run?.NoBuild, - localConfiguration?.Run?.GraphBuild, - localConfiguration?.Run?.Configuration); - + bool isCsProj = csproj.FullName.EndsWith(".csproj"); var tools = toolsConfiguration.GetOptions(); - var startInfo = new ProcessStartInfo(tools["dotnet"], commandPrefix + $"run --project \"{csproj.FullName}\"" + commandSuffix) + ProcessStartInfo startInfo; + if (isCsProj) { - WorkingDirectory = Path.GetDirectoryName(csproj.FullName), - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - }; + var commandPrefix = BuildCommandPrefix(localConfiguration?.Run?.Watch); + var commandSuffix = BuildCommandSuffix( + localConfiguration?.Run?.NoBuild, + localConfiguration?.Run?.GraphBuild, + localConfiguration?.Run?.Configuration); + + + startInfo = new ProcessStartInfo(tools["dotnet"], commandPrefix + $"run --project \"{csproj.FullName}\"" + commandSuffix) + { + WorkingDirectory = Path.GetDirectoryName(csproj.FullName), + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + } + else + { + var command = BuildAngularCommand( + localConfiguration?.Run?.NoBuild, + localConfiguration?.Run?.Configuration); + + startInfo = new ProcessStartInfo(tools["powershell"], command) + { + WorkingDirectory = Path.GetDirectoryName(csproj.FullName), + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + } localConfigurationManager.ApplyLocalEnvironmentForProcess(csproj.FullName, startInfo, localConfiguration); @@ -191,7 +211,7 @@ public async ValueTask ExecuteAsync(IConsole console) if (InstallLibs) { var installLibsRunninItem = new RunningInstallLibsItem( - csproj.Name.Replace(".csproj", " install-libs"), + csproj.Name.Replace(".csproj", " install-libs").Replace(".json", " install-libs"), Process.Start(new ProcessStartInfo("abp", "install-libs") { WorkingDirectory = Path.GetDirectoryName(csproj.FullName), @@ -213,7 +233,7 @@ public async ValueTask ExecuteAsync(IConsole console) private void ApplyLocalProjects(LocalConfiguration? localConfiguration) { - if(localConfiguration is not null) + if (localConfiguration is not null) { if (Projects.Length == 0 && localConfiguration?.Run?.Projects.Length > 0) { @@ -252,6 +272,25 @@ private string BuildCommandPrefix(bool? watchOverride) return Watch ? "watch " : string.Empty; } + private string BuildAngularCommand(bool? noBuild = null, string? configuration = null) + { + var angularConfSuffix = string.Empty; + if (configuration != null) + { + angularConfSuffix += $" --env={configuration.Replace("debug", "development").Replace("release", "production")}"; + } + else if (!string.IsNullOrEmpty(Configuration)) + { + angularConfSuffix += $" --env={Configuration.Replace("debug", "development").Replace("release", "production")}"; + } + + var angularSuffix = (NoBuild || noBuild == true) + ? "-Command yarn start" + angularConfSuffix + : $"-Command yarn{angularConfSuffix} && yarn start" + angularConfSuffix; + + return angularSuffix; + } + private async Task RenderProcesses(CancellationToken cancellationToken) { var table = new Table().Ascii2Border(); @@ -329,4 +368,11 @@ protected void KillRunningProcesses() project.Process?.WaitForExit(); } } + + private static IEnumerable MultiEnumerateFiles(string path, string patterns) + { + foreach (var pattern in patterns.Split('|')) + foreach (var file in Directory.EnumerateFiles(path, pattern, SearchOption.AllDirectories)) + yield return file; + } } \ No newline at end of file diff --git a/src/AbpDevTools/Commands/RunningProjectItem.cs b/src/AbpDevTools/Commands/RunningProjectItem.cs index 18087c1..10a9887 100644 --- a/src/AbpDevTools/Commands/RunningProjectItem.cs +++ b/src/AbpDevTools/Commands/RunningProjectItem.cs @@ -58,6 +58,16 @@ protected virtual void OutputReceived(object sender, DataReceivedEventArgs args) IsCompleted = true; } + if (args.Data != null && args.Data.Contains("** Angular Live Development Server is listening on ")) + { + Status = args.Data + [args.Data.IndexOf(", open your browser on ")..] + .Replace(", open your browser on ", string.Empty) + .Replace(" **", string.Empty); + Process?.CancelOutputRead(); + IsCompleted = true; + } + if (DateTime.Now - Process?.StartTime > TimeSpan.FromMinutes(5)) { Status = "Stale"; diff --git a/src/AbpDevTools/Configuration/RunConfiguration.cs b/src/AbpDevTools/Configuration/RunConfiguration.cs index 20976ca..956fed9 100644 --- a/src/AbpDevTools/Configuration/RunConfiguration.cs +++ b/src/AbpDevTools/Configuration/RunConfiguration.cs @@ -28,7 +28,8 @@ protected override RunOptions GetDefaults() ".Unified", ".PublicWeb", ".PublicWebGateway", - ".WebGateway" + ".WebGateway", + "angular" } }; }