Browse Source

Old files removed

pull/1/head
Sebastian 9 years ago
parent
commit
bf1cac3eca
  1. 23
      src/Squidex/Config/Web/WebpackServices.cs
  2. 27
      src/Squidex/Pipeline/RandomErrorAttribute.cs
  3. 93
      src/Squidex/Pipeline/WebpackRunner.cs

23
src/Squidex/Config/Web/WebpackServices.cs

@ -1,23 +0,0 @@
// ==========================================================================
// WebpackServices.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using Microsoft.Extensions.DependencyInjection;
using Squidex.Pipeline;
namespace Squidex.Config.Web
{
public static class WebpackServices
{
public static IServiceCollection AddWebpackBuilder(this IServiceCollection services)
{
services.AddSingleton<WebpackRunner>();
return services;
}
}
}

27
src/Squidex/Pipeline/RandomErrorAttribute.cs

@ -1,27 +0,0 @@
// ==========================================================================
// RandomErrorAttribute.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Squidex.Pipeline
{
public sealed class RandomErrorAttribute : ActionFilterAttribute
{
private static readonly Random Random = new Random();
public override void OnActionExecuted(ActionExecutedContext context)
{
if (Random.Next(10) < 5)
{
context.Result = new StatusCodeResult(500);
}
}
}
}

93
src/Squidex/Pipeline/WebpackRunner.cs

@ -1,93 +0,0 @@
// ==========================================================================
// WebpackRunner.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
// ReSharper disable ConvertToConstant.Local
namespace Squidex.Pipeline
{
public sealed class WebpackRunner
{
private const string WebpackDevServer = "webpack-dev-server";
private readonly ILoggerFactory loggerFactory;
private readonly IApplicationLifetime lifetime;
private Process process;
public WebpackRunner(ILoggerFactory loggerFactory, IApplicationLifetime lifetime)
{
this.loggerFactory = loggerFactory;
this.lifetime = lifetime;
}
public void Execute()
{
if (process != null)
{
return;
}
var logger = loggerFactory.CreateLogger(WebpackDevServer);
EnsuereNodeModluesInstalled(logger);
logger.LogInformation($"{WebpackDevServer} Execution started");
var app = GetNodeExecutable(WebpackDevServer);
var args = "--inline --hot --port 3000";
process = Process.Start(new ProcessStartInfo
{
FileName = app, Arguments = args, UseShellExecute = false
});
lifetime.ApplicationStopping.Register(OnShutdown);
logger.LogInformation($"{WebpackDevServer} started successfully");
}
private void OnShutdown()
{
process?.Kill();
process = null;
}
private static void EnsuereNodeModluesInstalled(ILogger logger)
{
logger.LogInformation("Verifying required tools are installed");
if (!File.Exists(GetNodeExecutable(WebpackDevServer)))
{
logger.LogError("webpack-dev-server is not installed. Please install it by executing npm i webpack-dev-server");
}
logger.LogInformation("All node modules are properly installed");
}
private static string GetNodeExecutable(string module)
{
var executablePath = Path.Combine(Directory.GetCurrentDirectory(), "node_modules", ".bin", module);
var osEnVariable = Environment.GetEnvironmentVariable("OS");
if (!string.IsNullOrEmpty(osEnVariable) &&
string.Equals(osEnVariable, "Windows_NT", StringComparison.OrdinalIgnoreCase))
{
executablePath += ".cmd";
}
return executablePath;
}
}
}
Loading…
Cancel
Save