Browse Source

Minor improvements to logging and webpack.

pull/297/head
Sebastian 8 years ago
parent
commit
a23519a761
  1. 21
      src/Squidex.Infrastructure/Log/ConsoleLogChannel.cs
  2. 4
      src/Squidex.Infrastructure/Log/Internal/AnsiLogConsole.cs
  3. 4
      src/Squidex.Infrastructure/Log/Internal/ConsoleLogProcessor.cs
  4. 2
      src/Squidex.Infrastructure/Log/Internal/IConsole.cs
  5. 5
      src/Squidex.Infrastructure/Log/Internal/WindowsLogConsole.cs
  6. 7
      src/Squidex/Config/Domain/LoggingServices.cs
  7. 2
      src/Squidex/app-config/karma.coverage.conf.js
  8. 27
      src/Squidex/app-config/webpack.config.js
  9. 24
      src/Squidex/app-config/webpack.run.base.js
  10. 22
      src/Squidex/app-config/webpack.run.dev.js
  11. 36
      src/Squidex/app-config/webpack.run.prod.js
  12. 38
      src/Squidex/app-config/webpack.test.coverage.js
  13. 6
      src/Squidex/appsettings.json
  14. 1
      src/Squidex/package.json

21
src/Squidex.Infrastructure/Log/ConsoleLogChannel.cs

@ -13,6 +13,12 @@ namespace Squidex.Infrastructure.Log
public sealed class ConsoleLogChannel : ILogChannel, IDisposable public sealed class ConsoleLogChannel : ILogChannel, IDisposable
{ {
private readonly ConsoleLogProcessor processor = new ConsoleLogProcessor(); private readonly ConsoleLogProcessor processor = new ConsoleLogProcessor();
private readonly bool useColors;
public ConsoleLogChannel(bool useColors = false)
{
this.useColors = useColors;
}
public void Dispose() public void Dispose()
{ {
@ -23,13 +29,16 @@ namespace Squidex.Infrastructure.Log
{ {
var color = 0; var color = 0;
if (logLevel == SemanticLogLevel.Warning) if (useColors)
{
color = 0xffff00;
}
else if (logLevel >= SemanticLogLevel.Error)
{ {
color = 0xff0000; if (logLevel == SemanticLogLevel.Warning)
{
color = 0xffff00;
}
else if (logLevel >= SemanticLogLevel.Error)
{
color = 0xff0000;
}
} }
processor.EnqueueMessage(new LogMessageEntry { Message = message, Color = color }); processor.EnqueueMessage(new LogMessageEntry { Message = message, Color = color });

4
src/Squidex.Infrastructure/Log/Internal/AnsiLogConsole.cs

@ -18,6 +18,10 @@ namespace Squidex.Infrastructure.Log.Internal
this.logToStdError = logToStdError; this.logToStdError = logToStdError;
} }
public void Reset()
{
}
public void WriteLine(int color, string message) public void WriteLine(int color, string message)
{ {
if (color != 0 && logToStdError) if (color != 0 && logToStdError)

4
src/Squidex.Infrastructure/Log/Internal/ConsoleLogProcessor.cs

@ -86,6 +86,10 @@ namespace Squidex.Infrastructure.Log.Internal
{ {
Debug.WriteLine($"Failed to shutdown log queue grateful: {ex}."); Debug.WriteLine($"Failed to shutdown log queue grateful: {ex}.");
} }
finally
{
console.Reset();
}
} }
} }
} }

2
src/Squidex.Infrastructure/Log/Internal/IConsole.cs

@ -10,5 +10,7 @@ namespace Squidex.Infrastructure.Log.Internal
public interface IConsole public interface IConsole
{ {
void WriteLine(int color, string message); void WriteLine(int color, string message);
void Reset();
} }
} }

5
src/Squidex.Infrastructure/Log/Internal/WindowsLogConsole.cs

@ -18,6 +18,11 @@ namespace Squidex.Infrastructure.Log.Internal
this.logToStdError = logToStdError; this.logToStdError = logToStdError;
} }
public void Reset()
{
Console.ResetColor();
}
public void WriteLine(int color, string message) public void WriteLine(int color, string message)
{ {
if (color != 0) if (color != 0)

7
src/Squidex/Config/Domain/LoggingServices.cs

@ -42,6 +42,13 @@ namespace Squidex.Config.Domain
.As<IInitializable>(); .As<IInitializable>();
} }
var useColors = config.GetValue<bool>("logging:colors");
if (console == null)
{
console = new ConsoleLogChannel(useColors);
}
services.AddSingletonAs(console) services.AddSingletonAs(console)
.As<ILogChannel>(); .As<ILogChannel>();

2
src/Squidex/app-config/karma.coverage.conf.js

