Skip to content

Commit

Permalink
default "start" script
Browse files Browse the repository at this point in the history
  • Loading branch information
snys98 committed Jan 20, 2021
1 parent c6e7732 commit 6da1635
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions AngularCliMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ public static class AngularCliMiddleware
private const string LogCategoryName = "Microsoft.AspNetCore.SpaServices";
private static TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(5.0);

public static void Attach(ISpaBuilder spaBuilder, string npmScriptName)
public static void Attach(ISpaBuilder spaBuilder)
{
string sourcePath = spaBuilder.Options.SourcePath;
if (string.IsNullOrEmpty(sourcePath))
throw new ArgumentException("Cannot be null or empty", "sourcePath");
if (string.IsNullOrEmpty(npmScriptName))
throw new ArgumentException("Cannot be null or empty", nameof(npmScriptName));
ILogger logger =
spaBuilder.ApplicationBuilder.ApplicationServices.GetService<ILogger<AngularCliServerInfo>>();
Task<Uri> targetUriTask = AngularCliMiddleware.StartAngularCliServerAsync(sourcePath, npmScriptName, logger).ContinueWith<Uri>((Func<Task<AngularCliMiddleware.AngularCliServerInfo>, Uri>)(task => new UriBuilder("http", "localhost", task.Result.Port).Uri));
Task<Uri> targetUriTask = AngularCliMiddleware.StartAngularCliServerAsync(sourcePath, logger).ContinueWith<Uri>((Func<Task<AngularCliMiddleware.AngularCliServerInfo>, Uri>)(task => new UriBuilder("http", "localhost", task.Result.Port).Uri));
spaBuilder.UseProxyToSpaDevelopmentServer((Func<Task<Uri>>)(() =>
{
TimeSpan startupTimeout = spaBuilder.Options.StartupTimeout;
Expand All @@ -40,11 +38,10 @@ public static void Attach(ISpaBuilder spaBuilder, string npmScriptName)

private static async Task<AngularCliMiddleware.AngularCliServerInfo> StartAngularCliServerAsync(
string sourcePath,
string npmScriptName,
ILogger logger)
{
logger.LogInformation("Starting @angular/cli ...");
NpmScriptRunner npmScriptRunner = new NpmScriptRunner(sourcePath, npmScriptName, (IDictionary<string, string>)null);
NpmScriptRunner npmScriptRunner = new NpmScriptRunner(sourcePath, "start", (IDictionary<string, string>)null);
npmScriptRunner.AttachToLogger(logger);
Match match;
using (EventedStreamStringReader stdErrReader = new EventedStreamStringReader(npmScriptRunner.StdErr))
Expand All @@ -55,7 +52,7 @@ public static void Attach(ISpaBuilder spaBuilder, string npmScriptName)
}
catch (EndOfStreamException ex)
{
throw new InvalidOperationException("The NPM script '" + npmScriptName + "' exited without indicating that the Angular CLI was listening for requests. The error output was: " + stdErrReader.ReadAsString(), (Exception)ex);
throw new InvalidOperationException("The NPM script 'start' exited without indicating that the Angular CLI was listening for requests. The error output was: " + stdErrReader.ReadAsString(), (Exception)ex);
}
}
Uri cliServerUri = new Uri(match.Groups[1].Value);
Expand Down
4 changes: 2 additions & 2 deletions Extensions/AngularCliMiddlewareExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
{
public static class AngularCliMiddlewareExtensions
{
public static void UseAngularCliServer(this ISpaBuilder spaBuilder, string npmScript)
public static void UseAngularCliServer(this ISpaBuilder spaBuilder)
{
if (spaBuilder == null)
throw new ArgumentNullException(nameof(spaBuilder));
if (string.IsNullOrEmpty(spaBuilder.Options.SourcePath))
throw new InvalidOperationException("To use UseAngularCliServer, you must supply a non-empty value for the SourcePath property of SpaOptions when calling UseSpa.");
AngularCliMiddleware.Attach(spaBuilder, npmScript);
AngularCliMiddleware.Attach(spaBuilder);
}
}
}

0 comments on commit 6da1635

Please sign in to comment.