Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(): angular support #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions src/AbpDevTools/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using AbpDevTools.Notifications;
using CliFx.Infrastructure;
using Spectre.Console;
using System;
using System.Diagnostics;

namespace AbpDevTools.Commands;
Expand Down Expand Up @@ -49,9 +48,11 @@ public async ValueTask ExecuteAsync(IConsole console)
buildFiles = await FindBuildFilesAsync("*.csproj", "csproj");
}

buildFiles = (buildFiles ?? Array.Empty<FileInfo>()).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;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down
80 changes: 63 additions & 17 deletions src/AbpDevTools/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand All @@ -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),
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -329,4 +368,11 @@ protected void KillRunningProcesses()
project.Process?.WaitForExit();
}
}

private static IEnumerable<string> MultiEnumerateFiles(string path, string patterns)
{
foreach (var pattern in patterns.Split('|'))
foreach (var file in Directory.EnumerateFiles(path, pattern, SearchOption.AllDirectories))
yield return file;
}
}
10 changes: 10 additions & 0 deletions src/AbpDevTools/Commands/RunningProjectItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/AbpDevTools/Configuration/RunConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ protected override RunOptions GetDefaults()
".Unified",
".PublicWeb",
".PublicWebGateway",
".WebGateway"
".WebGateway",
"angular"
}
};
}
Expand Down
Loading