mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 10:08:57 +00:00
Compare commits
1 Commits
rel/2.0.0-
...
angular4-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
678e230021 |
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-master/api/v3/index.json" />
|
||||
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
|
||||
<add key="AspNetCoreTools" value="https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json" />
|
||||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
@@ -33,7 +33,7 @@ cd $PSScriptRoot
|
||||
$repoFolder = $PSScriptRoot
|
||||
$env:REPO_FOLDER = $repoFolder
|
||||
|
||||
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview2.zip"
|
||||
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip"
|
||||
if ($env:KOREBUILD_ZIP)
|
||||
{
|
||||
$koreBuildZip=$env:KOREBUILD_ZIP
|
||||
|
||||
2
build.sh
2
build.sh
@@ -2,7 +2,7 @@
|
||||
repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd $repoFolder
|
||||
|
||||
koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview2.zip"
|
||||
koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip"
|
||||
if [ ! -z $KOREBUILD_ZIP ]; then
|
||||
koreBuildZip=$KOREBUILD_ZIP
|
||||
fi
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(InternalAspNetCoreSdkVersion)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
|
||||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework' AND '$(OutputType)'=='library'">
|
||||
<PackageReference Include="NETStandard.Library" Version="$(BundledNETStandardPackageVersion)" />
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<AspNetCoreVersion>2.0.0-preview2-*</AspNetCoreVersion>
|
||||
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
|
||||
<AutoMapperVersion>5.0.2</AutoMapperVersion>
|
||||
<CoreFxVersion>4.3.0</CoreFxVersion>
|
||||
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
|
||||
<JsonNetVersion>10.0.1</JsonNetVersion>
|
||||
<NETStandardImplicitPackageVersion>$(BundledNETStandardPackageVersion)</NETStandardImplicitPackageVersion>
|
||||
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
|
||||
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0-*</RuntimeFrameworkVersion>
|
||||
<ThreadingDataflowVersion>4.7.0</ThreadingDataflowVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
12
build/repo.targets
Normal file
12
build/repo.targets
Normal file
@@ -0,0 +1,12 @@
|
||||
<Project>
|
||||
<Target Name="NpmRestore" AfterTargets="Restore" Condition="'$(PreflightRestore)' != 'true'">
|
||||
<ItemGroup>
|
||||
<NpmModules Include="$(RepositoryRoot)**\package.json"
|
||||
Exclude="$(RepositoryRoot)**\node_modules\**\*" />
|
||||
</ItemGroup>
|
||||
|
||||
<Message Text="Restoring NPM modules for: %0A - @(NpmModules -> '%(FullPath)','%0A - ')" Importance="high" />
|
||||
|
||||
<Exec Command="npm install" WorkingDirectory="%(NpmModules.RootDir)%(Directory)" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,9 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\..\build\common.props" />
|
||||
<Import Project="..\..\..\build\dependencies.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<OutputType>exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="..\..\..\build\common.props" />
|
||||
<Import Project="..\..\..\build\dependencies.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace Webpack.ActionResults
|
||||
{
|
||||
var nodeServices = context.HttpContext.RequestServices.GetRequiredService<INodeServices>();
|
||||
var hostEnv = context.HttpContext.RequestServices.GetRequiredService<IHostingEnvironment>();
|
||||
var applicationLifetime = context.HttpContext.RequestServices.GetRequiredService<IApplicationLifetime>();
|
||||
var applicationBasePath = hostEnv.ContentRootPath;
|
||||
var request = context.HttpContext.Request;
|
||||
var response = context.HttpContext.Response;
|
||||
@@ -35,7 +34,6 @@ namespace Webpack.ActionResults
|
||||
var prerenderedHtml = await Prerenderer.RenderToString(
|
||||
applicationBasePath,
|
||||
nodeServices,
|
||||
applicationLifetime.ApplicationStopping,
|
||||
_moduleExport,
|
||||
request.GetEncodedUrl(),
|
||||
request.Path + request.QueryString.Value,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="..\..\..\build\common.props" />
|
||||
<Import Project="..\..\..\build\dependencies.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Socket-based RPC for Microsoft.AspNetCore.NodeServices.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<PackageTags>aspnetcore;aspnetcoremvc;nodeservices</PackageTags>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
</PropertyGroup>
|
||||
@@ -15,6 +15,14 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.NodeServices\Microsoft.AspNetCore.NodeServices.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||
<PackageReference Include="Microsoft.Tpl.Dataflow" Version="$(MicrosoftDataflowVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
|
||||
<PackageReference Include="System.IO.Pipes" Version="$(CoreFxVersion)" />
|
||||
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="$(ThreadingDataflowVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -18,7 +18,11 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets.PhysicalConnections
|
||||
PipeDirection.InOut,
|
||||
PipeOptions.Asynchronous);
|
||||
|
||||
#if NET451
|
||||
_namedPipeClientStream.Connect();
|
||||
#else
|
||||
await _namedPipeClientStream.ConnectAsync().ConfigureAwait(false);
|
||||
#endif
|
||||
|
||||
return _namedPipeClientStream;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets.PhysicalConnections
|
||||
|
||||
public static StreamConnection Create()
|
||||
{
|
||||
#if NET451
|
||||
return new NamedPipeConnection();
|
||||
#else
|
||||
var useNamedPipes = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
|
||||
System.Runtime.InteropServices.OSPlatform.Windows);
|
||||
if (useNamedPipes)
|
||||
@@ -21,6 +24,7 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets.PhysicalConnections
|
||||
{
|
||||
return new UnixDomainSocketConnection();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,16 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets.PhysicalConnections
|
||||
private NetworkStream _networkStream;
|
||||
private Socket _socket;
|
||||
|
||||
#if NET451
|
||||
public override Task<Stream> Open(string address)
|
||||
{
|
||||
// The 'null' assignments avoid the compiler warnings about unassigned fields.
|
||||
// Note that this whole class isn't supported on .NET 4.5.1, since that's not cross-platform.
|
||||
_networkStream = null;
|
||||
_socket = null;
|
||||
throw new System.PlatformNotSupportedException();
|
||||
}
|
||||
#else
|
||||
public override async Task<Stream> Open(string address)
|
||||
{
|
||||
var endPoint = new UnixDomainSocketEndPoint("/tmp/" + address);
|
||||
@@ -18,6 +28,7 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets.PhysicalConnections
|
||||
_networkStream = new NetworkStream(_socket);
|
||||
return _networkStream;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
|
||||
@@ -59,7 +59,11 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets.PhysicalConnections
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NET451
|
||||
_encodedPath = new byte[0];
|
||||
#else
|
||||
_encodedPath = Array.Empty<byte>();
|
||||
#endif
|
||||
_path = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets
|
||||
options.ProjectPath,
|
||||
options.WatchFileExtensions,
|
||||
MakeNewCommandLineOptions(socketAddress),
|
||||
options.ApplicationStoppingToken,
|
||||
options.NodeInstanceOutputLogger,
|
||||
options.EnvironmentVariables,
|
||||
options.InvocationTimeoutMilliseconds,
|
||||
|
||||
@@ -12,7 +12,11 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets.VirtualConnections
|
||||
/// </summary>
|
||||
internal class VirtualConnection : Stream
|
||||
{
|
||||
#if NET451
|
||||
private readonly static Task CompletedTask = Task.FromResult((object)null);
|
||||
#else
|
||||
private readonly static Task CompletedTask = Task.CompletedTask;
|
||||
#endif
|
||||
private VirtualConnectionClient _host;
|
||||
private readonly BufferBlock<byte[]> _receivedDataQueue = new BufferBlock<byte[]>();
|
||||
private ArraySegment<byte> _receivedDataNotYetUsed;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.NodeServices.HostingModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -43,12 +42,6 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
EnvironmentVariables["NODE_ENV"] = hostEnv.IsDevelopment() ? "development" : "production"; // De-facto standard values for Node
|
||||
}
|
||||
|
||||
var applicationLifetime = serviceProvider.GetService<IApplicationLifetime>();
|
||||
if (applicationLifetime != null)
|
||||
{
|
||||
ApplicationStoppingToken = applicationLifetime.ApplicationStopping;
|
||||
}
|
||||
|
||||
// If the DI system gives us a logger, use it. Otherwise, set up a default one.
|
||||
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
|
||||
NodeInstanceOutputLogger = loggerFactory != null
|
||||
@@ -100,10 +93,5 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
/// Specifies the maximum duration, in milliseconds, that your .NET code should wait for Node.js RPC calls to return.
|
||||
/// </summary>
|
||||
public int InvocationTimeoutMilliseconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A token that indicates when the host application is stopping.
|
||||
/// </summary>
|
||||
public CancellationToken ApplicationStoppingToken { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,6 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
options.ProjectPath,
|
||||
options.WatchFileExtensions,
|
||||
MakeCommandLineOptions(port),
|
||||
options.ApplicationStoppingToken,
|
||||
options.NodeInstanceOutputLogger,
|
||||
options.EnvironmentVariables,
|
||||
options.InvocationTimeoutMilliseconds,
|
||||
|
||||
@@ -45,7 +45,6 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
/// <param name="projectPath">The root path of the current project. This is used when resolving Node.js module paths relative to the project root.</param>
|
||||
/// <param name="watchFileExtensions">The filename extensions that should be watched within the project root. The Node instance will automatically shut itself down if any matching file changes.</param>
|
||||
/// <param name="commandLineArguments">Additional command-line arguments to be passed to the Node.js instance.</param>
|
||||
/// <param name="applicationStoppingToken">A token that indicates when the host application is stopping.</param>
|
||||
/// <param name="nodeOutputLogger">The <see cref="ILogger"/> to which the Node.js instance's stdout/stderr (and other log information) should be written.</param>
|
||||
/// <param name="environmentVars">Environment variables to be set on the Node.js process.</param>
|
||||
/// <param name="invocationTimeoutMilliseconds">The maximum duration, in milliseconds, to wait for RPC calls to complete.</param>
|
||||
@@ -56,7 +55,6 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
string projectPath,
|
||||
string[] watchFileExtensions,
|
||||
string commandLineArguments,
|
||||
CancellationToken applicationStoppingToken,
|
||||
ILogger nodeOutputLogger,
|
||||
IDictionary<string, string> environmentVars,
|
||||
int invocationTimeoutMilliseconds,
|
||||
@@ -69,7 +67,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
}
|
||||
|
||||
OutputLogger = nodeOutputLogger;
|
||||
_entryPointScript = new StringAsTempFile(entryPointScript, applicationStoppingToken);
|
||||
_entryPointScript = new StringAsTempFile(entryPointScript);
|
||||
_invocationTimeoutMilliseconds = invocationTimeoutMilliseconds;
|
||||
_launchWithDebugging = launchWithDebugging;
|
||||
|
||||
@@ -317,7 +315,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
|
||||
private static void SetEnvironmentVariable(ProcessStartInfo startInfo, string name, string value)
|
||||
{
|
||||
#if NET451
|
||||
startInfo.EnvironmentVariables[name] = value;
|
||||
#else
|
||||
startInfo.Environment[name] = value;
|
||||
#endif
|
||||
}
|
||||
|
||||
private static Process LaunchNodeProcess(ProcessStartInfo startInfo)
|
||||
@@ -381,6 +383,12 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
{
|
||||
OutputLogger.LogWarning(evt.Data);
|
||||
}
|
||||
else if (!initializationIsCompleted)
|
||||
{
|
||||
_connectionIsReadySource.SetException(
|
||||
new InvalidOperationException("The Node.js process failed to initialize: " + evt.Data));
|
||||
initializationIsCompleted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OnErrorDataReceived(UnencodeNewlines(evt.Data));
|
||||
@@ -394,11 +402,9 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
|
||||
private static bool IsDebuggerMessage(string message)
|
||||
{
|
||||
return message.StartsWith("Debugger attached", StringComparison.Ordinal) ||
|
||||
message.StartsWith("Debugger listening ", StringComparison.Ordinal) ||
|
||||
message.StartsWith("To start debugging", StringComparison.Ordinal) ||
|
||||
message.Equals("Warning: This is an experimental feature and could change at any time.", StringComparison.Ordinal) ||
|
||||
message.Equals("For help see https://nodejs.org/en/docs/inspector", StringComparison.Ordinal) ||
|
||||
return message.StartsWith("Debugger attached", StringComparison.OrdinalIgnoreCase) ||
|
||||
message.StartsWith("Debugger listening ", StringComparison.OrdinalIgnoreCase) ||
|
||||
message.StartsWith("To start debugging", StringComparison.OrdinalIgnoreCase) ||
|
||||
message.Contains("chrome-devtools:");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Invoke Node.js modules at runtime in ASP.NET Core applications.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<PackageTags>aspnetcore;aspnetcoremvc;nodeservices</PackageTags>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -20,6 +19,12 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="$(JsonNetVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
|
||||
<PackageReference Include="System.Diagnostics.Process" Version="$(CoreFxVersion)" />
|
||||
<PackageReference Include="System.IO.FileSystem.Watcher" Version="$(CoreFxVersion)" />
|
||||
<PackageReference Include="System.Runtime.Loader" Version="$(CoreFxVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
|
||||
<Exec Command="npm install" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js" />
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.NodeServices
|
||||
{
|
||||
@@ -12,21 +11,27 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
private bool _disposedValue;
|
||||
private bool _hasDeletedTempFile;
|
||||
private object _fileDeletionLock = new object();
|
||||
private IDisposable _applicationLifetimeRegistration;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of <see cref="StringAsTempFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="content">The contents of the temporary file to be created.</param>
|
||||
/// <param name="applicationStoppingToken">A token that indicates when the host application is stopping.</param>
|
||||
public StringAsTempFile(string content, CancellationToken applicationStoppingToken)
|
||||
public StringAsTempFile(string content)
|
||||
{
|
||||
FileName = Path.GetTempFileName();
|
||||
File.WriteAllText(FileName, content);
|
||||
|
||||
// Because .NET finalizers don't reliably run when the process is terminating, also
|
||||
// add event handlers for other shutdown scenarios.
|
||||
_applicationLifetimeRegistration = applicationStoppingToken.Register(EnsureTempFileDeleted);
|
||||
#if NET451
|
||||
AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
|
||||
AppDomain.CurrentDomain.DomainUnload += HandleProcessExit;
|
||||
#else
|
||||
// Note that this still doesn't capture SIGKILL (at least on macOS) - there doesn't
|
||||
// appear to be a way of doing that. So in that case, the temporary file will be
|
||||
// left behind.
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += HandleAssemblyUnloading;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,7 +55,12 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed state
|
||||
_applicationLifetimeRegistration.Dispose();
|
||||
#if NET451
|
||||
AppDomain.CurrentDomain.ProcessExit -= HandleProcessExit;
|
||||
AppDomain.CurrentDomain.DomainUnload -= HandleProcessExit;
|
||||
#else
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading -= HandleAssemblyUnloading;
|
||||
#endif
|
||||
}
|
||||
|
||||
EnsureTempFileDeleted();
|
||||
@@ -71,6 +81,18 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
}
|
||||
}
|
||||
|
||||
#if NET451
|
||||
private void HandleProcessExit(object sender, EventArgs args)
|
||||
{
|
||||
EnsureTempFileDeleted();
|
||||
}
|
||||
#else
|
||||
private void HandleAssemblyUnloading(System.Runtime.Loader.AssemblyLoadContext context)
|
||||
{
|
||||
EnsureTempFileDeleted();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Implements the finalization part of the IDisposable pattern by calling Dispose(false).
|
||||
/// </summary>
|
||||
|
||||
@@ -4,17 +4,15 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Helpers for building single-page applications on ASP.NET MVC Core.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<PackageTags>aspnetcore;aspnetcoremvc;nodeservices</PackageTags>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Content\**\*" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.NodeServices\Microsoft.AspNetCore.NodeServices.csproj" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="$(AspNetCoreVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
@@ -25,7 +24,6 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||
private static INodeServices _fallbackNodeServices; // Used only if no INodeServices was registered with DI
|
||||
|
||||
private readonly string _applicationBasePath;
|
||||
private readonly CancellationToken _applicationStoppingToken;
|
||||
private readonly INodeServices _nodeServices;
|
||||
|
||||
/// <summary>
|
||||
@@ -37,9 +35,6 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||
var hostEnv = (IHostingEnvironment) serviceProvider.GetService(typeof(IHostingEnvironment));
|
||||
_nodeServices = (INodeServices) serviceProvider.GetService(typeof(INodeServices)) ?? _fallbackNodeServices;
|
||||
_applicationBasePath = hostEnv.ContentRootPath;
|
||||
|
||||
var applicationLifetime = (IApplicationLifetime) serviceProvider.GetService(typeof(IApplicationLifetime));
|
||||
_applicationStoppingToken = applicationLifetime.ApplicationStopping;
|
||||
|
||||
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
|
||||
// in your startup file, but then again it might be confusing that you don't need to.
|
||||
@@ -106,7 +101,6 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||
var result = await Prerenderer.RenderToString(
|
||||
_applicationBasePath,
|
||||
_nodeServices,
|
||||
_applicationStoppingToken,
|
||||
new JavaScriptModuleExport(ModuleName)
|
||||
{
|
||||
ExportName = ExportName
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.NodeServices;
|
||||
|
||||
@@ -10,16 +9,22 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||
/// </summary>
|
||||
public static class Prerenderer
|
||||
{
|
||||
private static readonly object CreateNodeScriptLock = new object();
|
||||
private static readonly Lazy<StringAsTempFile> NodeScript;
|
||||
|
||||
private static StringAsTempFile NodeScript;
|
||||
static Prerenderer()
|
||||
{
|
||||
NodeScript = new Lazy<StringAsTempFile>(() =>
|
||||
{
|
||||
var script = EmbeddedResourceReader.Read(typeof(Prerenderer), "/Content/Node/prerenderer.js");
|
||||
return new StringAsTempFile(script); // Will be cleaned up on process exit
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs server-side prerendering by invoking code in Node.js.
|
||||
/// </summary>
|
||||
/// <param name="applicationBasePath">The root path to your application. This is used when resolving project-relative paths.</param>
|
||||
/// <param name="nodeServices">The instance of <see cref="INodeServices"/> that will be used to invoke JavaScript code.</param>
|
||||
/// <param name="applicationStoppingToken">A token that indicates when the host application is stopping.</param>
|
||||
/// <param name="bootModule">The path to the JavaScript file containing the prerendering logic.</param>
|
||||
/// <param name="requestAbsoluteUrl">The URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param>
|
||||
/// <param name="requestPathAndQuery">The path and query part of the URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param>
|
||||
@@ -30,7 +35,6 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||
public static Task<RenderToStringResult> RenderToString(
|
||||
string applicationBasePath,
|
||||
INodeServices nodeServices,
|
||||
CancellationToken applicationStoppingToken,
|
||||
JavaScriptModuleExport bootModule,
|
||||
string requestAbsoluteUrl,
|
||||
string requestPathAndQuery,
|
||||
@@ -39,7 +43,7 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||
string requestPathBase)
|
||||
{
|
||||
return nodeServices.InvokeExportAsync<RenderToStringResult>(
|
||||
GetNodeScriptFilename(applicationStoppingToken),
|
||||
NodeScript.Value.FileName,
|
||||
"renderToString",
|
||||
applicationBasePath,
|
||||
bootModule,
|
||||
@@ -49,19 +53,5 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||
timeoutMilliseconds,
|
||||
requestPathBase);
|
||||
}
|
||||
|
||||
private static string GetNodeScriptFilename(CancellationToken applicationStoppingToken)
|
||||
{
|
||||
lock(CreateNodeScriptLock)
|
||||
{
|
||||
if (NodeScript == null)
|
||||
{
|
||||
var script = EmbeddedResourceReader.Read(typeof(Prerenderer), "/Content/Node/prerenderer.js");
|
||||
NodeScript = new StringAsTempFile(script, applicationStoppingToken); // Will be cleaned up on process exit
|
||||
}
|
||||
}
|
||||
|
||||
return NodeScript.FileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,15 +98,7 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
|
||||
|
||||
using (var responseStream = await responseMessage.Content.ReadAsStreamAsync())
|
||||
{
|
||||
try
|
||||
{
|
||||
await responseStream.CopyToAsync(context.Response.Body, DefaultHttpBufferSize, context.RequestAborted);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// The CopyToAsync task will be canceled if the client disconnects (e.g., user
|
||||
// closes or refreshes the browser tab). Don't treat this as an error.
|
||||
}
|
||||
await responseStream.CopyToAsync(context.Response.Body, DefaultHttpBufferSize, context.RequestAborted);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.NodeServices;
|
||||
using Microsoft.AspNetCore.SpaServices.Webpack;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
@@ -49,7 +54,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||
// middleware). And since this is a dev-time-only feature, it doesn't matter if the default transport isn't
|
||||
// as fast as some theoretical future alternative.
|
||||
var nodeServicesOptions = new NodeServicesOptions(appBuilder.ApplicationServices);
|
||||
nodeServicesOptions.WatchFileExtensions = new string[] { }; // Don't watch anything
|
||||
nodeServicesOptions.WatchFileExtensions = new string[] {}; // Don't watch anything
|
||||
if (!string.IsNullOrEmpty(options.ProjectPath))
|
||||
{
|
||||
nodeServicesOptions.ProjectPath = options.ProjectPath;
|
||||
@@ -68,7 +73,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||
// Get a filename matching the middleware Node script
|
||||
var script = EmbeddedResourceReader.Read(typeof(WebpackDevMiddleware),
|
||||
"/Content/Node/webpack-dev-middleware.js");
|
||||
var nodeScript = new StringAsTempFile(script, nodeServicesOptions.ApplicationStoppingToken); // Will be cleaned up on process exit
|
||||
var nodeScript = new StringAsTempFile(script); // Will be cleaned up on process exit
|
||||
|
||||
// Ideally, this would be relative to the application's PathBase (so it could work in virtual directories)
|
||||
// but it's not clear that such information exists during application startup, as opposed to within the context
|
||||
|
||||
@@ -1,27 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' == ''">
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' != ''">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="2.0.0-preview2-25405-01" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-preview2-final" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview2-final" />
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -29,23 +21,7 @@
|
||||
<Content Remove="ClientApp\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--/-:cnd:noEmit -->
|
||||
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
|
||||
<!-- Ensure Node.js is installed -->
|
||||
<Exec Command="node --version" ContinueOnError="true">
|
||||
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
||||
</Exec>
|
||||
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
|
||||
|
||||
<!-- In development, the dist files won't exist on the first run or when cloning to
|
||||
a different machine, so rebuild them if not already present. -->
|
||||
<Message Importance="high" Text="Performing first-run Webpack build..." />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js" />
|
||||
</Target>
|
||||
<!--/+:cnd:noEmit -->
|
||||
|
||||
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
|
||||
<Exec Command="npm install" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { AppModuleShared } from './app.module.shared';
|
||||
import { AppComponent } from './components/app/app.component';
|
||||
|
||||
@NgModule({
|
||||
bootstrap: [ AppComponent ],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
AppModuleShared
|
||||
],
|
||||
providers: [
|
||||
{ provide: 'ORIGIN_URL', useValue: location.origin }
|
||||
]
|
||||
})
|
||||
export class AppModule {
|
||||
}
|
||||
22
templates/AngularSpa/ClientApp/app/app.module.client.ts
Normal file
22
templates/AngularSpa/ClientApp/app/app.module.client.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { HttpModule } from '@angular/http';
|
||||
import { sharedConfig } from './app.module.shared';
|
||||
|
||||
@NgModule({
|
||||
bootstrap: sharedConfig.bootstrap,
|
||||
declarations: sharedConfig.declarations,
|
||||
imports: [
|
||||
BrowserModule,
|
||||
FormsModule,
|
||||
HttpModule,
|
||||
...sharedConfig.imports
|
||||
],
|
||||
providers: [
|
||||
{ provide: 'ORIGIN_URL', useValue: location.origin },
|
||||
{ provide: 'PRERENDERING_DATA', useValue: (window as any).PRERENDERING_DATA }
|
||||
]
|
||||
})
|
||||
export class AppModule {
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { ServerModule } from '@angular/platform-server';
|
||||
import { AppModuleShared } from './app.module.shared';
|
||||
import { AppComponent } from './components/app/app.component';
|
||||
import { sharedConfig } from './app.module.shared';
|
||||
|
||||
@NgModule({
|
||||
bootstrap: [ AppComponent ],
|
||||
bootstrap: sharedConfig.bootstrap,
|
||||
declarations: sharedConfig.declarations,
|
||||
imports: [
|
||||
ServerModule,
|
||||
AppModuleShared
|
||||
...sharedConfig.imports
|
||||
]
|
||||
})
|
||||
export class AppModule {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { HttpModule } from '@angular/http';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
||||
import { AppComponent } from './components/app/app.component';
|
||||
import { AppComponent } from './components/app/app.component'
|
||||
import { NavMenuComponent } from './components/navmenu/navmenu.component';
|
||||
import { HomeComponent } from './components/home/home.component';
|
||||
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
|
||||
import { CounterComponent } from './components/counter/counter.component';
|
||||
|
||||
@NgModule({
|
||||
export const sharedConfig: NgModule = {
|
||||
bootstrap: [ AppComponent ],
|
||||
declarations: [
|
||||
AppComponent,
|
||||
NavMenuComponent,
|
||||
@@ -19,9 +17,6 @@ import { CounterComponent } from './components/counter/counter.component';
|
||||
HomeComponent
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
HttpModule,
|
||||
FormsModule,
|
||||
RouterModule.forRoot([
|
||||
{ path: '', redirectTo: 'home', pathMatch: 'full' },
|
||||
{ path: 'home', component: HomeComponent },
|
||||
@@ -30,6 +25,4 @@ import { CounterComponent } from './components/counter/counter.component';
|
||||
{ path: '**', redirectTo: 'home' }
|
||||
])
|
||||
]
|
||||
})
|
||||
export class AppModuleShared {
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<h1>Weather forecast</h1>
|
||||
|
||||
<p>Prerendering data: {{ prerenderingDataString }}</p>
|
||||
|
||||
<p>This component demonstrates fetching data from the server.</p>
|
||||
|
||||
<p *ngIf="!forecasts"><em>Loading...</em></p>
|
||||
|
||||
@@ -7,8 +7,11 @@ import { Http } from '@angular/http';
|
||||
})
|
||||
export class FetchDataComponent {
|
||||
public forecasts: WeatherForecast[];
|
||||
public prerenderingDataString: string;
|
||||
|
||||
constructor(http: Http, @Inject('ORIGIN_URL') originUrl: string, @Inject('PRERENDERING_DATA') prerenderingData: any) {
|
||||
this.prerenderingDataString = JSON.stringify(prerenderingData);
|
||||
|
||||
constructor(http: Http, @Inject('ORIGIN_URL') originUrl: string) {
|
||||
http.get(originUrl + '/api/SampleData/WeatherForecasts').subscribe(result => {
|
||||
this.forecasts = result.json() as WeatherForecast[];
|
||||
});
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import 'reflect-metadata';
|
||||
import 'zone.js';
|
||||
import 'bootstrap';
|
||||
import { enableProdMode } from '@angular/core';
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
import { AppModule } from './app/app.module.browser';
|
||||
import { AppModule } from './app/app.module.client';
|
||||
|
||||
if (module['hot']) {
|
||||
module['hot'].accept();
|
||||
|
||||
@@ -11,7 +11,8 @@ enableProdMode();
|
||||
export default createServerRenderer(params => {
|
||||
const providers = [
|
||||
{ provide: INITIAL_CONFIG, useValue: { document: '<app></app>', url: params.url } },
|
||||
{ provide: 'ORIGIN_URL', useValue: params.origin }
|
||||
{ provide: 'ORIGIN_URL', useValue: params.origin },
|
||||
{ provide: 'PRERENDERING_DATA', useValue: params.data }
|
||||
];
|
||||
|
||||
return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
|
||||
@@ -26,7 +27,8 @@ export default createServerRenderer(params => {
|
||||
// completing the request in case there's an error to report
|
||||
setImmediate(() => {
|
||||
resolve({
|
||||
html: state.renderToString()
|
||||
html: state.renderToString(),
|
||||
globals: { PRERENDERING_DATA: params.data }
|
||||
});
|
||||
moduleRef.destroy();
|
||||
});
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
|
||||
<app asp-prerender-module="ClientApp/dist/main-server"
|
||||
asp-prerender-data="new {
|
||||
IsGoldUser = true,
|
||||
Cookies = ViewContext.HttpContext.Request.Cookies
|
||||
}">Loading...</app>
|
||||
|
||||
<script src="~/dist/vendor.js" asp-append-version="true"></script>
|
||||
@section scripts {
|
||||
|
||||
3
templates/AngularSpa/global.json
Normal file
3
templates/AngularSpa/global.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"sdk": { "version": "sdkVersionInjectedHere" }
|
||||
}
|
||||
@@ -1,46 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' == ''">
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' != ''">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="2.0.0-preview2-25405-01" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-preview2-final" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--/-:cnd:noEmit -->
|
||||
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
|
||||
<!-- Ensure Node.js is installed -->
|
||||
<Exec Command="node --version" ContinueOnError="true">
|
||||
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
||||
</Exec>
|
||||
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
|
||||
|
||||
<!-- In development, the dist files won't exist on the first run or when cloning to
|
||||
a different machine, so rebuild them if not already present. -->
|
||||
<Message Importance="high" Text="Performing first-run Webpack build..." />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js" />
|
||||
</Target>
|
||||
<!--/+:cnd:noEmit -->
|
||||
|
||||
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
|
||||
<Exec Command="npm install" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
|
||||
|
||||
3
templates/AureliaSpa/global.json
Normal file
3
templates/AureliaSpa/global.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"sdk": { "version": "sdkVersionInjectedHere" }
|
||||
}
|
||||
@@ -1,46 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' == ''">
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' != ''">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="2.0.0-preview2-25405-01" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-preview2-final" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--/-:cnd:noEmit -->
|
||||
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
|
||||
<!-- Ensure Node.js is installed -->
|
||||
<Exec Command="node --version" ContinueOnError="true">
|
||||
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
||||
</Exec>
|
||||
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
|
||||
|
||||
<!-- In development, the dist files won't exist on the first run or when cloning to
|
||||
a different machine, so rebuild them if not already present. -->
|
||||
<Message Importance="high" Text="Performing first-run Webpack build..." />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js" />
|
||||
</Target>
|
||||
<!--/+:cnd:noEmit -->
|
||||
|
||||
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
|
||||
<Exec Command="npm install" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
|
||||
|
||||
3
templates/KnockoutSpa/global.json
Normal file
3
templates/KnockoutSpa/global.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"sdk": { "version": "sdkVersionInjectedHere" }
|
||||
}
|
||||
@@ -1,23 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' == ''">
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' != ''">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="2.0.0-preview2-25405-01" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-preview2-final" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -29,23 +21,7 @@
|
||||
<Content Remove="ClientApp\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--/-:cnd:noEmit -->
|
||||
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
|
||||
<!-- Ensure Node.js is installed -->
|
||||
<Exec Command="node --version" ContinueOnError="true">
|
||||
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
||||
</Exec>
|
||||
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
|
||||
|
||||
<!-- In development, the dist files won't exist on the first run or when cloning to
|
||||
a different machine, so rebuild them if not already present. -->
|
||||
<Message Importance="high" Text="Performing first-run Webpack build..." />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js" />
|
||||
</Target>
|
||||
<!--/+:cnd:noEmit -->
|
||||
|
||||
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
|
||||
<Exec Command="npm install" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
|
||||
|
||||
3
templates/ReactReduxSpa/global.json
Normal file
3
templates/ReactReduxSpa/global.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"sdk": { "version": "sdkVersionInjectedHere" }
|
||||
}
|
||||
@@ -1,46 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' == ''">
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' != ''">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="2.0.0-preview2-25405-01" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-preview2-final" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--/-:cnd:noEmit -->
|
||||
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
|
||||
<!-- Ensure Node.js is installed -->
|
||||
<Exec Command="node --version" ContinueOnError="true">
|
||||
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
||||
</Exec>
|
||||
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
|
||||
|
||||
<!-- In development, the dist files won't exist on the first run or when cloning to
|
||||
a different machine, so rebuild them if not already present. -->
|
||||
<Message Importance="high" Text="Performing first-run Webpack build..." />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js" />
|
||||
</Target>
|
||||
<!--/+:cnd:noEmit -->
|
||||
|
||||
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
|
||||
<Exec Command="npm install" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
|
||||
|
||||
3
templates/ReactSpa/global.json
Normal file
3
templates/ReactSpa/global.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"sdk": { "version": "sdkVersionInjectedHere" }
|
||||
}
|
||||
@@ -1,46 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' == ''">
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFrameworkOverride)' != ''">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="2.0.0-preview2-25405-01" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-preview2-final" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-*" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-*" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--/-:cnd:noEmit -->
|
||||
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
|
||||
<!-- Ensure Node.js is installed -->
|
||||
<Exec Command="node --version" ContinueOnError="true">
|
||||
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
||||
</Exec>
|
||||
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
|
||||
|
||||
<!-- In development, the dist files won't exist on the first run or when cloning to
|
||||
a different machine, so rebuild them if not already present. -->
|
||||
<Message Importance="high" Text="Performing first-run Webpack build..." />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js" />
|
||||
</Target>
|
||||
<!--/+:cnd:noEmit -->
|
||||
|
||||
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
|
||||
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
|
||||
<Exec Command="npm install" />
|
||||
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
|
||||
|
||||
3
templates/VueSpa/global.json
Normal file
3
templates/VueSpa/global.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"sdk": { "version": "sdkVersionInjectedHere" }
|
||||
}
|
||||
@@ -11,29 +11,26 @@ import * as targz from 'tar.gz';
|
||||
const isWindows = /^win/.test(process.platform);
|
||||
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx'];
|
||||
const yeomanGeneratorSource = './src/yeoman';
|
||||
const webToolsVSPackageGuid = '{0CD94836-1526-4E85-87D3-FB5274C5AFC9}';
|
||||
|
||||
const dotNetPackages = {
|
||||
builtIn: 'Microsoft.DotNet.Web.Spa.ProjectTemplates',
|
||||
extra: 'Microsoft.AspNetCore.SpaTemplates'
|
||||
// To support the "dotnet new" templates, we want to bundle prebuilt dist dev-mode files, because "dotnet new" can't auto-run
|
||||
// webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
|
||||
// scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
|
||||
const commonTemplatePrepublishSteps = [
|
||||
'npm install',
|
||||
'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js',
|
||||
'node node_modules/webpack/bin/webpack.js'
|
||||
];
|
||||
const commonForceInclusionRegex = /^(wwwroot|ClientApp)\/dist\//; // Files to be included in template, even though gitignored
|
||||
|
||||
const templates: { [key: string]: { dir: string, dotNetNewId: string, displayName: string, prepublish?: string[], forceInclusion?: RegExp } } = {
|
||||
'angular': { dir: '../../templates/AngularSpa/', dotNetNewId: 'Angular', displayName: 'Angular' },
|
||||
'aurelia': { dir: '../../templates/AureliaSpa/', dotNetNewId: 'Aurelia', displayName: 'Aurelia' },
|
||||
'knockout': { dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js' },
|
||||
'react-redux': { dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux' },
|
||||
'react': { dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.js' },
|
||||
'vue': { dir: '../../templates/VueSpa/', dotNetNewId: 'Vue', displayName: 'Vue.js' }
|
||||
};
|
||||
|
||||
interface TemplateConfig {
|
||||
dir: string;
|
||||
dotNetNewId: string;
|
||||
dotNetPackageId: string;
|
||||
displayName: string;
|
||||
localizationIdStart: number;
|
||||
}
|
||||
|
||||
const templates: { [key: string]: TemplateConfig } = {
|
||||
'angular': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/AngularSpa/', dotNetNewId: 'Angular', displayName: 'Angular', localizationIdStart: 1100 },
|
||||
'aurelia': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/AureliaSpa/', dotNetNewId: 'Aurelia', displayName: 'Aurelia', localizationIdStart: 1200 },
|
||||
'knockout': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js', localizationIdStart: 1300 },
|
||||
'react-redux': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux', localizationIdStart: 1400 },
|
||||
'react': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.js', localizationIdStart: 1500 },
|
||||
'vue': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/VueSpa/', dotNetNewId: 'Vue', displayName: 'Vue.js', localizationIdStart: 1600 }
|
||||
};
|
||||
|
||||
function isTextFile(filename: string): boolean {
|
||||
return textFileExtensions.indexOf(path.extname(filename).toLowerCase()) >= 0
|
||||
@@ -46,7 +43,7 @@ function writeFileEnsuringDirExists(root: string, filename: string, contents: st
|
||||
fs.writeFileSync(fullPath, contents);
|
||||
}
|
||||
|
||||
function listFilesExcludingGitignored(root: string): string[] {
|
||||
function listFilesExcludingGitignored(root: string, forceInclusion: RegExp): string[] {
|
||||
// Note that the gitignore files, prior to be written by the generator, are called 'template_gitignore'
|
||||
// instead of '.gitignore'. This is a workaround for Yeoman doing strange stuff with .gitignore files
|
||||
// (it renames them to .npmignore, which is not helpful).
|
||||
@@ -55,23 +52,21 @@ function listFilesExcludingGitignored(root: string): string[] {
|
||||
? gitignore.compile(fs.readFileSync(gitIgnorePath, 'utf8'))
|
||||
: { accepts: () => true };
|
||||
return glob.sync('**/*', { cwd: root, dot: true, nodir: true })
|
||||
.filter(fn => gitignoreEvaluator.accepts(fn));
|
||||
.filter(fn => gitignoreEvaluator.accepts(fn) || (forceInclusion && forceInclusion.test(fn)));
|
||||
}
|
||||
|
||||
function applyContentReplacements(sourceContent: Buffer, contentReplacements: { from: RegExp, to: string }[]) {
|
||||
let sourceText = sourceContent.toString('utf8');
|
||||
contentReplacements.forEach(replacement => {
|
||||
sourceText = sourceText.replace(replacement.from, replacement.to);
|
||||
});
|
||||
|
||||
return new Buffer(sourceText, 'utf8');
|
||||
}
|
||||
|
||||
function writeTemplate(sourceRoot: string, destRoot: string, contentReplacements: { from: RegExp, to: string }[], filenameReplacements: { from: RegExp, to: string }[]) {
|
||||
listFilesExcludingGitignored(sourceRoot).forEach(fn => {
|
||||
function writeTemplate(sourceRoot: string, destRoot: string, contentReplacements: { from: RegExp, to: string }[], filenameReplacements: { from: RegExp, to: string }[], forceInclusion: RegExp) {
|
||||
listFilesExcludingGitignored(sourceRoot, forceInclusion).forEach(fn => {
|
||||
let sourceContent = fs.readFileSync(path.join(sourceRoot, fn));
|
||||
|
||||
// For text files, replace hardcoded values with template tags
|
||||
if (isTextFile(fn)) {
|
||||
sourceContent = applyContentReplacements(sourceContent, contentReplacements);
|
||||
let sourceText = sourceContent.toString('utf8');
|
||||
contentReplacements.forEach(replacement => {
|
||||
sourceText = sourceText.replace(replacement.from, replacement.to);
|
||||
});
|
||||
|
||||
sourceContent = new Buffer(sourceText, 'utf8');
|
||||
}
|
||||
|
||||
// Also apply replacements in filenames
|
||||
@@ -91,22 +86,6 @@ function copyRecursive(sourceRoot: string, destRoot: string, matchGlob: string)
|
||||
});
|
||||
}
|
||||
|
||||
function leftPad(str: string, minLength: number, padChar: string) {
|
||||
while (str.length < minLength) {
|
||||
str = padChar + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function getBuildNumber(): string {
|
||||
if (process.env.APPVEYOR_BUILD_NUMBER) {
|
||||
return leftPad(process.env.APPVEYOR_BUILD_NUMBER, 6, '0');
|
||||
}
|
||||
|
||||
// For local builds, use timestamp
|
||||
return 't-' + Math.floor((new Date().valueOf() - new Date(2017, 0, 1).valueOf()) / (60*1000));
|
||||
}
|
||||
|
||||
function buildYeomanNpmPackage(outputRoot: string) {
|
||||
const outputTemplatesRoot = path.join(outputRoot, 'app/templates');
|
||||
rimraf.sync(outputTemplatesRoot);
|
||||
@@ -116,11 +95,12 @@ function buildYeomanNpmPackage(outputRoot: string) {
|
||||
{ from: /.*\.csproj$/, to: 'tokenreplace-namePascalCase.csproj' }
|
||||
];
|
||||
const contentReplacements = [
|
||||
// Currently, there are none
|
||||
// global.json items
|
||||
{ from: /sdkVersionInjectedHere/, to: '<%= sdkVersion %>' }
|
||||
];
|
||||
_.forEach(templates, (templateConfig, templateName) => {
|
||||
const outputDir = path.join(outputTemplatesRoot, templateName);
|
||||
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements);
|
||||
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
|
||||
});
|
||||
|
||||
// Also copy the generator files (that's the compiled .js files, plus all other non-.ts files)
|
||||
@@ -132,17 +112,7 @@ function buildYeomanNpmPackage(outputRoot: string) {
|
||||
rimraf.sync(tempRoot);
|
||||
}
|
||||
|
||||
function buildDotNetNewNuGetPackages(outputDir: string) {
|
||||
const dotNetPackageIds = _.values(dotNetPackages);
|
||||
dotNetPackageIds.forEach(packageId => {
|
||||
const dotNetNewNupkgPath = buildDotNetNewNuGetPackage(packageId);
|
||||
|
||||
// Move the .nupkg file to the output dir
|
||||
fs.renameSync(dotNetNewNupkgPath, path.join(outputDir, path.basename(dotNetNewNupkgPath)));
|
||||
});
|
||||
}
|
||||
|
||||
function buildDotNetNewNuGetPackage(packageId: string) {
|
||||
function buildDotNetNewNuGetPackage() {
|
||||
const outputRoot = './dist/dotnetnew';
|
||||
rimraf.sync(outputRoot);
|
||||
|
||||
@@ -155,13 +125,8 @@ function buildDotNetNewNuGetPackage(packageId: string) {
|
||||
];
|
||||
const contentReplacements = [];
|
||||
_.forEach(templates, (templateConfig, templateName) => {
|
||||
// Only include templates matching the output package ID
|
||||
if (templateConfig.dotNetPackageId !== packageId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
|
||||
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements);
|
||||
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
|
||||
|
||||
// Add the .template.config dir and its contents
|
||||
const templateConfigDir = path.join(templateOutputDir, '.template.config');
|
||||
@@ -169,10 +134,10 @@ function buildDotNetNewNuGetPackage(packageId: string) {
|
||||
|
||||
fs.writeFileSync(path.join(templateConfigDir, 'template.json'), JSON.stringify({
|
||||
author: 'Microsoft',
|
||||
classifications: ['Web', 'MVC', 'SPA'],
|
||||
groupIdentity: `${packageId}.${templateConfig.dotNetNewId}`,
|
||||
identity: `${packageId}.${templateConfig.dotNetNewId}.CSharp`,
|
||||
name: `ASP.NET Core with ${templateConfig.displayName}`,
|
||||
classifications: ["Web", "MVC", "SPA"],
|
||||
groupIdentity: `Microsoft.AspNetCore.SpaTemplates.${templateConfig.dotNetNewId}`,
|
||||
identity: `Microsoft.AspNetCore.SpaTemplates.${templateConfig.dotNetNewId}.CSharp`,
|
||||
name: `MVC ASP.NET Core with ${templateConfig.displayName}`,
|
||||
preferNameDirectory: true,
|
||||
primaryOutputs: [{ path: `${sourceProjectName}.csproj` }],
|
||||
shortName: `${templateConfig.dotNetNewId.toLowerCase()}`,
|
||||
@@ -183,116 +148,46 @@ function buildDotNetNewNuGetPackage(packageId: string) {
|
||||
exclude: ['.template.config/**']
|
||||
}],
|
||||
symbols: {
|
||||
TargetFrameworkOverride: {
|
||||
type: 'parameter',
|
||||
description: 'Overrides the target framework',
|
||||
replaces: 'TargetFrameworkOverride',
|
||||
datatype: 'string',
|
||||
defaultValue: ''
|
||||
sdkVersion: {
|
||||
type: 'bind',
|
||||
binding: 'dotnet-cli-version',
|
||||
replaces: 'sdkVersionInjectedHere'
|
||||
},
|
||||
Framework: {
|
||||
type: 'parameter',
|
||||
description: 'The target framework for the project.',
|
||||
datatype: 'choice',
|
||||
type: "parameter",
|
||||
description: "The target framework for the project.",
|
||||
datatype: "choice",
|
||||
choices: [
|
||||
{
|
||||
choice: 'netcoreapp2.0',
|
||||
description: 'Target netcoreapp2.0'
|
||||
choice: "netcoreapp1.1",
|
||||
description: "Target netcoreapp1.1"
|
||||
}
|
||||
],
|
||||
replaces: 'netcoreapp2.0',
|
||||
defaultValue: 'netcoreapp2.0'
|
||||
},
|
||||
HostIdentifier: {
|
||||
type: 'bind',
|
||||
binding: 'HostIdentifier'
|
||||
},
|
||||
skipRestore: {
|
||||
type: 'parameter',
|
||||
datatype: 'bool',
|
||||
description: 'If specified, skips the automatic restore of packages on project creation.',
|
||||
defaultValue: 'false'
|
||||
defaultValue: "netcoreapp1.1"
|
||||
}
|
||||
},
|
||||
tags: { language: 'C#', type: 'project' },
|
||||
postActions: [
|
||||
{
|
||||
condition: '(!skipRestore)',
|
||||
description: 'Restores NuGet packages required by this project.',
|
||||
manualInstructions: [{ text: 'Run \'dotnet restore\'' }],
|
||||
actionId: '210D431B-A78B-4D2F-B762-4ED3E3EA9025',
|
||||
continueOnError: true
|
||||
},
|
||||
/*
|
||||
// Currently it doesn't appear to be possible to run `npm install` from a
|
||||
// postAction, due to https://github.com/dotnet/templating/issues/849
|
||||
// We will re-enable this when that bug is fixed.
|
||||
{
|
||||
condition: '(!skipRestore)',
|
||||
description: 'Restores NPM packages required by this project.',
|
||||
manualInstructions: [{ text: 'Run \'npm install\'' }],
|
||||
actionId: '3A7C4B45-1F5D-4A30-959A-51B88E82B5D2',
|
||||
args: { executable: 'npm', args: 'install' },
|
||||
continueOnError: false
|
||||
}
|
||||
*/
|
||||
{
|
||||
// For the preview2 release, just display manual instructions instead.
|
||||
// This is only applicable on the command line, because VS will restore
|
||||
// NPM packages automatically by default.
|
||||
condition: '(HostIdentifier == "dotnetcli" || HostIdentifier == "dotnetcli-preview")',
|
||||
actionId: 'AC1156F7-BB77-4DB8-B28F-24EEBCCA1E5C',
|
||||
description: '\n\n-------------------------------------------------------------------\nIMPORTANT: Before running this project on the command line,\n you must restore NPM packages by running "npm install"\n-------------------------------------------------------------------\n',
|
||||
manualInstructions: [{ text: 'Run "npm install"' }]
|
||||
}
|
||||
],
|
||||
}, null, 2));
|
||||
|
||||
fs.writeFileSync(path.join(templateConfigDir, 'dotnetcli.host.json'), JSON.stringify({
|
||||
$schema: 'http://json.schemastore.org/dotnetcli.host',
|
||||
symbolInfo: {
|
||||
TargetFrameworkOverride: {
|
||||
isHidden: 'true',
|
||||
longName: 'target-framework-override',
|
||||
shortName: ''
|
||||
},
|
||||
Framework: {
|
||||
longName: 'framework'
|
||||
},
|
||||
skipRestore: {
|
||||
longName: 'no-restore',
|
||||
shortName: ''
|
||||
}
|
||||
}
|
||||
symbolInfo: {}
|
||||
}, null, 2));
|
||||
|
||||
const localisedNameId = templateConfig.localizationIdStart + 0;
|
||||
const localisedDescId = templateConfig.localizationIdStart + 1;
|
||||
|
||||
fs.writeFileSync(path.join(templateConfigDir, 'vs-2017.3.host.json'), JSON.stringify({
|
||||
$schema: 'http://json.schemastore.org/vs-2017.3.host',
|
||||
name: { text: templateConfig.displayName, package: webToolsVSPackageGuid, id: localisedNameId.toString() },
|
||||
description: { text: `A project template for creating an ASP.NET Core application with ${templateConfig.displayName}`, package: webToolsVSPackageGuid, id: localisedDescId.toString() },
|
||||
order: 301,
|
||||
name: { text: templateConfig.displayName },
|
||||
description: { text: `Web application built with MVC ASP.NET Core and ${templateConfig.displayName}` },
|
||||
order: 2000,
|
||||
icon: 'icon.png',
|
||||
learnMoreLink: 'https://github.com/aspnet/JavaScriptServices',
|
||||
uiFilters: [ 'oneaspnet' ],
|
||||
minFullFrameworkVersion: '4.6.1'
|
||||
uiFilters: [ 'oneaspnet' ]
|
||||
}, null, 2));
|
||||
});
|
||||
|
||||
// Create the .nuspec file
|
||||
const yeomanPackageVersion = JSON.parse(fs.readFileSync(path.join(yeomanGeneratorSource, 'package.json'), 'utf8')).version;
|
||||
const nuspecContentTemplate = fs.readFileSync(`./src/dotnetnew/${ packageId }.nuspec`);
|
||||
writeFileEnsuringDirExists(outputRoot,
|
||||
`${ packageId }.nuspec`,
|
||||
applyContentReplacements(nuspecContentTemplate, [
|
||||
{ from: /\{yeomanversion\}/g, to: yeomanPackageVersion },
|
||||
{ from: /\{buildnumber\}/g, to: getBuildNumber() },
|
||||
])
|
||||
);
|
||||
|
||||
// Invoke NuGet to create the final package
|
||||
const yeomanPackageVersion = JSON.parse(fs.readFileSync(path.join(yeomanGeneratorSource, 'package.json'), 'utf8')).version;
|
||||
writeTemplate('./src/dotnetnew', outputRoot, [
|
||||
{ from: /\{version\}/g, to: yeomanPackageVersion },
|
||||
], [], null);
|
||||
const nugetExe = path.join(process.cwd(), './bin/NuGet.exe');
|
||||
const nugetStartInfo = { cwd: outputRoot, stdio: 'inherit' };
|
||||
if (isWindows) {
|
||||
@@ -309,7 +204,21 @@ function buildDotNetNewNuGetPackage(packageId: string) {
|
||||
return glob.sync(path.join(outputRoot, './*.nupkg'))[0];
|
||||
}
|
||||
|
||||
function runPrepublishScripts(rootDir: string, scripts: string[]) {
|
||||
function runAllPrepublishScripts() {
|
||||
Object.getOwnPropertyNames(templates).forEach(templateKey => {
|
||||
const templateInfo = templates[templateKey];
|
||||
|
||||
// First run standard prepublish steps
|
||||
runScripts(templateInfo.dir, commonTemplatePrepublishSteps);
|
||||
|
||||
// Second, run any template-specific prepublish steps
|
||||
if (templateInfo.prepublish) {
|
||||
runScripts(templateInfo.dir, templateInfo.prepublish);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function runScripts(rootDir: string, scripts: string[]) {
|
||||
console.log(`[Prepublish] In directory: ${ rootDir }`);
|
||||
scripts.forEach(script => {
|
||||
console.log(`[Prepublish] Running: ${ script }`);
|
||||
@@ -324,8 +233,12 @@ const yeomanOutputRoot = path.join(distDir, 'generator-aspnetcore-spa');
|
||||
|
||||
rimraf.sync(distDir);
|
||||
mkdirp.sync(artifactsDir);
|
||||
runAllPrepublishScripts();
|
||||
buildYeomanNpmPackage(yeomanOutputRoot);
|
||||
buildDotNetNewNuGetPackages(artifactsDir);
|
||||
const dotNetNewNupkgPath = buildDotNetNewNuGetPackage();
|
||||
|
||||
// Move the .nupkg file to the artifacts dir
|
||||
fs.renameSync(dotNetNewNupkgPath, path.join(artifactsDir, path.basename(dotNetNewNupkgPath)));
|
||||
|
||||
// Finally, create a .tar.gz file containing the built generator-aspnetcore-spa.
|
||||
// The CI system can treat this as the final built artifact.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Microsoft.AspNetCore.SpaTemplates</id>
|
||||
<version>{yeomanversion}</version>
|
||||
<version>{version}</version>
|
||||
<description>Single Page Application templates for ASP.NET Core</description>
|
||||
<authors>Microsoft</authors>
|
||||
<language>en-US</language>
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Microsoft.DotNet.Web.Spa.ProjectTemplates</id>
|
||||
<version>1.0.0-preview-{buildnumber}</version>
|
||||
<description>Single Page Application templates for ASP.NET Core</description>
|
||||
<authors>Microsoft</authors>
|
||||
<language>en-US</language>
|
||||
<projectUrl>https://github.com/aspnet/javascriptservices</projectUrl>
|
||||
<licenseUrl>https://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
|
||||
<copyright>Copyright © Microsoft Corporation</copyright>
|
||||
<requireLicenseAcceptance>true</requireLicenseAcceptance>
|
||||
<packageTypes>
|
||||
<packageType name="Template" />
|
||||
</packageTypes>
|
||||
</metadata>
|
||||
</package>
|
||||
Reference in New Issue
Block a user