@ -1,4 +1,4 @@
var webpackConfig = require('./webpack.test'); var webpackConfig = require('./webpack.test.coverage');
module.exports = function (config) { module.exports = function (config) {
var _config = { var _config = {

27
src/Squidex/app-config/webpack.config.js

@ -1,9 +1,13 @@
var webpack = require('webpack'), const webpack = require('webpack'),
path = require('path'), path = require('path'),
HtmlWebpackPlugin = require('html-webpack-plugin'), helpers = require('./helpers');
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'), const plugins = {
helpers = require('./helpers'); // https://github.com/webpack-contrib/mini-css-extract-plugin
MiniCssExtractPlugin: require('mini-css-extract-plugin'),
// https://github.com/dividab/tsconfig-paths-webpack-plugin
TsconfigPathsPlugin: require('tsconfig-paths-webpack-plugin')
};
module.exports = { module.exports = {
/** /**
@ -25,7 +29,7 @@ module.exports = {
], ],
plugins: [ plugins: [
new TsconfigPathsPlugin() new plugins.TsconfigPathsPlugin()
] ]
}, },
@ -83,7 +87,7 @@ module.exports = {
}, { }, {
test: /\.css$/, test: /\.css$/,
use: [ use: [
MiniCssExtractPlugin.loader, plugins.MiniCssExtractPlugin.loader,
{ {
loader: 'css-loader' loader: 'css-loader'
}] }]
@ -100,6 +104,13 @@ module.exports = {
}, },
plugins: [ plugins: [
/*
* Puts each bundle into a file and appends the hash of the file to the path.
*
* See: https://github.com/webpack-contrib/mini-css-extract-plugin
*/
new plugins.MiniCssExtractPlugin('[name].css'),
new webpack.LoaderOptionsPlugin({ new webpack.LoaderOptionsPlugin({
options: { options: {
tslint: { tslint: {

24
src/Squidex/app-config/webpack.run.base.js

@ -1,8 +1,11 @@
 var webpack = require('webpack'), const webpack = require('webpack'),
webpackMerge = require('webpack-merge'), webpackMerge = require('webpack-merge'),
HtmlWebpackPlugin = require('html-webpack-plugin'), commonConfig = require('./webpack.config.js'),
commonConfig = require('./webpack.config.js'), helpers = require('./helpers');
helpers = require('./helpers');
const plugins = {
HtmlWebpackPlugin: require('html-webpack-plugin')
};
module.exports = webpackMerge(commonConfig, { module.exports = webpackMerge(commonConfig, {
/** /**
@ -17,21 +20,14 @@ module.exports = webpackMerge(commonConfig, {
}, },
plugins: [ plugins: [
/** new plugins.HtmlWebpackPlugin({
* Simplifies creation of HTML files to serve your webpack bundles.
* This is especially useful for webpack bundles that include a hash in the filename
* which changes every compilation.
*
* See: https://github.com/ampedandwired/html-webpack-plugin
*/
new HtmlWebpackPlugin({
hash: true, hash: true,
chunks: ['shims', 'app'], chunks: ['shims', 'app'],
chunksSortMode: 'manual', chunksSortMode: 'manual',
template: 'wwwroot/index.html' template: 'wwwroot/index.html'
}), }),
new HtmlWebpackPlugin({ new plugins.HtmlWebpackPlugin({
template: 'wwwroot/theme.html', hash: true, chunksSortMode: 'none', filename: 'theme.html' template: 'wwwroot/theme.html', hash: true, chunksSortMode: 'none', filename: 'theme.html'
}) })
] ]

22
src/Squidex/app-config/webpack.run.dev.js

@ -1,13 +1,13 @@
 var webpackMerge = require('webpack-merge'), const webpackMerge = require('webpack-merge'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'), runConfig = require('./webpack.run.base.js'),
runConfig = require('./webpack.run.base.js'), helpers = require('./helpers');
helpers = require('./helpers');
module.exports = webpackMerge(runConfig, { module.exports = webpackMerge(runConfig, {
mode: 'development', mode: 'development',
output: { output: {
filename: '[name].js', filename: '[name].js',
// Set the public path, because we are running the website from another port (5000) // Set the public path, because we are running the website from another port (5000)
publicPath: 'http://localhost:3000/' publicPath: 'http://localhost:3000/'
}, },
@ -37,20 +37,10 @@ module.exports = webpackMerge(runConfig, {
} }
] ]
}, },
plugins: [
/*
* Puts each bundle into a file and appends the hash of the file to the path.
*
* See: https://github.com/webpack-contrib/mini-css-extract-plugin
*/
new MiniCssExtractPlugin('[name].css'),
],
devServer: { devServer: {
historyApiFallback: true, stats: 'minimal',
headers: { headers: {
'Access-Control-Allow-Origin': '*' 'Access-Control-Allow-Origin': '*'
} },
historyApiFallback: true
} }
}); });

36
src/Squidex/app-config/webpack.run.prod.js

@ -1,10 +1,15 @@
 var webpack = require('webpack'), const webpack = require('webpack'),
webpackMerge = require('webpack-merge'), webpackMerge = require('webpack-merge'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'), runConfig = require('./webpack.run.base.js'),
ngToolsWebpack = require('@ngtools/webpack'), helpers = require('./helpers');
runConfig = require('./webpack.run.base.js'),
helpers = require('./helpers');
const plugins = {
// https://www.npmjs.com/package/@ngtools/webpack
NgToolsWebpack: require('@ngtools/webpack'),
// https://github.com/webpack-contrib/mini-css-extract-plugin
MiniCssExtractPlugin: require('mini-css-extract-plugin'),
};
helpers.removeLoaders(runConfig, ['scss', 'ts']); helpers.removeLoaders(runConfig, ['scss', 'ts']);
module.exports = webpackMerge(runConfig, { module.exports = webpackMerge(runConfig, {
@ -57,9 +62,9 @@ module.exports = webpackMerge(runConfig, {
* See: https://github.com/webpack-contrib/extract-text-webpack-plugin * See: https://github.com/webpack-contrib/extract-text-webpack-plugin
*/ */
use: [ use: [
MiniCssExtractPlugin.loader, plugins.MiniCssExtractPlugin.loader,
{ {
loader: 'css-loader' loader: 'css-loader', options: { minimize: true },
}, { }, {
loader: 'sass-loader' loader: 'sass-loader'
}], }],
@ -85,16 +90,11 @@ module.exports = webpackMerge(runConfig, {
}, },
plugins: [ plugins: [
/* new plugins.NgToolsWebpack.AngularCompilerPlugin({
* Puts each bundle into a file and appends the hash of the file to the path. entryModule: 'app/app.module#AppModule',
* sourceMap: false,
* See: https://github.com/webpack-contrib/mini-css-extract-plugin skipSourceGeneration: false,
*/ tsConfigPath: './tsconfig.json'
new MiniCssExtractPlugin('[name].css'),
new ngToolsWebpack.AngularCompilerPlugin({
tsConfigPath: './tsconfig.json',
entryModule: 'app/app.module#AppModule'
}) })
] ]
}); });

38
src/Squidex/app-config/webpack.test.coverage.js

@ -0,0 +1,38 @@
var webpackMerge = require('webpack-merge'),
path = require('path'),
helpers = require('./helpers'),
testConfig = require('./webpack.test.js');
helpers.removeLoaders(testConfig, ['ts']);
module.exports = webpackMerge(testConfig, {
module: {
/**
* An array of Rules which are matched to requests when modules are created.
*
* See: https://webpack.js.org/configuration/module/#module-rules
*/
rules: [
{
test: /\.ts$/,
use: [{
loader: 'awesome-typescript-loader'
}],
include: [/\.(e2e|spec)\.ts$/],
}, {
test: /\.ts$/,
use: [{
loader: 'istanbul-instrumenter-loader'
},{
loader: 'awesome-typescript-loader'
}, {
loader: 'angular2-router-loader'
}, {
loader: 'angular2-template-loader'
}],
exclude: [/\.(e2e|spec)\.ts$/]
}
]
}
});

6
src/Squidex/appsettings.json

@ -53,7 +53,11 @@
/* /*
* Setting the flag to true, enables well formatteds json logs. * Setting the flag to true, enables well formatteds json logs.
*/ */
"human": true "human": true,
/*
* Set to true, to use colors.
*/
"colors": true
}, },
"assetStore": { "assetStore": {

1
src/Squidex/package.json

@ -9,6 +9,7 @@
"test:coverage": "karma start karma.coverage.conf.js", "test:coverage": "karma start karma.coverage.conf.js",
"test:clean": "rimraf _test-output", "test:clean": "rimraf _test-output",
"dev": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/ && webpack-dev-server --config app-config/webpack.run.dev.js --inline --port 3000", "dev": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/ && webpack-dev-server --config app-config/webpack.run.dev.js --inline --port 3000",
"start": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/ && webpack-dev-server --config app-config/webpack.run.dev.js --inline --port 3000",
"build": "webpack --config app-config/webpack.run.prod.js", "build": "webpack --config app-config/webpack.run.prod.js",
"build:copy": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/", "build:copy": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/",
"build:clean": "rimraf wwwroot/build", "build:clean": "rimraf wwwroot/build",

Loading…
Cancel
Save