Renaming packageManagerCommand variables, fixing comment
This commit is contained in:
parent
7c7dd6569f
commit
c398361412
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task Build(ISpaBuilder spaBuilder)
|
public async Task Build(ISpaBuilder spaBuilder)
|
||||||
{
|
{
|
||||||
var pkgManagerName = spaBuilder.Options.PackageManagerName;
|
var pkgManagerCommand = spaBuilder.Options.PackageManagerCommand;
|
||||||
var sourcePath = spaBuilder.Options.SourcePath;
|
var sourcePath = spaBuilder.Options.SourcePath;
|
||||||
if (string.IsNullOrEmpty(sourcePath))
|
if (string.IsNullOrEmpty(sourcePath))
|
||||||
{
|
{
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
|
||||||
_scriptName,
|
_scriptName,
|
||||||
"--watch",
|
"--watch",
|
||||||
null,
|
null,
|
||||||
pkgManagerName);
|
pkgManagerCommand);
|
||||||
scriptRunner.AttachToLogger(logger);
|
scriptRunner.AttachToLogger(logger);
|
||||||
|
|
||||||
using (var stdOutReader = new EventedStreamStringReader(scriptRunner.StdOut))
|
using (var stdOutReader = new EventedStreamStringReader(scriptRunner.StdOut))
|
||||||
|
|
@ -69,14 +69,14 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
|
||||||
catch (EndOfStreamException ex)
|
catch (EndOfStreamException ex)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
$"The {pkgManagerName} script '{_scriptName}' exited without indicating success.\n" +
|
$"The {pkgManagerCommand} script '{_scriptName}' exited without indicating success.\n" +
|
||||||
$"Output was: {stdOutReader.ReadAsString()}\n" +
|
$"Output was: {stdOutReader.ReadAsString()}\n" +
|
||||||
$"Error output was: {stdErrReader.ReadAsString()}", ex);
|
$"Error output was: {stdErrReader.ReadAsString()}", ex);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException ex)
|
catch (OperationCanceledException ex)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
$"The {pkgManagerName} script '{_scriptName}' timed out without indicating success. " +
|
$"The {pkgManagerCommand} script '{_scriptName}' timed out without indicating success. " +
|
||||||
$"Output was: {stdOutReader.ReadAsString()}\n" +
|
$"Output was: {stdOutReader.ReadAsString()}\n" +
|
||||||
$"Error output was: {stdErrReader.ReadAsString()}", ex);
|
$"Error output was: {stdErrReader.ReadAsString()}", ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
|
||||||
ISpaBuilder spaBuilder,
|
ISpaBuilder spaBuilder,
|
||||||
string scriptName)
|
string scriptName)
|
||||||
{
|
{
|
||||||
var pkgManagerName = spaBuilder.Options.PackageManagerName;
|
var pkgManagerCommand = spaBuilder.Options.PackageManagerCommand;
|
||||||
var sourcePath = spaBuilder.Options.SourcePath;
|
var sourcePath = spaBuilder.Options.SourcePath;
|
||||||
if (string.IsNullOrEmpty(sourcePath))
|
if (string.IsNullOrEmpty(sourcePath))
|
||||||
{
|
{
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
|
||||||
// Start Angular CLI and attach to middleware pipeline
|
// Start Angular CLI and attach to middleware pipeline
|
||||||
var appBuilder = spaBuilder.ApplicationBuilder;
|
var appBuilder = spaBuilder.ApplicationBuilder;
|
||||||
var logger = LoggerFinder.GetOrCreateLogger(appBuilder, LogCategoryName);
|
var logger = LoggerFinder.GetOrCreateLogger(appBuilder, LogCategoryName);
|
||||||
var angularCliServerInfoTask = StartAngularCliServerAsync(sourcePath, scriptName, pkgManagerName, logger);
|
var angularCliServerInfoTask = StartAngularCliServerAsync(sourcePath, scriptName, pkgManagerCommand, logger);
|
||||||
|
|
||||||
// Everything we proxy is hardcoded to target http://localhost because:
|
// Everything we proxy is hardcoded to target http://localhost because:
|
||||||
// - the requests are always from the local machine (we're not accepting remote
|
// - the requests are always from the local machine (we're not accepting remote
|
||||||
|
|
@ -63,13 +63,13 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<AngularCliServerInfo> StartAngularCliServerAsync(
|
private static async Task<AngularCliServerInfo> StartAngularCliServerAsync(
|
||||||
string sourcePath, string scriptName, string pkgManagerName, ILogger logger)
|
string sourcePath, string scriptName, string pkgManagerCommand, ILogger logger)
|
||||||
{
|
{
|
||||||
var portNumber = TcpPortFinder.FindAvailablePort();
|
var portNumber = TcpPortFinder.FindAvailablePort();
|
||||||
logger.LogInformation($"Starting @angular/cli on port {portNumber}...");
|
logger.LogInformation($"Starting @angular/cli on port {portNumber}...");
|
||||||
|
|
||||||
var scriptRunner = new NodeScriptRunner(
|
var scriptRunner = new NodeScriptRunner(
|
||||||
sourcePath, scriptName, $"--port {portNumber}", null, pkgManagerName);
|
sourcePath, scriptName, $"--port {portNumber}", null, pkgManagerCommand);
|
||||||
scriptRunner.AttachToLogger(logger);
|
scriptRunner.AttachToLogger(logger);
|
||||||
|
|
||||||
Match openBrowserLine;
|
Match openBrowserLine;
|
||||||
|
|
@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
|
||||||
catch (EndOfStreamException ex)
|
catch (EndOfStreamException ex)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
$"The {pkgManagerName} script '{scriptName}' exited without indicating that the " +
|
$"The {pkgManagerCommand} script '{scriptName}' exited without indicating that the " +
|
||||||
$"Angular CLI was listening for requests. The error output was: " +
|
$"Angular CLI was listening for requests. The error output was: " +
|
||||||
$"{stdErrReader.ReadAsString()}", ex);
|
$"{stdErrReader.ReadAsString()}", ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.NodeServices.Npm
|
||||||
|
|
||||||
private static Regex AnsiColorRegex = new Regex("\x001b\\[[0-9;]*m", RegexOptions.None, TimeSpan.FromSeconds(1));
|
private static Regex AnsiColorRegex = new Regex("\x001b\\[[0-9;]*m", RegexOptions.None, TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
public NodeScriptRunner(string workingDirectory, string scriptName, string arguments, IDictionary<string, string> envVars, string pkgManagerName)
|
public NodeScriptRunner(string workingDirectory, string scriptName, string arguments, IDictionary<string, string> envVars, string pkgManagerCommand)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(workingDirectory))
|
if (string.IsNullOrEmpty(workingDirectory))
|
||||||
{
|
{
|
||||||
|
|
@ -35,12 +35,12 @@ namespace Microsoft.AspNetCore.NodeServices.Npm
|
||||||
throw new ArgumentException("Cannot be null or empty.", nameof(scriptName));
|
throw new ArgumentException("Cannot be null or empty.", nameof(scriptName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(pkgManagerName))
|
if (string.IsNullOrEmpty(pkgManagerCommand))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Cannot be null or empty.", nameof(pkgManagerName));
|
throw new ArgumentException("Cannot be null or empty.", nameof(pkgManagerCommand));
|
||||||
}
|
}
|
||||||
|
|
||||||
var exeToRun = pkgManagerName;
|
var exeToRun = pkgManagerCommand;
|
||||||
var completeArguments = $"run {scriptName} -- {arguments ?? string.Empty}";
|
var completeArguments = $"run {scriptName} -- {arguments ?? string.Empty}";
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.NodeServices.Npm
|
||||||
// directly (except with UseShellExecute=true, but that's no good, because
|
// directly (except with UseShellExecute=true, but that's no good, because
|
||||||
// it prevents capturing stdio). So we need to invoke it via "cmd /c".
|
// it prevents capturing stdio). So we need to invoke it via "cmd /c".
|
||||||
exeToRun = "cmd";
|
exeToRun = "cmd";
|
||||||
completeArguments = $"/c {pkgManagerName} {completeArguments}";
|
completeArguments = $"/c {pkgManagerCommand} {completeArguments}";
|
||||||
}
|
}
|
||||||
|
|
||||||
var processStartInfo = new ProcessStartInfo(exeToRun)
|
var processStartInfo = new ProcessStartInfo(exeToRun)
|
||||||
|
|
@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.NodeServices.Npm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var process = LaunchNodeProcess(processStartInfo, pkgManagerName);
|
var process = LaunchNodeProcess(processStartInfo, pkgManagerCommand);
|
||||||
StdOut = new EventedStreamReader(process.StandardOutput);
|
StdOut = new EventedStreamReader(process.StandardOutput);
|
||||||
StdErr = new EventedStreamReader(process.StandardError);
|
StdErr = new EventedStreamReader(process.StandardError);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
|
||||||
ISpaBuilder spaBuilder,
|
ISpaBuilder spaBuilder,
|
||||||
string scriptName)
|
string scriptName)
|
||||||
{
|
{
|
||||||
var pkgManagerName = spaBuilder.Options.PackageManagerName;
|
var pkgManagerCommand = spaBuilder.Options.PackageManagerCommand;
|
||||||
var sourcePath = spaBuilder.Options.SourcePath;
|
var sourcePath = spaBuilder.Options.SourcePath;
|
||||||
if (string.IsNullOrEmpty(sourcePath))
|
if (string.IsNullOrEmpty(sourcePath))
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
|
||||||
// Start create-react-app and attach to middleware pipeline
|
// Start create-react-app and attach to middleware pipeline
|
||||||
var appBuilder = spaBuilder.ApplicationBuilder;
|
var appBuilder = spaBuilder.ApplicationBuilder;
|
||||||
var logger = LoggerFinder.GetOrCreateLogger(appBuilder, LogCategoryName);
|
var logger = LoggerFinder.GetOrCreateLogger(appBuilder, LogCategoryName);
|
||||||
var portTask = StartCreateReactAppServerAsync(sourcePath, scriptName, pkgManagerName, logger);
|
var portTask = StartCreateReactAppServerAsync(sourcePath, scriptName, pkgManagerCommand, logger);
|
||||||
|
|
||||||
// Everything we proxy is hardcoded to target http://localhost because:
|
// Everything we proxy is hardcoded to target http://localhost because:
|
||||||
// - the requests are always from the local machine (we're not accepting remote
|
// - the requests are always from the local machine (we're not accepting remote
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<int> StartCreateReactAppServerAsync(
|
private static async Task<int> StartCreateReactAppServerAsync(
|
||||||
string sourcePath, string scriptName, string pkgManagerName, ILogger logger)
|
string sourcePath, string scriptName, string pkgManagerCommand, ILogger logger)
|
||||||
{
|
{
|
||||||
var portNumber = TcpPortFinder.FindAvailablePort();
|
var portNumber = TcpPortFinder.FindAvailablePort();
|
||||||
logger.LogInformation($"Starting create-react-app server on port {portNumber}...");
|
logger.LogInformation($"Starting create-react-app server on port {portNumber}...");
|
||||||
|
|
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
|
||||||
{ "BROWSER", "none" }, // We don't want create-react-app to open its own extra browser window pointing to the internal dev server port
|
{ "BROWSER", "none" }, // We don't want create-react-app to open its own extra browser window pointing to the internal dev server port
|
||||||
};
|
};
|
||||||
var scriptRunner = new NodeScriptRunner(
|
var scriptRunner = new NodeScriptRunner(
|
||||||
sourcePath, scriptName, null, envVars, pkgManagerName);
|
sourcePath, scriptName, null, envVars, pkgManagerCommand);
|
||||||
scriptRunner.AttachToLogger(logger);
|
scriptRunner.AttachToLogger(logger);
|
||||||
|
|
||||||
using (var stdErrReader = new EventedStreamStringReader(scriptRunner.StdErr))
|
using (var stdErrReader = new EventedStreamStringReader(scriptRunner.StdErr))
|
||||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
|
||||||
catch (EndOfStreamException ex)
|
catch (EndOfStreamException ex)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
$"The {pkgManagerName} script '{scriptName}' exited without indicating that the " +
|
$"The {pkgManagerCommand} script '{scriptName}' exited without indicating that the " +
|
||||||
$"create-react-app server was listening for requests. The error output was: " +
|
$"create-react-app server was listening for requests. The error output was: " +
|
||||||
$"{stdErrReader.ReadAsString()}", ex);
|
$"{stdErrReader.ReadAsString()}", ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.SpaServices
|
||||||
public class SpaOptions
|
public class SpaOptions
|
||||||
{
|
{
|
||||||
private PathString _defaultPage = "/index.html";
|
private PathString _defaultPage = "/index.html";
|
||||||
private string _defaultPackageManagerName = "npm";
|
private string _packageManagerCommand = "npm";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new instance of <see cref="SpaOptions"/>.
|
/// Constructs a new instance of <see cref="SpaOptions"/>.
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.SpaServices
|
||||||
internal SpaOptions(SpaOptions copyFromOptions)
|
internal SpaOptions(SpaOptions copyFromOptions)
|
||||||
{
|
{
|
||||||
_defaultPage = copyFromOptions.DefaultPage;
|
_defaultPage = copyFromOptions.DefaultPage;
|
||||||
_defaultPackageManagerName = copyFromOptions.PackageManagerName;
|
_packageManagerCommand = copyFromOptions.PackageManagerCommand;
|
||||||
DefaultPageStaticFileOptions = copyFromOptions.DefaultPageStaticFileOptions;
|
DefaultPageStaticFileOptions = copyFromOptions.DefaultPageStaticFileOptions;
|
||||||
SourcePath = copyFromOptions.SourcePath;
|
SourcePath = copyFromOptions.SourcePath;
|
||||||
}
|
}
|
||||||
|
|
@ -74,20 +74,19 @@ namespace Microsoft.AspNetCore.SpaServices
|
||||||
/// Gets or sets the name of the package manager executible, (e.g npm,
|
/// Gets or sets the name of the package manager executible, (e.g npm,
|
||||||
/// yarn) to run the SPA.
|
/// yarn) to run the SPA.
|
||||||
///
|
///
|
||||||
/// If not set, npm will be assumed as the default package manager
|
/// The default value is 'npm'.
|
||||||
/// executable
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PackageManagerName
|
public string PackageManagerCommand
|
||||||
{
|
{
|
||||||
get => _defaultPackageManagerName;
|
get => _packageManagerCommand;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(value))
|
if (string.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"The value for {nameof(PackageManagerName)} cannot be null or empty.");
|
throw new ArgumentException($"The value for {nameof(PackageManagerCommand)} cannot be null or empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_defaultPackageManagerName = value;
|
_packageManagerCommand = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue